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

[debug dump util] COPP Module Added #1670

Merged
merged 14 commits into from
Sep 17, 2021

Conversation

vivekrnv
Copy link
Contributor

@vivekrnv vivekrnv commented Jun 11, 2021

Signed-off-by: Vivek Reddy Karri vkarri@nvidia.com

What I did

HLD for Dump Utility: HLD.

  • Added the COPP Module to the Debug Dump Utility
  • Added the Corresponding UT's

How I did it

How to verify it

tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_all_args PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_custom_trap_with_default_grp PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_custom_trap_with_missing_group PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_default_grp_and_custom_trap_with_diff PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_default_trap_and_default_grp PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_default_trap_and_default_grp_with_diff PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_invalid_trap_id PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_missing_appl PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_missing_asic_dump PASSED [ 85%]
tests/dump_tests/module_tests/copp_test.py::TestCoppModule::test_missing_state PASSED [ 86%]

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

from dump.plugins.copp import Copp 
m_copp = Copp()
params = {Copp.ARG_NAME : "sample_packet", "sample_packet"  : "" }
dict = m_copp.execute(params)
print(dict)

{
    "CONFIG_DB": {
        "keys": [
            "COPP_GROUP|queue2_group1"
        ],
        "tables_not_found": []
    },
    "APPL_DB": {
        "keys": [
            "COPP_TABLE:queue2_group1"
        ],
        "tables_not_found": []
    },
    "ASIC_DB": {
        "keys": [
            "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP:oid:0x220000000004de",
            "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP_GROUP:oid:0x110000000004db",
            "ASIC_STATE:SAI_OBJECT_TYPE_POLICER:oid:0x120000000004dc",
            "ASIC_STATE:SAI_OBJECT_TYPE_QUEUE:oid:0x150000000002a1",
            "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TABLE_ENTRY:oid:0x230000000004d8",
            "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd0000000004d6"
        ],
        "tables_not_found": []
    },
    "STATE_DB": {
        "keys": [
            "COPP_TRAP_TABLE|sflow",
            "COPP_GROUP_TABLE|queue2_group1"
        ],
        "tables_not_found": []
    },
    "CONFIG_FILE": {
        "keys": [
            "COPP_TRAP|sflow",
            "COPP_GROUP|queue2_group1"
        ],
        "tables_not_found": []
    }
}
admin@sonic:~$ dump state copp bgp
{
    "bgp": {
        "CONFIG_DB": {
            "keys": [],
            "tables_not_found": []
        },
        "APPL_DB": {
            "keys": [
                {
                    "COPP_TABLE:queue4_group1": {
                        "queue": "4",
                        "trap_action": "trap",
                        "trap_ids": "bgp,bgpv6,lacp",
                        "trap_priority": "4"
                    }
                }
            ],
            "tables_not_found": []
        },
        "ASIC_DB": {
            "keys": [
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP:oid:0x22000000000c56": {
                        "SAI_HOSTIF_TRAP_ATTR_PACKET_ACTION": "SAI_PACKET_ACTION_TRAP",
                        "SAI_HOSTIF_TRAP_ATTR_TRAP_GROUP": "oid:0x11000000000c55",
                        "SAI_HOSTIF_TRAP_ATTR_TRAP_TYPE": "SAI_HOSTIF_TRAP_TYPE_BGP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP_GROUP:oid:0x11000000000c55": {
                        "SAI_HOSTIF_TRAP_GROUP_ATTR_QUEUE": "4"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_QUEUE:oid:0x15000000000626": {
                        "NULL": "NULL",
                        "SAI_QUEUE_ATTR_INDEX": "4",
                        "SAI_QUEUE_ATTR_TYPE": "SAI_QUEUE_TYPE_UNICAST"
                    }
                }
            ],
            "tables_not_found": [],
            "vidtorid": {
                "oid:0x22000000000c56": "oid:0x400300000022",
                "oid:0x11000000000c55": "oid:0x200000011",
                "oid:0x15000000000626": "oid:0x12e0000040015"
            }
        },
        "STATE_DB": {
            "keys": [
                {
                    "COPP_TRAP_TABLE|bgp": {
                        "state": "ok"
                    }
                },
                {
                    "COPP_GROUP_TABLE|queue4_group1": {
                        "state": "ok"
                    }
                }
            ],
            "tables_not_found": []
        },
        "CONFIG_FILE": {
            "keys": [
                {
                    "COPP_TRAP|bgp": {
                        "trap_ids": "bgp,bgpv6",
                        "trap_group": "queue4_group1"
                    }
                },
                {
                    "COPP_GROUP|queue4_group1": {
                        "trap_action": "trap",
                        "trap_priority": "4",
                        "queue": "4"
                    }
                }
            ],
            "tables_not_found": []
        }
    }
}


admin@sonic:~$ dump state copp arp_req --table --key-map
+-----------+-------------+-----------------------------------------------------------------------+
| trap_id   | DB_NAME     | DUMP                                                                  |
+===========+=============+=======================================================================+
| arp_req   | CONFIG_DB   | +------------------+                                                  |
|           |             | | Keys Collected   |                                                  |
|           |             | +==================+                                                  |
|           |             | +------------------+                                                  |
+-----------+-------------+-----------------------------------------------------------------------+
| arp_req   | APPL_DB     | +--------------------------+                                          |
|           |             | | Keys Collected           |                                          |
|           |             | +==========================+                                          |
|           |             | | COPP_TABLE:queue4_group2 |                                          |
|           |             | +--------------------------+                                          |
+-----------+-------------+-----------------------------------------------------------------------+
| arp_req   | ASIC_DB     | +-------------------------------------------------------------------+ |
|           |             | | Keys Collected                                                    | |
|           |             | +===================================================================+ |
|           |             | | ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP:oid:0x22000000000c5b       | |
|           |             | +-------------------------------------------------------------------+ |
|           |             | | ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF_TRAP_GROUP:oid:0x11000000000c59 | |
|           |             | +-------------------------------------------------------------------+ |
|           |             | | ASIC_STATE:SAI_OBJECT_TYPE_POLICER:oid:0x12000000000c5a           | |
|           |             | +-------------------------------------------------------------------+ |
|           |             | | ASIC_STATE:SAI_OBJECT_TYPE_QUEUE:oid:0x15000000000626             | |
|           |             | +-------------------------------------------------------------------+ |
|           |             | +----------------------+---------------------+                        |
|           |             | | vid                  | rid                 |                        |
|           |             | +======================+=====================+                        |
|           |             | | oid:0x22000000000c5b | oid:0x200000000022  |                        |
|           |             | +----------------------+---------------------+                        |
|           |             | | oid:0x11000000000c59 | oid:0x300000011     |                        |
|           |             | +----------------------+---------------------+                        |
|           |             | | oid:0x12000000000c5a | oid:0x200000012     |                        |
|           |             | +----------------------+---------------------+                        |
|           |             | | oid:0x15000000000626 | oid:0x12e0000040015 |                        |
|           |             | +----------------------+---------------------+                        |
+-----------+-------------+-----------------------------------------------------------------------+
| arp_req   | STATE_DB    | +--------------------------------+                                    |
|           |             | | Keys Collected                 |                                    |
|           |             | +================================+                                    |
|           |             | | COPP_TRAP_TABLE|arp            |                                    |
|           |             | +--------------------------------+                                    |
|           |             | | COPP_GROUP_TABLE|queue4_group2 |                                    |
|           |             | +--------------------------------+                                    |
+-----------+-------------+-----------------------------------------------------------------------+
| arp_req   | CONFIG_FILE | +--------------------------+                                          |
|           |             | | Keys Collected           |                                          |
|           |             | +==========================+                                          |
|           |             | | COPP_TRAP|arp            |                                          |
|           |             | +--------------------------+                                          |
|           |             | | COPP_GROUP|queue4_group2 |                                          |
|           |             | +--------------------------+                                          |
+-----------+-------------+-----------------------------------------------------------------------+

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@lgtm-com
Copy link

lgtm-com bot commented Jun 11, 2021

This pull request introduces 2 alerts when merging 05edcad into a425ca2 - view on LGTM.com

new alerts:

  • 2 for Unused import

@prsunny
Copy link
Contributor

prsunny commented Jun 11, 2021

@dgsudharsan , can you review/sign-off?

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

dgsudharsan
dgsudharsan previously approved these changes Jul 12, 2021
@vivekrnv
Copy link
Contributor Author

Request for 202106

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

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

as comments

dump/plugins/copp.py Show resolved Hide resolved
dump/plugins/copp.py Outdated Show resolved Hide resolved
dump/plugins/copp.py Show resolved Hide resolved
return sai_hostif_vid

def __get_asic_hostif_obj(self, sai_hostif_vid):
# Not adding tp tables_not_found because of the type of reason specified for policer obj
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is not correct

if not ret["error"] and len(ret["keys"]) > 0:
self.ret_temp["ASIC_DB"]["keys"].append(ret["keys"][0])

# When the user writes config to CONFIG_DB, that takes precedence over default config
Copy link
Contributor

Choose a reason for hiding this comment

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

indentation is not correct

