Skip to content

Commit

Permalink
Non-block reading counters to tolerate corrupted/delayed counters in …
Browse files Browse the repository at this point in the history
…COUNTERS_DB (#229)

**- What I did**
Interface counters in COUNTERS_DB may be corrupted or delayed. We could not assume they are always available.

**- How to verify it**
Unit test and smoke test on DUT
  • Loading branch information
qiluo-msft authored Aug 3, 2021
1 parent 21d7d97 commit 4d6bb79
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 113 deletions.
14 changes: 8 additions & 6 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ def update_if_counters(self):
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
counters_db_data = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB,
mibs.counter_table(sai_id),
blocking=True)
mibs.counter_table(sai_id))
if counters_db_data is None:
counters_db_data = {}
self.if_counters[if_idx] = {
counter: int(value) for counter, value in counters_db_data.items()
}
Expand All @@ -272,8 +273,9 @@ def update_rif_counters(self):
rif_sai_ids = list(self.rif_port_map) + list(self.vlan_name_map)
for sai_id in rif_sai_ids:
counters_db_data = Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB,
mibs.counter_table(mibs.split_sai_id_key(sai_id)[1]),
blocking=False)
mibs.counter_table(mibs.split_sai_id_key(sai_id)[1]))
if counters_db_data is None:
counters_db_data = {}
self.rif_counters[sai_id] = {
counter: int(value) for counter, value in counters_db_data.items()
}
Expand Down Expand Up @@ -358,8 +360,8 @@ def aggregate_counters(self):
port_idx = mibs.get_index_from_str(self.if_id_map[port_sai_id])
for port_counter_name, rif_counter_name in mibs.RIF_DROPS_AGGR_MAP.items():
self.if_counters[port_idx][port_counter_name] = \
self.if_counters[port_idx][port_counter_name] + \
self.rif_counters[rif_sai_id][rif_counter_name]
self.if_counters[port_idx].get(port_counter_name, 0) + \
self.rif_counters[rif_sai_id].get(rif_counter_name, 0)

for vlan_sai_id, vlan_name in self.vlan_name_map.items():
for port_counter_name, rif_counter_name in mibs.RIF_COUNTERS_AGGR_MAP.items():
Expand Down
7 changes: 5 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ def update_data(self):
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)
counter_table = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id))
if counter_table is None:
counter_table = {}
self.if_counters[if_idx] = counter_table

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
Expand Down
8 changes: 6 additions & 2 deletions src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def update_data(self):
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)
counter_table = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id))
if counter_table is None:
counter_table = {}
self.if_counters[if_idx] = counter_table


self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
Expand Down
102 changes: 0 additions & 102 deletions tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,108 +203,6 @@
"SAI_PORT_STAT_PFC_7_RX_PKTS": "8",
"SAI_PORT_STAT_PFC_7_TX_PKTS": "8"
},
"COUNTERS:oid:0x1000000000020": {
"SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0",
"SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0",
"SAI_PORT_STAT_IF_OUT_ERRORS": "0",
"SAI_PORT_STAT_ETHER_TX_OVERSIZE_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_1519_TO_2047_OCTETS": "0",
"SAI_PORT_STAT_IP_IN_RECEIVES": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_64_OCTETS": "0",
"SAI_PORT_STAT_IPV6_OUT_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_4096_TO_9216_OCTETS": "0",
"SAI_PORT_STAT_IF_IN_ERRORS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0",
"SAI_PORT_STAT_IF_IN_DISCARDS": "0",
"SAI_PORT_STAT_IP_OUT_DISCARDS": "0",
"SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS": "0",
"SAI_PORT_STAT_IPV6_IN_DISCARDS": "0",
"SAI_PORT_STAT_IPV6_OUT_DISCARDS": "0",
"SAI_PORT_STAT_IPV6_IN_OCTETS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_65_TO_127_OCTETS": "0",
"SAI_PORT_STAT_IF_IN_BROADCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_1519_TO_2047_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_MULTICAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_512_TO_1023_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_256_TO_511_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_9217_TO_16383_OCTETS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_512_TO_1023_OCTETS": "0",
"SAI_PORT_STAT_IPV6_IN_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_4096_TO_9216_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS": "0",
"SAI_PORT_STAT_IPV6_OUT_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_IF_IN_VLAN_DISCARDS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_65_TO_127_OCTETS": "0",
"SAI_PORT_STAT_IP_IN_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_FRAGMENTS": "0",
"SAI_PORT_STAT_IPV6_IN_UCAST_PKTS": "0",
"SAI_PORT_STAT_IPV6_IN_RECEIVES": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_4096_TO_9216_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_DISCARDS": "0",
"SAI_PORT_STAT_ETHER_STATS_DROP_EVENTS": "0",
"SAI_PORT_STAT_IPV6_OUT_MCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_RX_OVERSIZE_PKTS": "0",
"SAI_PORT_STAT_IF_OUT_OCTETS": "0",
"SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_9217_TO_16383_OCTETS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_1024_TO_1518_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_2048_TO_4095_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_512_TO_1023_OCTETS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_1519_TO_2047_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_RX_NO_ERRORS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_64_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_COLLISIONS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_1024_TO_1518_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_1024_TO_1518_OCTETS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_256_TO_511_OCTETS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_2048_TO_4095_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_UNDERSIZE_PKTS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_128_TO_255_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_64_OCTETS": "0",
"SAI_PORT_STAT_IP_OUT_OCTETS": "0",
"SAI_PORT_STAT_IF_IN_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_9217_TO_16383_OCTETS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_2048_TO_4095_OCTETS": "0",
"SAI_PORT_STAT_IP_OUT_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_JABBERS": "0",
"SAI_PORT_STAT_IF_IN_OCTETS": "0",
"SAI_PORT_STAT_IPV6_IN_MCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_65_TO_127_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_QLEN": "0",
"SAI_PORT_STAT_ETHER_STATS_PKTS_128_TO_255_OCTETS": "0",
"SAI_PORT_STAT_IP_IN_DISCARDS": "0",
"SAI_PORT_STAT_IPV6_OUT_OCTETS": "0",
"SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS": "0",
"SAI_PORT_STAT_IP_IN_OCTETS": "0",
"SAI_PORT_STAT_ETHER_OUT_PKTS_256_TO_511_OCTETS": "0",
"SAI_PORT_STAT_ETHER_STATS_CRC_ALIGN_ERRORS": "0",
"SAI_PORT_STAT_IP_OUT_UCAST_PKTS": "0",
"SAI_PORT_STAT_IP_IN_UCAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_STATS_MULTICAST_PKTS": "0",
"SAI_PORT_STAT_ETHER_IN_PKTS_128_TO_255_OCTETS": "0",
"SAI_PORT_STAT_IF_IN_MULTICAST_PKTS": "0",
"SAI_PORT_STAT_PAUSE_RX_PKTS": "0",
"SAI_PORT_STAT_PAUSE_TX_PKTS": "0",
"SAI_PORT_STAT_PFC_0_RX_PKTS": "1",
"SAI_PORT_STAT_PFC_0_TX_PKTS": "1",
"SAI_PORT_STAT_PFC_1_RX_PKTS": "2",
"SAI_PORT_STAT_PFC_1_TX_PKTS": "2",
"SAI_PORT_STAT_PFC_2_RX_PKTS": "3",
"SAI_PORT_STAT_PFC_2_TX_PKTS": "3",
"SAI_PORT_STAT_PFC_3_RX_PKTS": "4",
"SAI_PORT_STAT_PFC_3_TX_PKTS": "4",
"SAI_PORT_STAT_PFC_4_RX_PKTS": "5",
"SAI_PORT_STAT_PFC_4_TX_PKTS": "5",
"SAI_PORT_STAT_PFC_5_RX_PKTS": "6",
"SAI_PORT_STAT_PFC_5_TX_PKTS": "6",
"SAI_PORT_STAT_PFC_6_RX_PKTS": "7",
"SAI_PORT_STAT_PFC_6_TX_PKTS": "7",
"SAI_PORT_STAT_PFC_7_RX_PKTS": "8",
"SAI_PORT_STAT_PFC_7_TX_PKTS": "8"
},
"COUNTERS:oid:0x1000000000021": {
"SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0",
"SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0",
Expand Down
2 changes: 1 addition & 1 deletion tests/mock_tables/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def connect_SonicV2Connector(self, db_name, retry_on=True):
_old_connect_SonicV2Connector(self, db_name, retry_on)


def _subscribe_keyspace_notification(self, db_name, client):
def _subscribe_keyspace_notification(self, db_name):
pass


Expand Down

0 comments on commit 4d6bb79

Please sign in to comment.