diff options
Diffstat (limited to 'VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py')
-rw-r--r-- | VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py index 82067295..3945cd8e 100644 --- a/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py +++ b/VNFs/DPPD-PROX/helper-scripts/rapid/rapid_impairtest.py @@ -21,6 +21,7 @@ import sys import time import requests from rapid_log import RapidLog +from rapid_log import bcolors from rapid_test import RapidTest from statistics import mean @@ -28,54 +29,80 @@ class ImpairTest(RapidTest): """ Class to manage the impair testing """ - def __init__(self, test_param, lat_percentile, runtime, pushgateway, - environment_file, gen_machine, sut_machine): - super().__init__(test_param, runtime, pushgateway, environment_file) + def __init__(self, test_param, lat_percentile, runtime, testname, + environment_file, gen_machine, sut_machine, background_machines): + super().__init__(test_param, runtime, testname, environment_file) self.gen_machine = gen_machine self.sut_machine = sut_machine + self.background_machines = background_machines self.test['lat_percentile'] = lat_percentile def run(self): - # fieldnames = ['Flows','PacketSize','RequestedPPS','GeneratedPPS','SentPPS','ForwardedPPS','ReceivedPPS','AvgLatencyUSEC','MaxLatencyUSEC','Dropped','DropRate'] - # writer = csv.DictWriter(data_csv_file, fieldnames=fieldnames) - # writer.writeheader() + result_details = {'Details': 'Nothing'} imix = self.test['imix'] size = mean (imix) flow_number = self.test['flowsize'] - attempts = 0 + attempts = self.test['steps'] self.gen_machine.set_udp_packet_size(imix) flow_number = self.gen_machine.set_flows(flow_number) self.gen_machine.start_latency_cores() - RapidLog.info("+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+") - RapidLog.info("| Generator is sending UDP ({:>5} flow) packets ({:>5} bytes) to SUT via GW dropping and delaying packets. SUT sends packets back. Use ctrl-c to stop the test |".format(flow_number,size)) - RapidLog.info("+--------+------------------+-------------+-------------+-------------+------------------------+----------+----------+----------+-----------+-----------+-----------+-----------+-------+----+") - RapidLog.info('| Test | Speed requested | Gen by core | Sent by NIC | Fwrd by SUT | Rec. by core | Avg. Lat.|{:.0f} Pcentil| Max. Lat.| Sent | Received | Lost | Total Lost|L.Ratio|Time|'.format(self.test['lat_percentile']*100)) - RapidLog.info("+--------+------------------+-------------+-------------+-------------+------------------------+----------+----------+----------+-----------+-----------+-----------+-----------+-------+----+") - + RapidLog.info('+' + '-' * 188 + '+') + RapidLog.info(("| Generator is sending UDP ({:>5} flow) packets ({:>5}" + " bytes) to SUT via GW dropping and delaying packets. SUT sends " + "packets back.{:>60}").format(flow_number,round(size),'|')) + RapidLog.info('+' + '-' * 8 + '+' + '-' * 18 + '+' + '-' * 13 + + '+' + '-' * 13 + '+' + '-' * 13 + '+' + '-' * 24 + '+' + + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 11 + + '+' + '-' * 11 + '+' + '-' * 11 + '+' + '-' * 11 + '+' + + '-' * 7 + '+' + '-' * 4 + '+') + RapidLog.info(('| Test | Speed requested | Gen by core | Sent by NIC' + ' | Fwrd by SUT | Rec. by core | Avg. Lat.|{:.0f} Pcentil' + '| Max. Lat.| Sent | Received | Lost | Total Lost|' + 'L.Ratio|Time|').format(self.test['lat_percentile']*100)) + RapidLog.info('+' + '-' * 8 + '+' + '-' * 18 + '+' + '-' * 13 + + '+' + '-' * 13 + '+' + '-' * 13 + '+' + '-' * 24 + '+' + + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 11 + + '+' + '-' * 11 + '+' + '-' * 11 + '+' + '-' * 11 + '+' + + '-' * 7 + '+' + '-' * 4 + '+') speed = self.test['startspeed'] self.gen_machine.set_generator_speed(speed) - while True: - attempts += 1 + while attempts: + attempts -= 1 print('Measurement ongoing at speed: ' + str(round(speed,2)) + '% ',end='\r') sys.stdout.flush() time.sleep(1) # Get statistics now that the generation is stable and NO ARP messages any more - pps_req_tx,pps_tx,pps_sut_tx,pps_rx,lat_avg, lat_perc, lat_perc_max, lat_max, abs_tx, abs_rx, abs_dropped, abs_tx_fail, drop_rate, lat_min, lat_used, r, actual_duration = self.run_iteration(float(self.test['runtime']),flow_number,size,speed) + iteration_data = self.run_iteration(float(self.test['runtime']),flow_number,size,speed) + iteration_data['speed'] = speed # Drop rate is expressed in percentage. lat_used is a ratio (0 to 1). The sum of these 2 should be 100%. # If the sum is lower than 95, it means that more than 5% of the latency measurements where dropped for accuracy reasons. - if (drop_rate + lat_used * 100) < 95: - lat_warning = bcolors.WARNING + ' Latency accuracy issue?: {:>3.0f}%'.format(lat_used*100) + bcolors.ENDC + if (iteration_data['drop_rate'] + + iteration_data['lat_used'] * 100) < 95: + lat_warning = ('{} Latency accuracy issue?: {:>3.0f}%' + '{}').format(bcolors.WARNING, + iteration_data['lat_used']*100, bcolors.ENDC) else: lat_warning = '' - RapidLog.info(self.report_result(attempts,size,speed,pps_req_tx,pps_tx,pps_sut_tx,pps_rx,lat_avg,lat_perc,lat_perc_max,lat_max,abs_tx,abs_rx,abs_dropped,actual_duration)) -# writer.writerow({'Flows':flow_number,'PacketSize':(size+4),'RequestedPPS':self.get_pps(speed,size),'GeneratedPPS':pps_req_tx,'SentPPS':pps_tx,'ForwardedPPS':pps_sut_tx_str,'ReceivedPPS':pps_rx,'AvgLatencyUSEC':lat_avg,'MaxLatencyUSEC':lat_max,'Dropped':abs_dropped,'DropRate':drop_rate}) - if self.test['pushgateway']: - URL = self.test['pushgateway'] + self.test['test'] + '/instance/' + self.test['environment_file'] - DATA = 'Flows {}\nPacketSize {}\nRequestedPPS {}\nGeneratedPPS {}\nSentPPS {}\nForwardedPPS {}\nReceivedPPS {}\nAvgLatencyUSEC {}\nMaxLatencyUSEC {}\nDropped {}\nDropRate {}\n'.format(flow_number,size+4,self.get_pps(speed,size),pps_req_tx,pps_tx,pps_sut_tx,pps_rx,lat_avg,lat_max,abs_dropped,drop_rate) - HEADERS = {'X-Requested-With': 'Python requests', 'Content-type': 'text/xml'} - response = requests.post(url=URL, data=DATA,headers=HEADERS) - if (response.status_code != 202) and (response.status_code != 200): - RapidLog.info('Cannot send metrics to {}'.format(URL)) - RapidLog.info(DATA) + iteration_prefix = {'speed' : '', + 'lat_avg' : '', + 'lat_perc' : '', + 'lat_max' : '', + 'abs_drop_rate' : '', + 'drop_rate' : ''} + RapidLog.info(self.report_result(attempts, size, iteration_data, + iteration_prefix)) + iteration_data['test'] = self.test['testname'] + iteration_data['environment_file'] = self.test['environment_file'] + iteration_data['Flows'] = flow_number + iteration_data['Size'] = size + iteration_data['RequestedSpeed'] = RapidTest.get_pps( + iteration_data['speed'] ,size) + result_details = self.post_data(iteration_data) + RapidLog.debug(result_details) + RapidLog.info('+' + '-' * 8 + '+' + '-' * 18 + '+' + '-' * 13 + + '+' + '-' * 13 + '+' + '-' * 13 + '+' + '-' * 24 + '+' + + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 10 + '+' + '-' * 11 + + '+' + '-' * 11 + '+' + '-' * 11 + '+' + '-' * 11 + '+' + + '-' * 7 + '+' + '-' * 4 + '+') self.gen_machine.stop_latency_cores() - return (True) + return (True, result_details) |