Skip to content

[multi-asic] Add namespace support for show/config subinterface commands#4298

Open
william8545 wants to merge 6 commits intosonic-net:masterfrom
william8545:multi-asic-subinterface
Open

[multi-asic] Add namespace support for show/config subinterface commands#4298
william8545 wants to merge 6 commits intosonic-net:masterfrom
william8545:multi-asic-subinterface

Conversation

@william8545
Copy link

What I did

Added multi-ASIC namespace support for show subinterfaces status and config subinterface (add | del) commands.

On multi-ASIC platforms, subinterfaces belong to a specific ASIC namespace. Previously, these commands did not accept a namespace option, so they could only operate on the default (host) namespace. This change enables users to target a specific ASIC namespace when showing or configuring subinterfaces.

How I did it

  • config subinterface (config/main.py): Added -n/--namespace option to the config subinterface group command. The namespace is required on multi-ASIC systems and is passed to ConfigDBConnector so that add/del operations target the correct per-ASIC config DB.

  • show subinterfaces status (show/main.py): Added @multi_asic_click_options decorator to inject the standard -n/--namespace and -d/--display options. These are forwarded to the intfutil script.

  • intfutil (scripts/intfutil): Updated the subinterface status display logic to:

    • Add a "Namespace" column when displaying subinterfaces across all namespaces on a multi-ASIC system.
    • Filter subinterfaces based on the multi-ASIC display rules (frontend vs. all) by checking parent port visibility via skip_display.
    • Include the current namespace value in each row when showing all namespaces.
  • show interfaces mpls (show/interfaces/__init__.py): Added a guard to skip subinterface entries (e.g., Ethernet0.100) when iterating PORT table keys, preventing KeyError on multi-ASIC systems where subinterface keys may appear alongside port keys.

  • Command Reference (doc/Command-Reference.md): Updated documentation for show subinterfaces status and config subinterface add/del to reflect the new namespace options, usage syntax, and multi-ASIC examples.

  • Unit tests: Added comprehensive multi-ASIC unit tests in tests/multi_asic_subintf_test.py covering:

    • show subinterfaces status with namespace filtering and "all" display
    • config subinterface add/del with namespace for Ethernet and PortChannel parent interfaces (both long and short names)
    • Namespace isolation, invalid parent interface, duplicate subinterface, duplicate encap VLAN, name length validation, LAG member check, and invalid format scenarios
    • Added mock table entries in tests/mock_tables/asic0/ and tests/mock_tables/asic1/ for subinterface testing
    • Updated tests/conftest.py with a setup_multi_asic_db fixture for multi-ASIC DB initialization
    • Extended tests/multi_asic_intfutil_test.py with subinterface status test cases

How to verify it

  1. On a multi-ASIC system, run:
    show subinterfaces status
    show subinterfaces status -n asic0
    show subinterfaces status -n asic1
    show subinterfaces status -d all
    
  2. Configure subinterfaces with namespace:
    sudo config subinterface -n asic0 add Ethernet0.100
    sudo config subinterface -n asic0 del Ethernet0.100
    sudo config subinterface -n asic1 add Eth64.200 200
    sudo config subinterface -n asic1 del Eth64.200
    
  3. Run unit tests:
    python -m pytest tests/multi_asic_subintf_test.py -v
    python -m pytest tests/multi_asic_intfutil_test.py -v
    

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

admin@sonic:~$ show subinterfaces status
Sub port interface    Speed    MTU    Vlan    Admin                 Type
------------------  -------  -----  ------  -------  -------------------
    Ethernet0.100     100G   9100    100       up  dot1q-encapsulation

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

Single namespace query:

admin@sonic:~$ show subinterfaces status -n asic0
Sub port interface    Speed    MTU    Vlan    Admin                 Type
------------------  -------  -----  ------  -------  -------------------
    Ethernet0.100     100G   9100    100       up  dot1q-encapsulation

All namespaces (no -n option on a multi-ASIC system):

admin@sonic:~$ show subinterfaces status
Sub port interface    Namespace    Speed    MTU    Vlan    Admin                 Type
------------------  -----------  -------  -----  ------  -------  -------------------
    Ethernet0.100        asic0     100G   9100    100       up  dot1q-encapsulation
   Ethernet64.10        asic1     100G   9100     10       up  dot1q-encapsulation

Signed-off-by: William Tsai <willtsai@nvidia.com>
Signed-off-by: William Tsai <willtsai@nvidia.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: William Tsai <willtsai@nvidia.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: William Tsai <willtsai@nvidia.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: William Tsai <willtsai@nvidia.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: William Tsai <willtsai@nvidia.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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