Skip to content

Commit aa0d150

Browse files
Added detailed explanations in _get_counter and get_counter
Signed-off-by: Raphael Tryster <[email protected]>
1 parent 15cd0f2 commit aa0d150

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/sonic_ax_impl/mibs/ietf/rfc1213.py

+28
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ def _get_counter(self, oid, table_name):
331331
:return: the counter for the respective sub_id/table.
332332
"""
333333
# Enum.name or table_name = 'name_of_the_table'
334+
# Example:
335+
# table_name = <DbTables.SAI_PORT_STAT_IF_OUT_ERRORS: 20>
336+
# _table_name = 'SAI_PORT_STAT_IF_OUT_ERRORS'
334337
_table_name = getattr(table_name, 'name', table_name)
335338

336339
try:
@@ -385,12 +388,37 @@ def get_counter(self, sub_id, table_name):
385388
return 0
386389
elif oid in self.oid_lag_name_map:
387390
counter_value = 0
391+
# Sum the values of this counter for all ports in the LAG.
392+
# Example:
393+
# table_name = <DbTables.SAI_PORT_STAT_IF_OUT_ERRORS: 20>
394+
# oid = 1001
395+
# self.oid_lag_name_map = {1001: 'PortChannel01', 1002: 'PortChannel02', 1003: 'PortChannel03'}
396+
# self.oid_lag_name_map[oid] = 'PortChannel01'
397+
# self.lag_name_if_name_map = {'PortChannel01': ['Ethernet112'], 'PortChannel02': ['Ethernet116'], 'PortChannel03': ['Ethernet120']}
398+
# self.lag_name_if_name_map['PortChannel01'] = ['Ethernet112']
399+
# mibs.get_index_from_str('Ethernet112') = 113 (because Ethernet N = N + 1)
400+
# self._get_counter retrieves the counter per oid and table.
388401
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
389402
counter_value += self._get_counter(mibs.get_index_from_str(lag_member), table_name)
403+
# Check if we need to add a router interface count.
404+
# Example:
405+
# self.lag_sai_map = {'PortChannel01': '2000000000006', 'PortChannel02': '2000000000005', 'PortChannel03': '2000000000004'}
406+
# self.port_rif_map = {'2000000000006': '6000000000006', '2000000000005': '6000000000005', '2000000000004': '6000000000004'}
407+
# self.rif_port_map = {'6000000000006': '2000000000006', '6000000000005': '2000000000005', '6000000000004': '2000000000004'}
408+
# self.lag_sai_map['PortChannel01'] = '2000000000006'
409+
# self.port_rif_map['2000000000006'] = '6000000000006'
390410
sai_lag_id = self.lag_sai_map[self.oid_lag_name_map[oid]]
391411
sai_lag_rif_id = self.port_rif_map[sai_lag_id]
392412
if sai_lag_rif_id in self.rif_port_map:
413+
# Extract the 'name' part of 'table_name'.
414+
# Example:
415+
# table_name = <DbTables.SAI_PORT_STAT_IF_OUT_ERRORS: 20>
416+
# _table_name = 'SAI_PORT_STAT_IF_OUT_ERRORS'
393417
table_name = getattr(table_name, 'name', table_name)
418+
# Find rif counter table if applicable and add the count for this table.
419+
# Example:
420+
# mibs.RIF_DROPS_AGGR_MAP = {'SAI_PORT_STAT_IF_IN_ERRORS': 'SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS', 'SAI_PORT_STAT_IF_OUT_ERRORS': 'SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS'}
421+
# self.rif_counters['6000000000006'] = {'SAI_ROUTER_INTERFACE_STAT_IN_PACKETS': 6, ... 'SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS': 6, ...}
394422
if table_name in mibs.RIF_DROPS_AGGR_MAP:
395423
rif_table_name = mibs.RIF_DROPS_AGGR_MAP[table_name]
396424
counter_value += self.rif_counters[sai_lag_rif_id].get(rif_table_name, 0)

0 commit comments

Comments
 (0)