Skip to content

Commit

Permalink
[minigraph]: Support port name in ACL table AttachTo attribute (#13105)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bingwang-ms committed Jan 13, 2023
1 parent e077b53 commit 22fcc76
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -2064,6 +2070,7 @@ def parse_asic_meta_get_devices(root):

return local_devices

port_names_map = {}
port_alias_map = {}
port_alias_asic_map = {}

Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<DataAcls/>
<AclInterfaces>
<AclInterface>
<AttachTo>PortChannel01</AttachTo>
<AttachTo>PortChannel01;fortyGigE0/8;Ethernet12</AttachTo>
<InAcl>DataAcl</InAcl>
<Type>DataPlane</Type>
</AclInterface>
Expand Down
8 changes: 8 additions & 0 deletions src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ def test_minigraph_mirror_dscp(self):
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)
Expand Down

0 comments on commit 22fcc76

Please sign in to comment.