Skip to content

refactor(rib): split model/lookup test modules into own files - #60

Closed
rodonile wants to merge 3 commits into
network-analytics:mainfrom
rodonile:rib-tests-refactor
Closed

rodonile wants to merge 3 commits into
network-analytics:mainfrom
rodonile:rib-tests-refactor

Conversation

@rodonile

Copy link
Copy Markdown
Member

This PR depends on #59.

Pure test-code relocation, no behavior change.

Reason

model.rs and lookup.rs had grown long, splitting tests into
a same-named-folder file keeps the source file focused on
the implementation while keeping tests colocated and easy to find.

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.
@rodonile rodonile self-assigned this Sep 29, 2026
model.rs and lookup.rs had grown long, mostly from test code
(23 and 15 tests respectively). Move each `#[cfg(test)] mod tests`
block out to a same-named-folder file (model/tests.rs,
lookup/tests.rs), matching the pattern already used elsewhere in
the repo (e.g. collector/src/flow/enrichment/actor.rs).

No behavior change: `use super::*` becomes `use crate::<module>::*`
per the established convention for this pattern, everything else is
unmodified.
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