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

[snmpagent][rfc1213] Optimize ipRouteNextHop default-route lookup#373
vpandian-nokia wants to merge 2 commits into
sonic-net:masterfrom
vpandian-nokia:snmp-default-route-lookup

Conversation

@vpandian-nokia
Copy link
Copy Markdown

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

What I did

Optimized ipRouteNextHop handling in rfc1213.py to avoid scanning all route keys in APPL_DB.
This preserves existing SNMP behavior for default-route next-hop reporting while reducing polling-path Redis/CPU overhead.

  • Replaced ROUTE_TABLE:* scan + filter with direct lookup of ROUTE_TABLE:0.0.0.0/0.
  • Kept behavior of selecting the first valid nexthop.
  • Added robust parsing for nexthop tokens (strip() + invalid-token handling).
  • Ensured route_list is updated only after successful nexthop parse.
    Updated unit test coverage in tests/test_rfc1213.py:
  • Aligned tests to the new dbs_get_all code path.
  • Added coverage for invalid first nexthop token with fallback to next valid token.
  • Fixed Redis-exception test to mock the actual method used by NextHopUpdater (dbs_get_all).
  • Added assertion that dbs_keys is not called in the optimized path.

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 tokens and continue scanning remaining tokens.
  5. Populate SNMP route cache only when a valid nexthop is found.

How to verify it

  1. Unit tests:

    • Updated/added unit test coverage in tests/test_rfc1213.py.
  2. DUT functional checks:

    • No default route in APPL_DB -> SNMP ipRouteNextHop returns no instance.
    • Valid default route entry in APPL_DB -> SNMP returns expected nexthop.
    • Invalid first token in nexthop list -> warning logged; next valid nexthop is used.
  3. Regression/stability:

    • Repeated polling shows stable behavior and no functional regressions.

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 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).

Signed-off-by: Vijay Pandian <vijayaragavan.pandian@nokia.com>
@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.

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