Skip to content

Commit c31af3a

Browse files
author
rsh2prasad
committed
Adding snmp changes to pick up correct mgmt speed
1 parent 13b975b commit c31af3a

File tree

6 files changed

+142
-7
lines changed

6 files changed

+142
-7
lines changed

src/sonic_ax_impl/mibs/ietf/rfc2863.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,24 @@ def interface_name(self, sub_id):
201201

202202
return result
203203

204+
def _get_if_entry_state_db(self, oid):
205+
"""
206+
:param oid: The 1-based sub-identifier query.
207+
:return: the DB entry for the respective sub_id.
208+
"""
209+
if not oid:
210+
return
211+
212+
if_table = ""
213+
db = mibs.STATE_DB
214+
if oid in self.mgmt_oid_name_map:
215+
mgmt_if_name = self.mgmt_oid_name_map[oid]
216+
if_table = mibs.mgmt_if_entry_table_state_db(mgmt_if_name)
217+
else:
218+
return None
219+
220+
return Namespace.dbs_get_all(self.db_conn, db, if_table, blocking=False)
221+
204222
def interface_alias(self, sub_id):
205223
"""
206224
ifAlias specific - this is not the "Alias map".
@@ -308,13 +326,16 @@ def get_high_speed(self, sub_id):
308326
entry = self._get_if_entry(mibs.get_index_from_str(lag_member))
309327
if entry:
310328
speed += int(entry.get("speed", 0))
311-
return speed
312329

313-
entry = self._get_if_entry(oid)
330+
if oid in self.mgmt_oid_name_map:
331+
entry = self._get_if_entry_state_db(oid)
332+
else:
333+
entry = self._get_if_entry(oid)
334+
314335
if not entry:
315336
return
316337

317-
return int(entry.get("speed", 40000))
338+
return int(entry.get("speed", 40000))
318339

319340

320341
class InterfaceMIBObjects(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.31.1'):

tests/mock_tables/asic0/state_db.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@
4242
},
4343
"BUFFER_MAX_PARAM_TABLE|Ethernet24": {
4444
"max_queues": "16"
45+
},
46+
"MGMT_PORT_TABLE:Ethernet0": {
47+
"description": "snowflake",
48+
"alias": "etp1",
49+
"role": "Ext",
50+
"speed": 100000
51+
},
52+
"MGMT_PORT_TABLE:Ethernet4": {
53+
"description": "snowflake",
54+
"alias": "etp2",
55+
"role": "Ext",
56+
"speed": 100000
4557
}
4658
}

tests/mock_tables/asic1/state_db.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,16 @@
3939
},
4040
"BUFFER_MAX_PARAM_TABLE|Ethernet32": {
4141
"max_queues": "16"
42+
},
43+
"MGMT_PORT_TABLE:Ethernet8": {
44+
"description": "snowflake",
45+
"alias": "etp5",
46+
"role": "Ext",
47+
"speed": 100000
48+
},
49+
"MGMT_PORT_TABLE:Ethernet12": {
50+
"speed": 1000,
51+
"role": "Ext",
52+
"alias": "etp6"
4253
}
4354
}

tests/mock_tables/global_db/state_db.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,22 @@
6565
"tx4power": -5.4
6666
},
6767
"MGMT_PORT_TABLE|eth0": {
68-
"oper_status": "down"
68+
"description": "snowflake",
69+
"oper_status": "down",
70+
"speed": 1000
6971
},
7072
"MGMT_PORT_TABLE|eth1": {
71-
"oper_status": "up"
73+
"description": "snowflake",
74+
"admin_status": "up",
75+
"oper_status": "up",
76+
"alias": "mgmt1",
77+
"speed": 1000
78+
},
79+
"MGMT_PORT_TABLE|eth2": {
80+
"description": "NotExistInStateDB",
81+
"admin_status": "up",
82+
"alias": "mgmt2",
83+
"speed": 1000
7284
},
7385
"PHYSICAL_ENTITY_INFO|PSU 1": {
7486
"position_in_parent": 1,

tests/mock_tables/state_db.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@
8989
"tx4power": "N/A"
9090
},
9191
"MGMT_PORT_TABLE|eth0": {
92-
"oper_status": "down"
92+
"description": "snowflake",
93+
"speed": 1000
9394
},
9495
"MGMT_PORT_TABLE|eth1": {
95-
"oper_status": "up"
96+
"description": "snowflake",
97+
"oper_status": "up",
98+
"admin_status": "up",
99+
"alias": "mgmt1",
100+
"speed": 2000
96101
},
97102
"PHYSICAL_ENTITY_INFO|PSU 1": {
98103
"position_in_parent": 1,

tests/test_hc_interfaces.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,77 @@ def test_in_octets_override(self):
279279
self.assertEqual(value0.type_, ValueType.COUNTER_64)
280280
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 6, 5))))
281281
self.assertEqual(value0.data, 654321)
282+
283+
def test_mgmt_iface_ifMIB(self):
284+
"""
285+
Test that mgmt port is present in the ifMIB OID path of the MIB
286+
"""
287+
oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10000))
288+
get_pdu = GetNextPDU(
289+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
290+
oids=[oid]
291+
)
292+
293+
encoded = get_pdu.encode()
294+
response = get_pdu.make_response(self.lut)
295+
print(response)
296+
297+
value0 = response.values[0]
298+
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
299+
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 10001))))
300+
self.assertEqual(str(value0.data), "snowflake")
301+
302+
def test_mgmt_iface_speed_eth2(self):
303+
"""
304+
Test that mgmt port speed is 1000
305+
"""
306+
oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001))
307+
get_pdu = GetPDU(
308+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
309+
oids=[oid]
310+
)
311+
312+
encoded = get_pdu.encode()
313+
response = get_pdu.make_response(self.lut)
314+
print(response)
315+
316+
value0 = response.values[0]
317+
self.assertEqual(value0.type_, ValueType.GAUGE_32)
318+
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001))))
319+
self.assertEqual(value0.data, 2000)
320+
321+
def test_mgmt_iface_speed_getnext_eth0(self):
322+
"""
323+
Test that mgmt port speed is 1000
324+
"""
325+
oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10000))
326+
get_pdu = GetNextPDU(
327+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
328+
oids=[oid]
329+
)
330+
331+
encoded = get_pdu.encode()
332+
response = get_pdu.make_response(self.lut)
333+
print(response)
334+
335+
value0 = response.values[0]
336+
self.assertEqual(value0.type_, ValueType.GAUGE_32)
337+
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001))))
338+
self.assertEqual(value0.data, 2000)
339+
340+
def test_mgmt_iface_speed_getnext_eth1(self):
341+
"""
342+
Test that mgmt port speed is 1000
343+
"""
344+
oid = ObjectIdentifier(11, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 15, 10001))
345+
get_pdu = GetNextPDU(
346+
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
347+
oids=[oid]
348+
)
349+
350+
encoded = get_pdu.encode()
351+
response = get_pdu.make_response(self.lut)
352+
print(response)
353+
354+
value0 = response.values[0]
355+
self.assertEqual(value0.type_, ValueType.END_OF_MIB_VIEW)

0 commit comments

Comments
 (0)