diff --git a/src/sonic_ax_impl/mibs/ietf/rfc2863.py b/src/sonic_ax_impl/mibs/ietf/rfc2863.py index 4074cdc61..9e39b0c6d 100644 --- a/src/sonic_ax_impl/mibs/ietf/rfc2863.py +++ b/src/sonic_ax_impl/mibs/ietf/rfc2863.py @@ -201,6 +201,24 @@ def interface_name(self, sub_id): return result + def _get_if_entry_state_db(self, oid): + """ + :param oid: The 1-based sub-identifier query. + :return: the DB entry for the respective sub_id. + """ + if not oid: + return + + if_table = "" + db = mibs.STATE_DB + if oid in self.mgmt_oid_name_map: + mgmt_if_name = self.mgmt_oid_name_map[oid] + if_table = mibs.mgmt_if_entry_table_state_db(mgmt_if_name) + else: + return None + + return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=False) + def interface_alias(self, sub_id): """ ifAlias specific - this is not the "Alias map". @@ -310,11 +328,15 @@ def get_high_speed(self, sub_id): speed += int(entry.get("speed", 0)) return speed - entry = self._get_if_entry(oid) + if oid in self.mgmt_oid_name_map: + entry = self._get_if_entry_state_db(oid) + else: + entry = self._get_if_entry(oid) + if not entry: return - return int(entry.get("speed", 40000)) + return int(entry.get("speed", 40000)) class InterfaceMIBObjects(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.31.1'): diff --git a/tests/mock_tables/asic0/state_db.json b/tests/mock_tables/asic0/state_db.json index 5c281f9f4..cd89effd9 100644 --- a/tests/mock_tables/asic0/state_db.json +++ b/tests/mock_tables/asic0/state_db.json @@ -42,5 +42,17 @@ }, "BUFFER_MAX_PARAM_TABLE|Ethernet24": { "max_queues": "16" + }, + "MGMT_PORT_TABLE:Ethernet0": { + "description": "snowflake", + "alias": "etp1", + "role": "Ext", + "speed": 100000 + }, + "MGMT_PORT_TABLE:Ethernet4": { + "description": "snowflake", + "alias": "etp2", + "role": "Ext", + "speed": 100000 } } diff --git a/tests/mock_tables/asic1/state_db.json b/tests/mock_tables/asic1/state_db.json index 026d90b49..0a928cbf3 100644 --- a/tests/mock_tables/asic1/state_db.json +++ b/tests/mock_tables/asic1/state_db.json @@ -39,5 +39,16 @@ }, "BUFFER_MAX_PARAM_TABLE|Ethernet32": { "max_queues": "16" + }, + "MGMT_PORT_TABLE:Ethernet8": { + "description": "snowflake", + "alias": "etp5", + "role": "Ext", + "speed": 100000 + }, + "MGMT_PORT_TABLE:Ethernet12": { + "speed": 1000, + "role": "Ext", + "alias": "etp6" } } diff --git a/tests/mock_tables/global_db/state_db.json b/tests/mock_tables/global_db/state_db.json index 0674d83ab..d79da90f2 100644 --- a/tests/mock_tables/global_db/state_db.json +++ b/tests/mock_tables/global_db/state_db.json @@ -65,10 +65,22 @@ "tx4power": -5.4 }, "MGMT_PORT_TABLE|eth0": { - "oper_status": "down" + "description": "snowflake", + "oper_status": "down", + "speed": 1000 }, "MGMT_PORT_TABLE|eth1": { - "oper_status": "up" + "description": "snowflake", + "admin_status": "up", + "oper_status": "up", + "alias": "mgmt1", + "speed": 1000 + }, + "MGMT_PORT_TABLE|eth2": { + "description": "NotExistInStateDB", + "admin_status": "up", + "alias": "mgmt2", + "speed": 1000 }, "PHYSICAL_ENTITY_INFO|PSU 1": { "position_in_parent": 1, diff --git a/tests/mock_tables/state_db.json b/tests/mock_tables/state_db.json index 7de231f3d..e2098077e 100644 --- a/tests/mock_tables/state_db.json +++ b/tests/mock_tables/state_db.json @@ -89,10 +89,15 @@ "tx4power": "N/A" }, "MGMT_PORT_TABLE|eth0": { - "oper_status": "down" + "description": "snowflake", + "speed": 1000 }, "MGMT_PORT_TABLE|eth1": { - "oper_status": "up" + "description": "snowflake", + "oper_status": "up", + "admin_status": "up", + "alias": "mgmt1", + "speed": 2000 }, "PHYSICAL_ENTITY_INFO|PSU 1": { "position_in_parent": 1, diff --git a/tests/test_hc_interfaces.py b/tests/test_hc_interfaces.py index ea5638c3a..e558aa2d9 100644 --- a/tests/test_hc_interfaces.py +++ b/tests/test_hc_interfaces.py @@ -279,3 +279,77 @@ def test_in_octets_override(self): self.assertEqual(value0.type_, ValueType.COUNTER_64) self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 6, 5)))) self.assertEqual(value0.data, 654321) + + def test_mgmt_iface_ifMIB(self): + """ + Test that mgmt port is present in the ifMIB OID path of the MIB + """ + oid = ObjectIdentifier(11, 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(11, 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_speed_eth2(self): + """ + Test that mgmt port speed is 1000 + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 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.GAUGE_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001)))) + self.assertEqual(value0.data, 2000) + + def test_mgmt_iface_speed_getnext_eth0(self): + """ + Test that mgmt port speed is 1000 + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 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.GAUGE_32) + self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001)))) + self.assertEqual(value0.data, 2000) + + def test_mgmt_iface_speed_getnext_eth1(self): + """ + Test that mgmt port speed is 1000 + """ + oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001)) + 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.END_OF_MIB_VIEW)