From 04734ba9d86be413d32baf7ad615e6d93038d019 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Mon, 13 Jul 2020 22:35:49 +0000 Subject: [PATCH 1/4] + Modified buffer config template to include internal ASIC with 5m cable length --- files/build_templates/buffers_config.j2 | 13 +++++++++---- src/sonic-config-engine/sonic-cfggen | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/files/build_templates/buffers_config.j2 b/files/build_templates/buffers_config.j2 index ba4dcf49e813..dacdd162f5db 100644 --- a/files/build_templates/buffers_config.j2 +++ b/files/build_templates/buffers_config.j2 @@ -34,6 +34,7 @@ def {%- else %} {%- set ports2cable = { 'torrouter_server' : '5m', + 'internal' : '5m', 'leafrouter_torrouter' : '40m', 'spinerouter_leafrouter' : '300m' } @@ -47,10 +48,14 @@ def {%- if DEVICE_NEIGHBOR_METADATA is defined and DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %} {%- set neighbor = DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %} {%- set neighbor_role = neighbor.type %} - {%- set roles1 = switch_role + '_' + neighbor_role %} - {%- set roles2 = neighbor_role + '_' + switch_role %} - {%- set roles1 = roles1 | lower %} - {%- set roles2 = roles2 | lower %} + {%- 'asic' == neighbor_role | lower %} + {%- set roles1 = 'internal' %} + {%- else %} + {%- set roles1 = switch_role + '_' + neighbor_role %} + {%- set roles2 = neighbor_role + '_' + switch_role %} + {%- set roles1 = roles1 | lower %} + {%- set roles2 = roles2 | lower %} + {%- endif %} {%- if roles1 in ports2cable %} {%- if cable_len.append(ports2cable[roles1]) %}{% endif %} {%- elif roles2 in ports2cable %} diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index 9bda72071937..b296f4054c90 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -57,7 +57,9 @@ def sort_by_port_index(value): if not value: return if isinstance(value, list): - value.sort(key = lambda k: int(k[8:])) + value.sort( + key = lambda k: int(k[8:]) if "BP" not in k else int(k[11:]) + 1024 + ) def is_ipv4(value): if not value: From 9dd690381bc04d64266ba51703589537b3951386 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Tue, 14 Jul 2020 16:11:07 -0700 Subject: [PATCH 2/4] error in 'if' statement, fixed it --- files/build_templates/buffers_config.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/build_templates/buffers_config.j2 b/files/build_templates/buffers_config.j2 index dacdd162f5db..f8733ed8e587 100644 --- a/files/build_templates/buffers_config.j2 +++ b/files/build_templates/buffers_config.j2 @@ -48,7 +48,7 @@ def {%- if DEVICE_NEIGHBOR_METADATA is defined and DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %} {%- set neighbor = DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] %} {%- set neighbor_role = neighbor.type %} - {%- 'asic' == neighbor_role | lower %} + {%- if 'asic' == neighbor_role | lower %} {%- set roles1 = 'internal' %} {%- else %} {%- set roles1 = switch_role + '_' + neighbor_role %} From 383de5f05d1751799c140e5e1f55e0dfba956ce5 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Tue, 21 Jul 2020 05:13:27 +0000 Subject: [PATCH 3/4] + added unit test to verify cable length calculation for multi ASIC platforms. All links that include backend ports must be of role 'internal'. --- .../tests/test_multinpu_cfggen.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/sonic-config-engine/tests/test_multinpu_cfggen.py b/src/sonic-config-engine/tests/test_multinpu_cfggen.py index 7511ce9bcdd1..4b05541daa8f 100644 --- a/src/sonic-config-engine/tests/test_multinpu_cfggen.py +++ b/src/sonic-config-engine/tests/test_multinpu_cfggen.py @@ -4,6 +4,7 @@ import os import json import yaml +import shutil SKU = 'multi-npu-01' ASIC_SKU = 'multi-npu-asic' @@ -274,3 +275,47 @@ def test_loopback_intfs(self): "Loopback0|FC00:1::32/128": {}, "Loopback4096|8.0.0.5/32": {}, "Loopback4096|FD00:4::32/128": {}}) + + def test_buffers_multi_asic_template(self): + build_root_dir = os.path.join( + self.test_dir, "..", "..", ".." + ) + # using Trident2 buffer configuration + device_config_dir = os.path.join( + build_root_dir, + "device", + "arista", + "x86_64-arista_7050_qx32", + "Arista-7050-QX32" + ) + device_buffer_template = os.path.join( + device_config_dir, "buffers.json.j2" + ) + buffer_template = os.path.join( + build_root_dir, "files", "build_templates", "buffers_config.j2" + ) + port_config_ini_asic0 = os.path.join( + self.test_data_dir, "sample_port_config-0.ini" + ) + # asic0 - mix of front end and back end ports + shutil.copy2(buffer_template, device_config_dir) + argument = "-m {} -p {} -n asic0 -t {}".format( + self.sample_graph, port_config_ini_asic0, device_buffer_template + ) + output = json.loads(self.run_script(argument)) + os.remove(os.path.join(device_config_dir, "buffers_config.j2")) + self.assertDictEqual( + output['CABLE_LENGTH'], + { + 'AZURE': { + 'Ethernet8': '300m', + 'Ethernet0': '300m', + 'Ethernet4': '300m', + 'Ethernet-BP4': '5m', + 'Ethernet-BP0': '5m', + 'Ethernet-BP12': '5m', + 'Ethernet-BP8': '5m', + 'Ethernet12': '300m' + } + } + ) From ed754d8f3f23454de0e2ae75b89d8ca324139bd1 Mon Sep 17 00:00:00 2001 From: Mahesh Maddikayala Date: Thu, 23 Jul 2020 20:16:38 +0000 Subject: [PATCH 4/4] + added comment for the change in 'sort_port_by_index' API --- src/sonic-config-engine/sonic-cfggen | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sonic-config-engine/sonic-cfggen b/src/sonic-config-engine/sonic-cfggen index b296f4054c90..eb4c101f8c51 100755 --- a/src/sonic-config-engine/sonic-cfggen +++ b/src/sonic-config-engine/sonic-cfggen @@ -57,6 +57,8 @@ def sort_by_port_index(value): if not value: return if isinstance(value, list): + # In multi-ASIC platforms backend ethernet ports are identified as + # 'Ethernet-BPxy'. Add 1024 to sort backend ports to the end. value.sort( key = lambda k: int(k[8:]) if "BP" not in k else int(k[11:]) + 1024 )