Skip to content

Commit 8ba8fe5

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

File tree

3 files changed

+85
-7
lines changed

3 files changed

+85
-7
lines changed

src/sonic-config-engine/minigraph.py

+44-2
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,39 @@ def parse_meta(meta, hname):
415415
deployment_id = value
416416
return syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id
417417

418+
419+
def parse_linkmeta(meta, hname):
420+
link = meta.find(str(QName(ns, "Link")))
421+
linkmetas = {}
422+
for linkmeta in link.findall(str(QName(ns1, "LinkMetadata"))):
423+
port = None
424+
fec_disabled = None
425+
426+
# Sample: ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/4
427+
key = linkmeta.find(str(QName(ns1, "Key"))).text
428+
endpoints = key.split(';')
429+
for endpoint in endpoints:
430+
t = endpoint.split(':')
431+
if len(t) == 2 and t[0].lower() == hname.lower():
432+
port = t[1]
433+
break
434+
else:
435+
# Cannot find a matching hname, something went wrong
436+
continue
437+
438+
properties = linkmeta.find(str(QName(ns1, "Properties")))
439+
for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))):
440+
name = device_property.find(str(QName(ns1, "Name"))).text
441+
value = device_property.find(str(QName(ns1, "Value"))).text
442+
if name == "FECDisabled":
443+
fec_disabled = value
444+
445+
linkmetas[port] = {}
446+
if fec_disabled:
447+
linkmetas[port]["FECDisabled"] = fec_disabled
448+
return linkmetas
449+
450+
418451
def parse_deviceinfo(meta, hwsku):
419452
port_speeds = {}
420453
port_descriptions = {}
@@ -468,7 +501,6 @@ def filter_acl_mirror_table_bindings(acls, neighbors, port_channels):
468501

469502
def parse_xml(filename, platform=None, port_config_file=None):
470503
root = ET.parse(filename).getroot()
471-
mini_graph_path = filename
472504

473505
u_neighbors = None
474506
u_devices = None
@@ -500,6 +532,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
500532
erspan_dst = []
501533
bgp_peers_with_range = None
502534
deployment_id = None
535+
linkmetas = {}
503536

504537
hwsku_qn = QName(ns, "HwSku")
505538
hostname_qn = QName(ns, "Hostname")
@@ -525,6 +558,8 @@ def parse_xml(filename, platform=None, port_config_file=None):
525558
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
526559
elif child.tag == str(QName(ns, "MetadataDeclaration")):
527560
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname)
561+
elif child.tag == str(QName(ns, "LinkMetadataDeclaration")):
562+
linkmetas = parse_linkmeta(child, hostname)
528563
elif child.tag == str(QName(ns, "DeviceInfos")):
529564
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
530565

@@ -596,7 +631,14 @@ def parse_xml(filename, platform=None, port_config_file=None):
596631
ports.setdefault(port_name, {})['speed'] = port_speed_png[port_name]
597632

598633
for port_name, port in ports.items():
599-
if port.get('speed') == '100000':
634+
# get port alias from port_config.ini
635+
if port_config_file:
636+
alias = port.get('alias')
637+
else:
638+
alias = port_name
639+
# generate default 100G FEC
640+
# Note: FECDisabled only be effective on 100G port right now
641+
if port.get('speed') == '100000' and linkmetas.get(alias, {}).get('FECDisabled', '').lower() != 'true':
600642
port['fec'] = 'rs'
601643

