def pre_cleanup(self): self.cx_profile.cleanup_prefix() for sta in self.sta_list: self.local_realm.rm_port(sta, check_exists=True, debug_=self.debug) LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=self.sta_list, debug=self.debug)
def postcleanup(self): self.station_profile.cleanup() LFUtils.wait_until_ports_disappear( base_url=self.lfclient_url, port_list=self.station_profile.station_names, debug=self.debug) print("Test Completed")
def cleanup(self): self.cx_profile.cleanup() self.station_profile.cleanup() LFUtils.wait_until_ports_disappear( base_url=self.lfclient_url, port_list=self.station_profile.station_names, debug=self.debug)
def setup(self): self.clear_test_results() self.check_connect() upstream_json = self.json_get("%s?fields=alias,phantom,down,port,ip" % self.get_upstream_url(), debug_=False) if upstream_json is None: self._fail(message="Unable to query %s, bye" % self.upstream_port, print_=True) return False if upstream_json['interface']['ip'] == "0.0.0.0": 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 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) 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.lfclient_url, self.station_names) # Create stations and turn dhcp on self.station_profile = self.localrealm.new_station_profile() # Build stations self.station_profile.use_security(self.security, self.ssid, passwd="[BLANK]") self.station_profile.set_number_template(self.number_template) print("Creating stations") 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) self.station_profile.set_wifi_extra(key_mgmt=self.key_mgmt, eap=self.eap, identity=self.identity, passwd=self.ttls_passwd, realm=self.ttls_realm, domain=self.domain, hessid=self.hessid) self.station_profile.create(radio=self.radio, sta_names_=self.sta_list, debug=self.debug, use_radius=True, hs20_enable=False) self._pass("PASS: Station build finished")
def cleanup(self, sta_list): self.endp_profile.cleanup() self.ro_profile.cleanup() self.station_profile.cleanup(sta_list) LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list, debug=self.debug) self.mvlan_profile.cleanup()
def cleanup(self): for sta_name in self.station_names: LFUtils.removePort(self.resource, sta_name, self.lfclient_url) endp_names = [] removeCX(self.lfclient_url, self.cx_names.keys()) for cx_name in self.cx_names: endp_names.append(self.cx_names[cx_name]["a"]) endp_names.append(self.cx_names[cx_name]["b"]) removeEndps(self.lfclient_url, endp_names)
def start(self, print_pass=False, print_fail=False): self.station_profile.admin_up() temp_stas = [] for station in self.sta_list.copy(): temp_stas.append(self.local_realm.name_to_eid(station)[2]) pprint.pprint(self.station_profile.station_names) LFUtils.wait_until_ports_admin_up( base_url=self.lfclient_url, port_list=self.station_profile.station_names) if self.local_realm.wait_for_ip(temp_stas): self._pass("All stations got IPs", print_pass) else: self._fail("Stations failed to get IPs", print_fail) exit(1) cur_time = datetime.datetime.now() passes = 0 expected_passes = 0 self.generic_endps_profile.start_cx() time.sleep(15) end_time = self.local_realm.parse_time("30s") + cur_time print("Starting Test...") result = False while cur_time < end_time: cur_time = datetime.datetime.now() if self.generic_endps_profile.type == "lfping": result = self.choose_ping_command() elif self.generic_endps_profile.type == "generic": result = self.choose_generic_command() elif self.generic_endps_profile.type == "lfcurl": result = self.choose_lfcurl_command() elif self.generic_endps_profile.type == "speedtest": result = self.choose_speedtest_command() elif self.generic_endps_profile.type == "iperf3": result = self.choose_iperf3_command() else: continue expected_passes += 1 # pprint.pprint(result) if result is not None: if result[0]: passes += 1 else: self._fail( "%s Failed to ping %s " % (result[1], self.generic_endps_profile.dest), print_fail) break # print(cur_time) # print(end_time) time.sleep(1) if passes == expected_passes: self._pass("PASS: All tests passed", print_pass)
def cleanup_tcp(self): # remove all endpoints and cxs if self.cleanup_on_exit: for sta_name in self.station_names: LFUtils.removePort(self.resource, sta_name, self.lfclient_url) curr_endp_names = [] removeCX(self.lfclient_url, self.l3_tcp_tput_profile.get_cx_names()) for (cx_name, endp_names) in self.l3_tcp_tput_profile.created_cx.items(): curr_endp_names.append(endp_names[0]) curr_endp_names.append(endp_names[1]) removeEndps(self.lfclient_url, curr_endp_names, debug=self.debug)
def stop(self): self.cx_profile.stop_cx() for station_list in self.station_lists: for station_name in station_list: data = LFUtils.portDownRequest(1, station_name) url = "cli-json/set_port" self.json_post(url, data)
def start(self, print_pass=False, print_fail=False): print("Bringing up stations") up_request = LFUtils.port_up_request(resource_id=self.resource, port_name=self.side_b) self.local_realm.json_post("/cli-json/set_port", up_request) for station_profile, station_list in zip(self.station_profiles, self.station_lists): if self.debug: print("Bringing up station {}".format(station_profile)) station_profile.admin_up(self.resource) if self.local_realm.wait_for_ip(self.resource, station_list, timeout_sec=10 * len(station_list)): if self.debug: print("ip's aquired {}".format(station_list)) else: print("print failed to get IP's: {}".format(station_list)) if self.local_realm.wait_for_ip(self.resource, station_list, timeout_sec=120): print("tried again: print failed to get IP's: {}".format( station_list)) exit(1) self.cx_profile.start_cx() cur_time = datetime.datetime.now() old_rx_values = self.__get_rx_values() filtered_old_rx_values = [] filtered_old_rx_values = old_rx_values end_time = self.local_realm.parse_time(self.test_duration) + cur_time passes = 0 expected_passes = 0 while cur_time < end_time: interval_time = cur_time + datetime.timedelta(minutes=1) while cur_time < interval_time: cur_time = datetime.datetime.now() time.sleep(1) new_rx_values = self.__get_rx_values() filtered_new_rx_values = [] filtered_new_rx_values = new_rx_values expected_passes += 1 if self.__compare_vals(filtered_old_rx_values, filtered_new_rx_values): passes += 1 else: self._fail("FAIL: Not all stations increased traffic", print_fail) break old_rx_values = new_rx_values cur_time = datetime.datetime.now() if passes == expected_passes: self._pass("PASS: All tests passed", print_pass)
def main(): # create multiple OPEN stations station_names = LFUtils.port_name_series(start_id=0, end_id=1) test = StaConnect("localhost", 8080, _debugOn=False, _exit_on_error=True, _cleanup_on_exit=False, _runtime_sec=360, _exit_on_fail=True) test.sta_mode = sta_connect.MODE_AUTO test.upstream_resource = 1 test.upstream_port = "eth1" test.radio = "wiphy0" test.resource = 1 test.dut_security = sta_connect.OPEN test.dut_ssid = "jedway-open" test.dut_passwd = "[BLANK]" test.station_names = station_names test.runtime_secs = 5 test.cleanup_on_exit = True test.run() is_passing = test.passes() # recorded stations and endpoints can be retrieved this way: ''' for sta_name in test.resulting_stations: print("** recorded: "+sta_name) pprint.pprint(test.resulting_stations[sta_name]) for endp_name in test.resulting_endpoints: print("** endp: "+endp_name) pprint.pprint(test.resulting_endpoints[endp_name]) ''' if is_passing == False: # run_results = staConnect.get_failed_result_list() fail_message = test.get_fail_message() print("Some tests failed:\n" + fail_message) return else: print("Tests pass") # Stations use WPA2 test.dut_security = sta_connect.WPA2 test.dut_ssid = "jedway-wpa2-x2048-5-1" test.dut_passwd = "jedway-wpa2-x2048-5-1" test.run() is_passing = test.passes() if is_passing == False: # run_results = staConnect.get_failed_result_list() fail_message = test.get_fail_message() print("Some tests failed:\n" + fail_message) return else: print("Tests pass") if test.cleanup_on_exit == True: test.remove_stations()
def main(): lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='test_ipv6_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Create stations that attempt to authenticate, associate, and receive IPV6 addresses on the chosen SSID ''', description='''\ test_ipv6_connection.py: -------------------- Generic command example: python3 ./test_ipv6_connection.py --upstream_port eth1 \\ --radio wiphy0 \\ --num_stations 3 \\ --security {open|wep|wpa|wpa2|wpa3} \\ --ssid netgear \\ --passwd admin123 \\ --dest 10.40.0.1 \\ --test_duration 2m \\ --interval 1s \\ -- timeout 120 \\ --debug ''') parser.add_argument('--timeout', help='--timeout sets the length of time to wait until a connection is successful', default=120) args = parser.parse_args() num_sta=2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta-1, padding_number_=10000, radio=args.radio) ipv6_test = IPv6Test(host=args.mgr, port=args.mgr_port, ssid=args.ssid, password=args.passwd, security=args.security, sta_list=station_list) ipv6_test.cleanup(station_list) ipv6_test.build() if not ipv6_test.passes(): print(ipv6_test.get_fail_message()) exit(1) ipv6_test.start(station_list, False, False) ipv6_test.stop() if not ipv6_test.passes(): print(ipv6_test.get_fail_message()) exit(1) time.sleep(10) ipv6_test.cleanup(station_list) if ipv6_test.passes(): print("Full test passed, all stations associated and got IP")
def stop(self): self.cx_profile.stop_cx() for sta_name in self.sta_list: data = LFUtils.port_down_request( 1, self.local_realm.name_to_eid(sta_name)[2]) url = "cli-json/set_port" self.json_post(url, data)
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='example_wpa_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Example code that creates a specified amount of stations on a specified SSID using WPA security. ''', description='''\ example_wpa_connection.py -------------------- Generic command example: python3 ./example_wpa_connection.py \\ --host localhost (optional) \\ --port 8080 (optional) \\ --num_stations 3 \\ --ssid netgear-wpa \\ --passwd admin123-wpa \\ --radio wiphy1 --debug ''') parser.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="5m") parser.add_argument( '--url', help='--url specifies upload/download, address, and dest', default="dl http://10.40.0.1 /dev/null") args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, radio=args.radio) ip_test = IPv4Test(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd, radio=args.radio, security="wpa", sta_list=station_list) ip_test.cleanup(station_list) ip_test.timeout = 60 ip_test.build()
def precleanup(self): print("precleanup started") sta_list = [] for i in self.local_realm.station_list(): if list(i.keys())[0] == '1.1.wlan0': pass elif list(i.keys())[0] == '1.1.wlan1': pass else: sta_list.append(list(i.keys())[0]) print(sta_list) for sta in sta_list: self.local_realm.rm_port(sta, check_exists=True) time.sleep(1) LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list, debug=self.debug) print("precleanup done")
def build(self): data = { "name": "BLANK", "action": "overwrite", "clean_dut": "yes", "clean_chambers": "yes" } self.json_post("/cli-json/load", data) sleep(1) port_counter = 0 attempts = 6 while (attempts > 0) and (port_counter > 0): sleep(1) attempts -= 1 print("looking for ports like vap+") port_list = self.localrealm.find_ports_like("vap+") alias_map = LFUtils.portListToAliasMap(port_list) port_counter = len(alias_map) port_list = self.localrealm.find_ports_like("sta+") alias_map = LFUtils.portListToAliasMap(port_list) port_counter += len(alias_map) if port_counter == 0: break if (port_counter != 0) and (attempts == 0): print("There appears to be a vAP in this database, quitting.") pprint(alias_map) exit(1) data = { "name": self.lanforge_db, "action": "overwrite", "clean_dut": "yes", "clean_chambers": "yes" } self.json_post("/cli-json/load", data) sleep(1) self._pass("Loaded scenario %s" % self.lanforge_db, True) return True
def cleanup(self): # Removing Connections self.local_realm.cleanup_cxe_prefix(self.cx_profile.name_prefix) vap = self.local_realm.find_ports_like("vap+") bridges = self.local_realm.find_ports_like("br+") station_map = self.local_realm.find_ports_like("sta+") #Removing Bridges for eid, record in bridges.items(): self.local_realm.remove_vlan_by_eid(eid) time.sleep(0.03) #Removing VAP for eid, record in vap.items(): self.local_realm.remove_vlan_by_eid(eid) time.sleep(0.03) #Removing stations for eid, record in station_map.items(): self.local_realm.remove_vlan_by_eid(eid) time.sleep(0.03) del_sta_names = [] try: for eid, value in station_map.items(): tname = eid[eid.rfind('.'):] del_sta_names.append(tname) except Exception as x: self.local_realm.error(x) try: LFUtils.waitUntilPortsDisappear( base_url=self.local_realm.lfclient_url, port_list=del_sta_names, debug=True) print("Ports Successfully Cleaned up") return 0 except: print("Ports Successfully Cleaned up") time.sleep(5) return 0
def build(self): # refactor in LFUtils.port_zero_request() resource = 1 data ={ 'shelf':1, 'resource':1, 'port':'eth1', 'ip_addr':'0.0.0.0', 'netmask':'0.0.0.0', 'gateway':'0.0.0.0', 'current_flags':0, 'interest':402653212 } url = "cli-json/set_port" self.json_post(url, data) # refactor into LFUtils data ={ "shelf":1, "resource": resource, "port":"br0", "network_devs":"eth1", "br_flags":1 } url = "cli-json/add_br" self.json_post(url, data) try: data = LFUtils.port_dhcp_up_request(resource, self.side_b) self.json_post("/cli-json/set_port", data) except: print("LFUtils.port_dhcp_up_request didn't complete ") print("or the json_post failed either way {} did not set up dhcp so test may not pass data ".format(self.side_b)) resource = 1 index = 0 for station_profile, station_list in zip(self.station_profiles, self.station_lists): station_profile.use_security(station_profile.security, station_profile.ssid, station_profile.ssid_pass) station_profile.set_number_template(station_profile.number_template) print("radio: {} station_profile: {} Creating stations: {} ".format(self.radio_list[index],station_profile, station_list)) temp_station_list = [] for station in range(len(station_list)): temp_station_list.append(str(self.resource) + "." + station_list[station]) station_profile.create(resource=1, radio=self.radio_list[index], sta_names_=station_list, debug=False ) index += 1 self.cx_profile.create(endp_type=self.endp_type, side_a=temp_station_list, side_b='1.'+self.side_b, sleep_time=.5) self._pass("PASS: Stations build finished")
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='example_wpa3_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Example code that creates a specified amount of stations on a specified SSID using WPA3 security. ''', description='''\ example_wpa_connection.py -------------------- Generic command example: python3 ./example_wpa_connection.py \\ --host localhost (optional) \\ --port 8080 (optional) \\ --num_stations 3 \\ --security {open|wep|wpa|wpa2|wpa3} \\ --ssid netgear-wpa3 \\ --passwd admin123-wpa3 \\ --debug Note: multiple --radio switches may be entered up to the number of radios available: --radio wiphy0 <stations> <ssid> <ssid password> --radio <radio 01> <number of last station> <ssid> <ssid password> ''') args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, radio=args.radio) ip_test = IPv4Test(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd, radio=args.radio, security=args.security, sta_list=station_list) ip_test.cleanup(station_list) ip_test.timeout = 60 ip_test.build()
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='example_security_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Example flags and command line input to run the script. ''', description='''\ example_security_connection.py -------------------- This python script creates an inputted number of stations using user-inputted security. This verifies that the most basic form of security works with the LANforge device. -------------------- Generic command example: python3 ./example_security_connection.py \\ --host localhost (optional) \\ --port 8080 (optional) \\ --num_stations 6 \\ --radio wiphy2 --security {open|wep|wpa|wpa2|wpa3} \\ --ssid netgear-wpa3 \\ --passwd admin123-wpa3 \\ --debug ''') args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta-1, padding_number_=10000, radio=args.radio) ip_test = IPv4Test(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd, radio=args.radio, security=args.security, sta_list=station_list) ip_test.cleanup(station_list) ip_test.timeout = 60 ip_test.build()
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='example_wpa3_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Example code that creates a specified amount of stations on a specified SSID using WPA3 security. ''', description='''\ example_wpa3_connection.py -------------------- Generic command example: python3 ./example_wpa3_connection.py --host localhost (optional) --port 8080 (optional) --num_stations 3 --ssid netgear-wpa3 --passwd admin123-wpa3 --radio wiphy1 --debug ''') args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, radio=args.radio) ip_test = IPv4Test(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd, radio=args.radio, security="wpa3", sta_list=station_list) ip_test.cleanup(station_list) ip_test.timeout = 60 ip_test.build()
def main(): parser = LFCliBase.create_basic_argparse( prog='example_open_connection.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Example code that creates a specified amount of stations on a specified SSID using Open security. ''', description='''\ example_open_connection.py -------------------- Generic command example: python3 ./example_open_connection.py --mgr localhost --mgr_port 8080 --num_stations 3 --radio wiphy1 --ssid netgear-open --passwd [BLANK] --debug ''') args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_sta = int(args.num_stations) station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta-1, padding_number_=10000) ip_test = IPv4Test(host=args.mgr, port=args.mgr_port, ssid=args.ssid, password=args.passwd, security="open", radio=args.radio, sta_list=station_list) ip_test.cleanup(station_list) ip_test.timeout = 60 ip_test.build()
# convert station map to plain list del_sta_names = [] try: for eid, value in station_map.items(): #print("jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj") #pprint(eid) #print("rfind: %d" % ) #print("jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj") tname = eid[eid.rfind('.'):] del_sta_names.append(tname) except Exception as x: localrealm.error(x) LFUtils.waitUntilPortsDisappear(resource_id=1, base_url=localrealm.lfclient_url, port_list=del_sta_names, debug=False) 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_number_template("0100") profile.create(1, "wiphy0", 5) try: sta_list = localrealm.station_list() print("%s Stations:" % {len(sta_list)}) pprint(sta_list) print(" Stations like wlan+:") print(localrealm.find_ports_like("wlan+")) print(" Stations like wlan0:")
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='test_ipv4_l4_wifi.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Create layer-4 endpoints and test that the bytes-rd from the chosen URL are increasing over the duration of the test ''', description='''\ test_ipv4_l4_wifi.py: -------------------- Generic command example: python3 ./test_ipv4_l4_wifi.py --upstream_port eth1 \\ --radio wiphy0 \\ --num_stations 3 \\ --security {open|wep|wpa|wpa2|wpa3} \\ --ssid netgear \\ --passwd admin123 \\ --test_duration 2m \\ --requests_per_ten 600 \\ --direction {ul | dl} \\ --dest /dev/null (or 10.40.0.1)\\ --debug ''') parser.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="5m") parser.add_argument( '--requests_per_ten', help='--requests_per_ten number of request per ten minutes', default=600) parser.add_argument( '--direction', help='--direction <ul | dl> specifies upload or download', default="dl") parser.add_argument( '--dest', help= '--dest specifies the destination (dl) or source (ul) for the file', default="/dev/null") args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, radio=args.radio) ip_test = IPV4L4(host=args.mgr, port=args.mgr_port, ssid=args.ssid, password=args.passwd, radio=args.radio, security=args.security, station_list=station_list, direction=args.direction, dest=args.dest, test_duration=args.test_duration, upstream_port=args.upstream_port, requests_per_ten=args.requests_per_ten, _debug_on=args.debug) ip_test.cleanup(station_list) ip_test.build() if not ip_test.passes(): print(ip_test.get_fail_message()) ip_test.exit_fail() ip_test.start(False, False) ip_test.stop() if not ip_test.passes(): print(ip_test.get_fail_message()) ip_test.exit_fail() time.sleep(30) ip_test.cleanup(station_list) if ip_test.passes(): ("Full test passed, all endpoints had increased bytes-rd throughout test duration" ) ip_test.exit_success()
def main(): parser = LFCliBase.create_basic_argparse( prog='test_generic.py', formatter_class=argparse.RawTextHelpFormatter, epilog= '''Create generic endpoints and test for their ability to execute chosen commands\n''', description='''test_generic.py -------------------- Generic command example: python3 ./test_generic.py --mgr localhost (optional) --mgr_port 4122 (optional) --upstream_port eth1 (optional) --radio wiphy0 (required) --num_stations 3 (optional) --security {open|wep|wpa|wpa2|wpa3} (required) --ssid netgear (required) --passwd admin123 (required) --type lfping {generic|lfping|iperf3-client | speedtest | lf_curl} (required) --dest 10.40.0.1 (required - also target for iperf3) --test_duration 2m --interval 1s --debug Example commands: LFPING: ./test_generic.py --mgr localhost --mgr_port 4122 --radio wiphy0 --num_stations 7 --ssid jedway-wpa2-x2048-4-1 --passwd jedway-wpa2-x2048-4-1 --type lfping --dest 10.40.0.1 --security wpa2 LFCURL (under construction): ./test_generic.py --mgr localhost --mgr_port 4122 --radio wiphy1 --num_stations 26 --ssid jedway-wpa2-x2048-4-1 --passwd jedway-wpa2-x2048-4-1 --security wpa2 --type lfcurl --dest 10.40.0.1 GENERIC: ./test_generic.py --mgr localhost--mgr_port 4122 --radio wiphy1 --num_stations 2 --ssid jedway-wpa2-x2048-4-1 --passwd jedway-wpa2-x2048-4-1 --security wpa2 --type generic SPEEDTEST: ./test_generic.py --mgr localhost --mgr_port 4122 --radio wiphy2 --num_stations 13 --ssid jedway-wpa2-x2048-4-1 --passwd jedway-wpa2-x2048-4-1 --type speedtest --speedtest_min_up 20 --speedtest_min_dl 20 --speedtest_max_ping 150 --security wpa2 IPERF3 (under construction): ./test_generic.py --mgr localhost --mgr_port 4122 --radio wiphy1 --num_stations 3 --ssid jedway-wpa2-x2048-4-1 --passwd jedway-wpa2-x2048-4-1 --security wpa2 --type iperf3 ''') required = parser.add_argument_group('required arguments') required.add_argument( '--security', help='WiFi Security protocol: < open | wep | wpa | wpa2 | wpa3 >', required=True) parser.add_argument( '--type', help= 'type of command to run: generic, lfping, iperf3-client, iperf3-server, lfcurl', default="lfping") parser.add_argument( '--cmd', help='specifies command to be run by generic type endp', default='') parser.add_argument('--dest', help='destination IP for command', default="10.40.0.1") parser.add_argument('--test_duration', help='duration of the test eg: 30s, 2m, 4h', default="2m") parser.add_argument('--interval', help='interval to use when running lfping (1s, 1m)', default=1) parser.add_argument( '--speedtest_min_up', help='sets the minimum upload threshold for the speedtest type', default=None) parser.add_argument( '--speedtest_min_dl', help='sets the minimum download threshold for the speedtest type', default=None) parser.add_argument( '--speedtest_max_ping', help='sets the minimum ping threshold for the speedtest type', default=None) parser.add_argument('--client', help='client to the iperf3 server', default=None) args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(radio=args.radio, prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=100) generic_test = GenTest(host=args.mgr, port=args.mgr_port, number_template="00", radio=args.radio, sta_list=station_list, name_prefix="GT", type=args.type, dest=args.dest, cmd=args.cmd, interval=1, ssid=args.ssid, upstream=args.upstream_port, passwd=args.passwd, security=args.security, test_duration=args.test_duration, speedtest_min_up=args.speedtest_min_up, speedtest_min_dl=args.speedtest_min_dl, speedtest_max_ping=args.speedtest_max_ping, client=args.client, _debug_on=args.debug) generic_test.cleanup(station_list) generic_test.build() if not generic_test.passes(): print(generic_test.get_fail_message()) generic_test.exit_fail() generic_test.start() if not generic_test.passes(): print(generic_test.get_fail_message()) generic_test.exit_fail() generic_test.stop() time.sleep(30) generic_test.cleanup(station_list) if generic_test.passes(): generic_test.exit_success()
def start(self): if self.station_profile is None: self._fail("Incorrect setup") pprint.pprint(self.station_profile) if self.station_profile.up is None: self._fail("Incorrect station profile, missing profile.up") if self.station_profile.up == False: 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() 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 maxTime = 60 ip = "0.0.0.0" 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.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) station_info = self.json_get(sta_url) # + "?fields=port,ip,ap") if station_info is None: print("unable to query %s" % sta_url) self.resulting_stations[sta_url] = station_info ap = station_info["interface"]["ap"] ip = station_info["interface"]["ip"] if (ap != "") and (ap != "Not-Associated"): print(" %s +AP %s, " % (sta_name, ap), end="") if self.dut_bssid != "": if self.dut_bssid.lower() == ap.lower(): self._pass(sta_name + " connected to BSSID: " + ap) # self.test_results.append("PASSED: ) # print("PASSED: Connected to BSSID: "+ap) else: self._fail( "%s connected to wrong BSSID, requested: %s Actual: %s" % (sta_name, self.dut_bssid, ap)) else: self._fail(sta_name + " did not connect to AP") return False if ip == "0.0.0.0": self._fail("%s did not get an ip. Ending test" % sta_name) else: self._pass("%s connected to AP: %s With IP: %s" % (sta_name, ap, ip)) if self.passes() == False: if self.cleanup_on_exit: print("Cleaning up...") self.remove_stations() return False # start cx traffic print("\nStarting CX Traffic") self.create_traffic.l3_udp_profile.start_cx() self.create_traffic.l3_tcp_profile.start_cx() time.sleep(1) self.create_traffic.l3_tcp_profile.refresh_cx() self.create_traffic.l3_udp_profile.refresh_cx()
def remove_stations(self): for name in self.station_names: LFUtils.removePort(self.resource, name, self.lfclient_url)
def setup(self): self.clear_test_results() self.check_connect() upstream_json = self.json_get("%s?fields=alias,phantom,down,port,ip" % self.get_upstream_url(), debug_=False) if upstream_json is None: self._fail(message="Unable to query %s, bye" % self.upstream_port, print_=True) return False if upstream_json['interface']['ip'] == "0.0.0.0": 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 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) 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.lfclient_url, self.station_names) # Create stations and turn dhcp on self.station_profile = self.localrealm.new_station_profile() if self.dut_security == WPA2: self.station_profile.use_security(security_type="wpa2", ssid=self.dut_ssid, passwd=self.dut_passwd) elif self.dut_security == WPA: self.station_profile.use_security(security_type="wpa", ssid=self.dut_ssid, passwd=self.dut_passwd) elif self.dut_security == OPEN: self.station_profile.use_security(security_type="open", ssid=self.dut_ssid, passwd="[BLANK]") elif self.dut_security == WPA: self.station_profile.use_security(security_type="wpa", ssid=self.dut_ssid, passwd=self.dut_passwd) elif self.dut_security == WEP: self.station_profile.use_security(security_type="wep", ssid=self.dut_ssid, passwd=self.dut_passwd) self.station_profile.set_command_flag("add_sta", "create_admin_down", 1) print("Adding new stations ", end="") self.station_profile.create(radio=self.radio, sta_names_=self.station_names, up_=False, debug=self.debug, suppress_related_commands_=True) LFUtils.wait_until_ports_appear(self.lfclient_url, self.station_names, debug=self.debug)
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='test_ipv4_ttls.py', #formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''Demonstration showing wpa2-ent ttls authentication''', description='''\ test_ipv4_ttls.py: -------------------- Generic command layout: python ./test_ipv4_ttls.py --upstream_port <port> --radio <radio 0> --num_stations 3 --ssid ssid-wpa-1 --keyphrase ssid-wpa-1 --security <security type: wpa2, open, wpa3> --debug ''') 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="5m") parser.add_argument('--key-mgmt', help="--key-mgt: { %s }" % ", ".join(realm.wpa_ent_list()), default="WPA-EAP") parser.add_argument('--wpa_psk', help='wpa-ent pre shared key', default="[BLANK]") parser.add_argument('--eap', help='--eap eap method to use', default="TTLS") parser.add_argument('--identity', help='--identity eap identity string', default="testuser") parser.add_argument('--ttls_passwd', help='--ttls_passwd eap password string', default="testpasswd") parser.add_argument('--ttls_realm', help='--ttls_realm 802.11u home realm to use', default="localhost.localdomain") parser.add_argument('--domain', help='--domain 802.11 domain to use', default="localhost.localdomain") parser.add_argument( '--hessid', help='--hessid 802.11u HESSID (MAC addr format/peer for WDS)', default="00:00:00:00:00:01") parser.add_argument( '--ieee80211w', help='--ieee80211w <disabled(0),optional(1),required(2)', default='1') parser.add_argument('--use_hs20', help='use HotSpot 2.0', default=False) parser.add_argument('--enable_pkc', help='enable opportunistic PMKSA WPA2 key caching', default=False) args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000) ttls_test = TTLSTest( host=args.mgr, port=args.mgr_port, ssid=args.ssid, password=args.passwd, security=args.security, sta_list=station_list, radio=args.radio, key_mgmt=args.key_mgmt, wpa_psk=args.wpa_psk, eap=args.eap, identity=args.identity, ttls_passwd=args.ttls_passwd, ttls_realm=args.ttls_realm, domain=args.domain, hessid=args.hessid, ieee80211w=args.ieee80211w, hs20_enable=args.use_hs20, enable_pkc=args.enable_pkc, ) ttls_test.cleanup(station_list) ttls_test.build() if not ttls_test.passes(): print(ttls_test.get_fail_message()) exit(1) ttls_test.start(station_list, False, False) ttls_test.stop() if not ttls_test.passes(): print(ttls_test.get_fail_message()) exit(1) time.sleep(30) ttls_test.cleanup(station_list) if ttls_test.passes(): print("Full test passed, all stations associated and got IP")
def main(): lfjson_host = "localhost" lfjson_port = 8080 parser = LFCliBase.create_basic_argparse( prog='test_generic.py', # formatter_class=argparse.RawDescriptionHelpFormatter, formatter_class=argparse.RawTextHelpFormatter, epilog='''\ Create layer-4 endpoints and test that the bytes-rd from the chosen URL are increasing over the duration of the test ''', description='''\ test_ipv4_l4.py -------------------- Generic command layout: python ./test_ipv4_l4.py --upstream_port <port> --radio <radio 0> <stations> <ssid> <ssid password> <security type: wpa2, open, wpa3> --debug Command Line Example: python3 ./test_ipv4_l4.py --upstream_port eth1 (optional) --radio wiphy0 (required) --num_stations 3 (optional) --security {open|wep|wpa|wpa2|wpa3} (required) --ssid netgear (required) --url "dl http://10.40.0.1 /dev/null" (required) --password admin123 (required) --test_duration 2m (optional) --debug (optional) ''') parser.add_argument('--test_duration', help='--test_duration sets the duration of the test', default="5m") parser.add_argument( '--url', help='--url specifies upload/download, address, and dest', default="dl http://10.40.0.1 /dev/null") args = parser.parse_args() num_sta = 2 if (args.num_stations is not None) and (int(args.num_stations) > 0): num_stations_converted = int(args.num_stations) num_sta = num_stations_converted station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, radio=args.radio) ip_test = IPV4L4(host=args.mgr, port=args.mgr_port, ssid=args.ssid, radio=args.radio, password=args.passwd, security=args.security, station_list=station_list, url=args.url, test_duration=args.test_duration, upstream_port=args.upstream_port, _debug_on=args.debug) ip_test.cleanup(station_list) ip_test.build() if not ip_test.passes(): print(ip_test.get_fail_message()) ip_test.exit_fail() ip_test.start(False, False) ip_test.stop() if not ip_test.passes(): print(ip_test.get_fail_message()) ip_test.exit_fail() time.sleep(30) ip_test.cleanup(station_list) if ip_test.passes(): print( "Full test passed, all endpoints had increased bytes-rd throughout test duration" ) ip_test.exit_success()