def update_data(self): """ Subclass update data routine. Updates available LLDP counters. """ # establish connection to application database. self.db_conn.connect(mibs.APPL_DB) self.if_range = [] self.lldp_counters = {} for if_oid, if_name in self.oid_name_map.items(): lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs: continue try: time_mark = int(lldp_kvs[b'lldp_rem_time_mark']) remote_index = int(lldp_kvs[b'lldp_rem_index']) self.if_range.append((time_mark, if_oid, remote_index)) self.lldp_counters.update({if_name: lldp_kvs}) except (KeyError, AttributeError) as e: logger.warning("Exception when updating lldpRemTable: {}".format(e)) continue self.if_range.sort()
def update_rem_if_mgmt(self, if_oid, if_name): lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs or b'lldp_rem_man_addr' not in lldp_kvs: # this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address return try: mgmt_ip_str = lldp_kvs[b'lldp_rem_man_addr'].decode() time_mark = int(lldp_kvs[b'lldp_rem_time_mark']) remote_index = int(lldp_kvs[b'lldp_rem_index']) subtype = self.get_subtype(mgmt_ip_str) ip_hex = self.get_ip_hex(mgmt_ip_str, subtype) if subtype == ManAddrConst.man_addr_subtype_ipv4: addr_subtype_sub_oid = 4 mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip_str.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_str.split(':')]) else: logger.warning("Invalid management IP {}".format(mgmt_ip_str)) return self.if_range.append((time_mark, if_oid, remote_index, subtype, *mgmt_ip_sub_oid)) self.mgmt_ips.update({if_name: {"ip_str": mgmt_ip_str, "addr_subtype": subtype, "addr_hex": ip_hex}}) except (KeyError, AttributeError) as e: logger.warning("Error updating remote mgmt addr: {}".format(e)) return self.if_range.sort()
def update_data(self): """ Subclass update data routine. Updates available LLDP counters. """ # establish connection to application database. self.if_range = [] self.lldp_counters = {} for if_oid, if_name in self.oid_name_map.items(): lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs: continue try: # OID index for this MIB consists of remote time mark, if_oid, remote_index. # For multi-asic platform, it can happen that same interface index result # is seen in SNMP walk, with a different remote time mark. # To avoid repeating the data of same interface index with different remote # time mark, remote time mark is made as 0 in the OID indexing. time_mark = 0 remote_index = int(lldp_kvs['lldp_rem_index']) self.if_range.append((time_mark, if_oid, remote_index)) lldp_kvs['lldp_rem_sys_cap_supported'] = parse_sys_capability( lldp_kvs['lldp_rem_sys_cap_supported']) lldp_kvs['lldp_rem_sys_cap_enabled'] = parse_sys_capability( lldp_kvs['lldp_rem_sys_cap_enabled']) self.lldp_counters.update({if_name: lldp_kvs}) except (KeyError, AttributeError) as e: logger.warning( "Exception when updating lldpRemTable: {}".format(e)) continue self.if_range.sort()
def update_rem_if_mgmt(self, if_oid, if_name): lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs or 'lldp_rem_man_addr' not in lldp_kvs: # this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address return try: mgmt_ip_str = lldp_kvs['lldp_rem_man_addr'] mgmt_ip_str = mgmt_ip_str.strip() if len(mgmt_ip_str) == 0: # the peer advertise an emtpy mgmt address return mgmt_ip_set = set() 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 = self.get_subtype(mgmt_ip) if not subtype: logger.warning("Invalid management IP {}".format(mgmt_ip)) continue mgmt_ip_tuple = ip2byte_tuple(mgmt_ip) if mgmt_ip_tuple in mgmt_ip_set: continue elif subtype == ManAddrConst.man_addr_subtype_ipv4: addr_subtype_sub_oid = 4 else: addr_subtype_sub_oid = 16 mgmt_ip_set.add(mgmt_ip_tuple) mgmt_ip_sub_oid = (addr_subtype_sub_oid, *mgmt_ip_tuple) self.if_range.append((time_mark, if_oid, remote_index, subtype, *mgmt_ip_sub_oid)) except (KeyError, AttributeError) as e: logger.warning("Error updating remote mgmt addr: {}".format(e)) return self.if_range.sort()
def update_data(self): """ Listen to updates in APP DB, update local cache """ if not self.pubsub: redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) db = self.db_conn.db_map[self.db_conn.APPL_DB]["db"] self.pubsub = redis_client.pubsub() self.pubsub.psubscribe("__keyspace@{}__:{}".format( db, mibs.lldp_entry_table(b'*'))) while True: data, interface, if_index = poll_lldp_entry_updates(self.pubsub) if not data: break if b"set" in data: self.update_rem_if_mgmt(if_index, interface.encode()) elif b"del" in data: # some remote data about that neighbor is gone, del it and try to query again self.if_range = [ sub_oid for sub_oid in self.if_range if sub_oid[0] != if_index ] self.update_rem_if_mgmt(if_index, interface.encode())
def update_data(self): """ Subclass update data routine. Updates available LLDP counters. """ # establish connection to application database. self.db_conn.connect(mibs.APPL_DB) self.if_range = [] self.lldp_counters = {} for if_oid, if_name in self.oid_name_map.items(): lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs: continue try: time_mark = int(lldp_kvs[b'lldp_rem_time_mark']) remote_index = int(lldp_kvs[b'lldp_rem_index']) self.if_range.append((time_mark, if_oid, remote_index)) self.lldp_counters.update({if_name: lldp_kvs}) except (KeyError, AttributeError) as e: logger.warning( "Exception when updating lldpRemTable: {}".format(e)) continue self.if_range.sort()
def update_data(self): for i in range(len(self.db_conn)): if not self.pubsub[i]: pattern = mibs.lldp_entry_table('*') self.pubsub[i] = mibs.get_redis_pubsub(self.db_conn[i], self.db_conn[i].APPL_DB, pattern) self._update_per_namespace_data(self.pubsub[i])
def update_data(self): """ Subclass update data routine. Updates available sai_ids and LLDP counters. """ self.lldp_counters = {} for if_name in self.if_name_map: lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs: continue self.lldp_counters.update({if_name: lldp_kvs}) if not self.lldp_counters: logger.warning( "0 - b'LLDP_ENTRY_TABLE' is empty. No LLDP information could be retrieved." )
def update_data(self): """ Listen to updates in APP DB, update local cache """ if not self.pubsub: redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) db = self.db_conn.db_map[self.db_conn.APPL_DB]["db"] self.pubsub = redis_client.pubsub() self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) while True: data, interface, if_id = poll_lldp_entry_updates(self.pubsub) if not data: break if b"set" in data: self.update_interface_data(interface.encode())
def update_data(self): """ Listen to updates in APP DB, update local cache """ if not self.pubsub: redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) db = self.db_conn.get_dbid(self.db_conn.APPL_DB) self.pubsub = redis_client.pubsub() self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) while True: data, interface, if_id = poll_lldp_entry_updates(self.pubsub) if not data: break if b"set" in data: self.update_interface_data(interface.encode())
def update_rem_if_mgmt(self, if_oid, if_name): lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs or b'lldp_rem_man_addr' not in lldp_kvs: # this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address return try: mgmt_ip_str = lldp_kvs[b'lldp_rem_man_addr'].decode() mgmt_ip_str = mgmt_ip_str.strip() if len(mgmt_ip_str) == 0: # the peer advertise an emtpy mgmt address return time_mark = int(lldp_kvs[b'lldp_rem_time_mark']) remote_index = int(lldp_kvs[b'lldp_rem_index']) subtype = self.get_subtype(mgmt_ip_str) ip_hex = self.get_ip_hex(mgmt_ip_str, subtype) if subtype == ManAddrConst.man_addr_subtype_ipv4: addr_subtype_sub_oid = 4 mgmt_ip_sub_oid = (addr_subtype_sub_oid, *[int(i) for i in mgmt_ip_str.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_str.split(':')]) else: logger.warning("Invalid management IP {}".format(mgmt_ip_str)) return self.if_range.append( (time_mark, if_oid, remote_index, subtype, *mgmt_ip_sub_oid)) self.mgmt_ips.update({ if_name: { "ip_str": mgmt_ip_str, "addr_subtype": subtype, "addr_hex": ip_hex } }) except (KeyError, AttributeError) as e: logger.warning("Error updating remote mgmt addr: {}".format(e)) return self.if_range.sort()
def update_data(self): """ Subclass update data routine. Updates available LLDP counters. """ # establish connection to application database. self.db_conn.connect(mibs.APPL_DB) self.if_range = [] self.lldp_counters = {} for if_oid, if_name in self.oid_name_map.items(): lldp_kvs = self.db_conn.get_all(mibs.APPL_DB, mibs.lldp_entry_table(if_name)) if not lldp_kvs: continue self.if_range.append((if_oid, )) self.lldp_counters.update({if_name: lldp_kvs}) if not self.lldp_counters: logger.warning( "0 - b'LLDP_ENTRY_TABLE' is empty. No LLDP information could be retrieved." ) self.if_range.sort()
def update_data(self): """ Listen to updates in APP DB, update local cache """ if not self.pubsub: redis_client = self.db_conn.get_redis_client(self.db_conn.APPL_DB) db = self.db_conn.db_map[self.db_conn.APPL_DB]["db"] self.pubsub = redis_client.pubsub() self.pubsub.psubscribe("__keyspace@{}__:{}".format(db, mibs.lldp_entry_table(b'*'))) while True: data, interface, if_index = poll_lldp_entry_updates(self.pubsub) if not data: break if b"set" in data: self.update_rem_if_mgmt(if_index, interface.encode()) elif b"del" in data: # some remote data about that neighbor is gone, del it and try to query again self.if_range = [sub_oid for sub_oid in self.if_range if sub_oid[0] != if_index] self.update_rem_if_mgmt(if_index, interface.encode())