Skip to content

Commit f37c040

Browse files
arlakshmsanthosh-kt
authored andcommitted
Common functions for Multi ASIC (sonic-net#4973)
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan [email protected] The following common APIs are added for multi ASIC - an API to check if a given port is a internal or external port - an API to check if a given port-channel is internal or external - an API to check if a bgp-session is internal or external - an API to connect to the config and other dbs in the a given namespace - added common APIs to the sonic_py_common library. - update the sample port-config.ini with role column and add corresponding test to verify the ports configuration is - generated properly.
1 parent da1f8b4 commit f37c040

File tree

8 files changed

+355
-42
lines changed

8 files changed

+355
-42
lines changed

src/sonic-config-engine/minigraph.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from lxml.etree import QName
1515

1616
from portconfig import get_port_config
17-
from sonic_py_common.device_info import get_npu_id_from_name
17+
from sonic_py_common.multi_asic import get_asic_id_from_name
1818

1919
"""minigraph.py
2020
version_added: "1.9"
@@ -840,7 +840,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
840840

841841
# hostname is the asic_name, get the asic_id from the asic_name
842842
if asic_name is not None:
843-
asic_id = get_npu_id_from_name(asic_name)
843+
asic_id = get_asic_id_from_name(asic_name)
844844
else:
845845
asic_id = None
846846

src/sonic-config-engine/sonic-cfggen

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ from minigraph import parse_device_desc_xml
4343
from minigraph import parse_asic_sub_role
4444
from portconfig import get_port_config, get_port_config_file_name, get_breakout_mode
4545
from sonic_py_common.device_info import get_platform, get_system_mac
46-
from sonic_py_common.device_info import get_npu_id_from_name, is_multi_npu
46+
from sonic_py_common.multi_asic import get_asic_id_from_name, is_multi_asic
4747
from config_samples import generate_sample_config
4848
from config_samples import get_available_config
4949
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig
@@ -240,8 +240,8 @@ def _get_jinja2_env(paths):
240240
env.filters['ip_network'] = ip_network
241241
for attr in ['ip', 'network', 'prefixlen', 'netmask', 'broadcast']:
242242
env.filters[attr] = partial(prefix_attr, attr)
243-
# Pass the is_multi_npu function as global
244-
env.globals['multi_asic'] = is_multi_npu
243+
# Pass the is_multi_asic function as global
244+
env.globals['multi_asic'] = is_multi_asic
245245

246246
return env
247247

@@ -284,7 +284,7 @@ def main():
284284
asic_name = args.namespace
285285
asic_id = None
286286
if asic_name is not None:
287-
asic_id = get_npu_id_from_name(asic_name)
287+
asic_id = get_asic_id_from_name(asic_name)
288288

289289

290290
# Load the database config for the namespace from global database json
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# name lanes alias asic_port_name
2-
Ethernet0 33,34,35,36 Ethernet1/1 Eth0-ASIC0
3-
Ethernet4 29,30,31,32 Ethernet1/2 Eth1-ASIC0
4-
Ethernet8 41,42,43,44 Ethernet1/3 Eth2-ASIC0
5-
Ethernet12 37,38,39,40 Ethernet1/4 Eth3-ASIC0
6-
Ethernet-BP0 13,14,15,16 Ethernet-BP0 Eth4-ASIC0
7-
Ethernet-BP4 17,18,19,20 Ethernet-BP4 Eth5-ASIC0
8-
Ethernet-BP8 21,22,23,24 Ethernet-BP8 Eth6-ASIC0
9-
Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0
1+
# name lanes alias index asic_port_name role
2+
Ethernet0 33,34,35,36 Ethernet1/1 0 Eth0-ASIC0 Ext
3+
Ethernet4 29,30,31,32 Ethernet1/2 1 Eth1-ASIC0 Ext
4+
Ethernet8 41,42,43,44 Ethernet1/3 2 Eth2-ASIC0 Ext
5+
Ethernet12 37,38,39,40 Ethernet1/4 3 Eth3-ASIC0 Ext
6+
Ethernet-BP0 13,14,15,16 Ethernet-BP0 0 Eth4-ASIC0 Int
7+
Ethernet-BP4 17,18,19,20 Ethernet-BP4 1 Eth5-ASIC0 Int
8+
Ethernet-BP8 21,22,23,24 Ethernet-BP8 2 Eth6-ASIC0 Int
9+
Ethernet-BP12 25,26,27,28 Ethernet-BP12 3 Eth7-ASIC0 Int
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# name lanes alias asic_port_name
2-
Ethernet16 33,34,35,36 Ethernet1/5 Eth0-ASIC1
3-
Ethernet20 29,30,31,32 Ethernet1/6 Eth1-ASIC1
4-
Ethernet24 41,42,43,44 Ethernet1/7 Eth2-ASIC1
5-
Ethernet28 37,38,39,40 Ethernet1/8 Eth3-ASIC1
6-
Ethernet-BP16 13,14,15,16 Ethernet-BP16 Eth4-ASIC1
7-
Ethernet-BP20 17,18,19,20 Ethernet-BP20 Eth5-ASIC1
8-
Ethernet-BP24 21,22,23,24 Ethernet-BP24 Eth6-ASIC1
9-
Ethernet-BP28 25,26,27,28 Ethernet-BP28 Eth7-ASIC1
1+
# name lanes alias index asic_port_name role
2+
Ethernet16 33,34,35,36 Ethernet1/5 4 Eth0-ASIC1 Ext
3+
Ethernet20 29,30,31,32 Ethernet1/6 5 Eth1-ASIC1 Ext
4+
Ethernet24 41,42,43,44 Ethernet1/7 6 Eth2-ASIC1 Ext
5+
Ethernet28 37,38,39,40 Ethernet1/8 7 Eth3-ASIC1 Ext
6+
Ethernet-BP16 13,14,15,16 Ethernet-BP16 4 Eth4-ASIC1 Int
7+
Ethernet-BP20 17,18,19,20 Ethernet-BP20 5 Eth5-ASIC1 Int
8+
Ethernet-BP24 21,22,23,24 Ethernet-BP24 6 Eth6-ASIC1 Int
9+
Ethernet-BP28 25,26,27,28 Ethernet-BP28 7 Eth7-ASIC1 Int
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# name lanes alias asic_port_name
2-
Ethernet-BP256 61,62,63,64 Ethernet-BP256 Eth0-ASIC2
3-
Ethernet-BP260 57,58,59,60 Ethernet-BP260 Eth1-ASIC2
4-
Ethernet-BP264 53,54,55,56 Ethernet-BP264 Eth2-ASIC2
5-
Ethernet-BP268 49,50,51,52 Ethernet-BP268 Eth3-ASIC2
6-
Ethernet-BP272 45,46,47,48 Ethernet-BP272 Eth4-ASIC2
7-
Ethernet-BP276 41,42,43,44 Ethernet-BP276 Eth5-ASIC2
8-
Ethernet-BP280 37,38,39,40 Ethernet-BP280 Eth6-ASIC2
9-
Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2
1+
# name lanes alias index asic_port_name role
2+
Ethernet-BP256 61,62,63,64 Ethernet-BP256 8 Eth0-ASIC2 Int
3+
Ethernet-BP260 57,58,59,60 Ethernet-BP260 9 Eth1-ASIC2 Int
4+
Ethernet-BP264 53,54,55,56 Ethernet-BP264 10 Eth2-ASIC2 Int
5+
Ethernet-BP268 49,50,51,52 Ethernet-BP268 11 Eth3-ASIC2 Int
6+
Ethernet-BP272 45,46,47,48 Ethernet-BP272 12 Eth4-ASIC2 Int
7+
Ethernet-BP276 41,42,43,44 Ethernet-BP276 13 Eth5-ASIC2 Int
8+
Ethernet-BP280 37,38,39,40 Ethernet-BP280 14 Eth6-ASIC2 Int
9+
Ethernet-BP284 33,34,35,36 Ethernet-BP284 15 Eth7-ASIC2 Int
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# name lanes alias asic_port_name
2-
Ethernet-BP384 29,30,31,32 Ethernet-BP384 Eth0-ASIC3
3-
Ethernet-BP388 25,26,27,28 Ethernet-BP388 Eth1-ASIC3
4-
Ethernet-BP392 21,22,23,24 Ethernet-BP392 Eth2-ASIC3
5-
Ethernet-BP396 17,18,19,20 Ethernet-BP396 Eth3-ASIC3
6-
Ethernet-BP400 13,14,15,16 Ethernet-BP400 Eth4-ASIC3
7-
Ethernet-BP404 9,10,11,12 Ethernet-BP404 Eth5-ASIC3
8-
Ethernet-BP408 5,6,7,8 Ethernet-BP408 Eth6-ASIC3
9-
Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3
1+
# name lanes alias index asic_port_name role
2+
Ethernet-BP384 29,30,31,32 Ethernet-BP384 16 Eth0-ASIC3 Int
3+
Ethernet-BP388 25,26,27,28 Ethernet-BP388 17 Eth1-ASIC3 Int
4+
Ethernet-BP392 21,22,23,24 Ethernet-BP392 18 Eth2-ASIC3 Int
5+
Ethernet-BP396 17,18,19,20 Ethernet-BP396 19 Eth3-ASIC3 Int
6+
Ethernet-BP400 13,14,15,16 Ethernet-BP400 20 Eth4-ASIC3 Int
7+
Ethernet-BP404 9,10,11,12 Ethernet-BP404 21 Eth5-ASIC3 Int
8+
Ethernet-BP408 5,6,7,8 Ethernet-BP408 22 Eth6-ASIC3 Int
9+
Ethernet-BP412 1,2,3,4 Ethernet-BP412 23 Eth7-ASIC3 Int

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ def test_backend_asic_portchannel_intf(self):
158158
self.assertListEqual(output.keys(), \
159159
['PortChannel4013', 'PortChannel4013|10.1.0.2/31', 'PortChannel4014', 'PortChannel4014|10.1.0.6/31'])
160160

161+
def test_frontend_asic_ports(self):
162+
argument = "-m {} -p {} -n asic0 --var-json \"PORT\"".format(self.sample_graph, self.port_config[0])
163+
output = json.loads(self.run_script(argument))
164+
self.assertDictEqual(output, \
165+
{"Ethernet0": { "admin_status": "up", "alias": "Ethernet1/1", "asic_port_name": "Eth0-ASIC0", "description": "01T2:Ethernet1", "index": "0", "lanes": "33,34,35,36", "mtu": "9100", "pfc_asym": "off", "role": "Ext", "speed": "40000" },
166+
"Ethernet4": { "admin_status": "up", "alias": "Ethernet1/2", "asic_port_name": "Eth1-ASIC0", "description": "01T2:Ethernet2", "index": "1", "lanes": "29,30,31,32", "mtu": "9100", "pfc_asym": "off", "role": "Ext", "speed": "40000" },
167+
"Ethernet8": { "alias": "Ethernet1/3", "asic_port_name": "Eth2-ASIC0", "description": "Ethernet1/3", "index": "2", "lanes": "41,42,43,44", "mtu": "9100", "pfc_asym": "off", "role": "Ext", "speed": "40000" },
168+
"Ethernet12": { "alias": "Ethernet1/4", "asic_port_name": "Eth3-ASIC0", "description": "Ethernet1/4", "index": "3", "lanes": "37,38,39,40", "mtu": "9100", "pfc_asym": "off", "role": "Ext", "speed": "40000" },
169+
"Ethernet-BP0": { "admin_status": "up", "alias": "Ethernet-BP0", "asic_port_name": "Eth4-ASIC0", "description": "ASIC2:Eth0-ASIC2", "index": "0", "lanes": "13,14,15,16", "mtu": "9100", "pfc_asym": "off", "role": "Int", "speed": "40000" },
170+
"Ethernet-BP4": { "admin_status": "up", "alias": "Ethernet-BP4", "asic_port_name": "Eth5-ASIC0", "description": "ASIC2:Eth1-ASIC2", "index": "1", "lanes": "17,18,19,20", "mtu": "9100", "pfc_asym": "off", "role": "Int", "speed": "40000" },
171+
"Ethernet-BP8": { "admin_status": "up", "alias": "Ethernet-BP8", "asic_port_name": "Eth6-ASIC0", "description": "ASIC3:Eth0-ASIC3", "index": "2", "lanes": "21,22,23,24", "mtu": "9100", "pfc_asym": "off", "role": "Int", "speed": "40000" },
172+
"Ethernet-BP12": { "admin_status": "up", "alias": "Ethernet-BP12", "asic_port_name": "Eth7-ASIC0", "description": "ASIC3:Eth1-ASIC3", "index": "3", "lanes": "25,26,27,28", "mtu": "9100", "pfc_asym": "off", "role": "Int", "speed": "40000" }})
173+
161174
def test_frontend_asic_device_neigh(self):
162175
argument = "-m {} -p {} -n asic0 --var-json \"DEVICE_NEIGHBOR\"".format(self.sample_graph, self.port_config[0])
163176
output = json.loads(self.run_script(argument))

0 commit comments

Comments
 (0)