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

[Namespace]: Fix SAI_ID key used in cpfcIfTable and csqIfQosGroupStatsTable implementation #138

Merged
merged 11 commits into from
Aug 13, 2020

Conversation

SuvarnaMeenakshi
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi commented Jul 4, 2020

Signed-off-by: SuvarnaMeenakshi sumeenak@microsoft.com

- 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 make sure that data structures that use SAI Object ID as a key to retrieve data from COUNTERS_DB updated so that a combination of SAI Object ID and port index is used as a key.
- How I did it

  • Update data structure to use combination SAI Object ID and port index as a key to retrieve data from COUNTERS_DB.
  • Update Unit-test mock DB in namespaces, to reflect the scenario where SAI Object is same across different namespaces.
  • Updates done to MIB implementation for the below MIB tables to get data from the right database instances:
    • cpfcIfTable
    • csqIfQosGroupStatsTable

- How to verify it

- Description for the changelog

unique across the device. The SAI object ID is unique for asic
or within a namespace. Modify the existing code to make sure that
data structures using SAI OID, it is not used as a key directly.
Modify implementation for MIB tables using COUNTER_DB and ASIC_DB
so that SAI OID is used to retrieve data only from a single
namespace.
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Jul 4, 2020

This pull request introduces 4 alerts when merging 7a02ecc into eba1408 - view on LGTM.com

new alerts:

  • 2 for Syntax error
  • 1 for Mismatch in multiple assignment
  • 1 for Wrong number of arguments in a call

