From db0417c8646f009113a04374ad74af7a9bed5a4c Mon Sep 17 00:00:00 2001 From: Paul Wekesa Date: Mon, 14 Oct 2024 16:09:35 +0300 Subject: [PATCH 1/2] ibus: restructure IbusMsg IbusMsg had too many items (which can only keep growing). This commit restructures the actions and categorize each item e.g Interface/RouteId and actions like add, delete, update etc... Signed-off-by: Paul Wekesa --- holo-bfd/src/master.rs | 49 ++-- holo-bfd/src/session.rs | 6 +- holo-bgp/src/instance.rs | 66 +++--- holo-bgp/src/northbound/configuration.rs | 12 +- holo-bgp/src/southbound/tx.rs | 14 +- holo-interface/src/ibus.rs | 96 ++++---- holo-isis/src/instance.rs | 37 ++-- 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 | 59 +++-- holo-ldp/src/northbound/configuration.rs | 12 +- holo-ldp/src/southbound/tx.rs | 8 +- holo-ospf/src/instance.rs | 122 ++++++---- holo-ospf/src/neighbor.rs | 22 +- holo-ospf/src/northbound/configuration.rs | 12 +- holo-ospf/src/southbound/tx.rs | 24 +- holo-policy/src/northbound/configuration.rs | 9 +- holo-rip/src/instance.rs | 25 ++- holo-rip/src/northbound/configuration.rs | 12 +- holo-rip/src/southbound/tx.rs | 6 +- holo-routing/src/ibus.rs | 209 +++++++++++------- holo-routing/src/northbound/configuration.rs | 42 ++-- holo-system/src/ibus.rs | 15 +- holo-utils/src/ibus.rs | 184 +++++++++++---- 25 files changed, 652 insertions(+), 405 deletions(-) diff --git a/holo-bfd/src/master.rs b/holo-bfd/src/master.rs index 50d7137e..5e82b92e 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,32 @@ 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); + // 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(InterfaceMsg::Update(msg)) => { + southbound::process_iface_update(master, msg) } - // Ignore other events. + _ => {} } 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..9bc72678 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,50 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - IbusMsg::NexthopUpd { addr, metric } => { + // Nexthop + IbusMsg::Nexthop(NexthopMsg::Update { addr, metric }) => { // Nexthop tracking update notification. southbound::rx::process_nht_update(instance, addr, metric); } - IbusMsg::RouterIdUpdate(router_id) => { + + // Router ID + IbusMsg::RouterId(RouterIdMsg::Update(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); - } - IbusMsg::RouteRedistributeDel(msg) => { - // Route redistribute delete notification. - southbound::rx::process_route_del(instance, msg); + + // 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..9cc39e8e 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,16 @@ 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::Nexthop(NexthopMsg::Untrack(addr)); let _ = ibus_tx.send(msg); } diff --git a/holo-interface/src/ibus.rs b/holo-interface/src/ibus.rs index 45d9024f..a2683baf 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,40 +20,46 @@ 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 => { + _ => {} + }, + + // RouterId + IbusMsg::RouterId(RouterIdMsg::Query) => { notify_router_id_update( &master.ibus_tx, master.interfaces.router_id(), @@ -66,23 +74,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(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 +102,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); } @@ -106,11 +117,12 @@ pub(crate) fn notify_addr_del( addr: IpNetwork, flags: AddressFlags, ) { - let msg = IbusMsg::InterfaceAddressDel(AddressMsg { - ifname, - addr, - flags, - }); + let msg = + IbusMsg::InterfaceAddress(InterfaceAddressMsg::Delete(AddressMsg { + ifname, + addr, + flags, + })); notify(ibus_tx, msg); } diff --git a/holo-isis/src/instance.rs b/holo-isis/src/instance.rs index e8f34912..7aa39851 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,29 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - // Router ID update notification. - IbusMsg::RouterIdUpdate(router_id) => { + // ==== ROUTER ID ==== + IbusMsg::RouterId(RouterIdMsg::Update(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); + + // ==== INTERFACE ==== + IbusMsg::Interface(InterfaceMsg::Update(msg)) => { + // Interface update notification. + let _ = 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..be9d7092 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,45 @@ async fn process_ibus_msg( msg: IbusMsg, ) -> Result<(), Error> { match msg { - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { + // ==== INTERFACE ==== + IbusMsg::Interface(InterfaceMsg::Update(msg)) => { + // Interface update notification. 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) => { + + // ==== 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(RouterIdMsg::Update(router_id)) => { + // Router ID update notification. southbound::rx::process_router_id_update(instance, router_id).await; } - // Route redistribute update notification. - IbusMsg::RouteRedistributeAdd(msg) => { - southbound::rx::process_route_add(instance, msg); - } - // 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..fff7cd0a 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::{ + BfdSessionMsg, 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,87 @@ where V: Version, { match msg { - // BFD peer state update event. - IbusMsg::BfdStateUpd { sess_key, state } => { + // BFD session Message + IbusMsg::BfdSession(BfdSessionMsg::Update { sess_key, state }) => { events::process_bfd_state_update(instance, sess_key, state)? } - // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { + + // Interface + IbusMsg::Interface(InterfaceMsg::Update(msg)) => { + // Interface update notification. 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); - // Update all interfaces using this keychain. - events::process_keychain_update(instance, &keychain_name)? - } - // Router ID update notification. - IbusMsg::RouterIdUpdate(router_id) => { + // 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)? + } + + // 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(RouterIdMsg::Update(router_id)) => { + // Router ID update notification. 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(); - } - // 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(sr_config) => { + // BIER configuration update. + instance.shared.sr_config = sr_config; + } + + // 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..f24f1cf9 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,12 @@ where } Event::InterfaceQuerySouthbound(ifname, af) => { if self.is_active() { - let _ = self.tx.ibus.send(IbusMsg::InterfaceQuery { - ifname, - af: Some(af), - }); + let _ = self.tx.ibus.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..81336110 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,22 @@ where { match msg { // Interface update notification. - IbusMsg::InterfaceUpd(msg) => { + IbusMsg::Interface(InterfaceMsg::Update(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); - } + + // 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..5c3e826f 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,138 @@ 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); + 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::RouteMplsAdd(msg) => { - // Add MPLS route to the LIB. - master.rib.mpls_route_add(msg); + + // ==== 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::RouteMplsDel(msg) => { - // Remove MPLS route from the LIB. - master.rib.mpls_route_del(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::RouteRedistributeDump { protocol, af } => { + + // ==== ROUTE REDISTRIBUTE ==== + IbusMsg::RouteRedistribute(RouteRedistributeMsg::Dump { + protocol, + af, + }) => { // Redistribute all requested routes. master .rib .redistribute_request(protocol, af, &master.ibus_tx); } - IbusMsg::RouteBierAdd(msg) => { - master.birt.bier_nbr_add(msg); - } - IbusMsg::RouteBierDel(msg) => { - master.birt.bier_nbr_del(msg); - } + + // ==== 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 +164,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 +182,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 +193,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 +203,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..c8eb0939 100644 --- a/holo-system/src/ibus.rs +++ b/holo-system/src/ibus.rs @@ -4,22 +4,15 @@ // 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(), - ); - } - // Ignore other events. - _ => {} + if let IbusMsg::Hostname(HostnameMsg::Query) = msg { + notify_hostname_update(&master.ibus_tx, master.config.hostname.clone()); } } @@ -27,7 +20,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..e2e1f646 100644 --- a/holo-utils/src/ibus.rs +++ b/holo-utils/src/ibus.rs @@ -29,100 +29,186 @@ 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. From 625e8397c9fb656960bd1cdf20605f4f20c03deb Mon Sep 17 00:00:00 2001 From: Paul Wekesa Date: Thu, 7 Nov 2024 19:53:44 +0300 Subject: [PATCH 2/2] ibus: add derive_more crate Add derive_more crate. Simplifies the calling of the IbusMsg messages. Signed-off-by: Paul Wekesa --- Cargo.toml | 1 + holo-bfd/src/master.rs | 2 +- holo-bfd/src/session.rs | 8 +-- holo-bgp/src/northbound/configuration.rs | 9 +-- holo-bgp/src/southbound/tx.rs | 28 ++++---- holo-interface/src/ibus.rs | 29 ++++---- holo-isis/src/interface.rs | 7 +- holo-isis/src/southbound/tx.rs | 4 +- holo-keychain/src/northbound/configuration.rs | 10 +-- holo-ldp/src/northbound/configuration.rs | 13 ++-- holo-ldp/src/southbound/tx.rs | 18 +++-- holo-ospf/src/neighbor.rs | 28 ++++---- holo-ospf/src/northbound/configuration.rs | 11 ++- holo-ospf/src/southbound/tx.rs | 67 ++++++++----------- holo-policy/src/northbound/configuration.rs | 15 ++--- holo-rip/src/northbound/configuration.rs | 13 ++-- holo-rip/src/southbound/tx.rs | 16 ++--- holo-routing/src/ibus.rs | 17 +++-- holo-routing/src/northbound/configuration.rs | 52 +++++++------- holo-system/src/ibus.rs | 4 +- holo-utils/Cargo.toml | 1 + holo-utils/src/ibus.rs | 4 +- 22 files changed, 166 insertions(+), 191 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3c4b752..8f5ca3a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ chrono = { version = "0.4", features = ["serde"] } convert_case = "0.6" criterion = "0.4" crossbeam-channel = "0.5" +derive_more = { version="1.0.0", features = ["from"] } derive-new = "0.5" enum-as-inner = "0.6" fletcher = "1.0" diff --git a/holo-bfd/src/master.rs b/holo-bfd/src/master.rs index 5e82b92e..a0794800 100644 --- a/holo-bfd/src/master.rs +++ b/holo-bfd/src/master.rs @@ -144,7 +144,7 @@ impl ProtocolInstance for Master { async fn init(&mut self) { // Request information about all interfaces. - let _ = self.tx.ibus.send(IbusMsg::Interface(InterfaceMsg::Dump)); + let _ = self.tx.ibus.send(InterfaceMsg::Dump.into()); } async fn process_ibus_msg(&mut self, msg: IbusMsg) { diff --git a/holo-bfd/src/session.rs b/holo-bfd/src/session.rs index bf4942a7..c835258d 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::{BfdSessionMsg, IbusMsg}; +use holo_utils::ibus::BfdSessionMsg; use holo_utils::ip::{IpAddrExt, IpAddrKind}; use holo_utils::socket::{UdpSocket, TTL_MAX}; use holo_utils::task::{IntervalTask, TimeoutTask}; @@ -141,11 +141,11 @@ 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::BfdSession(BfdSessionMsg::Update { + let msg = BfdSessionMsg::Update { sess_key: self.key.clone(), state, - }); - let _ = tx.ibus.send(msg); + }; + let _ = tx.ibus.send(msg.into()); } // Send YANG notification. diff --git a/holo-bgp/src/northbound/configuration.rs b/holo-bgp/src/northbound/configuration.rs index ed5246f2..61c8e256 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, RouteRedistributeMsg}; +use holo_utils::ibus::RouteRedistributeMsg; use holo_utils::ip::{AddressFamily, IpAddrKind}; use holo_utils::policy::{ApplyPolicyCfg, DefaultPolicyType}; use holo_utils::protocol::Protocol; @@ -1363,12 +1363,13 @@ impl Provider for Instance { } } Event::RedistributeRequest(protocol, af) => { - let _ = self.tx.ibus.send(IbusMsg::RouteRedistribute( + let _ = self.tx.ibus.send( RouteRedistributeMsg::Dump { protocol, af: Some(af), - }, - )); + } + .into(), + ); } 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 9cc39e8e..f1c9f05b 100644 --- a/holo-bgp/src/southbound/tx.rs +++ b/holo-bgp/src/southbound/tx.rs @@ -7,9 +7,7 @@ use std::collections::BTreeSet; use std::net::IpAddr; -use holo_utils::ibus::{ - IbusMsg, IbusSender, NexthopMsg, RouteIpMsg, RouterIdMsg, -}; +use holo_utils::ibus::{IbusSender, NexthopMsg, RouteIpMsg, RouterIdMsg}; use holo_utils::protocol::Protocol; use holo_utils::southbound::{ Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs, @@ -21,7 +19,7 @@ use crate::rib::LocalRoute; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); + let _ = ibus_tx.send(RouterIdMsg::Query.into()); } pub(crate) fn route_install( @@ -43,7 +41,7 @@ pub(crate) fn route_install( .collect::>(); // Install route. - let msg = RouteMsg { + let msg = RouteIpMsg::Add(RouteMsg { protocol: Protocol::BGP, prefix: prefix.into(), distance: distance.into(), @@ -51,9 +49,8 @@ pub(crate) fn route_install( tag: None, opaque_attrs: RouteOpaqueAttrs::None, nexthops: nexthops.clone(), - }; - let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } pub(crate) fn route_uninstall( @@ -61,20 +58,19 @@ pub(crate) fn route_uninstall( prefix: impl Into, ) { // Uninstall route. - let msg = RouteKeyMsg { + let msg = RouteIpMsg::Delete(RouteKeyMsg { protocol: Protocol::BGP, prefix: prefix.into(), - }; - let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } pub(crate) fn nexthop_track(ibus_tx: &IbusSender, addr: IpAddr) { - let msg = IbusMsg::Nexthop(NexthopMsg::Track(addr)); - let _ = ibus_tx.send(msg); + let msg = NexthopMsg::Track(addr); + let _ = ibus_tx.send(msg.into()); } pub(crate) fn nexthop_untrack(ibus_tx: &IbusSender, addr: IpAddr) { - let msg = IbusMsg::Nexthop(NexthopMsg::Untrack(addr)); - let _ = ibus_tx.send(msg); + let msg = NexthopMsg::Untrack(addr); + let _ = ibus_tx.send(msg.into()); } diff --git a/holo-interface/src/ibus.rs b/holo-interface/src/ibus.rs index a2683baf..784ddb1d 100644 --- a/holo-interface/src/ibus.rs +++ b/holo-interface/src/ibus.rs @@ -74,8 +74,8 @@ pub(crate) fn notify_router_id_update( ibus_tx: &IbusSender, router_id: Option, ) { - let msg = IbusMsg::RouterId(RouterIdMsg::Update(router_id)); - notify(ibus_tx, msg); + let msg = RouterIdMsg::Update(router_id); + notify(ibus_tx, msg.into()); } pub(crate) fn notify_interface_update(ibus_tx: &IbusSender, iface: &Interface) { @@ -86,14 +86,14 @@ pub(crate) fn notify_interface_update(ibus_tx: &IbusSender, iface: &Interface) { flags: iface.flags, mac_address: iface.mac_address, }; - let msg = IbusMsg::Interface(InterfaceMsg::Update(update_msg)); + let msg = InterfaceMsg::Update(update_msg); - notify(ibus_tx, msg); + notify(ibus_tx, msg.into()); } pub(crate) fn notify_interface_del(ibus_tx: &IbusSender, ifname: String) { - let msg = IbusMsg::Interface(InterfaceMsg::Delete(ifname)); - notify(ibus_tx, msg); + let msg = InterfaceMsg::Delete(ifname); + notify(ibus_tx, msg.into()); } pub(crate) fn notify_addr_add( @@ -107,8 +107,8 @@ pub(crate) fn notify_addr_add( addr, flags, }; - let msg = IbusMsg::InterfaceAddress(InterfaceAddressMsg::Add(addr_msg)); - notify(ibus_tx, msg); + let msg = InterfaceAddressMsg::Add(addr_msg); + notify(ibus_tx, msg.into()); } pub(crate) fn notify_addr_del( @@ -117,13 +117,12 @@ pub(crate) fn notify_addr_del( addr: IpNetwork, flags: AddressFlags, ) { - let msg = - IbusMsg::InterfaceAddress(InterfaceAddressMsg::Delete(AddressMsg { - ifname, - addr, - flags, - })); - notify(ibus_tx, msg); + let msg = InterfaceAddressMsg::Delete(AddressMsg { + ifname, + addr, + flags, + }); + notify(ibus_tx, msg.into()); } // ===== helper functions ===== diff --git a/holo-isis/src/interface.rs b/holo-isis/src/interface.rs index e8034c2c..44270e21 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, InterfaceMsg}; +use holo_utils::ibus::{IbusSender, InterfaceMsg}; use holo_utils::ip::AddressFamily; use holo_utils::socket::{AsyncFd, Socket, SocketExt}; use holo_utils::southbound::InterfaceFlags; @@ -643,10 +643,11 @@ 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::Interface(InterfaceMsg::Query { + let msg = InterfaceMsg::Query { ifname: self.name.clone(), af: None, - })); + }; + let _ = ibus_tx.send(msg.into()); } } diff --git a/holo-isis/src/southbound/tx.rs b/holo-isis/src/southbound/tx.rs index fe328d33..dff62b1d 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, RouterIdMsg}; +use holo_utils::ibus::{IbusSender, RouterIdMsg}; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); + let _ = ibus_tx.send(RouterIdMsg::Query.into()); } diff --git a/holo-keychain/src/northbound/configuration.rs b/holo-keychain/src/northbound/configuration.rs index 753497c9..ba45625c 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, KeychainMsg}; +use holo_utils::ibus::KeychainMsg; use holo_utils::keychain::{Key, Keychain, KeychainKey}; use holo_utils::yang::DataNodeRefExt; use holo_yang::TryFromYang; @@ -443,13 +443,13 @@ impl Provider for Master { let keychain = Arc::new(keychain.clone()); // Notify protocols that the keychain has been updated. - let msg = IbusMsg::Keychain(KeychainMsg::Update(keychain)); - let _ = self.ibus_tx.send(msg); + let msg = KeychainMsg::Update(keychain); + let _ = self.ibus_tx.send(msg.into()); } Event::KeychainDelete(name) => { // Notify protocols that the keychain has been deleted. - let msg = IbusMsg::Keychain(KeychainMsg::Delete(name)); - let _ = self.ibus_tx.send(msg); + let msg = KeychainMsg::Delete(name); + let _ = self.ibus_tx.send(msg.into()); } } } diff --git a/holo-ldp/src/northbound/configuration.rs b/holo-ldp/src/northbound/configuration.rs index 40236be8..a040ed1e 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, InterfaceMsg}; +use holo_utils::ibus::InterfaceMsg; use holo_utils::ip::AddressFamily; use holo_utils::yang::DataNodeRefExt; @@ -471,12 +471,11 @@ impl Provider for Instance { } Event::InterfaceQuerySouthbound(ifname) => { if let Some((instance, _, _)) = self.as_up() { - let _ = instance.tx.ibus.send(IbusMsg::Interface( - InterfaceMsg::Query { - ifname, - af: Some(AddressFamily::Ipv4), - }, - )); + let msg = InterfaceMsg::Query { + ifname, + af: Some(AddressFamily::Ipv4), + }; + let _ = instance.tx.ibus.send(msg.into()); } } Event::TargetedNbrUpdate(tnbr_idx) => { diff --git a/holo-ldp/src/southbound/tx.rs b/holo-ldp/src/southbound/tx.rs index 7632ca7f..cacb0379 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, RouteMplsMsg, RouterIdMsg}; +use holo_utils::ibus::{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::RouterId(RouterIdMsg::Query)); + let _ = ibus_tx.send(RouterIdMsg::Query.into()); } pub(crate) fn label_install( @@ -35,7 +35,7 @@ pub(crate) fn label_install( let protocol = fec.protocol.unwrap(); // Fill-in message. - let msg = LabelInstallMsg { + let msg = RouteMplsMsg::Add(LabelInstallMsg { protocol: Protocol::LDP, label: local_label, nexthops: [southbound::Nexthop::Address { @@ -46,11 +46,10 @@ pub(crate) fn label_install( .into(), route: Some((protocol, *fec.prefix)), replace: false, - }; + }); // Send message. - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); - let _ = ibus_tx.send(msg); + let _ = ibus_tx.send(msg.into()); } pub(crate) fn label_uninstall( @@ -72,7 +71,7 @@ pub(crate) fn label_uninstall( let protocol = fec.protocol.unwrap(); // Fill-in message. - let msg = LabelUninstallMsg { + let msg = RouteMplsMsg::Delete(LabelUninstallMsg { protocol: Protocol::LDP, label: local_label, nexthops: [southbound::Nexthop::Address { @@ -82,9 +81,8 @@ pub(crate) fn label_uninstall( }] .into(), route: Some((protocol, *fec.prefix)), - }; + }); // Send message. - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + let _ = ibus_tx.send(msg.into()); } diff --git a/holo-ospf/src/neighbor.rs b/holo-ospf/src/neighbor.rs index cf34b842..08729696 100644 --- a/holo-ospf/src/neighbor.rs +++ b/holo-ospf/src/neighbor.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use chrono::{DateTime, Utc}; use holo_utils::bfd; -use holo_utils::ibus::IbusMsg; +use holo_utils::ibus::BfdSessionMsg; use holo_utils::task::{IntervalTask, TimeoutTask}; use nsm::{Event, State}; use rand::RngCore; @@ -553,14 +553,12 @@ where ) { Debug::::NeighborBfdReg(self.router_id).log(); - 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); + let msg = 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.into()); } pub(crate) fn bfd_unregister( @@ -570,13 +568,11 @@ where ) { Debug::::NeighborBfdUnreg(self.router_id).log(); - 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); + let msg = BfdSessionMsg::Unregistration { + sess_key: self.bfd_session_key(iface), + client_id: self.bfd_client_id(instance), + }; + let _ = instance.tx.ibus.send(msg.into()); } fn bfd_session_key(&self, iface: &Interface) -> bfd::SessionKey { diff --git a/holo-ospf/src/northbound/configuration.rs b/holo-ospf/src/northbound/configuration.rs index f24f1cf9..94287939 100644 --- a/holo-ospf/src/northbound/configuration.rs +++ b/holo-ospf/src/northbound/configuration.rs @@ -1448,12 +1448,11 @@ where } Event::InterfaceQuerySouthbound(ifname, af) => { if self.is_active() { - let _ = self.tx.ibus.send(IbusMsg::Interface( - InterfaceMsg::Query { - ifname, - af: Some(af), - }, - )); + let msg = InterfaceMsg::Query { + ifname, + af: Some(af), + }; + let _ = self.tx.ibus.send(msg.into()); } } Event::StubRouterChange => { diff --git a/holo-ospf/src/southbound/tx.rs b/holo-ospf/src/southbound/tx.rs index b106abd7..b16ff5f3 100644 --- a/holo-ospf/src/southbound/tx.rs +++ b/holo-ospf/src/southbound/tx.rs @@ -8,7 +8,7 @@ use std::collections::BTreeSet; use std::net::IpAddr; use holo_utils::ibus::{ - IbusMsg, IbusSender, RouteBierMsg, RouteIpMsg, RouteMplsMsg, RouterIdMsg, + IbusSender, RouteBierMsg, RouteIpMsg, RouteMplsMsg, RouterIdMsg, }; use holo_utils::mpls::Label; use holo_utils::southbound::{ @@ -24,7 +24,7 @@ use crate::version::Version; // ===== global functions ===== pub(crate) fn router_id_query(ibus_tx: &IbusSender) { - let _ = ibus_tx.send(IbusMsg::RouterId(RouterIdMsg::Query)); + let _ = ibus_tx.send(RouterIdMsg::Query.into()); } pub(crate) fn route_install( @@ -63,7 +63,7 @@ pub(crate) fn route_install( .collect::>(); // Install route. - let msg = RouteMsg { + let msg = RouteIpMsg::Add(RouteMsg { protocol: V::PROTOCOL, prefix: (*destination).into(), distance: distance.into(), @@ -73,46 +73,42 @@ pub(crate) fn route_install( route_type: route.path_type, }, nexthops: nexthops.clone(), - }; - let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); // Unnstall previous SR Prefix-SID input label if it has changed. if old_sr_label != route.sr_label { if let Some(old_sr_label) = old_sr_label { - let msg = LabelUninstallMsg { + let msg = RouteMplsMsg::Delete(LabelUninstallMsg { protocol: V::PROTOCOL, label: old_sr_label, nexthops: BTreeSet::new(), route: None, - }; - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } } // Install SR Prefix-SID input label. if let Some(sr_label) = &route.sr_label { - let msg = LabelInstallMsg { + let msg = RouteMplsMsg::Add(LabelInstallMsg { protocol: V::PROTOCOL, label: *sr_label, nexthops: nexthops.clone(), route: None, replace: true, - }; - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } // Install BIER neighbor entry if let Some(bier_info) = &route.bier_info { - let msg = BierNbrInstallMsg { + let msg = RouteBierMsg::Add(BierNbrInstallMsg { bier_info: bier_info.clone(), nexthops, prefix: (*destination).into(), - }; - let msg = IbusMsg::RouteBier(holo_utils::ibus::RouteBierMsg::Add(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } } @@ -124,35 +120,32 @@ pub(crate) fn route_uninstall( V: Version, { // Uninstall route. - let msg = RouteKeyMsg { + let msg = RouteIpMsg::Delete(RouteKeyMsg { protocol: V::PROTOCOL, prefix: (*destination).into(), - }; - let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); // Uninstall SR Prefix-SID input label. if let Some(sr_label) = &route.sr_label { - let msg = LabelUninstallMsg { + let msg = RouteMplsMsg::Delete(LabelUninstallMsg { protocol: V::PROTOCOL, label: *sr_label, nexthops: BTreeSet::new(), route: None, - }; - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } // Uninstall BIER neighbor entry if let Some(bier_info) = &route.bier_info { for bsl in &bier_info.bfr_bss { - let msg = BierNbrUninstallMsg { + let msg = RouteBierMsg::Delete(BierNbrUninstallMsg { sd_id: bier_info.sd_id, bfr_id: bier_info.bfr_id, bsl: *bsl, - }; - let msg = IbusMsg::RouteBier(RouteBierMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } } } @@ -165,7 +158,7 @@ pub(crate) fn adj_sid_install( ) where V: Version, { - let msg = LabelInstallMsg { + let msg = RouteMplsMsg::Add(LabelInstallMsg { protocol: V::PROTOCOL, label, nexthops: [Nexthop::Address { @@ -176,21 +169,19 @@ pub(crate) fn adj_sid_install( .into(), route: None, replace: false, - }; - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Add(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } pub(crate) fn adj_sid_uninstall(ibus_tx: &IbusSender, label: Label) where V: Version, { - let msg = LabelUninstallMsg { + let msg = RouteMplsMsg::Delete(LabelUninstallMsg { protocol: V::PROTOCOL, label, nexthops: BTreeSet::new(), route: None, - }; - let msg = IbusMsg::RouteMpls(RouteMplsMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + }); + let _ = ibus_tx.send(msg.into()); } diff --git a/holo-policy/src/northbound/configuration.rs b/holo-policy/src/northbound/configuration.rs index 689bcca4..5063547b 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, PolicyMsg}; +use holo_utils::ibus::PolicyMsg; use holo_utils::ip::AddressFamily; use holo_utils::policy::{ IpPrefixRange, MatchSetRestrictedType, MatchSetType, MetricType, @@ -1109,9 +1109,8 @@ impl Provider for Master { // Notify protocols that the policy match sets have been // updated. - let msg = - IbusMsg::Policy(PolicyMsg::MatchSetsUpdate(match_sets)); - let _ = self.ibus_tx.send(msg); + let msg = PolicyMsg::MatchSetsUpdate(match_sets); + let _ = self.ibus_tx.send(msg.into()); } Event::PolicyChange(name) => { let policy = self.policies.get_mut(&name).unwrap(); @@ -1121,13 +1120,13 @@ impl Provider for Master { let policy = Arc::new(policy.clone()); // Notify protocols that the policy has been updated. - let msg = IbusMsg::Policy(PolicyMsg::Update(policy)); - let _ = self.ibus_tx.send(msg); + let msg = PolicyMsg::Update(policy); + let _ = self.ibus_tx.send(msg.into()); } Event::PolicyDelete(name) => { // Notify protocols that the policy definition has been deleted. - let msg = IbusMsg::Policy(PolicyMsg::Delete(name)); - let _ = self.ibus_tx.send(msg); + let msg = PolicyMsg::Delete(name); + let _ = self.ibus_tx.send(msg.into()); } } } diff --git a/holo-rip/src/northbound/configuration.rs b/holo-rip/src/northbound/configuration.rs index 1dfbb1f1..ddfa26be 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, InterfaceMsg}; +use holo_utils::ibus::InterfaceMsg; use holo_utils::ip::IpAddrKind; use holo_utils::yang::DataNodeRefExt; use holo_yang::{ToYang, TryFromYang}; @@ -456,12 +456,11 @@ where } Event::InterfaceQuerySouthbound(ifname) => { if let Instance::Up(instance) = self { - let _ = instance.tx.ibus.send(IbusMsg::Interface( - InterfaceMsg::Query { - ifname, - af: Some(V::ADDRESS_FAMILY), - }, - )); + let msg = InterfaceMsg::Query { + ifname, + af: Some(V::ADDRESS_FAMILY), + }; + let _ = instance.tx.ibus.send(msg.into()); } } Event::JoinMulticast(iface_idx) => { diff --git a/holo-rip/src/southbound/tx.rs b/holo-rip/src/southbound/tx.rs index 4f273e81..7054c444 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, RouteIpMsg}; +use holo_utils::ibus::{IbusSender, RouteIpMsg}; use holo_utils::southbound::{ Nexthop, RouteKeyMsg, RouteMsg, RouteOpaqueAttrs, }; @@ -27,7 +27,7 @@ pub(crate) fn route_install( } // Fill-in message. - let msg = RouteMsg { + let msg = RouteIpMsg::Add(RouteMsg { protocol: V::PROTOCOL, prefix: route.prefix.into(), distance: distance.into(), @@ -40,11 +40,10 @@ pub(crate) fn route_install( labels: Vec::new(), }] .into(), - }; + }); // Send message. - let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); - let _ = ibus_tx.send(msg); + let _ = ibus_tx.send(msg.into()); } // Uninstall RIP route from the RIB. @@ -57,12 +56,11 @@ where } // Fill-in message. - let msg = RouteKeyMsg { + let msg = RouteIpMsg::Delete(RouteKeyMsg { protocol: V::PROTOCOL, prefix: route.prefix.into(), - }; + }); // Send message. - let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); - let _ = ibus_tx.send(msg); + let _ = ibus_tx.send(msg.into()); } diff --git a/holo-routing/src/ibus.rs b/holo-routing/src/ibus.rs index 5c3e826f..e264e9bc 100644 --- a/holo-routing/src/ibus.rs +++ b/holo-routing/src/ibus.rs @@ -164,7 +164,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::Interface(InterfaceMsg::Dump)); + send(ibus_tx, InterfaceMsg::Dump.into()); } // Sends route redistribute update notification. @@ -173,7 +173,7 @@ pub(crate) fn notify_redistribute_add( prefix: IpNetwork, route: &Route, ) { - let msg = RouteMsg { + let msg = RouteRedistributeMsg::Add(RouteMsg { protocol: route.protocol, prefix, distance: route.distance, @@ -181,9 +181,8 @@ pub(crate) fn notify_redistribute_add( tag: route.tag, opaque_attrs: route.opaque_attrs.clone(), nexthops: route.nexthops.clone(), - }; - let msg = IbusMsg::RouteRedistribute(RouteRedistributeMsg::Add(msg)); - send(ibus_tx, msg); + }); + send(ibus_tx, msg.into()); } // Sends route redistribute delete notification. @@ -193,8 +192,8 @@ pub(crate) fn notify_redistribute_del( protocol: Protocol, ) { let msg = RouteKeyMsg { protocol, prefix }; - let msg = IbusMsg::RouteRedistribute(RouteRedistributeMsg::Delete(msg)); - send(ibus_tx, msg); + let msg = RouteRedistributeMsg::Delete(msg); + send(ibus_tx, msg.into()); } // Sends route redistribute delete notification. @@ -203,8 +202,8 @@ pub(crate) fn notify_nht_update( addr: IpAddr, metric: Option, ) { - let msg = IbusMsg::Nexthop(NexthopMsg::Update { addr, metric }); - send(ibus_tx, msg); + let msg = NexthopMsg::Update { addr, metric }; + send(ibus_tx, msg.into()); } // ===== helper functions ===== diff --git a/holo-routing/src/northbound/configuration.rs b/holo-routing/src/northbound/configuration.rs index 9fe3eac5..6ff6c2e0 100644 --- a/holo-routing/src/northbound/configuration.rs +++ b/holo-routing/src/northbound/configuration.rs @@ -23,7 +23,7 @@ use holo_utils::bier::{ Bsl, SubDomainId, UnderlayProtocolType, }; use holo_utils::ibus::{ - BierCfgEvent, BierCfgMsg, IbusMsg, RouteIpMsg, SrCfgEvent, SrCfgMsg, + BierCfgEvent, BierCfgMsg, RouteIpMsg, SrCfgEvent, SrCfgMsg, }; use holo_utils::ip::{AddressFamily, IpNetworkKind}; use holo_utils::mpls::LabelRange; @@ -1022,7 +1022,7 @@ impl Provider for Master { } // Prepare message. - let msg = RouteMsg { + let msg = RouteIpMsg::Add(RouteMsg { protocol: Protocol::STATIC, prefix, distance: 1, @@ -1030,62 +1030,60 @@ impl Provider for Master { tag: None, opaque_attrs: RouteOpaqueAttrs::None, nexthops, - }; + }); // Send message. - let msg = IbusMsg::RouteIp(RouteIpMsg::Add(msg)); - let _ = self.ibus_tx.send(msg); + let _ = self.ibus_tx.send(msg.into()); } Event::StaticRouteUninstall(prefix) => { // Prepare message. - let msg = RouteKeyMsg { + let msg = RouteIpMsg::Delete(RouteKeyMsg { protocol: Protocol::STATIC, prefix, - }; + }); // Send message. - let msg = IbusMsg::RouteIp(RouteIpMsg::Delete(msg)); - let _ = self.ibus_tx.send(msg); + let _ = self.ibus_tx.send(msg.into()); } Event::SrCfgUpdate => { // Update the shared SR configuration by creating a new reference-counted copy. self.shared.sr_config = Arc::new(self.sr_config.clone()); // Notify protocol instances about the updated SR configuration. - let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Update( - self.shared.sr_config.clone(), - ))); + let _ = self.ibus_tx.send( + SrCfgMsg::Update(self.shared.sr_config.clone()).into(), + ); } Event::SrCfgLabelRangeUpdate => { // Notify protocol instances about the updated SRGB/SRLB configuration. - let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Event( - SrCfgEvent::LabelRangeUpdate, - ))); + let _ = self + .ibus_tx + .send(SrCfgMsg::Event(SrCfgEvent::LabelRangeUpdate).into()); } Event::SrCfgPrefixSidUpdate(af) => { // Notify protocol instances about the updated Prefix-SID configuration. - let _ = self.ibus_tx.send(IbusMsg::SrCfg(SrCfgMsg::Event( - SrCfgEvent::PrefixSidUpdate(af), - ))); + let _ = self.ibus_tx.send( + SrCfgMsg::Event(SrCfgEvent::PrefixSidUpdate(af)).into(), + ); } 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::BierCfg( - BierCfgMsg::Update(self.shared.bier_config.clone()), - )); + let _ = self.ibus_tx.send( + BierCfgMsg::Update(self.shared.bier_config.clone()).into(), + ); } Event::BierCfgEncapUpdate(_sd_id, af, _bsl, _encap_type) => { - let _ = self.ibus_tx.send(IbusMsg::BierCfg(BierCfgMsg::Event( - BierCfgEvent::EncapUpdate(af), - ))); + let _ = self.ibus_tx.send( + BierCfgMsg::Event(BierCfgEvent::EncapUpdate(af)).into(), + ); } Event::BierCfgSubDomainUpdate(af) => { - let _ = self.ibus_tx.send(IbusMsg::BierCfg(BierCfgMsg::Event( - BierCfgEvent::SubDomainUpdate(af), - ))); + let _ = self.ibus_tx.send( + BierCfgMsg::Event(BierCfgEvent::SubDomainUpdate(af)).into(), + ); } } } diff --git a/holo-system/src/ibus.rs b/holo-system/src/ibus.rs index c8eb0939..a61f1f14 100644 --- a/holo-system/src/ibus.rs +++ b/holo-system/src/ibus.rs @@ -20,8 +20,8 @@ pub(crate) fn notify_hostname_update( ibus_tx: &IbusSender, hostname: Option, ) { - let msg = IbusMsg::Hostname(HostnameMsg::Update(hostname)); - notify(ibus_tx, msg); + let msg = HostnameMsg::Update(hostname); + notify(ibus_tx, msg.into()); } // ===== helper functions ===== diff --git a/holo-utils/Cargo.toml b/holo-utils/Cargo.toml index 9a9f71ab..9b751fff 100644 --- a/holo-utils/Cargo.toml +++ b/holo-utils/Cargo.toml @@ -13,6 +13,7 @@ bitflags.workspace = true bytes.workspace = true capctl.workspace = true chrono.workspace = true +derive_more.workspace = true derive-new.workspace = true enum-as-inner.workspace = true ipnetwork.workspace = true diff --git a/holo-utils/src/ibus.rs b/holo-utils/src/ibus.rs index e2e1f646..74859b93 100644 --- a/holo-utils/src/ibus.rs +++ b/holo-utils/src/ibus.rs @@ -3,10 +3,10 @@ // // SPDX-License-Identifier: MIT // - use std::net::{IpAddr, Ipv4Addr}; use std::sync::Arc; +use derive_more::From; use serde::{Deserialize, Serialize}; use tokio::sync::broadcast::{Receiver, Sender}; @@ -27,7 +27,7 @@ pub type IbusReceiver = Receiver; pub type IbusSender = Sender; // Ibus message for communication among the different Holo components. -#[derive(Clone, Debug, Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, Serialize, From)] pub enum IbusMsg { // BFD session BfdSession(BfdSessionMsg),