[minigraph] Parse bandwidth for DeviceMgmtLinks (#7744)

Why I did it
The current code skips parsing bandwidth for DeviceMgmtLinks. We have a use case to set the speed for these type of links based on the bandwidth attribute in the minigraph

How to verify it
Ran sonic-cfggen on a minigraph and verified that interface of type DeviceMgmtLink has speed set in the PORT table from the bandwidth attribute in the minigraph
This commit is contained in:
Neetha John 2021-05-28 15:20:30 -07:00 committed by GitHub
parent 4f8dec9a6f
commit 4b00f8ab09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 4 deletions

View File

@ -218,7 +218,7 @@ def parse_png(png, hname, dpg_ecmp_content = None):
startdevice = link.find(str(QName(ns, "StartDevice"))).text startdevice = link.find(str(QName(ns, "StartDevice"))).text
port_device_map[endport] = startdevice port_device_map[endport] = startdevice
if linktype != "DeviceInterfaceLink" and linktype != "UnderlayInterfaceLink": if linktype != "DeviceInterfaceLink" and linktype != "UnderlayInterfaceLink" and linktype != "DeviceMgmtLink":
continue continue
enddevice = link.find(str(QName(ns, "EndDevice"))).text enddevice = link.find(str(QName(ns, "EndDevice"))).text
@ -230,13 +230,15 @@ def parse_png(png, hname, dpg_ecmp_content = None):
if enddevice.lower() == hname.lower(): if enddevice.lower() == hname.lower():
if endport in port_alias_map: if endport in port_alias_map:
endport = port_alias_map[endport] endport = port_alias_map[endport]
neighbors[endport] = {'name': startdevice, 'port': startport} if linktype != "DeviceMgmtLink":
neighbors[endport] = {'name': startdevice, 'port': startport}
if bandwidth: if bandwidth:
port_speeds[endport] = bandwidth port_speeds[endport] = bandwidth
elif startdevice.lower() == hname.lower(): elif startdevice.lower() == hname.lower():
if startport in port_alias_map: if startport in port_alias_map:
startport = port_alias_map[startport] startport = port_alias_map[startport]
neighbors[startport] = {'name': enddevice, 'port': endport} if linktype != "DeviceMgmtLink":
neighbors[startport] = {'name': enddevice, 'port': endport}
if bandwidth: if bandwidth:
port_speeds[startport] = bandwidth port_speeds[startport] = bandwidth
@ -1405,6 +1407,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
print("Warning: ignore interface '%s' as it is not in the port_config.ini" % port_name, file=sys.stderr) print("Warning: ignore interface '%s' as it is not in the port_config.ini" % port_name, file=sys.stderr)
continue continue
# skip management ports
if port_name in mgmt_alias_reverse_mapping.keys():
continue
ports.setdefault(port_name, {})['speed'] = port_speed_png[port_name] ports.setdefault(port_name, {})['speed'] = port_speed_png[port_name]
for port_name, port in list(ports.items()): for port_name, port in list(ports.items()):

View File

@ -20,6 +20,13 @@
}, },
"OP": "SET" "OP": "SET"
}, },
{
"PORT_TABLE:Ethernet16": {
"speed": "1000",
"description": "fortyGigE0/16"
},
"OP": "SET"
},
{ {
"PORT_TABLE:Ethernet12": { "PORT_TABLE:Ethernet12": {
"speed": "100000", "speed": "100000",

View File

@ -26,5 +26,12 @@
"description": "Interface description" "description": "Interface description"
}, },
"OP": "SET" "OP": "SET"
},
{
"PORT_TABLE:Ethernet16": {
"speed": "1000",
"description": "fortyGigE0/16"
},
"OP": "SET"
} }
] ]

View File

