From 743625c2b48dbda3735c38e6002b40b246bd7e28 Mon Sep 17 00:00:00 2001 From: arlakshm <55814491+arlakshm@users.noreply.github.com> Date: Fri, 12 Aug 2022 11:55:18 -0700 Subject: [PATCH] [Chassis] parse 400g zr port config from minigraph (#11616) Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan arlakshm@microsoft.com Why I did it Generate the port configuration required 400G ZR port from minigraph. How I did it Add parse logic to get tx_power and laser_freq from LinkMetadata section of the minigraph. Add UT for packet-chassis and voq chassis How to verify it UT Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan --- src/sonic-config-engine/minigraph.py | 20 ++++++++++++++++++- .../tests/sample-chassis-packet-lc-graph.xml | 19 ++++++++++++++++++ .../tests/sample-voq-graph.xml | 14 +++++++++++++ src/sonic-config-engine/tests/test_cfggen.py | 14 +++++++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 4e573cd22a..d267c24976 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -973,7 +973,8 @@ def parse_linkmeta(meta, hname): lower_tor_hostname = '' auto_negotiation = None macsec_enabled = False - + tx_power = None + laser_freq = None properties = linkmeta.find(str(QName(ns1, "Properties"))) for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))): name = device_property.find(str(QName(ns1, "Name"))).text @@ -990,6 +991,10 @@ def parse_linkmeta(meta, hname): auto_negotiation = value elif name == "MacSecEnabled": macsec_enabled = value + elif name == "TxPower": + tx_power = value + elif name == "Frequency": + laser_freq = value linkmetas[port] = {} if fec_disabled: @@ -1003,6 +1008,11 @@ def parse_linkmeta(meta, hname): linkmetas[port]["AutoNegotiation"] = auto_negotiation if macsec_enabled: linkmetas[port]["MacSecEnabled"] = macsec_enabled + if tx_power: + linkmetas[port]["tx_power"] = tx_power + # Convert the freq in GHz + if laser_freq: + linkmetas[port]["laser_freq"] = int(float(laser_freq)*1000) return linkmetas def parse_macsec_profile(val_string): @@ -1615,6 +1625,14 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw if macsec_enabled and 'PrimaryKey' in macsec_profile: port['macsec'] = macsec_profile['PrimaryKey'] + tx_power = linkmetas.get(alias, {}).get('tx_power') + if tx_power: + port['tx_power'] = tx_power + + laser_freq = linkmetas.get(alias, {}).get('laser_freq') + if laser_freq: + port['laser_freq'] = laser_freq + # set port description if parsed from deviceinfo for port_name in port_descriptions: # ignore port not in port_config.ini diff --git a/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml b/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml index ac83d87b96..6b22d30336 100644 --- a/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml +++ b/src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml @@ -222,6 +222,25 @@ + + + + + + + Frequency + 131 + + + TxPower + 7.5 + + + str2-8808-lc2-1:Eth1/1/13;ARISTA01-RH:Ethernet1/1 + + + + diff --git a/src/sonic-config-engine/tests/sample-voq-graph.xml b/src/sonic-config-engine/tests/sample-voq-graph.xml index f1fa436203..a43e64cf65 100644 --- a/src/sonic-config-engine/tests/sample-voq-graph.xml +++ b/src/sonic-config-engine/tests/sample-voq-graph.xml @@ -79,6 +79,20 @@ linecard-1:Ethernet1/1;ARISTA01-RH:Ethernet1/1 + + + + + Frequency + 195.875 + + + TxPower + -10 + + + linecard-1:Ethernet2/1;ARISTA01-RH:Ethernet1/1 + diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 232fded47e..1190ef9680 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -1008,3 +1008,17 @@ class TestCfgGen(TestCase): utils.to_dict(output.strip()), utils.to_dict("{('PortChannel32.2', '192.168.1.4/24'): {}, 'PortChannel32.2': {'admin_status': 'up'}, ('PortChannel33.2', '192.168.2.4/24'): {}, 'PortChannel33.2': {'admin_status': 'up'}}") ) + + def test_minigraph_voq_400g_zr_port_config(self): + argument = "-j {} -m {} -p {} -v \"PORT[\'Ethernet4\']\"".format(self.macsec_profile, self.sample_graph_voq, self.voq_port_config) + output = self.run_script(argument) + output_dict = utils.to_dict(output.strip()) + self.assertEqual(output_dict['tx_power'], '-10') + self.assertEqual(output_dict['laser_freq'], 195875) + + def test_minigraph_packet_chassis_400g_zr_port_config(self): + argument = "-m {} -p {} -n asic1 -v \"PORT[\'Ethernet13\']\"".format(self.packet_chassis_graph, self.packet_chassis_port_ini) + output = self.run_script(argument) + output_dict = utils.to_dict(output.strip()) + self.assertEqual(output_dict['tx_power'], '7.5') + self.assertEqual(output_dict['laser_freq'], 131000) \ No newline at end of file