elif trap_id_key_cf:
self.ret_temp["CONFIG_FILE"]["keys"].append(trap_id_key_cf)
self.copp_trap_cfg_key = trap_id_key_cf.split("|")[-1]
id_in_file, _ = self.__find_trap_id_in_db(self.copp_trap_cfg_key, False)
Copy link
Contributor

Choose a reason for hiding this comment

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

In line 247, the trap_id_key_cf is retrived only when there are no traps in the db. so in id_in_file will always be empty string and the key will not save to `ret_temp ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sry, i'll rename this to id_in_db.

And no, id_in_db can be trap_id_key_cf or NULL

Eg: Let's say user wanted a dump for trap_id: "ospfv6"

In Config File:

 "COPP_TRAP":{
        "bgp": {
              "trap_ids": "ospfv6,ospf"
         }
  }

In Config DB:

"COPP_TRAP": {
	    "bgp": {
		    "trap_ids": "bgp,bgpv6",
		    "trap_group": "queue4_group1"
	    }
}

In this case, after running trap_id_key_db, trap_group_db = self.__find_trap_id_in_db(), trap_id_key_db will still be empty as there is no direct way to find out the COPP_TRAP|bgp as the config DB entry doesn't have ospfv6,

We then find "trap_id_key_cf" from the file and the use that to find any diff present in the Config DB.

The complexity comes from the fact that there are two sources of truth for COPP config and you can provide a diff of any particular table (COPP_TRAP & COPP_GROUP) in any of the sources.

self.ret_temp["CONFIG_DB"]["keys"].append(trap_id_key_db)
self.copp_trap_cfg_key = trap_id_key_db.split("|")[-1]
id_in_file, _ = self.__find_trap_id_in_conf_file(self.copp_trap_cfg_key, False)
if id_in_file == trap_id_key_db: # If any diff
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems we add the trap_id to return ret_temp only when they are same. if they are different they are ignored ?

Copy link
Contributor Author

@vivekrnv vivekrnv Aug 20, 2021

Choose a reason for hiding this comment

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

id_in_file will either be trap_id_key_db or NULL/Empty String.

Eg: Let's say user wanted a dump for trap_id: "ospfv6"

In Config DB:

 "COPP_TRAP":{
        "bgp": {
              "trap_ids": "ospfv6,ospf"
         }
  }

In Config File:

"COPP_TRAP": {
	    "bgp": {
		    "trap_ids": "bgp,bgpv6",
		    "trap_group": "queue4_group1"
	    }
}

So, here we found out trap_id_key_db is bgp given ospfv6 as the trap_id. id_in_file is just a check in config file for any potential diff present in the COPP_TRAP|bgp key and thus id_in_file will either be "bgp" or NULL.

If it's NULL, we won't add it to the "CONFIG_FILE" section in the return template

from dump.helper import handle_error
from .executor import Executor

TRAP_ID_MAP = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this handle all the hostif traps defined in the SAI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, i've copied the table from copporch. LINK. Seems copporch doesn't handle all the hostif traps defined in the SAI

key_tg = ret["keys"][0]
self.ret_temp["CONFIG_FILE"]["keys"].append(key_tg)
return True
elif not_found_report:
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this elif ? seems like the not_found_report is always true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but just to keep the implementation consistent with __fill_trap_group_in_conf_db, i've retained it.

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vivekrnv
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link
Collaborator

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@vivekrnv
Copy link
Contributor Author

vivekrnv commented Sep 7, 2021

@SuvarnaMeenakshi and @arlakshm Can you finish the review and sign-off?

@dgsudharsan
Copy link
Collaborator

@arlakshm @SuvarnaMeenakshi Can you please review and sign off?

Copy link
Contributor

@arlakshm arlakshm left a comment

Choose a reason for hiding this comment

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

lgtm

@dgsudharsan
Copy link
Collaborator

@SuvarnaMeenakshi Can you please review and sign off?

@dgsudharsan
Copy link
Collaborator

@SuvarnaMeenakshi Can you please help here?

@SuvarnaMeenakshi SuvarnaMeenakshi merged commit c0b9917 into sonic-net:master Sep 17, 2021
SuvarnaMeenakshi pushed a commit that referenced this pull request Nov 10, 2021
What I did
Implemented vlan and vlan_member modules for debug dump utility.

How I did it
Used infrastructure and followed examples in
#1666
#1667
#1668
#1669
#1670

How to verify it
On switch: dump state vlan <vlan_name>
dump state vlan_member '<vlan_name|<member_name>'
Unit test: pytest-3 dump_tests/module_tests/vlan_test.py (same test file covers both vlan and vlan_member)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants