Skip to content

Commit

Permalink
daemon: make all components optional
Browse files Browse the repository at this point in the history
In addition to having routing protocols as optional features, make
the base components optional as well for extra modularity.

The optional feature dependency graph is as follows:
* keychain
* interface <- routing <- policy
                          protocols

By default, all features remain enabled.

This change allows users to customize the daemon according to their
specific requirements, reducing binary size on systems where certain
components are unnecessary (e.g., keychains and routing policies).

NOTE: some #[allow(...)] annotations were added to silence build
warnings when --no-default-features is passed.

Suggested-by: Frederic LOUI <[email protected]>
Signed-off-by: Renato Westphal <[email protected]>
  • Loading branch information
rwestphal committed Apr 5, 2024
1 parent 4403662 commit 663b268
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 33 deletions.
42 changes: 32 additions & 10 deletions holo-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ tracing.workspace = true
tracing-subscriber.workspace = true
yang2.workspace = true

holo-interface = { path = "../holo-interface" }
holo-interface = { path = "../holo-interface", optional = true }
holo-bfd = { path = "../holo-bfd", optional = true }
holo-bgp = { path = "../holo-bgp", optional = true }
holo-keychain = { path = "../holo-keychain" }
holo-keychain = { path = "../holo-keychain", optional = true }
holo-ldp = { path = "../holo-ldp", optional = true }
holo-northbound = { path = "../holo-northbound" }
holo-ospf = { path = "../holo-ospf", optional = true }
holo-policy = { path = "../holo-policy" }
holo-policy = { path = "../holo-policy", optional = true }
holo-protocol = { path = "../holo-protocol" }
holo-rip = { path = "../holo-rip", optional = true }
holo-routing = { path = "../holo-routing" }
holo-routing = { path = "../holo-routing", optional = true }
holo-utils = { path = "../holo-utils" }
holo-yang = { path = "../holo-yang" }

Expand All @@ -55,10 +55,32 @@ name = "holod"
path = "src/main.rs"

[features]
default = ["bfd", "bgp", "ldp", "ospf", "rip"]
bfd = ["holo-bfd"]
bgp = ["holo-bgp"]
ldp = ["holo-ldp"]
ospf = ["holo-ospf"]
rip = ["holo-rip"]
default = [
# Base components
"interface",
"keychain",
"policy",
"routing",
# Protocols
"bfd",
"bgp",
"ldp",
"ospf",
"rip",
]

# Base components
interface = ["holo-interface"]
keychain = ["holo-keychain"]
policy = ["holo-policy", "holo-routing"]
routing = ["holo-routing", "holo-interface"]

# Protocols
bfd = ["holo-bfd", "holo-routing"]
bgp = ["holo-bgp", "holo-routing"]
ldp = ["holo-ldp", "holo-routing"]
ospf = ["holo-ospf", "holo-routing"]
rip = ["holo-rip", "holo-routing"]

# Other features
io_uring = ["tokio-uring"]
61 changes: 38 additions & 23 deletions holo-daemon/src/northbound/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use holo_northbound::state::NodeAttributes;
use holo_northbound::{
api as papi, CallbackKey, CallbackOp, NbDaemonSender, NbProviderReceiver,
};
use holo_utils::ibus::{IbusReceiver, IbusSender};
use holo_utils::task::TimeoutTask;
use holo_utils::{Database, Receiver, Sender, UnboundedReceiver};
use holo_yang::YANG_CTX;
Expand Down Expand Up @@ -623,43 +624,57 @@ impl Default for ConfirmedCommit {
// ===== helper functions =====

// Starts base data providers.
#[allow(unused_mut, unused_variables)]
fn start_providers(
config: &Config,
db: Database,
) -> (NbProviderReceiver, Vec<NbDaemonSender>) {
let mut providers = Vec::new();
let (provider_tx, provider_rx) = mpsc::unbounded_channel();
let (ibus_tx, ibus_rx) = broadcast::channel(1024);
let (ibus_tx, ibus_rx): (IbusSender, IbusReceiver) =
broadcast::channel(1024);

// Start holo-routing.
let daemon_tx = holo_routing::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
db,
config.event_recorder.clone(),
);
providers.push(daemon_tx);
#[cfg(feature = "routing")]
{
let daemon_tx = holo_routing::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
db,
config.event_recorder.clone(),
);
providers.push(daemon_tx);
}

// Start holo-interface.
let daemon_tx = holo_interface::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
);
providers.push(daemon_tx);
#[cfg(feature = "interface")]
{
let daemon_tx = holo_interface::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
);
providers.push(daemon_tx);
}

// Start holo-keychain.
let daemon_tx = holo_keychain::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
);
providers.push(daemon_tx);
#[cfg(feature = "keychain")]
{
let daemon_tx = holo_keychain::start(
provider_tx.clone(),
ibus_tx.clone(),
ibus_tx.subscribe(),
);
providers.push(daemon_tx);
}

// Start holo-policy.
let daemon_tx = holo_policy::start(provider_tx, ibus_tx, ibus_rx);
providers.push(daemon_tx);
#[cfg(feature = "policy")]
{
let daemon_tx = holo_policy::start(provider_tx, ibus_tx, ibus_rx);
providers.push(daemon_tx);
}

(provider_rx, providers)
}
Expand Down
8 changes: 8 additions & 0 deletions holo-daemon/src/northbound/yang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use holo_northbound::ProviderBase;
use holo_yang as yang;
use holo_yang::YANG_CTX;

#[allow(dead_code)]
fn modules_add<P: ProviderBase>(modules: &mut Vec<&'static str>) {
modules.extend(P::yang_modules().iter());
}
Expand All @@ -30,9 +31,16 @@ pub(crate) fn create_context() {
}

// Add core modules.
#[cfg(feature = "interface")]
modules_add::<holo_interface::Master>(&mut modules);

#[cfg(feature = "routing")]
modules_add::<holo_routing::Master>(&mut modules);

#[cfg(feature = "keychain")]
modules_add::<holo_keychain::Master>(&mut modules);

#[cfg(feature = "policy")]
modules_add::<holo_policy::Master>(&mut modules);

// Add protocol modules based on enabled features.
Expand Down

0 comments on commit 663b268

Please sign in to comment.