Skip to content

Commit 8f7ef1e

Browse files
authored
[dualtor][minigraph.py] Add soc_ipv4 and cable_type to MUX_CABLE (#10776)
Why I did it To further add cable_type and soc_ipv4 field to table MUX_CABLE, this PR tries to parse the minigraph like the following: ``` <Device i:type="SmartCable"> <ElementType>SmartCable</ElementType> <SubType>active-active</SubType> <Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>192.168.0.3/21</d5p1:IPPrefix> </Address> <AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>::/0</d5p1:IPPrefix> </AddressV6> <ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix> </ManagementAddress> <ManagementAddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>::/0</d5p1:IPPrefix> </ManagementAddressV6> <SerialNumber i:nil="true" /> <Hostname>svcstr-7050-acs-1-Servers0-SC</Hostname> </Device> <Device i:type="Server"> <ElementType>Server</ElementType> <Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>192.168.0.2/21</d5p1:IPPrefix> </Address> <AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>fc02:1000::2/64</d5p1:IPPrefix> </AddressV6> <ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux"> <d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix> </ManagementAddress> <Hostname>Servers0</Hostname> </Device> ``` Signed-off-by: Longxiang Lyu [email protected] How I did it get_mux_cable_entries will try to get the mux cable device from the devices list and get the cable type and soc ip address from the device definition. How to verify it Pass the unit-test
1 parent 2faa69e commit 8f7ef1e

File tree

3 files changed

+90
-11
lines changed

3 files changed

+90
-11
lines changed

src/sonic-config-engine/minigraph.py

+33-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
FRONTEND_ASIC_SUB_ROLE = 'FrontEnd'
4545
BACKEND_ASIC_SUB_ROLE = 'BackEnd'
4646

47+
dualtor_cable_types = ["active-active", "active-standby"]
48+
4749
# Default Virtual Network Index (VNI)
4850
vni_default = 8000
4951

@@ -76,6 +78,7 @@ def get_peer_switch_info(link_metadata, devices):
7678

7779
return peer_switch_table
7880

81+
7982
def parse_device(device):
8083
lo_prefix = None
8184
lo_prefix_v6 = None
@@ -85,6 +88,7 @@ def parse_device(device):
8588
name = None
8689
deployment_id = None
8790
cluster = None
91+
d_subtype = None
8892

8993
for node in device:
9094
if node.tag == str(QName(ns, "Address")):
@@ -103,11 +107,14 @@ def parse_device(device):
103107
d_type = node.text
104108
elif node.tag == str(QName(ns, "ClusterName")):
105109
cluster = node.text
110+
elif node.tag == str(QName(ns, "SubType")):
111+
d_subtype = node.text
106112

107113
if d_type is None and str(QName(ns3, "type")) in device.attrib:
108114
d_type = device.attrib[str(QName(ns3, "type"))]
109115

110-
return (lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster)
116+
return (lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster, d_subtype)
117+
111118

112119
def calculate_lcm_for_ecmp (nhdevices_bank_map, nhip_bank_map):
113120
banks_enumerated = {}
@@ -243,14 +250,16 @@ def parse_png(png, hname, dpg_ecmp_content = None):
243250

244251
if child.tag == str(QName(ns, "Devices")):
245252
for device in child.findall(str(QName(ns, "Device"))):
246-
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster) = parse_device(device)
247-
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
253+
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster, d_subtype) = parse_device(device)
254+
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku}
248255
if cluster:
249256
device_data['cluster'] = cluster
250257
if deployment_id:
251258
device_data['deployment_id'] = deployment_id
252259
if lo_prefix_v6:
253260
device_data['lo_addr_v6'] = lo_prefix_v6
261+
if d_subtype:
262+
device_data['subtype'] = d_subtype
254263
devices[name] = device_data
255264

256265
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
@@ -275,10 +284,11 @@ def parse_png(png, hname, dpg_ecmp_content = None):
275284
for link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
276285
if link.find(str(QName(ns, "ElementType"))).text == "LogicalLink":
277286
intf_name = link.find(str(QName(ns, "EndPort"))).text
287+
start_device = link.find(str(QName(ns, "StartDevice"))).text
278288
if intf_name in port_alias_map:
279289
intf_name = port_alias_map[intf_name]
280290

281-
mux_cable_ports[intf_name] = "true"
291+
mux_cable_ports[intf_name] = start_device
282292

283293
if dpg_ecmp_content and (len(dpg_ecmp_content)):
284294
for version, content in dpg_ecmp_content.items(): # version is ipv4 or ipv6
@@ -373,7 +383,7 @@ def parse_asic_png(png, asic_name, hostname):
373383

374384
if child.tag == str(QName(ns, "Devices")):
375385
for device in child.findall(str(QName(ns, "Device"))):
376-
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster) = parse_device(device)
386+
(lo_prefix, lo_prefix_v6, mgmt_prefix, name, hwsku, d_type, deployment_id, cluster, _) = parse_device(device)
377387
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
378388
if cluster:
379389
device_data['cluster'] = cluster
@@ -1475,7 +1485,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
14751485
# If connected to a smart cable, get the connection position
14761486
for port_name, port in ports.items():
14771487
if port_name in mux_cable_ports:
1478-
port['mux_cable'] = mux_cable_ports[port_name]
1488+
port['mux_cable'] = "true"
14791489

14801490
# set port description if parsed from deviceinfo
14811491
for port_name in port_descriptions:
@@ -1720,7 +1730,7 @@ def get_tunnel_entries(tunnel_intfs, lo_intfs, hostname):
17201730
def get_mux_cable_entries(mux_cable_ports, neighbors, devices):
17211731
mux_cable_table = {}
17221732

1723-
for intf in mux_cable_ports:
1733+
for intf, cable_name in mux_cable_ports.items():
17241734
if intf in neighbors:
17251735
entry = {}
17261736
neighbor = neighbors[intf]['name']
@@ -1740,11 +1750,26 @@ def get_mux_cable_entries(mux_cable_ports, neighbors, devices):
17401750
else:
17411751
print("Warning: no server IPv4 loopback found for {}, skipping mux cable table entry".format(neighbor))
17421752

1753+
if cable_name in devices:
1754+
cable_type = devices[cable_name].get('subtype')
1755+
if cable_type is None:
1756+
continue
1757+
if cable_type in dualtor_cable_types:
1758+
mux_cable_table[intf]['cable_type'] = cable_type
1759+
if cable_type == 'active-active':
1760+
soc_ipv4 = devices[cable_name]['lo_addr'].split('/')[0]
1761+
soc_ipv4_prefix = ipaddress.ip_network(UNICODE_TYPE(soc_ipv4))
1762+
mux_cable_table[intf]['soc_ipv4'] = str(soc_ipv4_prefix)
1763+
else:
1764+
print("Warning: skip parsing device %s for mux cable entry, cable type %s not supported" % (cable_name, cable_type))
1765+
else:
1766+
print("Warning: skip parsing device %s for mux cable entry, device definition not found" % cable_name)
1767+
17431768
return mux_cable_table
17441769

17451770
def parse_device_desc_xml(filename):
17461771
root = ET.parse(filename).getroot()
1747-
(lo_prefix, lo_prefix_v6, mgmt_prefix, hostname, hwsku, d_type, _, _) = parse_device(root)
1772+
(lo_prefix, lo_prefix_v6, mgmt_prefix, hostname, hwsku, d_type, _, _, _) = parse_device(root)
17481773

