Skip to content

Commit

Permalink
bier,ospf: Handle configuration events
Browse files Browse the repository at this point in the history
- Handle BIER enable / disable by re-installing routes in the BIRT /
purging the BIRT, and re-originating self-LSA to advertise the update
- Handle BIER sub-domain configuration events by re-originating self-LSA
- Handle BIER encapsulation configuration events by re-originating
self-LSA

Signed-off-by: Nicolas Rybowski <[email protected]>
  • Loading branch information
nrybowski committed Sep 9, 2024
1 parent 5fdfa58 commit 3764c57
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 17 deletions.
23 changes: 22 additions & 1 deletion holo-ospf/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::sync::Arc;

use chrono::Utc;
use holo_utils::bfd;
use holo_utils::ibus::SrCfgEvent;
use holo_utils::ibus::{BierCfgEvent, SrCfgEvent};

use crate::area::{Area, AreaType};
use crate::collections::{
Expand Down Expand Up @@ -1429,6 +1429,27 @@ where
Ok(())
}

// ===== BIER configuration change event =====

pub(crate) fn process_bier_cfg_change<V>(
instance: &mut Instance<V>,
change: BierCfgEvent,
) -> Result<(), Error<V>>
where
V: Version,
{
if let Some((instance, arenas)) = instance.as_up()
&& instance.config.bier.enabled
{
V::lsa_orig_event(
&instance,
arenas,
LsaOriginateEvent::BierCfgChange { change },
)?;
}
Ok(())
}

// ===== BFD state update event =====

pub(crate) fn process_bfd_state_update<V>(
Expand Down
4 changes: 4 additions & 0 deletions holo-ospf/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,17 @@ where
IbusMsg::SrCfgUpd(sr_config) => {
instance.shared.sr_config = sr_config;
}
// BIER configuration update.
IbusMsg::BierCfgUpd(bier_config) => {
instance.shared.bier_config = bier_config.clone();
}
// SR configuration event.
IbusMsg::SrCfgEvent(event) => {
events::process_sr_cfg_change(instance, event)?
}
IbusMsg::BierCfgEvent(event) => {
events::process_bier_cfg_change(instance, event)?
}
// Ignore other events.
_ => {}
}
Expand Down
6 changes: 5 additions & 1 deletion holo-ospf/src/lsdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::time::Instant;
use bitflags::bitflags;
use chrono::Utc;
use derive_new::new;
use holo_utils::ibus::SrCfgEvent;
use holo_utils::ibus::{BierCfgEvent, SrCfgEvent};
use holo_utils::task::TimeoutTask;
use holo_utils::UnboundedSender;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -124,6 +124,10 @@ pub enum LsaOriginateEvent {
area_id: AreaId,
iface_id: InterfaceId,
},
BierEnableChange,
BierCfgChange {
change: BierCfgEvent,
},
}

#[derive(Debug)]
Expand Down
22 changes: 22 additions & 0 deletions holo-ospf/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub enum Event {
RerunSpf,
UpdateSummaries,
ReinstallRoutes,
BierEnableChange(bool),
}

pub static VALIDATION_CALLBACKS_OSPFV2: Lazy<ValidationCallbacks> =
Expand Down Expand Up @@ -791,6 +792,8 @@ where
.modify_apply(|instance, args| {
let mt_id = args.dnode.get_u8();
instance.config.bier.mt_id = mt_id;

// TODO: should reoriginate LSA
})
.delete_apply(|instance, _args| {
let mt_id = 0;
Expand All @@ -800,6 +803,9 @@ where
.modify_apply(|instance, args| {
let enable = args.dnode.get_bool();
instance.config.bier.enabled = enable;

let event_queue = args.event_queue;
event_queue.insert(Event::BierEnableChange(enable));
})
.path(ospf::bier_ospf_cfg::bier::advertise::PATH)
.modify_apply(|instance, args| {
Expand Down Expand Up @@ -1504,6 +1510,22 @@ where
}
}
}
Event::BierEnableChange(bier_enabled) => {
if let Some((instance, _arenas)) = self.as_up() {
// (Re)originate LSAs that might have been affected.
instance
.tx
.protocol_input
.lsa_orig_event(LsaOriginateEvent::BierEnableChange);

// Purge BIRT if bier disabled or re-install routes if enabled
if bier_enabled {
self.process_event(Event::ReinstallRoutes).await;
} else {
let _ = instance.tx.ibus.send(IbusMsg::BierPurge);
}
}
}
Event::RerunSpf => {
if let Some((instance, _)) = self.as_up() {
instance
Expand Down
19 changes: 18 additions & 1 deletion holo-ospf/src/ospfv3/lsdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::{hash_map, BTreeMap, HashMap};
use std::net::{IpAddr, Ipv4Addr};

use holo_utils::bier::{BierEncapsulationType, BierInBiftId, BiftId};
use holo_utils::ibus::SrCfgEvent;
use holo_utils::ibus::{BierCfgEvent, SrCfgEvent};
use holo_utils::ip::{AddressFamily, IpNetworkKind};
use holo_utils::mpls::Label;
use holo_utils::sr::{IgpAlgoType, Sid, SidLastHopBehavior};
Expand Down Expand Up @@ -281,6 +281,23 @@ impl LsdbVersion<Self> for Ospfv3 {
}
}
}
LsaOriginateEvent::BierEnableChange => {
// Reoriginate Intra-area-prefix-LSA(s) in all areas.
for area in arenas.areas.iter() {
lsa_orig_intra_area_prefix(area, instance, arenas);
}
}
LsaOriginateEvent::BierCfgChange { change } => match change {
BierCfgEvent::EncapUpdate(af)
| BierCfgEvent::SubDomainUpdate(af) => {
if af == instance.state.af {
for area in arenas.areas.iter() {
// Reoriginate Intra-area-prefix-LSA(s) in all areas.
lsa_orig_intra_area_prefix(area, instance, arenas);
}
}
}
},
};

