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

Updated lldpRemManAddrTable to use all the management ip address associated with interface. #201

Merged
merged 13 commits into from
Mar 15, 2021

Conversation

abdosi
Copy link
Contributor

@abdosi abdosi commented Mar 12, 2021

Why I did:

How I did:

  • Loop through all valid and unique management ip address associated
    with remote lldp interface and append to the the oid key list.

  • Removed some of utility API as they were not being used.

How I verify:

  • Extend Unit test case to cover all possible combination of management ip address
  • Verify the snmpwalk when both v4 and v6 address are present
admin@str-sxxxx-on-2:~$ redis-cli -n 0
127.0.0.1:6379> hgetall "LLDP_ENTRY_TABLE:eth0"
 1) "lldp_rem_sys_name"
 2) "str-22ex-235ab08"
 3) "lldp_rem_index"
 4) "1"
 5) "lldp_rem_sys_desc"
 6) "Juniper Networks, Inc. ex2200-48t-4g , version 12.3R4.6 Build date: 2013-09-13 02:53:16 UTC "
 7) "lldp_rem_man_addr"
 8) "10.224.25.100,2603:10e2:290:5016::"
 9) "lldp_rem_time_mark"
10) "84379"
11) "lldp_rem_port_id"
12) "ge-0/0/12"
13) "lldp_rem_sys_cap_supported"
14) "28 00"
15) "lldp_rem_sys_cap_enabled"
16) "28 00"
17) "lldp_rem_chassis_id_subtype"
18) "4"
19) "lldp_rem_port_id_subtype"
20) "5"
21) "lldp_rem_port_desc"
22) "ge-0/0/12.0"
23) "lldp_rem_chassis_id"
24) "f4:b5:2f:56:2d:80"


root@str-sxxxx-on-2:/# snmpwalk -v2c -c msft 127.0.0.1 1.0.8802.1.1.2.1.4.2
iso.0.8802.1.1.2.1.4.2.1.5.84379.10000.1.1.4.10.224.25.100 = OID: iso.3.6.1.2.1.2.2.1.1
iso.0.8802.1.1.2.1.4.2.1.5.84379.10000.1.2.6.9731.4322.656.20502.0.0 = OID: iso.3.6.1.2.1.2.2.1.1

sonic-net/sonic-buildimage#7036
sonic-net/sonic-buildimage#6636

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Mar 12, 2021

This pull request introduces 1 alert when merging 4dbc4dc into 9b83459 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi left a comment

Choose a reason for hiding this comment

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

Can you add multi-asic test case changes in tests/namespace/test_lldp.py also add namespace mock data in tests/mock_tables/asic0... etc as required.

@SuvarnaMeenakshi Done

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi left a comment

Choose a reason for hiding this comment

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

LGTM.

for entry in range(3, 6):
mib_entry = self.lut[(1, 0, 8802, 1, 1, 2, 1, 4, 2, 1, entry)]
ret = mib_entry(sub_id=(1, 5))
self.assertIsNotNone(ret)
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi Mar 12, 2021

Choose a reason for hiding this comment

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

How is the return value checked if both ipv4 and ipv6 exits?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

intention of testcase is to check when both ip address are present we can get the data from first key (can be either v4 or v6) for given interface. Basically to check we are not ignoring management ip information in such case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SuvarnaMeenakshi Updated test case for this. Fixed lookup() API.

self.mgmt_ips.update({if_name: {"ip_str": mgmt_ip_str,
"addr_subtype": subtype,
"addr_hex": ip_hex}})
for mgmt_ip in set(mgmt_ip_str.split(',')):
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 13, 2021

Choose a reason for hiding this comment

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

set [](start = 27, length = 3)

What is the benefit of set ? Just use splited list? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is just extra check in case if we have same ip's

Copy link
Contributor

Choose a reason for hiding this comment

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

Please be aware that different ipv6 strings could be the same ipv6 address.


In reply to: 593529516 [](ancestors = 593529516)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qiluo-msft Updated.

mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip.split('.')])
elif subtype == ManAddrConst.man_addr_subtype_ipv6:
addr_subtype_sub_oid = 6
mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i, 16) if i else 0 for i in mgmt_ip.split(':')])
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 13, 2021

Choose a reason for hiding this comment

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

[int(i, 16) if i else 0 for i in mgmt_ip.split(':')] [](start = 62, length = 52)

