Skip to content

Commit 3e19a49

Browse files
committed
[minigraph] Support FECDisabled in minigraph parser (#4556)
Signed-off-by: Qi Luo <[email protected]>
1 parent 7234bc1 commit 3e19a49

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

src/sonic-config-engine/minigraph.py

+49-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
BACKEND_ASIC_SUB_ROLE = 'BackEnd'
4040
BACKEND_ASIC_INTERFACE_NAME_PREFIX = 'Ethernet-BP'
4141

42-
# Default Virtual Network Index (VNI)
42+
# Default Virtual Network Index (VNI)
4343
vni_default = 8000
4444

4545
###############################################################################
@@ -554,6 +554,39 @@ def parse_meta(meta, hname):
554554
region = value
555555
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region
556556

557+
558+
def parse_linkmeta(meta, hname):
559+
link = meta.find(str(QName(ns, "Link")))
560+
linkmetas = {}
561+
for linkmeta in link.findall(str(QName(ns1, "LinkMetadata"))):
562+
port = None
563+
fec_disabled = None
564+
565+
# Sample: ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/4
566+
key = linkmeta.find(str(QName(ns1, "Key"))).text
567+
endpoints = key.split(';')
568+
for endpoint in endpoints:
569+
t = endpoint.split(':')
570+
if len(t) == 2 and t[0].lower() == hname.lower():
571+
port = t[1]
572+
break
573+
else:
574+
# Cannot find a matching hname, something went wrong
575+
continue
576+
577+
properties = linkmeta.find(str(QName(ns1, "Properties")))
578+
for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))):
579+
name = device_property.find(str(QName(ns1, "Name"))).text
580+
value = device_property.find(str(QName(ns1, "Value"))).text
581+
if name == "FECDisabled":
582+
fec_disabled = value
583+
584+
linkmetas[port] = {}
585+
if fec_disabled:
586+
linkmetas[port]["FECDisabled"] = fec_disabled
587+
return linkmetas
588+
589+
557590
def parse_asic_meta(meta, hname):
558591
sub_role = None
559592
device_metas = meta.find(str(QName(ns, "Devices")))
@@ -732,7 +765,6 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
732765
generate asic specific configuration.
733766
"""
734767
root = ET.parse(filename).getroot()
735-
mini_graph_path = filename
736768

737769
u_neighbors = None
738770
u_devices = None
@@ -766,8 +798,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
766798
deployment_id = None
767799
region = None
768800
hostname = None
801+
linkmetas = {}
769802

770-
#hostname is the asic_name, get the asic_id from the asic_name
803+
# hostname is the asic_name, get the asic_id from the asic_name
771804
if asic_name is not None:
772805
asic_id = get_npu_id_from_name(asic_name)
773806
else:
@@ -800,6 +833,8 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
800833
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
801834
elif child.tag == str(QName(ns, "MetadataDeclaration")):
802835
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region) = parse_meta(child, hostname)
836+
elif child.tag == str(QName(ns, "LinkMetadataDeclaration")):
837+
linkmetas = parse_linkmeta(child, hostname)
803838
elif child.tag == str(QName(ns, "DeviceInfos")):
804839
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
805840
else:
@@ -811,6 +846,8 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
811846
(neighbors, devices, port_speed_png) = parse_asic_png(child, asic_name, hostname)
812847
elif child.tag == str(QName(ns, "MetadataDeclaration")):
813848
(sub_role) = parse_asic_meta(child, asic_name)
849+
elif child.tag == str(QName(ns, "LinkMetadataDeclaration")):
850+
linkmetas = parse_linkmeta(child, hostname)
814851
elif child.tag == str(QName(ns, "DeviceInfos")):
815852
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
816853

@@ -896,7 +933,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
896933

897934
for port_name in port_speed_png:
898935
# not consider port not in port_config.ini
899-
#If no port_config_file is found ports is empty so ignore this error
936+
# If no port_config_file is found ports is empty so ignore this error
900937
if port_config_file is not None:
901938
if port_name not in ports:
902939
print >> sys.stderr, "Warning: ignore interface '%s' as it is not in the port_config.ini" % port_name
@@ -905,7 +942,14 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
905942
ports.setdefault(port_name, {})['speed'] = port_speed_png[port_name]
906943

907944
for port_name, port in ports.items():
908-
if port.get('speed') == '100000':
945+
# get port alias from port_config.ini
946+
if port_config_file:
947+
alias = port.get('alias')
948+
else:
949+
alias = port_name
950+
# generate default 100G FEC
951+
# Note: FECDisabled only be effective on 100G port right now
952+
if port.get('speed') == '100000' and linkmetas.get(alias, {}).get('FECDisabled', '').lower() != 'true':
909953
port['fec'] = 'rs'
910954

911955
# set port description if parsed from deviceinfo

src/sonic-config-engine/tests/t0-sample-graph.xml

+29-2
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,14 @@
381381
<EndPort>Ethernet1/1</EndPort>
382382
<StartDevice>switch-t0</StartDevice>
383383
<StartPort>fortyGigE0/124</StartPort>
384+
<Bandwidth>100000</Bandwidth>
384385
</DeviceLinkBase>
385386
<DeviceLinkBase>
386387
<ElementType>DeviceInterfaceLink</ElementType>
387388
<AutoNegotiation>true</AutoNegotiation>
388-
<Bandwidth>10000</Bandwidth>
389+
<Bandwidth>100000</Bandwidth>
389390
<EndDevice>switch-t0</EndDevice>
390-
<EndPort>fortyGigE0/2</EndPort>
391+
<EndPort>fortyGigE0/4</EndPort>
391392
<FlowControl>true</FlowControl>
392393
<StartDevice>ARISTA05T1</StartDevice>
393394
<StartPort>Ethernet1/33</StartPort>
@@ -439,6 +440,32 @@
439440
</Devices>
440441
<Properties xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
441442
</MetadataDeclaration>
443+
<LinkMetadataDeclaration>
444+
<Link xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
445+
<a:LinkMetadata>
446+
<a:Name i:nil="true"/>
447+
<a:Properties>
448+
<a:DeviceProperty>
449+
<a:Name>FECDisabled</a:Name>
450+
<a:Reference i:nil="true"/>
451+
<a:Value>True</a:Value>
452+
</a:DeviceProperty>
453+
</a:Properties>
454+
<a:Key>ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/4</a:Key>
455+
</a:LinkMetadata>
456+
<a:LinkMetadata>
457+
<a:Name i:nil="true"/>
458+
<a:Properties>
459+
<a:DeviceProperty>
460+
<a:Name>FECDisabled</a:Name>
461+
<a:Reference i:nil="true"/>
462+
<a:Value>True</a:Value>
463+
</a:DeviceProperty>
464+
</a:Properties>
465+
<a:Key>ARISTA06T1:Ethernet1/34;switch-t0:fortyGigE0/8</a:Key>
466+
</a:LinkMetadata>
467+
</Link>
468+
</LinkMetadataDeclaration>
442469
<Hostname>switch-t0</Hostname>
443470
<HwSku>Force10-S6000</HwSku>
444471
</DeviceMiniGraph>

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def test_minigraph_acl(self):
107107
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
108108
output = self.run_script(argument, True)
109109
self.assertEqual(output.strip(), "Warning: Ignoring Control Plane ACL NTP_ACL without type\n"
110-
"Warning: ignore interface 'fortyGigE0/2' as it is not in the port_config.ini\n"
111-
"Warning: ignore interface 'fortyGigE0/2' in DEVICE_NEIGHBOR as it is not in the port_config.ini\n"
112110
"{'NTP_ACL': {'services': ['NTP'], 'type': 'CTRLPLANE', 'policy_desc': 'NTP_ACL', 'stage': 'ingress'}, "
113111
"'EVERFLOW': {'stage': 'ingress', 'type': 'MIRROR', 'ports': ['PortChannel01', 'PortChannel02', 'PortChannel03', 'PortChannel04', 'Ethernet4'], 'policy_desc': 'EVERFLOW'}, "
114112
"'EVERFLOW_EGRESS': {'stage': 'egress', 'type': 'MIRROR', 'ports': ['PortChannel01', 'PortChannel02', 'PortChannel03', 'PortChannel04', 'Ethernet4'], 'policy_desc': 'EVERFLOW_EGRESS'}, "
@@ -191,7 +189,18 @@ def test_minigraph_extra_neighbors(self):
191189
def test_minigraph_port_description(self):
192190
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet124\']"'
193191
output = self.run_script(argument)
194-
self.assertEqual(output.strip(), "{'lanes': '101,102,103,104', 'description': 'ARISTA04T1:Ethernet1/1', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/124', 'admin_status': 'up'}")
192+
self.assertEqual(output.strip(), "{'lanes': '101,102,103,104', 'fec': 'rs', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/124', 'admin_status': 'up', 'speed': '100000', 'description': 'ARISTA04T1:Ethernet1/1'}")
193+
194+
def test_minigraph_port_fec_disabled(self):
195+
# Test for FECDisabled
196+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet4\']"'
197+
output = self.run_script(argument)
198+
self.assertEqual(output.strip(), "{'lanes': '25,26,27,28', 'description': 'Servers0:eth0', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/4', 'admin_status': 'up', 'speed': '100000'}")
199+
200+
def test_minigraph_port_rs(self):
201+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet124\']"'
202+
output = self.run_script(argument)
203+
self.assertEqual(output.strip(), "{'lanes': '101,102,103,104', 'fec': 'rs', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/124', 'admin_status': 'up', 'speed': '100000', 'description': 'ARISTA04T1:Ethernet1/1'}")
195204

196205
def test_minigraph_bgp(self):
197206
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v "BGP_NEIGHBOR[\'10.0.0.59\']"'

0 commit comments

Comments
 (0)