Skip to content

Commit

Permalink
Enhanced minigraph parser for packet-chasiss production graph (#21255)
Browse files Browse the repository at this point in the history
Fixed 2 issue while parsing production minigraph:

bfd flag not being set for STATIC_ROUTE table
Different mac-address not getting generated for each ASIC

How I fixed:
In production switch_type is derived using ForwardingMethod attribute. Modified code to use chassis_type which is derived using ForwardingMethod

Signed-off-by: Abhishek Dosi <[email protected]>
  • Loading branch information
abdosi authored Jan 2, 2025
1 parent 3c8fad3 commit 0ed3434
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2623,7 +2623,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw

if static_routes:
# Enable static Route BFD by default for static route in chassis-packet
if switch_type == "chassis-packet":
if switch_type == "chassis-packet" or chassis_type == "chassis-packet":
for pfx, data in static_routes.items():
data.update({"bfd":"true"})
results['STATIC_ROUTE'] = static_routes
Expand Down Expand Up @@ -2903,9 +2903,12 @@ def parse_asic_sub_role(filename, asic_name):
sub_role, _, _, _, _, _= parse_asic_meta(child, asic_name)
return sub_role

def parse_asic_switch_type(filename, asic_name):
def parse_asic_switch_type(filename, asic_name, hostname):
if os.path.isfile(filename):
root = ET.parse(filename).getroot()
switch_type, _ = get_chassis_type_and_hostname(root, hostname)
if switch_type:
return switch_type
for child in root:
if child.tag == str(QName(ns, "MetadataDeclaration")):
_, _, switch_type, _, _, _ = parse_asic_meta(child, asic_name)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def main():
if asic_name is not None:
if args.minigraph is not None:
asic_role = parse_asic_sub_role(args.minigraph, asic_name)
switch_type = parse_asic_switch_type(args.minigraph, asic_name)
switch_type = parse_asic_switch_type(args.minigraph, asic_name, hostname)
if ((switch_type is not None and switch_type.lower() == "chassis-packet") or
(asic_role is not None and asic_role.lower() == "backend") or
(platform == device_info.VS_PLATFORM)) :
Expand Down

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def setUp(self):
self.sample_resource_graph = os.path.join(self.test_dir, 'sample-graph-resource-type.xml')
self.sample_subintf_graph = os.path.join(self.test_dir, 'sample-graph-subintf.xml')
self.voq_port_config = os.path.join(self.test_dir, 'voq-sample-port-config.ini')
self.packet_chassis_graph0 = os.path.join(self.test_dir, 'minigraph-str2-temp-2-lc04.xml')
self.packet_chassis_graph = os.path.join(self.test_dir, 'sample-chassis-packet-lc-graph.xml')
self.packet_chassis_port_ini = os.path.join(self.test_dir, 'sample-chassis-packet-lc-port-config.ini')
self.macsec_profile = os.path.join(self.test_dir, 'macsec_profile.json')
Expand Down Expand Up @@ -1056,6 +1057,11 @@ def test_minigraph_bgp_packet_chassis_peer(self):
)