Ok(())
Expand Down
17 changes: 15 additions & 2 deletions holo-ospf/src/southbound/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::net::IpAddr;
use holo_utils::ibus::{IbusMsg, IbusSender};
use holo_utils::mpls::Label;
use holo_utils::southbound::{
BierNbrInstallMsg, LabelInstallMsg, LabelUninstallMsg, Nexthop,
RouteKeyMsg, RouteMsg, RouteOpaqueAttrs,
BierNbrInstallMsg, BierNbrUninstallMsg, LabelInstallMsg, LabelUninstallMsg,
Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs,
};

use crate::collections::Arena;
Expand Down Expand Up @@ -140,6 +140,19 @@ pub(crate) fn route_uninstall<V>(
let msg = IbusMsg::RouteMplsDel(msg);
let _ = ibus_tx.send(msg);
}

// Uninstall BIER neighbor entry
if let Some(bier_info) = &route.bier_info {
for bsl in &bier_info.bfr_bss {
let msg = BierNbrUninstallMsg {
sd_id: bier_info.sd_id,
bfr_id: bier_info.bfr_id,
bsl: *bsl,
};
let msg = IbusMsg::RouteBierDel(msg);
let _ = ibus_tx.send(msg);
}
}
}

pub(crate) fn adj_sid_install<V>(
Expand Down
6 changes: 6 additions & 0 deletions holo-routing/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) {
IbusMsg::RouteBierAdd(msg) => {
master.birt.bier_nbr_add(msg);
}
IbusMsg::RouteBierDel(msg) => {
master.birt.bier_nbr_del(msg);
}
IbusMsg::BierPurge => {
master.birt.entries.clear();
}
// Ignore other events.
_ => {}
}
Expand Down
20 changes: 18 additions & 2 deletions holo-routing/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum Event {
SrCfgPrefixSidUpdate(AddressFamily),
BierCfgUpdate,
BierCfgEncapUpdate(SubDomainId, AddressFamily, Bsl, BierEncapsulationType),
BierCfgSubDomainUpdate(AddressFamily),
}

