Skip to content

Commit 8fc4657

Browse files
committed
[sonic-buildimage] updated minigraph for ACL Table data and ACL Interface Binding for Multi-NPU platforms (#4491)
* [sonic-buildimage] updated minigraph for ACL Table data and ACL Interface binding update for multu-npu platform based on subrole as "Frontend" or "Backend". For backend npu no ACL table is associated. For frontend npu only front-panel interface are associated. Updated with test case and fix typo in sample-mingraph for npu Address Review comments Signed-off-by: Abhishek Dosi <[email protected]> * Fixed the logic as per preview comment. Interface Filter logic only applies to Everflow/Mirror tables. * Address Review Comments.
1 parent 2778363 commit 8fc4657

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

src/sonic-config-engine/minigraph.py

+52-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
VLAN_SUB_INTERFACE_SEPARATOR = '.'
3636
VLAN_SUB_INTERFACE_VLAN_ID = '10'
3737

38+
FRONTEND_ASIC_SUB_ROLE = 'FrontEnd'
39+
BACKEND_ASIC_SUB_ROLE = 'BackEnd'
40+
BACKEND_ASIC_INTERFACE_NAME_PREFIX = 'Ethernet-BP'
41+
3842
# Default Virtual Network Index (VNI)
3943
vni_default = 8000
4044

@@ -392,7 +396,9 @@ def parse_dpg(dpg, hname):
392396
# later after the rest of the minigraph has been parsed.
393397
acl_intfs = pc_intfs[:]
394398
for panel_port in port_alias_map.values():
395-
if panel_port not in intfs_inpc:
399+
# because of port_alias_asic_map we can have duplicate in port_alias_map
400+
# so check if already present do not add
401+
if panel_port not in intfs_inpc and panel_port not in acl_intfs:
396402
acl_intfs.append(panel_port)
397403
break
398404
if acl_intfs:
@@ -645,27 +651,61 @@ def parse_spine_chassis_fe(results, vni, lo_intfs, phyport_intfs, pc_intfs, pc_m
645651
#
646652
###############################################################################
647653

648-
def filter_acl_mirror_table_bindings(acls, neighbors, port_channels):
649-
"""
650-
Filters out inactive front-panel ports from the binding list for mirror
651-
ACL tables. We define an "active" port as one that is a member of a
652-
port channel or one that is connected to a neighboring device.
653-
"""
654+
def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role):
655+
filter_acls = {}
656+
657+
# If the asic role is BackEnd no ACL Table (Ctrl/Data/Everflow) is binded.
658+
# This will be applicable in Multi-NPU Platforms.
659+
660+
if sub_role == BACKEND_ASIC_SUB_ROLE:
661+
return filter_acls
662+
663+
front_port_channel_intf = []
664+
665+
# Get the front panel port channel. It will use port_alias_asic_map
666+
# which will get populated from port_config.ini for Multi-NPU
667+
# architecture
668+
for port_channel_intf in port_channels:
669+
backend_port_channel = any(lag_member in port_alias_asic_map \
670+
and lag_member.startswith(BACKEND_ASIC_INTERFACE_NAME_PREFIX) \
671+
for lag_member in port_channels[port_channel_intf]['members'])
672+
if not backend_port_channel:
673+
front_port_channel_intf.append(port_channel_intf)
654674

655675
for acl_table, group_params in acls.iteritems():
656676
group_type = group_params.get('type', None)
677+
filter_acls[acl_table] = acls[acl_table]
657678

679+
# For Control Plane and Data ACL no filtering is needed
680+
# Control Plane ACL has no Interface associated and
681+
# Data Plane ACL Interface are attached via minigraph
682+
# AclInterface.
658683
if group_type != 'MIRROR' and group_type != 'MIRRORV6':
659684
continue
660685

661-
active_ports = [ port for port in group_params.get('ports', []) if port in neighbors.keys() or port in port_channels ]
662-
686+
# Filters out back-panel ports from the binding list for Everflow (Mirror)
687+
# ACL tables. We define an "back-panel" port as one that is a member of a
688+
# port channel connected to back asic or directly connected to back asic.
689+
# This will be applicable in Multi-NPU Platforms.
690+
front_panel_ports = []
691+
for port in group_params.get('ports', []):
692+
if port in port_alias_asic_map and port.startswith(BACKEND_ASIC_INTERFACE_NAME_PREFIX):
693+
continue
694+
if port in port_channels and port not in front_port_channel_intf:
695+
continue
696+
front_panel_ports.append(port)
697+
698+
# Filters out inactive front-panel ports from the binding list for mirror
699+
# ACL tables. We define an "active" port as one that is a member of a
700+
# front pannel port channel or one that is connected to a neighboring device via front panel port.
701+
active_ports = [port for port in front_panel_ports if port in neighbors.keys() or port in front_port_channel_intf]
702+
663703
if not active_ports:
664704
print >> sys.stderr, 'Warning: mirror table {} in ACL_TABLE does not have any ports bound to it'.format(acl_table)
665705

666-
acls[acl_table]['ports'] = active_ports
706+
filter_acls[acl_table]['ports'] = active_ports
667707

668-
return acls
708+
return filter_acls
669709

670710
###############################################################################
671711
#
@@ -968,7 +1008,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
9681008
results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers)
9691009
results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers)
9701010
results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers)
971-
results['ACL_TABLE'] = filter_acl_mirror_table_bindings(acls, neighbors, pcs)
1011+
results['ACL_TABLE'] = filter_acl_table_bindings(acls, neighbors, pcs, sub_role)
9721012
results['FEATURE'] = {
9731013
'telemetry': {
9741014
'status': 'enabled'

src/sonic-config-engine/tests/multi_npu_data/sample-minigraph.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,14 @@
650650
<EndDevice>05T2</EndDevice>
651651
<EndPort>Ethernet1</EndPort>
652652
<StartDevice>multi_npu_platform_01</StartDevice>
653-
<StartPort>Ethernet1/8</StartPort>
653+
<StartPort>Ethernet1/5</StartPort>
654654
</DeviceLinkBase>
655655
<DeviceLinkBase>
656656
<ElementType>DeviceInterfaceLink</ElementType>
657657
<EndDevice>05T2</EndDevice>
658658
<EndPort>Ethernet2</EndPort>
659659
<StartDevice>multi_npu_platform_01</StartDevice>
660-
<StartPort>Ethernet1/9</StartPort>
660+
<StartPort>Ethernet1/6</StartPort>
661661
</DeviceLinkBase>
662662
<DeviceLinkBase i:type="DeviceInterfaceLink">
663663
<ElementType>DeviceInterfaceLink</ElementType>

src/sonic-config-engine/tests/test_multinpu_cfggen.py

+25
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,28 @@ def test_device_asic_metadata(self):
219219
self.assertEqual(output['localhost']['sub_role'], 'FrontEnd')
220220
else:
221221
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')
222+
223+
def test_global_asic_acl(self):
224+
argument = "-m {} --var-json \"ACL_TABLE\"".format(self.sample_graph)
225+
output = json.loads(self.run_script(argument))
226+
self.assertDictEqual(output, {\
227+
'DATAACL': {'policy_desc': 'DATAACL', 'ports': ['PortChannel0002','PortChannel0008'], 'stage': 'ingress', 'type': 'L3'},
228+
'EVERFLOW': {'policy_desc': 'EVERFLOW', 'ports': ['PortChannel0002','PortChannel0008'], 'stage': 'ingress', 'type': 'MIRROR'},
229+
'EVERFLOWV6':{'policy_desc': 'EVERFLOWV6', 'ports': ['PortChannel0002','PortChannel0008'], 'stage': 'ingress', 'type': 'MIRRORV6'},
230+
'SNMP_ACL': {'policy_desc': 'SNMP_ACL', 'services': ['SNMP'], 'stage': 'ingress', 'type': 'CTRLPLANE'},
231+
'SSH_ONLY': {'policy_desc': 'SSH_ONLY', 'services': ['SSH'], 'stage': 'ingress', 'type': 'CTRLPLANE'}})
232+
233+
def test_front_end_asic_acl(self):
234+
argument = "-m {} -p {} -n asic0 --var-json \"ACL_TABLE\"".format(self.sample_graph, self.port_config[0])
235+
output = json.loads(self.run_script(argument))
236+
self.assertDictEqual(output, {\
237+
'DATAACL': {'policy_desc': 'DATAACL', 'ports': ['PortChannel0002'], 'stage': 'ingress', 'type': 'L3'},
238+
'EVERFLOW': {'policy_desc': 'EVERFLOW', 'ports': ['PortChannel0002'], 'stage': 'ingress', 'type': 'MIRROR'},
239+
'EVERFLOWV6':{'policy_desc': 'EVERFLOWV6', 'ports': ['PortChannel0002'], 'stage': 'ingress', 'type': 'MIRRORV6'},
240+
'SNMP_ACL': {'policy_desc': 'SNMP_ACL', 'services': ['SNMP'], 'stage': 'ingress', 'type': 'CTRLPLANE'},
241+
'SSH_ONLY': {'policy_desc': 'SSH_ONLY', 'services': ['SSH'], 'stage': 'ingress', 'type': 'CTRLPLANE'}})
242+
243+
def test_back_end_asic_acl(self):
244+
argument = "-m {} -p {} -n asic3 --var-json \"ACL_TABLE\"".format(self.sample_graph, self.port_config[3])
245+
output = json.loads(self.run_script(argument))
246+
self.assertDictEqual(output, {})

0 commit comments

Comments
 (0)