602644
# 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
@@ -376,13 +376,14 @@
376376
<EndPort>Ethernet1/1</EndPort>
377377
<StartDevice>switch-t0</StartDevice>
378378
<StartPort>fortyGigE0/124</StartPort>
379+
<Bandwidth>100000</Bandwidth>
379380
</DeviceLinkBase>
380381
<DeviceLinkBase>
381382
<ElementType>DeviceInterfaceLink</ElementType>
382383
<AutoNegotiation>true</AutoNegotiation>
383-
<Bandwidth>10000</Bandwidth>
384+
<Bandwidth>100000</Bandwidth>
384385
<EndDevice>switch-t0</EndDevice>
385-
<EndPort>fortyGigE0/2</EndPort>
386+
<EndPort>fortyGigE0/4</EndPort>
386387
<FlowControl>true</FlowControl>
387388
<StartDevice>ARISTA05T1</StartDevice>
388389
<StartPort>Ethernet1/33</StartPort>
@@ -434,6 +435,32 @@
434435
</Devices>
435436
<Properties xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution"/>
436437
</MetadataDeclaration>
438+
<LinkMetadataDeclaration>
439+
<Link xmlns:a="http://schemas.datacontract.org/2004/07/Microsoft.Search.Autopilot.Evolution">
440+
<a:LinkMetadata>
441+
<a:Name i:nil="true"/>
442+
<a:Properties>
443+
<a:DeviceProperty>
444+
<a:Name>FECDisabled</a:Name>
445+
<a:Reference i:nil="true"/>
446+
<a:Value>True</a:Value>
447+
</a:DeviceProperty>
448+
</a:Properties>
449+
<a:Key>ARISTA05T1:Ethernet1/33;switch-t0:fortyGigE0/4</a:Key>
450+
</a:LinkMetadata>
451+
<a:LinkMetadata>
452+
<a:Name i:nil="true"/>
453+
<a:Properties>
454+
<a:DeviceProperty>
455+
<a:Name>FECDisabled</a:Name>
456+
<a:Reference i:nil="true"/>
457+
<a:Value>True</a:Value>
458+
</a:DeviceProperty>
459+
</a:Properties>
460+
<a:Key>ARISTA06T1:Ethernet1/34;switch-t0:fortyGigE0/8</a:Key>
461+
</a:LinkMetadata>
462+
</Link>
463+
</LinkMetadataDeclaration>
437464
<Hostname>switch-t0</Hostname>
438465
<HwSku>Force10-S6000</HwSku>
439466
</DeviceMiniGraph>

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def test_minigraph_acl(self):
8282
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
8383
output = self.run_script(argument, True)
8484
self.assertEqual(output.strip(), "Warning: Ignoring Control Plane ACL NTP_ACL without type\n"
85-
"Warning: ignore interface 'fortyGigE0/2' as it is not in the port_config.ini\n"
86-
"Warning: ignore interface 'fortyGigE0/2' in DEVICE_NEIGHBOR as it is not in the port_config.ini\n"
8785
"{'NTP_ACL': {'services': ['NTP'], 'type': 'CTRLPLANE', 'policy_desc': 'NTP_ACL', 'stage': 'ingress'}, "
8886
"'EVERFLOW': {'stage': 'ingress', 'type': 'MIRROR', 'ports': ['PortChannel01', 'PortChannel02', 'PortChannel03', 'PortChannel04', 'Ethernet4'], 'policy_desc': 'EVERFLOW'}, "
8987
"'ROUTER_PROTECT': {'services': ['SSH', 'SNMP'], 'type': 'CTRLPLANE', 'policy_desc': 'ROUTER_PROTECT', 'stage': 'ingress'}, "
@@ -165,7 +163,18 @@ def test_minigraph_extra_neighbors(self):
165163
def test_minigraph_port_description(self):
166164
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet124\']"'
167165
output = self.run_script(argument)
168-
self.assertEqual(output.strip(), "{'lanes': '101,102,103,104', 'description': 'ARISTA04T1:Ethernet1/1', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/124', 'admin_status': 'up'}")
166+
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'}")
167+
168+
def test_minigraph_port_fec_disabled(self):
169+
# Test for FECDisabled
170+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet4\']"'
171+
output = self.run_script(argument)
172+
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'}")
173+
174+
def test_minigraph_port_rs(self):
175+
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet124\']"'
176+
output = self.run_script(argument)
177+
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'}")
169178

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

0 commit comments

Comments
 (0)