- test_wanlink.py may now run with optional latency arguments:

* as together endpoints: --latency, the value of wanlink delay of both endpoints in ms.
	* as separate endpoints: --latency_A and/or --latency_B which default to the value of --latency.
	* the value of --latency is 20 (ms) by default.
 - Arguments passed from the command line into LANtoWAN are simplified into a single container args.
 - Several arguments of LANtoWAN are instead initialized as data members.
 - create_wanlink.py no longer attempts to alter the wanlink after creating it.
 - create_wanlink.py outputs less to the terminal.

Signed-off-by: Erin Grimes <erin.grimes@candelatech.com>
This commit is contained in:
Erin Grimes
2021-07-07 14:03:31 -07:00
parent 10d51764dc
commit b857d695b9
2 changed files with 73 additions and 115 deletions

View File

@@ -1,17 +1,12 @@
#!/usr/bin/python3 #!/usr/bin/python3
# Create and modify WAN Links Using LANforge JSON AP : http://www.candelatech.com/cookbook.php?vol=cli&book=JSON:+Managing+WANlinks+using+JSON+and+Python # Create and modify WAN Links Using LANforge JSON AP : http://www.candelatech.com/cookbook.php?vol=cli&book=JSON:+Managing+WANlinks+using+JSON+and+Python
# Written by Candela Technologies Inc. # Written by Candela Technologies Inc.
# Updated by: # Updated by: Erin Grimes
import sys import sys
import urllib import urllib
if sys.version_info[0] != 3: if sys.version_info[0] != 3:
print("This script requires Python 3") print("This script requires Python 3")
exit() exit()
import time import time
from time import sleep from time import sleep
from urllib import error from urllib import error
@@ -25,16 +20,19 @@ j_printer = pprint.PrettyPrinter(indent=2)
# typically you're using resource 1 in stand alone realm # typically you're using resource 1 in stand alone realm
resource_id = 1 resource_id = 1
def main(base_url="http://localhost:8080"): def main(base_url="http://localhost:8080", args={}):
json_post = "" json_post = ""
json_response = "" json_response = ""
num_wanlinks = -1 num_wanlinks = -1
# see if there are old wanlinks to remove # see if there are old wanlinks to remove
lf_r = LFRequest.LFRequest(base_url+"/wl/list") lf_r = LFRequest.LFRequest(base_url+"/wl/list")
print(lf_r.get_as_json()) print(lf_r.get_as_json())
# ports to set as endpoints
port_a ="rd0a" port_a ="rd0a"
port_b ="rd1a" port_b ="rd1a"
try: try:
json_response = lf_r.getAsJson() json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response) LFUtils.debug_printer.pprint(json_response)
@@ -75,7 +73,7 @@ def main(base_url="http://localhost:8080"):
'shelf': 1, 'shelf': 1,
'resource': '1', 'resource': '1',
'port': port_a, 'port': port_a,
'latency': '75', 'latency': args['latency_A'],
'max_rate': '128000', 'max_rate': '128000',
'description': 'cookbook-example' 'description': 'cookbook-example'
}) })
@@ -89,7 +87,7 @@ def main(base_url="http://localhost:8080"):
'shelf': 1, 'shelf': 1,
'resource': '1', 'resource': '1',
'port': port_b, 'port': port_b,
'latency': '95', 'latency': args['latency_B'],
'max_rate': '256000', 'max_rate': '256000',
'description': 'cookbook-example' 'description': 'cookbook-example'
}) })
@@ -134,6 +132,7 @@ def main(base_url="http://localhost:8080"):
continue continue
print("starting wanlink:") print("starting wanlink:")
# print("the latency is {laten}".format(laten=latency))
lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_cx_state") lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_cx_state")
lf_r.addPostData({ lf_r.addPostData({
'test_mgr': 'all', 'test_mgr': 'all',
@@ -163,25 +162,7 @@ def main(base_url="http://localhost:8080"):
print("Error code "+error.code) print("Error code "+error.code)
continue continue
print("Wanlink is running, wait one sec...") print("Wanlink is running")
sleep(1)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Now we can alter the delay and speed of the wanlink by
# updating its endpoints see https://www.candelatech.com/lfcli_ug.php#set_wanlink_info
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
print("Updating Wanlink...")
lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_wanlink_info")
lf_r.addPostData({
'name': 'wl_eg1-A',
'speed': 265333,
'latency': 30,
'reorder_freq': 3200, # thats 3200/1000000
'drop_freq': 2000, # 2000/1000000
'dup_freq': 1325, # 1325/1000000
'jitter_freq': 25125, # 25125/1000000
})
lf_r.jsonPost()
sleep(1)
# stop wanlink # stop wanlink
lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_cx_state") lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_cx_state")
@@ -214,20 +195,19 @@ def main(base_url="http://localhost:8080"):
print("Wanlink is stopped.") print("Wanlink is stopped.")
print("Wanlink info:") # print("Wanlink info:")
lf_r = LFRequest.LFRequest(base_url+"/wl/wl_eg1") # lf_r = LFRequest.LFRequest(base_url+"/wl/wl_eg1")
json_response = lf_r.getAsJson() # json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response) # LFUtils.debug_printer.pprint(json_response)
lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-A") # lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-A")
json_response = lf_r.getAsJson() # json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response) # LFUtils.debug_printer.pprint(json_response)
lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-B") # lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-B")
json_response = lf_r.getAsJson() # json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response) # LFUtils.debug_printer.pprint(json_response)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@@ -1,14 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# Create and modify WAN Links from the command line.
# Written by Candela Technologies Inc.
# Updated by: Erin Grimes
import sys import sys
if sys.version_info[0] != 3: if sys.version_info[0] != 3:
print("This script requires Python 3") print("This script requires Python 3")
exit(1) exit(1)
if 'py-json' not in sys.path: if 'py-json' not in sys.path:
sys.path.append('../py-json') sys.path.append('../py-json')
import argparse import argparse
from LANforge.lfcli_base import LFCliBase from LANforge.lfcli_base import LFCliBase
from LANforge.LFUtils import * from LANforge.LFUtils import *
@@ -17,44 +16,27 @@ import time
import create_wanlink import create_wanlink
class LANtoWAN(Realm): class LANtoWAN(Realm):
def __init__(self, host, port, ssid, security, password, def __init__(self, args):
lan_port="eth2", super().__init__(args['host'], args['port'])
wan_port="eth3", self.args = args
prefix='sta', self.lan_port="eth2"
number_template="00000", self.wan_port="eth3"
radio="wiphy0", self.prefix='sta'
sta_list = [], self.number_template="00000"
side_a_min_rate=56, side_a_max_rate=0, self.radio="wiphy0"
side_b_min_rate=56, side_b_max_rate=0, self.sta_list = []
upstream = None, self.side_a_min_rate=0
_debug_on=False, self.side_a_max_rate=56
_exit_on_error=False, self.side_b_min_rate=0
_exit_on_fail=False): self.side_b_max_rate=56
super().__init__(host, port) self._debug_on=False
self.upstream = upstream self._exit_on_error=False
self.host = host self._exit_on_fail=False
self.port = port
self.ssid = ssid
self.radio = radio
self.sta_list = sta_list
self.security = security
self.password = password
self.timeout = 120
self.lan_port = lan_port
self.wan_port = wan_port
self.prefix = prefix
self.number_template = number_template
self.station_profile = self.new_station_profile()
self.cx_profile = self.new_l3_cx_profile()
def create_wanlinks(self, shelf=1, resource=1, max_rate=1544000):
self.cx_profile.side_a_min_bps = side_a_min_rate
self.cx_profile.side_a_max_bps = side_a_max_rate
self.cx_profile.side_b_min_bps = side_b_min_rate
self.cx_profile.side_b_max_bps = side_b_max_rate
def create_wanlinks(self, shelf=1, resource=1, latency=20, max_rate=1544000):
print("Creating wanlinks") print("Creating wanlinks")
# print("the latency is {laten}\n".format(laten=self.latency))
# create redirects for wanlink # create redirects for wanlink
url = "/cli-json/add_rdd" url = "/cli-json/add_rdd"
data = { data = {
@@ -78,35 +60,29 @@ class LANtoWAN(Realm):
# create wanlink endpoints # create wanlink endpoints
url = "/cli-json/add_wl_endp" url = "/cli-json/add_wl_endp"
data = { data = {
"alias": "wlan0", "alias": "wlan1",
"shelf": shelf, "shelf": shelf,
"resource": resource, "resource": resource,
"port": "rd0a", "port": "rd0a",
"latency": latency, "latency": self.args['latency_A'],
"max_rate": max_rate "max_rate": max_rate
} }
self.json_post(url, data) self.json_post(url, data)
url = "/cli-json/add_wl_endp" url = "/cli-json/add_wl_endp"
data = { data = {
"alias": "wlan1", "alias": "wlan2",
"shelf": shelf, "shelf": shelf,
"resource": resource, "resource": resource,
"port": "rd1a", "port": "rd1a",
"latency": latency, "latency": self.args['latency_B'],
"max_rate": max_rate "max_rate": max_rate
} }
self.json_post(url, data) self.json_post(url, data)
create_wanlink.main(base_url='http://'+self.host+':8080') create_wanlink.main('http://'+self.args['host']+':8080', self.args)
time.sleep(.05)
def run(self):
#self.cx_profile.use_wpa2(True, self.ssid, self.password)
self.station_profile.create(radio="wiphy0", num_stations=3, debug=False)
def cleanup(self): pass def cleanup(self): pass
def main(): def main():
parser = LFCliBase.create_basic_argparse( parser = LFCliBase.create_basic_argparse(
prog='test_wanlink.py', prog='test_wanlink.py',
@@ -115,7 +91,6 @@ def main():
if group.title == "required arguments": if group.title == "required arguments":
required_args=group required_args=group
break break
#if required_args is not None:
optional_args=None optional_args=None
for group in parser._action_groups: for group in parser._action_groups:
@@ -123,27 +98,30 @@ def main():
optional_args=group optional_args=group
break break
if optional_args is not None: if optional_args is not None:
optional_args.add_argument('--lanport', help='Select the port you want for lanport', default='wiphy0') # optional_args.add_argument('--lanport', help='Select the port you want for lanport', default='wiphy0')
optional_args.add_argument('--wanport', help='Select the port you want for wanport', default='wiphy1') # optional_args.add_argument('--wanport', help='Select the port you want for wanport', default='wiphy1'
optional_args.add_argument('--latency', help='The delay of both ports', default=20)
optional_args.add_argument('--latency_A', help='The delay of port A', default=None)
optional_args.add_argument('--latency_B', help='The delay of port B', default=None)
# todo: bandwidth
# todo: packet loss
for group in parser._action_groups: for group in parser._action_groups:
if group.title == "optional arguments": if group.title == "optional arguments":
optional_args=group optional_args=group
break break
#if optional_args is not None: parseargs = parser.parse_args()
args = parser.parse_args() args = {
num_sta=4 "host": parseargs.mgr,
station_list = portNameSeries(prefix_="sta", start_id_=0, end_id_=num_sta - 1, padding_number_=10000, "port": parseargs.mgr_port,
radio=args.radio) "ssid": parseargs.ssid,
ltw=LANtoWAN(host=args.mgr, "security": parseargs.security,
port=args.mgr_port, "password": parseargs.passwd,
ssid=args.ssid, "latency": parseargs.latency,
sta_list=station_list, "latency_A": (parseargs.latency_A if parseargs.latency_A is not None else parseargs.latency),
security=args.security, "latency_B": (parseargs.latency_B if parseargs.latency_B is not None else parseargs.latency)
password=args.passwd, }
lan_port=args.lanport, ltw=LANtoWAN(args)
wan_port=args.wanport)
ltw.create_wanlinks() ltw.create_wanlinks()
#ltw.run()
ltw.cleanup() ltw.cleanup()
if __name__ == "__main__": if __name__ == "__main__":