diff --git a/src/sonic_ax_impl/mibs/__init__.py b/src/sonic_ax_impl/mibs/__init__.py index fe7e74ddb..dde858bc2 100644 --- a/src/sonic_ax_impl/mibs/__init__.py +++ b/src/sonic_ax_impl/mibs/__init__.py @@ -27,6 +27,20 @@ HOST_NAMESPACE_DB_IDX = 0 +RIF_COUNTERS_AGGR_MAP = { + "SAI_PORT_STAT_IF_IN_OCTETS": "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS", + "SAI_PORT_STAT_IF_IN_UCAST_PKTS": "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS", + "SAI_PORT_STAT_IF_IN_ERRORS": "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS", + "SAI_PORT_STAT_IF_OUT_OCTETS": "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS", + "SAI_PORT_STAT_IF_OUT_UCAST_PKTS": "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS", + "SAI_PORT_STAT_IF_OUT_ERRORS": "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS" +} + +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" +} + redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'} @@ -136,6 +150,14 @@ def if_entry_table(if_name): return 'PORT_TABLE:' + if_name +def vlan_entry_table(if_name): + """ + :param if_name: given interface to cast. + :return: VLAN_TABLE key. + """ + return 'VLAN_TABLE:' + if_name + + def lag_entry_table(lag_name): """ :param lag_name: given lag to cast. @@ -292,11 +314,52 @@ def init_sync_d_interface_tables(db_conn): return if_name_map, if_alias_map, if_id_map, oid_name_map + +def init_sync_d_rif_tables(db_conn): + """ + Initializes map of RIF SAI oids to port SAI oid. + :return: dict + """ + rif_port_map = {get_sai_id_key(db_conn.namespace, rif): get_sai_id_key(db_conn.namespace, port) + for rif, port in port_util.get_rif_port_map(db_conn).items()} + port_rif_map = {port: rif for rif, port in rif_port_map.items()} + logger.debug("Rif port map:\n" + pprint.pformat(rif_port_map, indent=2)) + + return rif_port_map, port_rif_map + + +def init_sync_d_vlan_tables(db_conn): + """ + Initializes vlan interface maps for SyncD-connected MIB(s). + :return: tuple(vlan_name_map, oid_sai_map, oid_name_map) + """ + + vlan_name_map = port_util.get_vlan_interface_oid_map(db_conn) + + logger.debug("Vlan oid map:\n" + pprint.pformat(vlan_name_map, indent=2)) + + oid_sai_map = {} + oid_name_map = {} + for sai_id, if_name in vlan_name_map.items(): + port_index = get_index_from_str(if_name) + if not port_index: + continue + # { OID -> sai_id } + oid_sai_map[port_index] = sai_id + # { OID -> if_name (SONiC) } + oid_name_map[port_index] = if_name + + logger.debug("OID sai map:\n" + pprint.pformat(oid_sai_map, indent=2)) + logger.debug("OID name map:\n" + pprint.pformat(oid_name_map, indent=2)) + + return vlan_name_map, oid_sai_map, oid_name_map + + def init_sync_d_lag_tables(db_conn): """ Helper method. Connects to and initializes LAG interface maps for SyncD-connected MIB(s). :param db_conn: database connector - :return: tuple(lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map) + :return: tuple(lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, lag_sai_map, sai_lag_map) """ # { lag_name (SONiC) -> [ lag_members (if_name) ] } # ex: { "PortChannel0" : [ "Ethernet0", "Ethernet4" ] } @@ -316,7 +379,7 @@ def init_sync_d_lag_tables(db_conn): lag_entries = db_conn.keys(APPL_DB, "LAG_TABLE:*") if not lag_entries: - return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, lag_sai_map + return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, lag_sai_map, sai_lag_map db_conn.connect(COUNTERS_DB) lag_sai_map = db_conn.get_all(COUNTERS_DB, "COUNTERS_LAG_NAME_MAP") @@ -345,7 +408,7 @@ def member_name_str(val, lag_name): if idx: oid_lag_name_map[idx] = if_name - return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, sai_lag_map + return lag_name_if_name_map, if_name_lag_name_map, oid_lag_name_map, lag_sai_map, sai_lag_map def init_sync_d_queue_tables(db_conn): """ @@ -360,7 +423,7 @@ def init_sync_d_queue_tables(db_conn): # Parse the queue_name_map and create the following maps: # port_queues_map -> {"port_index : queue_index" : sai_oid} - # queue_stat_map -> {"port_index : queue stat table name" : {counter name : value}} + # queue_stat_map -> {"port_index : queue stat table name" : {counter name : value}} # port_queue_list_map -> {port_index: [sorted queue list]} port_queues_map = {} queue_stat_map = {} @@ -424,7 +487,7 @@ class RedisOidTreeUpdater(MIBUpdater): def __init__(self, prefix_str): super().__init__() - self.db_conn = Namespace.init_namespace_dbs() + self.db_conn = Namespace.init_namespace_dbs() if prefix_str.startswith('.'): prefix_str = prefix_str[1:] self.prefix_str = prefix_str @@ -537,7 +600,7 @@ def dbs_get_all(dbs, db_name, _hash, *args, **kwargs): db get_all function executed on global and all namespace DBs. """ result = {} - # If there are multiple namespaces, _hash might not be + # If there are multiple namespaces, _hash might not be # present in all namespace, ignore if not present in a # specfic namespace. if len(dbs) > 1: diff --git a/src/sonic_ax_impl/mibs/ietf/rfc1213.py b/src/sonic_ax_impl/mibs/ietf/rfc1213.py index 0b8b69ff0..53c143c6e 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc1213.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc1213.py @@ -50,7 +50,8 @@ class DbTables(int, Enum): class IfTypes(int, Enum): """ IANA ifTypes """ ethernetCsmacd = 6 - ieee8023adLag = 161 + l3ipvlan = 136 + ieee8023adLag = 161 class ArpUpdater(MIBUpdater): def __init__(self): @@ -192,8 +193,13 @@ def __init__(self): self.lag_name_if_name_map = {} self.if_name_lag_name_map = {} self.oid_lag_name_map = {} + self.lag_sai_map = {} self.mgmt_oid_name_map = {} self.mgmt_alias_map = {} + self.vlan_oid_name_map = {} + self.vlan_name_map = {} + self.rif_port_map = {} + self.port_rif_map = {} # cache of interface counters self.if_counters = {} @@ -202,6 +208,8 @@ def __init__(self): self.if_alias_map = {} self.if_id_map = {} self.oid_name_map = {} + self.rif_counters = {} + self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn) def reinit_data(self): @@ -220,26 +228,56 @@ def reinit_data(self): self.mgmt_oid_name_map, \ self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0]) + self.vlan_name_map, \ + self.vlan_oid_sai_map, \ + self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn) + + self.rif_port_map, \ + self.port_rif_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_rif_tables, self.db_conn) + def update_data(self): """ Update redis (caches config) Pulls the table references for each interface. """ - 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) + + self.update_if_counters() + self.update_rif_counters() + + self.aggregate_counters() self.lag_name_if_name_map, \ self.if_name_lag_name_map, \ - self.oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) + self.oid_lag_name_map, \ + self.lag_sai_map, self.sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) self.if_range = sorted(list(self.oid_name_map.keys()) + list(self.oid_lag_name_map.keys()) + - list(self.mgmt_oid_name_map.keys())) + list(self.mgmt_oid_name_map.keys()) + + list(self.vlan_oid_name_map.keys())) self.if_range = [(i,) for i in self.if_range] + def update_if_counters(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]) + counters_db_data = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, + mibs.counter_table(sai_id), + blocking=True) + self.if_counters[if_idx] = { + counter: int(value) for counter, value in counters_db_data.items() + } + + 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) + self.rif_counters[sai_id] = { + counter: int(value) for counter, value in counters_db_data.items() + } + def get_next(self, sub_id): """ :param sub_id: The 1-based sub-identifier query. @@ -281,6 +319,8 @@ def interface_description(self, sub_id): return self.oid_lag_name_map[oid] elif oid in self.mgmt_oid_name_map: return self.mgmt_alias_map[self.mgmt_oid_name_map[oid]] + elif oid in self.vlan_oid_name_map: + return self.vlan_oid_name_map[oid] return self.if_alias_map[self.oid_name_map[oid]] @@ -291,18 +331,46 @@ def _get_counter(self, oid, table_name): :return: the counter for the respective sub_id/table. """ # Enum.name or table_name = 'name_of_the_table' + # Example: + # table_name = + # _table_name = 'SAI_PORT_STAT_IF_OUT_ERRORS' _table_name = getattr(table_name, 'name', table_name) try: counter_value = self.if_counters[oid][_table_name] # truncate to 32-bit counter (database implements 64-bit counters) - counter_value = int(counter_value) & 0x00000000ffffffff + counter_value = counter_value & 0x00000000ffffffff # done! return counter_value except KeyError as e: mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e)) return None + def aggregate_counters(self): + """ + For ports with l3 router interfaces l3 drops may be counted separately (RIF counters) + add l3 drops to l2 drop counters cache according to mapping + + For l3vlan map l3 counters to l2 counters + """ + for rif_sai_id, port_sai_id in self.rif_port_map.items(): + if port_sai_id in self.if_id_map: + 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] + + 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(): + vlan_idx = mibs.get_index_from_str(vlan_name) + vlan_rif_counters = self.rif_counters[vlan_sai_id] + if rif_counter_name in vlan_rif_counters: + self.if_counters.setdefault(vlan_idx, {}) + self.if_counters[vlan_idx][port_counter_name] = \ + vlan_rif_counters[rif_counter_name] + + def get_counter(self, sub_id, table_name): """ :param sub_id: The 1-based sub-identifier query. @@ -320,9 +388,40 @@ def get_counter(self, sub_id, table_name): return 0 elif oid in self.oid_lag_name_map: counter_value = 0 + # Sum the values of this counter for all ports in the LAG. + # Example: + # table_name = + # oid = 1001 + # self.oid_lag_name_map = {1001: 'PortChannel01', 1002: 'PortChannel02', 1003: 'PortChannel03'} + # self.oid_lag_name_map[oid] = 'PortChannel01' + # self.lag_name_if_name_map = {'PortChannel01': ['Ethernet112'], 'PortChannel02': ['Ethernet116'], 'PortChannel03': ['Ethernet120']} + # self.lag_name_if_name_map['PortChannel01'] = ['Ethernet112'] + # mibs.get_index_from_str('Ethernet112') = 113 (because Ethernet N = N + 1) + # self._get_counter retrieves the counter per oid and table. for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]: counter_value += self._get_counter(mibs.get_index_from_str(lag_member), table_name) - + # Check if we need to add a router interface count. + # Example: + # self.lag_sai_map = {'PortChannel01': '2000000000006', 'PortChannel02': '2000000000005', 'PortChannel03': '2000000000004'} + # self.port_rif_map = {'2000000000006': '6000000000006', '2000000000005': '6000000000005', '2000000000004': '6000000000004'} + # self.rif_port_map = {'6000000000006': '2000000000006', '6000000000005': '2000000000005', '6000000000004': '2000000000004'} + # self.lag_sai_map['PortChannel01'] = '2000000000006' + # self.port_rif_map['2000000000006'] = '6000000000006' + 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: + # Extract the 'name' part of 'table_name'. + # Example: + # table_name = + # _table_name = 'SAI_PORT_STAT_IF_OUT_ERRORS' + table_name = getattr(table_name, 'name', table_name) + # Find rif counter table if applicable and add the count for this table. + # Example: + # 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'} + # self.rif_counters['6000000000006'] = {'SAI_ROUTER_INTERFACE_STAT_IN_PACKETS': 6, ... 'SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS': 6, ...} + if table_name in mibs.RIF_DROPS_AGGR_MAP: + rif_table_name = mibs.RIF_DROPS_AGGR_MAP[table_name] + counter_value += self.rif_counters[sai_lag_rif_id].get(rif_table_name, 0) # truncate to 32-bit counter return counter_value & 0x00000000ffffffff else: @@ -352,6 +451,8 @@ def _get_if_entry(self, sub_id): elif oid in self.mgmt_oid_name_map: if_table = mibs.mgmt_if_entry_table(self.mgmt_oid_name_map[oid]) db = mibs.CONFIG_DB + elif oid in self.vlan_oid_name_map: + if_table = mibs.vlan_entry_table(self.vlan_oid_name_map[oid]) elif oid in self.oid_name_map: if_table = mibs.if_entry_table(self.oid_name_map[oid]) else: @@ -456,6 +557,7 @@ def get_if_type(self, sub_id): ethernetCsmacd(6), -- for all ethernet-like interfaces, -- regardless of speed, as per RFC3635 + l3ipvlan(136) -- Layer 3 Virtual LAN using IP ieee8023adLag(161) -- IEEE 802.3ad Link Aggregate """ oid = self.get_oid(sub_id) @@ -464,6 +566,8 @@ def get_if_type(self, sub_id): if oid in self.oid_lag_name_map: return IfTypes.ieee8023adLag + elif oid in self.vlan_oid_name_map: + return IfTypes.l3ipvlan else: return IfTypes.ethernetCsmacd diff --git a/src/sonic_ax_impl/mibs/ietf/rfc2863.py b/src/sonic_ax_impl/mibs/ietf/rfc2863.py index 1bfa4a588..159a5e078 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc2863.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc2863.py @@ -2,8 +2,9 @@ from bisect import bisect_right from sonic_ax_impl import mibs -from ax_interface.mib import MIBMeta, MIBUpdater, ValueType, SubtreeMIBEntry, OverlayAdpaterMIBEntry, OidMIBEntry +from ax_interface.mib import MIBMeta, MIBUpdater, ValueType, SubtreeMIBEntry, OverlayAdpaterMIBEntry, OidMIBEntry, MIBEntry from sonic_ax_impl.mibs import Namespace +from os import stat_result @unique class DbTables32(int, Enum): @@ -44,6 +45,42 @@ class DbTables64(int, Enum): SAI_PORT_STAT_IF_OUT_BROADCAST_PKTS = 13 +@unique +class DbTables(int, Enum): + """ + Maps database tables names to SNMP sub-identifiers. + https://tools.ietf.org/html/rfc1213#section-6.4 + REDIS_TABLE_NAME = (RFC1213 OID NUMBER) + """ + + # ifOperStatus ::= { ifEntry 8 } + # ifLastChange :: { ifEntry 9 } + # ifInOctets ::= { ifEntry 10 } + SAI_PORT_STAT_IF_IN_OCTETS = 10 + # ifInUcastPkts ::= { ifEntry 11 } + SAI_PORT_STAT_IF_IN_UCAST_PKTS = 11 + # ifInNUcastPkts ::= { ifEntry 12 } + SAI_PORT_STAT_IF_IN_NON_UCAST_PKTS = 12 + # ifInDiscards ::= { ifEntry 13 } + SAI_PORT_STAT_IF_IN_DISCARDS = 13 + # ifInErrors ::= { ifEntry 14 } + SAI_PORT_STAT_IF_IN_ERRORS = 14 + # ifInUnknownProtos ::= { ifEntry 15 } + SAI_PORT_STAT_IF_IN_UNKNOWN_PROTOS = 15 + # ifOutOctets ::= { ifEntry 16 } + SAI_PORT_STAT_IF_OUT_OCTETS = 16 + # ifOutUcastPkts ::= { ifEntry 17 } + SAI_PORT_STAT_IF_OUT_UCAST_PKTS = 17 + # ifOutNUcastPkts ::= { ifEntry 18 } + SAI_PORT_STAT_IF_OUT_NON_UCAST_PKTS = 18 + # ifOutDiscards ::= { ifEntry 19 } + SAI_PORT_STAT_IF_OUT_DISCARDS = 19 + # ifOutErrors ::= { ifEntry 20 } + SAI_PORT_STAT_IF_OUT_ERRORS = 20 + # ifOutQLen ::= { ifEntry 21 } + SAI_PORT_STAT_IF_OUT_QLEN = 21 + + class InterfaceMIBUpdater(MIBUpdater): def __init__(self): super().__init__() @@ -55,16 +92,16 @@ def __init__(self): self.oid_lag_name_map = {} self.mgmt_oid_name_map = {} self.mgmt_alias_map = {} - + self.vlan_oid_name_map = {} + self.vlan_name_map = {} + self.rif_port_map = {} self.if_counters = {} self.if_range = [] self.if_name_map = {} self.if_alias_map = {} self.if_id_map = {} self.oid_name_map = {} - self.lag_name_if_name_map = {} - self.if_name_lag_name_map = {} - self.oid_lag_name_map = {} + self.rif_counters = {} self.namespace_db_map = Namespace.get_namespace_db_map(self.db_conn) @@ -79,7 +116,7 @@ def reinit_data(self): self.lag_name_if_name_map, \ self.if_name_lag_name_map, \ - self.oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) + self.oid_lag_name_map, _, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) """ db_conn - will have db_conn to all namespace DBs and global db. First db in the list is global db. @@ -88,9 +125,17 @@ def reinit_data(self): self.mgmt_oid_name_map, \ self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0]) + self.vlan_name_map, \ + self.vlan_oid_sai_map, \ + self.vlan_oid_name_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_vlan_tables, self.db_conn) + + self.rif_port_map, \ + self.port_rif_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_rif_tables, self.db_conn) + self.if_range = sorted(list(self.oid_name_map.keys()) + list(self.oid_lag_name_map.keys()) + - list(self.mgmt_oid_name_map.keys())) + list(self.mgmt_oid_name_map.keys()) + + list(self.vlan_oid_name_map.keys())) self.if_range = [(i,) for i in self.if_range] def update_data(self): @@ -104,6 +149,17 @@ def update_data(self): self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \ mibs.counter_table(sai_id), blocking=True) + self.lag_name_if_name_map, \ + self.if_name_lag_name_map, \ + self.oid_lag_name_map, \ + self.lag_sai_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) + + self.if_range = sorted(list(self.oid_name_map.keys()) + + list(self.oid_lag_name_map.keys()) + + list(self.mgmt_oid_name_map.keys()) + + list(self.vlan_oid_name_map.keys())) + self.if_range = [(i,) for i in self.if_range] + def get_next(self, sub_id): """ :param sub_id: The 1-based sub-identifier query. @@ -134,12 +190,16 @@ def interface_name(self, sub_id): return if oid in self.oid_lag_name_map: - return self.oid_lag_name_map[oid] + result = self.oid_lag_name_map[oid] elif oid in self.mgmt_oid_name_map: - return self.mgmt_alias_map[self.mgmt_oid_name_map[oid]] - - return self.if_alias_map[self.oid_name_map[oid]] + result = self.mgmt_alias_map[self.mgmt_oid_name_map[oid]] + elif oid in self.vlan_oid_name_map: + result = self.vlan_oid_name_map[oid] + else: + result = self.if_alias_map[self.oid_name_map[oid]] + return result + def interface_alias(self, sub_id): """ ifAlias specific - this is not the "Alias map". @@ -151,7 +211,19 @@ def interface_alias(self, sub_id): if not entry: return - return entry.get("description", "") + result = entry.get("description", "") + + if not result: + #RFC2863 tables don't have descriptions for LAG, vlan & mgmt; take from RFC1213 + oid = self.get_oid(sub_id) + if oid in self.oid_lag_name_map: + result = self.oid_lag_name_map[oid] + elif oid in self.mgmt_oid_name_map: + result = self.mgmt_alias_map[self.mgmt_oid_name_map[oid]] + elif oid in self.vlan_oid_name_map: + result = self.vlan_oid_name_map[oid] + + return result def get_counter32(self, sub_id, table_name): oid = self.get_oid(sub_id) @@ -217,6 +289,8 @@ def _get_if_entry(self, sub_id): elif oid in self.mgmt_oid_name_map: if_table = mibs.mgmt_if_entry_table(self.mgmt_oid_name_map[oid]) db = mibs.CONFIG_DB + elif oid in self.vlan_oid_name_map: + if_table = mibs.vlan_entry_table(self.vlan_oid_name_map[oid]) elif oid in self.oid_name_map: if_table = mibs.if_entry_table(self.oid_name_map[oid]) else: @@ -270,7 +344,7 @@ class InterfaceMIBObjects(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.31.1'): DbTables32(4)), OidMIBEntry('1.1.4', ValueType.COUNTER_32, oidtree_updater.get_oidvalue) ) - + ifOutBroadcastPkts = \ OverlayAdpaterMIBEntry( SubtreeMIBEntry('1.1.5', if_updater, ValueType.COUNTER_32, if_updater.get_counter32, diff --git a/src/sonic_ax_impl/mibs/ietf/rfc4363.py b/src/sonic_ax_impl/mibs/ietf/rfc4363.py index 8dd5dead2..294e16f1d 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc4363.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc4363.py @@ -54,7 +54,7 @@ def reinit_data(self): self.lag_name_if_name_map, \ self.if_name_lag_name_map, \ self.oid_lag_name_map, \ - self.sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) + _, self.sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) self.if_bpid_map = Namespace.dbs_get_bridge_port_map(self.db_conn, mibs.ASIC_DB) self.bvid_vlan_map.clear() diff --git a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py index 3130de034..51acc8fe4 100644 --- a/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py +++ b/src/sonic_ax_impl/mibs/vendor/cisco/ciscoPfcExtMIB.py @@ -52,7 +52,7 @@ def update_data(self): self.lag_name_if_name_map, \ self.if_name_lag_name_map, \ - self.oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) + self.oid_lag_name_map, _, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn) self.if_range = sorted(list(self.oid_name_map.keys()) + list(self.oid_lag_name_map.keys())) self.if_range = [(i,) for i in self.if_range] @@ -94,7 +94,7 @@ def _get_counter(self, oid, counter_name): _counter_name = getattr(counter_name, 'name', counter_name) try: - counter_value = self.if_counters[oid][_counter_name] + counter_value = self.if_counters[oid][_counter_name] counter_value = int(counter_value) & 0xffffffffffffffff # done! return counter_value diff --git a/tests/mock_tables/asic0/appl_db.json b/tests/mock_tables/asic0/appl_db.json index d741bf6f8..49b796c36 100644 --- a/tests/mock_tables/asic0/appl_db.json +++ b/tests/mock_tables/asic0/appl_db.json @@ -84,6 +84,11 @@ "oper_status": "up", "mtu": "9216" }, + "VLAN_TABLE:Vlan1000": { + "admin_status": "up", + "hostif_name": "", + "mtu": "9216" + }, "INTF_TABLE:lo:10.1.0.32/32": { "scope": "global", "family": "IPv4" diff --git a/tests/mock_tables/asic0/asic_db.json b/tests/mock_tables/asic0/asic_db.json index 590918051..81f5ca798 100644 --- a/tests/mock_tables/asic0/asic_db.json +++ b/tests/mock_tables/asic0/asic_db.json @@ -23,5 +23,12 @@ "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT", "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000005", "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000006": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000007" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x1000000000007": { + "NULL": "NULL" } } diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 282a4b952..f1748c808 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -206,14 +206,14 @@ "COUNTERS:oid:0x1000000000005": { "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_IF_OUT_ERRORS": "100", "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_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", "SAI_PORT_STAT_IF_IN_DISCARDS": "0", @@ -245,7 +245,7 @@ "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_OUT_OCTETS": "100", "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", @@ -260,17 +260,17 @@ "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_IF_OUT_UCAST_PKTS": "100", "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_IF_IN_UCAST_PKTS": "100", "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_IF_IN_OCTETS": "100", "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", @@ -314,6 +314,46 @@ "COUNTERS_LAG_NAME_MAP": { "PortChannel01": "oid:0x1000000000007" }, + "COUNTERS_RIF_NAME_MAP": { + "Ethernet0": "oid:0x6000000000015", + "PortChannel01": "oid:0x6000000000006", + "Vlan1000": "oid:0x60000000005d0" + }, + "COUNTERS_RIF_TYPE_MAP": { + "oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN" + }, + "COUNTERS:oid:0x6000000000006": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "116", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "226", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "12", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "212", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "336" + }, + "COUNTERS:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x60000000005d0": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, "COUNTERS:oid:0x1000000000004": { "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", diff --git a/tests/mock_tables/asic1/appl_db.json b/tests/mock_tables/asic1/appl_db.json index b1389f441..f8d7f0aa9 100644 --- a/tests/mock_tables/asic1/appl_db.json +++ b/tests/mock_tables/asic1/appl_db.json @@ -45,13 +45,17 @@ "speed": 1000, "alias": "etp6" }, + "PORT_TABLE:Ethernet16": { + "speed": 1000, + "alias": "etp16" + }, "PORT_TABLE:Ethernet-BP8": { "alias": "etp7" }, "PORT_TABLE:Ethernet-BP12": { "description": "snowflake", "alias": "etp8", - "speed": 1000 + "speed": 1000 }, "ROUTE_TABLE:0.0.0.0/0": { "ifname": "Ethernet8,Ethernet12", diff --git a/tests/mock_tables/asic1/asic_db.json b/tests/mock_tables/asic1/asic_db.json index 9da04af83..4650923fb 100644 --- a/tests/mock_tables/asic1/asic_db.json +++ b/tests/mock_tables/asic1/asic_db.json @@ -7,5 +7,19 @@ "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT", "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000005", "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000003" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000001abc": { + "SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "101", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000010", + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000001abd": { + "SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "102", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000010", + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT" } } diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 86289526d..7304ffe10 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -309,12 +309,27 @@ "Ethernet8": "oid:0x1000000000003", "Ethernet12": "oid:0x1000000000004", "Ethernet-BP8": "oid:0x1000000000005", - "Ethernet-BP12": "oid:0x1000000000006" + "Ethernet-BP12": "oid:0x1000000000006", + "Ethernet16": "oid:0x1000000000010" }, "COUNTERS_LAG_NAME_MAP": { "PortChannel02": "oid:0x1000000000007" }, - "COUNTERS:oid:0x1000000000004": { + "COUNTERS_RIF_TYPE_MAP": { + "oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000012": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x60000000005d1": "SAI_ROUTER_INTERFACE_TYPE_VLAN" + }, + "COUNTERS_RIF_NAME_MAP": { + "Ethernet8": "oid:0x6000000000015", + "PortChannel02": "oid:0x6000000000012", + "Vlan1001": "oid:0x60000000005d1", + "Ethernet16.101": "oid:0x6000000001abc", + "Ethernet16.102": "oid:0x6000000001abd" + }, + "COUNTERS:oid:0x1000000000010": { "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", "SAI_PORT_STAT_IF_OUT_ERRORS": "0", @@ -416,7 +431,37 @@ "SAI_PORT_STAT_PFC_7_RX_PKTS": "8", "SAI_PORT_STAT_PFC_7_TX_PKTS": "8" }, - "COUNTERS:oid:0x1000000000003": { + "COUNTERS:oid:0x6000000001abc": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "101" + }, + "COUNTERS:oid:0x6000000001abd": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "102" + }, + "COUNTERS:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x1000000000004": { "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", "SAI_PORT_STAT_IF_OUT_ERRORS": "0", @@ -502,6 +547,108 @@ "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:0x1000000000003": { + "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", + "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", + "SAI_PORT_STAT_IF_OUT_ERRORS": "100", + "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": "100", + "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": "100", + "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": "100", + "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": "100", + "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": "100", + "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": "209347219842134092490", "SAI_PORT_STAT_PFC_1_RX_PKTS": "2", "SAI_PORT_STAT_PFC_1_TX_PKTS": "2", diff --git a/tests/mock_tables/asic2/appl_db.json b/tests/mock_tables/asic2/appl_db.json index c1cb8b996..d082d2844 100644 --- a/tests/mock_tables/asic2/appl_db.json +++ b/tests/mock_tables/asic2/appl_db.json @@ -86,6 +86,11 @@ "oper_status": "up", "mtu": "9216" }, + "VLAN_TABLE:Vlan1000": { + "admin_status": "up", + "hostif_name": "", + "mtu": "9216" + }, "INTF_TABLE:lo:10.1.0.32/32": { "scope": "global", "family": "IPv4" diff --git a/tests/mock_tables/asic2/counters_db.json b/tests/mock_tables/asic2/counters_db.json index 6b8058da0..36b0ff839 100644 --- a/tests/mock_tables/asic2/counters_db.json +++ b/tests/mock_tables/asic2/counters_db.json @@ -315,6 +315,12 @@ "PortChannel03": "oid:0x1000000000007", "PortChannel04": "oid:0x1000000000008" }, + "COUNTERS_RIF_NAME_MAP": { + "PortChannel03": "oid:0x6000000000017" + }, + "COUNTERS_RIF_TYPE_MAP": { + "oid:0x6000000000017": "SAI_ROUTER_INTERFACE_TYPE_PORT" + }, "COUNTERS:oid:0x1000000000004": { "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", diff --git a/tests/mock_tables/asic_db.json b/tests/mock_tables/asic_db.json index 4050ca3e8..25fc46fda 100644 --- a/tests/mock_tables/asic_db.json +++ b/tests/mock_tables/asic_db.json @@ -26,6 +26,40 @@ "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x1000000000008", "SAI_BRIDGE_PORT_ATTR_ADMIN_STATE": "true" }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000015" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x60000000005d0": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_VLAN", + "SAI_ROUTER_INTERFACE_ATTR_VLAN_ID": "oid:0x26000000005d0" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000006": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000006" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000005": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000005" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000004": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000004" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000001abc": { + "SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "101", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000017", + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000001abd": { + "SAI_ROUTER_INTERFACE_ATTR_OUTER_VLAN_ID": "102", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x1000000000017", + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000003": { + "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000003" + }, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT:oid:0x3a000000000a21": { "SAI_BRIDGE_PORT_ATTR_TYPE": "SAI_BRIDGE_PORT_TYPE_PORT", "SAI_BRIDGE_PORT_ATTR_PORT_ID": "oid:0x2000000000a14", @@ -36,5 +70,17 @@ }, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN:oid:0x26000000000013": { "NULL": "NULL" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x2000000000006": { + "NULL": "NULL" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x2000000000005": { + "NULL": "NULL" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x2000000000004": { + "NULL": "NULL" + }, + "ASIC_STATE:SAI_OBJECT_TYPE_LAG:oid:0x2000000000003": { + "NULL": "NULL" } } diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json old mode 100644 new mode 100755 index 531fa4c15..6914ffa42 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -920,14 +920,14 @@ "COUNTERS:oid:0x1000000000006": { "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_IF_OUT_ERRORS": "100", "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_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", "SAI_PORT_STAT_IF_IN_DISCARDS": "0", @@ -959,7 +959,7 @@ "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_OUT_OCTETS": "100", "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", @@ -974,17 +974,17 @@ "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_IF_OUT_UCAST_PKTS": "100", "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_IF_IN_UCAST_PKTS": "100", "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_IF_IN_OCTETS": "100", "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", @@ -2278,9 +2278,215 @@ "Ethernet68": "oid:0x1000000000020" }, "COUNTERS_LAG_NAME_MAP": { - "PortChannel01": "oid:0x1000000000023", + "PortChannel01": "oid:0x2000000000006", + "PortChannel02": "oid:0x2000000000005", + "PortChannel03": "oid:0x2000000000004", + "PortChannel04": "oid:0x2000000000003", "PortChannel101": "oid:0x2000000000a14" }, + "COUNTERS_RIF_NAME_MAP": { + "Ethernet20": "oid:0x6000000000015", + "Ethernet8.101": "oid:0x6000000001abc", + "Ethernet8.102": "oid:0x6000000001abd", + "PortChannel01": "oid:0x6000000000006", + "PortChannel02": "oid:0x6000000000005", + "PortChannel03": "oid:0x6000000000004", + "PortChannel04": "oid:0x6000000000003", + "PortChannel101": "oid:0x6000000000002", + "Vlan1000": "oid:0x60000000005d0" + }, + "COUNTERS_RIF_TYPE_MAP": { + "oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN" + }, + "COUNTERS:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x60000000005d0": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x6000000000006": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "116", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "226", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "12", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "212", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "336" + }, + "COUNTERS:oid:0x6000000000005": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, + "COUNTERS:oid:0x6000000000004": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, + "COUNTERS:oid:0x6000000001abc": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "101" + }, + "COUNTERS:oid:0x6000000001abd": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "102" + }, + "COUNTERS:oid:0x6000000000003": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, + "COUNTERS_RIF_NAME_MAP": { + "Ethernet20": "oid:0x6000000000015", + "Ethernet8.101": "oid:0x6000000001abc", + "Ethernet8.102": "oid:0x6000000001abd", + "PortChannel01": "oid:0x6000000000006", + "PortChannel02": "oid:0x6000000000005", + "PortChannel03": "oid:0x6000000000004", + "PortChannel04": "oid:0x6000000000003", + "PortChannel101": "oid:0x6000000000002", + "Vlan1000": "oid:0x60000000005d0" + }, + "COUNTERS_RIF_TYPE_MAP": { + "oid:0x6000000000015": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000001abc": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x6000000001abd": "SAI_ROUTER_INTERFACE_TYPE_SUB_PORT", + "oid:0x6000000000006": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000005": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000004": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000003": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x6000000000002": "SAI_ROUTER_INTERFACE_TYPE_PORT", + "oid:0x60000000005d0": "SAI_ROUTER_INTERFACE_TYPE_VLAN" + }, + "COUNTERS:oid:0x6000000000015": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x60000000005d0": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "10", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "2048", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "1", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "55", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "20", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "4096", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "2", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "110" + }, + "COUNTERS:oid:0x6000000000006": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "116", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "226", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "12", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "212", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "6", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "336" + }, + "COUNTERS:oid:0x6000000000005": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, + "COUNTERS:oid:0x6000000000004": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, + "COUNTERS:oid:0x6000000001abc": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "101", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "101" + }, + "COUNTERS:oid:0x6000000001abd": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "102", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "102" + }, + "COUNTERS:oid:0x6000000000003": { + "SAI_ROUTER_INTERFACE_STAT_IN_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_IN_ERROR_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_OCTETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_PACKETS": "0", + "SAI_ROUTER_INTERFACE_STAT_OUT_ERROR_OCTETS": "0" + }, "COUNTERS:oid:0x1000000000009": { "SAI_PORT_STAT_ETHER_STATS_TX_NO_ERRORS": "0", "SAI_PORT_STAT_ETHER_STATS_OVERSIZE_PKTS": "0", @@ -2998,14 +3204,14 @@ "COUNTERS:oid:0x1000000000015": { "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_IF_OUT_ERRORS": "100", "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_IF_IN_ERRORS": "100", "SAI_PORT_STAT_ETHER_STATS_PKTS": "0", "SAI_PORT_STAT_ETHER_STATS_BROADCAST_PKTS": "0", "SAI_PORT_STAT_IF_IN_DISCARDS": "0", @@ -3037,7 +3243,7 @@ "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_OUT_OCTETS": "100", "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", @@ -3052,17 +3258,17 @@ "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_IF_OUT_UCAST_PKTS": "100", "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_IF_IN_UCAST_PKTS": "100", "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_IF_IN_OCTETS": "100", "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", diff --git a/tests/namespace/test_interfaces.py b/tests/namespace/test_interfaces.py index ea51339f8..944787f74 100644 --- a/tests/namespace/test_interfaces.py +++ b/tests/namespace/test_interfaces.py @@ -2,12 +2,16 @@ import sys import importlib -# noinspection PyUnresolvedReferences -import tests.mock_tables.dbconnector +# 3 directory levels above sonic-snmpagent/tests/namespace/test_interfaces.py = sonic-snmpagent +modules_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# Insert sonic-snmpagent and sonic-snmpagent/src to path +sys.path.insert(0, modules_path) sys.path.insert(0, os.path.join(modules_path, 'src')) +# noinspection PyUnresolvedReferences +import tests.mock_tables.dbconnector + from unittest import TestCase from ax_interface import ValueType @@ -16,10 +20,10 @@ from ax_interface.constants import PduTypes from ax_interface.pdu import PDU, PDUHeader from ax_interface.mib import MIBTable -from sonic_ax_impl.mibs.ietf import rfc1213 +from sonic_ax_impl.mibs.ietf import rfc1213, rfc2863 from sonic_ax_impl import mibs -class TestGetNextPDU(TestCase): +class TestGetNextPDU_1213(TestCase): @classmethod def setUpClass(cls): tests.mock_tables.dbconnector.load_namespace_config() @@ -237,7 +241,7 @@ def test_if_type_portchannel(self): self.assertEqual(value0.data, 161) def test_getnextpdu_first_bp_ifindex(self): - oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1,1004)) + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 8999)) get_pdu = GetNextPDU( header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), oids=[oid] @@ -367,6 +371,580 @@ def test_in_octets_override(self): self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1)))) self.assertEqual(value0.data, 54321) + def test_vlan_iface(self): + """ + Test that vlan interface is present in the MIB + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 2999)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 3000)))) + self.assertEqual(value0.data, 2999) + + def test_vlan_iface_description(self): + """ + Test vlan interface description (which is simply the name) + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + + def test_if_type_l3vlan(self): + """ + For l3vlan the type shpuld be 136 + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 2000)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 3000)))) + self.assertEqual(value0.data, 136) + + def test_in_octets_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 9)))) + self.assertEqual(value0.data, 100) + + def test_in_ucast_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 9)))) + self.assertEqual(value0.data, 100) + + def test_in_errors_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)))) + self.assertEqual(value0.data, 101) + + def test_out_octets_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 9)))) + self.assertEqual(value0.data, 100) + + def test_out_ucast_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 9)))) + self.assertEqual(value0.data, 100) + + def test_out_errors_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)))) + self.assertEqual(value0.data, 102) + + def test_in_octets_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 3000)))) + self.assertEqual(value0.data, 2048) + + def test_in_ucast_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)))) + self.assertEqual(value0.data, 10) + + def test_in_errors_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)))) + self.assertEqual(value0.data, 1) + + def test_out_octets_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 3000)))) + self.assertEqual(value0.data, 4096) + + def test_out_ucast_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)))) + self.assertEqual(value0.data, 20) + + def test_out_errors_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)))) + self.assertEqual(value0.data, 2) + + def test_in_octets_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 17)))) + self.assertEqual(value0.data, 0) + + def test_in_ucast_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 17)))) + self.assertEqual(value0.data, 0) + + def test_in_errors_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 17)))) + self.assertEqual(value0.data, 203) + + def test_out_octets_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 17)))) + self.assertEqual(value0.data, 0) + + def test_out_ucast_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 17)))) + self.assertEqual(value0.data, 0) + + def test_out_errors_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 17)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 17)))) + self.assertEqual(value0.data, 203) + + def test_in_octets_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1001)))) + self.assertEqual(value0.data, 100) + + def test_in_ucast_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1001)))) + self.assertEqual(value0.data, 100) + + def test_in_errors_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)))) + self.assertEqual(value0.data, 106) + + def test_out_octets_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 1001)))) + self.assertEqual(value0.data, 100) + + def test_out_ucast_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 1001)))) + self.assertEqual(value0.data, 100) + + def test_out_errors_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)))) + self.assertEqual(value0.data, 106) + +class TestGetNextPDU_2863(TestCase): @classmethod - def tearDownClass(cls): - tests.mock_tables.dbconnector.clean_up_config() + def setUpClass(cls): + tests.mock_tables.dbconnector.load_namespace_config() + importlib.reload(rfc2863) + cls.lut = MIBTable(rfc2863.InterfaceMIBObjects) + for updater in cls.lut.updater_instances: + updater.update_data() + updater.reinit_data() + updater.update_data() + + def test_mgmt_iface_ifMIB(self): + """ + Test that mgmt port is present in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10000)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)))) + self.assertEqual(str(value0.data), 'snowflake') + + def test_mgmt_iface_description_ifMIB(self): + """ + Test mgmt port description (which is simply an alias) in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)))) + self.assertEqual(str(value0.data), 'snowflake') + + def test_vlan_iface_ifMIB(self): + """ + Test that vlan interface is present in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 2999)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + + def test_vlan_iface_description_ifMIB(self): + """ + Test vlan interface description (which is simply the name) in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + + diff --git a/tests/namespace/test_mibs.py b/tests/namespace/test_mibs.py index 109b0796d..5a04166fc 100644 --- a/tests/namespace/test_mibs.py +++ b/tests/namespace/test_mibs.py @@ -21,7 +21,9 @@ def test_init_namespace_sync_d_lag_tables(self): lag_name_if_name_map, \ if_name_lag_name_map, \ - oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, dbs) + oid_lag_name_map, \ + lag_sai_map, \ + sai_lag_map = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, dbs) #PortChannel in asic0 Namespace self.assertTrue("PortChannel01" in lag_name_if_name_map) self.assertTrue("Ethernet-BP0" in lag_name_if_name_map["PortChannel01"]) diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py old mode 100644 new mode 100755 index ae4ee53c4..e7b615bb3 --- a/tests/test_interfaces.py +++ b/tests/test_interfaces.py @@ -2,12 +2,12 @@ import sys import importlib -# noinspection PyUnresolvedReferences -import tests.mock_tables.dbconnector - modules_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.join(modules_path, 'src')) +# noinspection PyUnresolvedReferences +import tests.mock_tables.dbconnector + from unittest import TestCase from ax_interface import ValueType @@ -16,7 +16,7 @@ from ax_interface.constants import PduTypes from ax_interface.pdu import PDU, PDUHeader from ax_interface.mib import MIBTable -from sonic_ax_impl.mibs.ietf import rfc1213 +from sonic_ax_impl.mibs.ietf import rfc1213, rfc2863 class TestGetNextPDU(TestCase): @classmethod @@ -365,3 +365,580 @@ def test_in_octets_override(self): self.assertEqual(value0.type_, ValueType.COUNTER_32) self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1)))) self.assertEqual(value0.data, 54321) + + def test_vlan_iface(self): + """ + Test that vlan interface is present in the MIB + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 2999)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 1, 3000)))) + self.assertEqual(value0.data, 2999) + + def test_vlan_iface_description(self): + """ + Test vlan interface description (which is simply the name) + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + + def test_if_type_l3vlan(self): + """ + For l3vlan the type shpuld be 136 + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 2000)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.INTEGER) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 3, 3000)))) + self.assertEqual(value0.data, 136) + + def test_in_octets_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 21)))) + self.assertEqual(value0.data, 100) + + def test_in_ucast_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 21)))) + self.assertEqual(value0.data, 100) + + def test_in_errors_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 21)))) + self.assertEqual(value0.data, 101) + + def test_out_octets_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 21)))) + self.assertEqual(value0.data, 100) + + def test_out_ucast_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 21)))) + self.assertEqual(value0.data, 100) + + def test_out_errors_rif(self): + """ + For a port with RIF the counter values are aggregated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 21)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 21)))) + self.assertEqual(value0.data, 102) + + def test_in_octets_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 3000)))) + self.assertEqual(value0.data, 2048) + + def test_in_ucast_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 3000)))) + self.assertEqual(value0.data, 10) + + def test_in_errors_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 3000)))) + self.assertEqual(value0.data, 1) + + def test_out_octets_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 3000)))) + self.assertEqual(value0.data, 4096) + + def test_out_ucast_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 3000)))) + self.assertEqual(value0.data, 20) + + def test_out_errors_vlan(self): + """ + For a l3 Vlan values are mapped from RIF stats + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 3000)))) + self.assertEqual(value0.data, 2) + + def test_in_octets_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 9)))) + self.assertEqual(value0.data, 0) + + def test_in_ucast_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 9)))) + self.assertEqual(value0.data, 0) + + def test_in_errors_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 9)))) + self.assertEqual(value0.data, 203) + + def test_out_octets_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 9)))) + self.assertEqual(value0.data, 0) + + def test_out_ucast_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 9)))) + self.assertEqual(value0.data, 0) + + def test_out_errors_vlan_subinterface(self): + """ + For a port with multiple vlan subinterfaces (RIF) all RIF drops are accumulated + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 9)))) + self.assertEqual(value0.data, 203) + + def test_in_octets_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 10, 1001)))) + self.assertEqual(value0.data, 100) + + def test_in_ucast_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 11, 1001)))) + self.assertEqual(value0.data, 100) + + def test_in_errors_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 14, 1001)))) + self.assertEqual(value0.data, 106) + + def test_out_octets_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 16, 1001)))) + self.assertEqual(value0.data, 100) + + def test_out_ucast_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 17, 1001)))) + self.assertEqual(value0.data, 100) + + def test_out_errors_portchannel(self): + """ + For a l3 portchannel interface value is accumulated on members plus added Rif counters + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.COUNTER_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 2, 2, 1, 20, 1001)))) + self.assertEqual(value0.data, 106) + +class TestGetNextPDU_2863(TestCase): + @classmethod + def setUpClass(cls): + tests.mock_tables.dbconnector.load_namespace_config() + importlib.reload(rfc2863) + cls.lut = MIBTable(rfc2863.InterfaceMIBObjects) + for updater in cls.lut.updater_instances: + updater.update_data() + updater.reinit_data() + updater.update_data() + + def test_mgmt_iface_ifMIB(self): + """ + Test that mgmt port is present in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10000)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)))) + self.assertEqual(str(value0.data), 'snowflake') + + def test_mgmt_iface_description_ifMIB(self): + """ + Test mgmt port description (which is simply an alias) in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001)))) + self.assertEqual(str(value0.data), 'snowflake') + + def test_vlan_iface_ifMIB(self): + """ + Test that vlan interface is present in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 2999)) + get_pdu = GetNextPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + + def test_vlan_iface_description_ifMIB(self): + """ + Test vlan interface description (which is simply the name) in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)) + get_pdu = GetPDU( + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), + oids=[oid] + ) + + encoded = get_pdu.encode() + response = get_pdu.make_response(self.lut) + print(response) + + value0 = response.values[0] + self.assertEqual(value0.type_, ValueType.OCTET_STRING) + self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 3000)))) + self.assertEqual(str(value0.data), 'Vlan1000') + diff --git a/tests/test_mibs.py b/tests/test_mibs.py index 87a5f3e86..f8389d656 100644 --- a/tests/test_mibs.py +++ b/tests/test_mibs.py @@ -14,14 +14,15 @@ class TestGetNextPDU(TestCase): @classmethod def setUpClass(cls): #For single namespace scenario, load database_config.json - tests.mock_tables.dbconnector.load_database_config() + tests.mock_tables.dbconnector.load_database_config() def test_init_sync_d_lag_tables(self): db_conn = Namespace.init_namespace_dbs() lag_name_if_name_map, \ if_name_lag_name_map, \ - oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, db_conn) + oid_lag_name_map, \ + lag_sai_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, db_conn) self.assertTrue("PortChannel04" in lag_name_if_name_map) self.assertTrue(lag_name_if_name_map["PortChannel04"] == ["Ethernet124"]) @@ -30,3 +31,4 @@ def test_init_sync_d_lag_tables(self): self.assertTrue("PortChannel_Temp" in lag_name_if_name_map) self.assertTrue(lag_name_if_name_map["PortChannel_Temp"] == []) + self.assertTrue(lag_sai_map["PortChannel01"] == "2000000000006")