def update_stats(self): """ Update statistics. 1. Get and sort port list to keep the order in MIB 2. Prepare OID and get a statistic for each queue of each port 3. Get and sort LAG ports list to keep the order in MIB 4. Prepare OID for LAG and prepare a statistic for each queue of each LAG port """ # Clear previous data self.mib_oid_to_queue_map = {} self.mib_oid_list = [] # Sort the ports to keep the OID order in the MIB if_range = list(self.oid_name_map.keys()) # Update queue counters for port for if_index in if_range: if if_index not in self.port_queue_list_map: # Port does not has a queues, continue.. continue if_queues = self.port_queue_list_map[if_index] namespace = self.port_index_namespace[if_index] # The first half of queue id is for ucast, and second half is for mcast # To simulate vendor OID, we wrap queues by half distance pq_count = math.ceil((max(if_queues) + 1) / 2) for queue in if_queues: # Get queue type and statistics queue_sai_oid = self.port_queues_map[mibs.queue_key(if_index, queue)] queue_stat_table_name = mibs.queue_table(queue_sai_oid) queue_stat_key = mibs.queue_key(if_index, queue_stat_table_name) queue_type = self.queue_type_map[namespace].get(queue_sai_oid) queue_stat = self.queue_stat_map.get(queue_stat_key, {}) # Add supported counters to MIBs list and store counters values for (counter, counter_type), counter_mib_id in CounterMap.items(): # Only egress queues are supported mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % pq_count) + 1, counter_mib_id) counter_value = 0 if queue_type == counter_type: counter_value = int(queue_stat.get(counter, 0)) if mib_oid in self.mib_oid_to_queue_map: continue self.mib_oid_list.append(mib_oid) self.mib_oid_to_queue_map[mib_oid] = counter_value self.mib_oid_list.sort()
def update_stats(self): """ Update statistics. 1. Get and sort port list to keep the order in MIB 2. Prepare OID and get a statistic for each queue of each port 3. Get and sort LAG ports list to keep the order in MIB 4. Prepare OID for LAG and prepare a statistic for each queue of each LAG port """ # Clear previous data self.mib_oid_to_queue_map = {} self.mib_oid_list = [] # Sort the ports to keep the OID order in the MIB if_range = list(self.oid_sai_map.keys()) # Update queue counters for port for if_index in if_range: if if_index not in self.port_queue_list_map: # Port does not has a queues, continue.. continue if_queues = self.port_queue_list_map[if_index] # The first half of queue id is for ucast, and second half is for mcast # To simulate vendor OID, we wrap queues by half distance pq_count = math.ceil((max(if_queues) + 1) / 2) for queue in if_queues: # Get queue type and statistics queue_sai_oid = self.port_queues_map[mibs.queue_key(if_index, queue)] queue_stat_table_name = mibs.queue_table(queue_sai_oid) queue_type = self.queue_type_map.get(queue_sai_oid) queue_stat = self.queue_stat_map.get(queue_stat_table_name, {}) # Add supported counters to MIBs list and store counters values for (counter, counter_type), counter_mib_id in CounterMap.items(): # Only egress queues are supported mib_oid = (if_index, int(DirectionTypes.EGRESS), (queue % pq_count) + 1, counter_mib_id) counter_value = 0 if queue_type == counter_type: counter_value = int(queue_stat.get(counter, 0)) if mib_oid in self.mib_oid_to_queue_map: continue self.mib_oid_list.append(mib_oid) self.mib_oid_to_queue_map[mib_oid] = counter_value self.mib_oid_list.sort()
def update_data(self): """ Update redis (caches config) Pulls the table references for each queue. """ for queue_key, sai_id in self.port_queues_map.items(): queue_stat_name = mibs.queue_table(sai_id) port_index, _ = queue_key.split(':') queue_stat_idx = mibs.queue_key(port_index, queue_stat_name) namespace = self.port_index_namespace[int(port_index)] queue_stat = self.namespace_db_map[namespace].get_all( \ mibs.COUNTERS_DB, queue_stat_name, blocking=False) if queue_stat is not None: self.queue_stat_map[queue_stat_idx] = queue_stat else: del self.queue_stat_map[queue_stat_idx] self.update_stats()