Seems you are trying to parse ipv6

[int(i, 16) if i else 0 for i in mgmt_ip.split(':')]

but this is not working for general cases #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qiluo-msft Updated to use exploded API of ipaddress module.
https://docs.python.org/3/library/ipaddress.html

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comments

@qiluo-msft Made required changes.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
for mgmt_ip in mgmt_ip_str.split(','):
time_mark = int(lldp_kvs['lldp_rem_time_mark'])
remote_index = int(lldp_kvs['lldp_rem_index'])
subtype, exploded_mgmt_ip = self.get_subtype_and_exploded_ip(mgmt_ip)
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 13, 2021

Choose a reason for hiding this comment

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

get_subtype_and_exploded_ip [](start = 49, length = 27)

The code is okay, I am think about more readable and concise.
I found some sample code: https://github.com/Azure/sonic-snmpagent/blob/9b83459d647622a12387085f01d2256fd69430e2/src/sonic_ax_impl/mibs/vendor/cisco/bgp4.py#L41-L46

Suggest you extract a common method and reuse. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @qiluo-msft . Updated to use updated utility API.

tests/test_lldp.py Outdated Show resolved Hide resolved
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 2)

# Verfiy only valid ipv6 address exiit. Ethernet12 has this config.
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 14, 2021

Choose a reason for hiding this comment

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

exiit [](start = 41, length = 5)

typo #Closed

self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 2)

# Verfiy only valid ipv4 address exit. Ethernet8 has this config.
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 14, 2021

Choose a reason for hiding this comment

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

exit [](start = 41, length = 4)

typo #Closed

self.assertEqual(value0.type_, ValueType.OBJECT_IDENTIFIER)
self.assertEqual(str(value0.data), str(ObjectIdentifier(5, 2, 0, 0, (1, 2, 2, 1, 1))))

# Verfiy both valid ipv4 and invalid ipv6 address exit. Ethernet5 has this config.
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 14, 2021

Choose a reason for hiding this comment

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

exit [](start = 58, length = 4)

typo #Closed

self.assertEqual(value0.type_, ValueType.INTEGER)
self.assertEqual(value0.data, 2)

# Verfiy no mgmt address exit. Ethernet16 has this config.
Copy link
Contributor

@qiluo-msft qiluo-msft Mar 14, 2021

Choose a reason for hiding this comment

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

exit [](start = 33, length = 4)

typo #Closed

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

Minor typos in code comments

Sorry fixed now.

Signed-off-by: Abhishek Dosi <abdosi@microsoft.com>
continue
mgmt_ip_tuple = ip2byte_tuple(mgmt_ip)
if mgmt_ip_tuple in mgmt_ip_set:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

if mgmt_ip_set is present in mgmt_ip_tuple, should the data be still updated instead of continuing?
So that the time_mark gets updated?

Copy link
Contributor Author

@abdosi abdosi Mar 15, 2021

Choose a reason for hiding this comment

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

we keep key tuple (eg: time_mark) only for unique ip's. lldp_rem_time_mark is associated with all unique ip's in lldp_rem_man_addr. All the data is constant for this SNMP table entry

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

lgtm

@abdosi abdosi merged commit 292024a into sonic-net:master Mar 15, 2021
@abdosi abdosi deleted the snmp_lldp_fix branch March 15, 2021 19:15
abdosi added a commit that referenced this pull request Mar 15, 2021
…ciated with interface. (#201)

Fixes:-
sonic-net/sonic-buildimage#7036
sonic-net/sonic-buildimage#6636

Updated to use prefix of 16 byte instead of 6 byte for Ipv6 Management Address. Confirmed with other Vendor Nos

Fixed lookup() so that get-next work correctly from test-cases.

Updated all files to use new utility API ip2byte_tuple()
praveen-li pushed a commit to praveen-li/sonic-snmpagent that referenced this pull request Jun 2, 2021
…ciated with interface. (sonic-net#201)

Fixes:-
sonic-net/sonic-buildimage#7036
sonic-net/sonic-buildimage#6636

Updated to use prefix of 16 byte instead of 6 byte for Ipv6 Management Address. Confirmed with other Vendor Nos

Fixed lookup() so that get-next work correctly from test-cases.

Updated all files to use new utility API ip2byte_tuple()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants