Skip to content

Commit

Permalink
ibus: restructure IbusMsg
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Paul-weqe committed Oct 14, 2024
1 parent 4f0b1e9 commit 3cb75a9
Show file tree
Hide file tree
Showing 25 changed files with 746 additions and 424 deletions.
54 changes: 31 additions & 23 deletions holo-bfd/src/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
_ => {}
},

_ => {}
}

Expand Down
6 changes: 3 additions & 3 deletions holo-bfd/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}

Expand Down
85 changes: 55 additions & 30 deletions holo-bgp/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
_ => {}
Expand Down
12 changes: 7 additions & 5 deletions holo-bgp/src/northbound/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions holo-bgp/src/southbound/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}
Loading

0 comments on commit 3cb75a9

Please sign in to comment.