Skip to content

[orchagent]: Recreate custom BFD monitor for reused nexthop - #4808

Open
zjswhhh wants to merge 2 commits into
sonic-net:masterfrom
zjswhhh:fix-vnet-stale-custom-bfd-delete
Open

[orchagent]: Recreate custom BFD monitor for reused nexthop#4808
zjswhhh wants to merge 2 commits into
sonic-net:masterfrom
zjswhhh:fix-vnet-stale-custom-bfd-delete

Conversation

@zjswhhh

@zjswhhh zjswhhh commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

What I did

Decouple endpoint monitor setup from next-hop-group creation in VNetRouteOrch::selectNextHopGroup().

A directly connected next-hop group can survive route deletion. When the route was recreated, the existing NHG caused monitor setup to be skipped, so the route owned stale monitor state without recreating its custom BFD session. A later route update then emitted a delete for a session that had never been created in that cycle.

The updated logic recreates route-specific endpoint monitor state whenever either the NHG or route is new, while creating the shared NHG only when needed.

Added a DVS regression that deletes and recreates a local-only custom-BFD route while its directly connected next hop is reused.

Testing

  • make -C orchagent -j2 orchagent
  • Baseline test_vnet.py::TestVnetOrch::test_vnet_orch_34: fails at the second BFD-session check after route recreation
  • Fixed test_vnet.py::TestVnetOrch::test_vnet_orch_34: passed
  • git diff --check
  • python3 -m py_compile tests/test_vnet.py

Fixes sonic-net/sonic-buildimage#28336

sonic-mgmt validation

Targeted SmartSwitch HA validation used ha/test_ha_launch_with_no_peer.py::test_ha_launch_with_no_peer with sonic-mgmt PR #26298 applied.

  • Baseline: 3 target custom-BFD session creates and 4 route-cleanup markers reproduced 1 stale remove_bfd_session error.
  • Fixed orchagent: the same 3 target session creates and 4 route-cleanup markers produced 0 stale session-deletion errors.
  • Post-cleanup checks found no residual target BFD session or VNET route entries.
  • SWSS, syncd, GNMI, and DASH HA services remained active with zero restarts and no cores.

The issue-specific lifecycle validation passed. The overall pytest result remained non-passing because of an unrelated traffic assertion and Log Analyzer sensor errors.

Signed-off-by: Jing Zhang <zhangjing@microsoft.com>
Copilot AI review requested due to automatic review settings July 31, 2026 18:18
@zjswhhh
zjswhhh requested a review from prsunny as a code owner July 31, 2026 18:18
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@zjswhhh
zjswhhh marked this pull request as draft July 31, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a lifecycle bug in orchagent where per-route custom BFD endpoint monitor state was not recreated when a directly-connected next-hop-group (NHG) was reused after route deletion/recreation, leading to stale monitor ownership and incorrect subsequent delete behavior.

Changes:

  • Updates VNetRouteOrch::selectNextHopGroup() to (re)create route-specific endpoint monitor state when either the NHG is new or the route is new, while only creating the shared NHG when needed.
  • Adds a DVS regression scenario that deletes and recreates a local-only custom-BFD route while reusing the directly connected next hop.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
orchagent/vnetorch.cpp Adjusts monitor-setup vs NHG-creation logic in selectNextHopGroup() to ensure route-specific monitor state is recreated when appropriate.
tests/test_vnet.py Extends test_vnet_orch_34 with a delete/recreate route sequence validating custom BFD session recreation under NH reuse.

Comment thread orchagent/vnetorch.cpp
Comment on lines +1175 to +1177
bool next_hop_group_exists = hasNextHopGroup(vnet, nexthops_primary);
bool route_exists = syncd_tunnel_routes_[vnet].find(ipPrefix) != syncd_tunnel_routes_[vnet].end();

@zjswhhh
zjswhhh marked this pull request as ready for review August 3, 2026 17:13
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
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.

Bug: [HA] Stale custom BFD monitor delete logs error after local endpoint route cleanup

3 participants