Merge remote-tracking branch 'origin/master'

This commit is contained in:
Logan Lipke
2020-07-02 11:07:47 -07:00
9 changed files with 362 additions and 269 deletions

View File

@@ -50,8 +50,10 @@ class PortEID:
# end class PortEID
def staNewDownStaRequest(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="",
debug_on=False):
def staNewDownStaRequest(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False):
return sta_new_down_sta_request(sta_name, resource_id, radio, ssid, passphrase, debug_on)
def sta_new_down_sta_request(sta_name, resource_id=1, radio="wiphy0", ssid="", passphrase="", debug_on=False):
"""
For use with add_sta. If you don't want to generate mac addresses via patterns (xx:xx:xx:xx:81:*)
you can generate octets using random_hex.pop(0)[2:] and gen_mac(parent_radio_mac, octet)
@@ -78,6 +80,9 @@ def staNewDownStaRequest(sta_name, resource_id=1, radio="wiphy0", ssid="", passp
def portSetDhcpDownRequest(resource_id, port_name, debug_on=False):
return port_set_dhcp_down_request(resource_id, port_name, debug_on)
def port_set_dhcp_down_request(resource_id, port_name, debug_on=False):
"""
See http://localhost:8080/help/set_port
:param resource_id:
@@ -99,6 +104,9 @@ def portSetDhcpDownRequest(resource_id, port_name, debug_on=False):
def portDhcpUpRequest(resource_id, port_name, debug_on=False):
return port_dhcp_up_request(resource_id, port_name, debug_on)
def port_dhcp_up_request(resource_id, port_name, debug_on=False):
"""
See http://localhost:8080/help/set_port
:param resource_id:
@@ -120,6 +128,9 @@ def portDhcpUpRequest(resource_id, port_name, debug_on=False):
def portUpRequest(resource_id, port_name, debug_on=False):
return port_up_request(resource_id, port_name, debug_on)
def port_up_request(resource_id, port_name, debug_on=False):
"""
See http://localhost:8080/help/set_port
:param resource_id:
@@ -278,7 +289,7 @@ def findPortEids(resource_id=1, base_url="http://localhost:8080", port_names=(),
def waitUntilPortsAdminDown(resource_id=1, base_url="http://localhost:8080", port_list=()):
print("waitUntilPortsAdminDown")
print("Waiting until ports appear admin-down...")
up_stations = port_list.copy()
sleep(1)
port_url = "/port/1"
@@ -300,7 +311,7 @@ def waitUntilPortsAdminDown(resource_id=1, base_url="http://localhost:8080", por
def waitUntilPortsAdminUp(resource_id=1, base_url="http://localhost:8080", port_list=()):
print("waitUntilPortsAdminUp")
print("Waiting until ports appear admin-up...")
down_stations = port_list.copy()
sleep(1)
port_url = "/port/1"
@@ -325,8 +336,7 @@ def waitUntilPortsDisappear(resource_id=1, base_url="http://localhost:8080", por
wait_until_ports_disappear(resource_id, base_url, port_list, debug)
def wait_until_ports_disappear(resource_id=1, base_url="http://localhost:8080", port_list=[], debug=False):
if (debug):
print("waitUntilPortsDisappear")
print("Waiting until ports disappear...")
url = "/port/1"
found_stations = port_list.copy()
sleep(1)
@@ -345,8 +355,27 @@ def wait_until_ports_disappear(resource_id=1, base_url="http://localhost:8080",
def waitUntilPortsAppear(resource_id=1, base_url="http://localhost:8080", port_list=(), debug=False):
if debug:
print("waitUntilPortsAppear")
"""
Deprecated
:param resource_id:
:param base_url:
:param port_list:
:param debug:
:return:
"""
return wait_until_ports_appear(resource_id, base_url, port_list, debug=debug)
def wait_until_ports_appear(resource_id=1, base_url="http://localhost:8080", port_list=(), debug=False):
"""
:param resource_id:
:param base_url:
:param port_list:
:param debug:
:return:
"""
print("Waiting until ports appear...")
found_stations = []
sleep(2)
port_url = "/port/1"
@@ -376,7 +405,7 @@ def waitUntilPortsAppear(resource_id=1, base_url="http://localhost:8080", port_l
def removePort(resource, port_name, baseurl="http://localhost:8080/", debug=False):
if debug:
print("removePort")
print("Removing port %d.%s" % (resource, port_name))
url = "/cli-json/rm_vlan"
lf_r = LFRequest.LFRequest(baseurl, url)
lf_r.addPostData({
@@ -387,9 +416,11 @@ def removePort(resource, port_name, baseurl="http://localhost:8080/", debug=Fals
lf_r.jsonPost(debug)
def removeCX(baseurl, cxNames, debug=False):
def removeCX(baseurl, cx_names, debug=False):
if debug:
print("Removing cx %s" % ", ".join(cx_names))
url = "/cli-json/rm_cx"
for name in cxNames:
for name in cx_names:
data = {
"test_mgr": "all",
"cx_name": name
@@ -399,10 +430,12 @@ def removeCX(baseurl, cxNames, debug=False):
lf_r.jsonPost(debug)
def removeEndps(baseurl, endpNames, debug=False):
def removeEndps(baseurl, endp_names, debug=False):
if debug:
print("Removing endp %s" % ", ".join(endp_names))
url = "/cli-json/rm_endp"
lf_r = LFRequest.LFRequest(baseurl, url)
for name in endpNames:
for name in endp_names:
data = {
"endp_name": name
}

View File

@@ -60,13 +60,13 @@ class LFCliBase:
elif suppress_related_commands_ == False:
_data['suppress_preexec_cli'] = False
_data['suppress_preexec_method'] = False
_data['suppostss_postexec_cli'] = False
_data['suppostss_postexec_method'] = False
_data['suppress_postexec_cli'] = False
_data['suppress_postexec_method'] = False
elif self.suppress_related_commands or suppress_related_commands_:
_data['suppress_preexec_cli'] = False
_data['suppress_preexec_method'] = False
_data['suppostss_postexec_cli'] = True
_data['suppostss_postexec_method'] = True
_data['suppress_postexec_cli'] = True
_data['suppress_postexec_method'] = True
lf_r.addPostData(_data)
if debug_ or self.debug:

View File

@@ -14,8 +14,8 @@ import datetime
class Realm(LFCliBase):
def __init__(self, lfclient_host="localhost", lfclient_port=8080, debug_=True):
super().__init__(lfclient_host, lfclient_port, debug_, _halt_on_error=True)
def __init__(self, lfclient_host="localhost", lfclient_port=8080, debug_=False, halt_on_error_=False):
super().__init__(_lfjson_host=lfclient_host, _lfjson_port=lfclient_port, _debug=debug_, _halt_on_error=halt_on_error_)
# self.lfclient_url = "http://%s:%s" % (lfclient_host, lfclient_port)
self.debug = debug_
self.check_connect()
@@ -191,12 +191,15 @@ class Realm(LFCliBase):
def name_to_eid(self, eid):
info = []
if eid is None or eid == "":
if (eid is None) or (eid == "") or ('.' not in eid):
raise ValueError("name_to_eid wants eid like 1.1.sta0 but given[%s]" % eid)
else:
if '.' in eid:
info = eid.split('.')
return info
info = eid.split('.')
info[0] = int(info[0])
if len(info) == 3:
info[1] = int(info[1])
return info
return [1, int(info[0]), info[1]]
def parse_time(self, time_string):
if isinstance(time_string, str):
@@ -248,7 +251,7 @@ class L3CXProfile(LFCliBase):
side_a_max_bps=0, side_b_max_bps=0,
side_a_min_pdu=-1, side_b_min_pdu=-1,
side_a_max_pdu=0, side_b_max_pdu=0,
report_timer_=3000, prefix="Unset", debug_=False):
report_timer_=3000, name_prefix_="Unset", number_template_="00000", debug_=False):
"""
:param lfclient_host:
@@ -262,7 +265,8 @@ class L3CXProfile(LFCliBase):
:param side_b_min_pdu:
:param side_a_max_pdu:
:param side_b_max_pdu:
:param prefix:
:param name_prefix: prefix string for connection
:param number_template_: how many zeros wide we padd, possibly a starting integer with left padding
:param debug_:
"""
super().__init__(lfclient_host, lfclient_port, debug_, _halt_on_error=True)
@@ -279,9 +283,46 @@ class L3CXProfile(LFCliBase):
self.side_b_max_bps = side_b_max_bps
self.report_timer = report_timer_
self.created_cx = {}
self.prefix = prefix
self.name_prefix = name_prefix_
self.number_template = number_template_
def get_cx_names(self):
return self.created_cx.keys()
def refresh_cx(self):
for cx_name in self.created_cx.keys():
self.json_post("/cli-json/show_cxe", {
"test_mgr": "ALL",
"cross_connect": cx_name
}, debug_=self.debug)
print(".", end='')
def start_cx(self):
print("Starting CXs...")
for cx_name in self.created_cx.keys():
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "default_tm",
"cx_name": cx_name,
"cx_state":"RUNNING"
}, debug_=self.debug)
print(".", end='')
print("")
def stop_cx(self):
print("Stopping CXs...")
for cx_name in self.created_cx.keys():
self.json_post("/cli-json/set_cx_state", {
"test_mgr": "default_tm",
"cx_name": cx_name,
"cx_state":"STOPPED"
}, debug_=self.debug)
print(".", end='')
print("")
def create(self, endp_type, side_a, side_b, sleep_time=0.03, suppress_related_commands=None, debug_=False):
if self.debug:
debug_=True
def create(self, endp_type, side_a, side_b, sleep_time=.5):
cx_post_data = []
timer_post_data = []
# print(self.side_a_min_rate, self.side_a_max_rate)
@@ -294,33 +335,23 @@ class L3CXProfile(LFCliBase):
if type(side_a) == list and type(side_b) != list:
side_b_info = self.local_realm.name_to_eid(side_b)
if len(side_b_info) == 3:
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = side_b_info[2]
elif len(side_b_info) == 2:
side_b_shelf = 1
side_b_resource = side_b_info[0]
side_b_name = side_b_info[1]
else:
raise ValueError("side_b must have a shelf and/or resource number")
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = "%s%s" % (self.name_prefix, side_b_info[2])
for port_name in side_a:
side_a_info = self.local_realm.name_to_eid(port_name)
if len(side_a_info) == 3:
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
side_a_name = side_a_info[2]
else:
side_a_shelf = 1
side_a_resource = side_a_info[0]
side_a_name = side_a_info[1]
self.created_cx[port_name+"L3"] = [side_a_name + "-A", side_a_name + "-B"]
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
side_a_name = "%s%s"%(self.name_prefix, side_a_info[2])
cx_name = "%s%s" % (self.name_prefix, port_name)
self.created_cx[ cx_name ] = [side_a_name + "-A", side_a_name + "-B"]
endp_side_a = {
"alias": side_a_name + "-A",
"shelf": side_a_shelf,
"shelf": 1,
"resource": side_a_resource,
"port": side_a_name,
"port": side_a_info[2],
"type": endp_type,
"min_rate": self.side_a_min_bps,
"max_rate": self.side_a_max_bps,
@@ -330,9 +361,9 @@ class L3CXProfile(LFCliBase):
}
endp_side_b = {
"alias": side_a_name + "-B",
"shelf": side_b_shelf,
"shelf": 1,
"resource": side_b_resource,
"port": side_b_name,
"port": side_b_info[2],
"type": endp_type,
"min_rate": self.side_b_min_bps,
"max_rate": self.side_b_max_bps,
@@ -342,8 +373,9 @@ class L3CXProfile(LFCliBase):
}
url = "/cli-json/add_endp"
self.local_realm.json_post(url, endp_side_a)
self.local_realm.json_post(url, endp_side_b)
self.local_realm.json_post(url, endp_side_a, debug_=debug_, suppress_related_commands_=suppress_related_commands)
self.local_realm.json_post(url, endp_side_b, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print("napping %f sec"%sleep_time)
time.sleep(sleep_time)
url = "cli-json/set_endp_flag"
@@ -352,7 +384,7 @@ class L3CXProfile(LFCliBase):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data)
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
url = "cli-json/set_endp_flag"
data = {
@@ -360,15 +392,16 @@ class L3CXProfile(LFCliBase):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data)
cx_name = self.prefix, self.local_realm.name_to_eid(port_name)[-1]
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print("CXNAME366:")
#pprint(cx_name)
data = {
"alias": cx_name,
"test_mgr": "default_tm",
"tx_endp": side_a_name + "-A",
"rx_endp": side_a_name + "-B"
}
#pprint(data)
cx_post_data.append(data)
timer_post_data.append({
"test_mgr":"default_tm",
@@ -378,34 +411,24 @@ class L3CXProfile(LFCliBase):
elif type(side_b) == list and type(side_a) != list:
side_a_info = self.local_realm.name_to_eid(side_a)
if len(side_a_info) == 3:
side_a_shelf = side_a_info[0]
side_a_resource = side_a_info[1]
side_a_name = side_a_info[2]
elif len(side_a_info) == 2:
side_a_shelf = 1
side_a_resource = side_a_info[0]
side_a_name = side_a_info[1]
else:
raise ValueError("side_a must have a shelf and/or resource number")
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)
if len(side_b_info) == 3:
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = side_b_info[2]
else:
side_b_shelf = 1
side_b_resource = side_b_info[0]
side_b_name = side_b_info[1]
self.created_cx[port_name + "L3"] = [side_a_name + "-A", side_a_name + "-B"]
side_b_shelf = side_b_info[0]
side_b_resource = side_b_info[1]
side_b_name = side_b_info[2]
cx_name = "%s%s" % (self.name_prefix, port_name)
self.created_cx[ cx_name ] = [side_a_name + "-A", side_a_name + "-B"]
endp_side_a = {
"alias": side_b_name + "-A",
"shelf": side_a_shelf,
"shelf": 1,
"resource": side_a_resource,
"port": side_a_name,
"port": side_a_info[2],
"type": endp_type,
"min_rate": self.side_a_min_bps,
"max_rate": self.side_a_max_bps,
@@ -415,9 +438,9 @@ class L3CXProfile(LFCliBase):
}
endp_side_b = {
"alias": side_b_name + "-B",
"shelf": side_b_shelf,
"shelf": 1,
"resource": side_b_resource,
"port": side_b_name,
"port": side_b_info[2],
"type": endp_type,
"min_rate": self.side_b_min_bps,
"max_rate": self.side_b_max_bps,
@@ -427,8 +450,9 @@ class L3CXProfile(LFCliBase):
}
url = "/cli-json/add_endp"
self.local_realm.json_post(url, endp_side_a)
self.local_realm.json_post(url, endp_side_b)
self.local_realm.json_post(url, endp_side_a, debug_=debug_, suppress_related_commands_=suppress_related_commands)
self.local_realm.json_post(url, endp_side_b, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print("napping %f sec" %sleep_time )
time.sleep(sleep_time)
url = "cli-json/set_endp_flag"
@@ -437,7 +461,7 @@ class L3CXProfile(LFCliBase):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data)
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
url = "cli-json/set_endp_flag"
data = {
@@ -445,8 +469,8 @@ class L3CXProfile(LFCliBase):
"flag": "autohelper",
"val": 1
}
self.local_realm.json_post(url, data)
cx_name = self.local_realm.name_to_eid(port_name)[-1] + "L3"
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print("CXNAME451: %s" % cx_name)
data = {
"alias": cx_name,
"test_mgr": "default_tm",
@@ -465,15 +489,17 @@ class L3CXProfile(LFCliBase):
print("post_data", cx_post_data)
for data in cx_post_data:
url = "/cli-json/add_cx"
self.local_realm.json_post(url, data)
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands)
#print(" napping %f sec"%sleep_time, end='')
time.sleep(sleep_time)
#print("")
def to_string(self):
pprint.pprint(self)
class L4CXProfile(LFCliBase):
def __init__(self, lfclient_host, lfclient_port, local_realm,debug_=False):
def __init__(self, lfclient_host, lfclient_port, local_realm, debug_=False):
super().__init__(lfclient_host, lfclient_port, debug_, _halt_on_error=True)
self.lfclient_url = "http://%s:%s" % (lfclient_host, lfclient_port)
self.debug = debug_
@@ -481,7 +507,7 @@ class L4CXProfile(LFCliBase):
self.requests_per_ten = 600
self.local_realm = local_realm
def create(self, ports=[], sleep_time=.5):
def create(self, ports=[], sleep_time=.5, debug_=False, suppress_related_commands_=None):
cx_post_data = []
for port_name in ports:
endp_data = {
@@ -495,7 +521,7 @@ class L4CXProfile(LFCliBase):
"url": self.url
}
url = "cli-json/add_l4_endp"
self.local_realm.json_post(url, endp_data)
self.local_realm.json_post(url, endp_data, debug_=debug_, suppress_related_commands_=suppress_related_commands_)
time.sleep(sleep_time)
endp_data = {
@@ -508,7 +534,7 @@ class L4CXProfile(LFCliBase):
for cx_data in cx_post_data:
url = "/cli-json/add_cx"
self.local_realm.json_post(url, cx_data)
self.local_realm.json_post(url, cx_data, debug_=debug_, suppress_related_commands_=suppress_related_commands_)
time.sleep(sleep_time)
@@ -526,7 +552,9 @@ class GenCXProfile(LFCliBase):
self.cmd = ""
self.local_realm = local_realm
def create(self, ports=[], sleep_time=.5):
def create(self, ports=[], sleep_time=.5, debug_=False, suppress_related_commands_=None):
if self.debug:
debug_ = True;
post_data = []
for port_name in ports:
gen_name = self.local_realm.name_to_eid(port_name)[-1] + "_gen0"
@@ -550,7 +578,7 @@ class GenCXProfile(LFCliBase):
for data in post_data:
url = "/cli-json/add_cx"
self.local_realm.json_post(url, data)
self.local_realm.json_post(url, data, debug_=debug_, suppress_related_commands_=suppress_related_commands_)
time.sleep(sleep_time)
@@ -565,7 +593,7 @@ class GenCXProfile(LFCliBase):
# profile.build(resource, radio, 64)
#
class StationProfile:
def __init__(self, lfclient_url, ssid="NA", ssid_pass="NA", security="open", prefix="00000", mode=0, up=True,
def __init__(self, lfclient_url, ssid="NA", ssid_pass="NA", security="open", number_template_="00000", mode=0, up=True,
dhcp=True, debug_=False):
self.debug = debug_
self.lfclient_url = lfclient_url
@@ -578,7 +606,8 @@ class StationProfile:
self.COMMANDS = ["add_sta", "set_port"]
self.desired_add_sta_flags = ["wpa2_enable", "80211u_enable", "create_admin_down"]
self.desired_add_sta_flags_mask = ["wpa2_enable", "80211u_enable", "create_admin_down"]
self.prefix = prefix
self.number_template = number_template_
self.station_names = []
self.add_sta_data = {
"shelf": 1,
"resource": 1,
@@ -590,6 +619,7 @@ class StationProfile:
"mac": "xx:xx:xx:xx:*:xx",
"flags": 0, # (0x400 + 0x20000 + 0x1000000000) # create admin down
}
self.desired_set_port_cmd_flags = []
self.desired_set_port_current_flags = ["if_down"]
self.desired_set_port_interest_flags = ["current_flags", "ifdown"]
if self.dhcp:
@@ -604,7 +634,10 @@ class StationProfile:
"interest": 0, # (0x2 + 0x4000 + 0x800000) # current, dhcp, down,
}
# TODO: create use_wpa3()
def use_wpa2(self, on=False, ssid=None, passwd=None):
self.add_sta_data["ssid"] = ssid
if on:
if (ssid is None) or ("" == ssid):
raise ValueError("use_wpa2: WPA2 requires ssid")
@@ -612,8 +645,10 @@ class StationProfile:
raise ValueError("use_wpa2: WPA2 requires passphrase or [BLANK]")
self.set_command_param("add_sta", "ssid", ssid)
self.set_command_param("add_sta", "key", passwd)
self.set_command_flag("add_sta", "wpa2_enable", 1)
self.add_sta_data["key"] = passwd
else:
self.set_command_flag("add_sta", "flags", "wpa2_enable", 0)
self.set_command_flag("add_sta", "wpa2_enable", 0)
def set_command_param(self, command_name, param_name, param_value):
# we have to check what the param name is
@@ -645,9 +680,9 @@ class StationProfile:
pprint(add_sta.add_sta_flags)
return
if (value == 1) and (param_name not in self.desired_add_sta_flags):
self.desired_add_sta_flags_flags.append(param_name)
self.desired_add_sta_flags.append(param_name)
elif value == 0:
self.desired_set_port_flags_flags.remove(param_name)
self.desired_add_sta_flags.remove(param_name)
elif command_name == "set_port":
if (param_name not in set_port.set_port_current_flags) and (param_name not in set_port.set_port_cmd_flags):
@@ -657,16 +692,28 @@ class StationProfile:
pprint(set_port.set_port_current_flags)
pprint(set_port.set_port_interest_flags)
return
if (value == 1) and (param_name not in self.desired_set_port_flags):
self.desired_set_port_flags_flags.append(param_name)
elif value == 0:
self.desired_set_port_flags_flags.remove(param_name)
if (param_name in set_port.set_port_cmd_flags):
if (value == 1) and (param_name not in self.desired_set_port_cmd_flags):
self.desired_set_port_cmd_flags.append(param_name)
elif value == 0:
self.desired_set_port_cmd_flags.remove(param_name)
elif (param_name in set_port.set_port_current_flags):
if (value == 1) and (param_name not in self.desired_set_port_current_flags):
self.desired_set_port_current_flags.append(param_name)
elif value == 0:
self.desired_set_port_current_flags.remove(param_name)
elif (param_name in set_port.set_port_interest_flags):
if (value == 1) and (param_name not in self.desired_set_port_interest_flags):
self.desired_set_port_interest_flags.append(param_name)
elif value == 0:
self.desired_set_port_interest_flags.remove(param_name)
else:
raise ValueError("Unknown param name: "+param_name)
# use this for hinting station name; stations begin with 'sta', the
# stations created with a prefix '0100' indicate value 10100 + n with
# resulting substring(1,) applied; station 900 becomes 'sta1000'
def set_prefix(self, pref):
self.prefix = pref
def set_number_template(self, pref):
self.number_template = pref
def add_named_flags(self, desired_list, command_ref):
if desired_list is None:
@@ -689,8 +736,16 @@ class StationProfile:
return result
def admin_up(self, resource):
set_port_r = LFRequest.LFRequest(self.lfclient_url, "/cli-json/set_port", debug_=self.debug)
for sta_name in self.station_names:
req_json = LFUtils.portUpRequest(resource, sta_name, debug_on=False)
set_port_r.addPostData(req_json)
json_response = set_port_r.jsonPost(self.debug)
time.sleep(0.03)
# Checks for errors in initialization values and creates specified number of stations using init parameters
def create(self, resource, radio, num_stations=0, sta_names_=None, dry_run=False, debug=False):
def create(self, resource, radio, num_stations=0, sta_names_=None, dry_run=False, up_=None, debug=False):
# try:
# resource = resource_radio[0: resource_radio.index(".")]
# name = resource_radio[resource_radio.index(".") + 1:]
@@ -699,9 +754,18 @@ class StationProfile:
# print("Building %s on radio %s.%s" % (num_stations, resource, radio_name))
# except ValueError as e:
# print(e)
if up_ is not None:
self.up = up_
if (sta_names_ is None) and (num_stations == 0):
raise ValueError("StationProfile.create needs either num_stations= or sta_names_= specified")
if self.up:
if "create_admin_down" in self.desired_add_sta_flags:
del self.desired_add_sta_flags["create_admin_down"]
elif "create_admin_down" not in self.desired_add_sta_flags:
self.desired_add_sta_flags.append("create_admin_down")
# create stations down, do set_port on them, then set stations up
self.add_sta_data["flags"] = self.add_named_flags(self.desired_add_sta_flags, add_sta.add_sta_flags)
self.add_sta_data["flags_mask"] = self.add_named_flags(self.desired_add_sta_flags_mask, add_sta.add_sta_flags)
@@ -714,19 +778,20 @@ class StationProfile:
add_sta_r = LFRequest.LFRequest(self.lfclient_url + "/cli-json/add_sta")
set_port_r = LFRequest.LFRequest(self.lfclient_url + "/cli-json/set_port")
sta_names = None
self.station_names = []
if num_stations > 0:
sta_names = LFUtils.portNameSeries("sta", 0, num_stations - 1, int("1"+self.prefix))
self.station_names = LFUtils.portNameSeries("sta", 0, num_stations - 1, int("1" + self.number_template))
else:
sta_names = sta_names_
if len(sta_names) >= 50:
self.station_names = sta_names_
if len(self.station_names) >= 50:
self.add_sta_data["suppress_preexec_cli"] = "yes"
self.add_sta_data["suppress_preexec_method"] = 1
self.set_port_data["suppress_preexec_cli"] = "yes"
self.set_port_data["suppress_preexec_method"] = 1
num = 0
for name in sta_names:
for name in self.station_names:
num += 1
self.add_sta_data["sta_name"] = name
if debug:
@@ -747,18 +812,18 @@ class StationProfile:
json_response = set_port_r.jsonPost(debug)
time.sleep(.03)
LFUtils.waitUntilPortsAppear(resource, self.lfclient_url, sta_names)
LFUtils.waitUntilPortsAppear(resource, self.lfclient_url, self.station_names)
# and set ports up
if dry_run:
return
for sta_name in sta_names:
req = LFUtils.portUpRequest(resource, sta_name, debug_on=False)
set_port_r.addPostData(req)
json_response = set_port_r.jsonPost(debug)
time.sleep(0.03)
if (self.up):
self.admin_up()
# for sta_name in self.station_names:
# req = LFUtils.portUpRequest(resource, sta_name, debug_on=False)
# set_port_r.addPostData(req)
# json_response = set_port_r.jsonPost(debug)
# time.sleep(0.03)
print("created %s stations" % num)

View File

@@ -55,7 +55,7 @@ print("** Creating Stations **")
profile = localrealm.new_station_profile()
profile.use_wpa2(True, "jedway-wpa2-x2048-5-1", "jedway-wpa2-x2048-5-1")
profile.set_command_flag("add_sta", "80211u_enable", 1)
profile.set_prefix("0100")
profile.set_number_template("0100")
profile.create(1, "wiphy0", 5)
try:

View File

@@ -33,14 +33,14 @@ class StaConnect2(LFCliBase):
def __init__(self, host, port, _dut_ssid="MyAP", _dut_passwd="NA", _dut_bssid="",
_user="", _passwd="", _sta_mode="0", _radio="wiphy0",
_resource=1, _upstream_resource=1, _upstream_port="eth2",
_sta_name=None, _debugOn=False, _dut_security=OPEN, _exit_on_error=False,
_sta_name=None, debug_=False, _dut_security=OPEN, _exit_on_error=False,
_cleanup_on_exit=True, _runtime_sec=60, _exit_on_fail=False):
# do not use `super(LFCLiBase,self).__init__(self, host, port, _debugOn)
# that is py2 era syntax and will force self into the host variable, making you
# very confused.
super().__init__(host, port, _debug=_debugOn, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
self.debugOn = _debugOn
self.dut_security = ""
super().__init__(host, port, _debug=debug_, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
self.debug = debug_
self.dut_security = _dut_security
self.dut_ssid = _dut_ssid
self.dut_passwd = _dut_passwd
self.dut_bssid = _dut_bssid
@@ -62,6 +62,9 @@ class StaConnect2(LFCliBase):
self.localrealm = Realm(lfclient_host=host, lfclient_port=port) # py > 3.6
self.resulting_stations = {}
self.resulting_endpoints = {}
self.sta_profile = None
self.l3_udp_profile = None
self.l3_tcp_profile = None
# def get_realm(self) -> Realm: # py > 3.6
def get_realm(self):
@@ -125,64 +128,68 @@ class StaConnect2(LFCliBase):
return False
if upstream_json['interface']['ip'] == "0.0.0.0":
pprint.pprint(upstream_json)
if self.debug:
pprint.pprint(upstream_json)
self._fail("Warning: %s lacks ip address" % self.get_upstream_url(), print_=True)
return False
# remove old stations
print("removing old station")
print("Removing old stations")
for sta_name in self.station_names:
sta_url = self.get_station_url(sta_name)
response = self.json_get(sta_url)
if response is not None:
if response["interface"] is not None:
for sta_name in self.station_names:
LFUtils.removePort(self.resource, sta_name, self.lfclient_url)
LFUtils.wait_until_ports_disappear(self.resource, self.lfclient_url, self.station_names)
if (response is not None) and (response["interface"] is not None):
for sta_name in self.station_names:
LFUtils.removePort(self.resource, sta_name, self.lfclient_url)
LFUtils.wait_until_ports_disappear(self.resource, self.lfclient_url, self.station_names)
# Create stations and turn dhcp on
sta_profile = self.localrealm.new_station_profile()
self.station_profile = self.localrealm.new_station_profile()
if self.dut_security == WPA2:
sta_profile.use_wpa2(on=True, ssid=self.dut_ssid, passwd=self.dut_passwd)
self.station_profile.use_wpa2(on=True, ssid=self.dut_ssid, passwd=self.dut_passwd)
elif self.dut_security == OPEN:
sta_profile.use_wpa2(on=False, ssid=self.dut_ssid)
sta_profile.set_command_flag("add_sta", "create_admin_down", 1)
self.station_profile.use_wpa2(on=False, ssid=self.dut_ssid)
self.station_profile.set_command_flag("add_sta", "create_admin_down", 1)
print("Adding new stations ", end="")
sta_profile.create(resource=self.resource, radio=self.radio, sta_names_=self.station_names)
self.station_profile.create(resource=self.resource, radio=self.radio, sta_names_=self.station_names, up_=False, debug=False)
LFUtils.wait_until_ports_appear(self.resource, self.lfclient_url, self.station_names)
# Create endpoints and cxs
# Create UDP endpoints
l3_udp_profile = self.localrealm.new_l3_cx_profile()
l3_udp_profile.side_a_min_bps = 128000
l3_udp_profile.side_b_min_bps = 128000
l3_udp_profile.side_a_min_pdu = 1200
l3_udp_profile.side_b_min_pdu = 1500
l3_udp_profile.report_timer = 1000
l3_udp_profile.prefix = "udp_"
l3_udp_profile.create(endp_type="lf_udp",
side_a=list(self.localrealm.find_ports_like("sta+")),
side_b="%d.%s" % (self.resource, self.upstream_port))
self.l3_udp_profile = self.localrealm.new_l3_cx_profile()
self.l3_udp_profile.side_a_min_bps = 128000
self.l3_udp_profile.side_b_min_bps = 128000
self.l3_udp_profile.side_a_min_pdu = 1200
self.l3_udp_profile.side_b_min_pdu = 1500
self.l3_udp_profile.report_timer = 1000
self.l3_udp_profile.name_prefix = "udp"
self.l3_udp_profile.create(endp_type="lf_udp",
side_a=list(self.localrealm.find_ports_like("sta+")),
side_b="%d.%s" % (self.resource, self.upstream_port),
suppress_related_commands=True)
# Create TCP endpoints
l3_tcp_profile = self.localrealm.new_l3_cx_profile()
l3_tcp_profile.side_a_min_bps = 128000
l3_tcp_profile.side_b_min_bps = 56000
l3_tcp_profile.prefix = "tcp_"
l3_tcp_profile.report_timer = 1000
self.l3_tcp_profile = self.localrealm.new_l3_cx_profile()
self.l3_tcp_profile.side_a_min_bps = 128000
self.l3_tcp_profile.side_b_min_bps = 56000
self.l3_tcp_profile.name_prefix = "tcp"
self.l3_tcp_profile.report_timer = 1000
self.l3_tcp_profile.create(endp_type="lf_tcp",
side_a=list(self.localrealm.find_ports_like("sta+")),
side_b="%d.%s" % (self.resource, self.upstream_port),
suppress_related_commands=True)
def start(self):
# print("\nBringing ports up...")
# data = {"shelf": 1,
# "resource": self.resource,
# "port": "ALL",
# "probe_flags": 1}
# self.json_post("/cli-json/nc_show_ports", data)
# LFUtils.waitUntilPortsAdminUp(self.resource, self.lfclient_url, self.station_names)
if not self.station_profile.up:
print("\nBringing ports up...")
data = {"shelf": 1,
"resource": self.resource,
"port": "ALL",
"probe_flags": 1}
self.json_post("/cli-json/nc_show_ports", data)
self.station_profile.admin_up(self.resource)
LFUtils.waitUntilPortsAdminUp(self.resource, self.lfclient_url, self.station_names)
# station_info = self.jsonGet(self.mgr_url, "%s?fields=port,ip,ap" % (self.getStaUrl()))
duration = 0
@@ -191,40 +198,37 @@ class StaConnect2(LFCliBase):
ap = ""
print("Waiting for %s stations to associate to AP: " % len(self.station_names), end="")
connected_stations = {}
# while (len(connected_stations.keys()) < len(self.station_names)) and (duration < maxTime):
# duration += 3
# time.sleep(3)
# print(".", end="")
# for sta_name in self.station_names:
# sta_url = self.get_station_url(sta_name)
# station_info = self.json_get(sta_url + "?fields=port,ip,ap")
#
# # LFUtils.debug_printer.pprint(station_info)
# if (station_info is not None) and ("interface" in station_info):
# if "ip" in station_info["interface"]:
# ip = station_info["interface"]["ip"]
# if "ap" in station_info["interface"]:
# ap = station_info["interface"]["ap"]
#
# if (ap == "Not-Associated") or (ap == ""):
# if self.debugOn:
# print(" -%s," % sta_name, end="")
# else:
# if ip == "0.0.0.0":
# if self.debugOn:
# print(" %s (0.0.0.0)" % sta_name, end="")
# else:
# connected_stations[sta_name] = sta_url
# data = {
# "shelf":1,
# "resource": self.resource,
# "port": "ALL",
# "probe_flags": 1
# }
# self.json_post("/cli-json/nc_show_ports", data)
while (len(connected_stations.keys()) < len(self.station_names)) and (duration < maxTime):
duration += 3
time.sleep(3)
print(".", end="")
for sta_name in self.station_names:
sta_url = self.get_station_url(sta_name)
station_info = self.json_get(sta_url + "?fields=port,ip,ap")
# make a copy of the connected stations for test records
# LFUtils.debug_printer.pprint(station_info)
if (station_info is not None) and ("interface" in station_info):
if "ip" in station_info["interface"]:
ip = station_info["interface"]["ip"]
if "ap" in station_info["interface"]:
ap = station_info["interface"]["ap"]
if (ap == "Not-Associated") or (ap == ""):
if self.debug:
print(" -%s," % sta_name, end="")
else:
if ip == "0.0.0.0":
if self.debug:
print(" %s (0.0.0.0)" % sta_name, end="")
else:
connected_stations[sta_name] = sta_url
data = {
"shelf":1,
"resource": self.resource,
"port": "ALL",
"probe_flags": 1
}
self.json_post("/cli-json/nc_show_ports", data)
for sta_name in self.station_names:
sta_url = self.get_station_url(sta_name)
@@ -258,82 +262,61 @@ class StaConnect2(LFCliBase):
self.remove_stations()
return False
# start cx traffic
print("\nStarting CX Traffic")
# for cx_name in cx_names.keys():
# data = {
# "test_mgr": "ALL",
# "cx_name": cx_name,
# "cx_state": "RUNNING"
# }
# self.json_post("/cli-json/set_cx_state", data)
self.l3_udp_profile.start_cx()
self.l3_tcp_profile.start_cx()
time.sleep(1)
# Refresh stats
self.l3_udp_profile.refresh_cx()
self.l3_tcp_profile.refresh_cx()
def collect_endp_stats(self, endp_map):
print("Collecting Data")
fields="?fields=name,tx+bytes,rx+bytes"
for (cx_name, endps) in endp_map.items():
try:
endp_url = "/endp/%s%s" % (endps[0], fields)
endp_json = self.json_get(endp_url)
self.resulting_endpoints[endp_url] = endp_json
ptest_a_tx = endp_json['endpoint']['tx bytes']
ptest_a_rx = endp_json['endpoint']['rx bytes']
#ptest = self.json_get("/endp/%s?fields=tx+bytes,rx+bytes" % cx_names[cx_name]["b"])
endp_url = "/endp/%s%s" % (endps[1], fields)
endp_json = self.json_get(endp_url)
self.resulting_endpoints[endp_url] = endp_json
ptest_b_tx = endp_json['endpoint']['tx bytes']
ptest_b_rx = endp_json['endpoint']['rx bytes']
self.compare_vals("testTCP-A TX", ptest_a_tx)
self.compare_vals("testTCP-A RX", ptest_a_rx)
self.compare_vals("testTCP-B TX", ptest_b_tx)
self.compare_vals("testTCP-B RX", ptest_b_rx)
except Exception as e:
self.error(e)
print("Refresh CX stats")
# for cx_name in cx_names.keys():
# data = {
# "test_mgr": "ALL",
# "cross_connect": cx_name
# }
# self.json_post("/cli-json/show_cxe", data)
def stop(self):
# stop cx traffic
print("Stopping CX Traffic")
# for cx_name in cx_names.keys():
# data = {
# "test_mgr": "ALL",
# "cx_name": cx_name,
# "cx_state": "STOPPED"
# }
# self.json_post("/cli-json/set_cx_state", data)
self.l3_udp_profile.stop_cx()
self.l3_tcp_profile.stop_cx()
# Refresh stats
print("\nRefresh CX stats")
# for cx_name in cx_names.keys():
# data = {
# "test_mgr": "ALL",
# "cross_connect": cx_name
# }
# self.json_post("/cli-json/show_cxe", data)
self.l3_udp_profile.refresh_cx()
self.l3_tcp_profile.refresh_cx()
# print("Sleeping for 5 seconds")
print("Sleeping for 5 seconds")
time.sleep(5)
# get data for endpoints JSON
print("Collecting Data")
# for cx_name in cx_names.keys():
# try:
# # ?fields=tx+bytes,rx+bytes
# endp_url = "/endp/%s" % cx_names[cx_name]["a"]
# ptest = self.json_get(endp_url)
# self.resulting_endpoints[endp_url] = ptest
#
# ptest_a_tx = ptest['endpoint']['tx bytes']
# ptest_a_rx = ptest['endpoint']['rx bytes']
#
# #ptest = self.json_get("/endp/%s?fields=tx+bytes,rx+bytes" % cx_names[cx_name]["b"])
# endp_url = "/endp/%s" % cx_names[cx_name]["b"]
# ptest = self.json_get(endp_url)
# self.resulting_endpoints[endp_url] = ptest
#
# ptest_b_tx = ptest['endpoint']['tx bytes']
# ptest_b_rx = ptest['endpoint']['rx bytes']
#
# self.compare_vals("testTCP-A TX", ptest_a_tx)
# self.compare_vals("testTCP-A RX", ptest_a_rx)
#
# self.compare_vals("testTCP-B TX", ptest_b_tx)
# self.compare_vals("testTCP-B RX", ptest_b_rx)
#
# except Exception as e:
# self.error(e)
# Examples of what happens when you add test results that do not begin with PASS
# self.test_results.append("Neutral message will fail")
# self.test_results.append("FAILED message will fail")
self.collect_endp_stats(self.l3_udp_profile.created_cx)
self.collect_endp_stats(self.l3_tcp_profile.created_cx)
# print("\n")
def cleanup(self):
@@ -342,10 +325,12 @@ class StaConnect2(LFCliBase):
for sta_name in self.station_names:
LFUtils.removePort(self.resource, sta_name, self.lfclient_url)
endp_names = []
removeCX(self.lfclient_url, cx_names.keys())
for cx_name in cx_names:
endp_names.append(cx_names[cx_name]["a"])
endp_names.append(cx_names[cx_name]["b"])
removeCX(self.lfclient_url, self.l3_udp_profile.get_cx_names())
removeCX(self.lfclient_url, self.l3_tcp_profile.get_cx_names())
for (cx_name, endp_names) in self.l3_udp_profile.created_cx.items():
endp_names.append(endp_names[0])
endp_names.append(endp_names[1])
removeEndps(self.lfclient_url, endp_names)
# ~class
@@ -373,8 +358,10 @@ Example:
parser.add_argument("--sta_mode", type=str,
help="LANforge station-mode setting (see add_sta LANforge CLI documentation, default is 0 (auto))")
parser.add_argument("--dut_ssid", type=str, help="DUT SSID")
parser.add_argument("--dut_security", type=str, help="DUT security: openLF, wpa, wpa2, wpa3")
parser.add_argument("--dut_passwd", type=str, help="DUT PSK password. Do not set for OPEN auth")
parser.add_argument("--dut_bssid", type=str, help="DUT BSSID to which we expect to connect.")
parser.add_argument("--debug", type=str, help="enable debugging")
args = parser.parse_args()
if args.dest is not None:
@@ -382,7 +369,13 @@ Example:
if args.port is not None:
lfjson_port = args.port
staConnect = StaConnect2(lfjson_host, lfjson_port)
on_flags = [ 1, "1", "on", "yes", "true" ]
debug_v = False
if args.debug is not None:
if args.debug in on_flags:
debug_v = True
staConnect = StaConnect2(lfjson_host, lfjson_port, debug_=debug_v)
staConnect.station_names = [ "sta0000" ]
if args.user is not None:
staConnect.user = args.user
@@ -398,16 +391,18 @@ Example:
staConnect.radio = args.radio
if args.resource is not None:
staConnect.resource = args.resource
if args.dut_ssid is not None:
staConnect.dut_ssid = args.dut_ssid
if args.dut_passwd is not None:
staConnect.dut_passwd = args.dut_passwd
if args.dut_bssid is not None:
staConnect.dut_bssid = args.dut_bssid
if args.dut_ssid is not None:
staConnect.dut_ssid = args.dut_ssid
if args.dut_security is not None:
staConnect.dut_security = args.dut_security
staConnect.setup()
staConnect.start()
print("napping %f sec" % staConnect.runtime_secs)
time.sleep(staConnect.runtime_secs)
staConnect.stop()
run_results = staConnect.get_result_list()

View File

@@ -31,13 +31,13 @@ class IPv4Test(LFCliBase):
self.prefix = prefix
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
self.profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
security=self.security, prefix=self.prefix, mode=0, up=True, dhcp=True,
security=self.security, number_template_=self.prefix, mode=0, up=True, dhcp=True,
debug_=False)
def build(self):
# Build stations
self.profile.use_wpa2(True, self.ssid, self.password)
self.profile.set_prefix(self.prefix)
self.profile.set_number_template(self.prefix)
print("Creating stations")
self.profile.set_command_flag("add_sta", "create_admin_down", 1)
self.profile.create(resource=1, radio="wiphy0", sta_names_=self.sta_list, debug=False)

View File

@@ -33,7 +33,7 @@ class IPV4VariableTime(LFCliBase):
self.prefix = prefix
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
self.station_profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
security=self.security, prefix=self.prefix, mode=0, up=True,
security=self.security, number_template_=self.prefix, mode=0, up=True,
dhcp=True,
debug_=False)
self.cx_profile = realm.L3CXProfile(self.host, self.port, self.local_realm, side_a_min_bps=side_a_min_rate,
@@ -163,7 +163,7 @@ class IPV4VariableTime(LFCliBase):
sta_list = []
self.station_profile.use_wpa2(True, self.ssid, self.password)
self.station_profile.set_prefix(self.prefix)
self.station_profile.set_number_template(self.prefix)
print("Creating stations")
self.station_profile.create(resource=1, radio="wiphy0", num_stations=self.num_stations, debug=False)

View File

@@ -33,7 +33,7 @@ class IPV6VariableTime(LFCliBase):
self.prefix = prefix
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
self.station_profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
security=self.security, prefix=self.prefix, mode=0, up=True,
security=self.security, number_template_=self.prefix, mode=0, up=True,
dhcp=True,
debug_=False)
self.cx_profile = realm.L3CXProfile(self.host, self.port, self.local_realm, side_a_min_rate=side_a_min_rate,
@@ -163,7 +163,7 @@ class IPV6VariableTime(LFCliBase):
sta_list = []
self.station_profile.use_wpa2(True, self.ssid, self.password)
self.station_profile.set_prefix(self.prefix)
self.station_profile.set_number_template(self.prefix)
print("Creating stations")
self.station_profile.create(resource=1, radio="wiphy0", num_stations=self.num_stations, debug=False)

View File

@@ -30,7 +30,7 @@ class LANtoWAN(LFCliBase):
self.wan_port = wan_port
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
self.profile = realm.StationProfile(self.lfclient_url, ssid=self.ssid, ssid_pass=self.password,
security=self.security, prefix=self.prefix, mode=0, up=True, dhcp=True,
security=self.security, number_template_=self.prefix, mode=0, up=True, dhcp=True,
debug_=False)
self.cxProfile = realm.new_l3_cx_profile()