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

Loopback interfaces are part of ifTable,ifXTable and some fixes #220

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
119 changes: 119 additions & 0 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ax_interface.util import oid2tuple
from sonic_ax_impl import logger
from sonic_py_common import multi_asic
from ax_interface.util import mac_decimals

COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
Expand Down Expand Up @@ -174,6 +175,14 @@ def mgmt_if_entry_table(if_name):

return 'MGMT_PORT|' + if_name

def vlan_if_entry_table(vlan):
"""
:param if_name: given interface to cast
:return: VLAN_TABLE key
"""

return 'VLAN_TABLE:' + vlan


def mgmt_if_entry_table_state_db(if_name):
"""
Expand Down Expand Up @@ -255,6 +264,91 @@ def init_mgmt_interface_tables(db_conn):

return oid_name_map, if_alias_map

def init_vlan_interface_tables(db_conn, mac=""):
"""
Initializes interface maps for vlan ports
:param db_conn: db connector
:return: tuple of vlan name to oid map and vlan name to alias map
"""

db_conn.connect(APPL_DB)

vlan_intf_keys = db_conn.keys(APPL_DB, 'INTF_TABLE:Vlan*')

if not vlan_intf_keys:
logger.debug('No vlan interfaces found.' )
return {},{}

oid_name_map = {}
oid_mac_map = {}
for key in vlan_intf_keys:
vlan = key.split(':')[1]
index = get_index_from_str(vlan)
oid_name_map[index] = vlan
#get mac addr of vlan
ent = db_conn.get_all(APPL_DB, key)
if ent and 'mac_addr' in ent:
mactuple = mac_decimals(ent['mac_addr'])
oid_mac_map[index] = ''.join(chr(b) for b in mactuple)
else:
oid_mac_map[index] = mac

logger.debug('vlan interface map:\n' + pprint.pformat(oid_name_map, indent=2))
return oid_name_map, oid_mac_map

def init_mclag_interface_tables(db_conn, mac=""):
"""
Initializes interface maps for vlan ports
:param db_conn: db connector
:return: tuple of vlan name to oid map and vlan name to alias map
"""

db_conn.connect(STATE_DB)

intf_keys = db_conn.keys(STATE_DB, 'MCLAG_LOCAL_INTF_TABLE|*')

if not intf_keys:
logger.debug('No vlan interfaces found.' )
return {},{}

oid_name_map = {}
oid_mac_map = {}
for key in intf_keys:
name = key.split('|')[1]
index = get_index_from_str(name)
oid_name_map[index] = name
#get mac addr of vlan
ent = db_conn.get_all(STATE_DB, key)
if ent and 'interface_mac' in ent:
mactuple = mac_decimals(ent['interface_mac'])
oid_mac_map[index] = ''.join(chr(b) for b in mactuple)
else:
oid_mac_map[index] = mac

logger.debug('vlan interface map:\n' + pprint.pformat(oid_name_map, indent=2))
return oid_name_map, oid_mac_map

def init_loopback_interface_tables(db_conn):
"""
Initializes interface maps for loopback ports
:param db_conn: db connector
:return: tuple of loopback name to oid map
"""

db_conn.connect(CONFIG_DB)

lpbk_intf_keys = db_conn.keys(CONFIG_DB, 'LOOPBACK_INTERFACE|*')

if not lpbk_intf_keys:
logger.debug('No lpbk interfaces found.' )
return {}

lpbk_interfaces = [key.split('|')[1] for key in lpbk_intf_keys]
oid_name_map = {get_index_from_str(lpbk_name): lpbk_name for lpbk_name in lpbk_interfaces}
logger.debug('lpbk interface map:\n' + pprint.pformat(oid_name_map, indent=2))

return oid_name_map

def init_sync_d_interface_tables(db_conn):
"""
Initializes interface maps for SyncD-connected MIB(s).
Expand Down Expand Up @@ -431,6 +525,8 @@ def init_sync_d_queue_tables(db_conn):
port_name, queue_index = queue_name.split(':')
queue_index = ''.join(i for i in queue_index if i.isdigit())
port_index = get_index_from_str(port_name)
if port_index is None:
continue
key = queue_key(port_index, queue_index)
port_queues_map[key] = sai_id

Expand Down Expand Up @@ -458,6 +554,29 @@ def init_sync_d_queue_tables(db_conn):

return port_queues_map, queue_stat_map, port_queue_list_map

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

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

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

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

device_metadata = get_config_device_metadata(db_conn)
if device_metadata and 'intf_naming_mode' in device_metadata:
return device_metadata['intf_naming_mode']
return None

def get_device_metadata(db_conn):
"""
:param db_conn: Sonic DB connector
Expand Down
20 changes: 16 additions & 4 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ def reinit_data(self):
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
self.loc_chassis_data = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE)
if self.loc_chassis_data:
self.loc_chassis_data['lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data['lldp_loc_sys_cap_supported'])
self.loc_chassis_data['lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data['lldp_loc_sys_cap_enabled'])
if 'lldp_loc_sys_cap_supported' in self.loc_chassis_data:
self.loc_chassis_data['lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data['lldp_loc_sys_cap_supported'])
if 'lldp_loc_sys_cap_enabled' in self.loc_chassis_data:
self.loc_chassis_data['lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data['lldp_loc_sys_cap_enabled'])

def update_data(self):
"""
Expand Down Expand Up @@ -157,6 +159,7 @@ def __init__(self):
self.db_conn = Namespace.init_namespace_dbs()
# establish connection to application database.
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
Namespace.connect_all_dbs(self.db_conn, mibs.CONFIG_DB)
self.if_name_map = {}
self.if_alias_map = {}
self.if_id_map = {}
Expand Down Expand Up @@ -340,6 +343,8 @@ def reinit_data(self):
logger.error("Invalid local mgmt IP {}".format(self.mgmt_ip_str))
return

if mgmt_ip_sub_oid is None:
return
sub_oid = (ManAddrConst.man_addr_subtype_ipv4,
*mgmt_ip_sub_oid)
self.man_addr_list.append(sub_oid)
Expand Down Expand Up @@ -442,7 +447,9 @@ def update_data(self):
self.lldp_counters = {}
for if_oid, if_name in self.oid_name_map.items():
lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name))
if not lldp_kvs:
if (not lldp_kvs or
'lldp_rem_time_mark' not in lldp_kvs or
'lldp_rem_index' not in lldp_kvs ):
continue
try:
# OID index for this MIB consists of remote time mark, if_oid, remote_index.
Expand Down Expand Up @@ -508,13 +515,17 @@ def __init__(self):
# establish connection to application database.
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)
self.if_range = []
self.mgmt_ips = {}
self.oid_name_map = {}
self.mgmt_oid_name_map = {}
self.pubsub = [None] * len(self.db_conn)

def update_rem_if_mgmt(self, if_oid, if_name):
lldp_kvs = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, mibs.lldp_entry_table(if_name))
if not lldp_kvs or 'lldp_rem_man_addr' not in lldp_kvs:
if (not lldp_kvs or
'lldp_rem_man_addr' not in lldp_kvs or
'lldp_rem_time_mark' not in lldp_kvs or
'lldp_rem_index' not in lldp_kvs ):
# this interfaces doesn't have remote lldp data, or the peer doesn't advertise his mgmt address
return
try:
Expand Down Expand Up @@ -586,6 +597,7 @@ def reinit_data(self):
Namespace.connect_all_dbs(self.db_conn, mibs.APPL_DB)

self.if_range = []
self.mgmt_ips = {}
for if_oid, if_name in self.oid_name_map.items():
self.update_rem_if_mgmt(if_oid, if_name)

Expand Down
Loading