Skip to content

Commit

Permalink
Support interface speed for PortChannels (#262)
Browse files Browse the repository at this point in the history
**- What I did**
This change makes SNMP report the correct interface speed for PortChannels instead of defaulting to 40G.

**- How I did it**
Similar to `intfutil`, the code simply sums up the interface speeds of all member ports. The logic for iterating over members is based on `_get_counter`.

**- How to verify it**
- Check `snmpwalk -v 2c -c public <IP> ifHighSpeed`, note that PortChannels are reported as 40G
- Apply the change
- Check again, note that the same speed as in `show interface status` is reported now.

**- Description for the changelog**
Support reporting interface speeds for PortChannels through SNMP
  • Loading branch information
lukasstockner authored and StormLiangMS committed Oct 17, 2023
1 parent 4622b8d commit d714a6c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ def interface_alias(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: The SONiC interface description, empty string if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down Expand Up @@ -259,15 +263,11 @@ def _get_counter(self, oid, table_name, mask):
mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e))
return None

def _get_if_entry(self, sub_id):
def _get_if_entry(self, oid):
"""
:param oid: The 1-based sub-identifier query.
:return: the DB entry for the respective sub_id.
"""
oid = self.get_oid(sub_id)
if not oid:
return

if_table = ""
# Once PORT_TABLE will be moved to CONFIG DB
# we will get entry from CONFIG_DB for all cases
Expand All @@ -291,7 +291,19 @@ def get_high_speed(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: speed value for the respective sub_id or 40000 if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

if oid in self.oid_lag_name_map:
speed = 0
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
entry = self._get_if_entry(mibs.get_index_from_str(lag_member))
if entry:
speed += int(entry.get("speed", 0))
return speed

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down
3 changes: 3 additions & 0 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@
"nexthop": "",
"ifname": "lo"
},
"LAG_MEMBER_TABLE:PortChannel01:Ethernet108": {
"status": "enabled"
},
"LAG_MEMBER_TABLE:PortChannel01:Ethernet112": {
"status": "enabled"
},
Expand Down
19 changes: 19 additions & 0 deletions tests/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ def test_no_speed(self):
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 121))))
self.assertEqual(value0.data, 40000)

def test_portchannel_speed(self):
"""
For a portchannel, the speed should be the sum of all members' speeds
"""
oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 1000))
get_pdu = GetNextPDU(
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
oids=[oid]
)

encoded = get_pdu.encode()
response = get_pdu.make_response(self.lut)
print(response)

value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.GAUGE_32)
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 1001))))
self.assertEqual(value0.data, 200000)

def test_no_description(self):
"""
For a port with no speed in the db the result should be 40000
Expand Down

0 comments on commit d714a6c

Please sign in to comment.