Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -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'):
Expand Down
12 changes: 12 additions & 0 deletions tests/mock_tables/asic0/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 11 additions & 0 deletions tests/mock_tables/asic1/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
16 changes: 14 additions & 2 deletions tests/mock_tables/global_db/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
74 changes: 74 additions & 0 deletions tests/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading