Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minigraph ECMP parsing support (cleaner format) #4985

Merged
merged 2 commits into from
Dec 30, 2020

Conversation

kktheballer
Copy link
Contributor

- Why I did it
To support FG_ECMP for certain azd scenarios
- How I did it
Modified minigraph parser to parse ECMP fields in the case they are present in minigraph
- How to verify it
Loaded ensuing config_db file on a DUT to verify the fields are parsed and configure device correctly
- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@lguohan
Copy link
Collaborator

lguohan commented Jul 21, 2020

need to add sonic-cfggen tests, please

@kktheballer
Copy link
Contributor Author

retest mellanox please.

@kktheballer
Copy link
Contributor Author

retest mellanox please

1 similar comment
@kktheballer
Copy link
Contributor Author

retest mellanox please

@kktheballer
Copy link
Contributor Author

retest mellanox please

@kktheballer kktheballer force-pushed the ecmp_parsing branch 2 times, most recently from 318355b to cb2c833 Compare August 11, 2020 21:04
@kktheballer
Copy link
Contributor Author

retest mellanox please

1 similar comment
@kktheballer
Copy link
Contributor Author

retest mellanox please

@prsunny prsunny requested review from anish-n and abdosi August 18, 2020 17:34
LCM = sum(lcm_array)
FG_NHG_MEMBER[0] = {ip: {"FG_NHG": ipv4_tag, "Bank": bank} for ip, bank in nhipv4_bank_map.items()}
FG_NHG_PREFIX[0] = {nhgaddr[0]: {"FG_NHG": ipv4_tag}}
FG_NHG[0] = {ipv4_tag: {"hash_bucket_size": LCM}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "hash_bucket_size" to "bucket_size" per schema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

lcm_comp = lcm_comp * i / gcd(lcm_comp, i)
lcm_array.append(lcm_comp)
LCM = sum(lcm_array)
FG_NHG_MEMBER[0] = {ip: {"FG_NHG": ipv4_tag, "Bank": bank} for ip, bank in nhipv4_bank_map.items()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change "Bank" to "bank"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@kktheballer
Copy link
Contributor Author

retests vsimage please

@kktheballer
Copy link
Contributor Author

retest vsimage please

endport = link.find(str(QName(ns, "EndPort"))).text
startdevice = link.find(str(QName(ns, "StartDevice"))).text
port_device_map[endport] = startdevice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest moving this logic to line 211, and utilizing the endport and startdevice values already generated on line 194 and 195.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I had written like this to work around the already in-place lines of code in 190-191

dpg_ecmp_content = []
ipnhs = child.find(str(QName(ns, "IPNextHops")))
if ipnhs is not None:
for ipnh in ipnhs.findall(str(QName(ns, "IPNextHop"))):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets add a check for IPNextHop type FineGrainedECMPGroupMember

a = ipaddress.IPAddress(unicode(subnet_check_ip))
n = ipaddress.IPNetwork(unicode(subnet_range))
if (n.Contains(a)):
nhgvlan = ip_intfs_map[subnet_range]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we rename the variable name, not necessary that it is a vlan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can use nhg_int if that is better

nhgvlan = ip_intfs_map[subnet_range]
dwnstrms = child.find(str(QName(ns, "DownstreamSummarySet")))
for dwnstrm in dwnstrms.findall(str(QName(ns, "DownstreamSummary"))):
dwnstrmentry = str(ET.tostring(dwnstrm))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use the QName based search/parse in the below section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that one specific section, very oddly, there were errors trying to do so. I will look into it again

port_nhipv4_map = dpg_ecmp_content[0]
port_nhipv6_map = dpg_ecmp_content[1]
nhgaddr = dpg_ecmp_content[2]
nhgvlan = dpg_ecmp_content[3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change variable name since its not necessary that it is a vlan

nhdevices_bank_map = {device: bank for bank, device in enumerate(nhdevices)}
nhipv4_bank_map = {ip: nhdevices_bank_map[device] for ip, device in nhipv4_device_map.items()}
nhipv6_bank_map = {ip: nhdevices_bank_map[device] for ip, device in nhipv6_device_map.items()}
for value in nhdevices_bank_map.values():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPv4 and IPv6 could have a different enumeration of banks and as a result a different lcm. I would also suggest moving this calculation of lcm to a helper function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do this

@kktheballer
Copy link
Contributor Author

retest vsimage please

@lgtm-com
Copy link

lgtm-com bot commented Nov 17, 2020

This pull request introduces 1 alert and fixes 10 when merging bfb5236488f4f5049f3c61650dc9a2c9b4874e10 into b595a6e - view on LGTM.com

new alerts:

  • 1 for Syntax error

fixed alerts:

  • 5 for Unused import
  • 3 for Unused local variable
  • 1 for Testing equality to None
  • 1 for Except block handles 'BaseException'

@kktheballer
Copy link
Contributor Author

retest mellanox please

dwnstrmentry = str(ET.tostring(dwnstrm))
if ("FineGrainedECMPGroupDestination" in dwnstrmentry):
subnet_ip = dwnstrm.find(str(QName(ns1, "Subnet"))).text
truncsubnet_ip = subnet_ip.split("/")[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to truncate it here for the IPv4/IPv6 check?

port_nhipv4_map = dpg_ecmp_content[0]
port_nhipv6_map = dpg_ecmp_content[1]
nhgaddr = dpg_ecmp_content[2]
nhg_int = dpg_ecmp_content[3]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: readability consideration, I would recommend making dpg_ecmp_content a dictionary instead of an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed for dpg_ecmp_content as well as png_ecmp_content

@kktheballer
Copy link
Contributor Author

retest mellanox please

@kktheballer
Copy link
Contributor Author

retest mellanox please

a = ipaddress.ip_address(UNICODE_TYPE(subnet_check_ip))
n = list(ipaddress.ip_network(UNICODE_TYPE(subnet_range), False).hosts())
if a in n:
nhg_int = ip_intfs_map[subnet_range]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assumes a single interface for all IPs, though it may be addressed in a future PR: it is better to not to assume single interface associated with all IPs.

anish-n
anish-n previously approved these changes Dec 11, 2020
Copy link
Contributor

@abdosi abdosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the comments and update it accordingly.

abdosi
abdosi previously approved these changes Dec 23, 2020
Copy link
Contributor

@abdosi abdosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kktheballer
Copy link
Contributor Author

retest vsimage please

@kktheballer
Copy link
Contributor Author

retest vsimage please

Copy link
Contributor

@abdosi abdosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

output = self.run_script(argument)
self.assertEqual(output.strip(), "['200.200.200.1', '200.200.200.10', '200.200.200.2', '200.200.200.3', '200.200.200.4', '200.200.200.5',"
" '200.200.200.6', '200.200.200.7', '200.200.200.8', '200.200.200.9', '200:200:200:200::1', '200:200:200:200::10',"
" '200:200:200:200::2', '200:200:200:200::3', '200:200:200:200::4', '200:200:200:200::5', '200:200:200:200::6',"
Copy link
Contributor

@anish-n anish-n Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR can we address adding checks for the values being populated in these entries(FG_NHG, link, and bank), having only the keys tested prevents 100% test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do so

Copy link
Contributor

@anish-n anish-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, I provided a comment on test improvement, I would recommend that for a follow up PR.

@abdosi abdosi merged commit ba92a08 into sonic-net:master Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants