def get_counter(self, sub_id, table_name): """ :param sub_id: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :return: the counter for the respective sub_id/table. """ oid = self.get_oid(sub_id) if not oid: return if oid in self.mgmt_oid_name_map: # TODO: mgmt counters not available through SNMP right now # COUNTERS DB does not have support for generic linux (mgmt) interface counters return 0 elif oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[ self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name) # truncate to 32-bit counter return counter_value & 0x00000000ffffffff else: return self._get_counter(oid, table_name)
def indications_per_priority(self, sub_id): """ :param sub_id: The 0-based sub-identifier query. :return: the counter for the respective sub_id/table. """ port_oid = '' queue_index = '' try: if not sub_id: return None port_oid = self.get_oid((sub_id[0], )) queue_index = self.queue_index(sub_id) if port_oid is None or queue_index is None: return None except IndexError: mibs.logger.warning( "indicationsPerPriority: incorrect sub_id = {}".format( str(sub_id))) return None counter_name = 'SAI_PORT_STAT_PFC_' + str(queue_index) + '_TX_PKTS' if port_oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[ self.oid_lag_name_map[port_oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), counter_name) return counter_value else: return self._get_counter(port_oid, counter_name)
def _get_counter(self, oid, table_name, mask): """ :param oid: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :param mask: mask to apply to counter :return: the counter for the respective sub_id/table. """ if oid in self.mgmt_oid_name_map: # TODO: mgmt counters not available through SNMP right now # COUNTERS DB does not have support for generic linux (mgmt) interface counters return 0 if oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name, mask) return counter_value & mask # Enum.name or table_name = 'name_of_the_table' _table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8') try: counter_value = self.if_counters[oid][_table_name] # truncate to 32-bit counter (database implements 64-bit counters) counter_value = int(counter_value) & mask # done! return counter_value except KeyError as e: mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e)) return None
def update_data(self): """ Update redis (caches config) Pulls the table references for each interface. """ self.vlanmac_ifindex_map = {} self.vlanmac_ifindex_list = [] fdb_strings = Namespace.dbs_keys(self.db_conn, mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*") if not fdb_strings: return for s in fdb_strings: fdb_str = s.decode() try: fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1]) except ValueError as e: # includes simplejson.decoder.JSONDecodeError mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e)) break ent = Namespace.dbs_get_all(self.db_conn, mibs.ASIC_DB, s, blocking=True) # Example output: oid:0x3a000000000608 bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:] if bridge_port_id not in self.if_bpid_map: continue port_id = self.if_bpid_map[bridge_port_id] vlanmac = self.fdb_vlanmac(fdb) self.vlanmac_ifindex_map[vlanmac] = mibs.get_index(self.if_id_map[port_id]) self.vlanmac_ifindex_list.append(vlanmac) self.vlanmac_ifindex_list.sort()
def update_data(self): """ Update redis (caches config) Pulls the table references for each interface. """ self.db_conn.connect(mibs.ASIC_DB) fdb_strings = self.db_conn.keys( mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*") self.vlanmac_ifindex_map = {} self.vlanmac_ifindex_list = [] if fdb_strings is None: return for s in fdb_strings: fdb_str = s.decode() try: fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1]) except ValueError as e: # includes simplejson.decoder.JSONDecodeError mibs.logger.error( "SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.". format(fdb_str, e)) break ent = self.db_conn.get_all(mibs.ASIC_DB, s, blocking=True) port_oid = ent[b"SAI_FDB_ENTRY_ATTR_PORT_ID"] if port_oid.startswith(b"oid:0x"): port_oid = port_oid[6:] vlanmac = fdb_vlanmac(fdb) self.vlanmac_ifindex_map[vlanmac] = mibs.get_index( self.if_id_map[port_oid]) self.vlanmac_ifindex_list.append(vlanmac) self.vlanmac_ifindex_list.sort()
def _get_counter(self, oid, table_name, mask): """ :param oid: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :param mask: mask to apply to counter :return: the counter for the respective sub_id/table. """ if oid in self.mgmt_oid_name_map: # TODO: mgmt counters not available through SNMP right now # COUNTERS DB does not have support for generic linux (mgmt) interface counters return 0 if oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name, mask) return counter_value & mask sai_id = self.oid_sai_map[oid] # Enum.name or table_name = 'name_of_the_table' _table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8') try: counter_value = self.if_counters[sai_id][_table_name] # truncate to 32-bit counter (database implements 64-bit counters) counter_value = int(counter_value) & mask # done! return counter_value except KeyError as e: mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e)) return None
def indications_per_priority(self, sub_id): """ :param sub_id: The 0-based sub-identifier query. :return: the counter for the respective sub_id/table. """ port_oid = '' queue_index = '' try: if not sub_id: return None port_oid = self.get_oid((sub_id[0],)) queue_index = self.queue_index(sub_id) if port_oid is None or queue_index is None: return None except IndexError: mibs.logger.warning("indicationsPerPriority: incorrect sub_id = {}".format(str(sub_id))) return None counter_name = 'SAI_PORT_STAT_PFC_' + str(queue_index) + '_RX_PKTS' if port_oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[port_oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), counter_name) return counter_value else: return self._get_counter(port_oid, counter_name)
def get_counter(self, sub_id, table_name): """ :param sub_id: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :return: the counter for the respective sub_id/table. """ oid = self.get_oid(sub_id) if not oid: return if oid in self.mgmt_oid_name_map: # TODO: mgmt counters not available through SNMP right now # COUNTERS DB does not have support for generic linux (mgmt) interface counters return 0 elif oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[ self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name) sai_lag_id = self.lag_sai_map[self.oid_lag_name_map[oid]] sai_lag_rif_id = self.port_rif_map[sai_lag_id] if sai_lag_rif_id in self.rif_port_map: table_name = bytes(getattr(table_name, 'name', table_name), 'utf-8') if table_name in mibs.RIF_DROPS_AGGR_MAP: rif_table_name = mibs.RIF_DROPS_AGGR_MAP[table_name] counter_value += int( self.rif_counters[sai_lag_rif_id][rif_table_name]) # truncate to 32-bit counter return counter_value & 0x00000000ffffffff else: return self._get_counter(oid, table_name)
def update_data(self): """ Update redis (caches config) Pulls the table references for each interface. """ self.db_conn.connect(mibs.ASIC_DB) self.vlanmac_ifindex_map = {} self.vlanmac_ifindex_list = [] fdb_strings = self.db_conn.keys(mibs.ASIC_DB, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:*") if not fdb_strings: return for s in fdb_strings: fdb_str = s.decode() try: fdb = json.loads(fdb_str.split(":", maxsplit=2)[-1]) except ValueError as e: # includes simplejson.decoder.JSONDecodeError mibs.logger.error("SyncD 'ASIC_DB' includes invalid FDB_ENTRY '{}': {}.".format(fdb_str, e)) break ent = self.db_conn.get_all(mibs.ASIC_DB, s, blocking=True) # Example output: oid:0x3a000000000608 bridge_port_id = ent[b"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID"][6:] if bridge_port_id not in self.if_bpid_map: continue port_id = self.if_bpid_map[bridge_port_id] vlanmac = self.fdb_vlanmac(fdb) self.vlanmac_ifindex_map[vlanmac] = mibs.get_index(self.if_id_map[port_id]) self.vlanmac_ifindex_list.append(vlanmac) self.vlanmac_ifindex_list.sort()
def cpfc_if_indications(self, sub_id): """ :param sub_id: The 1-based sub-identifier query. :return: the counter for the respective sub_id/table. """ oid = self.get_oid(sub_id) if oid is None: return None # BUG: need the sum of all the priorities counter_name = 'SAI_PORT_STAT_PFC_3_RX_PKTS' if oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), counter_name) return counter_value else: return self._get_counter(oid, counter_name)
def get_counter(self, sub_id, table_name): """ :param sub_id: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :return: the counter for the respective sub_id/table. """ oid = self.get_oid(sub_id) if not oid: return if oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[ self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name) # truncate to 32-bit counter return counter_value & 0x00000000ffffffff else: return self._get_counter(oid, table_name)
def get_counter(self, sub_id, table_name): """ :param sub_id: The 1-based sub-identifier query. :param table_name: the redis table (either IntEnum or string literal) to query. :return: the counter for the respective sub_id/table. """ oid = self.get_oid(sub_id) if not oid: return if oid in self.mgmt_oid_name_map: # TODO: mgmt counters not available through SNMP right now # COUNTERS DB does not have support for generic linux (mgmt) interface counters return 0 elif oid in self.oid_lag_name_map: counter_value = 0 for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index(lag_member), table_name) # truncate to 32-bit counter return counter_value & 0x00000000ffffffff else: return self._get_counter(oid, table_name)