[minigraph]: Support port name in ACL table AttachTo attribute (#13105)
Why I did it This PR is to update minigraph.py to support both port alias and port name as input of AttachTo attribute of ACL table. Before this change, only port alias is supported. How I did it Add a global variable to store port names Search both port names and port alias wheh parsing the value of AttachTo. How to verify it Verified by a new unit test case test_minigraph_acl_attach_to_ports Verified by copying the new minigraph.py to a testbed and run conflg load_minigraph.
This commit is contained in:
parent
e077b5362c
commit
22fcc760c4
@ -674,10 +674,14 @@ def parse_dpg(dpg, hname):
|
||||
acl_intfs.extend(vlan_member_list[member])
|
||||
else:
|
||||
acl_intfs.append(member)
|
||||
elif member in port_alias_map:
|
||||
acl_intfs.append(port_alias_map[member])
|
||||
elif (member in port_alias_map) or (member in port_names_map):
|
||||
if member in port_alias_map:
|
||||
acl_intf = port_alias_map[member]
|
||||
else:
|
||||
acl_intf = member
|
||||
acl_intfs.append(acl_intf)
|
||||
# Give a warning if trying to attach ACL to a LAG member interface, correct way is to attach ACL to the LAG interface
|
||||
if port_alias_map[member] in intfs_inpc:
|
||||
if acl_intf in intfs_inpc:
|
||||
print("Warning: ACL " + aclname + " is attached to a LAG member interface " + port_alias_map[member] + ", instead of LAG interface", file=sys.stderr)
|
||||
elif member.lower().startswith('erspan') or member.lower().startswith('egress_erspan') or member.lower().startswith('erspan_dscp'):
|
||||
if 'dscp' in member.lower():
|
||||
@ -1396,6 +1400,8 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
|
||||
docker_routing_config_mode = child.text
|
||||
|
||||
(ports, alias_map, alias_asic_map) = get_port_config(hwsku=hwsku, platform=platform, port_config_file=port_config_file, asic_name=asic_name, hwsku_config_file=hwsku_config_file)
|
||||
|
||||
port_names_map.update(ports)
|
||||
port_alias_map.update(alias_map)
|
||||
port_alias_asic_map.update(alias_asic_map)
|
||||
|
||||
@ -2064,6 +2070,7 @@ def parse_asic_meta_get_devices(root):
|
||||
|
||||
return local_devices
|
||||
|
||||
port_names_map = {}
|
||||
port_alias_map = {}
|
||||
port_alias_asic_map = {}
|
||||
|
||||
|
@ -180,7 +180,7 @@
|
||||
<DataAcls/>
|
||||
<AclInterfaces>
|
||||
<AclInterface>
|
||||
<AttachTo>PortChannel01</AttachTo>
|
||||
<AttachTo>PortChannel01;fortyGigE0/8;Ethernet12</AttachTo>
|
||||
<InAcl>DataAcl</InAcl>
|
||||
<Type>DataPlane</Type>
|
||||
</AclInterface>
|
||||
|
@ -467,6 +467,14 @@ class TestCfgGenCaseInsensitive(TestCase):
|
||||
expected_ports.sort()
|
||||
)
|
||||
|
||||
def test_minigraph_acl_attach_to_ports(self):
|
||||
"""
|
||||
The test case is to verify ACL table can be bound to both port names and alias
|
||||
"""
|
||||
result = minigraph.parse_xml(self.sample_graph, port_config_file=self.port_config)
|
||||
expected_dataacl_ports = ['PortChannel01','fortyGigE0/8','Ethernet12']
|
||||
self.assertEqual(result['ACL_TABLE']['DATAACL']['ports'].sort(), expected_dataacl_ports.sort())
|
||||
|
||||
def test_parse_device_desc_xml_mgmt_interface(self):
|
||||
# Regular device_desc.xml with both IPv4 and IPv6 mgmt address
|
||||
result = minigraph.parse_device_desc_xml(self.sample_simple_device_desc)
|
||||
|
Loading…
Reference in New Issue
Block a user