17491774
results = {}
17501775
results['DEVICE_METADATA'] = {'localhost': {

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

+39-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
<EndDevice>switch-t0</EndDevice>
259259
<EndPort>fortyGigE0/4</EndPort>
260260
<FlowControl>true</FlowControl>
261-
<StartDevice>mux-cable</StartDevice>
261+
<StartDevice>server1-SC</StartDevice>
262262
<StartPort>L</StartPort>
263263
<Validate>true</Validate>
264264
</DeviceLinkBase>
@@ -269,7 +269,7 @@
269269
<EndDevice>switch-t0</EndDevice>
270270
<EndPort>fortyGigE0/8</EndPort>
271271
<FlowControl>true</FlowControl>
272-
<StartDevice>mux-cable</StartDevice>
272+
<StartDevice>server2-SC</StartDevice>
273273
<StartPort>U</StartPort>
274274
<Validate>true</Validate>
275275
</DeviceLinkBase>
@@ -317,6 +317,24 @@
317317
</ManagementAddress>
318318
<HwSku>Force10-S6000</HwSku>
319319
</Device>
320+
<Device i:type="SmartCable">
321+
<ElementType>SmartCable</ElementType>
322+
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
323+
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
324+
</Address>
325+
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
326+
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
327+
</AddressV6>
328+
<ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
329+
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
330+
</ManagementAddress>
331+
<ManagementAddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
332+
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
333+
</ManagementAddressV6>
334+
<SerialNumber i:nil="true" />
335+
<Hostname>server1-SC</Hostname>
336+
<HwSku>smartcable-sku</HwSku>
337+
</Device>
320338
<Device i:type="Server">
321339
<ElementType>Server</ElementType>
322340
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
@@ -331,6 +349,25 @@
331349
<Hostname>server1</Hostname>
332350
<HwSku>server-sku</HwSku>
333351
</Device>
352+
<Device i:type="SmartCable">
353+
<ElementType>SmartCable</ElementType>
354+
<SubType>active-active</SubType>
355+
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
356+
<d5p1:IPPrefix>10.10.10.3/32</d5p1:IPPrefix>
357+
</Address>
358+
<AddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
359+
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
360+
</AddressV6>
361+
<ManagementAddress xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
362+
<d5p1:IPPrefix>0.0.0.0/0</d5p1:IPPrefix>
363+
</ManagementAddress>
364+
<ManagementAddressV6 xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">
365+
<d5p1:IPPrefix>::/0</d5p1:IPPrefix>
366+
</ManagementAddressV6>
367+
<SerialNumber i:nil="true" />
368+
<Hostname>server2-SC</Hostname>
369+
<HwSku>smartcable-sku</HwSku>
370+
</Device>
334371
<Device i:type="Server">
335372
<ElementType>Server</ElementType>
336373
<Address xmlns:d5p1="Microsoft.Search.Autopilot.NetMux">

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ def test_minigraph_neighbor_metadata(self):
226226
'lo_addr_v6': 'fe80::0002/128',
227227
'mgmt_addr': '10.0.0.2/32',
228228
'type': 'Server'
229+
},
230+
'server1-SC': {
231+
'hwsku': 'smartcable-sku',
232+
'lo_addr': '0.0.0.0/0',
233+
'lo_addr_v6': '::/0',
234+
'mgmt_addr': '0.0.0.0/0',
235+
'type': 'SmartCable'
236+
},
237+
'server2-SC': {
238+
'hwsku': 'smartcable-sku',
239+
'lo_addr': '10.10.10.3/32',
240+
'lo_addr_v6': '::/0',
241+
'mgmt_addr': '0.0.0.0/0',
242+
'type': 'SmartCable',
243+
'subtype': 'active-active'
229244
}
230245
}
231246
output = self.run_script(argument)
@@ -365,7 +380,9 @@ def test_minigraph_mux_cable_table(self):
365380
'Ethernet8': {
366381
'state': 'auto',
367382
'server_ipv4': '10.10.10.2/32',
368-
'server_ipv6': 'fe80::2/128'
383+
'server_ipv6': 'fe80::2/128',
384+
'soc_ipv4': '10.10.10.3/32',
385+
'cable_type': 'active-active'
369386
}
370387
}
371388

0 commit comments

Comments
 (0)