Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmd line parser #219

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ arbitrary = { version = "1.4.1", default-features = false, features = [] }
arrayvec = { version = "0.7.6", default-features = false, features = [] }
bindgen = { version = "0.71.1", default-features = false, features = [] }
bolero = { version = "0.12.0", default-features = false, features = [] }
clap = { version = "4.5.27", default-features = false, features = ["std"] }
ctrlc = { version = "3.4.5", default-features = false, features = [] }
doxygen-rs = { version = "0.4.0", default-features = false, features = [] }
etherparse = { version = "0.17.0", default-features = false, features = [] }
Expand Down
1 change: 1 addition & 0 deletions dataplane/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0"

[dependencies]

clap = { workspace = true, features = ["derive"] }
ctrlc = { workspace = true, features = ["termination"] }
net = { workspace = true, features = ["serde"] }
dpdk = { workspace = true }
Expand Down
77 changes: 77 additions & 0 deletions dataplane/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Open Network Fabric Authors

pub(crate) use clap::Parser;
#[derive(Parser)]
#[command(name = "Hedgehog Fabric Gateway dataplane")]
#[command(version = "1.0")] // FIXME
#[command(about = "A next-gen dataplane for next-gen fabric gateway", long_about = None)]
pub(crate) struct CmdArgs {
#[arg(long, value_name = "core-id used as main", default_value_t = 2)]
main_lcore: u8,
#[arg(long, value_name = "map lcore set to cpu set")]
Fredi-raspall marked this conversation as resolved.
Show resolved Hide resolved
lcores: Option<String>,
#[arg(long, value_name = "PCI devices to probe")]
allow: Vec<String>,
#[arg(long, value_name = "huge pages", default_value_t = 8192)]
huge_worker_stack: u32,
#[arg(long, value_name = "socket memory")]
socket_mem: Option<String>,
#[arg(long, value_name = "iova mode(va|pa)")]
iova_mode: Option<String>,
#[arg(long, value_name = "loglevel for a specific component")]
daniel-noland marked this conversation as resolved.
Show resolved Hide resolved
log_level: Vec<String>,
// other non-EAL params (NAT, routing, etc.)
}
impl CmdArgs {
pub fn eal_params(&self) -> Vec<String> {
let mut out = Vec::new();
/* hardcoded (always) */
out.push("--in-memory".to_string());

out.push("--main-lcore".to_owned());
out.push(self.main_lcore.to_string());

out.push("--lcores".to_string());
out.push(
self.lcores
.clone()
.map_or_else(|| "2-4".to_owned(), |lcores| lcores.to_owned()),
);

/* IOVA mode */
out.push(format!(
"--iova-mode={}",
Fredi-raspall marked this conversation as resolved.
Show resolved Hide resolved
&self
.iova_mode
.clone()
.map_or_else(|| { "va".to_owned() }, |mode| mode.to_owned())
));

/* worker huge page stack size */
out.push(format!("--huge-worker-stack={}", self.huge_worker_stack));

/* --allow */
for a in self.allow.iter() {
out.push("--allow".to_string());
out.push(a.to_owned());
}

// To be removed
if self.allow.len() == 0 {
out.push("--allow".to_string());
out.push("0000:01:00.0,dv_flow_en=1".to_string());
Fredi-raspall marked this conversation as resolved.
Show resolved Hide resolved
}

/* --log-level */
for level in self.log_level.iter() {
out.push("--log-level".to_string());
out.push(level.to_owned());
}

// To replace by log
println!("DPDK EAL init params: {:#?}", out);

out
}
}
19 changes: 5 additions & 14 deletions dataplane/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ use dpdk::{dev, eal, socket};
use net::packet::Packet;
use net::parse::Parse;
use tracing::{info, warn};

mod args;
mod nat;

use args::{CmdArgs, Parser};

#[global_allocator]
static GLOBAL_ALLOCATOR: RteAllocator = RteAllocator::new_uninitialized();

Expand All @@ -30,19 +32,8 @@ fn init(args: impl IntoIterator<Item = impl AsRef<str>>) -> Eal {
}

fn main() {
let eal: Eal = init([
"--main-lcore",
"2",
"--lcores",
"2-4",
"--in-memory",
"--allow",
"0000:01:00.0,dv_flow_en=1",
"--huge-worker-stack=8192",
"--socket-mem=8192,0,0,0",
"--no-telemetry",
"--iova-mode=va",
]);
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"))
Expand Down
Loading