Removed latest code and added older code(wlan-lanforge-scripts code)

Signed-off-by: jitendracandela <jitendra.kushavah@candelatech.com>
This commit is contained in:
jitendracandela
2022-09-14 16:40:32 +05:30
parent 75232eec8e
commit 15a71d3dfe

View File

@@ -27,9 +27,7 @@ import sys
import os
import importlib
import argparse
import logging
import time
import csv
import datetime
if sys.version_info[0] != 3:
print("This script requires Python 3")
@@ -42,13 +40,6 @@ realm = importlib.import_module("py-json.realm")
Realm = realm.Realm
InfluxRequest = importlib.import_module('py-dashboard.InfluxRequest')
RecordInflux = InfluxRequest.RecordInflux
lf_logger_config = importlib.import_module("py-scripts.lf_logger_config")
lf_report = importlib.import_module("py-scripts.lf_report")
lf_graph = importlib.import_module("py-scripts.lf_graph")
lf_kpi_csv = importlib.import_module("py-scripts.lf_kpi_csv")
logger = logging.getLogger(__name__)
class IPVariableTime(Realm):
@@ -60,12 +51,12 @@ class IPVariableTime(Realm):
use_existing_sta=False,
name_prefix=None,
upstream=None,
upstream_resource=1,
radio=None,
host="localhost",
port=8080,
mode=0,
ap=None,
no_cleanup=None,
traffic_type=None,
side_a_min_rate=256000, side_a_max_rate=0,
side_b_min_rate=256000, side_b_max_rate=0,
@@ -77,9 +68,6 @@ class IPVariableTime(Realm):
layer3_cols=None,
port_mgr_cols=None,
monitor_interval='10s',
kpi_csv=None,
kpi_path=None,
outfile=None,
influx_host=None,
influx_port=None,
influx_org=None,
@@ -109,12 +97,11 @@ class IPVariableTime(Realm):
self.radio = radio
self.mode = mode
self.ap = ap
self.no_cleanup = no_cleanup
self.traffic_type = traffic_type
self.side_a_min_rate = side_a_min_rate
self.side_b_min_rate = side_b_min_rate
self.number_template = number_template
self.debug = _debug_on
self.timeout_sec = 60
self.upstream_resource = upstream_resource
# self.json_post("/cli-json/set_resource", {
# "shelf":1,
# "resource":all,
@@ -133,7 +120,7 @@ class IPVariableTime(Realm):
self.station_profile.use_ht160 = use_ht160
if self.station_profile.use_ht160:
self.station_profile.mode = 9
# self.station_profile.mode = mode
self.station_profile.mode = mode
if self.ap:
self.station_profile.set_command_param("add_sta", "ap", self.ap)
if self.use_existing_sta:
@@ -150,10 +137,6 @@ class IPVariableTime(Realm):
self.layer3_cols = layer3_cols
self.port_mgr_cols = port_mgr_cols
self.monitor_interval = monitor_interval
self.outfile = outfile
self.kpi_csv = kpi_csv
self.kpi_path = kpi_path
self.epoch_time = int(time.time())
self.influx_host = influx_host
self.influx_port = influx_port
self.influx_org = influx_org
@@ -166,127 +149,6 @@ class IPVariableTime(Realm):
self.cx_profile.side_a_max_bps = side_a_max_rate
self.cx_profile.side_b_min_bps = side_b_min_rate
self.cx_profile.side_b_max_bps = side_b_max_rate
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
if self.outfile is not None:
results = self.outfile[:-4]
results = results + "-results.csv"
self.csv_results_file = open(results, "w")
self.csv_results_writer = csv.writer(self.csv_results_file, delimiter=",")
def get_kpi_results(self):
# make json call to get kpi results
endp_list = self.json_get(
"endp?fields=name,eid,delay,jitter,rx+rate,rx+rate+ll,rx+bytes,rx+drop+%25,rx+pkts+ll",
debug_=False)
logger.info("endp_list: {endp_list}".format(endp_list=endp_list))
def get_csv_name(self):
logger.info("self.csv_results_file {}".format(self.csv_results_file.name))
return self.csv_results_file.name
# Query all endpoints to generate rx and other stats, returned
# as an array of objects.
def get_rx_values(self):
endp_list = self.json_get(
"endp?fields=name,eid,delay,jitter,rx+rate,rx+rate+ll,rx+bytes,rx+drop+%25,rx+pkts+ll",
debug_=True)
# logger.info("endp_list: {endp_list}".format(endp_list=endp_list))
endp_rx_drop_map = {}
endp_rx_map = {}
endps = []
total_ul = 0
total_ul_ll = 0
total_dl = 0
total_dl_ll = 0
udp_dl = 0
tcp_dl = 0
udp_ul = 0
tcp_ul = 0
'''
for e in self.cx_profile.created_endp.keys():
our_endps[e] = e
print("our_endps {our_endps}".format(our_endps=our_endps))
'''
for endp_name in endp_list['endpoint']:
if endp_name != 'uri' and endp_name != 'handler':
for item, endp_value in endp_name.items():
# if item in our_endps:
if True:
endps.append(endp_value)
logger.debug("endpoint: {item} value:\n".format(item=item))
# logger.debug(endp_value)
# logger.info("item {item}".format(item=item))
for value_name, value in endp_value.items():
if value_name == 'rx bytes':
endp_rx_map[item] = value
logger.info("rx_rate {value}".format(value=value))
if value_name == 'rx rate':
endp_rx_map[item] = value
logger.info("rx_rate {value}".format(value=value))
if value_name == 'rx rate ll':
endp_rx_map[item] = value
logger.info("rx_rate_ll {value}".format(value=value))
if value_name == 'rx pkts ll':
endp_rx_map[item] = value
if value_name == 'rx drop %':
endp_rx_drop_map[item] = value
if value_name == 'rx rate':
# This hack breaks for mcast or if someone names endpoints weirdly.
# logger.info("item: ", item, " rx-bps: ", value_rx_bps)
# info for upload test data
logger.info(self.traffic_type)
if self.traffic_type.endswith("udp") and item.endswith("0-A"):
udp_ul += int(value)
# logger.info(udp_ul)
elif self.traffic_type.endswith("udp") and item.endswith("1-A"):
udp_ul += int(value)
# logger.info(udp_ul)
elif self.traffic_type.endswith("tcp") and item.endswith("0-A"):
tcp_ul += int(value)
# logger.info(total_ul)
elif self.traffic_type.endswith("tcp") and item.endswith("1-A"):
tcp_ul += int(value)
# logger.info(total_ul)
# info for download test data
if self.traffic_type.endswith("udp") and item.endswith("0-B"):
udp_dl += int(value)
# logger.info(udp_dl)
elif self.traffic_type.endswith("udp") and item.endswith("1-B"):
udp_dl += int(value)
# logger.info(udp_dl)
elif self.traffic_type.endswith("tcp") and item.endswith("0-B"):
tcp_dl += int(value)
# logger.info(tcp_dl)
elif self.traffic_type.endswith("tcp") and item.endswith("1-B"):
tcp_dl += int(value)
# logger.info(tcp_dl)
# combine total download (tcp&udp) and upload (tcp&udp) test data
if item.endswith("-A"):
total_ul += int(value)
# logger.info(total_dl)
else:
total_dl += int(value)
# logger.info(total_ul)
if value_name == 'rx rate ll':
# This hack breaks for mcast or if someone
# names endpoints weirdly.
if item.endswith("-A"):
total_ul_ll += int(value)
else:
total_dl_ll += int(value)
# logger.debug("total-dl: ", total_dl, " total-ul: ", total_ul, "\n")
return endp_rx_map, endp_rx_drop_map, endps, udp_dl, tcp_dl, udp_ul, tcp_ul, total_dl, total_ul, total_dl_ll, total_ul_ll
# Common code to generate timestamp for CSV files.
def time_stamp(self):
return time.strftime('%m_%d_%Y_%H_%M_%S', time.localtime(self.epoch_time))
def set_wifi_radio(self, country=0, resource=1, mode="NA", radio="wiphy6", channel=5):
data = {
@@ -304,14 +166,13 @@ class IPVariableTime(Realm):
# if self.use_existing_station:
# to-do- check here if upstream port got IP
self.station_profile.admin_up()
self.csv_add_column_headers()
temp_stas = self.station_profile.station_names.copy()
# logger.info("temp_stas {temp_stas}".format(temp_stas=temp_stas))
if self.wait_for_ip(temp_stas, ipv4=not self.ipv6, ipv6=self.ipv6, debug=self.debug):
print("temp_stas {temp_stas}".format(temp_stas=temp_stas))
if self.wait_for_ip(temp_stas, ipv4=not self.ipv6, ipv6=self.ipv6, timeout_sec=self.timeout_sec):
self._pass("All stations got IPs")
else:
self._fail("Stations failed to get IPs")
self.exit_fail()
#self.exit_fail()
self.cx_profile.start_cx()
def stop(self):
@@ -322,9 +183,8 @@ class IPVariableTime(Realm):
self.cx_profile.cleanup_prefix()
# do not clean up station if existed prior to test
if not self.use_existing_sta:
for sta_list in self.sta_list:
for sta in sta_list:
self.rm_port(sta, check_exists=True, debug_=self.debug)
for sta in self.sta_list:
self.rm_port(sta, check_exists=True, debug_=False)
def cleanup(self):
self.cx_profile.cleanup()
@@ -334,65 +194,45 @@ class IPVariableTime(Realm):
debug=self.debug)
def build(self):
for i in range(len(self.upstream)):
if self.use_existing_sta:
self.sta_list[i] = [self.sta_list[i]]
logger.info("Use Existing Stations: {sta_list}".format(sta_list=self.sta_list))
self.station_profile.station_names = self.sta_list[i]
self.station_profile.use_security(self.security, self.ssid, self.password)
self.station_profile.set_number_template(self.number_template)
# print("sta_list {}".format(self.sta_list))
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
self.station_profile.set_command_param("set_port", "report_timer", 1500)
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
else:
self.station_profile.use_security(self.security[i], self.ssid[i], self.password[i])
self.station_profile.set_number_template(self.number_template)
logger.info("sta_list {}".format(self.sta_list))
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
self.station_profile.set_command_param("set_port", "report_timer", 1500)
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
logger.info("Creating stations")
try:
self.station_profile.mode = self.mode[i]
except Exception as e:
self.station_profile.mode = 0
self.station_profile.create(radio=self.radio[i], sta_names_=self.sta_list[i], debug=self.debug)
self._pass("PASS: Station build finished")
self.cx_profile.create(endp_type=self.traffic_type, side_a=self.sta_list[i],
side_b=self.upstream[i],
sleep_time=0)
if self.use_existing_sta:
print("Use Existing Stations: {sta_list}".format(sta_list=self.sta_list))
else:
print("Creating stations")
self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug)
self._pass("PASS: Station build finished")
self.cx_profile.create(endp_type=self.traffic_type, side_a=self.sta_list,
side_b="%d.%s" % (int(self.upstream_resource), self.upstream),
sleep_time=0)
def run(self):
if self.report_file is None:
# new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':','-') + '_test_ip_variable_time'
# create path name
new_file_path = self.kpi_path
# new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':','-') + \
# '_test_ip_variable_time' # create path name
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':',
'-') + '_test_ip_variable_time' # create path name
if os.path.exists('/home/lanforge/report-data'):
path = os.path.join('/home/lanforge/report-data/', new_file_path)
if os.path.exists(path):
pass
else:
os.mkdir(path)
os.mkdir(path)
else:
logger.info(new_file_path)
# curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# curr_dir_path += '/py-scripts'
# path = os.path.join(curr_dir_path, new_file_path)
# os.mkdir(path)
# systeminfopath = str(path) + '/systeminfo.txt'
systeminfopath = str(new_file_path) + '/systeminfo.txt'
curr_dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
path = os.path.join(curr_dir_path, new_file_path)
os.mkdir(path)
systeminfopath = str(path) + '/systeminfo.txt'
if self.output_format in ['csv', 'json', 'html', 'hdf', 'stata', 'pickle', 'pdf', 'png', 'parquet',
'xlsx']:
# report_f = str(path) + '/data.' + self.output_format
report_f = str(new_file_path) + '/data.' + self.output_format
report_f = str(path) + '/data.' + self.output_format
output = self.output_format
else:
logger.info(
print(
'Not supporting this report format or cannot find report format provided. Defaulting to csv data file '
'output type, naming it data.csv.')
# report_f = str(path) + '/data.csv'
report_f = str(new_file_path) + '/data.csv'
report_f = str(path) + '/data.csv'
output = 'csv'
else:
systeminfopath = str(self.report_file).split('/')[-1]
@@ -408,7 +248,7 @@ class IPVariableTime(Realm):
# CMR What is this code doing
if not self.use_existing_sta:
if not self.passes():
logger.error(self.get_fail_message())
print(self.get_fail_message())
self.exit_fail()
try:
@@ -429,17 +269,15 @@ class IPVariableTime(Realm):
port_mgr_cols = self.port_mgr_cols
# send col names here to file to reformat
if self.debug:
logger.debug("Layer 3 Endp column names are...")
logger.debug(layer3_cols)
logger.debug("Port Manager column names are...")
logger.debug(port_mgr_cols)
print("Layer 3 Endp column names are...")
print(layer3_cols)
print("Port Manager column names are...")
print(port_mgr_cols)
try:
monitor_interval = Realm.parse_time(self.monitor_interval).total_seconds()
except ValueError as error:
logger.critical(error)
logger.critical(
"The time string provided for monitor_interval argument is invalid. Please see supported time stamp increments and inputs for monitor_interval in --help. ")
print(error)
return ValueError(
"The time string provided for monitor_interval argument is invalid. Please see supported time stamp increments and inputs for monitor_interval in --help. ")
self.start()
@@ -467,284 +305,40 @@ class IPVariableTime(Realm):
compared_report_format = self.compared_report.split('.')[-1]
# if compared_report_format not in ['csv', 'json', 'dta', 'pkl','html','xlsx','parquet','h5']:
if compared_report_format != 'csv':
logger.critical("Cannot process this file type. Please select a different file and re-run script.")
raise ValueError("Cannot process this file type. Please select a different file and re-run script.")
else:
compared_rept = self.compared_report
# remove endpoints from layer3connections that do not begin with 'VT' prefix:
logger.info(layer3connections)
# convert layer3connections to list:
split_l3_endps = layer3connections.split(",")
# logger.info(split_l3_endps)
new_l3_endps_list = []
for item in split_l3_endps:
if item.startswith('VT'):
new_l3_endps_list.append(item)
# logger.info(new_l3_endps_list)
# convert new_l3_endps_list to str:
layer3endps = ','.join(str(l3endps) for l3endps in new_l3_endps_list)
# logger.info(layer3endps)
# for i in range(len(self.upstream)):
comp_sta_list = []
list(map(comp_sta_list.extend,self.sta_list))
self.cx_profile.monitor(layer3_cols=layer3_cols,
sta_list=comp_sta_list,
sta_list=self.sta_list,
port_mgr_cols=port_mgr_cols,
report_file=report_f,
systeminfopath=systeminfopath,
duration_sec=self.test_duration,
monitor_interval_ms=monitor_interval,
created_cx=layer3endps,
created_cx=layer3connections,
output_format=output,
compared_report=compared_rept,
script_name='test_ip_variable_time',
debug=self.debug)
# fill out data kpi.csv and results reports
temp_stations_list = []
temp_stations_list.extend(self.station_profile.station_names.copy())
total_test = len(self.get_result_list())
total_pass = len(self.get_passed_result_list())
endp_rx_map, endp_rx_drop_map, endps, udp_dl, tcp_dl, udp_ul, tcp_ul, total_dl, total_ul, total_dl_ll, total_ul_ll = self.get_rx_values()
self.record_kpi_csv(temp_stations_list, total_test, total_pass, udp_dl, tcp_dl, udp_ul, tcp_ul, total_dl, total_ul)
self.record_results(len(temp_stations_list), udp_dl, tcp_dl, udp_ul, tcp_ul, total_dl, total_ul)
self.stop()
if not self.use_existing_sta:
if not self.passes():
logger.info(self.get_fail_message())
print(self.get_fail_message())
self.exit_fail()
if self.passes():
self.success()
logger.info(report_f)
logger.info(compared_rept)
logger.info(port_mgr_cols)
logger.info(output)
if not self.no_cleanup:
self.cleanup()
logger.info("Leaving existing stations...")
logger.info("IP Variable Time Test Report Data: {}".format(report_f))
# builds test data into kpi.csv report
def record_kpi_csv(
self,
tmp_sta_list,
total_test,
total_pass,
udp_dl,
tcp_dl,
udp_ul,
tcp_ul,
total_dl,
total_ul):
'''
logger.debug(
"NOTE: Adding kpi to kpi.csv, sta_count {sta_list} total-download-bps:{total_dl} upload: {total_ul} bi-directional: {total}\n".format(
sta_list=sta_list, total_dl=total_dl, total_ul=total_ul,
total=(total_ul + total_dl)))
logger.debug(
"NOTE: Adding kpi to kpi.csv, sta_count {sta_list} total-download-bps:{total_dl_ll_bps} upload: {total_ul_ll_bps}
bi-directional: {total_ll}\n".format(sta_list=sta_list, total_dl_ll_bps=total_dl_ll_bps, total_ul_ll_bps=total_ul_ll_bps,
total_ll=(total_ul_ll_bps + total_dl_ll_bps)))
'''
# the short description will allow for more data to show up in one test-tag graph
sta_list = len(tmp_sta_list)
# logic for Subtest-Pass & Subtest-Fail columns
subpass_udp_dl = 0
subpass_udp_ul = 0
subpass_tcp_dl = 0
subpass_tcp_ul = 0
subfail_udp_dl = 1
subfail_udp_ul = 1
subfail_tcp_dl = 1
subfail_tcp_ul = 1
if udp_dl > 0:
subpass_udp_dl = 1
subfail_udp_dl = 0
if udp_ul > 0:
subpass_udp_ul = 1
subfail_udp_ul = 0
if tcp_dl > 0:
subpass_tcp_dl = 1
subfail_tcp_dl = 0
if tcp_ul > 0:
subpass_tcp_ul = 1
subfail_tcp_ul = 0
# logic for pass/fail column
# total_test & total_pass values from lfcli_base.py
if total_test == total_pass:
pass_fail = "PASS"
else:
pass_fail = "FAIL"
# mode = []
for stas in tmp_sta_list:
# logger.info(stas)
entity_id = self.local_realm.name_to_eid(stas)
# entity_id[0]=shelf, entity_id[1]=resource, entity_id[2]=port
# logger.info(entity_id)
resource_val = str(entity_id[1])
sta_data = self.json_get("port/1/" + resource_val + "/" + entity_id[2], debug_=True)
# logger.info("sta_data: {sta_data}".format(sta_data=sta_data))
# get the wifi 802.11 mode from sta_data:
mode = sta_data['interface']['mode']
# logger.info(mode)
'''
for sta_info in sta_data['interface']:
logger.info(sta_info)
if sta_info == 'mode':
mode = sta_data['interface'][sta_info]
logger.info(mode)
'''
# logger.info("mode: {mode}".format(mode=mode))
# kpi data for TCP download traffic
if self.traffic_type.endswith("tcp"):
results_dict = self.kpi_csv.kpi_csv_get_dict_update_time()
results_dict['Graph-Group'] = "TCP Download Rate"
results_dict['pass/fail'] = pass_fail
results_dict['Subtest-Pass'] = subpass_tcp_dl
results_dict['Subtest-Fail'] = subfail_tcp_dl
results_dict['short-description'] = "Mode {mode} TCP-DL {side_a_min_rate} bps {sta_list} STA".format(mode=mode, side_a_min_rate=self.side_a_min_rate, sta_list=sta_list)
results_dict['numeric-score'] = "{}".format(total_dl)
results_dict['Units'] = "bps"
self.kpi_csv.kpi_csv_write_dict(results_dict)
# kpi data for TCP upload traffic
results_dict['Graph-Group'] = "TCP Upload Rate"
results_dict['pass/fail'] = pass_fail
results_dict['Subtest-Pass'] = subpass_tcp_ul
results_dict['Subtest-Fail'] = subfail_tcp_ul
results_dict['short-description'] = "Mode {mode} TCP-UL {side_a_min_rate} bps {sta_list} STA".format(mode=mode, side_a_min_rate=self.side_a_min_rate, sta_list=sta_list)
results_dict['numeric-score'] = "{}".format(total_ul)
results_dict['Units'] = "bps"
self.kpi_csv.kpi_csv_write_dict(results_dict)
# kpi data for UDP download traffic
elif self.traffic_type.endswith("udp"):
results_dict = self.kpi_csv.kpi_csv_get_dict_update_time()
results_dict['Graph-Group'] = "UDP Download Rate"
results_dict['pass/fail'] = pass_fail
results_dict['Subtest-Pass'] = subpass_udp_dl
results_dict['Subtest-Fail'] = subfail_udp_dl
results_dict['short-description'] = "Mode {mode} UDP-DL {side_a_min_rate} bps {sta_list} STA".format(mode=mode, side_a_min_rate=self.side_a_min_rate, sta_list=sta_list)
results_dict['numeric-score'] = "{}".format(total_dl)
results_dict['Units'] = "bps"
self.kpi_csv.kpi_csv_write_dict(results_dict)
# kpi data for UDP upload traffic
results_dict['Graph-Group'] = "UDP Upload Rate"
results_dict['pass/fail'] = pass_fail
results_dict['Subtest-Pass'] = subpass_udp_ul
results_dict['Subtest-Fail'] = subfail_udp_ul
results_dict['short-description'] = "Mode {mode} UDP-UL {side_a_min_rate} bps {sta_list} STA".format(mode=mode, side_a_min_rate=self.side_a_min_rate, sta_list=sta_list)
results_dict['numeric-score'] = "{}".format(total_ul)
results_dict['Units'] = "bps"
self.kpi_csv.kpi_csv_write_dict(results_dict)
# record results for .html & .pdf reports
def record_results(
self,
sta_count,
udp_dl,
tcp_dl,
udp_ul,
tcp_ul,
total_dl_bps,
total_ul_bps):
dl = self.side_a_min_rate
ul = self.side_b_min_rate
tags = dict()
tags['requested-ul-bps'] = ul
tags['requested-dl-bps'] = dl
tags['station-count'] = sta_count
# tags['attenuation'] = atten
tags["script"] = 'test_ip_variable_time'
# now = str(datetime.datetime.utcnow().isoformat())
print(
"NOTE: Adding results to influx, total-download-bps: %s upload: %s bi-directional: %s\n" %
(total_dl_bps, total_ul_bps, (total_ul_bps + total_dl_bps)))
if self.traffic_type.endswith("tcp"):
if self.csv_results_file:
row = [self.epoch_time, self.time_stamp(), sta_count,
ul, ul, dl, dl, tcp_ul, tcp_dl,
total_ul_bps, total_dl_bps, (total_ul_bps + total_dl_bps)
]
self.csv_results_writer.writerow(row)
self.csv_results_file.flush()
elif self.traffic_type.endswith("udp"):
if self.csv_results_file:
row = [self.epoch_time, self.time_stamp(), sta_count,
ul, ul, dl, dl, udp_ul, udp_dl,
total_ul_bps, total_dl_bps, (total_ul_bps + total_dl_bps)
]
self.csv_results_writer.writerow(row)
self.csv_results_file.flush()
def csv_generate_results_column_headers(self):
if self.traffic_type.endswith("tcp"):
csv_rx_headers = [
'Time epoch',
'Time',
'Station-Count',
'UL-Min-Requested',
'UL-Max-Requested',
'DL-Min-Requested',
'DL-Max-Requested',
# 'Attenuation',
'TCP-Upload-bps',
'TCP-Download-bps',
'Total-TCP-Upload-bps',
'Total-TCP-Download-bps',
'Total-TCP-UL/DL-bps']
elif self.traffic_type.endswith("udp"):
csv_rx_headers = [
'Time epoch',
'Time',
'Station-Count',
'UL-Min-Requested',
'UL-Max-Requested',
'DL-Min-Requested',
'DL-Max-Requested',
# 'Attenuation',
'UDP-Upload-bps',
'UDP-Download-bps',
'Total-UDP-Upload-bps',
'Total-UDP-Download-bps',
'Total-UDP-UL/DL-bps']
return csv_rx_headers
# Write initial headers to csv file.
def csv_add_column_headers(self):
if self.csv_results_file is not None:
self.csv_results_writer.writerow(
self.csv_generate_results_column_headers())
self.csv_results_file.flush()
self.cleanup()
print("IP Variable Time Test Report Data: {}".format(report_f))
def main():
# Realm args parser is one directory up then traverse into /py-json/LANforge/lfcli_base.py
# search for create_basic_argsparse
# --mgr --mgr_port --upstream_port --num_stations --radio --security --ssid --passwd
parser = argparse.ArgumentParser(
parser = Realm.create_basic_argparse(
prog='test_ip_variable_time.py',
formatter_class=argparse.RawTextHelpFormatter,
epilog='''\
@@ -780,7 +374,7 @@ python3 ./test_ip_variable_time.py
"bgnAC" : "11",
"abgnAX" : "12",
"bgnAX" : "13"}
--ssid <ssid>
--ssid netgear
--password admin123
--test_duration 2m (default)
--monitor_interval_ms
@@ -959,7 +553,7 @@ python3 ./test_ip_variable_time.py
Example command:
1. Use Existing station , Note: put the shelf.resource.wifi-sta (below is 1.1.wlan4),
1. Use Existing station , Note: put the resource.shelf.wifi-sta (below is 1.1.wlan4),
The station needs to configured with the ssid, passwd, security and mode in the LANforge GUI
./test_ip_variable_time.py --mgr 192.168.0.100 --radio wiphy4 --ssid ssid_5g --passwd pass_5g
--security wpa2 --test_duration 60s --output_format csv --traffic_type lf_tcp
@@ -979,210 +573,63 @@ python3 ./test_ip_variable_time.py
--a_min 600000000 --b_min 600000000 --upstream_port eth2 --mode '5'
--layer3_cols 'name','tx rate','rx rate' --port_mgr_cols 'alias','channel','activity','mode'
--num_stations 2
4. Create Multiple stations and run traffic with different upstream port
./test_ip_variable_time.py --mgr 192.168.200.37 --radio wiphy0 wiphy0 --ssid ssid_2g ssid_5g
--test_duration 60s --output_format csv --traffic_type lf_tcp --a_min 600000000 --b_min 600000000
--upstream_port eth2 eth1 --mode '5' --num_stations 1 --passwd pass_2g pass_5g --security wpa2 wpa2
''')
optional = parser.add_argument_group('optional arguments')
required = parser.add_argument_group('required arguments')
# Realm args parser is one directory up then traverse into /py-json/LANforge/lfcli_base.py
# search for create_basic_argsparse
# --mgr --mgr_port --upstream_port --num_stations --radio --security --ssid --passwd
optional.add_argument('--mgr', '--lfmgr', default='localhost',
help='hostname for where LANforge GUI is running')
optional.add_argument('--mgr_port', '--port', default=8080,
help='port LANforge GUI HTTP service is running on')
optional.add_argument('-u', '--upstream_port', nargs="+", default=['eth1'],
help='non-station port that generates traffic: <resource>.<port>, e.g: --u eth1 eth2')
optional.add_argument('--num_stations', type=int, default=0,
help='Number of stations to create')
optional.add_argument('--test_id',
default="webconsole",
help='Test ID (intended to use for ws events)')
optional.add_argument('-d', '--debug', action="store_true",
help='Enable debugging')
optional.add_argument('--log_level', default=None,
help='Set logging level: debug | info | warning | error | critical')
optional.add_argument('--lf_logger_config_json',
help="--lf_logger_config_json <json file> , json configuration of logger")
optional.add_argument('--proxy', nargs='?', default=None,
help="Connection proxy like http://proxy.localnet:80 \n"
+ " or https://user:pass@proxy.localnet:3128")
optional.add_argument('--debugging', nargs="+", action="append",
help="Indicate what areas you would like express debug output:\n"
+ " - digest - print terse indications of lanforge_api calls\n"
+ " - json - print url and json data\n"
+ " - http - print HTTP headers\n"
+ " - gui - ask the GUI for extra debugging in responses\n"
+ " - method:method_name - enable by_method() debugging (if present)\n"
+ " - tag:tagname - enable matching by_tag() debug output\n"
)
optional.add_argument('--debug_log', default=None,
help="Specify a file to send debug output to")
optional.add_argument('--no_cleanup', help='Do not cleanup before exit', action='store_true')
#-----required---------------
required.add_argument('--radio', nargs="+", help='radio EID, e.g: --radio wiphy0 wiphy2')
required.add_argument('--security', nargs="+", default=["open"],
help='WiFi Security protocol: < open | wep | wpa | wpa2 | wpa3 > e.g: --security open wpa')
required.add_argument('--ssid', nargs="+", help='WiFi SSID for script objects to associate to e.g: --ssid ap1_ssid ap2_ssid')
required.add_argument('--passwd', '--password', '--key', nargs="+", default=["[BLANK]"],
help='WiFi passphrase/password/key e.g: --passwd [BLANK] passwd@123')
optional.add_argument('--mode', nargs="+", help='Used to force mode of stations e.g: --mode 11 9')
optional.add_argument('--ap', nargs="+", help='Used to force a connection to a particular AP')
optional.add_argument('--traffic_type', help='Select the Traffic Type [lf_udp, lf_tcp, udp, tcp], type will be '
parser.add_argument('--mode', help='Used to force mode of stations')
parser.add_argument('--ap', help='Used to force a connection to a particular AP')
parser.add_argument('--traffic_type', help='Select the Traffic Type [lf_udp, lf_tcp, udp, tcp], type will be '
'adjusted automatically between ipv4 and ipv6 based on use of --ipv6 flag',
required=True)
optional.add_argument('--output_format', help='choose either csv or xlsx')
optional.add_argument('--report_file', help='where you want to store results', default=None)
optional.add_argument('--a_min', help='--a_min bps rate minimum for side_a', default=256000)
optional.add_argument('--b_min', help='--b_min bps rate minimum for side_b', default=256000)
optional.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="2m")
optional.add_argument('--layer3_cols', help='Columns wished to be monitored from layer 3 endpoint tab',
parser.add_argument('--output_format', help='choose either csv or xlsx')
parser.add_argument('--report_file', help='where you want to store results', default=None)
parser.add_argument('--a_min', help='--a_min bps rate minimum for side_a', default=256000)
parser.add_argument('--b_min', help='--b_min bps rate minimum for side_b', default=256000)
parser.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="2m")
parser.add_argument('--layer3_cols', help='Columns wished to be monitored from layer 3 endpoint tab',
default=['name', 'tx bytes', 'rx bytes', 'tx rate', 'rx rate'])
optional.add_argument('--port_mgr_cols', help='Columns wished to be monitored from port manager tab',
parser.add_argument('--port_mgr_cols', help='Columns wished to be monitored from port manager tab',
default=['alias', 'ap', 'ip', 'parent dev', 'rx-rate'])
optional.add_argument('--compared_report', help='report path and file which is wished to be compared with new report',
parser.add_argument('--compared_report', help='report path and file which is wished to be compared with new report',
default=None)
optional.add_argument('--monitor_interval',
parser.add_argument('--monitor_interval',
help='how frequently do you want your monitor function to take measurements, 35s, 2h',
default='10s')
optional.add_argument('--ipv6', help='Sets the test to use IPv6 traffic instead of IPv4', action='store_true')
optional.add_argument('--influx_host')
optional.add_argument('--influx_token', help='Username for your Influx database')
optional.add_argument('--influx_bucket', help='Password for your Influx database')
optional.add_argument('--influx_org', help='Name of your Influx database')
optional.add_argument('--influx_port', help='Port where your influx database is located', default=8086)
optional.add_argument('--influx_tag', action='append', nargs=2,
parser.add_argument('--ipv6', help='Sets the test to use IPv6 traffic instead of IPv4', action='store_true')
parser.add_argument('--influx_host')
parser.add_argument('--influx_token', help='Username for your Influx database')
parser.add_argument('--influx_bucket', help='Password for your Influx database')
parser.add_argument('--influx_org', help='Name of your Influx database')
parser.add_argument('--influx_port', help='Port where your influx database is located', default=8086)
parser.add_argument('--influx_tag', action='append', nargs=2,
help='--influx_tag <key> <val> Can add more than one of these.')
optional.add_argument('--influx_mgr',
parser.add_argument('--influx_mgr',
help='IP address of the server your Influx database is hosted if different from your LANforge Manager',
default=None)
parser.add_argument('--use_existing_sta', help='Used an existing stations to a particular AP', action='store_true')
parser.add_argument('--use_existing_sta', help='Used an existing stationsto a particular AP', action='store_true')
parser.add_argument('--sta_names', help='Used to force a connection to a particular AP', default="sta0000")
parser.add_argument('--local_lf_report_dir',
help='--local_lf_report_dir override the report path, primary use when running test in test suite',
default="")
# kpi_csv arguments:
parser.add_argument(
"--test_rig",
default="",
help="test rig for kpi.csv, testbed that the tests are run on")
parser.add_argument(
"--test_tag",
default="",
help="test tag for kpi.csv, test specific information to differenciate the test")
parser.add_argument(
"--dut_hw_version",
default="",
help="dut hw version for kpi.csv, hardware version of the device under test")
parser.add_argument(
"--dut_sw_version",
default="",
help="dut sw version for kpi.csv, software version of the device under test")
parser.add_argument(
"--dut_model_num",
default="",
help="dut model for kpi.csv, model number / name of the device under test")
parser.add_argument(
"--dut_serial_num",
default="",
help="dut serial for kpi.csv, serial number / serial number of the device under test")
parser.add_argument(
"--test_priority",
default="",
help="dut model for kpi.csv, test-priority is arbitrary number")
parser.add_argument(
'--csv_outfile',
help="--csv_outfile <Output file for csv data>",
default="")
args = parser.parse_args()
# set up logger
logger_config = lf_logger_config.lf_logger_config()
# set the logger level to requested level
logger_config.set_level(level=args.log_level)
# lf_logger_config_json will take presidence to changing debug levels
if args.lf_logger_config_json:
logger_config.lf_logger_config_json = args.lf_logger_config_json
logger_config.load_lf_logger_config()
# for kpi.csv generation
local_lf_report_dir = args.local_lf_report_dir
test_rig = args.test_rig
test_tag = args.test_tag
dut_hw_version = args.dut_hw_version
dut_sw_version = args.dut_sw_version
dut_model_num = args.dut_model_num
dut_serial_num = args.dut_serial_num
# test_priority = args.test_priority # this may need to be set per test
test_id = args.test_id
if local_lf_report_dir != "":
report = lf_report.lf_report(
_path=local_lf_report_dir,
_results_dir_name="test_ip_variable_time",
_output_html="test_ip_variable_time.html",
_output_pdf="test_ip_variable_time.pdf")
else:
report = lf_report.lf_report(
_results_dir_name="test_ip_variable_time",
_output_html="test_ip_variable_time.html",
_output_pdf="test_ip_variable_time.pdf")
kpi_path = report.get_report_path()
# kpi_filename = "kpi.csv"
logger.info("kpi_path :{kpi_path}".format(kpi_path=kpi_path))
kpi_csv = lf_kpi_csv.lf_kpi_csv(
_kpi_path=kpi_path,
_kpi_test_rig=test_rig,
_kpi_test_tag=test_tag,
_kpi_dut_hw_version=dut_hw_version,
_kpi_dut_sw_version=dut_sw_version,
_kpi_dut_model_num=dut_model_num,
_kpi_dut_serial_num=dut_serial_num,
_kpi_test_id=test_id)
if args.csv_outfile is None:
current_time = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
csv_outfile = "{}_{}-test_ip_variable_time.csv".format(
args.csv_outfile, current_time)
csv_outfile = report.file_add_path(csv_outfile)
logger.info("csv output file : {}".format(csv_outfile))
if len(args.upstream_port) and len(args.radio) and len(args.ssid) and len(args.security) != len(args.passwd):
raise ValueError(f"Upstream-ports - {args.upstream_port}\nradio - {args.radio}\nSSID - {args.ssid}\n"
f"Security - {args.security}\nPassword - {args.passwd}\n"
f"Value given to upstream_port,radio,ssid,security,passwd should be equal in number")
num_sta = 1
if args.num_stations:
logger.info("one")
print("one")
num_sta = int(args.num_stations)
if not args.use_existing_sta:
logger.info("two")
station_list = []
for i in args.radio:
station_list.append(LFUtils.portNameSeries(prefix_="R"+str(args.radio.index(i))+"-sta", start_id_=0, end_id_=num_sta - 1,
padding_number_=10000, radio=i))
print("two")
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1,
padding_number_=10000,
radio=args.radio)
else:
logger.info("three")
print("three")
station_list = args.sta_names.split(",")
logger.info("args.num_stations: {create}".format(create=args.num_stations))
logger.info("args.sta_names: {create}".format(create=args.sta_names))
logger.info("args.use_existing_sta: {create} {typeof}".format(create=args.use_existing_sta, typeof=type(args.use_existing_sta)))
logger.info("station_list: {sta}".format(sta=station_list))
print("args.num_stations: {create}".format(create=args.num_stations))
print("args.sta_names: {create}".format(create=args.sta_names))
print("args.use_existing_sta: {create} {typeof}".format(create=args.use_existing_sta, typeof=type(args.use_existing_sta)))
print("station_list: {sta}".format(sta=station_list))
# Create directory
# if file path with output file extension is not given...
@@ -1192,7 +639,7 @@ python3 ./test_ip_variable_time.py
CX_TYPES = ("tcp", "udp", "lf_tcp", "lf_udp")
if not args.traffic_type or (args.traffic_type not in CX_TYPES):
logger.error("cx_type needs to be lf_tcp, lf_udp, tcp, or udp, bye")
print("cx_type needs to be lf_tcp, lf_udp, tcp, or udp, bye")
exit(1)
if args.ipv6:
@@ -1223,15 +670,11 @@ python3 ./test_ip_variable_time.py
side_b_min_rate=args.b_min,
mode=args.mode,
ap=args.ap,
no_cleanup=args.no_cleanup,
report_file=args.report_file,
output_format=args.output_format,
layer3_cols=args.layer3_cols,
port_mgr_cols=args.port_mgr_cols,
monitor_interval=args.monitor_interval,
kpi_csv=kpi_csv,
kpi_path=kpi_path,
outfile=args.csv_outfile,
influx_host=args.influx_host,
influx_port=args.influx_port,
influx_org=args.influx_org,
@@ -1246,22 +689,6 @@ python3 ./test_ip_variable_time.py
# ip_var_test.set_wifi_radio(radio=args.radio)
ip_var_test.run()
# Reporting Results (.pdf & .html)
csv_results_file = ip_var_test.get_csv_name()
logger.info("csv_results_file: {}".format(csv_results_file))
# csv_results_file = kpi_path + "/" + kpi_filename
report.set_title("L3 IP Variable Time")
report.build_banner()
report.set_table_title("L3 IP Variable Time Key Performance Indexes")
report.build_table_title()
report.set_table_dataframe_from_csv(csv_results_file)
report.build_table()
report.write_html_with_timestamp()
report.write_index_html()
# report.write_pdf(_page_size = 'A3', _orientation='Landscape')
# report.write_pdf_with_timestamp(_page_size='A4', _orientation='Portrait')
report.write_pdf_with_timestamp(_page_size='A4', _orientation='Landscape')
if __name__ == "__main__":
main()