Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for some bridge-mib and q-bridge-mib objects #227

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
126 changes: 126 additions & 0 deletions src/sonic_ax_impl/mibs/ietf/rfc4188.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#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 = mibs.get_index_from_str(ifname)
if if_index is None:
continue
self.dot1dbase_port_map[if_index-1] = if_index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is " if_index-1" used as the OID index?
In interface MIB, if index is directly used as OID.
Example: https://github.com/Azure/sonic-snmpagent/blob/master/src/sonic_ax_impl/mibs/ietf/rfc1213.py#L298

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per if-mib ifIndex should be (1..2147483647) . if_index is 1 based not zero based.


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