From b253c0bc091e3fea772c9d01231b5eee603bc165 Mon Sep 17 00:00:00 2001 From: Logan Lipke Date: Tue, 3 Nov 2020 17:31:58 -0800 Subject: [PATCH] Added MACVLANProfile and new_macvlanprofile. WIP --- py-json/realm.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/py-json/realm.py b/py-json/realm.py index a9e8ec30..5097dc4f 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -729,6 +729,9 @@ class Realm(LFCliBase): def new_dut_profile(self): return DUTProfile(self.lfclient_host, self.lfclient_port, local_realm=self, debug_=self.debug) + def new_mvlan_profile(self): + return MACVLANProfile(self.lfclient_host, self.lfclient_port, local_realm=self, debug_=self.debug) + class MULTICASTProfile(LFCliBase): def __init__(self, lfclient_host, lfclient_port, local_realm, report_timer_=3000, name_prefix_="Unset", number_template_="00000", debug_=False): @@ -2330,6 +2333,57 @@ class FIOEndpProfile(LFCliBase): self.local_realm.json_post(url, cx_data, debug_=debug_, suppress_related_commands_=suppress_related_commands_) time.sleep(sleep_time) + +class MACVLANProfile(LFCliBase): + def __init__(self, lfclient_host, lfclient_port, + local_realm, + upstream_port="eth1", + num_macvlans=1, + admin_down=False, + debug_=False): + super().__init__(lfclient_host, lfclient_port, debug_, _halt_on_error=True) + self.local_realm = local_realm + self.num_macvlans = num_macvlans + self.upstream_port = upstream_port + self.resource = 1 + self.shelf = 1 + self.created_macvlans = [] + + def create(self, admin_down=False): + print("Creating MACVLANs...") + req_url = "/cli-json/add_mvlan" + for i in range(self.num_macvlans): + data = { + "shelf": self.shelf, + "resource": self.resource, + "mac": "xx:xx:xx:*:*:xx", + "port": self.local_realm.name_to_eid(self.upstream_port)[2], + "index": i, + "flags": None + } + if self.admin_down: + data["flags"] = 1 + else: + data["flags"] = 0 + self.created_macvlans.append("%s.%s.%s#%s" % (self.shelf, self.resource, + self.local_realm.name_to_eid(self.upstream_port)[2], i)) + self.local_realm.json_post(req_url, data) + + def cleanup(self): + print("Cleaning up MACVLANs...") + for port_eid in self.created_macvlans: + self.local_realm.rm_port(port_eid, check_exists=True) + # And now see if they are gone + # LFUtils.wait_until_ports_disappear(base_url=self.lfclient_url, port_list=self.created_macvlans) + + def admin_up(self): + for macvlan in self.created_macvlans: + self.local_realm.admin_up(macvlan) + + def admin_down(self): + for macvlan in self.created_macvlans: + self.local_realm.admin_down(macvlan) + class PacketFilter(): def get_filter_wlan_assoc_packets(self, ap_mac, sta_mac):