// ===== configuration structs =====
Expand Down Expand Up @@ -665,6 +666,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.delete_apply(|master, args| {
let sd_id = args.dnode.get_u8_relative("./sub-domain-id").unwrap();
Expand All @@ -673,6 +675,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.lookup(|_master, _list_entry, dnode| {
let sd_id = dnode.get_u8_relative("./sub-domain-id").unwrap();
Expand All @@ -689,6 +692,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::underlay_protocol_type::PATH)
.modify_apply(|context, args| {
Expand All @@ -701,6 +705,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::mt_id::PATH)
.modify_apply(|context, args| {
Expand All @@ -712,6 +717,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::bfr_id::PATH)
.modify_apply(|context, args| {
Expand All @@ -723,6 +729,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::bsl::PATH)
.modify_apply(|context, args| {
Expand All @@ -735,6 +742,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::igp_algorithm::PATH)
.modify_apply(|context, args| {
Expand All @@ -746,6 +754,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::bier_algorithm::PATH)
.modify_apply(|context, args| {
Expand All @@ -757,6 +766,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::load_balance_num::PATH)
.modify_apply(|context, args| {
Expand All @@ -768,6 +778,7 @@ fn load_callbacks() -> Callbacks<Master> {

let event_queue = args.event_queue;
event_queue.insert(Event::BierCfgUpdate);
event_queue.insert(Event::BierCfgSubDomainUpdate(af));
})
.path(bier::sub_domain::encapsulation::PATH)
.create_apply(|context, args| {
Expand Down Expand Up @@ -1062,9 +1073,14 @@ impl Provider for Master {
.ibus_tx
.send(IbusMsg::BierCfgUpd(self.shared.bier_config.clone()));
}
Event::BierCfgEncapUpdate(sd_id, af, bsl, encap_type) => {
Event::BierCfgEncapUpdate(_sd_id, af, _bsl, _encap_type) => {
let _ = self
.ibus_tx
.send(IbusMsg::BierCfgEvent(BierCfgEvent::EncapUpdate(af)));
}
Event::BierCfgSubDomainUpdate(af) => {
let _ = self.ibus_tx.send(IbusMsg::BierCfgEvent(
BierCfgEvent::EncapUpdate(sd_id, af, bsl, encap_type),
BierCfgEvent::SubDomainUpdate(af),
));
}
}
Expand Down
9 changes: 7 additions & 2 deletions holo-routing/src/rib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use holo_utils::ip::{AddressFamily, IpNetworkExt, Ipv4AddrExt, Ipv6AddrExt};
use holo_utils::mpls::Label;
use holo_utils::protocol::Protocol;
use holo_utils::southbound::{
AddressFlags, AddressMsg, BierNbrInstallMsg, LabelInstallMsg,
LabelUninstallMsg, Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs,
AddressFlags, AddressMsg, BierNbrInstallMsg, BierNbrUninstallMsg,
LabelInstallMsg, LabelUninstallMsg, Nexthop, RouteKeyMsg, RouteMsg,
RouteOpaqueAttrs,
};
use holo_utils::{UnboundedReceiver, UnboundedSender};
use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
Expand Down Expand Up @@ -83,6 +84,10 @@ impl Birt {
}
});
}

pub(crate) fn bier_nbr_del(&mut self, msg: BierNbrUninstallMsg) {
let _ = self.entries.remove(&(msg.sd_id, msg.bfr_id, msg.bsl));
}
}

// ===== impl Rib =====
Expand Down
17 changes: 10 additions & 7 deletions holo-utils/src/ibus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use serde::{Deserialize, Serialize};
use tokio::sync::broadcast::{Receiver, Sender};

use crate::bfd;
use crate::bier::{BierCfg, BierEncapsulationType, Bsl, SubDomainId};
use crate::bier::BierCfg;
use crate::ip::AddressFamily;
use crate::keychain::Keychain;
use crate::policy::{MatchSets, Policy};
use crate::protocol::Protocol;
use crate::southbound::{
AddressMsg, BierNbrInstallMsg, InterfaceUpdateMsg, LabelInstallMsg,
LabelUninstallMsg, RouteKeyMsg, RouteMsg,
AddressMsg, BierNbrInstallMsg, BierNbrUninstallMsg, InterfaceUpdateMsg,
LabelInstallMsg, LabelUninstallMsg, RouteKeyMsg, RouteMsg,
};
use crate::sr::SrCfg;

Expand Down Expand Up @@ -112,10 +112,12 @@ pub enum IbusMsg {
BierCfgUpd(Arc<BierCfg>),
// BIER configuration event.
BierCfgEvent(BierCfgEvent),
// Request to install an entry in the BIRT
// Request to install an entry in the BIRT.
RouteBierAdd(BierNbrInstallMsg),
// Request to uninstall an entry in the BIRT
RouteBierDel(),
// Request to uninstall an entry in the BIRT.
RouteBierDel(BierNbrUninstallMsg),
// Purge the BIRT.
BierPurge,
}

// Type of Segment Routing configuration change.
Expand All @@ -128,5 +130,6 @@ pub enum SrCfgEvent {
// Type of BIER configuration events.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum BierCfgEvent {
EncapUpdate(SubDomainId, AddressFamily, Bsl, BierEncapsulationType),
SubDomainUpdate(AddressFamily),
EncapUpdate(AddressFamily),
}
10 changes: 9 additions & 1 deletion holo-utils/src/southbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use holo_yang::{ToYang, TryFromYang};
use ipnetwork::IpNetwork;
use serde::{Deserialize, Serialize};

use crate::bier::BierInfo;
use crate::bier::{BfrId, BierInfo, Bsl, SubDomainId};
use crate::mpls::Label;
use crate::protocol::Protocol;

Expand Down Expand Up @@ -110,6 +110,14 @@ pub struct BierNbrInstallMsg {
pub prefix: IpNetwork,
}

#[derive(Clone, Debug)]
#[derive(Deserialize, Serialize)]
pub struct BierNbrUninstallMsg {
pub sd_id: SubDomainId,
pub bfr_id: BfrId,
pub bsl: Bsl,
}

#[derive(Clone, Debug)]
#[derive(Deserialize, Serialize)]
pub struct LabelInstallMsg {
Expand Down

0 comments on commit 3764c57

Please sign in to comment.