Skip to content

[snmpagent][rfc1213] Optimize ipRouteNextHop default-route lookup - #373

Open
vpandian-nokia wants to merge 2 commits into
sonic-net:masterfrom
vpandian-nokia:snmp-default-route-lookup
Open

vpandian-nokia wants to merge 2 commits into
sonic-net:masterfrom
vpandian-nokia:snmp-default-route-lookup

Conversation

@vpandian-nokia

@vpandian-nokia vpandian-nokia commented May 6, 2026 •

Copy link
Copy Markdown

What I did

Optimized ipRouteNextHop handling in rfc1213.py to avoid scanning all route keys in APPL_DB, while preserving RFC1213 default-route behavior.

  • Replaced ROUTE_TABLE:* scan + filter with direct lookup of ROUTE_TABLE:0.0.0.0/0.
  • Kept behavior of selecting the first valid IPv4 nexthop.
  • Added robust parsing for nexthop tokens (strip() + invalid-token handling).
  • Skip non-IPv4 nexthops (IPv6 tokens are ignored with warning), aligned with RFC1213 IPv4 semantics.
  • Ensured route_list is updated only after successful IPv4 nexthop parse.
  • Updated unit tests in tests/test_rfc1213.py for direct lookup path, invalid-token fallback, and IPv6/IPv4 nexthop cases.

How I did it

Modified NextHopUpdater.update_data() to:

  1. Query only ROUTE_TABLE:0.0.0.0/0 from APPL_DB.
  2. Read nexthop field from the returned route entry.
  3. Parse nexthops left-to-right and pick the first valid IPv4 token.
  4. Log warning for invalid/non-IPv4 tokens and continue scanning remaining tokens.
  5. Populate SNMP route cache only when a valid IPv4 nexthop is found.

How to verify it

  • Unit tests: tests/test_rfc1213.py
  • DUT functional validation on a Broadcom-based SONiC switch with large BGP route scale (~250k routes):
    • Verified optimized code path (ROUTE_TABLE:0.0.0.0/0 direct lookup + IPv4-only nexthop filter)
    • No default route: snmpwalk 1.3.6.1.2.1.4.21.1.7 returns No Such Instance in <200ms (stable across repeated polls)
    • With temporary static default route (0.0.0.0/0 via valid IPv4 nexthop): snmpwalk/get returns expected IPv4 nexthop in <200ms
    • After route removal: behavior restored to No Such Instance

- Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202605

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO):
Failure type: N/A (optimization; no backport requested)

- Tested branch

  • master
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202605
  • N/A

- Test result

  • master:
    • Unit tests in tests/test_rfc1213.py passed
    • DUT SNMP validation passed on a large-scale route table (~250k BGP routes), covering:
      • no default route (No Such Instance, fast response)
      • temporary default route (expected IPv4 nexthop returned, fast response)
    • Repeated polling showed stable behavior with no timeout/hang

Description for the changelog

Optimize SNMP ipRouteNextHop default-route lookup by replacing full route-table scan with direct ROUTE_TABLE:0.0.0.0/0 query and improving IPv4 nexthop parsing robustness.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@vpandian-nokia
vpandian-nokia force-pushed the snmp-default-route-lookup branch from 163fe96 to 50a662f Compare May 6, 2026 16:41
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@vpandian-nokia

Copy link
Copy Markdown
Author

@qiluo-msft This PR is a follow-up optimization of ipRouteNextHop (default-route-only) in PR #26.

Changes in this PR:

  • replace ROUTE_TABLE:* scan with direct lookup of ROUTE_TABLE:0.0.0.0/0
  • preserve existing default-route behavior
  • add robustness for invalid nexthop tokens

Would appreciate your review when you have a chance.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@vpandian-nokia

Copy link
Copy Markdown
Author

@deepak-singhal0408: The relevant sonic-mgmt SNMP tests passed for this change. I would appreciate a reviewer taking a look and, if everything looks good, helping approve the PR.

@vpandian-nokia

Copy link
Copy Markdown
Author

@qiluo-msft Gentle follow-up on this PR when you have a chance.

The relevant sonic-mgmt SNMP tests have passed, and the change is ready for review. Please let me know if any additional information is needed.

Signed-off-by: Vijay Pandian <vijayaragavan.pandian@nokia.com>
@vpandian-nokia
vpandian-nokia force-pushed the snmp-default-route-lookup branch from 2411e71 to bb82431 Compare September 3, 2026 20:09
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

Select the first valid IPv4 nexthop for RFC1213 ipRouteNextHop while
skipping invalid and IPv6 tokens. Add unit tests for IPv6-only and
IPv6-then-IPv4 nexthop lists.

Signed-off-by: Vijay Pandian <vijayaragavan.pandian@nokia.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@vpandian-nokia

Copy link
Copy Markdown
Author

Hi @deepak-singhal0408 @qiluo-msft —

Latest update:

  • Rebased on current master
  • Added c986fc1 (IPv4-only nexthop handling + unit tests)
  • DUT validation completed on ~250k-route scale (no-default and temporary default-route cases)
  • PR description updated

CI is green on c986fc1. If Semgrep approval is still needed for this fork PR, please help approve/run it.

Ready for review/merge.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants