Skip to content

Commit 2f4ce21

Browse files
qiluo-msftlguohan
authored andcommitted
[minigraph] Fix parser on PNG DeviceInterfaceLink Bandwidth (#1592)
* [minigraph] Fix parser on PNG DeviceInterfaceLink Bandwidth Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
1 parent f8aac10 commit 2f4ce21

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

src/sonic-config-engine/minigraph.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def parse_png(png, hname):
6262
console_port = ''
6363
mgmt_dev = ''
6464
mgmt_port = ''
65+
port_speeds = {}
6566
for child in png:
6667
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
6768
for link in child.findall(str(QName(ns, "DeviceLinkBase"))):
@@ -73,15 +74,21 @@ def parse_png(png, hname):
7374
endport = link.find(str(QName(ns, "EndPort"))).text
7475
startdevice = link.find(str(QName(ns, "StartDevice"))).text
7576
startport = link.find(str(QName(ns, "StartPort"))).text
77+
bandwidth_node = link.find(str(QName(ns, "Bandwidth")))
78+
bandwidth = bandwidth_node.text if bandwidth_node is not None else None
7679

7780
if enddevice == hname:
7881
if port_alias_map.has_key(endport):
7982
endport = port_alias_map[endport]
8083
neighbors[endport] = {'name': startdevice, 'port': startport}
84+
if bandwidth:
85+
port_speeds[endport] = bandwidth
8186
else:
8287
if port_alias_map.has_key(startport):
8388
startport = port_alias_map[startport]
8489
neighbors[startport] = {'name': enddevice, 'port': endport}
90+
if bandwidth:
91+
port_speeds[startport] = bandwidth
8592

8693
if child.tag == str(QName(ns, "Devices")):
8794
for device in child.findall(str(QName(ns, "Device"))):
@@ -106,7 +113,7 @@ def parse_png(png, hname):
106113
elif node.tag == str(QName(ns, "EndDevice")):
107114
mgmt_dev = node.text
108115

109-
return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port)
116+
return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds)
110117

111118

112119
def parse_dpg(dpg, hname):
@@ -368,7 +375,8 @@ def parse_xml(filename, platform=None, port_config_file=None):
368375
neighbors = None
369376
devices = None
370377
hostname = None
371-
port_speeds = {}
378+
port_speeds_default = {}
379+
port_speed_png = {}
372380
port_descriptions = {}
373381
syslog_servers = []
374382
dhcp_servers = []
@@ -395,13 +403,13 @@ def parse_xml(filename, platform=None, port_config_file=None):
395403
elif child.tag == str(QName(ns, "CpgDec")):
396404
(bgp_sessions, bgp_asn, bgp_peers_with_range) = parse_cpg(child, hostname)
397405
elif child.tag == str(QName(ns, "PngDec")):
398-
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port) = parse_png(child, hostname)
406+
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png) = parse_png(child, hostname)
399407
elif child.tag == str(QName(ns, "UngDec")):
400-
(u_neighbors, u_devices, _, _, _, _) = parse_png(child, hostname)
408+
(u_neighbors, u_devices, _, _, _, _, _) = parse_png(child, hostname)
401409
elif child.tag == str(QName(ns, "MetadataDeclaration")):
402410
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname)
403411
elif child.tag == str(QName(ns, "DeviceInfos")):
404-
(port_speeds, port_descriptions) = parse_deviceinfo(child, hwsku)
412+
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)
405413

406414
results = {}
407415
results['DEVICE_METADATA'] = {'localhost': {
@@ -438,14 +446,23 @@ def parse_xml(filename, platform=None, port_config_file=None):
438446
results['VLAN_INTERFACE'] = vlan_intfs
439447
results['PORTCHANNEL_INTERFACE'] = pc_intfs
440448

441-
for port_name in port_speeds:
449+
for port_name in port_speeds_default:
442450
# ignore port not in port_config.ini
443451
if not ports.has_key(port_name):
444452
continue
445453

446-
ports.setdefault(port_name, {})['speed'] = port_speeds[port_name]
447-
if port_speeds[port_name] == '100000':
448-
ports.setdefault(port_name, {})['fec'] = 'rs'
454+
ports.setdefault(port_name, {})['speed'] = port_speeds_default[port_name]
455+
456+
for port_name in port_speed_png:
457+
# if port_name is not in port_config.ini, still consider it.
458+
# and later swss will pick up and behave on-demand port break-up.
459+
# if on-deman port break-up is not supported on a specific platform, swss will return error.
460+
ports.setdefault(port_name, {})['speed'] = port_speed_png[port_name]
461+
462+
for port_name, port in ports.items():
463+
if port.get('speed') == '100000':
464+
port['fec'] = 'rs'
465+
449466
for port_name in port_descriptions:
450467
# ignore port not in port_config.ini
451468
if not ports.has_key(port_name):

src/sonic-config-engine/tests/sample_output/ports.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"PORT_TABLE:Ethernet8": {
4-
"speed": "40000",
4+
"speed": "1000",
55
"description": "Interface description"
66
},
77
"OP": "SET"

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,19 @@
181181
</DeviceDataPlaneInfo>
182182
</DpgDec>
183183
<PngDec>
184-
<DeviceInterfaceLinks/>
184+
<DeviceInterfaceLinks>
185+
<DeviceLinkBase i:type="DeviceInterfaceLink">
186+
<ElementType>DeviceInterfaceLink</ElementType>
187+
<AutoNegotiation>true</AutoNegotiation>
188+
<Bandwidth>1000</Bandwidth>
189+
<EndDevice>ARISTA01T1</EndDevice>
190+
<EndPort>et1</EndPort>
191+
<FlowControl>true</FlowControl>
192+
<StartDevice>switch-t0</StartDevice>
193+
<StartPort>fortyGigE0/8</StartPort>
194+
<Validate>true</Validate>
195+
</DeviceLinkBase>
196+
</DeviceInterfaceLinks>
185197
<Devices>
186198
<Device i:type="ToRRouter">
187199
<Hostname>switch-t0</Hostname>

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_minigraph_deployment_id(self):
148148
def test_minigraph_ethernet_interfaces(self):
149149
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet8\']"'
150150
output = self.run_script(argument)
151-
self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '40000'}")
151+
self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '1000'}")
152152
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet12\']"'
153153
output = self.run_script(argument)
154154
self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/12', 'lanes': '33,34,35,36', 'fec': 'rs', 'speed': '100000', 'description': 'Interface description'}")
@@ -157,7 +157,7 @@ def test_minigraph_extra_ethernet_interfaces(self):
157157
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT"'
158158
output = self.run_script(argument)
159159
self.assertEqual(output.strip(), \
160-
"{'Ethernet8': {'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '40000'}, "
160+
"{'Ethernet8': {'alias': 'fortyGigE0/8', 'lanes': '37,38,39,40', 'description': 'Interface description', 'speed': '1000'}, "
161161
"'Ethernet0': {'alias': 'fortyGigE0/0', 'lanes': '29,30,31,32', 'speed': '10000'}, "
162162
"'Ethernet4': {'alias': 'fortyGigE0/4', 'lanes': '25,26,27,28', 'speed': '25000'}, "
163163
"'Ethernet108': {'alias': 'fortyGigE0/108', 'lanes': '81,82,83,84'}, "

0 commit comments

Comments
 (0)