Skip to content

feat(rib): add LPM lookup over per-router RIB views - #59

Draft
rodonile wants to merge 2 commits into
network-analytics:mainfrom
rodonile:rib-lookup
Draft

rodonile wants to merge 2 commits into
network-analytics:mainfrom
rodonile:rib-lookup

Conversation

@rodonile

@rodonile rodonile commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

This PR depends on #57

Adds the read path on top of the netcalyx-rib data model landed
in #57 : resolving an address to its best-matching route across a
router's RIB views.

Reason

Flow enrichment and other consumers need to resolve an address
(e.g. flow src/dst) into path attributes and forwarding info.

Changelog

  • Add lookup::lookup(): LPM lookup against one or more
    LookupTargets (context + AFI-SAFI + optional RD), trying RIB
    views in precedence order (loc-rib first, then the four
    adj-ribs, DEFAULT_VIEW_ORDER or a caller-supplied order). Returns
    a Match with the active path's attributes/forwarding info, the
    view that answered, and the peer that answered (None for
    loc-rib).
  • Resolve a flow's neighbor address to a peer via PeerIndex
    before reading an adj-rib view; fall back to the lowest
    (peer_address, bgp_id) among matching peers when the neighbor is
    ambiguous or absent.
  • 16 new tests in lookup.rs; 50 tests pass overall for the crate.

@rodonile rodonile self-assigned this Sep 29, 2026
@rodonile rodonile changed the title feat(rib): add LPM lookup over per-router RIB views - #9 feat(rib): add LPM lookup over per-router RIB views Sep 29, 2026
@rodonile
rodonile force-pushed the rib-lookup branch 3 times, most recently from 26fbc87 to cb8c16d Compare October 1, 2026 14:01
Introduce crates/rib (netcalyx-rib): sync only, no tokio, no lookup or
ingestion yet.

- types: TableId/RibContext (per-VRF table addressing, RD-normalized
  the same way for every consumer), AfiSafiType (RFC 4760 AFI/SAFI
  identities), LabeledRouteExtra/Srv6RouteExtra (MPLS/SRv6 forwarding
  info carried per route).
- attrs: RouteAttributes (flattened path attributes) and AttrStore,
  which interns both sub-components (AS-path, communities, cluster
  list, ...) and whole attribute sets, so a full table's worth of
  routes share Arc'd attribute sets instead of duplicating them per
  route.
- model: RibStore -> RouterRib -> AfiSafiTable -> AfiSafiRib, the five
  RIB views per table (loc-rib plus the four adj-ribs) held per peer
  in PeerRibs, and Route/MultiRoute for per-prefix path storage
  (best-path selection, ECMP, path status). Arc-per-trie copy-on-write:
  a write after a snapshot publish clones only the one trie it
  touches, not the whole router.
- peers: a flow's next-hop is an address, but BMP identifies a peer by
  a five-field tuple; PeerIndex resolves address -> peer within one RIB
  context in O(1) instead of scanning every peer in a table.
  peer_identity() normalizes RD the same way RibContext does, so
  inconsistent RD reporting can't split one peer's adj-rib in two.

Lookup (LPM) and BMP ingestion are intentionally out of scope here,
landing as separate follow-up PRs.

Add docs/rib_structure.md: hierarchy sketch and copy-on-write
lifecycle walkthrough for the new crate.
Add `lookup::lookup()`, resolving one address against
`(RibContext, AfiSafiType[, RouteDistinguisher])` targets into the
active path of the first RIB view with a hit, trying `loc-rib` then
the four adj-ribs in precedence order (overridable via
`LookupRequest::view_order`). Adj-rib reads resolve the flow's
neighbor address to a peer through `PeerAddrIndex`; ambiguous or
absent neighbors fall back to the lowest `(peer_address, bgp_id)`
among matching peers, deterministically.

Consolidate the `(post_policy, adj_rib_out) -> view` mapping, which
previously existed independently in three places, into
`RibView::from_peer_flags` plus `PeerRibs::view()`/`view_mut()` as
the single source of truth; `adj_rib_view_mut` and `lookup` both
delegate to it now.
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.

1 participant