From fa6052e2daca3ebc2ae73ed305b8006b21bb0545 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Wed, 29 Sep 2021 23:19:57 -0700 Subject: [PATCH] [201911][cherry-pick] Update minigraph parser to support MIRROR_DSCP (#8826) * Update minigraph parser to support MIRROR_DSCP Signed-off-by: bingwang --- src/sonic-config-engine/minigraph.py | 13 +++++++++---- .../tests/simple-sample-graph-case.xml | 5 +++++ .../tests/test_minigraph_case.py | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index ea750426c677..3819013317da 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -400,6 +400,7 @@ def parse_dpg(dpg, hname): acl_intfs = [] is_mirror = False is_mirror_v6 = False + is_mirror_dscp = False # TODO: Ensure that acl_intfs will only ever contain front-panel interfaces (e.g., # maybe we should explicity ignore management and loopback interfaces?) because we @@ -422,8 +423,10 @@ def parse_dpg(dpg, hname): # 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: print >> sys.stderr, "Warning: ACL " + aclname + " is attached to a LAG member interface " + port_alias_map[member] + ", instead of LAG interface" - elif member.lower().startswith('erspan') or member.lower().startswith('egress_erspan'): - if member.lower().startswith('erspanv6') or member.lower().startswith('egress_erspanv6'): + elif member.lower().startswith('erspan') or member.lower().startswith('egress_erspan') or member.lower().startswith('erspan_dscp'): + if 'dscp' in member.lower(): + is_mirror_dscp = True + elif member.lower().startswith('erspanv6') or member.lower().startswith('egress_erspanv6'): is_mirror_v6 = True else: is_mirror = True @@ -443,7 +446,7 @@ def parse_dpg(dpg, hname): # are binded then do not classify as Control plane. # For multi-asic platforms it's possible there is no # interface are binded to everflow in host namespace. - if acl_intfs or is_mirror_v6 or is_mirror: + if acl_intfs or is_mirror_v6 or is_mirror or is_mirror_dscp: # Remove duplications dedup_intfs = [] for intf in acl_intfs: @@ -457,6 +460,8 @@ def parse_dpg(dpg, hname): acls[aclname]['type'] = 'MIRROR' elif is_mirror_v6: acls[aclname]['type'] = 'MIRRORV6' + elif is_mirror_dscp: + acls[aclname]['type'] = 'MIRROR_DSCP' else: acls[aclname]['type'] = 'L3V6' if 'v6' in aclname.lower() else 'L3' else: @@ -808,7 +813,7 @@ def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role): # Control Plane ACL has no Interface associated and # Data Plane ACL Interface are attached via minigraph # AclInterface. - if group_type != 'MIRROR' and group_type != 'MIRRORV6': + if group_type != 'MIRROR' and group_type != 'MIRRORV6' and group_type != 'MIRROR_DSCP': continue # Filters out back-panel ports from the binding list for Everflow (Mirror) diff --git a/src/sonic-config-engine/tests/simple-sample-graph-case.xml b/src/sonic-config-engine/tests/simple-sample-graph-case.xml index 1e04bc162aee..add1964c5243 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph-case.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph-case.xml @@ -175,6 +175,11 @@ SNMP_ACL SNMP + + ERSPAN_DSCP + Everflow_dscp + Everflow_dscp + diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 4fba07a757a6..300f4e3f280c 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -4,7 +4,7 @@ import tests.common_utils as utils from unittest import TestCase - +import minigraph class TestCfgGenCaseInsensitive(TestCase): @@ -155,3 +155,17 @@ def test_minigraph_bgp_mon(self): argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "BGP_MONITORS"' output = self.run_script(argument) self.assertEqual(output.strip(), "{}") + + def test_minigraph_mirror_dscp(self): + result = minigraph.parse_xml(self.sample_graph, port_config_file=self.port_config) + self.assertTrue('EVERFLOW_DSCP' in result['ACL_TABLE']) + everflow_dscp_entry = result['ACL_TABLE']['EVERFLOW_DSCP'] + + self.assertEqual(everflow_dscp_entry['type'], 'MIRROR_DSCP') + self.assertEqual(everflow_dscp_entry['stage'], 'ingress') + expected_ports = ['PortChannel01', 'Ethernet12', 'Ethernet8', 'Ethernet0'] + self.assertEqual( + everflow_dscp_entry['ports'].sort(), + expected_ports.sort() + ) +