From bd3277e4fdfe9d8059effd18e885c36f0f9b68d9 Mon Sep 17 00:00:00 2001 From: nrybowski Date: Thu, 8 Aug 2024 10:05:21 +0200 Subject: [PATCH] bier: Update BIRT from OSPFv3 Signed-off-by: Nicolas Rybowski --- holo-ospf/src/ospfv2/spf.rs | 4 + holo-ospf/src/ospfv3/lsdb.rs | 36 +++-- holo-ospf/src/ospfv3/packet/lsa.rs | 1 + holo-ospf/src/ospfv3/spf.rs | 1 + holo-ospf/src/packet/tlv.rs | 1 - holo-ospf/src/route.rs | 46 ++++++- holo-ospf/src/southbound/tx.rs | 17 ++- holo-ospf/src/spf.rs | 3 +- holo-ospf/tests/packet/ospfv3.rs | 2 + holo-routing/src/ibus.rs | 3 + holo-routing/src/lib.rs | 5 +- holo-routing/src/northbound/mod.rs | 1 + holo-routing/src/northbound/state.rs | 57 +++++++- holo-routing/src/rib.rs | 31 ++++- holo-utils/src/bier.rs | 126 ++++++++++++++---- holo-utils/src/ibus.rs | 8 +- holo-utils/src/southbound.rs | 9 ++ .../modules/augmentations/holo-routing.yang | 70 ++++++++++ holo-yang/src/lib.rs | 3 + 19 files changed, 365 insertions(+), 59 deletions(-) create mode 100644 holo-yang/modules/augmentations/holo-routing.yang diff --git a/holo-ospf/src/ospfv2/spf.rs b/holo-ospf/src/ospfv2/spf.rs index e350dc8c..c73a28e5 100644 --- a/holo-ospf/src/ospfv2/spf.rs +++ b/holo-ospf/src/ospfv2/spf.rs @@ -491,6 +491,8 @@ impl SpfVersion for Ospfv2 { prefix_options: Default::default(), metric: 0, prefix_sids, + // FIXME: BIER not supported yet for OSPFv2 + bier: Default::default(), }); } VertexLsa::Router(lsa) => { @@ -523,6 +525,8 @@ impl SpfVersion for Ospfv2 { prefix_options: Default::default(), metric, prefix_sids, + // FIXME: BIER not supported yet for OSPFv2 + bier: Default::default(), } }), ) diff --git a/holo-ospf/src/ospfv3/lsdb.rs b/holo-ospf/src/ospfv3/lsdb.rs index c7ab8d49..4c644412 100644 --- a/holo-ospf/src/ospfv3/lsdb.rs +++ b/holo-ospf/src/ospfv3/lsdb.rs @@ -820,8 +820,8 @@ fn lsa_orig_intra_area_prefix( } } - // Add BIER Sub-TLV(s) - if instance.config.bier.enabled { + // Add BIER Sub-TLV(s) if BIER is enabled and allowed to advertise + if instance.config.bier.enabled && instance.config.bier.advertise { bier_config .sd_cfg .iter() @@ -835,35 +835,29 @@ fn lsa_orig_intra_area_prefix( .encap .iter() .filter_map(|((bsl, encap_type), encap)| { - if let Some(id) = match encap_type { + match encap_type { BierEncapsulationType::Mpls => { // TODO: where is the label defined? Some(BierEncapId::Mpls(Label::new(0))) } - _ => { - if let Some(id) = match encap.in_bift_id { - BierInBiftId::Base(id) => Some(id), - BierInBiftId::Encoding(true) => Some(0), - _ => None, - } { - Some(BierEncapId::NonMpls(BiftId::new( - id, - ))) - } else { - None - } + _ => match encap.in_bift_id { + BierInBiftId::Base(id) => Some(id), + BierInBiftId::Encoding(true) => Some(0), + _ => None, } - } { - Some(BierSubSubTlv::BierEncapSubSubTlv( + .map(|id| { + BierEncapId::NonMpls(BiftId::new(id)) + }), + } + .map(|id| { + BierSubSubTlv::BierEncapSubSubTlv( BierEncapSubSubTlv::new( encap.max_si, id, (*bsl).into(), ), - )) - } else { - None - } + ) + }) }) .collect::>(); diff --git a/holo-ospf/src/ospfv3/packet/lsa.rs b/holo-ospf/src/ospfv3/packet/lsa.rs index f204d563..5e45a7e2 100644 --- a/holo-ospf/src/ospfv3/packet/lsa.rs +++ b/holo-ospf/src/ospfv3/packet/lsa.rs @@ -2372,6 +2372,7 @@ impl LsaIntraAreaPrefix { // Parse Sub-TLVs. let stlvs = ExtLsaSubTlvs::decode(&mut buf_tlv)?; prefix.prefix_sids = stlvs.prefix_sids; + prefix.bier = stlvs.bier; prefix.unknown_stlvs = stlvs.unknown; iap.prefixes.push(prefix); diff --git a/holo-ospf/src/ospfv3/spf.rs b/holo-ospf/src/ospfv3/spf.rs index ae935184..4dd1cf5d 100644 --- a/holo-ospf/src/ospfv3/spf.rs +++ b/holo-ospf/src/ospfv3/spf.rs @@ -473,6 +473,7 @@ impl SpfVersion for Ospfv3 { prefix_options: prefix.options, metric: prefix.metric, prefix_sids: prefix.prefix_sids, + bier: prefix.bier, }) }) } diff --git a/holo-ospf/src/packet/tlv.rs b/holo-ospf/src/packet/tlv.rs index 7e741810..cc70f1f1 100644 --- a/holo-ospf/src/packet/tlv.rs +++ b/holo-ospf/src/packet/tlv.rs @@ -458,7 +458,6 @@ impl BierSubTlv { buf.put_u24(0); tlv_encode_end(buf, start_pos); } - _ => {} } } tlv_encode_end(buf, start_pos); diff --git a/holo-ospf/src/route.rs b/holo-ospf/src/route.rs index 99bd9ef0..17b70f3c 100644 --- a/holo-ospf/src/route.rs +++ b/holo-ospf/src/route.rs @@ -10,7 +10,8 @@ use std::net::Ipv4Addr; use bitflags::bitflags; use derive_new::new; -use holo_utils::ip::IpAddrKind; +use holo_utils::bier::{BierInfo, Bsl, UnderlayProtocolType}; +use holo_utils::ip::{IpAddrKind, IpNetworkKind}; use holo_utils::mpls::Label; use holo_utils::southbound::OspfRouteType; use holo_utils::sr::IgpAlgoType; @@ -23,6 +24,7 @@ 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}; @@ -41,6 +43,7 @@ pub struct RouteNet { pub sr_label: Option