Skip to content

Commit

Permalink
dataplane: add simple cmd line parser ..
Browse files Browse the repository at this point in the history
.. so that the GW dataplane can accept also non-EAL related params.

Signed-off-by: Fredi Raspall <fredi@githedgehog.com>
  • Loading branch information
Fredi-raspall committed Feb 7, 2025
1 parent 5d85763 commit 6c339d9
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 14 deletions.
115 changes: 115 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 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 = { version = "4.5.27", features = ["derive"] }
ctrlc = { workspace = true, features = ["termination"] }
net = { workspace = true, features = ["serde"] }
dpdk = { workspace = true }
Expand Down
60 changes: 60 additions & 0 deletions dataplane/src/args.rs
Original file line number Diff line number Diff line change
@@ -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<bool>,
#[arg(long)]
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)]
no_telemetry: Option<bool>,
#[arg(long, value_name = "iova mode")]
iova_mode: Option<String>,
// other non-EAL params (NAT, routing, etc.)
}
impl CmdArgs {
pub fn eal_params(&self) -> Vec<String> {
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
}
}
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

0 comments on commit 6c339d9

Please sign in to comment.