Skip to content

Commit

Permalink
[Chassis] parse 400g zr port config from minigraph (#11616)
Browse files Browse the repository at this point in the history
Signed-off-by: Arvindsrinivasan Lakshmi Narasimhan [email protected]

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 <[email protected]>
  • Loading branch information
arlakshm authored and yxieca committed Aug 17, 2022
1 parent 25e48f9 commit f9bfa47
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,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
Expand All @@ -989,6 +990,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:
Expand All @@ -1002,6 +1007,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):
Expand Down Expand Up @@ -1613,6 +1623,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
Expand Down
19 changes: 19 additions & 0 deletions src/sonic-config-engine/tests/sample-chassis-packet-lc-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@
</IPNextHops>
</DeviceDataPlaneInfo>
</DpgDec>
<LinkMetadataDeclaration>
<Link xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
<a:LinkMetadata>
<a:Name i:nil="true"/>
<a:Properties>
<a:DeviceProperty>
<a:Name>Frequency</a:Name>
<a:Value>131</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>TxPower</a:Name>
<a:Value>7.5</a:Value>
</a:DeviceProperty>
</a:Properties>
<a:Key>str2-8808-lc2-1:Eth1/1/13;ARISTA01-RH:Ethernet1/1</a:Key>
</a:LinkMetadata>
</Link>
<Properties xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
</LinkMetadataDeclaration>
<PngDec>
<DeviceInterfaceLinks>
<DeviceLinkBase>
Expand Down
14 changes: 14 additions & 0 deletions src/sonic-config-engine/tests/sample-voq-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@
</a:Properties>
<a:Key>linecard-1:Ethernet1/1;ARISTA01-RH:Ethernet1/1</a:Key>
</a:LinkMetadata>
<a:LinkMetadata>
<a:Name i:nil="true"/>
<a:Properties>
<a:DeviceProperty>
<a:Name>Frequency</a:Name>
<a:Value>195.875</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>TxPower</a:Name>
<a:Value>-10</a:Value>
</a:DeviceProperty>
</a:Properties>
<a:Key>linecard-1:Ethernet2/1;ARISTA01-RH:Ethernet1/1</a:Key>
</a:LinkMetadata>
</Link>
<Properties xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
</LinkMetadataDeclaration>
Expand Down
14 changes: 14 additions & 0 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,3 +1008,17 @@ def test_minigraph_bgp_packet_chassis_vlan_subintf(self):
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)

0 comments on commit f9bfa47

Please sign in to comment.