Skip to content

Commit

Permalink
Extend RFC 2737 MIB and implement RFC 3433 (sonic-net#69)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stepanblyschak authored and qiluo-msft committed Aug 5, 2018
1 parent 573dd92 commit ae99de0
Show file tree
Hide file tree
Showing 8 changed files with 1,214 additions and 62 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
MIB implementations included:

* [RFC 1213](https://www.ietf.org/rfc/rfc1213.txt) MIB-II
* [RFC 2737](https://www.ietf.org/rfc/rfc2737.txt) Physical Table MIB
* [RFC 2863](https://www.ietf.org/rfc/rfc2863.txt) Interfaces MIB
* [RFC 3433](https://www.ietf.org/rfc/rfc3433.txt) Sensor Table MIB
* [RFC 4292](https://tools.ietf.org/html/rfc4292) ipCidrRouteDest table in IP Forwarding Table MIB
* [RFC 4363](https://tools.ietf.org/html/rfc4363) dot1qTpFdbPort in Q-BRIDGE-MIB
* [IEEE 802.1 AB](http://www.ieee802.org/1/files/public/MIBs/LLDP-MIB-200505060000Z.txt) LLDP-MIB
Expand Down
3 changes: 2 additions & 1 deletion src/sonic_ax_impl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ax_interface
from sonic_ax_impl.mibs import ieee802_1ab
from . import logger
from .mibs.ietf import rfc1213, rfc2737, rfc2863, rfc4292, rfc4363
from .mibs.ietf import rfc1213, rfc2737, rfc2863, rfc3433, rfc4292, rfc4363
from .mibs.vendor import dell, cisco

# Background task update frequency ( in seconds )
Expand All @@ -25,6 +25,7 @@ class SonicMIB(
rfc1213.InterfacesMIB,
rfc1213.IpMib,
rfc2737.PhysicalTableMIB,
rfc3433.PhysicalSensorTableMIB,
rfc2863.InterfaceMIBObjects,
rfc4363.QBridgeMIBObjects,
rfc4292.IpCidrRouteTable,
Expand Down
85 changes: 85 additions & 0 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@
ASIC_DB = 'ASIC_DB'
COUNTERS_DB = 'COUNTERS_DB'

TABLE_NAME_SEPARATOR_COLON = ':'
TABLE_NAME_SEPARATOR_VBAR = '|'

# This is used in both rfc2737 and rfc3433
SENSOR_PART_ID_MAP = {
"temperature": 1,
"voltage": 2,
"rx1power": 11,
"rx2power": 21,
"rx3power": 31,
"rx4power": 41,
"tx1bias": 12,
"tx2bias": 22,
"tx3bias": 32,
"tx4bias": 42,
"tx1power": 13,
"tx2power": 23,
"tx3power": 33,
"tx4power": 43,
}

# IfIndex to OID multiplier for transceiver
IFINDEX_SUB_ID_MULTIPLIER = 1000

redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'}

def counter_table(sai_id):
Expand All @@ -34,6 +58,21 @@ def queue_table(sai_id):
def queue_key(port_index, queue_index):
return str(port_index) + ':' + str(queue_index)

def transceiver_info_table(port_name):
"""
:param: port_name: port name
:return: transceiver info entry for this port
"""

return "TRANSCEIVER_INFO" + TABLE_NAME_SEPARATOR_VBAR + port_name

def transceiver_dom_table(port_name):
"""
:param: port_name: port name
:return: transceiver dom entry for this port
"""

return "TRANSCEIVER_DOM_SENSOR" + TABLE_NAME_SEPARATOR_VBAR + port_name

def lldp_entry_table(if_name):
"""
Expand Down Expand Up @@ -225,3 +264,49 @@ def init_sync_d_queue_tables(db_conn):

return port_queues_map, queue_stat_map, port_queue_list_map

def get_device_metadata(db_conn):
"""
:param db_conn: Sonic DB connector
:return: device metadata
"""

DEVICE_METADATA = "DEVICE_METADATA|localhost"
db_conn.connect(db_conn.STATE_DB)

device_metadata = db_conn.get_all(db_conn.STATE_DB, DEVICE_METADATA)
return device_metadata

def get_transceiver_sub_id(ifindex):
"""
Returns sub OID for transceiver. Sub OID is calculated as folows:
+------------+------------+
|Interface |Index |
+------------+------------+
|Ethernet[X] |X * 1000 |
+------------+------------+
()
:param ifindex: interface index
:return: sub OID of a port calculated as sub OID = {{index}} * 1000
"""

return (ifindex * IFINDEX_SUB_ID_MULTIPLIER, )

def get_transceiver_sensor_sub_id(ifindex, sensor):
"""
Returns sub OID for transceiver sensor. Sub OID is calculated as folows:
+-------------------------------------+------------------------------+
|Sensor |Index |
+-------------------------------------+------------------------------+
|RX Power for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 1 |
|TX Bias for Ethernet[X]/[LANEID] |X * 1000 + LANEID * 10 + 2 |
|Temperature for Ethernet[X] |X * 1000 + 1 |
|Voltage for Ethernet[X]/[LANEID] |X * 1000 + 2 |
+-------------------------------------+------------------------------+
()
:param ifindex: interface index
:param sensor: sensor key
:return: sub OID = {{index}} * 1000 + {{lane}} * 10 + sensor id
"""

transceiver_oid, = get_transceiver_sub_id(ifindex)
return (transceiver_oid + SENSOR_PART_ID_MAP[sensor], )
Loading

0 comments on commit ae99de0

Please sign in to comment.