-
Notifications
You must be signed in to change notification settings - Fork 114
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
[Namespace] Fix interfaces counters in InterfacesMIB RFC 2863 #141
Conversation
multi-asic platforms. In multi-asic platforms SAI oid is not unique across namespace/asic. Use interface index as the key instead of using SAI oid. Signed-off-by: SuvarnaMeenakshi <[email protected]>
to reduce time taken. Signed-off-by: SuvarnaMeenakshi <[email protected]> (cherry picked from commit 16f36d8)
platform. Signed-off-by: SuvarnaMeenakshi <[email protected]>
Do not run namespace unit-test for MIBs using SAI id as key. Signed-off-by: SuvarnaMeenakshi <[email protected]>
Signed-off-by: SuvarnaMeenakshi <[email protected]>
Signed-off-by: SuvarnaMeenakshi <[email protected]>
Signed-off-by: SuvarnaMeenakshi <[email protected]>
@@ -4,6 +4,7 @@ | |||
from sonic_ax_impl import mibs | |||
from ax_interface.mib import MIBMeta, MIBUpdater, ValueType, SubtreeMIBEntry, OverlayAdpaterMIBEntry, OidMIBEntry | |||
from sonic_ax_impl.mibs import Namespace | |||
from swsssdk.port_util import get_index_from_str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[](start = 30, length = 1)
One extra blank #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/sonic_ax_impl/mibs/__init__.py
Outdated
@@ -160,6 +160,22 @@ def mgmt_if_entry_table_state_db(if_name): | |||
|
|||
return b'MGMT_PORT_TABLE|' + if_name | |||
|
|||
def get_sai_id_key(namespace, sai_id): | |||
sai_id = sai_id.decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decode [](start = 20, length = 6)
decode and encode will applied to single ASIC and this could be optimized. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/sonic_ax_impl/mibs/__init__.py
Outdated
def get_sai_id_key(namespace, sai_id): | ||
sai_id = sai_id.decode() | ||
if namespace != '': | ||
key = namespace + ':' + sai_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace + ':' + sai_id [](start = 14, length = 24)
why not just concat b':' without decoding? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified as per comment.
src/sonic_ax_impl/mibs/__init__.py
Outdated
def split_sai_id_key(sai_id_key): | ||
sai_id_key = sai_id_key.decode() | ||
if ':' in sai_id_key: | ||
namespace, sai_id = sai_id_key.split(':') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split(':') [](start = 39, length = 10)
Why not just split(b':')
without decoding? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified as per comment.
@@ -221,7 +237,8 @@ def init_sync_d_interface_tables(db_conn): | |||
if_name_map = {if_name: sai_id for if_name, sai_id in if_name_map.items() if \ | |||
(re.match(port_util.SONIC_ETHERNET_RE_PATTERN, if_name.decode()) or \ | |||
re.match(port_util.SONIC_ETHERNET_BP_RE_PATTERN, if_name.decode()))} | |||
if_id_map = {sai_id: if_name for sai_id, if_name in if_id_map.items() if \ | |||
# sai_id_key = namespace : sai_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: [](start = 29, length = 1)
This is a new assumption that ':' will not appear in name space or sai_id. Please add code comment. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using '|' which is widely used in Redis keys
In reply to: 453139692 [](ancestors = 453139692)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment.
if_idx = get_index_from_str(self.if_id_map[sai_id_key].decode()) | ||
for db in self.db_conn: | ||
if db.namespace == namespace: | ||
self.if_counters[if_idx] = db.get_all(mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.if_counters[if_idx] = db.get_all(mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True) [](start = 20, length = 98)
break after this line? #Closed
namespace, sai_id = mibs.split_sai_id_key(sai_id_key) | ||
if_idx = get_index_from_str(self.if_id_map[sai_id_key].decode()) | ||
for db in self.db_conn: | ||
if db.namespace == namespace: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not efficient, because you search self.db_conn
too many times.
Propose 2 alternative solutions:
- create a map (namespace -> db)
- use db_index instread of namespace in
get_sai_id_key
#Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a map, db_index cannot be obtained directly in this function and will have to be passed as an additional argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiluo-msft thanks for pointing out.
we discussed to have map but to avoid new map went with this approach of checking namespace and break considering loop is small.
tests/namespace/test_fdb.py
Outdated
@@ -23,6 +23,7 @@ | |||
class TestSonicMIB(TestCase): | |||
@classmethod | |||
def setUpClass(cls): | |||
cls.skipTest(cls, "Namespace not implemented") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
skipTest [](start = 12, length = 8)
What is the meaning of "Namespace not implemented"?
Why you skip test? #Pending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For multi-asic platform, the change is made to if_id_map key to store namespace and sai id together.
with this change, MIBS using this key have to be updated to use the new type of key.
Instead of making this change on all MIBS together in same PR, will make change in other PRs.
So, for multi-asic platform, the unit-tests for these MIB implementations are skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SuvarnaMeenakshi better we should add similar comment in test case itself as TODO so that is easy to understand and track
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment with TODO
Signed-off-by: SuvarnaMeenakshi <[email protected]>
src/sonic_ax_impl/mibs/__init__.py
Outdated
Return value: namespace:sai id or sai id | ||
""" | ||
if namespace != '': | ||
sai_id_key = namespace + ':' + sai_id.decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace + ':' + sai_id.decode() [](start = 22, length = 33)
return namespace.encode() + b':' + sai_id
This will be easier and shorter. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as per comment.
Add a new dict of namespace:db connector for easier access. Signed-off-by: SuvarnaMeenakshi <[email protected]>
Signed-off-by: SuvarnaMeenakshi <[email protected]>
src/sonic_ax_impl/mibs/__init__.py
Outdated
""" | ||
if b':' in sai_id_key: | ||
namespace, sai_id = sai_id_key.split(b':') | ||
return namespace.decode(), sai_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can split first and check result len().
This will scan the string only once. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated as per comment.
Signed-off-by: SuvarnaMeenakshi <[email protected]>
This pull request introduces 2 alerts when merging 5a54bdb into 1d210d9 - view on LGTM.com new alerts:
|
@SuvarnaMeenakshi Please fix 2 new alerts |
* [InterfacesMIB]: Fix counters in InterfacesMIB for multi-asic platforms. In multi-asic platforms SAI oid is not unique across namespace/asic. Use interface index as the key instead of using SAI oid. Signed-off-by: SuvarnaMeenakshi <[email protected]> * [Namespace]: Remove key exists check in dbs_get_all to reduce time taken. Signed-off-by: SuvarnaMeenakshi <[email protected]> (cherry picked from commit 16f36d8) * Change the key used in if_id_map to support multi-asic platform. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Fix interface counters only for rfc2863. Do not run namespace unit-test for MIBs using SAI id as key. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Fix getting interface index in InterfacesMIB Signed-off-by: SuvarnaMeenakshi <[email protected]> * Remove debug print. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Remove db connect that is not required. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Modify as per review comments. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Fix as per review comment. Add a new dict of namespace:db connector for easier access. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Fix as per review comment. Signed-off-by: SuvarnaMeenakshi <[email protected]> * Modify based on review comment. Signed-off-by: SuvarnaMeenakshi <[email protected]> Co-authored-by: abdosi <[email protected]>
- What I did
In multi-asic platform, SAI OID is not unique for the whole device. It is unique for an asic and within a single namespace.
This PR is to fix InterfacesMIB rfc2863 implementation to make sure that interfaces counters is keyed based on interface index and not SAI OID.
- How I did it
FDB/PFC and InterfacesMIB in rfc1213.
- How to verify it
Tested InterfacesMIB snmp query on multi-asic platform.
- Description for the changelog