- 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
# 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.
# Updated by:
# Updated by: Erin Grimes
import sys
import urllib
if sys.version_info[0] != 3:
print("This script requires Python 3")
exit()
import time
from time import sleep
from urllib import error
@@ -25,16 +20,19 @@ j_printer = pprint.PrettyPrinter(indent=2)
# typically you're using resource 1 in stand alone realm
resource_id = 1
def main(base_url="http://localhost:8080"):
def main(base_url="http://localhost:8080", args={}):
json_post = ""
json_response = ""
num_wanlinks = -1
# see if there are old wanlinks to remove
lf_r = LFRequest.LFRequest(base_url+"/wl/list")
print(lf_r.get_as_json())
# ports to set as endpoints
port_a ="rd0a"
port_b ="rd1a"
try:
json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response)
@@ -75,7 +73,7 @@ def main(base_url="http://localhost:8080"):
'shelf': 1,
'resource': '1',
'port': port_a,
'latency': '75',
'latency': args['latency_A'],
'max_rate': '128000',
'description': 'cookbook-example'
})
@@ -89,7 +87,7 @@ def main(base_url="http://localhost:8080"):
'shelf': 1,
'resource': '1',
'port': port_b,
'latency': '95',
'latency': args['latency_B'],
'max_rate': '256000',
'description': 'cookbook-example'
})
@@ -134,6 +132,7 @@ def main(base_url="http://localhost:8080"):
continue
print("starting wanlink:")
# print("the latency is {laten}".format(laten=latency))
lf_r = LFRequest.LFRequest(base_url+"/cli-json/set_cx_state")
lf_r.addPostData({
'test_mgr': 'all',
@@ -163,25 +162,7 @@ def main(base_url="http://localhost:8080"):
print("Error code "+error.code)
continue
print("Wanlink is running, wait one sec...")
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)
print("Wanlink is running")
# stop wanlink
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 info:")
lf_r = LFRequest.LFRequest(base_url+"/wl/wl_eg1")
json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response)
# print("Wanlink info:")
# lf_r = LFRequest.LFRequest(base_url+"/wl/wl_eg1")
# json_response = lf_r.getAsJson()
# LFUtils.debug_printer.pprint(json_response)
lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-A")
json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response)
# lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-A")
# json_response = lf_r.getAsJson()
# LFUtils.debug_printer.pprint(json_response)
lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-B")
json_response = lf_r.getAsJson()
LFUtils.debug_printer.pprint(json_response)
# lf_r = LFRequest.LFRequest(base_url+"/wl_ep/wl_eg1-B")
# json_response = lf_r.getAsJson()
# LFUtils.debug_printer.pprint(json_response)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if __name__ == '__main__':
main()

View File

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