Skip to content

Conversation

@kalash-nexthop
Copy link
Contributor

@kalash-nexthop kalash-nexthop commented Nov 27, 2025

fixes# 4139

What I did

When software BFD is enabled (CONFIG_DB:SYSTEM_DEFAULTS|software_bfd|status=enabled), the show bfd summary and show bfd peer commands now:

  1. Query FRR directly via vtysh (similar to show ip bgp commands)

  2. Filter BFD sessions to only show peers configured in CONFIG_DB:

    • BGP neighbors with bfd=true
    • Static routes with bfd=true

    This fixes the issue where software BFD sessions were not visible in 'show bfd summary' because they are not written to STATE_DB:BFD_SESSION_TABLE.

For hardware BFD, the commands continue to use STATE_DB as before.

How I did it

Changes:

  • Added utilities_common/bfd_util.py with helper functions:

    • is_software_bfd_enabled(): Check if software BFD is configured
    • get_bfd_peers_from_config(): Get BFD-enabled peers from CONFIG_DB
    • get_bfd_sessions_from_frr(): Query FRR via vtysh
    • filter_bfd_sessions_by_config(): Filter FRR sessions by CONFIG_DB
  • Updated show/main.py:

    • Modified 'show bfd summary' to use vtysh for software BFD
    • Modified 'show bfd peer' to use vtysh for software BFD
    • Both commands filter output to only show configured peers

How to verify it

Unit tests are added.

Manual verification:

vtysh output:
admin@vlab-01:~$ vtysh -c "show bfd peers json" | jq .
[
  {
    "multihop": false,
    "peer": "10.0.0.33",
    "local": "10.0.0.32",
    "vrf": "default",
    "interface": "Ethernet4",
    "id": 3483190008,
    "remote-id": 0,
    "passive-mode": false,
    "status": "down",
    "downtime": 1697,
    "diagnostic": "ok",
    "remote-diagnostic": "ok",
    "type": "dynamic",
    "receive-interval": 300,
    "transmit-interval": 300,
    "echo-receive-interval": 50,
    "echo-transmit-interval": 0,
    "detect-multiplier": 3,
    "remote-receive-interval": 1000,
    "remote-transmit-interval": 1000,
    "remote-echo-receive-interval": 0,
    "remote-detect-multiplier": 3,
    "rtt-min": 0,
    "rtt-avg": 0,
    "rtt-max": 0
  }
]

sonic command output after the change:

admin@vlab-01:~$ show bfd summary
Total number of BFD sessions: 1
Peer Addr    Interface    Vrf      State    Type     Local Addr      TX Interval    RX Interval    Multiplier  Multihop      Local Discriminator
-----------  -----------  -------  -------  -------  ------------  -------------  -------------  ------------  ----------  ---------------------
10.0.0.33    Ethernet4    default  down     dynamic  10.0.0.32               300            300             3  no                     3483190008

admin@vlab-01:~$ show bfd peer 10.0.0.33
Total number of BFD sessions for peer IP 10.0.0.33: 1
Peer Addr    Interface    Vrf      State    Type     Local Addr      TX Interval    RX Interval    Multiplier  Multihop      Local Discriminator
-----------  -----------  -------  -------  -------  ------------  -------------  -------------  ------------  ----------  ---------------------
10.0.0.33    Ethernet4    default  down     dynamic  10.0.0.32               300            300             3  no                     3483190008
admin@vlab-01:~$

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

admin@vlab-01:~$ show bfd summary
show bfd summary
Total number of BFD sessions: 0
Peer Addr    Interface    Vrf    State    Type    Local Addr    TX Interval    RX Interval    Multiplier    Multihop    Local Discriminator
-----------  -----------  -----  -------  ------  ------------  -------------  -------------  ------------  ----------  ---------------------

admin@vlab-01:~$ show bfd peer 10.0.0.33
No BFD sessions found for peer IP 10.0.0.33
admin@vlab-01:~$

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

admin@vlab-01:~$ show bfd summary
Total number of BFD sessions: 1
Peer Addr    Interface    Vrf      State    Type     Local Addr      TX Interval    RX Interval    Multiplier  Multihop      Local Discriminator
-----------  -----------  -------  -------  -------  ------------  -------------  -------------  ------------  ----------  ---------------------
10.0.0.33    Ethernet4    default  down     dynamic  10.0.0.32               300            300             3  no                     3483190008

admin@vlab-01:~$ show bfd peer 10.0.0.33
Total number of BFD sessions for peer IP 10.0.0.33: 1
Peer Addr    Interface    Vrf      State    Type     Local Addr      TX Interval    RX Interval    Multiplier  Multihop      Local Discriminator
-----------  -----------  -------  -------  -------  ------------  -------------  -------------  ------------  ----------  ---------------------
10.0.0.33    Ethernet4    default  down     dynamic  10.0.0.32               300            300             3  no                     3483190008
admin@vlab-01:~$

When software BFD is enabled (CONFIG_DB:SYSTEM_DEFAULTS|software_bfd|status=enabled),
the 'show bfd summary' and 'show bfd peer' commands now:

1. Query FRR directly via vtysh (similar to 'show ip bgp' commands)
2. Filter BFD sessions to only show peers configured in CONFIG_DB:
   - BGP neighbors with bfd=true
   - Static routes with bfd=true

This fixes the issue where software BFD sessions were not visible in
'show bfd summary' because they are not written to STATE_DB:BFD_SESSION_TABLE.

For hardware BFD, the commands continue to use STATE_DB as before.

Changes:
- Added utilities_common/bfd_util.py with helper functions:
  - is_software_bfd_enabled(): Check if software BFD is configured
  - get_bfd_peers_from_config(): Get BFD-enabled peers from CONFIG_DB
  - get_bfd_sessions_from_frr(): Query FRR via vtysh
  - filter_bfd_sessions_by_config(): Filter FRR sessions by CONFIG_DB

- Updated show/main.py:
  - Modified 'show bfd summary' to use vtysh for software BFD
  - Modified 'show bfd peer' to use vtysh for software BFD
  - Both commands filter output to only show configured peers
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kalash-nexthop kalash-nexthop changed the title show bfd: Use vtysh for software BFD and filter by CONFIG_DB Make 'show bfd {summary | peer}' commands work for software BFD Nov 28, 2025
@kalash-nexthop kalash-nexthop changed the title Make 'show bfd {summary | peer}' commands work for software BFD Make 'show bfd {summary|peer}' commands work for software BFD sessions Nov 28, 2025
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.

2 participants