Skip to content

Commit

Permalink
bgp: update prefix-trie to v0.4.1 for optimized prefix counting
Browse files Browse the repository at this point in the history
Update prefix-trie to v0.4.1, using the new O(1) `len()` method in
`PrefixMap` to replace `iter().count()` and improve performance.

Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed May 28, 2024
1 parent 9968094 commit 761c5b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ netlink-sys = "0.8"
num-derive = "0.4"
num-traits = "0.2"
pickledb = "0.5"
prefix-trie = { version = "0.3", features = ["ipnetwork"] }
prefix-trie = { version = "0.4.1", features = ["ipnetwork"] }
prost = "0.12"
rand = "0.8.5"
regex = "1.10"
Expand Down
8 changes: 4 additions & 4 deletions holo-bgp/src/northbound/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn load_callbacks() -> Callbacks<Instance> {
let afi_safi = args.list_entry.as_global_afi_safi().unwrap();
let state = instance.state.as_ref().unwrap();
let total_prefixes = match afi_safi {
AfiSafi::Ipv4Unicast => state.rib.tables.ipv4_unicast.prefixes.iter().count(),
AfiSafi::Ipv6Unicast => state.rib.tables.ipv6_unicast.prefixes.iter().count(),
AfiSafi::Ipv4Unicast => state.rib.tables.ipv4_unicast.prefixes.len(),
AfiSafi::Ipv6Unicast => state.rib.tables.ipv6_unicast.prefixes.len(),
};
Box::new(Statistics {
// TODO
Expand All @@ -92,8 +92,8 @@ fn load_callbacks() -> Callbacks<Instance> {
use bgp::global::statistics::Statistics;
let mut total_prefixes = None;
if let Some(state) = &instance.state {
let total_ipv4 = state.rib.tables.ipv4_unicast.prefixes.iter().count();
let total_ipv6 = state.rib.tables.ipv6_unicast.prefixes.iter().count();
let total_ipv4 = state.rib.tables.ipv4_unicast.prefixes.len();
let total_ipv6 = state.rib.tables.ipv6_unicast.prefixes.len();
total_prefixes = Some(total_ipv4 as u32 + total_ipv6 as u32);
}
Box::new(Statistics {
Expand Down

0 comments on commit 761c5b3

Please sign in to comment.