Skip to content

Commit

Permalink
support for some bridge-mib and q-bridge-mib objects
Browse files Browse the repository at this point in the history
  • Loading branch information
suresh-rupanagudi committed Jul 15, 2021
1 parent 7a78703 commit 1adb270
Show file tree
Hide file tree
Showing 8 changed files with 976 additions and 8 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'mockredispy>=2.9.3',
'pytest',
'pytest-cov',
'bitstring>=3.1.6',
]

high_performance_deps = [
Expand Down
7 changes: 6 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, rfc3433, rfc4292, rfc4363
from .mibs.ietf import rfc1213, rfc2737, rfc2863, rfc3433, rfc4292, rfc4363, rfc4188
from .mibs.vendor import dell, cisco

# Background task update frequency ( in seconds )
Expand All @@ -29,7 +29,12 @@ class SonicMIB(
rfc3433.PhysicalSensorTableMIB,
rfc2863.InterfaceMIBObjects,
rfc4363.QBridgeMIBObjects,
rfc4363.Dot1qFdbMIBObjects,
rfc4363.Dot1qVlanCurrentMIBObjects,
rfc4363.Dot1qVlanStaticMIBObjects,
rfc4363.Dot1qPortVlanMIBObjects,
rfc4292.IpCidrRouteTable,
rfc4188.Dot1dBaseMIB,
ieee802_1ab.LLDPLocalSystemData,
ieee802_1ab.LLDPLocalSystemData.LLDPLocPortTable,
ieee802_1ab.LLDPLocalSystemData.LLDPLocManAddrTable,
Expand Down
127 changes: 127 additions & 0 deletions src/sonic_ax_impl/mibs/ietf/rfc4188.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#import json
#import ipaddress
#from enum import unique, Enum

#from swsssdk import port_util
from sonic_ax_impl import mibs
from sonic_ax_impl.mibs import Namespace
from ax_interface import MIBMeta, ValueType, MIBUpdater, SubtreeMIBEntry, MIBEntry
#from ax_interface.encodings import OctetString
#from ax_interface.util import mac_decimals, ip2tuple_v4
from bisect import bisect_right
#import re


class Dot1dBaseTypeConst:
unknown = 1
transparent = 2
source_route = 3
srt = 4

class Dot1dBaseUpdater(MIBUpdater):
def __init__(self):
super().__init__()
self.db_conn = Namespace.init_namespace_dbs()
self.dot1dbase_port_map = {}
self.dot1dbase_port_list = []
self.dot1dbase_bridge_addr = None
self.dot1d_aging_time = 600

def reinit_data(self):
"""
Subclass update interface information
"""
Namespace.connect_all_dbs(self.db_conn, mibs.CONFIG_DB)
self.dot1dbase_bridge_addr = self.db_conn[0].get(mibs.CONFIG_DB, "DEVICE_METADATA|localhost", 'mac')

def update_data(self):
"""
Update redis (caches config)
Pulls the table references for each vlan member.
"""
self.dot1dbase_port_map = {}
self.dot1dbase_port_list = []

fdb_aging_time = self.db_conn[0].get(mibs.CONFIG_DB, "SWITCH|switch", 'fdb_aging_time')
if fdb_aging_time:
self.dot1d_aging_time = int(fdb_aging_time)
else:
self.dot1d_aging_time = 600

vlanmem_entries = Namespace.dbs_keys(self.db_conn, mibs.CONFIG_DB, "VLAN_MEMBER|*")
if not vlanmem_entries:
return

for vmem_entry in vlanmem_entries:
ifname = vmem_entry.split('|')[2]
#if_index = port_util.get_index_from_str(ifname)
if_index = mibs.get_index_from_str(ifname)
if if_index is None:
continue
self.dot1dbase_port_map[if_index-1] = if_index

self.dot1dbase_port_list = sorted(self.dot1dbase_port_map.keys())
self.dot1dbase_port_list = [(i,) for i in self.dot1dbase_port_list]
mibs.logger.debug('Port map entries : {}' .format(self.dot1dbase_port_map))
mibs.logger.debug('Port list : {}' .format(self.dot1dbase_port_list))

def get_dot1dbase_bridge_addr(self):
return self.dot1dbase_bridge_addr

def get_dot1d_base_num_ports(self):
return len(self.dot1dbase_port_map)

def get_dot1d_base_type(self):
return Dot1dBaseTypeConst.transparent

def get_dot1d_aging_time(self):
return self.dot1d_aging_time

def get_dot1dbase_port(self, sub_id):
if sub_id:
if sub_id in self.dot1dbase_port_list:
return sub_id[0]
return

def get_dot1dbase_port_ifindex(self, sub_id):
if sub_id:
return self.dot1dbase_port_map.get(sub_id[0], None)

def get_dot1dbase_port_delay_discard(self, sub_id):
if sub_id:
return 0

def get_dot1dbase_port_mtu_discard(self, sub_id):
if sub_id:
return 0

def get_next(self, sub_id):
right = bisect_right(self.dot1dbase_port_list, sub_id)
if right == len(self.dot1dbase_port_list):
return None

return self.dot1dbase_port_list[right]

class Dot1dBaseMIB(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.17'):
"""
' dot1dBase MIB' https://tools.ietf.org/html/rfc4188
"""

dot1dbase_updater = Dot1dBaseUpdater()

# (subtree, value_type, callable_, *args, handler=None)
dot1dBaseBridgeAddress = MIBEntry('1.1.0', ValueType.OCTET_STRING, dot1dbase_updater.get_dot1dbase_bridge_addr)
dot1dBaseNumPorts = MIBEntry('1.2.0', ValueType.INTEGER, dot1dbase_updater.get_dot1d_base_num_ports)
dot1dBaseType = MIBEntry('1.3.0', ValueType.INTEGER, dot1dbase_updater.get_dot1d_base_type)

dot1dBasePort = \
SubtreeMIBEntry('1.4.1.1', dot1dbase_updater, ValueType.INTEGER, dot1dbase_updater.get_dot1dbase_port)
dot1dBasePortIfIndex = \
SubtreeMIBEntry('1.4.1.2', dot1dbase_updater, ValueType.INTEGER, dot1dbase_updater.get_dot1dbase_port_ifindex)
dot1dBasePortDelayExceededDiscards = \
SubtreeMIBEntry('1.4.1.4', dot1dbase_updater, ValueType.COUNTER_32, dot1dbase_updater.get_dot1dbase_port_delay_discard)
dot1dBasePortMtuExceededDiscards = \
SubtreeMIBEntry('1.4.1.5', dot1dbase_updater, ValueType.COUNTER_32, dot1dbase_updater.get_dot1dbase_port_mtu_discard)

dot1dTpAgingTime = MIBEntry('4.2.0', ValueType.INTEGER, dot1dbase_updater.get_dot1d_aging_time)

Loading

0 comments on commit 1adb270

Please sign in to comment.