mirror of
				https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
				synced 2025-11-04 04:38:02 +00:00 
			
		
		
		
	Adding functionality to use flags when modifying and creating stations, DUTs, and VAPs
Signed-off-by: Matthew Stidham <stidmatt@gmail.com>
This commit is contained in:
		@@ -2,6 +2,22 @@
 | 
				
			|||||||
from enum import Enum
 | 
					from enum import Enum
 | 
				
			||||||
from collections import namedtuple
 | 
					from collections import namedtuple
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					add_dut_flags = {
 | 
				
			||||||
 | 
					    'STA_MODE'      : 0x1,      # (1) DUT acts as Station.,
 | 
				
			||||||
 | 
					    'AP_MODE'       : 0x2,      # (2) DUT acts as AP.
 | 
				
			||||||
 | 
					    'INACTIVE'      : 0x4,      # (3) Ignore this in ChamberView, etc
 | 
				
			||||||
 | 
					    'WEP'           : 0x8,      # Use WEP encryption on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'WPA'           : 0x10,     # Use WPA encryption on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'WPA2'          : 0x20,     # Use WPA2 encryption on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'DHCPD-LAN'     : 0x40,     # Provides DHCP server on LAN port
 | 
				
			||||||
 | 
					    'DHCPD-WAN'     : 0x80,     # Provides DHCP server on WAN port
 | 
				
			||||||
 | 
					    'WPA3'          : 0x100,    # Use WPA3 encryption on all ssids, deprecated, see add_dut_extras.
 | 
				
			||||||
 | 
					    '11r'           : 0x200,    # Use .11r connection logic on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'EAP-TTLS'      : 0x400,    # Use EAP-TTLS connection logic on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'EAP-PEAP'      : 0x800,    # Use EAP-PEAP connection logic on all ssids, deprecated, see add_dut_ssid.
 | 
				
			||||||
 | 
					    'NOT-DHCPCD'    : 0x1000,   # Station/edge device that is NOT using DHCP.
 | 
				
			||||||
 | 
					     # Otherwise, automation logic assumes it is using dhcp client.'
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
class dut_params(namedtuple("dut_params", "key maxlen"), Enum):
 | 
					class dut_params(namedtuple("dut_params", "key maxlen"), Enum):
 | 
				
			||||||
    name            = "name",           48
 | 
					    name            = "name",           48
 | 
				
			||||||
    flags           = "flags",          256
 | 
					    flags           = "flags",          256
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ import time
 | 
				
			|||||||
# !/usr/bin/env python3
 | 
					# !/usr/bin/env python3
 | 
				
			||||||
# ---- ---- ---- ---- LANforge Base Imports ---- ---- ---- ----
 | 
					# ---- ---- ---- ---- LANforge Base Imports ---- ---- ---- ----
 | 
				
			||||||
from LANforge.lfcli_base import LFCliBase
 | 
					from LANforge.lfcli_base import LFCliBase
 | 
				
			||||||
 | 
					from LANforge.add_dut import add_dut_flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class cv_dut(LFCliBase):
 | 
					class cv_dut(LFCliBase):
 | 
				
			||||||
@@ -13,6 +14,8 @@ class cv_dut(LFCliBase):
 | 
				
			|||||||
                 hw_version="NA",
 | 
					                 hw_version="NA",
 | 
				
			||||||
                 serial_num="NA",
 | 
					                 serial_num="NA",
 | 
				
			||||||
                 model_num="NA",
 | 
					                 model_num="NA",
 | 
				
			||||||
 | 
					                 desired_dut_flags=None,
 | 
				
			||||||
 | 
					                 desired_dut_flags_mask=None
 | 
				
			||||||
                 ):
 | 
					                 ):
 | 
				
			||||||
        super().__init__(_lfjson_host=lfclient_host,
 | 
					        super().__init__(_lfjson_host=lfclient_host,
 | 
				
			||||||
                         _lfjson_port=lfclient_port)
 | 
					                         _lfjson_port=lfclient_port)
 | 
				
			||||||
@@ -27,6 +30,30 @@ class cv_dut(LFCliBase):
 | 
				
			|||||||
        self.lan_port = "[BLANK]"
 | 
					        self.lan_port = "[BLANK]"
 | 
				
			||||||
        self.api_id = "0"
 | 
					        self.api_id = "0"
 | 
				
			||||||
        self.flags_mask = "NA"
 | 
					        self.flags_mask = "NA"
 | 
				
			||||||
 | 
					        if desired_dut_flags is not None:
 | 
				
			||||||
 | 
					            self.dut_flags = desired_dut_flags
 | 
				
			||||||
 | 
					            self.dut_flags_mask = desired_dut_flags_mask
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def add_named_flags(self, desired_list, command_ref):
 | 
				
			||||||
 | 
					        if desired_list is None:
 | 
				
			||||||
 | 
					            raise ValueError("addNamedFlags wants a list of desired flag names")
 | 
				
			||||||
 | 
					        if len(desired_list) < 1:
 | 
				
			||||||
 | 
					            print("addNamedFlags: empty desired list")
 | 
				
			||||||
 | 
					            return 0
 | 
				
			||||||
 | 
					        if (command_ref is None) or (len(command_ref) < 1):
 | 
				
			||||||
 | 
					            raise ValueError("addNamedFlags wants a maps of flag values")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        result = 0
 | 
				
			||||||
 | 
					        for name in desired_list:
 | 
				
			||||||
 | 
					            if (name is None) or (name == ""):
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            if name not in command_ref:
 | 
				
			||||||
 | 
					                if self.debug:
 | 
				
			||||||
 | 
					                    print(command_ref)
 | 
				
			||||||
 | 
					                raise ValueError("flag %s not in map" % name)
 | 
				
			||||||
 | 
					            result += command_ref[name]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create_dut(self,
 | 
					    def create_dut(self,
 | 
				
			||||||
                   ssid1="[BLANK]",
 | 
					                   ssid1="[BLANK]",
 | 
				
			||||||
@@ -43,6 +70,11 @@ class cv_dut(LFCliBase):
 | 
				
			|||||||
                   top_left_x="NA",
 | 
					                   top_left_x="NA",
 | 
				
			||||||
                   top_left_y="NA",
 | 
					                   top_left_y="NA",
 | 
				
			||||||
                   ):
 | 
					                   ):
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            self.flags = self.add_named_flags(self.dut_flags, add_dut_flags)
 | 
				
			||||||
 | 
					            self.flags_mask = self.add_named_flags(self.dut_flags_mask, add_dut_flags)
 | 
				
			||||||
 | 
					        except:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
        response_json = []
 | 
					        response_json = []
 | 
				
			||||||
        req_url = "/cli-json/add_dut"
 | 
					        req_url = "/cli-json/add_dut"
 | 
				
			||||||
        data = {
 | 
					        data = {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
# !/usr/bin/env python3
 | 
					# !/usr/bin/env python3
 | 
				
			||||||
from LANforge.lfcli_base import LFCliBase
 | 
					from LANforge.lfcli_base import LFCliBase
 | 
				
			||||||
from LANforge import LFRequest
 | 
					from LANforge import LFRequest
 | 
				
			||||||
@@ -32,10 +31,7 @@ class StationProfile:
 | 
				
			|||||||
                 shelf=1,
 | 
					                 shelf=1,
 | 
				
			||||||
                 dhcp=True,
 | 
					                 dhcp=True,
 | 
				
			||||||
                 debug_=False,
 | 
					                 debug_=False,
 | 
				
			||||||
                 use_ht160=False,
 | 
					                 use_ht160=False):
 | 
				
			||||||
                 COMMANDS=["add_sta", "set_port"],
 | 
					 | 
				
			||||||
                 desired_add_sta_flags = ["wpa2_enable", "80211u_enable", "create_admin_down"],
 | 
					 | 
				
			||||||
                 desired_add_sta_flags_mask = ["wpa2_enable", "80211u_enable", "create_admin_down"]):
 | 
					 | 
				
			||||||
        self.debug = debug_
 | 
					        self.debug = debug_
 | 
				
			||||||
        self.lfclient_url = lfclient_url
 | 
					        self.lfclient_url = lfclient_url
 | 
				
			||||||
        self.ssid = ssid
 | 
					        self.ssid = ssid
 | 
				
			||||||
@@ -48,9 +44,9 @@ class StationProfile:
 | 
				
			|||||||
        self.security = security
 | 
					        self.security = security
 | 
				
			||||||
        self.local_realm = local_realm
 | 
					        self.local_realm = local_realm
 | 
				
			||||||
        self.use_ht160 = use_ht160
 | 
					        self.use_ht160 = use_ht160
 | 
				
			||||||
        self.COMMANDS = COMMANDS
 | 
					        self.COMMANDS = ["add_sta", "set_port"]
 | 
				
			||||||
        self.desired_add_sta_flags = desired_add_sta_flags
 | 
					        self.desired_add_sta_flags = ["wpa2_enable", "80211u_enable", "create_admin_down"]
 | 
				
			||||||
        self.desired_add_sta_flags_mask = desired_add_sta_flags_mask
 | 
					        self.desired_add_sta_flags_mask = ["wpa2_enable", "80211u_enable", "create_admin_down"]
 | 
				
			||||||
        self.number_template = number_template_
 | 
					        self.number_template = number_template_
 | 
				
			||||||
        self.station_names = []  # eids, these are created station names
 | 
					        self.station_names = []  # eids, these are created station names
 | 
				
			||||||
        self.add_sta_data = {
 | 
					        self.add_sta_data = {
 | 
				
			||||||
@@ -63,6 +59,7 @@ class StationProfile:
 | 
				
			|||||||
            "mode": 0,
 | 
					            "mode": 0,
 | 
				
			||||||
            "mac": "xx:xx:xx:xx:*:xx",
 | 
					            "mac": "xx:xx:xx:xx:*:xx",
 | 
				
			||||||
            "flags": 0,  # (0x400 + 0x20000 + 0x1000000000)  # create admin down
 | 
					            "flags": 0,  # (0x400 + 0x20000 + 0x1000000000)  # create admin down
 | 
				
			||||||
 | 
					            "flags_mask": 0
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        self.desired_set_port_cmd_flags = []
 | 
					        self.desired_set_port_cmd_flags = []
 | 
				
			||||||
        self.desired_set_port_current_flags = ["if_down"]
 | 
					        self.desired_set_port_current_flags = ["if_down"]
 | 
				
			||||||
@@ -535,4 +532,24 @@ class StationProfile:
 | 
				
			|||||||
        if self.debug:
 | 
					        if self.debug:
 | 
				
			||||||
            print("created %s stations" % num)
 | 
					            print("created %s stations" % num)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#
 | 
					    def modify(self, radio):
 | 
				
			||||||
 | 
					        for station in self.station_names:
 | 
				
			||||||
 | 
					            print(station)
 | 
				
			||||||
 | 
					            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)
 | 
				
			||||||
 | 
					            self.add_sta_data["radio"] = radio
 | 
				
			||||||
 | 
					            self.add_sta_data["sta_name"] = station
 | 
				
			||||||
 | 
					            self.add_sta_data["ssid"] = 'NA'
 | 
				
			||||||
 | 
					            self.add_sta_data["key"] = 'NA'
 | 
				
			||||||
 | 
					            self.add_sta_data['mac'] = 'NA'
 | 
				
			||||||
 | 
					            self.add_sta_data['mode'] = 'NA'
 | 
				
			||||||
 | 
					            self.add_sta_data['suppress_preexec_cli'] = 'NA'
 | 
				
			||||||
 | 
					            self.add_sta_data['suppress_preexec_method'] = 'NA'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            add_sta_r = LFRequest.LFRequest(self.lfclient_url + "/cli-json/add_sta")
 | 
				
			||||||
 | 
					            if self.debug:
 | 
				
			||||||
 | 
					                print(self.lfclient_url + "/cli_json/add_sta")
 | 
				
			||||||
 | 
					                print(self.add_sta_data)
 | 
				
			||||||
 | 
					            add_sta_r.addPostData(self.add_sta_data)
 | 
				
			||||||
 | 
					            json_response = add_sta_r.jsonPost(self.debug)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -351,13 +351,7 @@ class VAPProfile(LFCliBase):
 | 
				
			|||||||
        if (self.up):
 | 
					        if (self.up):
 | 
				
			||||||
            self.admin_up(resource)
 | 
					            self.admin_up(resource)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def modify(self, resource, radio):
 | 
					    def modify(self, radio):
 | 
				
			||||||
        list_ports = self.local_realm.json_get("/port/1/%s" % resource,
 | 
					 | 
				
			||||||
                                               debug_=self.debug)
 | 
					 | 
				
			||||||
        for item in list_ports['interfaces']:
 | 
					 | 
				
			||||||
            if self.vap_name == list(item.values())[0]['alias']:
 | 
					 | 
				
			||||||
                url = (list(item.values())[0]['_links'])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.add_vap_data["flags"] = self.add_named_flags(self.desired_add_vap_flags, add_vap.add_vap_flags)
 | 
					        self.add_vap_data["flags"] = self.add_named_flags(self.desired_add_vap_flags, add_vap.add_vap_flags)
 | 
				
			||||||
        self.add_vap_data["flags_mask"] = self.add_named_flags(self.desired_add_vap_flags_mask, add_vap.add_vap_flags)
 | 
					        self.add_vap_data["flags_mask"] = self.add_named_flags(self.desired_add_vap_flags_mask, add_vap.add_vap_flags)
 | 
				
			||||||
        self.add_vap_data["radio"] = radio
 | 
					        self.add_vap_data["radio"] = radio
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -143,7 +143,6 @@ class CreateChamberview(cv):
 | 
				
			|||||||
                                            );  # To manage scenario
 | 
					                                            );  # To manage scenario
 | 
				
			||||||
        if not line and not raw_line:
 | 
					        if not line and not raw_line:
 | 
				
			||||||
            raise Exception("scenario creation failed")
 | 
					            raise Exception("scenario creation failed")
 | 
				
			||||||
            return False
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -170,9 +169,7 @@ class CreateChamberview(cv):
 | 
				
			|||||||
        print("completed building %s scenario" %scenario_name)
 | 
					        print("completed building %s scenario" %scenario_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
 | 
					 | 
				
			||||||
    parser = argparse.ArgumentParser(
 | 
					    parser = argparse.ArgumentParser(
 | 
				
			||||||
        description="""
 | 
					        description="""
 | 
				
			||||||
        For Two line scenario use --line twice as shown in example, for multi line scenario
 | 
					        For Two line scenario use --line twice as shown in example, for multi line scenario
 | 
				
			||||||
@@ -203,7 +200,6 @@ def main():
 | 
				
			|||||||
                        help="delete scenario (by default: False)")
 | 
					                        help="delete scenario (by default: False)")
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    Create_Chamberview = CreateChamberview(lfmgr=args.lfmgr,
 | 
					    Create_Chamberview = CreateChamberview(lfmgr=args.lfmgr,
 | 
				
			||||||
                                           port=args.port,
 | 
					                                           port=args.port,
 | 
				
			||||||
                                           )
 | 
					                                           )
 | 
				
			||||||
@@ -216,6 +212,5 @@ def main():
 | 
				
			|||||||
    Create_Chamberview.build(args.create_scenario)
 | 
					    Create_Chamberview.build(args.create_scenario)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    main()
 | 
					    main()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,6 +72,7 @@ class DUT(dut):
 | 
				
			|||||||
                 hw_version="NA",
 | 
					                 hw_version="NA",
 | 
				
			||||||
                 serial_num="NA",
 | 
					                 serial_num="NA",
 | 
				
			||||||
                 model_num="NA",
 | 
					                 model_num="NA",
 | 
				
			||||||
 | 
					                 dut_flags=None,
 | 
				
			||||||
                 ):
 | 
					                 ):
 | 
				
			||||||
        super().__init__(
 | 
					        super().__init__(
 | 
				
			||||||
            lfclient_host=lfmgr,
 | 
					            lfclient_host=lfmgr,
 | 
				
			||||||
@@ -80,12 +81,15 @@ class DUT(dut):
 | 
				
			|||||||
            hw_version=hw_version,
 | 
					            hw_version=hw_version,
 | 
				
			||||||
            serial_num=serial_num,
 | 
					            serial_num=serial_num,
 | 
				
			||||||
            model_num=model_num,
 | 
					            model_num=model_num,
 | 
				
			||||||
 | 
					            desired_dut_flags=dut_flags,
 | 
				
			||||||
 | 
					            desired_dut_flags_mask=dut_flags
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self.cv_dut_name = dut_name
 | 
					        self.cv_dut_name = dut_name
 | 
				
			||||||
        self.cv_test = cvtest(lfmgr, port)
 | 
					        self.cv_test = cvtest(lfmgr, port)
 | 
				
			||||||
        self.dut_name = dut_name
 | 
					        self.dut_name = dut_name
 | 
				
			||||||
        self.ssid = ssid
 | 
					        self.ssid = ssid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setup(self):
 | 
					    def setup(self):
 | 
				
			||||||
        self.create_dut()
 | 
					        self.create_dut()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -156,6 +160,7 @@ def main():
 | 
				
			|||||||
    parser.add_argument("--hw_version", default="NA", help="DUT Hardware version.")
 | 
					    parser.add_argument("--hw_version", default="NA", help="DUT Hardware version.")
 | 
				
			||||||
    parser.add_argument("--serial_num", default="NA", help="DUT Serial number.")
 | 
					    parser.add_argument("--serial_num", default="NA", help="DUT Serial number.")
 | 
				
			||||||
    parser.add_argument("--model_num", default="NA", help="DUT Model Number.")
 | 
					    parser.add_argument("--model_num", default="NA", help="DUT Model Number.")
 | 
				
			||||||
 | 
					    parser.add_argument('--dut_flag', help='station flags to add', default=None, action='append')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
    new_dut = DUT(lfmgr=args.lfmgr,
 | 
					    new_dut = DUT(lfmgr=args.lfmgr,
 | 
				
			||||||
@@ -166,6 +171,7 @@ def main():
 | 
				
			|||||||
                  hw_version = args.hw_version,
 | 
					                  hw_version = args.hw_version,
 | 
				
			||||||
                  serial_num = args.serial_num,
 | 
					                  serial_num = args.serial_num,
 | 
				
			||||||
                  model_num = args.model_num,
 | 
					                  model_num = args.model_num,
 | 
				
			||||||
 | 
					                  dut_flags=args.dut_flag
 | 
				
			||||||
                  )
 | 
					                  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    new_dut.setup()
 | 
					    new_dut.setup()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,7 @@ class CreateStation(Realm):
 | 
				
			|||||||
                 _port=None,
 | 
					                 _port=None,
 | 
				
			||||||
                 _mode=0,
 | 
					                 _mode=0,
 | 
				
			||||||
                 _sta_list=None,
 | 
					                 _sta_list=None,
 | 
				
			||||||
 | 
					                 _sta_flags=None,
 | 
				
			||||||
                 _number_template="00000",
 | 
					                 _number_template="00000",
 | 
				
			||||||
                 _radio="wiphy0",
 | 
					                 _radio="wiphy0",
 | 
				
			||||||
                 _proxy_str=None,
 | 
					                 _proxy_str=None,
 | 
				
			||||||
@@ -46,6 +47,7 @@ class CreateStation(Realm):
 | 
				
			|||||||
        self.password = _password
 | 
					        self.password = _password
 | 
				
			||||||
        self.mode = _mode
 | 
					        self.mode = _mode
 | 
				
			||||||
        self.sta_list = _sta_list
 | 
					        self.sta_list = _sta_list
 | 
				
			||||||
 | 
					        self.sta_flags = _sta_flags
 | 
				
			||||||
        self.radio = _radio
 | 
					        self.radio = _radio
 | 
				
			||||||
        self.timeout = 120
 | 
					        self.timeout = 120
 | 
				
			||||||
        self.number_template = _number_template
 | 
					        self.number_template = _number_template
 | 
				
			||||||
@@ -59,6 +61,10 @@ class CreateStation(Realm):
 | 
				
			|||||||
        self.station_profile.security = self.security
 | 
					        self.station_profile.security = self.security
 | 
				
			||||||
        self.station_profile.number_template_ = self.number_template
 | 
					        self.station_profile.number_template_ = self.number_template
 | 
				
			||||||
        self.station_profile.mode = self.mode
 | 
					        self.station_profile.mode = self.mode
 | 
				
			||||||
 | 
					        if self.sta_flags is not None:
 | 
				
			||||||
 | 
					            self.station_profile.desired_add_sta_flags = self.sta_flags
 | 
				
			||||||
 | 
					            self.station_profile.desired_add_sta_mask = self.sta_flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if self.debug:
 | 
					        if self.debug:
 | 
				
			||||||
            print("----- Station List ----- ----- ----- ----- ----- ----- \n")
 | 
					            print("----- Station List ----- ----- ----- ----- ----- ----- \n")
 | 
				
			||||||
            pprint.pprint(self.sta_list)
 | 
					            pprint.pprint(self.sta_list)
 | 
				
			||||||
@@ -115,6 +121,7 @@ Command example:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    optional = parser.add_argument_group('Optional arguments')
 | 
					    optional = parser.add_argument_group('Optional arguments')
 | 
				
			||||||
    optional.add_argument('--mode', help='Mode for your station (as a number)',default=0)
 | 
					    optional.add_argument('--mode', help='Mode for your station (as a number)',default=0)
 | 
				
			||||||
 | 
					    optional.add_argument('--station_flag', help='station flags to add', required=False, default=None, action='append')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    args = parser.parse_args()
 | 
					    args = parser.parse_args()
 | 
				
			||||||
    # if args.debug:
 | 
					    # if args.debug:
 | 
				
			||||||
@@ -156,6 +163,7 @@ Command example:
 | 
				
			|||||||
                                   _password=args.passwd,
 | 
					                                   _password=args.passwd,
 | 
				
			||||||
                                   _security=args.security,
 | 
					                                   _security=args.security,
 | 
				
			||||||
                                   _sta_list=station_list,
 | 
					                                   _sta_list=station_list,
 | 
				
			||||||
 | 
					                                   _sta_flags=args.station_flag,
 | 
				
			||||||
                                   _mode=args.mode,
 | 
					                                   _mode=args.mode,
 | 
				
			||||||
                                   _radio=args.radio,
 | 
					                                   _radio=args.radio,
 | 
				
			||||||
                                   _set_txo_data=None,
 | 
					                                   _set_txo_data=None,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										157
									
								
								py-scripts/modify_station.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										157
									
								
								py-scripts/modify_station.py
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,157 @@
 | 
				
			|||||||
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					    Script for modifying stations.
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import os
 | 
				
			||||||
 | 
					import argparse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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'))
 | 
				
			||||||
 | 
					from LANforge.lfcli_base import LFCliBase
 | 
				
			||||||
 | 
					from realm import Realm
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ModifyStation(Realm):
 | 
				
			||||||
 | 
					    def __init__(self,
 | 
				
			||||||
 | 
					                 _ssid="NA",
 | 
				
			||||||
 | 
					                 _security="NA",
 | 
				
			||||||
 | 
					                 _password="NA",
 | 
				
			||||||
 | 
					                 _mac="NA",
 | 
				
			||||||
 | 
					                 _host=None,
 | 
				
			||||||
 | 
					                 _port=None,
 | 
				
			||||||
 | 
					                 _station_list=None,
 | 
				
			||||||
 | 
					                 _enable_flags=None,
 | 
				
			||||||
 | 
					                 _disable_flags=None,
 | 
				
			||||||
 | 
					                 _number_template="00000",
 | 
				
			||||||
 | 
					                 _radio=None,
 | 
				
			||||||
 | 
					                 _proxy_str=None,
 | 
				
			||||||
 | 
					                 _debug_on=False,
 | 
				
			||||||
 | 
					                 _exit_on_error=False,
 | 
				
			||||||
 | 
					                 _exit_on_fail=False,
 | 
				
			||||||
 | 
					                 _dhcp=True):
 | 
				
			||||||
 | 
					        super().__init__(_host,
 | 
				
			||||||
 | 
					                         _port)
 | 
				
			||||||
 | 
					        self.host = _host
 | 
				
			||||||
 | 
					        self.port = _port
 | 
				
			||||||
 | 
					        self.ssid = _ssid
 | 
				
			||||||
 | 
					        self.security = _security
 | 
				
			||||||
 | 
					        self.password = _password
 | 
				
			||||||
 | 
					        self.mac = _mac
 | 
				
			||||||
 | 
					        self.station_list = _station_list
 | 
				
			||||||
 | 
					        self.enable_flags = _enable_flags
 | 
				
			||||||
 | 
					        self.disable_flags = _disable_flags
 | 
				
			||||||
 | 
					        self.radio = _radio
 | 
				
			||||||
 | 
					        self.timeout = 120
 | 
				
			||||||
 | 
					        self.number_template = _number_template
 | 
				
			||||||
 | 
					        self.debug = _debug_on
 | 
				
			||||||
 | 
					        self.dhcp = _dhcp
 | 
				
			||||||
 | 
					        self.station_profile = self.new_station_profile()
 | 
				
			||||||
 | 
					        self.station_profile.station_names = self.station_list
 | 
				
			||||||
 | 
					        self.station_profile.ssid = self.ssid
 | 
				
			||||||
 | 
					        self.station_profile.security = self.security
 | 
				
			||||||
 | 
					        self.station_profile.ssid_pass = self.password
 | 
				
			||||||
 | 
					        self.station_profile.mac = self.mac
 | 
				
			||||||
 | 
					        self.station_profile.dhcp = self.dhcp
 | 
				
			||||||
 | 
					        self.station_profile.debug = self.debug
 | 
				
			||||||
 | 
					        self.station_profile.desired_add_sta_flags = self.enable_flags
 | 
				
			||||||
 | 
					        self.station_profile.desired_add_sta_flags_mask = self.enable_flags + self.disable_flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def set_station(self):
 | 
				
			||||||
 | 
					        return self.station_profile.modify(radio=self.radio)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def main():
 | 
				
			||||||
 | 
					    parser = LFCliBase.create_basic_argparse(
 | 
				
			||||||
 | 
					        prog='modify_station.py',
 | 
				
			||||||
 | 
					        formatter_class=argparse.RawTextHelpFormatter,
 | 
				
			||||||
 | 
					        epilog='''\
 | 
				
			||||||
 | 
					         Modify stations on a system. Use the enable_flag to create a flag on a station. Turn off a flag with \
 | 
				
			||||||
 | 
					         the disable_flag option. A list of available flags are available in the add_station.py file in \
 | 
				
			||||||
 | 
					         py-json/LANforge.
 | 
				
			||||||
 | 
					            ''',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        description='''\
 | 
				
			||||||
 | 
					        modify_station.py
 | 
				
			||||||
 | 
					        --------------------
 | 
				
			||||||
 | 
					        Command example:
 | 
				
			||||||
 | 
					        ./modify_station.py
 | 
				
			||||||
 | 
					            --radio wiphy0
 | 
				
			||||||
 | 
					            --station 1.1.sta0000
 | 
				
			||||||
 | 
					            --security open
 | 
				
			||||||
 | 
					            --ssid netgear
 | 
				
			||||||
 | 
					            --passwd BLANK
 | 
				
			||||||
 | 
					            --enable_flag osen_enable
 | 
				
			||||||
 | 
					            --disable_flag ht160_enable
 | 
				
			||||||
 | 
					            --debug
 | 
				
			||||||
 | 
					        --------------------
 | 
				
			||||||
 | 
					        Station flags are currently defined as:
 | 
				
			||||||
 | 
					        wpa_enable           | 0x10         # Enable WPA
 | 
				
			||||||
 | 
					        custom_conf          | 0x20         # Use Custom wpa_supplicant config file.
 | 
				
			||||||
 | 
					        wep_enable           | 0x200        # Use wpa_supplicant configured for WEP encryption.
 | 
				
			||||||
 | 
					        wpa2_enable          | 0x400        # Use wpa_supplicant configured for WPA2 encryption.
 | 
				
			||||||
 | 
					        ht40_disable         | 0x800        # Disable HT-40 even if hardware and AP support it.
 | 
				
			||||||
 | 
					        scan_ssid            | 0x1000       # Enable SCAN-SSID flag in wpa_supplicant.
 | 
				
			||||||
 | 
					        passive_scan         | 0x2000       # Use passive scanning (don't send probe requests).
 | 
				
			||||||
 | 
					        disable_sgi          | 0x4000       # Disable SGI (Short Guard Interval).
 | 
				
			||||||
 | 
					        lf_sta_migrate       | 0x8000       # OK-To-Migrate (Allow station migration between LANforge radios)
 | 
				
			||||||
 | 
					        verbose              | 0x10000      # Verbose-Debug:  Increase debug info in wpa-supplicant and hostapd logs.
 | 
				
			||||||
 | 
					        80211u_enable        | 0x20000      # Enable 802.11u (Interworking) feature.
 | 
				
			||||||
 | 
					        80211u_auto          | 0x40000      # Enable 802.11u (Interworking) Auto-internetworking feature.  Always enabled currently.
 | 
				
			||||||
 | 
					        80211u_gw            | 0x80000      # AP Provides access to internet (802.11u Interworking)
 | 
				
			||||||
 | 
					        80211u_additional    | 0x100000     # AP requires additional step for access (802.11u Interworking)
 | 
				
			||||||
 | 
					        80211u_e911          | 0x200000     # AP claims emergency services reachable (802.11u Interworking)
 | 
				
			||||||
 | 
					        80211u_e911_unauth   | 0x400000     # AP provides Unauthenticated emergency services (802.11u Interworking)
 | 
				
			||||||
 | 
					        hs20_enable          | 0x800000     # Enable Hotspot 2.0 (HS20) feature.  Requires WPA-2.
 | 
				
			||||||
 | 
					        disable_gdaf         | 0x1000000    # AP:  Disable DGAF (used by HotSpot 2.0).
 | 
				
			||||||
 | 
					        8021x_radius         | 0x2000000    # Use 802.1x (RADIUS for AP).
 | 
				
			||||||
 | 
					        80211r_pmska_cache   | 0x4000000    # Enable oportunistic PMSKA caching for WPA2 (Related to 802.11r).
 | 
				
			||||||
 | 
					        disable_ht80         | 0x8000000    # Disable HT80 (for AC chipset NICs only)
 | 
				
			||||||
 | 
					        ibss_mode            | 0x20000000   # Station should be in IBSS mode.
 | 
				
			||||||
 | 
					        osen_enable          | 0x40000000   # Enable OSEN protocol (OSU Server-only Authentication)
 | 
				
			||||||
 | 
					        disable_roam         | 0x80000000   # Disable automatic station roaming based on scan results.
 | 
				
			||||||
 | 
					        ht160_enable         | 0x100000000  # Enable HT160 mode.
 | 
				
			||||||
 | 
					        disable_fast_reauth  | 0x200000000  # Disable fast_reauth option for virtual stations.
 | 
				
			||||||
 | 
					        mesh_mode            | 0x400000000  # Station should be in MESH mode.
 | 
				
			||||||
 | 
					        power_save_enable    | 0x800000000  # Station should enable power-save.  May not work in all drivers/configurations.
 | 
				
			||||||
 | 
					        create_admin_down    | 0x1000000000 # Station should be created admin-down.
 | 
				
			||||||
 | 
					        wds-mode             | 0x2000000000 # WDS station (sort of like a lame mesh), not supported on ath10k
 | 
				
			||||||
 | 
					        no-supp-op-class-ie  | 0x4000000000 # Do not include supported-oper-class-IE in assoc requests.  May work around AP bugs.
 | 
				
			||||||
 | 
					        txo-enable           | 0x8000000000 # Enable/disable tx-offloads, typically managed by set_wifi_txo command
 | 
				
			||||||
 | 
					        use-wpa3             | 0x10000000000 # Enable WPA-3 (SAE Personal) mode.
 | 
				
			||||||
 | 
					        use-bss-transition   | 0x80000000000 # Enable BSS transition.
 | 
				
			||||||
 | 
					        disable-twt          | 0x100000000000 # Disable TWT mode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    ''')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    optional = parser.add_argument_group('optional arguments')
 | 
				
			||||||
 | 
					    optional.add_argument('--enable_flag', help='station flags to add', default=list(), action='append')
 | 
				
			||||||
 | 
					    optional.add_argument('--disable_flag', help='station flags to disable', default=list(), action='append')
 | 
				
			||||||
 | 
					    optional.add_argument('--station', help='station to modify', required=True, action='append')
 | 
				
			||||||
 | 
					    optional.add_argument('--mac', default="NA")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    args = parser.parse_args()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    modify_station = ModifyStation(_host=args.mgr,
 | 
				
			||||||
 | 
					                                   _port=args.mgr_port,
 | 
				
			||||||
 | 
					                                   _ssid=args.ssid,
 | 
				
			||||||
 | 
					                                   _password=args.passwd,
 | 
				
			||||||
 | 
					                                   _security=args.security,
 | 
				
			||||||
 | 
					                                   _mac=args.mac,
 | 
				
			||||||
 | 
					                                   _station_list=args.station,
 | 
				
			||||||
 | 
					                                   _radio=args.radio,
 | 
				
			||||||
 | 
					                                   _proxy_str=args.proxy,
 | 
				
			||||||
 | 
					                                   _enable_flags=args.enable_flag,
 | 
				
			||||||
 | 
					                                   _disable_flags=args.disable_flag,
 | 
				
			||||||
 | 
					                                   _debug_on=args.debug)
 | 
				
			||||||
 | 
					    modify_station.set_station()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == "__main__":
 | 
				
			||||||
 | 
					    main()
 | 
				
			||||||
@@ -14,13 +14,8 @@ if sys.version_info[0] != 3:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if 'py-json' not in sys.path:
 | 
					if 'py-json' not in sys.path:
 | 
				
			||||||
    sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
 | 
					    sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
 | 
				
			||||||
import LANforge
 | 
					 | 
				
			||||||
from LANforge.lfcli_base import LFCliBase
 | 
					from LANforge.lfcli_base import LFCliBase
 | 
				
			||||||
from LANforge import LFUtils
 | 
					 | 
				
			||||||
import realm
 | 
					 | 
				
			||||||
from realm import Realm
 | 
					from realm import Realm
 | 
				
			||||||
import time
 | 
					 | 
				
			||||||
import pprint
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ModifyVAP(Realm):
 | 
					class ModifyVAP(Realm):
 | 
				
			||||||
@@ -69,8 +64,7 @@ class ModifyVAP(Realm):
 | 
				
			|||||||
        self.vap_profile.desired_add_vap_flags_mask = self.enable_flags + self.disable_flags
 | 
					        self.vap_profile.desired_add_vap_flags_mask = self.enable_flags + self.disable_flags
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_vap(self):
 | 
					    def set_vap(self):
 | 
				
			||||||
        return self.vap_profile.modify(resource=1,
 | 
					        return self.vap_profile.modify(radio=self.radio)
 | 
				
			||||||
                                       radio=self.radio)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
@@ -96,6 +90,38 @@ def main():
 | 
				
			|||||||
            --enable_flag osen_enable
 | 
					            --enable_flag osen_enable
 | 
				
			||||||
            --disable_flag ht160_enable
 | 
					            --disable_flag ht160_enable
 | 
				
			||||||
            --debug
 | 
					            --debug
 | 
				
			||||||
 | 
					        --------------------
 | 
				
			||||||
 | 
					        AP flags are currently defined as:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enable_wpa           | 0x10            # Enable WPA
 | 
				
			||||||
 | 
					hostapd_config       | 0x20            # Use Custom hostapd config file.
 | 
				
			||||||
 | 
					enable_80211d        | 0x40            # Enable 802.11D to broadcast country-code & channels in VAPs
 | 
				
			||||||
 | 
					short_preamble       | 0x80            # Allow short-preamble
 | 
				
			||||||
 | 
					pri_sec_ch_enable    | 0x100           # Enable Primary/Secondary channel switch.
 | 
				
			||||||
 | 
					wep_enable           | 0x200           # Enable WEP Encryption
 | 
				
			||||||
 | 
					wpa2_enable          | 0x400           # Enable WPA2 Encryption
 | 
				
			||||||
 | 
					disable_ht40         | 0x800           # Disable HT-40 (will use HT-20 if available).
 | 
				
			||||||
 | 
					verbose              | 0x10000         # Verbose-Debug:  Increase debug info in wpa-supplicant and hostapd logs.
 | 
				
			||||||
 | 
					80211u_enable        | 0x20000         # Enable 802.11u (Interworking) feature.
 | 
				
			||||||
 | 
					80211u_auto          | 0x40000         # Enable 802.11u (Interworking) Auto-internetworking feature.  Always enabled currently.
 | 
				
			||||||
 | 
					80211u_gw            | 0x80000         # AP Provides access to internet (802.11u Interworking)
 | 
				
			||||||
 | 
					80211u_additional    | 0x100000        # AP requires additional step for access (802.11u Interworking)
 | 
				
			||||||
 | 
					80211u_e911          | 0x200000        # AP claims emergency services reachable (802.11u Interworking)
 | 
				
			||||||
 | 
					80211u_e911_unauth   | 0x400000        # AP provides Unauthenticated emergency services (802.11u Interworking)
 | 
				
			||||||
 | 
					hs20_enable          | 0x800000        # Enable Hotspot 2.0 (HS20) feature.  Requires WPA-2.
 | 
				
			||||||
 | 
					disable_dgaf         | 0x1000000       # AP Disable DGAF (used by HotSpot 2.0).
 | 
				
			||||||
 | 
					8021x_radius         | 0x2000000       # Use 802.1x (RADIUS for AP).
 | 
				
			||||||
 | 
					80211r_pmska_cache   | 0x4000000       # Enable oportunistic PMSKA caching for WPA2 (Related to 802.11r).
 | 
				
			||||||
 | 
					disable_ht80         | 0x8000000       # Disable HT80 (for AC chipset NICs only)
 | 
				
			||||||
 | 
					80211h_enable        | 0x10000000      # Enable 802.11h (needed for running on DFS channels)  Requires 802.11d.
 | 
				
			||||||
 | 
					osen_enable          | 0x40000000      # Enable OSEN protocol (OSU Server-only Authentication)
 | 
				
			||||||
 | 
					ht160_enable         | 0x100000000     # Enable HT160 mode.
 | 
				
			||||||
 | 
					create_admin_down    | 0x1000000000    # Station should be created admin-down.
 | 
				
			||||||
 | 
					use-wpa3             | 0x10000000000   # Enable WPA-3 (SAE Personal) mode.
 | 
				
			||||||
 | 
					use-bss-load         | 0x20000000000   # Enable BSS Load IE in Beacons and Probe Responses (.11e).
 | 
				
			||||||
 | 
					use-rrm-report       | 0x40000000000   # Enable Radio measurements IE in beacon and probe responses.
 | 
				
			||||||
 | 
					use-bss-transition   | 0x80000000000   # Enable BSS transition.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    ''')
 | 
					                    ''')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    optional = parser.add_argument_group('optional arguments')
 | 
					    optional = parser.add_argument_group('optional arguments')
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user