Skip to content

Commit

Permalink
dp: Split main() function into EAL init, devices init, workers start
Browse files Browse the repository at this point in the history
Make the code more modular by moving EAL/devices init, and workers
start, into dedicated functions. A follow-up step could be to move the
closure passed to WorkerThread::launch() to a dedicated function.

The motivation is to get a clearer function to hook the oncoming NAT
code.

Signed-off-by: Quentin Monnet <[email protected]>
  • Loading branch information
qmonnet committed Feb 14, 2025
1 parent e1d1033 commit 629c360
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions dataplane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::pipeline::{MetaPacket, Metadata, Passthrough, Pipeline};
#[global_allocator]
static GLOBAL_ALLOCATOR: RteAllocator = RteAllocator::new_uninitialized();

fn init(args: impl IntoIterator<Item = impl AsRef<str>>) -> Eal {
fn init_eal(args: impl IntoIterator<Item = impl AsRef<str>>) -> Eal {
let rte = eal::init(args);
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
Expand All @@ -48,16 +48,8 @@ fn setup_pipeline() -> Pipeline {
pipeline
}

fn main() {
let args = CmdArgs::parse();
let eal: Eal = init(args.eal_params());

let (stop_tx, stop_rx) = std::sync::mpsc::channel();
ctrlc::set_handler(move || stop_tx.send(()).expect("Error sending SIGINT signal"))
.expect("failed to set SIGINT handler");

let devices: Vec<Dev> = eal
.dev
fn init_devices(eal: &Eal) -> Vec<Dev> {
eal.dev
.iter()
.map(|dev| {
let config = dev::DevConfig {
Expand Down Expand Up @@ -107,8 +99,10 @@ fn main() {
dev.start().unwrap();
dev
})
.collect();
.collect()
}

fn start_rte_workers(devices: &Vec<Dev>) {
LCoreId::iter().enumerate().for_each(|(i, lcore_id)| {
info!("Starting RTE Worker on {lcore_id:?}");
let rx_queue = devices[0].rx_queue(RxQueueIndex(i as u16)).unwrap();
Expand Down Expand Up @@ -145,6 +139,20 @@ fn main() {
}
});
});
}

fn main() {
let (stop_tx, stop_rx) = std::sync::mpsc::channel();
ctrlc::set_handler(move || stop_tx.send(()).expect("Error sending SIGINT signal"))
.expect("failed to set SIGINT handler");

let args = CmdArgs::parse();
let eal: Eal = init_eal(args.eal_params());

let devices: Vec<Dev> = init_devices(&eal);

start_rte_workers(&devices);

stop_rx.recv().expect("failed to receive stop signal");
info!("Shutting down dataplane");
std::process::exit(0);
Expand Down

0 comments on commit 629c360

Please sign in to comment.