Skip to content

[debug dump util] Route Module added#16

Closed
vivekrnv wants to merge 7 commits intomasterfrom
dump_module_route
Closed

[debug dump util] Route Module added#16
vivekrnv wants to merge 7 commits intomasterfrom
dump_module_route

Conversation

@vivekrnv
Copy link
Copy Markdown
Owner

@vivekrnv vivekrnv commented Aug 4, 2021

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

What I did

HLD for Dump Utility: HLD.

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

How I did it

How to verify it

tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_all_args PASSED                                                                                                                                                    [ 11%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_caching_redis_keys PASSED                                                                                                                                          [ 22%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_directly_connected_route PASSED                                                                                                                                    [ 33%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_ip2me_route PASSED                                                                                                                                                 [ 44%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_no_next_hop_id PASSED                                                                                                                                              [ 55%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_no_route_entry PASSED                                                                                                                                              [ 66%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_route_with_next_hop PASSED                                                                                                                                         [ 77%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_route_with_next_hop_group PASSED                                                                                                                                   [ 88%]
tests/dump_tests/module_tests/route_test.py::TestRouteModule::test_static_route PASSED   

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)

admin@r-tigon-11:~$ dump state route 200.0.1.0/26
{
    "200.0.1.0/26": {
        "APPL_DB": {
            "keys": [
                {
                    "ROUTE_TABLE:200.0.1.0/26": {
                        "ifname": "PortChannel0004,PortChannel0007",
                        "nexthop": "10.0.0.37,10.0.0.41"
                    }
                }
            ],
            "tables_not_found": []
        },
        "ASIC_DB": {
            "keys": [
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY:{\"dest\":\"200.0.1.0/26\",\"switch_id\":\"oid:0x21000000000000\",\"vr\":\"oid:0x3000000000002\"}": {
                        "SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID": "oid:0x5000000000c92"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_VIRTUAL_ROUTER:oid:0x3000000000002": {
                        "NULL": "NULL"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000c92": {
                        "SAI_NEXT_HOP_GROUP_ATTR_TYPE": "SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000c72": {
                        "SAI_NEXT_HOP_GROUP_ATTR_TYPE": "SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000c4f": {
                        "SAI_NEXT_HOP_GROUP_ATTR_TYPE": "SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP:oid:0x5000000000c57": {
                        "SAI_NEXT_HOP_GROUP_ATTR_TYPE": "SAI_NEXT_HOP_GROUP_TYPE_DYNAMIC_UNORDERED_ECMP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER:oid:0x2d000000000c94": {
                        "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": "oid:0x5000000000c92",
                        "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID": "oid:0x4000000000c49"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP_GROUP_MEMBER:oid:0x2d000000000c93": {
                        "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID": "oid:0x5000000000c92",
                        "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_ID": "oid:0x4000000000c1c"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP:oid:0x4000000000c49": {
                        "SAI_NEXT_HOP_ATTR_IP": "10.0.0.41",
                        "SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID": "oid:0x6000000000b47",
                        "SAI_NEXT_HOP_ATTR_TYPE": "SAI_NEXT_HOP_TYPE_IP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP:oid:0x4000000000c1c": {
                        "SAI_NEXT_HOP_ATTR_IP": "10.0.0.37",
                        "SAI_NEXT_HOP_ATTR_ROUTER_INTERFACE_ID": "oid:0x6000000000b44",
                        "SAI_NEXT_HOP_ATTR_TYPE": "SAI_NEXT_HOP_TYPE_IP"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000b47": {
                        "SAI_ROUTER_INTERFACE_ATTR_MTU": "9100",
                        "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000b1f",
                        "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": "1C:34:DA:1D:EA:00",
                        "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT",
                        "SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": "oid:0x3000000000002"
                    }
                },
                {
                    "ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x6000000000b44": {
                        "SAI_ROUTER_INTERFACE_ATTR_MTU": "9100",
                        "SAI_ROUTER_INTERFACE_ATTR_PORT_ID": "oid:0x2000000000b1c",
                        "SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS": "1C:34:DA:1D:EA:00",
                        "SAI_ROUTER_INTERFACE_ATTR_TYPE": "SAI_ROUTER_INTERFACE_TYPE_PORT",
                        "SAI_ROUTER_INTERFACE_ATTR_VIRTUAL_ROUTER_ID": "oid:0x3000000000002"
                    }
                }
            ],
            "tables_not_found": [],
            "vidtorid": {
                "oid:0x3000000000002": "oid:0x3",
                "oid:0x5000000000c92": "oid:0x3900000005",
                "oid:0x5000000000c72": "oid:0x3800000005",
                "oid:0x5000000000c4f": "oid:0x3300000005",
                "oid:0x5000000000c57": "oid:0x3500000005",
                "oid:0x2d000000000c94": "oid:0x3000390000002d",
                "oid:0x2d000000000c93": "oid:0x500390000002d",
                "oid:0x4000000000c49": "oid:0x3000000004",
                "oid:0x4000000000c1c": "oid:0x500000004",
                "oid:0x6000000000b47": "oid:0x1c100000006",
                "oid:0x6000000000b44": "oid:0x10100000006"
            }
        }
    }
}

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>
"distance": "0",
"ifname": ",",
"nexthop": "1.1.1.2",
"nexthop-vrf": ","
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correct indentation.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Handled

"ifname": "PortChannel0001,PortChannel0002,PortChannel0003,PortChannel0004",
"nexthop": "fc00::72,fc00::76,fc00::7a,fc00::7e"
}
} No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Missing newline.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Handled

ddiff = DeepDiff(returned, expect, ignore_order=True)
assert not ddiff, ddiff

def test_caching_redis_keys(self, match_engine):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is there a way to test whether return comes from cache or redis call?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Added that check

"SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID":"oid:0x60000000002cd"
},
"ASIC_STATE:SAI_OBJECT_TYPE_ROUTER_INTERFACE:oid:0x60000000002cd": {
"SAI_ROUTER_INTERFACE_ATTR_MTU": "9100",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Have uniform indentation.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Handled

"nexthop":"::"
},
"ROUTE_TABLE:20c0:e6e0:0:80::/64": {
"ifname": "PortChannel0001,PortChannel0002,PortChannel0003,PortChannel0004",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Correct indentation here and below

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Handled

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

class NextHopGroupMatchOptimizer():
"""
A Stateful Wrapper which optimizes the the queries by caching the redis keys.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a type: double the.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done!, Thanks

"""

def __init__(self, m_engine):
self.key_cache = dict()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggest to use one way to initialize dictionary.
In some places it is dict() and in some {}, e.g. line 27.
(BTW, {} is a bit faster comparing to dict())

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done!, Thanks

def __init__(self, route_obj):
self.rt = route_obj

def collect(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like it is abstract method which is required to be overridden by derived classes.
At least I as I see all derived classes always implement it so it looks likes it is must.
If it is the case then there is recommended exception to raise in base class in such abstract methods: NotImplementedError

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This is invoked from here:

def init_asic_nh(self):
        self.nh_type = self.get_nh_type()
        nh_ex = NHExtractor.initialize(self) # This will call the actual derived class of NHExtractor
        nh_ex.collect()
@staticmethod
    def initialize(route_obj):
        if route_obj.nh_type == NH:
            return SingleNextHop(route_obj)
        elif route_obj.nh_type == NH_GRP:
            return MultipleNextHop(route_obj)
        elif route_obj.nh_type == RIF:
            return DirecAttachedRt(route_obj)
        elif route_obj.nh_type == CPU_PORT:
            return CPUPort(route_obj)
        return NHExtractor(route_obj)

When a nh_type apart from NH, NH_GRP, RIF or CPU_PORT is provided, the base class itself is initialized, so a NotImplemented exception will cause the dump module to not exit gracefully.

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
@vivekrnv vivekrnv closed this Nov 6, 2021
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.

3 participants