Merge branch 'master' of github.com:greearb/lanforge-scripts

This commit is contained in:
Matthew Stidham
2021-02-16 17:02:11 -08:00
7 changed files with 129 additions and 50 deletions

View File

@@ -959,6 +959,21 @@ def main():
if (args.action == "auto_rf"):
command = "show ap auto-rf 802.11a %s"%(args.ap)
egg.sendline(command)
command_done = False
loop_count = 0
while command_done == False and loop_count <= 10 :
i = egg.expect_exact(["--More--",CCP,pexpect.TIMEOUT],timeout=2)
if i == 0:
print(egg.before.decode('utf-8', 'ignore'))
egg.sendline(NL)
if i == 1:
print(egg.before.decode('utf-8', 'ignore'))
command_done = True
if i == 2:
print(egg.before.decode('utf-8', 'ignore'))
command_done = True
command = None # so additional command will not be sent
if ((args.action == "ap_country") and ((args.value is None) or (args.ap is None))):
raise Exception("ap_country requires country and AP name")

View File

@@ -16,6 +16,7 @@ from LANforge import LFRequest
import LANforge.LFRequest
import csv
import pandas as pd
#import xlsxwriter
class LFCliBase:
@@ -624,27 +625,29 @@ class LFCliBase:
#================ Pandas Dataframe Functions ======================================
#takes any dataframe and returns the specified file extension of it
def df_to_file(self, dataframe=None, output_f=None):
def df_to_file(self, output_f=None,dataframe=None, save_path=None):
df = dataframe
if output_f == 'hdf':
return df.to_hdf(output_f, 'table', append=True)
if output_f == 'parquet':
return df.to_parquet(output_f, engine='pyarrow')
if output_f == 'png':
#pd.set_option("display.max_rows", None, "display.max_columns", None)
#print(df)
if output_f.lower() == 'hdf':
df.to_hdf(save_path, 'table', append=True)
if output_f.lower() == 'parquet':
df.to_parquet(save_path, engine='pyarrow')
if output_f.lower() == 'png':
fig = df.plot().get_figure()
return fig.savefig(output_f)
if output_f.lower() in ['excel', 'xlsx']:
return df.to_excel(output_f, index=False)
if output_f == 'df':
return df
if output_f == 'json':
return df.to_json(output_f)
if output_f == 'stata':
return df.to_stata(output_f)
if output_f == 'pickle':
return df.to_pickle(output_f)
if output_f == 'html':
return df.to_html(output_f)
fig.savefig(save_path)
if output_f.lower() == 'xlsx':
df.to_excel(save_path)
if output_f.lower() == 'df':
df
if output_f.lower() == 'json':
df.to_json(save_path)
if output_f.lower() == 'stata':
df.to_stata(save_path)
if output_f.lower() == 'pickle':
df.to_pickle(save_path)
if output_f.lower() == 'html':
df.to_html(save_path)
#takes any format of a file and returns a dataframe of it
def file_to_df(self,file_name):

View File

@@ -545,8 +545,9 @@ class Realm(LFCliBase):
return matched_map
def name_to_eid(self, eid):
self.logg(level="debug", mesg="name_to_eid: "+str(eid))
def name_to_eid(self, eid,debug=False):
if debug:
self.logg(level="debug", mesg="name_to_eid: "+str(eid))
if (type(eid) is list) or (type(eid) is tuple):
return eid
return LFUtils.name_to_eid(eid)
@@ -1206,6 +1207,7 @@ class L3CXProfile(LFCliBase):
#default save to csv first
if report_file.split('.')[-1] != 'csv':
report_file = report_file.replace(str(output_format),'csv',1)
print("Saving rolling data into..." + str(report_file))
#retrieve compared report if specified - turn into dataframe === under construction ===
if compared_report is not None:
@@ -1330,10 +1332,7 @@ class L3CXProfile(LFCliBase):
#df to final report file output if necessary
if output_format.lower() != 'csv':
dataframe_output = pd.read_csv(report_file)
final_file = self.df_to_file(dataframe=dataframe_output, output_f=output_format)
#save final file output
#print(report_file)
self.df_to_file(dataframe=pd.read_csv(report_file), output_f=output_format, save_path=report_file.replace('csv',output_format,1))
def refresh_cx(self):
@@ -1408,7 +1407,7 @@ class L3CXProfile(LFCliBase):
side_b_resource = side_b_info[1]
for port_name in side_a:
side_a_info = self.local_realm.name_to_eid(port_name)
side_a_info = self.local_realm.name_to_eid(port_name,debug=debug_)
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
if port_name.find('.') < 0:
@@ -1491,14 +1490,14 @@ class L3CXProfile(LFCliBase):
})
elif type(side_b) == list and type(side_a) != list:
side_a_info = self.local_realm.name_to_eid(side_a)
side_a_info = self.local_realm.name_to_eid(side_a,debug=debug_)
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
# side_a_name = side_a_info[2]
for port_name in side_b:
print(side_b)
side_b_info = self.local_realm.name_to_eid(port_name)
side_b_info = self.local_realm.name_to_eid(port_name,debug=debug_)
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = side_b_info[2]

View File