def test_minigraph_bgp_packet_chassis_static_route(self):
argument = ['-m', self.packet_chassis_graph0, '-p', self.packet_chassis_port_ini, '-n', "asic1", '-v', "STATIC_ROUTE"]
output = self.run_script(argument)
self.assertEqual(
utils.to_dict(output.strip()),
utils.to_dict("{'192.0.0.1/32': {'nexthop': '10.235.96.11,10.235.96.136,10.235.97.11,10.235.97.136,10.235.98.11,10.235.98.136,10.235.99.11,10.235.99.136,10.235.100.11,10.235.100.136', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::1/128': {'nexthop': 'fc00:34::a:eb60:b01,fc00:34::a:eb60:8801,fc00:34::a:eb61:b01,fc00:34::a:eb61:8801,fc00:34::a:eb62:b01,fc00:34::a:eb62:8801,fc00:34::a:eb63:b01,fc00:34::a:eb63:8801,fc00:34::a:eb64:b01,fc00:34::a:eb64:8801', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.2/32': {'nexthop': '10.235.96.12,10.235.96.137,10.235.97.12,10.235.97.137,10.235.98.12,10.235.98.137,10.235.99.12,10.235.99.137,10.235.100.12,10.235.100.137', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::2/128': {'nexthop': 'fc00:34::a:eb60:c01,fc00:34::a:eb60:8901,fc00:34::a:eb61:c01,fc00:34::a:eb61:8901,fc00:34::a:eb62:c01,fc00:34::a:eb62:8901,fc00:34::a:eb63:c01,fc00:34::a:eb63:8901,fc00:34::a:eb64:c01,fc00:34::a:eb64:8901', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.3/32': {'nexthop': '10.235.96.13,10.235.96.134,10.235.97.13,10.235.97.134,10.235.98.13,10.235.98.134,10.235.99.13,10.235.99.134,10.235.100.13,10.235.100.134', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::3/128': {'nexthop': 'fc00:34::a:eb60:d01,fc00:34::a:eb60:8601,fc00:34::a:eb61:d01,fc00:34::a:eb61:8601,fc00:34::a:eb62:d01,fc00:34::a:eb62:8601,fc00:34::a:eb63:d01,fc00:34::a:eb63:8601,fc00:34::a:eb64:d01,fc00:34::a:eb64:8601', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.4/32': {'nexthop': '10.235.96.9,10.235.96.140,10.235.97.9,10.235.97.140,10.235.98.9,10.235.98.140,10.235.99.9,10.235.99.140,10.235.100.9,10.235.100.140', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::4/128': {'nexthop': 'fc00:34::a:eb60:901,fc00:34::a:eb60:8c01,fc00:34::a:eb61:901,fc00:34::a:eb61:8c01,fc00:34::a:eb62:901,fc00:34::a:eb62:8c01,fc00:34::a:eb63:901,fc00:34::a:eb63:8c01,fc00:34::a:eb64:901,fc00:34::a:eb64:8c01', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.5/32': {'nexthop': '10.235.96.10,10.235.96.141,10.235.97.10,10.235.97.141,10.235.98.10,10.235.98.141,10.235.99.10,10.235.99.141,10.235.100.10,10.235.100.141', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::5/128': {'nexthop': 'fc00:34::a:eb60:a01,fc00:34::a:eb60:8d01,fc00:34::a:eb61:a01,fc00:34::a:eb61:8d01,fc00:34::a:eb62:a01,fc00:34::a:eb62:8d01,fc00:34::a:eb63:a01,fc00:34::a:eb63:8d01,fc00:34::a:eb64:a01,fc00:34::a:eb64:8d01', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.6/32': {'nexthop': '10.235.96.7,10.235.96.138,10.235.97.7,10.235.97.138,10.235.98.7,10.235.98.138,10.235.99.7,10.235.99.138,10.235.100.7,10.235.100.138', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::6/128': {'nexthop': 'fc00:34::a:eb60:701,fc00:34::a:eb60:8a01,fc00:34::a:eb61:701,fc00:34::a:eb61:8a01,fc00:34::a:eb62:701,fc00:34::a:eb62:8a01,fc00:34::a:eb63:701,fc00:34::a:eb63:8a01,fc00:34::a:eb64:701,fc00:34::a:eb64:8a01', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.7/32': {'nexthop': '10.235.96.6,10.235.96.139,10.235.97.6,10.235.97.139,10.235.98.6,10.235.98.139,10.235.99.6,10.235.99.139,10.235.100.6,10.235.100.139', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::7/128': {'nexthop': 'fc00:34::a:eb60:601,fc00:34::a:eb60:8b01,fc00:34::a:eb61:601,fc00:34::a:eb61:8b01,fc00:34::a:eb62:601,fc00:34::a:eb62:8b01,fc00:34::a:eb63:601,fc00:34::a:eb63:8b01,fc00:34::a:eb64:601,fc00:34::a:eb64:8b01', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.8/32': {'nexthop': '10.235.96.4,10.235.96.132,10.235.97.4,10.235.97.132,10.235.98.4,10.235.98.132,10.235.99.4,10.235.99.132,10.235.100.4,10.235.100.132', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::8/128': {'nexthop': 'fc00:34::a:eb60:401,fc00:34::a:eb60:8401,fc00:34::a:eb61:401,fc00:34::a:eb61:8401,fc00:34::a:eb62:401,fc00:34::a:eb62:8401,fc00:34::a:eb63:401,fc00:34::a:eb63:8401,fc00:34::a:eb64:401,fc00:34::a:eb64:8401', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.9/32': {'nexthop': '10.235.96.5,10.235.96.133,10.235.97.5,10.235.97.133,10.235.98.5,10.235.98.133,10.235.99.5,10.235.99.133,10.235.100.5,10.235.100.133', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::9/128': {'nexthop': 'fc00:34::a:eb60:501,fc00:34::a:eb60:8501,fc00:34::a:eb61:501,fc00:34::a:eb61:8501,fc00:34::a:eb62:501,fc00:34::a:eb62:8501,fc00:34::a:eb63:501,fc00:34::a:eb63:8501,fc00:34::a:eb64:501,fc00:34::a:eb64:8501', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.10/32': {'nexthop': '10.235.96.8,10.235.96.135,10.235.97.8,10.235.97.135,10.235.98.8,10.235.98.135,10.235.99.8,10.235.99.135,10.235.100.8,10.235.100.135', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::a/128': {'nexthop': 'fc00:34::a:eb60:801,fc00:34::a:eb60:8701,fc00:34::a:eb61:801,fc00:34::a:eb61:8701,fc00:34::a:eb62:801,fc00:34::a:eb62:8701,fc00:34::a:eb63:801,fc00:34::a:eb63:8701,fc00:34::a:eb64:801,fc00:34::a:eb64:8701', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.12/32': {'nexthop': '10.235.96.2,10.235.96.130,10.235.97.2,10.235.97.130,10.235.98.2,10.235.98.130,10.235.99.2,10.235.99.130,10.235.100.2,10.235.100.130', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::c/128': {'nexthop': 'fc00:34::a:eb60:201,fc00:34::a:eb60:8201,fc00:34::a:eb61:201,fc00:34::a:eb61:8201,fc00:34::a:eb62:201,fc00:34::a:eb62:8201,fc00:34::a:eb63:201,fc00:34::a:eb63:8201,fc00:34::a:eb64:201,fc00:34::a:eb64:8201', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '192.0.0.13/32': {'nexthop': '10.235.96.3,10.235.96.131,10.235.97.3,10.235.97.131,10.235.98.3,10.235.98.131,10.235.99.3,10.235.99.131,10.235.100.3,10.235.100.131', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}, '2603:10e2:400::d/128': {'nexthop': 'fc00:34::a:eb60:301,fc00:34::a:eb60:8301,fc00:34::a:eb61:301,fc00:34::a:eb61:8301,fc00:34::a:eb62:301,fc00:34::a:eb62:8301,fc00:34::a:eb63:301,fc00:34::a:eb63:8301,fc00:34::a:eb64:301,fc00:34::a:eb64:8301', 'ifname': 'PortChannel4001,PortChannel4014,PortChannel4027,PortChannel4040,PortChannel4053,PortChannel4066,PortChannel4079,PortChannel4092,PortChannel4105,PortChannel4118', 'advertise': 'false', 'bfd': 'true'}}"))
argument = ['-m', self.packet_chassis_graph, '-p', self.packet_chassis_port_ini, '-n', "asic1", '-v', "STATIC_ROUTE"]
output = self.run_script(argument)
self.assertEqual(
Expand Down

0 comments on commit 0ed3434

Please sign in to comment.