diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 41fbd383b9ce..e4c513498eed 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -158,6 +158,23 @@ def get_chassis_type_and_hostname(root, hname): chassis_hostname = value return chassis_type, chassis_hostname +def is_chassis_lc_macsec_enabled(root, hname): + macsec_enble = None + for child in root: + if child.tag == str(QName(ns, "MetadataDeclaration")): + devices = child.find(str(QName(ns, "Devices"))) + for device_meta in devices.findall(str(QName(ns1, "DeviceMetadata"))): + device_name = device_meta.find(str(QName(ns1, "Name"))).text + if device_name != hname: + continue + properties = device_meta.find(str(QName(ns1, "Properties"))) + for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))): + name = device_property.find(str(QName(ns1, "Name"))).text + value = device_property.find(str(QName(ns1, "Value"))).text + if name == "MacSecEnabled": + macsec_enble = value + return macsec_enble + def is_minigraph_for_chassis(chassis_type): if chassis_type in [CHASSIS_CARD_VOQ, CHASSIS_CARD_PACKET]: return True @@ -2028,6 +2045,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw slot_index = None max_num_cores = None card_type = None + macsec_enabled = None hwsku_qn = QName(ns, "HwSku") hostname_qn = QName(ns, "Hostname") @@ -2041,6 +2059,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw docker_routing_config_mode = child.text hwsku, hostname, docker_routing_config_mode, chassis_type, chassis_hostname = parse_global_info(root) + macsec_enabled = is_chassis_lc_macsec_enabled(root, hostname) (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) @@ -2172,6 +2191,13 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw print("Warning: more than one peer switch was found. Only the first will be parsed: {}".format(results['PEER_SWITCH'].keys()[0])) results['DEVICE_METADATA']['localhost']['peer_switch'] = list(results['PEER_SWITCH'].keys())[0] + elif results['DEVICE_METADATA']['localhost']['type'] == 'SpineRouter': + if macsec_enabled == 'True': + results['DEVICE_METADATA']['localhost']['subtype'] = 'UpstreamLC' + elif macsec_enabled == 'False': + results['DEVICE_METADATA']['localhost']['subtype'] = 'DownstreamLC' + else: + results['DEVICE_METADATA']['localhost']['subtype'] = 'Supervisor' # Enable tunnel_qos_remap if downstream_redundancy_types(T1) or redundancy_type(T0) = Gemini/Libra enable_tunnel_qos_map = False diff --git a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_multi_asic.xml b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_multi_asic.xml index 2bbf8868da5e..f19e6adbb716 100644 --- a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_multi_asic.xml +++ b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_multi_asic.xml @@ -44009,7 +44009,7 @@ MacSecEnabled - True + False OsVersion @@ -48335,4 +48335,4 @@ Sonic-400g-lc-sku 1.0.1388.35297 - \ No newline at end of file + diff --git a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml index bb237ecbd79d..7e02cc781a8d 100644 --- a/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml +++ b/src/sonic-config-engine/tests/chassis_data/voq_chassis_data/voq_chassis_lc_single_asic.xml @@ -43525,7 +43525,7 @@ MacSecEnabled - False + True OsVersion diff --git a/src/sonic-config-engine/tests/test_chassis_cfggen.py b/src/sonic-config-engine/tests/test_chassis_cfggen.py index 83d4be6f3550..70805a9dc5e0 100644 --- a/src/sonic-config-engine/tests/test_chassis_cfggen.py +++ b/src/sonic-config-engine/tests/test_chassis_cfggen.py @@ -138,7 +138,8 @@ def test_device_metadata(self): 'switch_type': 'voq', 'switch_id': 20, 'max_cores': 64, - 'slice_type': 'AZNG_Production'}) + 'slice_type': 'AZNG_Production', + 'subtype': 'UpstreamLC'}) def test_port(self): argument = ['-m', self.sample_graph, '-p', @@ -444,8 +445,10 @@ def test_device_metadata(self): 'chassis_hostname': 'str-sonic', 'deployment_id': '3', 'cluster': 'TestbedForstr-sonic', + 'subtype': 'DownstreamLC', 'switch_type': 'voq', - 'max_cores': 64}) + 'max_cores': 64, + }) def test_device_metadata_for_namespace(self): argument = [ @@ -473,7 +476,8 @@ def test_device_metadata_for_namespace(self): 'asic_name': 'asic0', 'switch_type': 'voq', 'switch_id': 8, - 'max_cores': 64}) + 'max_cores': 64, + 'subtype': 'DownstreamLC'}) def test_system_port(self): argument = ['-m', self.sample_graph, @@ -920,6 +924,7 @@ def test_device_metadata(self): "chassis_hostname": "str-sonic", "deployment_id": "3", "cluster": "TestbedForstr-sonic", + "subtype": "Supervisor", "switch_type": "fabric", "sub_role": "fabric", "max_cores": 64 @@ -950,7 +955,8 @@ def test_device_metadata_for_namespace(self): "sub_role": "Fabric", "asic_name": "asic0", "switch_type": "fabric", - "max_cores": 64 + "max_cores": 64, + "subtype": "Supervisor", } ) @@ -1054,6 +1060,7 @@ def test_device_metadata(self): "chassis_hostname": "str-sonic", "deployment_id": "3", "cluster": "TestbedForstr-sonic", + "subtype": "Supervisor", "switch_type": "chassis-packet", "sub_role": "BackEnd", "max_cores": 64 @@ -1082,6 +1089,7 @@ def test_device_metadata_for_namespace(self): "deployment_id": "3", "cluster": "TestbedForstr-sonic", "sub_role": "BackEnd", + "subtype": "Supervisor", "asic_name": "asic0", "switch_type": "chassis-packet", "max_cores": 64 diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json b/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json index 119e5b7cec44..99310fecc6ab 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/device_metadata.json @@ -94,8 +94,17 @@ "DEVICE_METADATA_VALID_CLUSTER": { "desc": "Verifying valid cluster configuration." }, - "DEVICE_METADATA_VALID_SUBTYPE": { - "desc": "Verifying valid subtype value" + "DEVICE_METADATA_VALID_SUBTYPE0": { + "desc": "Verifying valid subtype value dualtor" + }, + "DEVICE_METADATA_VALID_SUBTYPE1": { + "desc": "Verifying valid subtype value supervisor" + }, + "DEVICE_METADATA_VALID_SUBTYPE2": { + "desc": "Verifying valid subtype value upstreamLC" + }, + "DEVICE_METADATA_VALID_SUBTYPE3": { + "desc": "Verifying valid subtype value downstreamLC" }, "DEVICE_METADATA_INVALID_SUBTYPE": { "desc": "Verifying invalid subtype value", diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json index 5d0e0201b4ff..44f0966c8b18 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/device_metadata.json @@ -256,7 +256,7 @@ } } }, - "DEVICE_METADATA_VALID_SUBTYPE": { + "DEVICE_METADATA_VALID_SUBTYPE0": { "sonic-device_metadata:sonic-device_metadata": { "sonic-device_metadata:DEVICE_METADATA": { "sonic-device_metadata:localhost": { @@ -265,6 +265,33 @@ } } }, + "DEVICE_METADATA_VALID_SUBTYPE1": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "subtype": "Supervisor" + } + } + } + }, + "DEVICE_METADATA_VALID_SUBTYPE2": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "subtype": "UpstreamLC" + } + } + } + }, + "DEVICE_METADATA_VALID_SUBTYPE3": { + "sonic-device_metadata:sonic-device_metadata": { + "sonic-device_metadata:DEVICE_METADATA": { + "sonic-device_metadata:localhost": { + "subtype": "DownstreamLC" + } + } + } + }, "DEVICE_METADATA_INVALID_SUBTYPE": { "sonic-device_metadata:sonic-device_metadata": { "sonic-device_metadata:DEVICE_METADATA": { diff --git a/src/sonic-yang-models/yang-models/sonic-device_metadata.yang b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang index c097da81a870..0d0607fd3cab 100644 --- a/src/sonic-yang-models/yang-models/sonic-device_metadata.yang +++ b/src/sonic-yang-models/yang-models/sonic-device_metadata.yang @@ -164,7 +164,7 @@ module sonic-device_metadata { leaf subtype { type string { - pattern "DualToR|SmartSwitch"; + pattern "DualToR|SmartSwitch|Supervisor|UpstreamLC|DownstreamLC"; } }