diff --git a/Cargo.lock b/Cargo.lock index 1be5a581..44ea16ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,12 +36,56 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + [[package]] name = "anstyle" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.95" @@ -245,6 +289,52 @@ dependencies = [ "libloading", ] +[[package]] +name = "clap" +version = "4.5.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e77c3243bd94243c03672cb5154667347c457ca271254724f9f393aee1c05ff" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.98", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "ctrlc" version = "3.4.5" @@ -259,6 +349,7 @@ dependencies = [ name = "dataplane" version = "0.1.0" dependencies = [ + "clap", "ctrlc", "dpdk", "net", @@ -372,6 +463,12 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "indexmap" version = "2.7.1" @@ -382,6 +479,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.13.0" @@ -785,6 +888,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "1.0.109" @@ -948,6 +1057,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "valuable" version = "0.1.1" diff --git a/dataplane/Cargo.toml b/dataplane/Cargo.toml index ee07312f..3f5b35c3 100644 --- a/dataplane/Cargo.toml +++ b/dataplane/Cargo.toml @@ -7,6 +7,7 @@ license = "Apache-2.0" [dependencies] +clap = { version = "4.5.27", features = ["derive"] } ctrlc = { workspace = true, features = ["termination"] } net = { workspace = true, features = ["serde"] } dpdk = { workspace = true } diff --git a/dataplane/src/args.rs b/dataplane/src/args.rs new file mode 100644 index 00000000..904c5147 --- /dev/null +++ b/dataplane/src/args.rs @@ -0,0 +1,60 @@ +// 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 = "main-lcore", default_value_t = 2)] + main_lcore: u8, + #[arg(long, value_name = "lcores")] + lcores: String, + #[arg(long)] + in_memory: Option, + #[arg(long)] + allow: Vec, + #[arg(long, value_name = "huge pages", default_value_t = 8192)] + huge_worker_stack: u32, + #[arg(long, value_name = "socket memory")] + socket_mem: Option, + #[arg(long)] + no_telemetry: Option, + #[arg(long, value_name = "iova mode")] + iova_mode: Option, + // other non-EAL params (NAT, routing, etc.) +} +impl CmdArgs { + pub fn eal_params(&self) -> Vec { + let mut out = Vec::new(); + + out.push("--main-lcore".to_owned()); + out.push(self.main_lcore.to_string()); + + out.push("--lcores".to_string()); + out.push(self.lcores.to_string()); + + if self.in_memory.is_some() { + out.push("--in-memory".to_string()); + } + if self.no_telemetry.is_some() { + out.push("--no-telemetry".to_string()); + } + out.push(format!( + "--iova-mode={}", + &self + .iova_mode + .clone() + .map_or_else(|| { "va".to_owned() }, |mode| mode.to_owned()) + )); + out.push(format!("--huge-worker-stack={}", self.huge_worker_stack)); + + for a in self.allow.iter() { + out.push("--allow".to_string()); + out.push(a.to_owned()); + } + out + } +} diff --git a/dataplane/src/main.rs b/dataplane/src/main.rs index 40238c19..2884549d 100644 --- a/dataplane/src/main.rs +++ b/dataplane/src/main.rs @@ -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(); @@ -30,19 +32,8 @@ fn init(args: impl IntoIterator>) -> 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"))