From 36b4e80ccf4376ff5f471b581f41e27a4229552c Mon Sep 17 00:00:00 2001 From: nrybowski Date: Mon, 9 Sep 2024 11:06:47 +0200 Subject: [PATCH] ospf,bier: Move BIER route addition procedure into separate function Signed-off-by: Nicolas Rybowski --- holo-ospf/src/bier.rs | 57 ++++++++++++++++++++++++++++++++++++++++++ holo-ospf/src/lib.rs | 1 + holo-ospf/src/route.rs | 42 +++---------------------------- 3 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 holo-ospf/src/bier.rs diff --git a/holo-ospf/src/bier.rs b/holo-ospf/src/bier.rs new file mode 100644 index 00000000..3b01dd8e --- /dev/null +++ b/holo-ospf/src/bier.rs @@ -0,0 +1,57 @@ +// +// Copyright (c) The Holo Core Contributors +// +// SPDX-License-Identifier: MIT +// + +use holo_utils::bier::{BierInfo, Bsl, UnderlayProtocolType}; +use holo_utils::ip::IpNetworkKind; + +use crate::instance::InstanceUpView; +use crate::packet::tlv::BierSubSubTlv; +use crate::route::RouteNet; +use crate::spf::SpfIntraAreaNetwork; +use crate::version::Version; + +pub(crate) fn bier_route_add( + instance: &InstanceUpView<'_, V>, + new_route: &mut RouteNet, + stub: &SpfIntraAreaNetwork<'_, V>, +) where + V: Version, +{ + let bier_cfg = &instance.shared.bier_config; + + // 1. Does the BFR match a locally configured BIER sub-domain? + stub.bier.iter().for_each(|tlv| { + if instance.config.bier.mt_id == tlv.mt_id + && let Some(sd_cfg) = bier_cfg + .sd_cfg + .get(&(tlv.sub_domain_id, stub.prefix.address_family())) + && sd_cfg.underlay_protocol == UnderlayProtocolType::Ospf + { + // 2. Register entry in BIRT for each supported bitstring length by the BFR prefix + // TODO: Use BAR and IPA + + // TODO: Sanity check on bitstring lengths upon LSA reception + + let bfr_bss: Vec = tlv + .subtlvs + .iter() + .filter_map(|stlv| match stlv { + BierSubSubTlv::BierEncapSubSubTlv(encap) => { + Bsl::try_from(encap.bs_len).ok() + } + }) + .collect(); + + if !bfr_bss.is_empty() { + new_route.bier_info = Some(BierInfo { + bfr_bss, + sd_id: tlv.sub_domain_id, + bfr_id: tlv.bfr_id, + }) + } + } + }); +} diff --git a/holo-ospf/src/lib.rs b/holo-ospf/src/lib.rs index 27144378..2198ab38 100644 --- a/holo-ospf/src/lib.rs +++ b/holo-ospf/src/lib.rs @@ -12,6 +12,7 @@ #![feature(btree_extract_if, hash_extract_if, ip, let_chains)] pub mod area; +pub mod bier; pub mod collections; pub mod debug; pub mod error; diff --git a/holo-ospf/src/route.rs b/holo-ospf/src/route.rs index 17b70f3c..b1d7c28a 100644 --- a/holo-ospf/src/route.rs +++ b/holo-ospf/src/route.rs @@ -10,8 +10,8 @@ use std::net::Ipv4Addr; use bitflags::bitflags; use derive_new::new; -use holo_utils::bier::{BierInfo, Bsl, UnderlayProtocolType}; -use holo_utils::ip::{IpAddrKind, IpNetworkKind}; +use holo_utils::bier::BierInfo; +use holo_utils::ip::IpAddrKind; use holo_utils::mpls::Label; use holo_utils::southbound::OspfRouteType; use holo_utils::sr::IgpAlgoType; @@ -24,10 +24,9 @@ use crate::interface::Interface; use crate::lsdb::{LsaEntry, LSA_INFINITY}; use crate::northbound::configuration::InstanceCfg; use crate::packet::lsa::{LsaKey, LsaRouterFlagsVersion}; -use crate::packet::tlv::BierSubSubTlv; use crate::spf::{SpfPartialComputation, VertexLsaVersion}; use crate::version::Version; -use crate::{southbound, sr}; +use crate::{bier, southbound, sr}; // Network routing table entry. #[derive(Clone, Debug, Eq, PartialEq)] @@ -422,40 +421,7 @@ fn update_rib_intra_area( // Update BIER Routing Table (BIRT) if instance.config.bier.enabled && instance.config.bier.receive { - let bier_cfg = &instance.shared.bier_config; - - // 1. Does the BFR match a locally configured BIER sub-domain? - stub.bier.iter().for_each(|tlv| { - if instance.config.bier.mt_id == tlv.mt_id - && let Some(sd_cfg) = bier_cfg - .sd_cfg - .get(&(tlv.sub_domain_id, stub.prefix.address_family())) - && sd_cfg.underlay_protocol == UnderlayProtocolType::Ospf - { - // 2. Register entry in BIRT for each supported bitstring length by the BFR prefix - // TODO: Use BAR and IPA - - // TODO: Sanity check on bitstring lengths upon LSA reception - - let bfr_bss: Vec = tlv - .subtlvs - .iter() - .filter_map(|stlv| match stlv { - BierSubSubTlv::BierEncapSubSubTlv(encap) => { - Bsl::try_from(encap.bs_len).ok() - } - }) - .collect(); - - if !bfr_bss.is_empty() { - new_route.bier_info = Some(BierInfo { - bfr_bss, - sd_id: tlv.sub_domain_id, - bfr_id: tlv.bfr_id, - }) - } - } - }); + bier::bier_route_add(&instance, &mut new_route, &stub); } // Try to add or update stub route in the RIB.