Skip to content

Switchport mode update for 'show interfaces status'#3788

Merged
qiluo-msft merged 4 commits intosonic-net:masterfrom
cshivashgit:show_interfaces_fix
Jul 22, 2025
Merged

Switchport mode update for 'show interfaces status'#3788
qiluo-msft merged 4 commits intosonic-net:masterfrom
cshivashgit:show_interfaces_fix

Conversation

@cshivashgit
Copy link
Contributor

@cshivashgit cshivashgit commented Feb 27, 2025

What I did

Fixed "show interfaces status" output for interfaces with switchport mode configuration.

How I did it

Configured "switchport mode" is fetched from DB for all front panel ports and PortChannel interfaces.
"Vlan" column in "show interface status" is displayed based on below considerations:

  1. If interface is part of PortChannel - display PortChannel interface name [present behavior]
  2. If "switchport mode" is configured on interface [Ethernet/PortChannel] - display configured mode [new behavior]
  3. If "switchport mode" is NOT configured on interface but part of a VLAN [Ethernet/PortChannel] - display as "trunk" [present behavior]
  4. If "switchport mode" is NOT configured on interface and NOT part of a VLAN [Ethernet/PortChannel] - display as "routed" [present behavior]

How to verify it

Configure "switchport mode" for an interface/portchannel and verify the output in below show commands

  1. show interfaces switchport status
  2. show interfaces status

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

Previously it was always displaying as trunk even if interface is configured as access

root@sonic:~# config switchport mode access Ethernet0
Ethernet0 switched to access mode

root@sonic:~# show interfaces switchport status | grep Ethernet0
Ethernet0    access

root@sonic:~#
root@sonic:~# show interfaces status | grep Ethernet0
  Ethernet0  2304,2305,2306,2307     100G   9100    N/A     etp0   trunk      up       up  QSFP28 or later         N/A

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

root@sonic:~# config switchport mode access Ethernet0
Ethernet0 switched to access mode

root@sonic:~# show interfaces switchport status | grep Ethernet0
Ethernet0    access

root@sonic:~#
root@sonic:~# show interfaces status | grep Ethernet0
  Ethernet0  2304,2305,2306,2307     100G   9100    N/A     etp0   access      up       up  QSFP28 or later         N/A

closes #3787

@mssonicbld
Copy link
Collaborator

/azp run

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 27, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cshivashgit
Copy link
Contributor Author

@wen587 @xwjiang-ms please review

FengPan-Frank
FengPan-Frank previously approved these changes Mar 10, 2025
@wen587
Copy link
Contributor

wen587 commented Mar 11, 2025

Could we add some ut for the new support?

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

RCA:
According to present design port was conisdered as "trunk" if its part of
a VLAN, there was no handling to fetch the acutal mode from Redis DB
regarding the configured switchport mode.

Solution:
Configured "switchport mode" is fetched from DB for all front panel ports and
PortChannel interfaces.
"Vlan" column in "show interface status"  is displayed based on below considerations:
1. If interface is part of PortChannel - display PortChannel interface name [present behavior]
2. If "switchport mode" is configured on interface [Ethernet/PortChannel] - display configured mode [new behavior]
3. If "switchport mode" is NOT configured on interface but part of a VLAN [Ethernet/PortChannel] - display as "trunk" [present behavior]
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cshivashgit cshivashgit force-pushed the show_interfaces_fix branch from 5f3096f to 76d9279 Compare June 6, 2025 08:18
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cshivashgit cshivashgit force-pushed the show_interfaces_fix branch from 76d9279 to 4344831 Compare June 6, 2025 08:35
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@cshivashgit
Copy link
Contributor Author

Could we add some ut for the new support?

@wen587 : UT cases are added, please review.

wsycqyz
wsycqyz previously approved these changes Jun 24, 2025
Copy link

@wsycqyz wsycqyz left a comment

Choose a reason for hiding this comment

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

lğtm

@vrajeshe
Copy link

vrajeshe commented Jul 1, 2025

@wsycqyz
sonic-net/sonic-mgmt#17442
this is the tests for the same Pull req

@vrajeshe
Copy link

Hi @prgeor can you please check and merge this.

Thanks

@vrajeshe
Copy link

Sonic-Mgmt testcases for this PR
sonic-net/sonic-mgmt#17442

@vrajeshe
Copy link

Hi @prsunny Can you kindly help in merging this.

@prsunny
Copy link
Contributor

prsunny commented Jul 18, 2025

@vrajeshe , can you update one more line in description

  1. If "switchport mode" is NOT configured on interface and NOT part of a VLAN [Ethernet/PortChannel] - display as "routed"?

Basically want to ensure we don't change the existing behavior if switchport is not configured to 'access'.

@FengPan-Frank to review/approve

@cshivashgit
Copy link
Contributor Author

@vrajeshe , can you update one more line in description

  1. If "switchport mode" is NOT configured on interface and NOT part of a VLAN [Ethernet/PortChannel] - display as "routed"?

Basically want to ensure we don't change the existing behavior if switchport is not configured to 'access'.

@FengPan-Frank to review/approve

@prsunny Updated the description. Yes that is the present behaviour, we have not changed that.

FengPan-Frank
FengPan-Frank previously approved these changes Jul 21, 2025
Copy link
Contributor

@FengPan-Frank FengPan-Frank left a comment

Choose a reason for hiding this comment

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

LGTM

prsunny
prsunny previously approved these changes Jul 21, 2025
@prsunny
Copy link
Contributor

prsunny commented Jul 22, 2025

@qiluo-msft to merge

@qiluo-msft qiluo-msft requested a review from Copilot July 22, 2025 22:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the "show interfaces status" command to properly display switchport modes in the "Vlan" column. Previously, interfaces configured with "switchport mode access" would incorrectly show as "trunk" in the status output.

Key changes:

  • Refactored interface vlan/mode determination logic to prioritize configured switchport modes
  • Added comprehensive test coverage for switchport mode verification
  • Updated the display logic to show configured switchport modes instead of inferring from VLAN membership

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
scripts/intfutil Refactored vlan determination logic to use switchport mode configuration and updated function signatures
tests/vlan_test.py Added test helper function and switchport mode verification to existing tests

def setup_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "1"
os.environ["PATH"] += os.pathsep + scripts_path
os.environ['UTILITIES_UNIT_TESTING'] = "2"
Copy link

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

The environment variable value changed from "1" to "2" without explanation. This magic number should be documented or use a descriptive constant to clarify why this change was made.

Suggested change
os.environ['UTILITIES_UNIT_TESTING'] = "2"
os.environ['UTILITIES_UNIT_TESTING'] = UNIT_TESTING_MODE_ENABLED

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@qiluo-msft qiluo-msft dismissed stale reviews from prsunny, FengPan-Frank, and wsycqyz via 2e81b49 July 22, 2025 22:17
@mssonicbld
Copy link
Collaborator

/azp run

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@azure-pipelines
Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft enabled auto-merge (squash) July 22, 2025 22:19
@qiluo-msft qiluo-msft merged commit e18640e into sonic-net:master Jul 22, 2025
7 checks passed
@cshivashgit
Copy link
Contributor Author

@qiluo-msft : Can you please help me in merging this PR to 202505 branch as well?
I was not able to add the label Request for 202505 Branch

CC: @prsunny

@qiluo-msft
Copy link
Contributor

@yejianquan please help check 202505.

@Aravind-Subbaroyan
Copy link

@yejianquan - Could you please help to cherry-pick for 202505?

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202505: #4035

YairRaviv pushed a commit to YairRaviv/sonic-utilities that referenced this pull request Jan 12, 2026
What I did
Fixed "show interfaces status" output for interfaces with switchport mode configuration.

How I did it
Configured "switchport mode" is fetched from DB for all front panel ports and PortChannel interfaces.
"Vlan" column in "show interface status" is displayed based on below considerations:

If interface is part of PortChannel - display PortChannel interface name [present behavior]
If "switchport mode" is configured on interface [Ethernet/PortChannel] - display configured mode [new behavior]
If "switchport mode" is NOT configured on interface but part of a VLAN [Ethernet/PortChannel] - display as "trunk" [present behavior]
If "switchport mode" is NOT configured on interface and NOT part of a VLAN [Ethernet/PortChannel] - display as "routed" [present behavior]
How to verify it
Configure "switchport mode" for an interface/portchannel and verify the output in below show commands

show interfaces switchport status
show interfaces status
Previous command output (if the output of a command-line utility has changed)
Previously it was always displaying as trunk even if interface is configured as access

root@sonic:~# config switchport mode access Ethernet0
Ethernet0 switched to access mode

root@sonic:~# show interfaces switchport status | grep Ethernet0
Ethernet0    access

root@sonic:~#
root@sonic:~# show interfaces status | grep Ethernet0
  Ethernet0  2304,2305,2306,2307     100G   9100    N/A     etp0   trunk      up       up  QSFP28 or later         N/A
New command output (if the output of a command-line utility has changed)
root@sonic:~# config switchport mode access Ethernet0
Ethernet0 switched to access mode

root@sonic:~# show interfaces switchport status | grep Ethernet0
Ethernet0    access

root@sonic:~#
root@sonic:~# show interfaces status | grep Ethernet0
  Ethernet0  2304,2305,2306,2307     100G   9100    N/A     etp0   access      up       up  QSFP28 or later         N/A
closes sonic-net#3787
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.

"show interfaces status" always shows port as trunk port