@rlhui rlhui requested review from abdosi, qiluo-msft and zhenggen-xu and removed request for zhenggen-xu July 7, 2020 19:25
{sai_id: Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB, mibs.counter_table(sai_id), blocking=True)
for sai_id in self.if_id_map}
{if_idx: self.db_conn[self.if_oid_namespace[if_idx]].get_all(
mibs.COUNTERS_DB, mibs.counter_table(self.oid_sai_map[if_idx]), blocking=True)
Copy link
Contributor

@abdosi abdosi Jul 8, 2020

Choose a reason for hiding this comment

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

Missing for loop of retrieving if_idx. Apply for all below files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the loop.

@@ -1,11 +1,11 @@
{
"ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY:{\"bridge_id\":\"oid:0x0\",\"bridge_type\":\"SAI_FDB_ENTRY_BRIDGE_TYPE_1Q\",\"mac\":\"7C:FE:90:80:9F:10\",\"switch_id\":\"oid:0x21000000000000\",\"vlan\":\"1000\"}": {
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID": "oid:0x3a0000000006208",
"SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID": "oid:0x3a000000000616",
Copy link
Contributor

Choose a reason for hiding this comment

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

what trigger this changes ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified namespace mock dbs to reflect the idea that SAI ID will be repeated across namespaces.

@@ -320,7 +320,8 @@ def init_sync_d_queue_tables(db_conn):
queue_stat_name = queue_table(sai_id)
Copy link
Contributor

@qiluo-msft qiluo-msft Jul 8, 2020

Choose a reason for hiding this comment

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

queue_stat_name [](start = 8, length = 15)

SAI Object ID is unique in this db_conn. So the original implementation of init_sync_d_queue_tables makes sense.

Let's block this PR and continue exploration the dbs dict strategy, as also discussed in another PR (#137) #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As the data will eventually merged together , we have to make sure that the keys are unique in these dictionaries.
So in maps which use SAI ID as key, modified it to use a combination of if_idx and SAI ID.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Revert FDB MIB namespace related changes.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@lgtm-com
Copy link

lgtm-com bot commented Aug 4, 2020

This pull request introduces 2 alerts when merging 7657c72 into 90e9f2e - view on LGTM.com

new alerts:

  • 1 for First parameter of a method is not named 'self'
  • 1 for Non-callable called

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@qiluo-msft
Copy link
Contributor

qiluo-msft commented Aug 5, 2020

# { Port index : Queue index (SONiC) -> sai_id }

Sorry this is not your fault. The correct comment should be "Port name". #Closed


Refers to: src/sonic_ax_impl/mibs/init.py:336 in ce764d1. [](commit_id = ce764d1, deletion_comment = False)

@@ -339,8 +339,8 @@ def init_sync_d_queue_tables(db_conn):
logger.debug("Queue name map:\n" + pprint.pformat(queue_name_map, indent=2))

# Parse the queue_name_map and create the following maps:
# port_queues_map -> {"if_index : queue_index" : sai_oid}
# queue_stat_map -> {queue stat table name : {counter name : value}}
# port_queues_map -> {"if_name : queue_index" : sai_oid}
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 5, 2020

Choose a reason for hiding this comment

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

if_name [](start = 27, length = 7)

It should be "port_index"? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this, it should be port_index and not port_name.

@qiluo-msft
Copy link
Contributor

qiluo-msft commented Aug 5, 2020

# ex: { "1:2" : "1000000000023" }

Ethernet0:2 #Closed


Refers to: src/sonic_ax_impl/mibs/init.py:337 in 661ffe9. [](commit_id = 661ffe9, deletion_comment = False)

@@ -65,6 +65,7 @@ def __init__(self):
self.mib_oid_list = []

self.queue_type_map = {}
self.if_id_namespace = {}
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 5, 2020

Choose a reason for hiding this comment

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

if_ [](start = 13, length = 3)

The concept in this MIB is port, not interface. Suggest rename if_* to port_* #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have modified the naming in this file.

Fix variable name used in ciscoSwitchQosMIB and queue related
init function.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@SuvarnaMeenakshi
Copy link
Contributor Author

# ex: { "1:2" : "1000000000023" }

Ethernet0:2

Refers to: src/sonic_ax_impl/mibs/init.py:337 in 661ffe9. [](commit_id = 661ffe9, deletion_comment = False)

This is port_index, so existing comment is good.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@SuvarnaMeenakshi
Copy link
Contributor Author

# { Port index : Queue index (SONiC) -> sai_id }

Sorry this is not your fault. The correct comment should be "Port name".

Refers to: src/sonic_ax_impl/mibs/init.py:336 in ce764d1. [](commit_id = ce764d1, deletion_comment = False)

Fixed as suggested.

@SuvarnaMeenakshi
Copy link
Contributor Author

# ex: { "1:2" : "1000000000023" }

Ethernet0:2
Refers to: src/sonic_ax_impl/mibs/init.py:337 in 661ffe9. [](commit_id = 661ffe9, deletion_comment = False)

This is port_index, so existing comment is good.

The correct comment is port_name, Fixed as suggested.

qiluo-msft
qiluo-msft previously approved these changes Aug 5, 2020
@SuvarnaMeenakshi SuvarnaMeenakshi changed the title [Namespace]: Fix code to avoid using SAI object ID as key [Namespace]: Fix SAI_ID key used in cpfcIfTable and csqIfQosGroupStatsTable implementation Aug 7, 2020
queue_stat = Namespace.dbs_get_all(self.db_conn, mibs.COUNTERS_DB, queue_stat_name, blocking=False)
if_index, _ = queue_key.split(':')
queue_stat_idx = mibs.queue_key(if_index, queue_stat_name)
queue_stat = self.queue_stat_map.get(queue_stat_idx, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

can queue_stat be None ? Do we have to do this check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can queue_stat be None ? Do we have to do this check

We have a check in the line below to check if queue_stat is not None.

Copy link
Contributor

Choose a reason for hiding this comment

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

my point was can it be ever None ? do we need to put if condition ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake, none check is required the same as in: https://github.com/SuvarnaMeenakshi/sonic-snmpagent/blob/counters_fix/src/sonic_ax_impl/mibs/__init__.py#L358.
I have fixed the code to do a get_all to get the updated stats.
The previous code was providing the correct results as each time reinit_data was invoked, the stats was getting updated.
But update data is called more frequently, and update_data also should do a get_all each time, after which the None check will be required.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
queue_stat_idx = mibs.queue_key(port_index, queue_stat_name)
namespace = self.port_index_namespace[int(port_index)]
queue_stat = self.namespace_db_map[namespace].get_all( \
mibs.COUNTERS_DB, queue_stat_name, blocking=False)
if queue_stat is not None:
Copy link
Contributor

@qiluo-msft qiluo-msft Aug 8, 2020

Choose a reason for hiding this comment

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

if queue_stat is not None [](start = 12, length = 25)

Otherwise, del the index from self.queue_stat_map #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if queue_stat is not None [](start = 12, length = 25)

Otherwise, del the index from self.queue_stat_map

Added as per comment.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
qiluo-msft
qiluo-msft previously approved these changes Aug 8, 2020
@@ -88,13 +91,12 @@ def _get_counter(self, oid, counter_name):
:param counter_name: the redis table (either IntEnum or string literal) to query.
:return: the counter for the respective sub_id/table.
"""
sai_id = self.oid_sai_map[oid]
Copy link
Contributor

Choose a reason for hiding this comment

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

is oid_sai_map is being used or this can be removed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed oid_sai_map as it is not required. The required information can be retrieved from oid_name_map.

The required data can be retrieved from oid_name_map data structure.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
@qiluo-msft
Copy link
Contributor

Retest this please

@SuvarnaMeenakshi SuvarnaMeenakshi merged commit 1a2b62a into sonic-net:master Aug 13, 2020
abdosi pushed a commit that referenced this pull request Sep 28, 2020
…sTable implementation (#138)

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 make sure that data structures that use SAI Object ID as a key to retrieve data from COUNTERS_DB updated so that a combination of SAI Object ID and port index is used as a key.
Update data structure to use combination SAI Object ID and port index as a key to retrieve data from COUNTERS_DB.
Update Unit-test mock DB in namespaces, to reflect the scenario where SAI Object is same across different namespaces.
Updates done to MIB implementation for the below MIB tables to get data from the right database instances:
cpfcIfTable
csqIfQosGroupStatsTable
* Remove usage of oid_sai_map data structure as it is not being used.
The required data can be retrieved from oid_name_map data structure.

Signed-off-by: SuvarnaMeenakshi <sumeenak@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants