Skip to content

[Nexthop][fboss2-dev] sort show interface status and transceiver by numeric interface ID - #1422

Open
benoit-nexthop wants to merge 1 commit into
facebook:mainfrom
nexthop-ai:fboss2-sort-interfaces
Open

[Nexthop][fboss2-dev] sort show interface status and transceiver by numeric interface ID#1422
benoit-nexthop wants to merge 1 commit into
facebook:mainfrom
nexthop-ai:fboss2-sort-interfaces

Conversation

@benoit-nexthop

Copy link
Copy Markdown
Contributor

Summary

show interface status and show transceiver ordered interfaces by a plain lexicographic comparison of the interface name, so ports came out as:

eth1/1/1
eth1/10/1
eth1/100/1
eth1/101/1
eth1/2/1

show port doesn't have this problem because it sorts with utils::comparePortName, which parses the moduleNum/port/subport components and compares them numerically. This PR points the other two commands at the same comparator so all three sort consistently:

eth1/1/1
eth1/2/1
eth1/10/1
eth1/100/1
eth1/101/1
  • show interface status (CmdShowInterfaceStatus.cpp): the model is already a sorted std::vector; swapped the a.name() < b.name() lambda for utils::comparePortName.
  • show transceiver (CmdShowTransceiver.cpp): the ordering came from its map<string, TransceiverDetail> model key, so there was no explicit sort to change. The rows are now sorted in printOutput before being emitted. comparePortName throws on names that don't match the moduleNum/port/subport pattern, so it's wrapped to fall back to lexicographic order for bypass modules whose interface names may not match — preserving today's behavior for those rather than crashing the command.

Test Plan

Added unit tests:

  • CmdShowInterfaceStatusTest.createModelNaturalSort — feeds eth1/2/1, eth1/10/1, eth1/1/1, eth1/100/1, eth2/1/1 and asserts the model comes out in numeric order.
  • CmdShowTransceiverTest.printOutputNaturalSort — injects eth1/10/1 (which sorts between eth1/1/1 and eth1/2/1 as a string) and asserts it is printed after eth1/8/1.

Existing createModel/printOutput tests are unchanged since their fixtures use single-digit ports that already sort identically both ways.

…terface ID

# Summary

`show interface status` and `show transceiver` ordered interfaces by a
plain lexicographic comparison of the interface name, so ports came out
as:

```
eth1/1/1
eth1/10/1
eth1/100/1
eth1/101/1
eth1/2/1
```

`show port` doesn't have this problem because it sorts with
`utils::comparePortName`, which parses the `moduleNum/port/subport`
components and compares them numerically. This PR points the other two
commands at the same comparator so all three sort consistently:

```
eth1/1/1
eth1/2/1
eth1/10/1
eth1/100/1
eth1/101/1
```

- **`show interface status`** (`CmdShowInterfaceStatus.cpp`): the model
is already a sorted `std::vector`; swapped the `a.name() < b.name()`
lambda for `utils::comparePortName`.
- **`show transceiver`** (`CmdShowTransceiver.cpp`): the ordering came
from its `map<string, TransceiverDetail>` model key, so there was no
explicit sort to change. The rows are now sorted in `printOutput` before
being emitted. `comparePortName` throws on names that don't match the
`moduleNum/port/subport` pattern, so it's wrapped to fall back to
lexicographic order for bypass modules whose interface names may not
match — preserving today's behavior for those rather than crashing the
command.

# Test Plan

Added unit tests:

- `CmdShowInterfaceStatusTest.createModelNaturalSort` — feeds `eth1/2/1,
eth1/10/1, eth1/1/1, eth1/100/1, eth2/1/1` and asserts the model comes
out in numeric order.
- `CmdShowTransceiverTest.printOutputNaturalSort` — injects `eth1/10/1`
(which sorts between `eth1/1/1` and `eth1/2/1` as a string) and asserts
it is printed after `eth1/8/1`.

Existing `createModel`/`printOutput` tests are unchanged since their
fixtures use single-digit ports that already sort identically both ways.
@benoit-nexthop
benoit-nexthop requested a review from a team as a code owner July 27, 2026 19:17
@meta-cla meta-cla Bot added the CLA Signed label Jul 27, 2026
@meta-codesync

meta-codesync Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

@joseph5wu has imported this pull request. If you are a Meta employee, you can view this in D113812048.

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.

1 participant