@@ -1,4 +1,5 @@
from realm import BaseProfile
import time
class VRProfile(BaseProfile):
"""
@@ -147,6 +148,18 @@ class VRProfile(BaseProfile):
"shelf": 1,
"resource": self.vr_eid[1]
}, debug_=debug)
time.sleep(1)
self.json_post("/cli-json/nc_show_vr", {
"shelf": 1,
"resource": self.vr_eid[1],
"router": "all"
}, debug_=debug)
self.json_post("/cli-json/nc_show_vrcx", {
"shelf": 1,
"resource": self.vr_eid[1],
"cx_name": "all"
}, debug_=debug)
# # Create 1 rdd pair
# self.create_rdd(resource=resource, ip_addr=rdd_ip, gateway=rdd_gateway,
@@ -160,8 +173,38 @@ class VRProfile(BaseProfile):
# nexthop=local_nexthop,
# flags=1, suppress_related_commands_=suppress_related_commands_, debug_=debug)
def cleanup(self, resource, delay=0.03):
def cleanup(self, resource=0, vr_id=0, delay=0.3, debug=False):
debug |= self.debug
if self.vr_eid is None:
return
if resource == 0:
resource = self.vr_eid[1]
if vr_id == 0:
vr_id = self.vr_eid[2]
pass
data = {
"shelf": 1,
"resource": resource,
"router_name": vr_id
}
self.json_post("/cli-json/rm_vr", data, debug_=debug)
time.sleep(delay)
self.refresh(resource, debug)
def refresh_gui(self, resource=0, delay=0.03, debug=False):
debug |= self.debug
self.json_post("/cli-json/nc_show_vr", {
"shelf": 1,
"resource": resource,
"router": "all"
}, debug_=debug)
self.json_post("/cli-json/nc_show_vrcx", {
"shelf": 1,
"resource": resource,
"cx_name": "all"
}, debug_=debug)
time.sleep(delay)
self.json_post("/vr/1/%s/%s" % (resource, 0), {
"action":"refresh"
}, debug)
#

View File

@@ -15,7 +15,7 @@ if 'py-json' not in sys.path:
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
from LANforge.lfcli_base import LFCliBase
from realm import Realm
import time
class CreateVR(Realm):
def __init__(self,
@@ -53,12 +53,7 @@ class CreateVR(Realm):
if (self.vr_profile.vr_eid is not None) \
and (self.vr_profile.vr_eid[1] is not None) \
and (self.vr_profile.vr_eid[2] is not None):
data = {
"shelf": 1,
"resource": self.vr_profile.vr_eid[1],
"router_name": self.vr_profile.vr_eid[2]
}
self.json_post("/cli-json/rm_vr", data, debug_=self.debug)
self.vr_profile.cleanup(debug=self.debug)
if (self.vr_name is not None) \
and (self.vr_name[1] is not None) \
@@ -69,6 +64,18 @@ class CreateVR(Realm):
"router_name": self.vr_name[2]
}
self.json_post("/cli-json/rm_vr", data, debug_=self.debug)
time.sleep(1)
self.json_post("/cli-json/nc_show_vr", {
"shelf": 1,
"resource": self.vr_name[1],
"router": "all"
}, debug_=self.debug)
self.json_post("/cli-json/nc_show_vrcx", {
"shelf": 1,
"resource": self.vr_name[1],
"cx_name": "all"
}, debug_=self.debug)
def build(self):

View File

@@ -1368,7 +1368,7 @@ class L3VariableTime(Realm):
def read_auto_rf(self):
logg.info("read_channel: cisco_wifi_ctl.py action advanced")
logg.info("read_channel: cisco_wifi_ctl.py action auto-rf")
pss = ""
try:
logg.info("\
@@ -1389,6 +1389,17 @@ class L3VariableTime(Realm):
format(process_error.returncode, process_error.output))
time.sleep(1)
exit(1)
blacklist_time = ""
for line in pss.splitlines():
pat = 'Channel\s+%s\S+\s+(\S+)\s+\S+\s+remaining'%(self.chan_5ghz)
m = re.search(pat, line)
if ( m != None ):
blacklist_time = m.group(1)
logg.info("dfs_channel: {} blacklist_time: {}".format(self.chan_5ghz,blacklist_time))
return blacklist_time
def dfs_get_frequency(self,channel):
@@ -1467,8 +1478,8 @@ class L3VariableTime(Realm):
interval_ = "1428"
count_ = "18"
frequency_ = "5260000" # channel 52
sweep_time_ = "1000"
#sweep_time_ = "0"
#sweep_time_ = "1000"
sweep_time_ = "0"
if_gain_ = "40"
bb_gain_ = "20"
gain_ = "0"
@@ -1625,9 +1636,9 @@ class L3VariableTime(Realm):
logg.info("###########################################")
if (initial_channel != self.chan_5ghz):
logg.warn("##################################################################")
logg.warn("# DFS LOCKOUT? COMMAND LINE CHANNEL: {} NOT EQUAL INITIAL CONTROLLER CHANNEL: {}".format(self.chan_5ghz,initial_channel))
logg.warn("##################################################################")
logg.info("##################################################################")
logg.info("# DFS LOCKOUT? COMMAND LINE CHANNEL: {} NOT EQUAL INITIAL CONTROLLER CHANNEL: {}".format(self.chan_5ghz,initial_channel))
logg.info("##################################################################")
time.sleep(30)
@@ -1719,7 +1730,7 @@ class L3VariableTime(Realm):
logg.info("FAIL: channel set on command line: {} not configured in controller: {} is there a DFS lockout condition".format(self.chan_5ghz,initial_channel))
pass_fail = "fail"
#if self.dfs
blacklist_time = self.read_auto_rf()
best_csv_rx_row_data.append(initial_channel)
@@ -1727,6 +1738,7 @@ class L3VariableTime(Realm):
best_csv_rx_row_data.append(pass_fail)
best_csv_rx_row_data.append(self.CAC_TIMER)
best_csv_rx_row_data.append(self.CAC_EXPIRY_EVT)
best_csv_rx_row_data.append(blacklist_time)
self.csv_add_row(best_csv_rx_row_data,self.csv_results_writer,self.csv_results)
# TO DO check to see if the data is still being transmitted
@@ -1761,7 +1773,7 @@ class L3VariableTime(Realm):
def csv_generate_column_results_headers(self):
csv_rx_headers = self.test_keys.copy()
csv_rx_headers.extend
csv_rx_headers.extend(['max_tp_mbps','expected_tp','test_id','epoch_time','time','initial_channel','final_channel','pass_fail','cac_timer','cac_expiry_evt'])
csv_rx_headers.extend(['max_tp_mbps','expected_tp','test_id','epoch_time','time','initial_channel','final_channel','pass_fail','cac_timer','cac_expiry_evt','blacklist_time_sec_remaining'])
'''for i in range(1,6):
csv_rx_headers.append("least_rx_data {}".format(i))
for i in range(1,6):
@@ -3086,7 +3098,7 @@ if __name__ == "__main__":
SAMPLE Command 2/15/2021
./lf_cisco_dfs.py -cc 192.168.100.112 -cu admin -cpw Cisco123 -cca APA453.0E7B.CF9C -ccf "a" -cwm "auto" -cc5 "52 56 60 64 68 96 100 104 108 112 116 120 124 128 132 136 140 144" -ccw "20" -ccd "1" -cs "3504" --endp_type 'lf_udp' --upstream_port eth2 --cisco_wlan "test_candela" --cisco_wlanID 1 --cisco_wlanSSID "test_candela" --cisco_directions "upstream" --cisco_prompt "(Cisco Controller)" --radio "radio==1.wiphy0 stations==1 ssid==test_candela ssid_pw==[BLANK] security==open wifimode==auto"
SAMPLE Command with AP
./lf_cisco_dfs.py -cc 192.168.100.112 -cu admin -cpw Cisco123 -cca APA453.0E7B.CF9C -ccf "a" -cwm "auto" -cc5 "52" -ccw "20" -ccd "1" -cs "3504" --endp_type 'lf_udp' --upstream_port eth2 --cisco_wlan "test_candela" --cisco_wlanID 1 --cisco_wlanSSID "test_candela" --cisco_directions "upstream" --cisco_prompt "(Cisco Controller)" --radio "radio==1.wiphy0 stations==1 ssid==test_candela ssid_pw==[BLANK] security==open wifimode==auto" --ap_info "ap_scheme==serial ap_prompt==APA453.0E7B.CF9C ap_ip==0 ap_port==0 ap_user==admin ap_pw==Admin123 ap_tty==/dev/ttyUSB2 ap_baud==9600"
SAMPLE Command with AP (need root if using serial)
sudo ./lf_cisco_dfs.py -cc 192.168.100.112 -cu admin -cpw Cisco123 -cca APA453.0E7B.CF9C -ccf "a" -cwm "auto" -cc5 "56" -ccw "20" -ccd "1" -cs "3504" --endp_type 'lf_udp' --upstream_port eth2 --cisco_wlan "test_candela" --cisco_wlanID 1 --cisco_wlanSSID "test_candela" --cisco_directions "upstream" --cisco_prompt "(Cisco Controller)" --radio "radio==1.wiphy0 stations==1 ssid==test_candela ssid_pw==[BLANK] security==open wifimode==auto" --ap_info "ap_scheme==serial ap_prompt==APA453.0E7B.CF9C ap_ip==0 ap_port==0 ap_user==admin ap_pw==Admin123 ap_tty==/dev/ttyUSB2 ap_baud==9600" --cisco_dfs
'''

View File

@@ -281,7 +281,7 @@ 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-%S")).replace(':',
new_file_path = str(datetime.datetime.now().strftime("%Y-%m-%d-%H-h-%M-m-%S-s")).replace(':',
'-') + '-test_ipv4_variable_time' # create path name
try:
path = os.path.join('/home/lanforge/report-data/', new_file_path)
@@ -296,7 +296,7 @@ python3 ./test_ipv4_variable_time.py
report_f = str(path) + '/data.' + args.output_format
output = args.output_format
else:
print('Defaulting to csv data file output type, naming it data.csv.')
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'
output = 'csv'
@@ -306,7 +306,7 @@ python3 ./test_ipv4_variable_time.py
output = str(args.report_file).split('.')[-1]
else:
output = args.output_format
print("Saving report data in ... " + report_f)
print("Saving final report data in ... " + report_f)
# Retrieve last data file
compared_rept = None