Skip to content

bgp: give AddressFamily an associated Prefix key type - #132

Open
gusbourg wants to merge 2 commits into
holo-routing:masterfrom
gusbourg:bgp-af-prefix-key-pr
Open

bgp: give AddressFamily an associated Prefix key type#132
gusbourg wants to merge 2 commits into
holo-routing:masterfrom
gusbourg:bgp-af-prefix-key-pr

Conversation

@gusbourg

@gusbourg gusbourg commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Preparatory refactor for multiprotocol RIBs (VPN, labeled-unicast, EVPN). Adds an associated Prefix type to the AddressFamily trait, separating the RIB/NLRI key from the policy/wire IP-network type, with conversion hooks. IPv4/IPv6 unicast keep Prefix = IpNetwork; behavior is unchanged.

The BGP RIB container changes from prefix_trie::PrefixMap to an exact-key ordered map, because BGP uses exact lookup/iteration (not LPM); this also avoids forcing wider NLRI keys (e.g. VPNv6 = RD + IPv6) into a single primitive-integer representation.

Includes a small test-infrastructure commit so workspace tests build under the testing feature.

🤖 Generated with Claude Code

gusbourg and others added 2 commits July 5, 2026 10:41
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add an AddressFamily::Prefix associated type for NLRI/RIB keys while keeping policy, northbound, and IBus boundaries on normal IP network values. IPv4 and IPv6 unicast use identity conversions, preserving current behavior.

Switch BGP RIB prefix storage from PrefixMap to BTreeMap so future address families are not constrained by prefix_trie's primitive-integer key representation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@Paul-weqe Paul-weqe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's interesting seeing steps towards implementing protocols like EVPN.

I have been able to do some basic testing on munet and things look to be working fine. I haven't been able to look through every single line of code, but find my overall review:

Comment thread holo-protocol/src/lib.rs
}

#[cfg(feature = "testing")]
pub fn spawn_protocol_task_with_test<P>(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This would work just fine with the old spawn_protocol_task function signature. I don't think there is a need to separate it into 3 different functions.

The feature flag will handle that.

Comment thread holo-utils/src/task.rs
impl TimeoutTask {
/// Returns an inert timeout handle for deterministic protocol tests.
#[cfg(feature = "testing")]
pub fn new<F, Fut>(_timeout: Duration, _cb: F) -> TimeoutTask

@Paul-weqe Paul-weqe Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Descent proposition but this is handled by default in each protocols' task.rs file. e.g

TimeoutTask {}

We may need to add some lines of code before the TimeourTask {} is called in future for some protocols, and this limits that.

Comment thread holo-bgp/src/rib.rs

#[derive(Debug)]
pub struct RoutingTable<A: AddressFamily> {
pub prefixes: PrefixMap<A::IpNetwork, Destination>,

@Paul-weqe Paul-weqe Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure what I think about nuking the PrefixMap for BtreeMap.

It works particularly well in this context where we need a Map that is more flexible than the traditional Ipv4 & Ipv6 Unicast addresses...also way better for insertions when the number of prefixes grow.

However, once the tables REALLY grow in size, PrefixMap becomes really useful in terms of searching through the existing prefixes.

We can give this some more thought ?
I may be wrong of course, but I think we can do a compromise...

Maybe having a PrefixMap for the IPV4 and IPV6 Addresses. Then for the rest (like VPNv6), we could use a BTreeMap. Throwing a thought out there, I'd like to know yours.

Comment thread holo-bgp/src/ibus/rx.rs
// Get prefix RIB entry.
let rib = &mut instance.state.rib;
let table = A::table(&mut rib.tables);
let prefix = A::prefix_from_ip_network(prefix.into()).unwrap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use a default here instead of unwrap....

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.

2 participants