Skip to content

Commit b8f19ee

Browse files
[sonic-snmpagent] SONiC physical entity mib extension (#168)
Implement all mib objects defined in EntPhysicalEntry of RFC 2737. **- How I did it** Refactor rfc2737.py to have different mib updater for different physical entity: XcvrCacheUpdater, FanCacheUpdater, FanDrawerCacheUpdater, PsuCacheUpdater, ThermalCacheUpdater. **- How to verify it** Manual test on MSN2410
1 parent 6b94ec3 commit b8f19ee

File tree

8 files changed

+1311
-260
lines changed

8 files changed

+1311
-260
lines changed

src/sonic_ax_impl/mibs/__init__.py

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,6 @@
2525
TABLE_NAME_SEPARATOR_COLON = ':'
2626
TABLE_NAME_SEPARATOR_VBAR = '|'
2727

28-
# This is used in both rfc2737 and rfc3433
29-
SENSOR_PART_ID_MAP = {
30-
"temperature": 1,
31-
"voltage": 2,
32-
"rx1power": 11,
33-
"rx2power": 21,
34-
"rx3power": 31,
35-
"rx4power": 41,
36-
"tx1bias": 12,
37-
"tx2bias": 22,
38-
"tx3bias": 32,
39-
"tx4bias": 42,
40-
"tx1power": 13,
41-
"tx2power": 23,
42-
"tx3power": 33,
43-
"tx4power": 43,
44-
}
45-
46-
# IfIndex to OID multiplier for transceiver
47-
IFINDEX_SUB_ID_MULTIPLIER = 1000
48-
4928
redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'}
5029

5130

@@ -65,6 +44,22 @@ def chassis_info_table(chassis_name):
6544

6645
return "CHASSIS_INFO" + TABLE_NAME_SEPARATOR_VBAR + chassis_name
6746

47+
def fan_info_table(fan_name):
48+
"""
49+
:param: fan_name: fan name
50+
:return: fan info entry for this fan
51+
"""
52+
return 'FAN_INFO' + TABLE_NAME_SEPARATOR_VBAR + fan_name
53+
54+
55+
def fan_drawer_info_table(drawer_name):
56+
"""
57+
:param: drawer_name: fan drawer name
58+
:return: fan drawer info entry for this fan
59+
"""
60+
return 'FAN_DRAWER_INFO' + TABLE_NAME_SEPARATOR_VBAR + drawer_name
61+
62+
6863
def psu_info_table(psu_name):
6964
"""
7065
:param: psu_name: psu name
@@ -73,6 +68,15 @@ def psu_info_table(psu_name):
7368

7469
return "PSU_INFO" + TABLE_NAME_SEPARATOR_VBAR + psu_name
7570

71+
72+
def physical_entity_info_table(name):
73+
"""
74+
:param: name: object name
75+
:return: entity info entry for this object
76+
"""
77+
return 'PHYSICAL_ENTITY_INFO' + TABLE_NAME_SEPARATOR_VBAR + name
78+
79+
7680
def counter_table(sai_id):
7781
"""
7882
:param if_name: given sai_id to cast.
@@ -106,6 +110,14 @@ def transceiver_dom_table(port_name):
106110

107111
return "TRANSCEIVER_DOM_SENSOR" + TABLE_NAME_SEPARATOR_VBAR + port_name
108112

113+
def thermal_info_table(thermal_name):
114+
"""
115+
:param: port_name: port name
116+
:return: transceiver dom entry for this port
117+
"""
118+
119+
return "TEMPERATURE_INFO" + TABLE_NAME_SEPARATOR_VBAR + thermal_name
120+
109121
def lldp_entry_table(if_name):
110122
"""
111123
:param if_name: given interface to cast.
@@ -386,40 +398,6 @@ def get_device_metadata(db_conn):
386398
device_metadata = db_conn.get_all(db_conn.STATE_DB, DEVICE_METADATA)
387399
return device_metadata
388400

389-
def get_transceiver_sub_id(ifindex):
390-
"""
391-
Returns sub OID for transceiver. Sub OID is calculated as folows:
392-
+------------+------------+
393-
|Interface |Index |
394-
+------------+------------+
395-
|Ethernet[X] |X * 1000 |
396-
+------------+------------+
397-
()
398-
:param ifindex: interface index
399-
:return: sub OID of a port calculated as sub OID = {{index}} * 1000
400-
"""
401-
402-
return (ifindex * IFINDEX_SUB_ID_MULTIPLIER, )
403-
404-
def get_transceiver_sensor_sub_id(ifindex, sensor):
405-
"""
406-
Returns sub OID for transceiver sensor. Sub OID is calculated as folows:
407-
+-------------------------------------+------------------------------+
408-
|Sensor |Index |
409-
+-------------------------------------+------------------------------+
410-
|RX Power for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 1 |
411-
|TX Bias for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 2 |
412-
|Temperature for Ethernet[X] |X * 1000 + 1 |
413-
|Voltage for Ethernet[X]/[LANEID] |X * 1000 + 2 |
414-
+-------------------------------------+------------------------------+
415-
()
416-
:param ifindex: interface index
417-
:param sensor: sensor key
418-
:return: sub OID = {{index}} * 1000 + {{lane}} * 10 + sensor id
419-
"""
420-
421-
transceiver_oid, = get_transceiver_sub_id(ifindex)
422-
return (transceiver_oid + SENSOR_PART_ID_MAP[sensor], )
423401

424402
def get_redis_pubsub(db_conn, db_name, pattern):
425403
redis_client = db_conn.get_redis_client(db_name)
@@ -428,6 +406,7 @@ def get_redis_pubsub(db_conn, db_name, pattern):
428406
pubsub.psubscribe("__keyspace@{}__:{}".format(db, pattern))
429407
return pubsub
430408

409+
431410
class RedisOidTreeUpdater(MIBUpdater):
432411
def __init__(self, prefix_str):
433412
super().__init__()
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
"""
2+
For non-port entity, the rule to generate entPhysicalIndex describes below:
3+
The entPhysicalIndex is divided into 3 layers:
4+
1. Module layer which includes modules located on system (e.g. fan drawer, PSU)
5+
2. Device layer which includes system devices (e.g. fan )
6+
3. Sensor layer which includes system sensors (e.g. temperature sensor, fan sensor)
7+
The entPhysicalIndex is a 9 digits number, and each digit describes below:
8+
Digit 1: Module Type
9+
Digit 2~3: Module Index
10+
Digit 4~5: Device Type
11+
Digit 6~7: Device Index
12+
Digit 8: Sensor Type
13+
Digit 9: Sensor Index
14+
15+
Module Type describes below:
16+
2 - Management
17+
5 - Fan Drawer
18+
6 - PSU
19+
Device Type describes below:
20+
01 - PS
21+
02 - Fan
22+
24 - Power Monitor (temperature, power, current, voltage...)
23+
99 - Chassis Thermals
24+
Sensor Type describes below:
25+
1 - Temperature
26+
2 - Fan Tachometers
27+
3 - Power
28+
4 - Current
29+
5 - Voltage
30+
31+
e.g. 501000000 means the first fan drawer, 502020100 means the first fan of the second fan drawer
32+
33+
As we are using ifindex to generate port entPhysicalIndex and ifindex might be a valur larger
34+
than 99, we uses a different way to generate port entPhysicalIndex.
35+
36+
For port entity, the entPhysicalIndex is a 10 digits number, and each digit describes below:
37+
Digit 1: 1
38+
Digit 2~8: ifindex
39+
Digit 9: Sensor Type
40+
Digit 10: Sensor Index
41+
42+
Port Sensor Type describes below:
43+
1 - Temperature
44+
2 - TX Power
45+
3 - RX Power
46+
4 - TX BIAS
47+
5 - Voltage
48+
"""
49+
50+
# Moduel Type Definition
51+
MODULE_TYPE_MULTIPLE = 100000000
52+
MODULE_INDEX_MULTIPLE = 1000000
53+
MODULE_TYPE_MGMT = 2 * MODULE_TYPE_MULTIPLE
54+
MODULE_TYPE_FAN_DRAWER = 5 * MODULE_TYPE_MULTIPLE
55+
MODULE_TYPE_PSU = 6 * MODULE_TYPE_MULTIPLE
56+
MODULE_TYPE_PORT = 1000000000
57+
58+
# Device Type Definition
59+
DEVICE_TYPE_MULTIPLE = 10000
60+
DEVICE_INDEX_MULTIPLE = 100
61+
DEVICE_TYPE_PS = 1 * DEVICE_TYPE_MULTIPLE
62+
DEVICE_TYPE_FAN = 2 * DEVICE_TYPE_MULTIPLE
63+
DEVICE_TYPE_CHASSIS_THERMAL = 99 * DEVICE_TYPE_MULTIPLE
64+
DEVICE_TYPE_POWER_MONITOR = 24 * DEVICE_TYPE_MULTIPLE
65+
66+
# Sensor Type Definition
67+
SENSOR_TYPE_MULTIPLE = 10
68+
SENSOR_TYPE_TEMP = 1 * SENSOR_TYPE_MULTIPLE
69+
SENSOR_TYPE_FAN = 2 * SENSOR_TYPE_MULTIPLE
70+
SENSOR_TYPE_POWER = 3 * SENSOR_TYPE_MULTIPLE
71+
SENSOR_TYPE_CURRENT = 4 * SENSOR_TYPE_MULTIPLE
72+
SENSOR_TYPE_VOLTAGE = 5 * SENSOR_TYPE_MULTIPLE
73+
74+
# Port entPhysicalIndex Definition
75+
PORT_IFINDEX_MULTIPLE = 100
76+
SENSOR_TYPE_PORT_TX_POWER = 2 * SENSOR_TYPE_MULTIPLE
77+
SENSOR_TYPE_PORT_RX_POWER = 3 * SENSOR_TYPE_MULTIPLE
78+
SENSOR_TYPE_PORT_TX_BIAS = 4 * SENSOR_TYPE_MULTIPLE
79+
80+
CHASSIS_SUB_ID = 1
81+
CHASSIS_MGMT_SUB_ID = MODULE_TYPE_MGMT
82+
83+
# This is used in both rfc2737 and rfc3433
84+
XCVR_SENSOR_PART_ID_MAP = {
85+
"temperature": SENSOR_TYPE_TEMP,
86+
"tx1power": SENSOR_TYPE_PORT_TX_POWER + 1,
87+
"tx2power": SENSOR_TYPE_PORT_TX_POWER + 2,
88+
"tx3power": SENSOR_TYPE_PORT_TX_POWER + 3,
89+
"tx4power": SENSOR_TYPE_PORT_TX_POWER + 4,
90+
"rx1power": SENSOR_TYPE_PORT_RX_POWER + 1,
91+
"rx2power": SENSOR_TYPE_PORT_RX_POWER + 2,
92+
"rx3power": SENSOR_TYPE_PORT_RX_POWER + 3,
93+
"rx4power": SENSOR_TYPE_PORT_RX_POWER + 4,
94+
"tx1bias": SENSOR_TYPE_PORT_TX_BIAS + 1,
95+
"tx2bias": SENSOR_TYPE_PORT_TX_BIAS + 2,
96+
"tx3bias": SENSOR_TYPE_PORT_TX_BIAS + 3,
97+
"tx4bias": SENSOR_TYPE_PORT_TX_BIAS + 4,
98+
"voltage": SENSOR_TYPE_VOLTAGE,
99+
}
100+
101+
PSU_SENSOR_PART_ID_MAP = {
102+
'temperature': SENSOR_TYPE_TEMP,
103+
'power': SENSOR_TYPE_POWER,
104+
'current': SENSOR_TYPE_CURRENT,
105+
'voltage': SENSOR_TYPE_VOLTAGE
106+
}
107+
108+
def get_chassis_thermal_sub_id(position):
109+
"""
110+
Returns sub OID for thermals that belong to chassis. Sub OID is calculated as follows:
111+
sub OID = CHASSIS_MGMT_SUB_ID + DEVICE_TYPE_CHASSIS_THERMAL + position * DEVICE_INDEX_MULTIPLE + SENSOR_TYPE_TEMP,
112+
:param position: thermal position
113+
:return: sub OID of the thermal
114+
"""
115+
return (CHASSIS_MGMT_SUB_ID + DEVICE_TYPE_CHASSIS_THERMAL + position * DEVICE_INDEX_MULTIPLE + SENSOR_TYPE_TEMP, )
116+
117+
def get_fan_sub_id(parent_id, position):
118+
"""
119+
Returns sub OID for fan. Sub OID is calculated as follows:
120+
sub OID = parent_id[0] + DEVICE_TYPE_FAN + position * DEVICE_INDEX_MULTIPLE
121+
If parent_id is chassis OID, will use a "virtual" fan drawer OID as its parent_id
122+
:param parent_id: parent device sub OID
123+
:param position: fan position
124+
:return: sub OID of the fan
125+
"""
126+
if parent_id[0] == CHASSIS_SUB_ID:
127+
parent_id = MODULE_TYPE_FAN_DRAWER + position * MODULE_INDEX_MULTIPLE
128+
else:
129+
parent_id = parent_id[0]
130+
return (parent_id + DEVICE_TYPE_FAN + position * DEVICE_INDEX_MULTIPLE, )
131+
132+
def get_fan_drawer_sub_id(position):
133+
"""
134+
Returns sub OID for fan drawer. Sub OID is calculated as follows:
135+
sub OID = MODULE_TYPE_FAN_DRAWER + position * MODULE_INDEX_MULTIPLE
136+
:param position: fan drawer position
137+
:return: sub OID of the fan drawer
138+
"""
139+
return (MODULE_TYPE_FAN_DRAWER + position * MODULE_INDEX_MULTIPLE, )
140+
141+
def get_fan_tachometers_sub_id(parent_id):
142+
"""
143+
Returns sub OID for fan tachometers. Sub OID is calculated as follows:
144+
sub OID = parent_id[0] + SENSOR_TYPE_FAN
145+
:param parent_id: parent device sub OID
146+
:return: sub OID of the fan tachometers
147+
"""
148+
return (parent_id[0] + SENSOR_TYPE_FAN, )
149+
150+
def get_psu_sub_id(position):
151+
"""
152+
Returns sub OID for PSU. Sub OID is calculated as follows:
153+
sub OID = MODULE_TYPE_PSU + position * MODULE_INDEX_MULTIPLE
154+
:param position: PSU position
155+
:return: sub OID of PSU
156+
"""
157+
return (MODULE_TYPE_PSU + position * MODULE_INDEX_MULTIPLE, )
158+
159+
def get_psu_sensor_sub_id(parent_id, sensor):
160+
"""
161+
Returns sub OID for PSU sensor. Sub OID is calculated as follows:
162+
sub OID = parent_id[0] + DEVICE_TYPE_POWER_MONITOR + PSU_SENSOR_PART_ID_MAP[sensor]
163+
:param parent_id: PSU oid
164+
:param sensor: PSU sensor name
165+
:return: sub OID of PSU sensor
166+
"""
167+
return (parent_id[0] + DEVICE_TYPE_POWER_MONITOR + PSU_SENSOR_PART_ID_MAP[sensor], )
168+
169+
def get_transceiver_sub_id(ifindex):
170+
"""
171+
Returns sub OID for transceiver. Sub OID is calculated as folows:
172+
sub OID = MODULE_TYPE_PORT + ifindex * PORT_IFINDEX_MULTIPLE
173+
:param ifindex: interface index
174+
:return: sub OID of a port
175+
"""
176+
return (MODULE_TYPE_PORT + ifindex * PORT_IFINDEX_MULTIPLE, )
177+
178+
def get_transceiver_sensor_sub_id(ifindex, sensor):
179+
"""
180+
Returns sub OID for transceiver sensor. Sub OID is calculated as folows:
181+
sub OID = transceiver_oid + XCVR_SENSOR_PART_ID_MAP[sensor]
182+
:param ifindex: interface index
183+
:param sensor: sensor key
184+
:return: sub OID = {{index}} * 1000 + {{lane}} * 10 + sensor id
185+
"""
186+
187+
transceiver_oid, = get_transceiver_sub_id(ifindex)
188+
return (transceiver_oid + XCVR_SENSOR_PART_ID_MAP[sensor],)

0 commit comments

Comments
 (0)