@ -308,6 +308,25 @@
<StartPort>Ethernet1/33</StartPort> <StartPort>Ethernet1/33</StartPort>
<Validate>true</Validate> <Validate>true</Validate>
</DeviceLinkBase> </DeviceLinkBase>
<DeviceLinkBase i:type="DeviceMgmtLink">
<ElementType>DeviceMgmtLink</ElementType>
<Bandwidth>1000</Bandwidth>
<EndDevice>switch-t0</EndDevice>
<EndPort>fortyGigE0/16</EndPort>
<FlowControl>true</FlowControl>
<StartDevice>ChassisMTS1</StartDevice>
<StartPort>mgmt0</StartPort>
<Validate>true</Validate>
</DeviceLinkBase>
<DeviceLinkBase i:type="DeviceMgmtLink">
<ElementType>DeviceMgmtLink</ElementType>
<Bandwidth>1000</Bandwidth>
<EndDevice>switch-t0</EndDevice>
<EndPort>Management1</EndPort>
<StartDevice>switch-m0</StartDevice>
<StartPort>Management1</StartPort>
<Validate>true</Validate>
</DeviceLinkBase>
</DeviceInterfaceLinks> </DeviceInterfaceLinks>
<Devices> <Devices>
<Device i:type="ToRRouter"> <Device i:type="ToRRouter">
@ -410,6 +429,18 @@
<Speed>100000</Speed> <Speed>100000</Speed>
<Description>Interface description</Description> <Description>Interface description</Description>
</a:EthernetInterface> </a:EthernetInterface>
<a:EthernetInterface>
<ElementType>DeviceInterface</ElementType>
<AlternateSpeeds i:nil="true"/>
<EnableFlowControl>true</EnableFlowControl>
<Index>1</Index>
<InterfaceName>fortyGigE0/16</InterfaceName>
<InterfaceType i:nil="true"/>
<MultiPortsInterface>false</MultiPortsInterface>
<PortName>0</PortName>
<Priority>0</Priority>
<Speed>100000</Speed>
</a:EthernetInterface>
</EthernetInterfaces> </EthernetInterfaces>
<FlowControl>true</FlowControl> <FlowControl>true</FlowControl>
<Height>0</Height> <Height>0</Height>

View File

@ -524,7 +524,7 @@ class TestCfgGen(TestCase):
"'Ethernet4': {'lanes': '25,26,27,28', 'description': 'fortyGigE0/4', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/4', 'admin_status': 'up', 'speed': '25000'}, " "'Ethernet4': {'lanes': '25,26,27,28', 'description': 'fortyGigE0/4', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/4', 'admin_status': 'up', 'speed': '25000'}, "
"'Ethernet8': {'lanes': '37,38,39,40', 'description': 'Interface description', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/8', 'admin_status': 'up', 'speed': '1000'}, " "'Ethernet8': {'lanes': '37,38,39,40', 'description': 'Interface description', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/8', 'admin_status': 'up', 'speed': '1000'}, "
"'Ethernet12': {'lanes': '33,34,35,36', 'fec': 'rs', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/12', 'admin_status': 'up', 'speed': '100000', 'description': 'Interface description'}, " "'Ethernet12': {'lanes': '33,34,35,36', 'fec': 'rs', 'pfc_asym': 'off', 'mtu': '9100', 'alias': 'fortyGigE0/12', 'admin_status': 'up', 'speed': '100000', 'description': 'Interface description'}, "
"'Ethernet16': {'alias': 'fortyGigE0/16', 'pfc_asym': 'off', 'lanes': '41,42,43,44', 'description': 'fortyGigE0/16', 'mtu': '9100'}, " "'Ethernet16': {'lanes': '41,42,43,44', 'pfc_asym': 'off', 'description': 'fortyGigE0/16', 'mtu': '9100', 'alias': 'fortyGigE0/16', 'speed': '1000'}, "
"'Ethernet20': {'alias': 'fortyGigE0/20', 'pfc_asym': 'off', 'lanes': '45,46,47,48', 'description': 'fortyGigE0/20', 'mtu': '9100'}, " "'Ethernet20': {'alias': 'fortyGigE0/20', 'pfc_asym': 'off', 'lanes': '45,46,47,48', 'description': 'fortyGigE0/20', 'mtu': '9100'}, "
"'Ethernet24': {'alias': 'fortyGigE0/24', 'pfc_asym': 'off', 'lanes': '5,6,7,8', 'description': 'fortyGigE0/24', 'mtu': '9100'}, " "'Ethernet24': {'alias': 'fortyGigE0/24', 'pfc_asym': 'off', 'lanes': '5,6,7,8', 'description': 'fortyGigE0/24', 'mtu': '9100'}, "
"'Ethernet28': {'alias': 'fortyGigE0/28', 'pfc_asym': 'off', 'lanes': '1,2,3,4', 'description': 'fortyGigE0/28', 'mtu': '9100'}, " "'Ethernet28': {'alias': 'fortyGigE0/28', 'pfc_asym': 'off', 'lanes': '1,2,3,4', 'description': 'fortyGigE0/28', 'mtu': '9100'}, "