From 0990709b07970d8fb326f22248679b250c19ea09 Mon Sep 17 00:00:00 2001 From: shivamcandela Date: Tue, 22 Sep 2020 20:16:22 +0530 Subject: [PATCH] LF DUT VAP and Stations L3 CX TEST With Graph Plotting --- py-scripts/lf_dut_sta_vap_test.py | 205 ++++++++++++++++++------------ 1 file changed, 121 insertions(+), 84 deletions(-) diff --git a/py-scripts/lf_dut_sta_vap_test.py b/py-scripts/lf_dut_sta_vap_test.py index 79cba8cc..2a0fba88 100644 --- a/py-scripts/lf_dut_sta_vap_test.py +++ b/py-scripts/lf_dut_sta_vap_test.py @@ -6,10 +6,15 @@ 3. Login_DUT : This class is specifically used to test the Linux based DUT that has SSH Server. It is used to read the CPU Core temperature during testing In this example, Another Lanforge is used as DUT It also have a function : GenerateReport that generates the report in xlsx format as well as it plots the Graph of throughput over time with temperature + It also have Plot function that generates a html page that contains the plot + Prerequisite Installation + pip install paramiko + pip install bokeh + pip install XlsxWriter Example - .\lf_dut_sta_vap_test.py --lf_host 192.168.200.15 --dut_host 192.168.200.18 --dut_radio wiphy1 --lf_radio wiphy1 --num_sta 1 --sta_id 1 --lf_ssid lanforge_ap --dut_ssid lexusap --security open --dut_upstream eth2 --lf_upstream eth1 --protocol lf_udp --min_bps 1000 --max_bps 10000 --time 1 + .\Lexus_Final.py --lf_host 192.168.200.15 --dut_host 192.168.200.18 --dut_radio wiphy1 --lf_radio wiphy1 --num_sta 1 --sta_id 1 --lf_ssid lanforge_ap --dut_ssid lexusap --security open --dut_upstream eth2 --lf_upstream eth1 --protocol lf_udp --min_bps 1000 --max_bps 10000 --time 1 This Script is intended to automate the testing of DUT That has stations as well as AP. To automate the simultaenous testing and check the DUT Temperature ''' @@ -21,7 +26,7 @@ if sys.version_info[0] != 3: if 'py-json' not in sys.path: sys.path.append('../py-json') -import pexpect + import argparse import time from LANforge import LFUtils @@ -29,9 +34,10 @@ from LANforge import lfcli_base from LANforge.lfcli_base import LFCliBase from LANforge.LFUtils import * import realm -from realm import VRProfile + from realm import Realm import logging + import paramiko as pm from paramiko.ssh_exception import NoValidConnectionsError as exception import xlsxwriter @@ -39,10 +45,10 @@ from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.models import LinearAxis, Range1d from bokeh.models import HoverTool +from bokeh.layouts import row - - +# Specifically for Measuring CPU Core Temperatures class Login_DUT: def __init__(self, threadID, name, HOST): @@ -62,7 +68,7 @@ class Login_DUT: stdin, stdout, stderr= self.CLIENT.exec_command("sensors") out_lines = stdout.readlines() err_lines = stderr.readlines() - print(out_lines[len(out_lines)-3],out_lines[len(out_lines)-2]) + print(out_lines[len(out_lines)-3], out_lines[len(out_lines)-2]) self.data_core1.append(out_lines[len(out_lines)-3]) self.data_core2.append(out_lines[len(out_lines)-2]) @@ -87,10 +93,10 @@ class LoadScenario(LFCliBase): print("Scenario Loaded...") time.sleep(2) - +# Class to create stations and run L3 Cross connects and run them for given time. It also stores the endpoint names for measuring throughput class CreateSTA_CX(LFCliBase): - def __init__(self, host, port, radio, num_sta, sta_id, ssid, security, password, upstream, protocol, min_bps, max_bps, security_debug_on=True, _exit_on_error=True,_exit_on_fail=True): + def __init__(self, host, port, radio, num_sta, sta_id, ssid, security, password, upstream, protocol, min_bps, max_bps, security_debug_on=True, _exit_on_error=True, _exit_on_fail=True): super().__init__(host, port, _debug=security_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail) self.host = host @@ -127,6 +133,7 @@ class CreateSTA_CX(LFCliBase): self.sta_list.append("sta00") #portDhcpUpRequest + ''' upstream_dhcp = LFRequest.LFRequest("http://"+str(host)+":"+str(port)+"/"+"/cli-form/set_port") upstream_dhcp.addPostData( LFUtils.portSetDhcpDownRequest(1, upstream)) upstream_dhcp.formPost() @@ -134,13 +141,13 @@ class CreateSTA_CX(LFCliBase): upstream_dhcp.addPostData( LFUtils.portUpRequest(1, upstream)) upstream_dhcp.formPost() print(upstream + "Set to DHCP For Cross Connects") - + ''' def build(self): #Creating Stations of Given Profile Settings self.station_profile.use_security(self.security, self.ssid, passwd=self.password) - self.station_profile.create(self.radio,num_stations=self.num_sta, sta_names_=self.sta_list) + self.station_profile.create(self.radio, num_stations=self.num_sta, sta_names_=self.sta_list) self.station_profile.admin_up() #Wait for a while time.sleep(15) @@ -161,13 +168,13 @@ class CreateSTA_CX(LFCliBase): self.cx_profile.create(self.protocol, side_a="1.1."+self.upstream, side_b=list(self.local_realm.find_ports_like("sta0+"))) time.sleep(15) - + # Getting all the Endpoint Names for measuring Throughput Later for i in self.cx_profile.get_cx_names(): self.cx_names.append(i) for j in self.cx_names: x=self.local_realm.json_get("/cx/"+j) - self.endp.append(x.get(j).get('endpoints')[1]) - + self.endp.append(x.get(j).get('endpoints')[0]) + #print(self.endp) return 0 @@ -206,78 +213,92 @@ class CreateSTA_CX(LFCliBase): print("Ports Successfully Cleaned up") time.sleep(5) return 0 - -def GenerateReport(throughput, core1_temp, core2_temp): - workbook = xlsxwriter.Workbook('demo.xlsx') + + +# Generates XLSX Report +def GenerateReport(throughput_sta, throughput_vap, core1_temp, core2_temp, duration,name): + workbook = xlsxwriter.Workbook(name) worksheet = workbook.add_worksheet() - worksheet.write('A1', 'THROUGHPUT OVER TIME ') - worksheet.write('B1', 'CORE 0 TEMP') - worksheet.write('C1', 'CORE 1 TEMP') + worksheet.write('A1', 'THROUGHPUT OVER TIME STA CX ') + worksheet.write('B1', 'THROUGHPUT OVER TIME VAP ') + worksheet.write('C1', 'CORE 0 TEMP') + worksheet.write('D1', 'CORE 1 TEMP') core1=[] core2=[] + sta_throu=[] + vap_throu=[] j=2 - for i in throughput: - worksheet.write('A'+str(j), str(i/1000000)+" MBPS") + for i in throughput_sta: + sta_throu.append(i/1000000) + worksheet.write('A'+str(j), str(i/1000000)+" Mbps") + j=j+1 + j=2 + for i in throughput_vap: + vap_throu.append(i/1000000) + worksheet.write('B'+str(j), str(i/1000000)+" Mbps") j=j+1 j=2 for i in core1_temp: core1.append(int(str(i).split(':')[1].split('(')[0].split('.')[0].split('+')[1])) - worksheet.write('B'+str(j),str(i).split(':')[1].split('(')[0] ) + worksheet.write('C'+str(j),str(i).split(':')[1].split('(')[0] ) j=j+1 j=2 for i in core2_temp: core2.append(int(str(i).split(':')[1].split('(')[0].split('.')[0].split('+')[1])) - worksheet.write('C'+str(j), str(i).split(':')[1].split('(')[0]) + worksheet.write('D'+str(j), str(i).split(':')[1].split('(')[0]) j=j+1 + + Time =[] + for i in range(0,int(duration)*5): + Time.append(i) + plot(sta_throu, vap_throu, core1, core2, Time) workbook.close() - x=[] - for i in range(0,5*len(throughput)): - x.append(i) - ''' - y = throughput +# Plotting Function for Parameters +def plot(throughput_sta, throughput_vap, core1_temp, core2_temp, Time): + - TOOLTIPS = [ - ("index", "$index"), - ("(Throughput,Time)", "($y, $x)"), - - ] + s1 = figure() + s1.title.text = "WIFI Throughput vs Temperature Plot" + s1.xaxis.axis_label = "Time in Seconds" + s1.yaxis.axis_label = "Throughput in Mbps" - s1 = figure(y_range = (0,15000),tooltips = TOOLTIPS) - - s1.line(y, x, color='#f45666') - s1.circle(y, x, color='pink') - + s1.line( Time, throughput_sta, color='black') + s1.circle(Time, throughput_sta, color='red') - s1.extra_y_ranges = {"NumStations":} + s1.line( Time, throughput_vap, color='orange') + s1.circle(Time, throughput_vap, color='blue') + + s1.extra_y_ranges = {"Temperature": Range1d(start=0, end=150)} + s1.add_layout(LinearAxis(y_range_name="Temperature", axis_label="Temperature in Degree Celsius"), 'right') + + s1.line(Time, core1_temp, y_range_name='Temperature', color='black') + s1.circle(Time, core1_temp, y_range_name='Temperature', color='red') - s1.add_layout(LinearAxis(y_range_name="NumStations"), 'right') - s1.line(core1,x, y_range_name='NumStations', color='blue') - s1.circle(core1, x, y_range_name='NumStations', color='black') + s1.line(Time, core2_temp, y_range_name='Temperature', color='green') + s1.circle(Time, core2_temp, y_range_name='Temperature', color='blue') - s1.line(core2,x, y_range_name='NumStations', color='blue') - s1.circle(core2, x, y_range_name='NumStations', color='black') show(s1) - ''' - - - + + +# Creates the Instance for LFCliBase +class VAP_Measure(LFCliBase): + def __init__(self, lfclient_host, lfclient_port): + super().__init__(lfclient_host, lfclient_port) +# main method def main(): - parser = argparse.ArgumentParser(description="Test Scenario of DUT Temperature measurement along with simultaneous throughput") + parser = argparse.ArgumentParser(description="Test Scenario of DUT Temperature measurement along with simultaneous throughput on VAP as well as stations") parser.add_argument("-m", "--lf_host", type=str, help="Enter the address of LF which will test the DUT") parser.add_argument("-d", "--dut_host", type=str, help="Enter the address of LF Which is to be dut") - parser.add_argument("-lr", "--lf_radio", type=str, help="Enter the radio on which you want to create a station/s on (Lanforge Side)") parser.add_argument("-dr", "--dut_radio", type=str, help="Enter the radio on which you want to create a station/s on (DUT Side)") - parser.add_argument("-n", "--num_sta", type=int, help="Enter the Number of Stations You want to create") - parser.add_argument("-st", "--sta_id", type=int, help="Enter Station id [for sta001, enter 1]") parser.add_argument("-ls", "--lf_ssid", type=str, help="Enter the ssid, with which you want to associate your stations (Enter the SSID of VAP in Lanforge)") @@ -289,7 +310,8 @@ def main(): parser.add_argument("-pr", "--protocol", type=str, help="Enter the protocol on which you want to run your connections [lf_udp, lf_tcp]") parser.add_argument("-minb", "--min_bps", type=str, help="Enter the Minimum Rate") parser.add_argument("-maxb", "--max_bps", type=str, help="Enter the Maximum Rate") - parser.add_argument("-t", "--time", type=int, help="Enter the Time for which you want to run test (In Minutes)") + parser.add_argument("-t", "--duration", type=int, help="Enter the Time for which you want to run test (In Minutes)") + parser.add_argument("-r", "--report_name", type=str, help="Enter the Name of the Output file ('Report.xlsx')") args = None @@ -329,55 +351,70 @@ def main(): max_bps = int(args.max_bps)*1000000 if (args.max_bps is not None and args.max_bps is "same"): max_bps = args.min_bps - if (args.time is not None): - tme = (args.time * 60)/5 + if (args.duration is not None): + duration = (args.duration * 60)/5 + if (args.report_name is not None): + report_name = args.report_name except Exception as e: logging.exception(e) exit(2) - DB_Lanforge_1 = "AUTO_CV-2020-09-18-07-41-19" + DB_Lanforge_1 = "Lexus_DUT" #Loading the Scenario on Lanforge_1 (Here Considered as DUT) [Created VAP With SSID 'lexusap' on wiphy0 with eth1 as backhaul] - Scenario_1 = LoadScenario(dut_host,8080,DB_Lanforge_1) + Scenario_1 = LoadScenario(dut_host, 8080, DB_Lanforge_1) - DB_Lanforge_2 = "AUTO_CV-2020-09-18-08-00-36" + DB_Lanforge_2 = "LANforge_TEST" #Loading the Scenario on Lanforge_2 (Here Considered as LANFORGE Test) [Created VAP With SSID 'lanforge_ap' on wiphy0 with eth2 as backhaul] - Scenario_2 = LoadScenario(lf_host,8080,DB_Lanforge_2) + Scenario_2 = LoadScenario(lf_host, 8080, DB_Lanforge_2) + # Object to Measure the Traffic at VAP + vap_measure_obj = VAP_Measure(lf_host, 8080) + + + + + #Create Station and cross connects on Lanforge_1 that connects on VAP on Lanforge_2 - DUT = CreateSTA_CX(dut_host,8080,dut_radio,num_sta, sta_id, lf_ssid, security, password, dut_upstream, protocol, min_bps, max_bps) - #DUT.cleanup() - DUT.build() - DUT.start() - + dut_traffic_profile = CreateSTA_CX(dut_host, 8080, dut_radio, num_sta, sta_id, lf_ssid, security, password, dut_upstream, protocol, min_bps, max_bps) + dut_traffic_profile.build() + + #Create Station and cross connects on Lanforge_2 that connects on VAP on Lanforge_1 (lexus_ap) - LF = CreateSTA_CX(lf_host,8080,lf_radio,num_sta, sta_id, dut_ssid, security, password, lf_upstream, protocol, min_bps, max_bps) - #LF.cleanup() - LF.build() - LF.start() + lf_traffic_profile = CreateSTA_CX(lf_host, 8080, lf_radio, num_sta, sta_id, dut_ssid, security, password, lf_upstream, protocol, min_bps, max_bps) + lf_traffic_profile.build() + + # Starting Running Traffic + lf_traffic_profile.start() + dut_traffic_profile.start() + + print("Collecting Throughput Values...") - a = Login_DUT(1, "Thread-1", dut_host) + dut_temp_obj = Login_DUT(1, "Thread-1", dut_host) time.sleep(10) - - csv_data =[] - for i in range(0,int(tme)): + + #List for Storing the Total Throughput + throughput_sta =[] + throughput_vap =[] + + # This loop will get the Data from All the endpoints and sum up to give total Throughput over time + for i in range(0,int(duration)): temp=0 - for j in LF.endp: - x=LF.local_realm.json_get("/endp/"+j).get('endpoint').get('rx rate') - temp=temp+x - for j in DUT.endp: - y=DUT.local_realm.json_get("/endp/"+j).get('endpoint').get('rx rate') + for j in lf_traffic_profile.endp: + y=lf_traffic_profile.local_realm.json_get("/endp/"+j).get('endpoint').get('rx rate') temp=temp+y - csv_data.append(temp) - a.run() - print(temp) + throughput_sta.append(temp) + throughput_vap.append(vap_measure_obj.json_get("/port/1/1/vap0000/").get('interface').get('bps rx')) + dut_temp_obj.run() + print("Throughput Stations side: ", throughput_sta) + print("\nThroughput VAP side: ", throughput_vap) time.sleep(5) - print(csv_data) - DUT.cleanup() - LF.cleanup() - GenerateReport(csv_data,a.data_core1,a.data_core2) + print(throughput_sta) + dut_traffic_profile.cleanup() + lf_traffic_profile.cleanup() + GenerateReport(throughput_sta, throughput_vap, dut_temp_obj.data_core1, dut_temp_obj.data_core2, duration)