Skip to content

feat(rib): add netcalyx-rib core data model crate - #57

Open
rodonile wants to merge 1 commit into
network-analytics:mainfrom
rodonile:rib-model
Open

rodonile wants to merge 1 commit into
network-analytics:mainfrom
rodonile:rib-model

Conversation

@rodonile

@rodonile rodonile commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Adds crates/rib (netcalyx-rib): the core in-memory BGP RIB data model.

The collector needs an in-memory RIB to enrich flow records via
longest-prefix-match against BGP attributes. The design (per-router
snapshots, Arc-per-trie copy-on-write) was benchmarked and validated
separately before porting here; this PR lands only the data model.
Lookups, ingestion, and collector wiring will follow as separate PRs.

Changelog

  • New crate netcalyx-rib, workspace member, sync only
  • types: TableId, RibContext, AfiSafiType, LabeledRouteExtra,
    Srv6RouteExtra.
  • attrs: RouteAttributes, AttrStore (sub-component + whole-attribute
    interning with explicit gc).
  • model: RibStore, RouterRib, AfiSafiTable/AfiSafiRib/PeerRibs
    (loc-rib + 4 adj-rib views), Route/MultiRoute, RibViewCounts.
    Arc sits at up to four levels so a write clones only the touched trie.
  • peers: PeerIndex (address → candidate peer(s), self-healing on
    session flap) and peer_identity() (normalizes RD the same way
    RibContext does, so inconsistent RD reporting can't split one peer's
    adj-rib in two).
  • docs/rib_structure.md: hierarchy diagram and copy-on-write walkthrough.

Testing

  • cargo test -p netcalyx-rib: 32 unit tests, including a dedicated
    copy-on-write correctness test (Arc sharing before a write, private
    copy after) and RD-normalization/AFI-SAFI-mapping coverage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

RD normalization can merge distinct VRFs, and several documentation and copy-on-write coverage issues remain.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 2 Low severity

Open (4)
What changed in this PR

Adds the in-memory BGP RIB data model, including attribute interning, peer indexing, route structures, copy-on-write snapshots, and documentation.

Changes:

  • Introduces RIB types, tables, routes, and peer resolution.
  • Adds attribute interning with explicit garbage collection.
  • Registers and documents the new workspace crate.
File Description
Cargo.toml Registers the RIB crate and prefix-trie dependency.
Cargo.lock Locks new crate dependencies.
crates/​rib/​Cargo.toml Defines crate metadata and dependencies.
crates/​rib/​LICENSE Adds the Apache 2.0 license.
crates/​rib/​README.md Summarizes crate scope.
crates/​rib/​src/​lib.rs Exposes the public API.
crates/​rib/​src/​attrs.rs Implements attribute interning and GC.
crates/​rib/​src/​model.rs Defines RIB storage and route models.
crates/​rib/​src/​peers.rs Implements peer identity and indexing.
crates/​rib/​src/​types.rs Defines table, context, and labeled-route types.
docs/​rib_structure.md Documents hierarchy and copy-on-write behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/rib/src/types.rs
Comment thread crates/rib/src/model.rs Outdated
Comment thread crates/rib/Cargo.toml
Comment thread crates/rib/src/lib.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Published metadata advertises deferred LPM functionality, and peer normalization documentation contradicts the implementation.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (4)

Comment thread crates/rib/src/peers.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The package metadata advertises LPM lookup even though lookup support is explicitly deferred.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Public crate documentation and package metadata incorrectly advertise LPM lookup that is explicitly deferred to a later change.

Review effort: Balanced
Findings: 2 Low severity

Open (2)

Comment thread crates/rib/src/lib.rs Outdated
Comment thread crates/rib/src/peers.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The crate metadata incorrectly advertises LPM lookup support that this PR explicitly defers.

Review effort: Balanced
Findings: None

Resolved since last review (2)

@rodonile
rodonile force-pushed the rib-model branch 2 times, most recently from e948988 to 8987444 Compare October 1, 2026 14:00
@rodonile
rodonile requested a review from mxyns October 2, 2026 12:42
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.
Comment thread crates/rib/src/model.rs
/// 2. Any path marked as PRIMARY (useful for ECMP)
/// 3. Fallback to lowest Path-ID
pub fn active_path(&self) -> Option<&Route<E>> {
use netcalyx_bmp_pkt::v4::PathStatus;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use PathStatus file wide

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.

3 participants