mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-10-29 18:02:35 +00:00
Updated cli args to match example_wpa_connection.py
This commit is contained in:
@@ -1,158 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pprint
|
||||
import os
|
||||
|
||||
|
||||
if sys.version_info[0] != 3:
|
||||
print("This script requires Python 3")
|
||||
exit(1)
|
||||
|
||||
if 'py-json' not in sys.path:
|
||||
sys.path.append(os.path.join(os.path.abspath('.'),'py-json'))
|
||||
|
||||
pprint.pprint(sys.path)
|
||||
import argparse
|
||||
#import LANforge
|
||||
from LANforge import LFUtils
|
||||
from LANforge import lfcli_base
|
||||
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
|
||||
import LANforge
|
||||
from LANforge.lfcli_base import LFCliBase
|
||||
from LANforge.LFUtils import *
|
||||
import realm
|
||||
from realm import Realm
|
||||
from LANforge import LFUtils
|
||||
import realm
|
||||
import argparse
|
||||
import time
|
||||
import pprint
|
||||
|
||||
|
||||
class IPv4Test(LFCliBase):
|
||||
def __init__(self, host, port, ssid, security, password, num_stations=0, prefix="00000", _debug_on=False,
|
||||
def __init__(self, host, port, ssid, security, password, sta_list=None, number_template="00000", _debug_on=False,
|
||||
_exit_on_error=False,
|
||||
_exit_on_fail=False):
|
||||
#initializes LFCliBase init
|
||||
super().__init__(host, port, _debug=_debug_on, _halt_on_error=_exit_on_error, _exit_on_fail=_exit_on_fail)
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.ssid = ssid
|
||||
self.security = security
|
||||
self.password = password
|
||||
self.num_stations = num_stations
|
||||
self.sta_list = sta_list
|
||||
self.timeout = 120
|
||||
self.prefix = prefix
|
||||
self.number_template = number_template
|
||||
self.debug = _debug_on
|
||||
self.local_realm = Realm(lfclient_host=host,lfclient_port=port)
|
||||
self.profile = self.local_realm.new_station_profile()
|
||||
self.local_realm = realm.Realm(lfclient_host=self.host, lfclient_port=self.port)
|
||||
self.station_profile = self.local_realm.new_station_profile()
|
||||
|
||||
|
||||
def check_association(self, sta_list, print_pass, print_fail):
|
||||
"""
|
||||
Usage:
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
|
||||
TODO: Currently N/A
|
||||
"""
|
||||
|
||||
associated_map = {}
|
||||
ip_map = {}
|
||||
|
||||
for sec in range(self.timeout):
|
||||
|
||||
for sta_name in sta_list:
|
||||
|
||||
sta_status = self.json_get("port/1/1/" + sta_name+"?fields=port,alias,ip,ap")
|
||||
pprint.pprint(sta_status)
|
||||
|
||||
if (sta_status is None) or (sta_status['interface'] is None) or (sta_status['interface']['ap'] is None):
|
||||
continue
|
||||
|
||||
if len(sta_status['interface']['ap']) == 17 and sta_status['interface']['ap'][-3] == ':' :
|
||||
#print("Associated", sta_name, sta_status['interface']['ap'], sta_status['interface']['ip'])
|
||||
associated_map[sta_name] = 1
|
||||
|
||||
if sta_status['interface']['ip'] != '0.0.0.0':
|
||||
#print("IP", sta_name, sta_status['interface']['ap'], sta_status['interface']['ip'])
|
||||
associated_map[sta_name] = 1
|
||||
ip_map[sta_name] = 1
|
||||
if len(sta_list) == len(ip_map) and len(sta_list) == len(associated_map):
|
||||
break
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
if len(sta_list) == len(ip_map) and len(sta_list) == len(associated_map):
|
||||
self._pass("PASS: All stations associated with IP", print_pass)
|
||||
else:
|
||||
self._fail("FAIL: Not all stations able to associate/get IP", print_fail)
|
||||
|
||||
return self.passes()
|
||||
|
||||
def cleanup(self):
|
||||
"""
|
||||
Usage:
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
|
||||
TODO: Currently N/A
|
||||
"""
|
||||
port_list = self.local_realm.station_list()
|
||||
sta_list = []
|
||||
for item in list(port_list):
|
||||
#print(list(item))
|
||||
if "sta" in list(item)[0]:
|
||||
sta_list.append(self.local_realm.name_to_eid(list(item)[0])[2])
|
||||
|
||||
for sta_name in sta_list:
|
||||
req_url = "cli-json/rm_vlan"
|
||||
data = {
|
||||
"shelf": 1,
|
||||
"resource": 1,
|
||||
"port": sta_name
|
||||
}
|
||||
# print(data)
|
||||
super().json_post(req_url, data)
|
||||
|
||||
def start(self):
|
||||
self.profile.admin_up(resource=1)
|
||||
LFUtils.waitUntilPortsAdminUp(resource_id=1, base_url=self.lfclient_url, port_list = self.profile.station_names)
|
||||
self.check_association(sta_list = self.profile.station_names, print_pass = True, print_fail = True)
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
self.station_profile.lfclient_url = self.lfclient_url
|
||||
self.station_profile.ssid = self.ssid
|
||||
self.station_profile.ssid_pass = self.password,
|
||||
self.station_profile.security = self.security
|
||||
self.station_profile.number_template_ = self.number_template
|
||||
self.station_profile.mode = 0
|
||||
|
||||
def build(self):
|
||||
"""
|
||||
Usage:
|
||||
|
||||
Args:
|
||||
|
||||
Returns:
|
||||
|
||||
TODO: Currently N/A
|
||||
|
||||
"""
|
||||
super().clear_test_results()
|
||||
print("Cleaning up old stations")
|
||||
self.cleanup()
|
||||
sta_list = []
|
||||
self.profile.use_wpa2(False, self.ssid)
|
||||
|
||||
# Build stations
|
||||
self.station_profile.use_security(self.security, self.ssid, self.password)
|
||||
self.station_profile.set_number_template(self.number_template)
|
||||
print("Creating stations")
|
||||
self.profile.create(resource=1, radio="wiphy0", num_stations=self.num_stations, debug=True)
|
||||
LFUtils.wait_until_ports_appear(resource_id=1, base_url=self.lfclient_url, port_list=self.profile.station_names, debug=False)
|
||||
self._pass("stations created")
|
||||
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.create(radio="wiphy0", sta_names_=self.sta_list, debug=self.debug)
|
||||
self._pass("PASS: Station build finished")
|
||||
self.station_profile.admin_up()
|
||||
|
||||
def cleanup(self, sta_list):
|
||||
self.station_profile.cleanup(sta_list)
|
||||
LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=sta_list,
|
||||
debug=self.debug)
|
||||
|
||||
def main():
|
||||
lfjson_host = "localhost"
|
||||
lfjson_port = 8080
|
||||
ip_test = IPv4Test(lfjson_host, lfjson_port, ssid="jedway-open", password="[BLANK]", num_stations=1,
|
||||
security="open")
|
||||
ip_test.cleanup()
|
||||
|
||||
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_wpa_connection.py
|
||||
--------------------
|
||||
|
||||
Generic command example:
|
||||
python3 ./example_open_connection.py \\
|
||||
--host localhost (optional) \\
|
||||
--port 8080 (optional) \\
|
||||
--num_stations 3 \\
|
||||
--security {open|wep|wpa|wpa2|wpa3} \\
|
||||
--ssid netgear-open \\
|
||||
--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_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(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd,
|
||||
security=args.security, sta_list=station_list)
|
||||
ip_test.cleanup(station_list)
|
||||
ip_test.timeout = 60
|
||||
ip_test.build()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -12,6 +12,7 @@ import LANforge
|
||||
from LANforge.lfcli_base import LFCliBase
|
||||
from LANforge import LFUtils
|
||||
import realm
|
||||
import argparse
|
||||
import time
|
||||
import pprint
|
||||
|
||||
@@ -59,16 +60,47 @@ class IPv4Test(LFCliBase):
|
||||
def main():
|
||||
lfjson_host = "localhost"
|
||||
lfjson_port = 8080
|
||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000)
|
||||
ip_test = IPv4Test(lfjson_host, lfjson_port, ssid="jedway-wep-48", password="0123456789",
|
||||
security="wep", sta_list=station_list)
|
||||
|
||||
parser = LFCliBase.create_basic_argparse(
|
||||
prog='example_wep_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 WEP 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-wep \\
|
||||
--passwd admin123-wep \\
|
||||
--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_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(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd,
|
||||
security=args.security, sta_list=station_list)
|
||||
ip_test.cleanup(station_list)
|
||||
ip_test.timeout = 60
|
||||
ip_test.build()
|
||||
time.sleep(30)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -12,6 +12,7 @@ import LANforge
|
||||
from LANforge.lfcli_base import LFCliBase
|
||||
from LANforge import LFUtils
|
||||
import realm
|
||||
import argparse
|
||||
import time
|
||||
import pprint
|
||||
|
||||
@@ -59,13 +60,47 @@ class IPv4Test(LFCliBase):
|
||||
def main():
|
||||
lfjson_host = "localhost"
|
||||
lfjson_port = 8080
|
||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000)
|
||||
ip_test = IPv4Test(lfjson_host, lfjson_port, ssid="jedway-wpa2-x2048-4-4", password="jedway-wpa2-x2048-4-4",
|
||||
security="wpa2", sta_list=station_list)
|
||||
|
||||
parser = LFCliBase.create_basic_argparse(
|
||||
prog='example_wpa2_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 WPA2 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-wpa2 \\
|
||||
--passwd admin123-wpa2 \\
|
||||
--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_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(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd,
|
||||
security=args.security, sta_list=station_list)
|
||||
ip_test.cleanup(station_list)
|
||||
ip_test.timeout = 60
|
||||
ip_test.build()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -11,6 +11,7 @@ import LANforge
|
||||
from LANforge.lfcli_base import LFCliBase
|
||||
from LANforge import LFUtils
|
||||
import realm
|
||||
import argparse
|
||||
import time
|
||||
import pprint
|
||||
|
||||
@@ -59,14 +60,47 @@ class IPv4Test(LFCliBase):
|
||||
def main():
|
||||
lfjson_host = "localhost"
|
||||
lfjson_port = 8080
|
||||
station_list = LFUtils.portNameSeries(prefix_="sta", start_id_=0, end_id_=1, padding_number_=10000)
|
||||
ip_test = IPv4Test(lfjson_host, lfjson_port, ssid="jedway-wpa3-44", password="jedway-wpa3-44",
|
||||
security="wpa3", sta_list=station_list,_debug_on=False)
|
||||
#print("created IPv4Test object")
|
||||
|
||||
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_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(lfjson_host, lfjson_port, ssid=args.ssid, password=args.passwd,
|
||||
security=args.security, sta_list=station_list)
|
||||
ip_test.cleanup(station_list)
|
||||
ip_test.timeout = 60
|
||||
ip_test.build()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user