From 3cb75a9a388663c793b98d718dae4d7b44b4dfaa Mon Sep 17 00:00:00 2001 From: Paul Wekesa Date: Mon, 14 Oct 2024 14:59:51 +0300 Subject: [PATCH] ibus: restructure IbusMsg IbusMsg had too many items (which can only keep growing). This commie restructures the actions and categorize each item e.g Interface and it's actions e.g add, delete, update etc... Signed-off-by: Paul Wekesa --- holo-bfd/src/master.rs | 54 ++-- holo-bfd/src/session.rs | 6 +- holo-bgp/src/instance.rs | 85 ++++--- holo-bgp/src/northbound/configuration.rs | 12 +- holo-bgp/src/southbound/tx.rs | 15 +- holo-interface/src/ibus.rs | 97 ++++---- holo-isis/src/instance.rs | 53 ++-- holo-isis/src/interface.rs | 6 +- holo-isis/src/southbound/tx.rs | 4 +- holo-keychain/src/northbound/configuration.rs | 6 +- holo-ldp/src/instance.rs | 76 ++++-- holo-ldp/src/northbound/configuration.rs | 12 +- holo-ldp/src/southbound/tx.rs | 8 +- holo-ospf/src/instance.rs | 145 +++++++---- holo-ospf/src/neighbor.rs | 22 +- holo-ospf/src/northbound/configuration.rs | 6 +- holo-ospf/src/southbound/tx.rs | 24 +- holo-policy/src/northbound/configuration.rs | 9 +- holo-rip/src/instance.rs | 32 ++- holo-rip/src/northbound/configuration.rs | 12 +- holo-rip/src/southbound/tx.rs | 6 +- holo-routing/src/ibus.rs | 232 +++++++++++------- holo-routing/src/northbound/configuration.rs | 42 ++-- holo-system/src/ibus.rs | 21 +- holo-utils/src/ibus.rs | 185 ++++++++++---- 25 files changed, 746 insertions(+), 424 deletions(-) diff --git a/holo-bfd/src/master.rs b/holo-bfd/src/master.rs index 50d7137e..78590661 100644 --- a/holo-bfd/src/master.rs +++ b/holo-bfd/src/master.rs @@ -12,7 +12,7 @@ use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; use holo_utils::bfd::{PathType, State}; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{BfdSessionMsg, IbusMsg, InterfaceMsg}; use holo_utils::ip::AddressFamily; use holo_utils::protocol::Protocol; use holo_utils::task::Task; @@ -144,7 +144,7 @@ impl ProtocolInstance for Master { async fn init(&mut self) { // Request information about all interfaces. - let _ = self.tx.ibus.send(IbusMsg::InterfaceDump); + let _ = self.tx.ibus.send(IbusMsg::Interface(InterfaceMsg::Dump)); } async fn process_ibus_msg(&mut self, msg: IbusMsg) { @@ -229,27 +229,35 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - // BFD peer registration. - IbusMsg::BfdSessionReg { - client_id, - sess_key, - client_config, - } => events::process_client_peer_reg( - master, - sess_key, - client_id, - client_config, - )?, - // BFD peer unregistration. - IbusMsg::BfdSessionUnreg { - sess_key, - client_id, - } => events::process_client_peer_unreg(master, sess_key, client_id)?, - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - southbound::process_iface_update(master, msg); - } - // Ignore other events. + // BFD Session + IbusMsg::BfdSession(bfd_msg) => match bfd_msg { + BfdSessionMsg::Registration { + sess_key, + client_id, + client_config, + } => events::process_client_peer_reg( + master, + sess_key, + client_id, + client_config, + )?, + BfdSessionMsg::Unregistration { + sess_key, + client_id, + } => { + events::process_client_peer_unreg(master, sess_key, client_id)? + } + _ => {} + }, + + // Interface + IbusMsg::Interface(iface_msg) => match iface_msg { + InterfaceMsg::Update(msg) => { + southbound::process_iface_update(master, msg) + } + _ => {} + }, + _ => {} } diff --git a/holo-bfd/src/session.rs b/holo-bfd/src/session.rs index 37543d00..bf4942a7 100644 --- a/holo-bfd/src/session.rs +++ b/holo-bfd/src/session.rs @@ -15,7 +15,7 @@ use generational_arena::{Arena, Index}; use holo_northbound::yang::control_plane_protocol::bfd; use holo_protocol::InstanceChannelsTx; use holo_utils::bfd::{ClientCfg, ClientId, SessionKey, State}; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{BfdSessionMsg, IbusMsg}; use holo_utils::ip::{IpAddrExt, IpAddrKind}; use holo_utils::socket::{UdpSocket, TTL_MAX}; use holo_utils::task::{IntervalTask, TimeoutTask}; @@ -141,10 +141,10 @@ impl Session { // Notify protocol clients about the state transition if necessary. if self.should_notify_clients(old_state) && !self.clients.is_empty() { - let msg = IbusMsg::BfdStateUpd { + let msg = IbusMsg::BfdSession(BfdSessionMsg::Update { sess_key: self.key.clone(), state, - }; + }); let _ = tx.ibus.send(msg); } diff --git a/holo-bgp/src/instance.rs b/holo-bgp/src/instance.rs index 202bc880..d7ed30fc 100644 --- a/holo-bgp/src/instance.rs +++ b/holo-bgp/src/instance.rs @@ -12,7 +12,9 @@ use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; use holo_utils::bgp::AfiSafi; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{ + IbusMsg, NexthopMsg, PolicyMsg, RouteRedistributeMsg, RouterIdMsg, +}; use holo_utils::ip::AddressFamily; use holo_utils::policy::PolicyType; use holo_utils::protocol::Protocol; @@ -447,36 +449,59 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - IbusMsg::NexthopUpd { addr, metric } => { - // Nexthop tracking update notification. - southbound::rx::process_nht_update(instance, addr, metric); - } - IbusMsg::RouterIdUpdate(router_id) => { - // Router ID update notification. - southbound::rx::process_router_id_update(instance, router_id).await; - } - IbusMsg::PolicyMatchSetsUpd(match_sets) => { - // Update the local copy of the policy match sets. - instance.shared.policy_match_sets = match_sets; - } - IbusMsg::PolicyUpd(policy) => { - // Update the local copy of the policy definition. - instance - .shared - .policies - .insert(policy.name.clone(), policy.clone()); - } - IbusMsg::PolicyDel(policy_name) => { - // Remove the local copy of the policy definition. - instance.shared.policies.remove(&policy_name); - } - IbusMsg::RouteRedistributeAdd(msg) => { - // Route redistribute update notification. - southbound::rx::process_route_add(instance, msg); + // Nexthop + IbusMsg::Nexthop(nexthop_msg) => { + match nexthop_msg { + NexthopMsg::Update { addr, metric } => { + // Nexthop tracking update notification. + southbound::rx::process_nht_update(instance, addr, metric); + } + _ => {} + } } - IbusMsg::RouteRedistributeDel(msg) => { - // Route redistribute delete notification. - southbound::rx::process_route_del(instance, msg); + + // Router ID + IbusMsg::RouterId(router_id_msg) => match router_id_msg { + RouterIdMsg::Update(router_id) => { + // Router ID update notification. + southbound::rx::process_router_id_update(instance, router_id) + .await; + } + _ => {} + }, + + // policy + IbusMsg::Policy(policy_msg) => match policy_msg { + PolicyMsg::MatchSetsUpdate(match_sets) => { + // Update the local copy of the policy match sets. + instance.shared.policy_match_sets = match_sets; + } + PolicyMsg::Update(policy) => { + // Update the local copy of the policy definition. + instance + .shared + .policies + .insert(policy.name.clone(), policy.clone()); + } + PolicyMsg::Delete(policy_name) => { + // Remove the local copy of the policy definition. + instance.shared.policies.remove(&policy_name); + } + }, + + // route redistribute + IbusMsg::RouteRedistribute(route_redistribute_msg) => { + match route_redistribute_msg { + RouteRedistributeMsg::Add(msg) => { + // Route redistribute update notification. + southbound::rx::process_route_add(instance, msg); + } + RouteRedistributeMsg::Delete(msg) => { + // Route redistribute delete notification. + southbound::rx::process_route_del(instance, msg); + } + _ => {} + } } // Ignore other events. _ => {} diff --git a/holo-bgp/src/northbound/configuration.rs b/holo-bgp/src/northbound/configuration.rs index 93b17230..ed5246f2 100644 --- a/holo-bgp/src/northbound/configuration.rs +++ b/holo-bgp/src/northbound/configuration.rs @@ -18,7 +18,7 @@ use holo_northbound::configuration::{ }; use holo_northbound::yang::control_plane_protocol::bgp; use holo_utils::bgp::AfiSafi; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, RouteRedistributeMsg}; use holo_utils::ip::{AddressFamily, IpAddrKind}; use holo_utils::policy::{ApplyPolicyCfg, DefaultPolicyType}; use holo_utils::protocol::Protocol; @@ -1363,10 +1363,12 @@ impl Provider for Instance { } } Event::RedistributeRequest(protocol, af) => { - let _ = self.tx.ibus.send(IbusMsg::RouteRedistributeDump { - protocol, - af: Some(af), - }); + let _ = self.tx.ibus.send(IbusMsg::RouteRedistribute( + RouteRedistributeMsg::Dump { + protocol, + af: Some(af), + }, + )); } Event::RedistributeDelete(protocol, afi_safi) => { let Some((mut instance, _)) = self.as_up() else { diff --git a/holo-bgp/src/southbound/tx.rs b/holo-bgp/src/southbound/tx.rs index 1b9622ea..ca934145 100644 --- a/holo-bgp/src/southbound/tx.rs +++ b/holo-bgp/src/southbound/tx.rs @@ -7,7 +7,9 @@ use std::collections::BTreeSet; use std::net::IpAddr; -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{ + IbusMsg, IbusSender, NexthopMsg, RouteIpMsg, RouterIdMsg, +}; use holo_utils::protocol::Protocol; use holo_utils::southbound::{ Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs, @@ -19,7 +21,7 @@ use crate::rib::LocalRoute; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterIdQuery); + let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); } pub(crate) fn route_install( @@ -50,7 +52,7 @@ pub(crate) fn route_install( opaque_attrs: RouteOpaqueAttrs::None, nexthops: nexthops.clone(), }; - let msg = IbusMsg::RouteIpAdd(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); let _ = ibus_tx.send(msg); } @@ -63,16 +65,17 @@ pub(crate) fn route_uninstall( protocol: Protocol::BGP, prefix: prefix.into(), }; - let msg = IbusMsg::RouteIpDel(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); let _ = ibus_tx.send(msg); } pub(crate) fn nexthop_track(ibus_tx: &IbusSender, addr: IpAddr) { - let msg = IbusMsg::NexthopTrack(addr); + let msg = IbusMsg::Nexthop(NexthopMsg::Track(addr)); let _ = ibus_tx.send(msg); } pub(crate) fn nexthop_untrack(ibus_tx: &IbusSender, addr: IpAddr) { - let msg = IbusMsg::NexthopUntrack(addr); + //let msg = IbusMsg::NexthopUntrack(addr); + let msg = IbusMsg::Nexthop(NexthopMsg::Untrack(msg)); let _ = ibus_tx.send(msg); } diff --git a/holo-interface/src/ibus.rs b/holo-interface/src/ibus.rs index 45d9024f..382ec17e 100644 --- a/holo-interface/src/ibus.rs +++ b/holo-interface/src/ibus.rs @@ -6,7 +6,9 @@ use std::net::Ipv4Addr; -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{ + IbusMsg, IbusSender, InterfaceAddressMsg, InterfaceMsg, RouterIdMsg, +}; use holo_utils::ip::IpNetworkKind; use holo_utils::southbound::{AddressFlags, AddressMsg, InterfaceUpdateMsg}; use ipnetwork::IpNetwork; @@ -18,45 +20,53 @@ use crate::Master; pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) { match msg { - IbusMsg::InterfaceDump => { - for iface in master.interfaces.iter() { - notify_interface_update(&master.ibus_tx, iface); - - for iface_addr in iface.addresses.values() { - notify_addr_add( - &master.ibus_tx, - iface.name.clone(), - iface_addr.addr, - iface_addr.flags, - ); + // Interface Message + IbusMsg::Interface(iface_msg) => match iface_msg { + InterfaceMsg::Dump => { + for iface in master.interfaces.iter() { + notify_interface_update(&master.ibus_tx, iface); + + for iface_addr in iface.addresses.values() { + notify_addr_add( + &master.ibus_tx, + iface.name.clone(), + iface_addr.addr, + iface_addr.flags, + ); + } } } - } - IbusMsg::InterfaceQuery { ifname, af } => { - if let Some(iface) = master.interfaces.get_by_name(&ifname) { - notify_interface_update(&master.ibus_tx, iface); - - for iface_addr in - iface.addresses.values().filter(|iface_addr| match af { - Some(af) => iface_addr.addr.address_family() == af, - None => true, - }) - { - notify_addr_add( - &master.ibus_tx, - iface.name.clone(), - iface_addr.addr, - iface_addr.flags, - ); + InterfaceMsg::Query { ifname, af } => { + if let Some(iface) = master.interfaces.get_by_name(&ifname) { + notify_interface_update(&master.ibus_tx, iface); + + for iface_addr in + iface.addresses.values().filter(|iface_addr| match af { + Some(af) => iface_addr.addr.address_family() == af, + None => true, + }) + { + notify_addr_add( + &master.ibus_tx, + iface.name.clone(), + iface_addr.addr, + iface_addr.flags, + ); + } } } - } - IbusMsg::RouterIdQuery => { - notify_router_id_update( - &master.ibus_tx, - master.interfaces.router_id(), - ); - } + }, + + // RouterId + IbusMsg::RouterId(router_id_msg) => match router_id_msg { + RouterIdMsg::Query => { + notify_router_id_update( + &master.ibus_tx, + master.interfaces.router_id(), + ); + } + _ => {} + }, // Ignore other events. _ => {} } @@ -66,23 +76,25 @@ pub(crate) fn notify_router_id_update( ibus_tx: &IbusSender, router_id: Option, ) { - let msg = IbusMsg::RouterIdUpdate(router_id); + let msg = IbusMsg::RouterId(RouterIdMsg::Update(router_id)); notify(ibus_tx, msg); } pub(crate) fn notify_interface_update(ibus_tx: &IbusSender, iface: &Interface) { - let msg = IbusMsg::InterfaceUpd(InterfaceUpdateMsg { + let update_msg = InterfaceUpdateMsg { ifname: iface.name.clone(), ifindex: iface.ifindex.unwrap_or(0), mtu: iface.mtu.unwrap_or(0), flags: iface.flags, mac_address: iface.mac_address, - }); + }; + let msg = IbusMsg::Interface(InterfaceMsg::Update(msg)); + notify(ibus_tx, msg); } pub(crate) fn notify_interface_del(ibus_tx: &IbusSender, ifname: String) { - let msg = IbusMsg::InterfaceDel(ifname); + let msg = IbusMsg::Interface(InterfaceMsg::Delete(ifname)); notify(ibus_tx, msg); } @@ -92,11 +104,12 @@ pub(crate) fn notify_addr_add( addr: IpNetwork, flags: AddressFlags, ) { - let msg = IbusMsg::InterfaceAddressAdd(AddressMsg { + let addr_msg = AddressMsg { ifname, addr, flags, - }); + }; + let msg = IbusMsg::InterfaceAddress(InterfaceAddressMsg::Add(addr_msg)); notify(ibus_tx, msg); } diff --git a/holo-isis/src/instance.rs b/holo-isis/src/instance.rs index e8f34912..8ca6d1f7 100644 --- a/holo-isis/src/instance.rs +++ b/holo-isis/src/instance.rs @@ -16,7 +16,9 @@ use chrono::{DateTime, Utc}; use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{ + IbusMsg, InterfaceAddressMsg, InterfaceMsg, RouterIdMsg, +}; use holo_utils::protocol::Protocol; use holo_utils::task::TimeoutTask; use holo_utils::{Receiver, Sender, UnboundedReceiver, UnboundedSender}; @@ -486,22 +488,41 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - // Router ID update notification. - IbusMsg::RouterIdUpdate(router_id) => { - southbound::rx::process_router_id_update(instance, router_id).await; - } - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - southbound::rx::process_iface_update(instance, msg)?; - } - // Interface address addition notification. - IbusMsg::InterfaceAddressAdd(msg) => { - southbound::rx::process_addr_add(instance, msg); - } - // Interface address deletion notification. - IbusMsg::InterfaceAddressDel(msg) => { - southbound::rx::process_addr_del(instance, msg); + // ==== ROUTER ID ==== + IbusMsg::RouterId(router_id_msg) => { + match router_id_msg { + // Router ID update notification. + RouterIdMsg::Update(router_id) => { + southbound::rx::process_router_id_update( + instance, router_id, + ) + .await; + } + _ => {} + } } + + // ==== INTERFACE ==== + IbusMsg::Interface(iface_msg) => match iface_msg { + // Interface update notification. + InterfaceMsg::Update(msg) => { + southbound::rx::process_iface_update(instance, msg); + } + _ => {} + }, + + // ==== INTERFACE ADDRESS ==== + IbusMsg::InterfaceAddress(iface_addr_msg) => match iface_addr_msg { + // Interface address addition notification. + InterfaceAddressMsg::Add(msg) => { + southbound::rx::process_addr_add(instance, msg); + } + + // Interface address deletion notification. + InterfaceAddressMsg::Delete(msg) => { + southbound::rx::process_addr_del(instance, msg); + } + }, // Ignore other events. _ => {} } diff --git a/holo-isis/src/interface.rs b/holo-isis/src/interface.rs index 429d80d9..e8034c2c 100644 --- a/holo-isis/src/interface.rs +++ b/holo-isis/src/interface.rs @@ -13,7 +13,7 @@ use std::sync::Arc; use chrono::{DateTime, Utc}; use holo_protocol::InstanceChannelsTx; -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{IbusMsg, IbusSender, InterfaceMsg}; use holo_utils::ip::AddressFamily; use holo_utils::socket::{AsyncFd, Socket, SocketExt}; use holo_utils::southbound::InterfaceFlags; @@ -643,10 +643,10 @@ impl Interface { // Sends a southbound request for interface system information, such as // operational status and IP addresses. pub(crate) fn query_southbound(&self, ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::InterfaceQuery { + let _ = ibus_tx.send(IbusMsg::Interface(InterfaceMsg::Query { ifname: self.name.clone(), af: None, - }); + })); } } diff --git a/holo-isis/src/southbound/tx.rs b/holo-isis/src/southbound/tx.rs index 11dc1a57..fe328d33 100644 --- a/holo-isis/src/southbound/tx.rs +++ b/holo-isis/src/southbound/tx.rs @@ -7,10 +7,10 @@ // See: https://nlnet.nl/NGI0 // -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{IbusMsg, IbusSender, RouterIdMsg}; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterIdQuery); + let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); } diff --git a/holo-keychain/src/northbound/configuration.rs b/holo-keychain/src/northbound/configuration.rs index 6d305561..753497c9 100644 --- a/holo-keychain/src/northbound/configuration.rs +++ b/holo-keychain/src/northbound/configuration.rs @@ -15,7 +15,7 @@ use holo_northbound::configuration::{ }; use holo_northbound::yang::key_chains; use holo_utils::crypto::CryptoAlgo; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, KeychainMsg}; use holo_utils::keychain::{Key, Keychain, KeychainKey}; use holo_utils::yang::DataNodeRefExt; use holo_yang::TryFromYang; @@ -443,12 +443,12 @@ impl Provider for Master { let keychain = Arc::new(keychain.clone()); // Notify protocols that the keychain has been updated. - let msg = IbusMsg::KeychainUpd(keychain); + let msg = IbusMsg::Keychain(KeychainMsg::Update(keychain)); let _ = self.ibus_tx.send(msg); } Event::KeychainDelete(name) => { // Notify protocols that the keychain has been deleted. - let msg = IbusMsg::KeychainDel(name); + let msg = IbusMsg::Keychain(KeychainMsg::Delete(name)); let _ = self.ibus_tx.send(msg); } } diff --git a/holo-ldp/src/instance.rs b/holo-ldp/src/instance.rs index 870cdb03..577851fe 100644 --- a/holo-ldp/src/instance.rs +++ b/holo-ldp/src/instance.rs @@ -14,7 +14,10 @@ use derive_new::new; use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{ + IbusMsg, InterfaceAddressMsg, InterfaceMsg, RouteRedistributeMsg, + RouterIdMsg, +}; use holo_utils::protocol::Protocol; use holo_utils::socket::{TcpListener, UdpSocket}; use holo_utils::task::Task; @@ -468,29 +471,56 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - southbound::rx::process_iface_update(instance, msg); - } - // Interface address addition notification. - IbusMsg::InterfaceAddressAdd(msg) => { - southbound::rx::process_addr_add(instance, msg); - } - // Interface address delete notification. - IbusMsg::InterfaceAddressDel(msg) => { - southbound::rx::process_addr_del(instance, msg); - } - // Router ID update notification. - IbusMsg::RouterIdUpdate(router_id) => { - southbound::rx::process_router_id_update(instance, router_id).await; - } - // Route redistribute update notification. - IbusMsg::RouteRedistributeAdd(msg) => { - southbound::rx::process_route_add(instance, msg); + // ==== INTERFACE ==== + IbusMsg::Interface(iface_msg) => match iface_msg { + // Interface update notification. + InterfaceMsg::Update(msg) => { + southbound::rx::process_iface_update(instance, msg); + } + _ => {} + }, + + // ==== INTERFACE ADDRESS ==== + IbusMsg::InterfaceAddress(iface_addr_msg) => match iface_addr_msg { + // Interface address addition notification. + InterfaceAddressMsg::Add(msg) => { + southbound::rx::process_addr_add(instance, msg); + } + + // Interface address delete notification. + InterfaceAddressMsg::Delete(msg) => { + southbound::rx::process_addr_del(instance, msg); + } + }, + + // ==== ROUTER ID ==== + IbusMsg::RouterId(router_id_msg) => { + match router_id_msg { + // Router ID update notification. + RouterIdMsg::Update(router_id) => { + southbound::rx::process_router_id_update( + instance, router_id, + ) + .await; + } + _ => {} + } } - // Route redistribute delete notification. - IbusMsg::RouteRedistributeDel(msg) => { - southbound::rx::process_route_del(instance, msg); + + // ==== ROUTE REDISTRIBUTE ==== + IbusMsg::RouteRedistribute(route_redistribute_msg) => { + match route_redistribute_msg { + // Route redistribute update notification. + RouteRedistributeMsg::Add(msg) => { + southbound::rx::process_route_add(instance, msg); + } + + // Route redistribute delete notification. + RouteRedistributeMsg::Delete(msg) => { + southbound::rx::process_route_del(instance, msg); + } + _ => {} + } } // Ignore other events. _ => {} diff --git a/holo-ldp/src/northbound/configuration.rs b/holo-ldp/src/northbound/configuration.rs index e217c847..40236be8 100644 --- a/holo-ldp/src/northbound/configuration.rs +++ b/holo-ldp/src/northbound/configuration.rs @@ -15,7 +15,7 @@ use holo_northbound::configuration::{ ValidationCallbacksBuilder, }; use holo_northbound::yang::control_plane_protocol::mpls_ldp; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, InterfaceMsg}; use holo_utils::ip::AddressFamily; use holo_utils::yang::DataNodeRefExt; @@ -471,10 +471,12 @@ impl Provider for Instance { } Event::InterfaceQuerySouthbound(ifname) => { if let Some((instance, _, _)) = self.as_up() { - let _ = instance.tx.ibus.send(IbusMsg::InterfaceQuery { - ifname, - af: Some(AddressFamily::Ipv4), - }); + let _ = instance.tx.ibus.send(IbusMsg::Interface( + InterfaceMsg::Query { + ifname, + af: Some(AddressFamily::Ipv4), + }, + )); } } Event::TargetedNbrUpdate(tnbr_idx) => { diff --git a/holo-ldp/src/southbound/tx.rs b/holo-ldp/src/southbound/tx.rs index 9e3fd073..7632ca7f 100644 --- a/holo-ldp/src/southbound/tx.rs +++ b/holo-ldp/src/southbound/tx.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT // -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{IbusMsg, IbusSender, RouteMplsMsg, RouterIdMsg}; use holo_utils::protocol::Protocol; use holo_utils::southbound::{self, LabelInstallMsg, LabelUninstallMsg}; @@ -13,7 +13,7 @@ use crate::fec::{FecInner, Nexthop}; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterIdQuery); + let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); } pub(crate) fn label_install( @@ -49,7 +49,7 @@ pub(crate) fn label_install( }; // Send message. - let msg = IbusMsg::RouteMplsAdd(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); let _ = ibus_tx.send(msg); } @@ -85,6 +85,6 @@ pub(crate) fn label_uninstall( }; // Send message. - let msg = IbusMsg::RouteMplsDel(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); let _ = ibus_tx.send(msg); } diff --git a/holo-ospf/src/instance.rs b/holo-ospf/src/instance.rs index 3a516637..07037063 100644 --- a/holo-ospf/src/instance.rs +++ b/holo-ospf/src/instance.rs @@ -15,7 +15,10 @@ use chrono::{DateTime, Utc}; use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{ + BierCfgMsg, IbusMsg, InterfaceAddressMsg, InterfaceMsg, KeychainMsg, + RouterIdMsg, SrCfgMsg, +}; use holo_utils::ip::AddressFamily; use holo_utils::protocol::Protocol; use holo_utils::task::TimeoutTask; @@ -737,60 +740,100 @@ where V: Version, { match msg { - // BFD peer state update event. - IbusMsg::BfdStateUpd { sess_key, state } => { - events::process_bfd_state_update(instance, sess_key, state)? - } - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - southbound::rx::process_iface_update(instance, msg); - } - // Interface address addition notification. - IbusMsg::InterfaceAddressAdd(msg) => { - southbound::rx::process_addr_add(instance, msg); - } - // Interface address delete notification. - IbusMsg::InterfaceAddressDel(msg) => { - southbound::rx::process_addr_del(instance, msg); - } - // Keychain update event. - IbusMsg::KeychainUpd(keychain) => { - // Update the local copy of the keychain. - instance - .shared - .keychains - .insert(keychain.name.clone(), keychain.clone()); - - // Update all interfaces using this keychain. - events::process_keychain_update(instance, &keychain.name)? - } - // Keychain delete event. - IbusMsg::KeychainDel(keychain_name) => { - // Remove the local copy of the keychain. - instance.shared.keychains.remove(&keychain_name); + // BFD session Message + IbusMsg::BfdSession(bfd_msg) => match bfd_msg { + holo_utils::ibus::BfdSessionMsg::Update { sess_key, state } => { + events::process_bfd_state_update(instance, sess_key, state)? + } + _ => {} + }, + + // Interface + IbusMsg::Interface(iface_msg) => match iface_msg { + // Interface update notification. + InterfaceMsg::Update(msg) => { + southbound::rx::process_iface_update(instance, msg); + } + _ => {} + }, + + // Interface Address + IbusMsg::InterfaceAddress(iface_addr_msg) => match iface_addr_msg { + // Interface address addition notification. + InterfaceAddressMsg::Add(msg) => { + southbound::rx::process_addr_add(instance, msg); + } + // Interface address delete notification. + InterfaceAddressMsg::Delete(msg) => { + southbound::rx::process_addr_del(instance, msg); + } + }, + + // Keychain + IbusMsg::Keychain(keychain_msg) => match keychain_msg { + // Keychain update event. + KeychainMsg::Update(keychain) => { + // Update the local copy of the keychain. + instance + .shared + .keychains + .insert(keychain.name.clone(), keychain.clone()); + + // Update all interfaces using this keychain. + events::process_keychain_update(instance, &keychain.name)? + } - // Update all interfaces using this keychain. - events::process_keychain_update(instance, &keychain_name)? - } - // Router ID update notification. - IbusMsg::RouterIdUpdate(router_id) => { - southbound::rx::process_router_id_update(instance, router_id); - } - // SR configuration update. - IbusMsg::SrCfgUpd(sr_config) => { - instance.shared.sr_config = sr_config; - } - // BIER configuration update. - IbusMsg::BierCfgUpd(bier_config) => { - instance.shared.bier_config = bier_config.clone(); + // Keychain delete event. + KeychainMsg::Delete(keychain_name) => { + // Remove the local copy of the keychain. + instance.shared.keychains.remove(&keychain_name); + + // Update all interfaces using this keychain. + events::process_keychain_update(instance, &keychain_name)? + } + }, + + // Router ID + IbusMsg::RouterId(router_id_msg) => { + match router_id_msg { + // Router ID update notification. + RouterIdMsg::Update(router_id) => { + southbound::rx::process_router_id_update( + instance, router_id, + ); + } + _ => {} + } } - // SR configuration event. - IbusMsg::SrCfgEvent(event) => { - events::process_sr_cfg_change(instance, event)? + + // SrCfg + IbusMsg::SrCfg(sr_cfg_msg) => { + match sr_cfg_msg { + SrCfgMsg::Update(msg) => { + // BIER configuration update. + instance.shared.bier_config = bier_config.clone(); + } + + // SR configuration event. + SrCfgMsg::Event(event) => { + events::process_sr_cfg_change(instance, event)? + } + } } - IbusMsg::BierCfgEvent(event) => { - events::process_bier_cfg_change(instance, event)? + + // BierCfg + IbusMsg::BierCfg(bier_cfg_msg) => { + match bier_cfg_msg { + // BIER configuration update. + BierCfgMsg::Update(bier_config) => { + instance.shared.bier_config = bier_config.clone(); + } + BierCfgMsg::Event(event) => { + events::process_bier_cfg_change(instance, event)? + } + } } + // Ignore other events. _ => {} } diff --git a/holo-ospf/src/neighbor.rs b/holo-ospf/src/neighbor.rs index 56dd13fe..cf34b842 100644 --- a/holo-ospf/src/neighbor.rs +++ b/holo-ospf/src/neighbor.rs @@ -553,11 +553,13 @@ where ) { Debug::::NeighborBfdReg(self.router_id).log(); - let msg = IbusMsg::BfdSessionReg { - sess_key: self.bfd_session_key(iface), - client_id: self.bfd_client_id(instance), - client_config: Some(iface.config.bfd_params), - }; + let msg = IbusMsg::BfdSession( + holo_utils::ibus::BfdSessionMsg::Registration { + sess_key: self.bfd_session_key(iface), + client_id: self.bfd_client_id(instance), + client_config: Some(iface.config.bfd_params), + }, + ); let _ = instance.tx.ibus.send(msg); } @@ -568,10 +570,12 @@ where ) { Debug::::NeighborBfdUnreg(self.router_id).log(); - let msg = IbusMsg::BfdSessionUnreg { - sess_key: self.bfd_session_key(iface), - client_id: self.bfd_client_id(instance), - }; + let msg = IbusMsg::BfdSession( + holo_utils::ibus::BfdSessionMsg::Unregistration { + sess_key: self.bfd_session_key(iface), + client_id: self.bfd_client_id(instance), + }, + ); let _ = instance.tx.ibus.send(msg); } diff --git a/holo-ospf/src/northbound/configuration.rs b/holo-ospf/src/northbound/configuration.rs index 36e09b53..fff65a67 100644 --- a/holo-ospf/src/northbound/configuration.rs +++ b/holo-ospf/src/northbound/configuration.rs @@ -17,7 +17,7 @@ use holo_northbound::configuration::{ use holo_northbound::yang::control_plane_protocol::ospf; use holo_utils::bfd; use holo_utils::crypto::CryptoAlgo; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, InterfaceMsg}; use holo_utils::ip::{AddressFamily, IpAddrKind, IpNetworkKind}; use holo_utils::yang::DataNodeRefExt; use holo_yang::{ToYang, TryFromYang}; @@ -1448,10 +1448,10 @@ where } Event::InterfaceQuerySouthbound(ifname, af) => { if self.is_active() { - let _ = self.tx.ibus.send(IbusMsg::InterfaceQuery { + let _ = self.tx.send(IbusMsg::Interface(InterfaceMsg::Query { ifname, af: Some(af), - }); + })); } } Event::StubRouterChange => { diff --git a/holo-ospf/src/southbound/tx.rs b/holo-ospf/src/southbound/tx.rs index 4e455557..b106abd7 100644 --- a/holo-ospf/src/southbound/tx.rs +++ b/holo-ospf/src/southbound/tx.rs @@ -7,7 +7,9 @@ use std::collections::BTreeSet; use std::net::IpAddr; -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{ + IbusMsg, IbusSender, RouteBierMsg, RouteIpMsg, RouteMplsMsg, RouterIdMsg, +}; use holo_utils::mpls::Label; use holo_utils::southbound::{ BierNbrInstallMsg, BierNbrUninstallMsg, LabelInstallMsg, LabelUninstallMsg, @@ -22,7 +24,7 @@ use crate::version::Version; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterIdQuery); + let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); } pub(crate) fn route_install( @@ -72,7 +74,7 @@ pub(crate) fn route_install( }, nexthops: nexthops.clone(), }; - let msg = IbusMsg::RouteIpAdd(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); let _ = ibus_tx.send(msg); // Unnstall previous SR Prefix-SID input label if it has changed. @@ -84,7 +86,7 @@ pub(crate) fn route_install( nexthops: BTreeSet::new(), route: None, }; - let msg = IbusMsg::RouteMplsDel(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); let _ = ibus_tx.send(msg); } } @@ -98,7 +100,7 @@ pub(crate) fn route_install( route: None, replace: true, }; - let msg = IbusMsg::RouteMplsAdd(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); let _ = ibus_tx.send(msg); } @@ -109,7 +111,7 @@ pub(crate) fn route_install( nexthops, prefix: (*destination).into(), }; - let msg = IbusMsg::RouteBierAdd(msg); + let msg = IbusMsg::RouteBier(holo_utils::ibus::RouteBierMsg::Add(msg)); let _ = ibus_tx.send(msg); } } @@ -126,7 +128,7 @@ pub(crate) fn route_uninstall( protocol: V::PROTOCOL, prefix: (*destination).into(), }; - let msg = IbusMsg::RouteIpDel(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); let _ = ibus_tx.send(msg); // Uninstall SR Prefix-SID input label. @@ -137,7 +139,7 @@ pub(crate) fn route_uninstall( nexthops: BTreeSet::new(), route: None, }; - let msg = IbusMsg::RouteMplsDel(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); let _ = ibus_tx.send(msg); } @@ -149,7 +151,7 @@ pub(crate) fn route_uninstall( bfr_id: bier_info.bfr_id, bsl: *bsl, }; - let msg = IbusMsg::RouteBierDel(msg); + let msg = IbusMsg::RouteBier(RouteBierMsg::Delete(msg)); let _ = ibus_tx.send(msg); } } @@ -175,7 +177,7 @@ pub(crate) fn adj_sid_install( route: None, replace: false, }; - let msg = IbusMsg::RouteMplsAdd(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); let _ = ibus_tx.send(msg); } @@ -189,6 +191,6 @@ where nexthops: BTreeSet::new(), route: None, }; - let msg = IbusMsg::RouteMplsDel(msg); + let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); let _ = ibus_tx.send(msg); } diff --git a/holo-policy/src/northbound/configuration.rs b/holo-policy/src/northbound/configuration.rs index 33a3e210..689bcca4 100644 --- a/holo-policy/src/northbound/configuration.rs +++ b/holo-policy/src/northbound/configuration.rs @@ -13,7 +13,7 @@ use holo_northbound::configuration::{ self, Callbacks, CallbacksBuilder, Provider, }; use holo_northbound::yang::routing_policy; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, PolicyMsg}; use holo_utils::ip::AddressFamily; use holo_utils::policy::{ IpPrefixRange, MatchSetRestrictedType, MatchSetType, MetricType, @@ -1109,7 +1109,8 @@ impl Provider for Master { // Notify protocols that the policy match sets have been // updated. - let msg = IbusMsg::PolicyMatchSetsUpd(match_sets); + let msg = + IbusMsg::Policy(PolicyMsg::MatchSetsUpdate(match_sets)); let _ = self.ibus_tx.send(msg); } Event::PolicyChange(name) => { @@ -1120,12 +1121,12 @@ impl Provider for Master { let policy = Arc::new(policy.clone()); // Notify protocols that the policy has been updated. - let msg = IbusMsg::PolicyUpd(policy); + let msg = IbusMsg::Policy(PolicyMsg::Update(policy)); let _ = self.ibus_tx.send(msg); } Event::PolicyDelete(name) => { // Notify protocols that the policy definition has been deleted. - let msg = IbusMsg::PolicyDel(name); + let msg = IbusMsg::Policy(PolicyMsg::Delete(name)); let _ = self.ibus_tx.send(msg); } } diff --git a/holo-rip/src/instance.rs b/holo-rip/src/instance.rs index a31530ca..62841506 100644 --- a/holo-rip/src/instance.rs +++ b/holo-rip/src/instance.rs @@ -16,7 +16,7 @@ use enum_as_inner::EnumAsInner; use holo_protocol::{ InstanceChannelsTx, InstanceShared, MessageReceiver, ProtocolInstance, }; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, InterfaceAddressMsg, InterfaceMsg}; use holo_utils::protocol::Protocol; use holo_utils::task::{IntervalTask, TimeoutTask}; use holo_utils::{Receiver, Sender, UnboundedReceiver, UnboundedSender}; @@ -539,17 +539,25 @@ where { match msg { // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - southbound::rx::process_iface_update(instance, msg); - } - // Interface address addition notification. - IbusMsg::InterfaceAddressAdd(msg) => { - southbound::rx::process_addr_add(instance, msg); - } - // Interface address delete notification. - IbusMsg::InterfaceAddressDel(msg) => { - southbound::rx::process_addr_del(instance, msg); - } + IbusMsg::Interface(iface_msg) => match iface_msg { + InterfaceMsg::Update(msg) => { + southbound::rx::process_iface_update(instance, msg); + } + _ => {} + }, + + // Interface address + IbusMsg::InterfaceAddress(iface_addr_msg) => match iface_addr_msg { + // Interface address addition notification. + InterfaceAddressMsg::Add(msg) => { + southbound::rx::process_addr_add(instance, msg); + } + + // Interface address delete notification. + InterfaceAddressMsg::Delete(msg) => { + southbound::rx::process_addr_del(instance, msg); + } + }, // Ignore other events. _ => {} } diff --git a/holo-rip/src/northbound/configuration.rs b/holo-rip/src/northbound/configuration.rs index 27a8d0f7..1dfbb1f1 100644 --- a/holo-rip/src/northbound/configuration.rs +++ b/holo-rip/src/northbound/configuration.rs @@ -16,7 +16,7 @@ use holo_northbound::configuration::{ }; use holo_northbound::yang::control_plane_protocol::rip; use holo_utils::crypto::CryptoAlgo; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::{IbusMsg, InterfaceMsg}; use holo_utils::ip::IpAddrKind; use holo_utils::yang::DataNodeRefExt; use holo_yang::{ToYang, TryFromYang}; @@ -456,10 +456,12 @@ where } Event::InterfaceQuerySouthbound(ifname) => { if let Instance::Up(instance) = self { - let _ = instance.tx.ibus.send(IbusMsg::InterfaceQuery { - ifname, - af: Some(V::ADDRESS_FAMILY), - }); + let _ = instance.tx.ibus.send(IbusMsg::Interface( + InterfaceMsg::Query { + ifname, + af: Some(V::ADDRESS_FAMILY), + }, + )); } } Event::JoinMulticast(iface_idx) => { diff --git a/holo-rip/src/southbound/tx.rs b/holo-rip/src/southbound/tx.rs index b00dc27a..4f273e81 100644 --- a/holo-rip/src/southbound/tx.rs +++ b/holo-rip/src/southbound/tx.rs @@ -4,7 +4,7 @@ // SPDX-License-Identifier: MIT // -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{IbusMsg, IbusSender, RouteIpMsg}; use holo_utils::southbound::{ Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs, }; @@ -43,7 +43,7 @@ pub(crate) fn route_install( }; // Send message. - let msg = IbusMsg::RouteIpAdd(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); let _ = ibus_tx.send(msg); } @@ -63,6 +63,6 @@ where }; // Send message. - let msg = IbusMsg::RouteIpDel(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); let _ = ibus_tx.send(msg); } diff --git a/holo-routing/src/ibus.rs b/holo-routing/src/ibus.rs index c741a3e1..514fcf93 100644 --- a/holo-routing/src/ibus.rs +++ b/holo-routing/src/ibus.rs @@ -6,7 +6,11 @@ use std::net::IpAddr; -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{ + IbusMsg, IbusSender, InterfaceAddressMsg, InterfaceMsg, KeychainMsg, + NexthopMsg, PolicyMsg, RouteBierMsg, RouteIpMsg, RouteMplsMsg, + RouteRedistributeMsg, +}; use holo_utils::protocol::Protocol; use holo_utils::southbound::{RouteKeyMsg, RouteMsg}; use ipnetwork::IpNetwork; @@ -18,89 +22,153 @@ use crate::{Interface, Master}; pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) { match msg { - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { - master.interfaces.insert( - msg.ifname.clone(), - Interface::new(msg.ifname, msg.ifindex, msg.flags), - ); - } - // Interface delete notification. - IbusMsg::InterfaceDel(ifname) => { - master.interfaces.remove(&ifname); - } - // Interface address addition notification. - IbusMsg::InterfaceAddressAdd(msg) => { - // Add connected route to the RIB. - master.rib.connected_route_add(msg, &master.interfaces); - } - // Interface address delete notification. - IbusMsg::InterfaceAddressDel(msg) => { - // Remove connected route from the RIB. - master.rib.connected_route_del(msg); - } - IbusMsg::KeychainUpd(keychain) => { - // Update the local copy of the keychain. - master - .shared - .keychains - .insert(keychain.name.clone(), keychain.clone()); - } - IbusMsg::KeychainDel(keychain_name) => { - // Remove the local copy of the keychain. - master.shared.keychains.remove(&keychain_name); - } - IbusMsg::NexthopTrack(addr) => { + IbusMsg::Interface(iface_msg) => match iface_msg { + // Interface update notification. + InterfaceMsg::Update(msg) => { + master.interfaces.insert( + msg.ifname.clone(), + Interface::new(msg.ifname, msg.ifindex, msg.flags), + ); + } + + // Interface delete notification. + InterfaceMsg::Delete(ifname) => { + master.interfaces.remove(&ifname); + } + _ => {} + }, + + // Interface Address + IbusMsg::InterfaceAddress(iface_addr_msg) => match iface_addr_msg { + // Interface address addition notification. + InterfaceAddressMsg::Add(msg) => { + // Add connected route to the RIB. + master.rib.connected_route_add(msg, &master.interfaces); + } + + // Interface address delete notification. + InterfaceAddressMsg::Delete(msg) => { + // Remove connected route from the RIB. + master.rib.connected_route_del(msg); + } + }, + + // Keychain + IbusMsg::Keychain(keychain_msg) => match keychain_msg { + KeychainMsg::Update(keychain) => { + // Update the local copy of the keychain. + master + .shared + .keychains + .insert(keychain.name.clone(), keychain.clone()); + } + KeychainMsg::Delete(keychain_name) => { + // Remove the local copy of the keychain. + master.shared.keychains.remove(&keychain_name); + } + }, + + // Nexthop + IbusMsg::Nexthop(nexthop_msg) => match nexthop_msg { // Nexthop tracking registration. - master.rib.nht_add(addr, &master.ibus_tx); - } - IbusMsg::NexthopUntrack(addr) => { + NexthopMsg::Track(addr) => { + master.rib.nht_add(addr, &master.ibus_tx); + } + // Nexthop tracking unregistration. - master.rib.nht_del(addr); - } - IbusMsg::PolicyMatchSetsUpd(match_sets) => { - // Update the local copy of the policy match sets. - master.shared.policy_match_sets = match_sets; - } - IbusMsg::PolicyUpd(policy) => { - // Update the local copy of the policy definition. - master - .shared - .policies - .insert(policy.name.clone(), policy.clone()); - } - IbusMsg::PolicyDel(policy_name) => { - // Remove the local copy of the policy definition. - master.shared.policies.remove(&policy_name); - } - IbusMsg::RouteIpAdd(msg) => { - // Add route to the RIB. - master.rib.ip_route_add(msg); - } - IbusMsg::RouteIpDel(msg) => { - // Remove route from the RIB. - master.rib.ip_route_del(msg); - } - IbusMsg::RouteMplsAdd(msg) => { - // Add MPLS route to the LIB. - master.rib.mpls_route_add(msg); - } - IbusMsg::RouteMplsDel(msg) => { - // Remove MPLS route from the LIB. - master.rib.mpls_route_del(msg); + NexthopMsg::Untrack(addr) => { + master.rib.nht_del(addr); + } + + _ => {} + }, + + // ==== POLICY ==== + IbusMsg::Policy(policy_msg) => { + match policy_msg { + PolicyMsg::MatchSetsUpdate(match_sets) => { + // Update the local copy of the policy match sets. + master.shared.policy_match_sets = match_sets; + } + PolicyMsg::Update(policy) => { + // Update the local copy of the policy definition. + master + .shared + .policies + .insert(policy.name.clone(), policy.clone()); + } + PolicyMsg::Delete(policy_name) => { + // Remove the local copy of the policy definition. + master.shared.policies.remove(&policy_name); + } + } } - IbusMsg::RouteRedistributeDump { protocol, af } => { - // Redistribute all requested routes. - master - .rib - .redistribute_request(protocol, af, &master.ibus_tx); + + // ==== ROUTE IP ==== + IbusMsg::RouteIp(route_ip_msg) => { + match route_ip_msg { + RouteIpMsg::Add(msg) => { + // Add route to the RIB. + master.rib.ip_route_add(msg); + } + RouteIpMsg::Delete(msg) => { + // Remove route from the RIB. + master.rib.ip_route_del(msg); + } + } } - IbusMsg::RouteBierAdd(msg) => { - master.birt.bier_nbr_add(msg); + + // ==== ROUTE MPLS ==== + IbusMsg::RouteMpls(route_mpls_msg) => { + match route_mpls_msg { + RouteMplsMsg::Add(msg) => { + // Add MPLS route to the LIB. + master.rib.mpls_route_add(msg); + } + RouteMplsMsg::Delete(msg) => { + // Remove MPLS route from the LIB. + master.rib.mpls_route_del(msg); + } + } } - IbusMsg::RouteBierDel(msg) => { - master.birt.bier_nbr_del(msg); + + // ==== ROUTE REDISTRIBUTE ==== + IbusMsg::RouteRedistribute(route_redistribute_msg) => { + match route_redistribute_msg { + RouteRedistributeMsg::Dump { protocol, af } => { + // Redistribute all requested routes. + master.rib.redistribute_request( + protocol, + af, + &master.ibus_tx, + ); + } + RouteRedistributeMsg::Add(msg) => { + master.birt.bier_nbr_add(msg); + } + RouteRedistributeMsg::Dump { protocol, af } => { + // Redistribute all requested routes. + master.rib.redistribute_request( + protocol, + af, + &master.ibus_tx, + ); + } + _ => {} + } } + + // ==== ROUTE BIER ==== + IbusMsg::RouteBier(route_bier_msg) => match route_bier_msg { + RouteBierMsg::Add(msg) => { + master.birt.bier_nbr_add(msg); + } + RouteBierMsg::Delete(msg) => { + master.birt.bier_nbr_del(msg); + } + }, + + // ===== BIER PURGE ==== IbusMsg::BierPurge => { master.birt.entries.clear(); } @@ -111,7 +179,7 @@ pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) { // Requests information about all interfaces addresses. pub(crate) fn request_addresses(ibus_tx: &IbusSender) { - send(ibus_tx, IbusMsg::InterfaceDump); + send(ibus_tx, IbusMsg::Interface(InterfaceMsg::Dump)); } // Sends route redistribute update notification. @@ -129,7 +197,7 @@ pub(crate) fn notify_redistribute_add( opaque_attrs: route.opaque_attrs.clone(), nexthops: route.nexthops.clone(), }; - let msg = IbusMsg::RouteRedistributeAdd(msg); + let msg = IbusMsg::RouteRedistribute(RouteRedistributeMsg::Add(msg)); send(ibus_tx, msg); } @@ -140,7 +208,7 @@ pub(crate) fn notify_redistribute_del( protocol: Protocol, ) { let msg = RouteKeyMsg { protocol, prefix }; - let msg = IbusMsg::RouteRedistributeDel(msg); + let msg = IbusMsg::RouteRedistribute(RouteRedistributeMsg::Delete(msg)); send(ibus_tx, msg); } @@ -150,7 +218,7 @@ pub(crate) fn notify_nht_update( addr: IpAddr, metric: Option, ) { - let msg = IbusMsg::NexthopUpd { addr, metric }; + let msg = IbusMsg::Nexthop(NexthopMsg::Update { addr, metric }); send(ibus_tx, msg); } diff --git a/holo-routing/src/northbound/configuration.rs b/holo-routing/src/northbound/configuration.rs index 30928bc4..9fe3eac5 100644 --- a/holo-routing/src/northbound/configuration.rs +++ b/holo-routing/src/northbound/configuration.rs @@ -22,7 +22,9 @@ use holo_utils::bier::{ BierEncapsulation, BierEncapsulationType, BierInBiftId, BierSubDomainCfg, Bsl, SubDomainId, UnderlayProtocolType, }; -use holo_utils::ibus::{BierCfgEvent, IbusMsg, SrCfgEvent}; +use holo_utils::ibus::{ + BierCfgEvent, BierCfgMsg, IbusMsg, RouteIpMsg, SrCfgEvent, SrCfgMsg, +}; use holo_utils::ip::{AddressFamily, IpNetworkKind}; use holo_utils::mpls::LabelRange; use holo_utils::protocol::Protocol; @@ -1031,7 +1033,7 @@ impl Provider for Master { }; // Send message. - let msg = IbusMsg::RouteIpAdd(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); let _ = self.ibus_tx.send(msg); } Event::StaticRouteUninstall(prefix) => { @@ -1042,7 +1044,7 @@ impl Provider for Master { }; // Send message. - let msg = IbusMsg::RouteIpDel(msg); + let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); let _ = self.ibus_tx.send(msg); } Event::SrCfgUpdate => { @@ -1050,40 +1052,40 @@ impl Provider for Master { self.shared.sr_config = Arc::new(self.sr_config.clone()); // Notify protocol instances about the updated SR configuration. - let _ = self - .ibus_tx - .send(IbusMsg::SrCfgUpd(self.shared.sr_config.clone())); + let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Update( + self.shared.sr_config.clone(), + ))); } Event::SrCfgLabelRangeUpdate => { // Notify protocol instances about the updated SRGB/SRLB configuration. - let _ = self - .ibus_tx - .send(IbusMsg::SrCfgEvent(SrCfgEvent::LabelRangeUpdate)); + let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Event( + SrCfgEvent::LabelRangeUpdate, + ))); } Event::SrCfgPrefixSidUpdate(af) => { // Notify protocol instances about the updated Prefix-SID configuration. - let _ = self - .ibus_tx - .send(IbusMsg::SrCfgEvent(SrCfgEvent::PrefixSidUpdate(af))); + let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Event( + SrCfgEvent::PrefixSidUpdate(af), + ))); } Event::BierCfgUpdate => { // Update the shared BIER configuration by creating a new reference-counted copy. self.shared.bier_config = Arc::new(self.bier_config.clone()); // Notify protocol instances about the updated BIER configuration. - let _ = self - .ibus_tx - .send(IbusMsg::BierCfgUpd(self.shared.bier_config.clone())); + let _ = self.ibus_tx.send(IbusMsg::BierCfg( + BierCfgMsg::Update(self.shared.bier_config.clone()), + )); } Event::BierCfgEncapUpdate(_sd_id, af, _bsl, _encap_type) => { - let _ = self - .ibus_tx - .send(IbusMsg::BierCfgEvent(BierCfgEvent::EncapUpdate(af))); + let _ = self.ibus_tx.send(IbusMsg::BierCfg(BierCfgMsg::Event( + BierCfgEvent::EncapUpdate(af), + ))); } Event::BierCfgSubDomainUpdate(af) => { - let _ = self.ibus_tx.send(IbusMsg::BierCfgEvent( + let _ = self.ibus_tx.send(IbusMsg::BierCfg(BierCfgMsg::Event( BierCfgEvent::SubDomainUpdate(af), - )); + ))); } } } diff --git a/holo-system/src/ibus.rs b/holo-system/src/ibus.rs index 622b3c05..89822a84 100644 --- a/holo-system/src/ibus.rs +++ b/holo-system/src/ibus.rs @@ -4,22 +4,23 @@ // SPDX-License-Identifier: MIT // -use holo_utils::ibus::{IbusMsg, IbusSender}; +use holo_utils::ibus::{HostnameMsg, IbusMsg, IbusSender}; use crate::Master; // ===== global functions ===== pub(crate) fn process_msg(master: &mut Master, msg: IbusMsg) { - match msg { - IbusMsg::HostnameQuery => { - notify_hostname_update( - &master.ibus_tx, - master.config.hostname.clone(), - ); + if let IbusMsg::Hostname(hostname_msg) = msg { + match hostname_msg { + HostnameMsg::Query => { + notify_hostname_update( + &master.ibus_tx, + master.config.hostname.clone(), + ); + } + _ => {} } - // Ignore other events. - _ => {} } } @@ -27,7 +28,7 @@ pub(crate) fn notify_hostname_update( ibus_tx: &IbusSender, hostname: Option, ) { - let msg = IbusMsg::HostnameUpdate(hostname); + let msg = IbusMsg::Hostname(HostnameMsg::Update(hostname)); notify(ibus_tx, msg); } diff --git a/holo-utils/src/ibus.rs b/holo-utils/src/ibus.rs index 1e6aec6b..aa7af8f8 100644 --- a/holo-utils/src/ibus.rs +++ b/holo-utils/src/ibus.rs @@ -29,102 +29,189 @@ pub type IbusSender = Sender; // Ibus message for communication among the different Holo components. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum IbusMsg { + // BFD session + BfdSession(BfdSessionMsg), + // Hostname + Hostname(HostnameMsg), + // Interface + Interface(InterfaceMsg), + // Interface Address + InterfaceAddress(InterfaceAddressMsg), + // Keychain + Keychain(KeychainMsg), + // Nexthop + Nexthop(NexthopMsg), + // policy + Policy(PolicyMsg), + // Router ID + RouterId(RouterIdMsg), + // Route Ip + RouteIp(RouteIpMsg), + // Route Mpls + RouteMpls(RouteMplsMsg), + // Route redistribute + RouteRedistribute(RouteRedistributeMsg), + // SrCfg + SrCfg(SrCfgMsg), + // BIER + BierCfg(BierCfgMsg), + // ROUTE BIER + RouteBier(RouteBierMsg), + // Purge the BIRT. + /* TODO: Add Protocol argument to BierPurge to specify which BIRT has to be purged. + * E.g., One could ask to purge the BIRT populated by a specific instance + * of OSPFv3 but not those populated by IS-IS. + * See https://github.com/holo-routing/holo/pull/16#discussion_r1729456621. + */ + BierPurge, +} + +// Bfd session ibus messages +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum BfdSessionMsg { // BFD peer registration. - BfdSessionReg { + Registration { sess_key: bfd::SessionKey, client_id: bfd::ClientId, client_config: Option, }, + // BFD peer unregistration. - BfdSessionUnreg { + Unregistration { sess_key: bfd::SessionKey, client_id: bfd::ClientId, }, + // BFD peer state update. - BfdStateUpd { + Update { sess_key: bfd::SessionKey, state: bfd::State, }, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum HostnameMsg { // Query the current hostname. - HostnameQuery, + Query, // Hostname update notification. - HostnameUpdate(Option), + Update(Option), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum InterfaceMsg { // Request to dump information about all interfaces. - InterfaceDump, + Dump, // Query information about a specific interface. - InterfaceQuery { + Query { ifname: String, af: Option, }, // Interface update notification. - InterfaceUpd(InterfaceUpdateMsg), + Update(InterfaceUpdateMsg), // Interface delete notification. - InterfaceDel(String), + Delete(String), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum InterfaceAddressMsg { // Interface address addition notification. - InterfaceAddressAdd(AddressMsg), + Add(AddressMsg), + // Interface address delete notification. - InterfaceAddressDel(AddressMsg), + Delete(AddressMsg), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum KeychainMsg { // Keychain update notification. - KeychainUpd(Arc), + Update(Arc), + // Keychain delete notification. - KeychainDel(String), - // Nexthop tracking registration. - NexthopTrack(IpAddr), - // Nexthop tracking unregistration. - NexthopUntrack(IpAddr), - // Nexthop tracking update. - NexthopUpd { - addr: IpAddr, - metric: Option, - }, + Delete(String), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum NexthopMsg { + // Nexthop tracking registration + Track(IpAddr), + + // Nexthop tracking unregistration + Untrack(IpAddr), + + // Nexthop tracking update + Update { addr: IpAddr, metric: Option }, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum PolicyMsg { // Policy match sets update notification. - PolicyMatchSetsUpd(Arc), + MatchSetsUpdate(Arc), // Policy definition update notification. - PolicyUpd(Arc), + Update(Arc), // Policy definition delete notification. - PolicyDel(String), + Delete(String), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum RouterIdMsg { // Query the current Router ID. - RouterIdQuery, + Query, // Router ID update notification. - RouterIdUpdate(Option), - // Request to install IP route in the RIB. - RouteIpAdd(RouteMsg), - // Request to uninstall IP route from the RIB. - RouteIpDel(RouteKeyMsg), + Update(Option), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum RouteIpMsg { + Add(RouteMsg), + Delete(RouteKeyMsg), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum RouteMplsMsg { // Request to install MPLS route in the LIB. - RouteMplsAdd(LabelInstallMsg), + Add(LabelInstallMsg), // Request to uninstall MPLS route from the LIB. - RouteMplsDel(LabelUninstallMsg), + Delete(LabelUninstallMsg), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum RouteRedistributeMsg { // Request to redistribute routes. - RouteRedistributeDump { + Dump { protocol: Protocol, af: Option, }, // Route redistribute update notification. - RouteRedistributeAdd(RouteMsg), + Add(RouteMsg), // Route redistribute delete notification. - RouteRedistributeDel(RouteKeyMsg), + Delete(RouteKeyMsg), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum SrCfgMsg { // Segment Routing configuration update. - SrCfgUpd(Arc), + Update(Arc), // Segment Routing configuration event. - SrCfgEvent(SrCfgEvent), + Event(SrCfgEvent), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum BierCfgMsg { // BIER configuration update. - BierCfgUpd(Arc), + Update(Arc), // BIER configuration event. - BierCfgEvent(BierCfgEvent), + Event(BierCfgEvent), +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub enum RouteBierMsg { // Request to install an entry in the BIRT. - RouteBierAdd(BierNbrInstallMsg), + Add(BierNbrInstallMsg), // Request to uninstall an entry in the BIRT. - RouteBierDel(BierNbrUninstallMsg), - // Purge the BIRT. - /* TODO: Add Protocol argument to BierPurge to specify which BIRT has to be purged. - * E.g., One could ask to purge the BIRT populated by a specific instance - * of OSPFv3 but not those populated by IS-IS. - * See https://github.com/holo-routing/holo/pull/16#discussion_r1729456621. - */ - BierPurge, + Delete(BierNbrUninstallMsg), } + // Type of Segment Routing configuration change. #[derive(Clone, Debug, Deserialize, Serialize)] pub enum SrCfgEvent {