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

[202012] Fix IfHighSpeed UT issue on 202012 #297

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
748b545
[SNMP] Update description of entPhysicalDescr mib in case interface i…
liorghub Apr 5, 2021
946e5cf
Fix: SonicV2Connector behavior change: get_all will return empty dict…
qiluo-msft Jul 12, 2021
a4dd3bf
Non-block reading counters to tolerate corrupted/delayed counters in …
qiluo-msft Aug 4, 2021
c160c2b
CPU Spike because of redundant and flooded keyspace notifis handled (…
vivekrnv Aug 5, 2021
5c0d941
[201911][RFC1213]: Initialize lag oid map in reinit_data (#234)
SuvarnaMeenakshi Sep 17, 2021
60f5237
[multi-asic]: Udpate to use SonicDBConfig from swsscommon (#219)
SuvarnaMeenakshi Jun 30, 2021
414692f
LLDPLocalSystemDataUpdater Exception Log Handled (#249)
vivekrnv Apr 4, 2022
c75440b
Fix: not to use blocking get_all() after keys() (#255)
qiluo-msft May 2, 2022
13ddb0e
Fix: if routestr does not exist, skip (#257)
qiluo-msft May 5, 2022
792afe8
Don't cache the vlan-id if it is not valid from DB (#273)
zhenggen-xu Nov 14, 2022
00b4dc0
Remove error logging on "failed in fdb_vlanmac" (#272)
qiluo-msft Nov 14, 2022
e60a64c
Use github code scanning instead of LGTM (#274)
liushilongbuaa Nov 30, 2022
7147354
Fix: zero route may have empty nexthop (#276)
qiluo-msft Feb 15, 2023
fba50c6
[202012]: snmp vlan support per RFC1213 and added the missing support…
SuvarnaMeenakshi Mar 4, 2023
551898e
Revert "[202012]: snmp vlan support per RFC1213 and added the missing…
SuvarnaMeenakshi Mar 29, 2023
b292c01
Fix FdbUpdater crash when SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID attribute…
liuh-80 Aug 30, 2023
64f0def
Support interface speed for PortChannels (#262)
lukasstockner Sep 14, 2023
2cb8241
Add ifhighspeed UT (#296)
liuh-80 Oct 10, 2023
52021b0
Fix backup port rfc2863 UT to 202012 branch issue
liuh-80 Oct 13, 2023
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
4 changes: 4 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "CodeQL config"
queries:
- uses: security-and-quality
- uses: security-extended
43 changes: 43 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# For more infomation, please visit: https://github.com/github/codeql-action

name: "CodeQL"

on:
push:
branches:
- 'master'
- '202[0-9][0-9][0-9]'
pull_request_target:
branches:
- 'master'
- '202[0-9][0-9][0-9]'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
config-file: ./.github/codeql/codeql-config.yml
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
30 changes: 23 additions & 7 deletions src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import os

from swsscommon.swsscommon import SonicV2Connector
from swsssdk import SonicDBConfig
from swsscommon.swsscommon import SonicDBConfig
from swsssdk import port_util
from swsssdk.port_util import get_index_from_str
from ax_interface.mib import MIBUpdater
from ax_interface.util import oid2tuple
from sonic_ax_impl import logger
from sonic_py_common import multi_asic

COUNTERS_PORT_NAME_MAP = 'COUNTERS_PORT_NAME_MAP'
COUNTERS_QUEUE_NAME_MAP = 'COUNTERS_QUEUE_NAME_MAP'
Expand Down Expand Up @@ -194,7 +195,12 @@ def init_db():
Connects to DB
:return: db_conn
"""
SonicDBConfig.load_sonic_global_db_config()
if not SonicDBConfig.isInit():
if multi_asic.is_multi_asic():
# Load the global config file database_global.json once.
SonicDBConfig.load_sonic_global_db_config()
else:
SonicDBConfig.load_sonic_db_config()
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
# Redis PubSub objects (such as those within swsssdk) are NOT thread-safe.
db_conn = SonicV2Connector(**redis_kwargs)
Expand Down Expand Up @@ -473,10 +479,20 @@ class Namespace:
@staticmethod
def init_namespace_dbs():
db_conn = []
SonicDBConfig.load_sonic_global_db_config()
for namespace in SonicDBConfig.get_ns_list():
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace, decode_responses=True)
if not SonicDBConfig.isInit():
if multi_asic.is_multi_asic():
SonicDBConfig.load_sonic_global_db_config()
else:
SonicDBConfig.load_sonic_db_config()
host_namespace_idx = 0
for idx, namespace in enumerate(SonicDBConfig.get_ns_list()):
if namespace == multi_asic.DEFAULT_NAMESPACE:
host_namespace_idx = idx
db = SonicV2Connector(use_unix_socket_path=True, namespace=namespace)
db_conn.append(db)
# Ensure that db connector of default namespace is the first element of
# db_conn list.
db_conn[0], db_conn[host_namespace_idx] = db_conn[host_namespace_idx], db_conn[0]

Namespace.connect_namespace_dbs(db_conn)
return db_conn
Expand Down Expand Up @@ -537,15 +553,15 @@ def dbs_get_all(dbs, db_name, _hash, *args, **kwargs):
result = {}
# If there are multiple namespaces, _hash might not be
# present in all namespace, ignore if not present in a
# specfic namespace.
# specific namespace.
if len(dbs) > 1:
tmp_kwargs = kwargs.copy()
tmp_kwargs['blocking'] = False
else:
tmp_kwargs = kwargs
for db_conn in dbs:
ns_result = db_conn.get_all(db_name, _hash, *args, **tmp_kwargs)
if ns_result is not None:
if ns_result:
result.update(ns_result)
return result

Expand Down
32 changes: 21 additions & 11 deletions src/sonic_ax_impl/mibs/ieee802_1ab.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ def poll_lldp_entry_updates(pubsub):
return ret
return data, interface, if_index

def get_latest_notification(pubsub):
"""
Fetches the latest notification recorded on a lldp entry.
"""
latest_update_map = {}
while True:
data, interface, if_index = poll_lldp_entry_updates(pubsub)
if not data:
break
latest_update_map[interface] = (data, if_index)
return latest_update_map

def parse_sys_capability(sys_cap):
return bytearray([int (x, 16) for x in sys_cap.split()])

Expand All @@ -114,8 +126,8 @@ 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'])
self.loc_chassis_data['lldp_loc_sys_cap_supported'] = parse_sys_capability(self.loc_chassis_data.get('lldp_loc_sys_cap_supported', ''))
self.loc_chassis_data['lldp_loc_sys_cap_enabled'] = parse_sys_capability(self.loc_chassis_data.get('lldp_loc_sys_cap_enabled', ''))

def update_data(self):
"""
Expand Down Expand Up @@ -542,19 +554,17 @@ def _update_per_namespace_data(self, pubsub):
"""
Listen to updates in APP DB, update local cache
"""
while True:
data, interface, if_index = poll_lldp_entry_updates(pubsub)

if not data:
break

event_cache = get_latest_notification(pubsub)
for interface in event_cache:
data = event_cache[interface][0]
if_index = event_cache[interface][1]

if "set" in data:
self.update_rem_if_mgmt(if_index, interface)
elif "del" in data:
# some remote data about that neighbor is gone, del it and try to query again
# if del is the latest notification, then delete it from the local cache
self.if_range = [sub_oid for sub_oid in self.if_range if sub_oid[0] != if_index]
self.update_rem_if_mgmt(if_index, interface)


def update_data(self):
for i in range(len(self.db_conn)):
if not self.pubsub[i]:
Expand Down
37 changes: 22 additions & 15 deletions src/sonic_ax_impl/mibs/ietf/rfc1213.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _update_from_db(self):
neigh_str = neigh_key
db_index = self.neigh_key_list[neigh_key]
neigh_info = self.db_conn[db_index].get_all(mibs.APPL_DB, neigh_key, blocking=False)
if neigh_info is None:
if not neigh_info:
continue
ip_family = neigh_info['family']
if ip_family == "IPv4":
Expand Down Expand Up @@ -150,14 +150,18 @@ def update_data(self):
ipnstr = routestr[len("ROUTE_TABLE:"):]
if ipnstr == "0.0.0.0/0":
ipn = ipaddress.ip_network(ipnstr)
ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=True)
nexthops = ent["nexthop"]
for nh in nexthops.split(','):
# TODO: if ipn contains IP range, create more sub_id here
sub_id = ip2byte_tuple(ipn.network_address)
self.route_list.append(sub_id)
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
break # Just need the first nexthop
ent = Namespace.dbs_get_all(self.db_conn, mibs.APPL_DB, routestr, blocking=False)
if ent:
nexthops = ent.get("nexthop", None)
if nexthops is None:
mibs.logger.warning("Route has no nexthop: {} {}".format(routestr, str(ent)))
continue
for nh in nexthops.split(','):
# TODO: if ipn contains IP range, create more sub_id here
sub_id = ip2byte_tuple(ipn.network_address)
self.route_list.append(sub_id)
self.nexthop_map[sub_id] = ipaddress.ip_address(nh).packed
break # Just need the first nexthop

self.route_list.sort()

Expand Down Expand Up @@ -220,6 +224,10 @@ def reinit_data(self):
self.mgmt_oid_name_map, \
self.mgmt_alias_map = mibs.init_mgmt_interface_tables(self.db_conn[0])

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
self.oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn)

def update_data(self):
"""
Update redis (caches config)
Expand All @@ -228,12 +236,11 @@ def update_data(self):
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)

self.lag_name_if_name_map, \
self.if_name_lag_name_map, \
self.oid_lag_name_map, _ = Namespace.get_sync_d_from_all_namespace(mibs.init_sync_d_lag_tables, self.db_conn)
counter_table = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id))
if counter_table is None:
counter_table = {}
self.if_counters[if_idx] = counter_table

self.if_range = sorted(list(self.oid_name_map.keys()) +
list(self.oid_lag_name_map.keys()) +
Expand Down
7 changes: 5 additions & 2 deletions src/sonic_ax_impl/mibs/ietf/rfc2737.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ def get_transceiver_description(sfp_type, if_alias):
:param if_alias: Port alias name
:return: Transceiver decsription
"""
if not if_alias:
description = "{}".format(sfp_type)
else:
description = "{} for {}".format(sfp_type, if_alias)

return "{} for {}".format(sfp_type, if_alias)

return description

def get_transceiver_sensor_description(name, lane_number, if_alias):
"""
Expand Down
33 changes: 24 additions & 9 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ def update_data(self):
for sai_id_key in self.if_id_map:
namespace, sai_id = mibs.split_sai_id_key(sai_id_key)
if_idx = mibs.get_index_from_str(self.if_id_map[sai_id_key])
self.if_counters[if_idx] = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id), blocking=True)
counter_table = self.namespace_db_map[namespace].get_all(mibs.COUNTERS_DB, \
mibs.counter_table(sai_id))
if counter_table is None:
counter_table = {}
self.if_counters[if_idx] = counter_table

def get_next(self, sub_id):
"""
Expand Down Expand Up @@ -147,7 +150,11 @@ def interface_alias(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: The SONiC interface description, empty string if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down Expand Up @@ -199,15 +206,11 @@ def _get_counter(self, oid, table_name, mask):
mibs.logger.warning("SyncD 'COUNTERS_DB' missing attribute '{}'.".format(e))
return None

def _get_if_entry(self, sub_id):
def _get_if_entry(self, oid):
"""
:param oid: The 1-based sub-identifier query.
:return: the DB entry for the respective sub_id.
"""
oid = self.get_oid(sub_id)
if not oid:
return

if_table = ""
# Once PORT_TABLE will be moved to CONFIG DB
# we will get entry from CONFIG_DB for all cases
Expand All @@ -229,7 +232,19 @@ def get_high_speed(self, sub_id):
:param sub_id: The 1-based sub-identifier query.
:return: speed value for the respective sub_id or 40000 if not defined.
"""
entry = self._get_if_entry(sub_id)
oid = self.get_oid(sub_id)
if not oid:
return

if oid in self.oid_lag_name_map:
speed = 0
for lag_member in self.lag_name_if_name_map[self.oid_lag_name_map[oid]]:
entry = self._get_if_entry(mibs.get_index_from_str(lag_member))
if entry:
speed += int(entry.get("speed", 0))
return speed

entry = self._get_if_entry(oid)
if not entry:
return

Expand Down
12 changes: 9 additions & 3 deletions src/sonic_ax_impl/mibs/ietf/rfc4292.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ def update_data(self):
continue
port_table = multi_asic.get_port_table_for_asic(db_conn.namespace)
ent = db_conn.get_all(mibs.APPL_DB, route_str, blocking=False)
if ent is None:
if not ent:
continue
nexthops = ent.get("nexthop", None)
if nexthops is None:
mibs.logger.warning("Route has no nexthop: {} {}".format(route_str, str(ent)))
continue
ifnames = ent.get("ifname", None)
if ifnames is None:
mibs.logger.warning("Route has no ifname: {} {}".format(route_str, str(ent)))
continue
nexthops = ent["nexthop"]
ifnames = ent["ifname"]
for nh, ifn in zip(nexthops.split(','), ifnames.split(',')):
## Ignore non front panel interfaces
## TODO: non front panel interfaces should not be in APPL_DB at very beginning
Expand Down
Loading
Loading