mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-03 04:07:52 +00:00
adding parse_time to ipv4_variable_time
This commit is contained in:
@@ -619,7 +619,7 @@ class LFCliBase:
|
||||
#================ Pandas Dataframe Functions ======================================
|
||||
|
||||
#takes any dataframe and returns the specified outputfile format of it
|
||||
def df_to_file(dataframe=None, output_f=None):
|
||||
def df_to_file(self, dataframe=None, output_f=None):
|
||||
df = dataframe
|
||||
if output_f == 'hdf':
|
||||
return df.to_hdf(output_f, 'table', append=True)
|
||||
@@ -638,8 +638,8 @@ class LFCliBase:
|
||||
# return exec('df.to_' + x + '("'+file_name'")')
|
||||
|
||||
#takes any format of a file and returns a dataframe of it
|
||||
def file_to_df(file_name=None):
|
||||
pass
|
||||
def file_to_df(file_name):
|
||||
return pd.read_csv(file_name)
|
||||
|
||||
def compare_two_df(dataframe_one=None,dataframe_two=None):
|
||||
pass
|
||||
|
||||
@@ -670,7 +670,8 @@ class Realm(LFCliBase):
|
||||
raise ValueError("time_string must be of type str. Type %s provided" % type(time_string))
|
||||
return duration_sec
|
||||
|
||||
def parse_time(self, time_string):
|
||||
@staticmethod
|
||||
def parse_time(time_string):
|
||||
if isinstance(time_string, str):
|
||||
pattern = re.compile("^(\d+)([dhms]$)")
|
||||
td = pattern.match(time_string)
|
||||
@@ -1163,7 +1164,7 @@ class L3CXProfile(LFCliBase):
|
||||
|
||||
def monitor(self,
|
||||
duration_sec=60,
|
||||
monitor_interval=1,
|
||||
monitor_interval_ms=1,
|
||||
layer3_cols=None,
|
||||
port_mgr_cols=None,
|
||||
created_cx=None,
|
||||
@@ -1179,13 +1180,13 @@ class L3CXProfile(LFCliBase):
|
||||
except:
|
||||
if (duration_sec is None) or (duration_sec <= 1):
|
||||
raise ValueError("L3CXProfile::monitor wants duration_sec > 1 second")
|
||||
if (duration_sec <= monitor_interval):
|
||||
if (duration_sec <= monitor_interval_ms):
|
||||
raise ValueError("L3CXProfile::monitor wants duration_sec > monitor_interval")
|
||||
if report_file == None:
|
||||
raise ValueError("Monitor requires an output file to be defined")
|
||||
if created_cx == None:
|
||||
raise ValueError("Monitor needs a list of Layer 3 connections")
|
||||
if (monitor_interval is None) or (monitor_interval < 1):
|
||||
if (monitor_interval_ms is None) or (monitor_interval_ms < 1):
|
||||
raise ValueError("L3CXProfile::monitor wants monitor_interval >= 1 second")
|
||||
if layer3_cols is None:
|
||||
raise ValueError("L3CXProfile::monitor wants a list of column names to monitor")
|
||||
@@ -1278,15 +1279,15 @@ class L3CXProfile(LFCliBase):
|
||||
self.fail("FAIL: Not all stations increased traffic")
|
||||
self.exit_fail()
|
||||
old_cx_rx_values = new_cx_rx_values
|
||||
time.sleep(monitor_interval)
|
||||
time.sleep(monitor_interval_ms)
|
||||
csvfile.close()
|
||||
|
||||
#here, do column manipulations
|
||||
|
||||
#here, do df to final report file output
|
||||
if output_format.lower() != 'csv':
|
||||
dataframe_output = self.file_to_df(file_name=report_file)
|
||||
file_output_file = self.df_to_file(dataframe=dataframe_output, output_f=output_format)
|
||||
dataframe_output = pd.read_csv(report_file)
|
||||
self.df_to_file(dataframe=dataframe_output, output_f=output_format)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ from realm import Realm
|
||||
import time
|
||||
import datetime
|
||||
|
||||
|
||||
class IPV4VariableTime(Realm):
|
||||
def __init__(self,
|
||||
ssid=None,
|
||||
@@ -79,7 +80,6 @@ class IPV4VariableTime(Realm):
|
||||
if self.ap is not None:
|
||||
self.station_profile.set_command_param("add_sta", "ap", self.ap)
|
||||
|
||||
|
||||
self.cx_profile.host = self.host
|
||||
self.cx_profile.port = self.port
|
||||
self.cx_profile.name_prefix = self.name_prefix
|
||||
@@ -100,7 +100,6 @@ class IPV4VariableTime(Realm):
|
||||
self.exit_fail()
|
||||
self.cx_profile.start_cx()
|
||||
|
||||
|
||||
def stop(self):
|
||||
self.cx_profile.stop_cx()
|
||||
self.station_profile.admin_down()
|
||||
@@ -125,9 +124,11 @@ class IPV4VariableTime(Realm):
|
||||
self.station_profile.set_command_param("set_port", "report_timer", 1500)
|
||||
self.station_profile.set_command_flag("set_port", "rpt_timer", 1)
|
||||
self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug)
|
||||
self.cx_profile.create(endp_type="lf_udp", side_a=self.station_profile.station_names, side_b=self.upstream, sleep_time=0)
|
||||
self.cx_profile.create(endp_type="lf_udp", side_a=self.station_profile.station_names, side_b=self.upstream,
|
||||
sleep_time=0)
|
||||
self._pass("PASS: Station build finished")
|
||||
|
||||
|
||||
def main():
|
||||
optional = []
|
||||
optional.append({'name': '--mode', 'help': 'Used to force mode of stations'})
|
||||
@@ -136,10 +137,18 @@ def main():
|
||||
optional.append({'name': '--report_file', 'help': 'where you want to store results', 'default': None})
|
||||
optional.append({'name': '--a_min', 'help': '--a_min bps rate minimum for side_a', 'default': 256000})
|
||||
optional.append({'name': '--b_min', 'help': '--b_min bps rate minimum for side_b', 'default': 256000})
|
||||
optional.append({'name':'--test_duration','help':'--test_duration sets the duration of the test', 'default':"2m"})
|
||||
optional.append({'name':'--layer3_cols','help':'Columns wished to be monitored from layer 3 endpoint tab', 'default':['name','tx bytes','rx bytes']})
|
||||
optional.append({'name':'--port_mgr_cols','help':'Columns wished to be monitored from port manager tab', 'default':['ap','ip','rx bytes']})
|
||||
optional.append({'name':'--compared_report','help':'report path and file which is wished to be compared with new report', 'default':None})
|
||||
optional.append(
|
||||
{'name': '--test_duration', 'help': '--test_duration sets the duration of the test', 'default': "2m"})
|
||||
optional.append({'name': '--layer3_cols', 'help': 'Columns wished to be monitored from layer 3 endpoint tab',
|
||||
'default': ['name', 'tx bytes', 'rx bytes']})
|
||||
optional.append({'name': '--port_mgr_cols', 'help': 'Columns wished to be monitored from port manager tab',
|
||||
'default': ['ap', 'ip', 'rx bytes']})
|
||||
optional.append(
|
||||
{'name': '--compared_report', 'help': 'report path and file which is wished to be compared with new report',
|
||||
'default': None})
|
||||
optional.append({'name': '--monitor_interval',
|
||||
'help': 'how frequently do you want your monitor function to take measurements; 250ms, 35s, 2h',
|
||||
'default': '2s'})
|
||||
parser = LFCliBase.create_basic_argparse(
|
||||
prog='test_ipv4_variable_time.py',
|
||||
formatter_class=argparse.RawTextHelpFormatter,
|
||||
@@ -174,6 +183,7 @@ python3 ./test_ipv4_variable_time.py
|
||||
--ssid netgear
|
||||
--password admin123
|
||||
--test_duration 2m (default)
|
||||
--monitor_interval_ms
|
||||
--a_min 3000
|
||||
--b_min 1000
|
||||
--ap "00:0e:8e:78:e1:76"
|
||||
@@ -263,7 +273,8 @@ python3 ./test_ipv4_variable_time.py
|
||||
# in new folder based in current file's directory
|
||||
|
||||
if args.report_file is None:
|
||||
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")).replace(':','-')+'test_ipv4_variable_time' #create path name
|
||||
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")).replace(':',
|
||||
'-') + 'test_ipv4_variable_time' # create path name
|
||||
try:
|
||||
path = os.path.join('/home/lanforge/report-data/', new_file_path)
|
||||
os.mkdir(path)
|
||||
@@ -272,7 +283,8 @@ python3 ./test_ipv4_variable_time.py
|
||||
path = os.path.join(curr_dir_path, new_file_path)
|
||||
os.mkdir(path)
|
||||
|
||||
if args.output_format in ['csv','json','html','hdf','stata','pickle','pdf','png','df','parquet','xlsx']:
|
||||
if args.output_format in ['csv', 'json', 'html', 'hdf', 'stata', 'pickle', 'pdf', 'png', 'df', 'parquet',
|
||||
'xlsx']:
|
||||
report_f = str(path) + '/data.' + args.output_format
|
||||
output = args.output_format
|
||||
else:
|
||||
@@ -296,10 +308,11 @@ python3 ./test_ipv4_variable_time.py
|
||||
if output == last_report_format:
|
||||
compared_rept = args.compared_report
|
||||
else:
|
||||
ValueError("Compared report format is not the same as the new report format. Please make sure they are of the same file type.")
|
||||
ValueError(
|
||||
"Compared report format is not the same as the new report format. Please make sure they are of the same file type.")
|
||||
|
||||
|
||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta-1, padding_number_=10000, radio=args.radio)
|
||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000,
|
||||
radio=args.radio)
|
||||
ip_var_test = IPV4VariableTime(host=args.mgr,
|
||||
port=args.mgr_port,
|
||||
number_template="0000",
|
||||
@@ -347,10 +360,13 @@ python3 ./test_ipv4_variable_time.py
|
||||
print("Port Manager column names are...")
|
||||
print(port_mgr_cols)
|
||||
|
||||
monitor_interval = Realm.parse_time(args.monitor_interval).total_seconds()
|
||||
|
||||
ip_var_test.l3cxprofile.monitor(layer3_cols=layer3_cols,
|
||||
port_mgr_cols=port_mgr_cols,
|
||||
report_file=report_f,
|
||||
duration_sec=ip_var_test.parse_time(args.test_duration).total_seconds(),
|
||||
duration_sec=Realm.parse_time(args.test_duration).total_seconds(),
|
||||
monitor_interval_ms=monitor_interval,
|
||||
created_cx=layer3connections,
|
||||
output_format=output,
|
||||
compared_report=compared_rept,
|
||||
@@ -367,5 +383,6 @@ python3 ./test_ipv4_variable_time.py
|
||||
if ip_var_test.passes():
|
||||
ip_var_test.exit_success()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user