Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202012][cherry-pick] Support port name in ACL table AttachTo attribute #13178

Open
wants to merge 2 commits into
base: 202012
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,14 @@ def parse_dpg(dpg, hname):
acl_intfs.extend(vlans[member]['members'])
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 @@ -1254,6 +1258,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 @@ -1803,6 +1809,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 @@ -456,6 +456,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