Skip to content

Commit ae99de0

Browse files
stepanblyschakqiluo-msft
authored andcommitted
Extend RFC 2737 MIB and implement RFC 3433 (#69)
* Extend RFC 2737 MIB and implement RFC 3433 * [rfc2737 & rfc3433] Update transceiver data only when there is a change, comments handling * Add TX Power sensor to Sensor MIB * [comments] Fix typo
1 parent 573dd92 commit ae99de0

File tree

8 files changed

+1214
-62
lines changed

8 files changed

+1214
-62
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
MIB implementations included:
66

77
* [RFC 1213](https://www.ietf.org/rfc/rfc1213.txt) MIB-II
8+
* [RFC 2737](https://www.ietf.org/rfc/rfc2737.txt) Physical Table MIB
89
* [RFC 2863](https://www.ietf.org/rfc/rfc2863.txt) Interfaces MIB
10+
* [RFC 3433](https://www.ietf.org/rfc/rfc3433.txt) Sensor Table MIB
911
* [RFC 4292](https://tools.ietf.org/html/rfc4292) ipCidrRouteDest table in IP Forwarding Table MIB
1012
* [RFC 4363](https://tools.ietf.org/html/rfc4363) dot1qTpFdbPort in Q-BRIDGE-MIB
1113
* [IEEE 802.1 AB](http://www.ieee802.org/1/files/public/MIBs/LLDP-MIB-200505060000Z.txt) LLDP-MIB

src/sonic_ax_impl/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import ax_interface
1212
from sonic_ax_impl.mibs import ieee802_1ab
1313
from . import logger
14-
from .mibs.ietf import rfc1213, rfc2737, rfc2863, rfc4292, rfc4363
14+
from .mibs.ietf import rfc1213, rfc2737, rfc2863, rfc3433, rfc4292, rfc4363
1515
from .mibs.vendor import dell, cisco
1616

1717
# Background task update frequency ( in seconds )
@@ -25,6 +25,7 @@ class SonicMIB(
2525
rfc1213.InterfacesMIB,
2626
rfc1213.IpMib,
2727
rfc2737.PhysicalTableMIB,
28+
rfc3433.PhysicalSensorTableMIB,
2829
rfc2863.InterfaceMIBObjects,
2930
rfc4363.QBridgeMIBObjects,
3031
rfc4292.IpCidrRouteTable,

src/sonic_ax_impl/mibs/__init__.py

+85
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@
1515
ASIC_DB = 'ASIC_DB'
1616
COUNTERS_DB = 'COUNTERS_DB'
1717

18+
TABLE_NAME_SEPARATOR_COLON = ':'
19+
TABLE_NAME_SEPARATOR_VBAR = '|'
20+
21+
# This is used in both rfc2737 and rfc3433
22+
SENSOR_PART_ID_MAP = {
23+
"temperature": 1,
24+
"voltage": 2,
25+
"rx1power": 11,
26+
"rx2power": 21,
27+
"rx3power": 31,
28+
"rx4power": 41,
29+
"tx1bias": 12,
30+
"tx2bias": 22,
31+
"tx3bias": 32,
32+
"tx4bias": 42,
33+
"tx1power": 13,
34+
"tx2power": 23,
35+
"tx3power": 33,
36+
"tx4power": 43,
37+
}
38+
39+
# IfIndex to OID multiplier for transceiver
40+
IFINDEX_SUB_ID_MULTIPLIER = 1000
41+
1842
redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'}
1943

2044
def counter_table(sai_id):
@@ -34,6 +58,21 @@ def queue_table(sai_id):
3458
def queue_key(port_index, queue_index):
3559
return str(port_index) + ':' + str(queue_index)
3660

61+
def transceiver_info_table(port_name):
62+
"""
63+
:param: port_name: port name
64+
:return: transceiver info entry for this port
65+
"""
66+
67+
return "TRANSCEIVER_INFO" + TABLE_NAME_SEPARATOR_VBAR + port_name
68+
69+
def transceiver_dom_table(port_name):
70+
"""
71+
:param: port_name: port name
72+
:return: transceiver dom entry for this port
73+
"""
74+
75+
return "TRANSCEIVER_DOM_SENSOR" + TABLE_NAME_SEPARATOR_VBAR + port_name
3776

3877
def lldp_entry_table(if_name):
3978
"""
@@ -225,3 +264,49 @@ def init_sync_d_queue_tables(db_conn):
225264

226265
return port_queues_map, queue_stat_map, port_queue_list_map
227266

267+
def get_device_metadata(db_conn):
268+
"""
269+
:param db_conn: Sonic DB connector
270+
:return: device metadata
271+
"""
272+
273+
DEVICE_METADATA = "DEVICE_METADATA|localhost"
274+
db_conn.connect(db_conn.STATE_DB)
275+
276+
device_metadata = db_conn.get_all(db_conn.STATE_DB, DEVICE_METADATA)
277+
return device_metadata
278+
279+
def get_transceiver_sub_id(ifindex):
280+
"""
281+
Returns sub OID for transceiver. Sub OID is calculated as folows:
282+
+------------+------------+
283+
|Interface |Index |
284+
+------------+------------+
285+
|Ethernet[X] |X * 1000 |
286+
+------------+------------+
287+
()
288+
:param ifindex: interface index
289+
:return: sub OID of a port calculated as sub OID = {{index}} * 1000
290+
"""
291+
292+
return (ifindex * IFINDEX_SUB_ID_MULTIPLIER, )
293+
294+
def get_transceiver_sensor_sub_id(ifindex, sensor):
295+
"""
296+
Returns sub OID for transceiver sensor. Sub OID is calculated as folows:
297+
+-------------------------------------+------------------------------+
298+
|Sensor |Index |
299+
+-------------------------------------+------------------------------+
300+
|RX Power for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 1 |
301+
|TX Bias for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 2 |
302+
|Temperature for Ethernet[X] |X * 1000 + 1 |
303+
|Voltage for Ethernet[X]/[LANEID] |X * 1000 + 2 |
304+
+-------------------------------------+------------------------------+
305+
()
306+
:param ifindex: interface index
307+
:param sensor: sensor key
308+
:return: sub OID = {{index}} * 1000 + {{lane}} * 10 + sensor id
309+
"""
310+
311+
transceiver_oid, = get_transceiver_sub_id(ifindex)
312+
return (transceiver_oid + SENSOR_PART_ID_MAP[sensor], )

0 commit comments

Comments
 (0)