Skip to content

Commit ae1f6a8

Browse files
committed
dataplane: add simple cmd line parser ..
.. so that the GW dataplane can accept also non-EAL related params. Signed-off-by: Fredi Raspall <[email protected]>
1 parent 5d85763 commit ae1f6a8

File tree

4 files changed

+200
-14
lines changed

4 files changed

+200
-14
lines changed

Cargo.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dataplane/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "Apache-2.0"
77

88
[dependencies]
99

10+
clap = { version = "4.5.27", features = ["derive"] }
1011
ctrlc = { workspace = true, features = ["termination"] }
1112
net = { workspace = true, features = ["serde"] }
1213
dpdk = { workspace = true }

dataplane/src/args.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Open Network Fabric Authors
3+
4+
pub(crate) use clap::Parser;
5+
#[derive(Parser)]
6+
#[command(name = "Hedgehog Fabric Gateway dataplane")]
7+
#[command(version = "1.0")] // FIXME
8+
#[command(about = "A next-gen dataplane for next-gen fabric gateway", long_about = None)]
9+
pub(crate) struct CmdArgs {
10+
#[arg(long, value_name = "core-id used as main", default_value_t = 2)]
11+
main_lcore: u8,
12+
#[arg(long, value_name = "map lcore set to cpu set")]
13+
lcores: Option<String>,
14+
#[arg(long, value_name = "in-memory flag", default_value_t = false)]
15+
in_memory: bool,
16+
#[arg(long)]
17+
allow: Vec<String>,
18+
#[arg(long, value_name = "huge pages", default_value_t = 8192)]
19+
huge_worker_stack: u32,
20+
#[arg(long, value_name = "socket memory")]
21+
socket_mem: Option<String>,
22+
#[arg(long, value_name = "enable/disable telemetry", default_value_t = true)]
23+
no_telemetry: bool,
24+
#[arg(long, value_name = "iova mode(va|pa)")]
25+
iova_mode: Option<String>,
26+
#[arg(long, value_name = "loglevel for a specific component")]
27+
log_level: Vec<String>,
28+
// other non-EAL params (NAT, routing, etc.)
29+
}
30+
impl CmdArgs {
31+
pub fn eal_params(&self) -> Vec<String> {
32+
let mut out = Vec::new();
33+
34+
out.push("--main-lcore".to_owned());
35+
out.push(self.main_lcore.to_string());
36+
37+
out.push("--lcores".to_string());
38+
out.push(
39+
self.lcores
40+
.clone()
41+
.map_or_else(|| "2-4".to_owned(), |lcores| lcores.to_owned()),
42+
);
43+
44+
if self.in_memory {
45+
out.push("--in-memory".to_string());
46+
}
47+
if self.no_telemetry == false {
48+
out.push("--no-telemetry".to_string());
49+
} else {
50+
out.push("--telemetry".to_string()); /* DPDK default */
51+
}
52+
53+
/* IOVA mode */
54+
out.push(format!(
55+
"--iova-mode={}",
56+
&self
57+
.iova_mode
58+
.clone()
59+
.map_or_else(|| { "va".to_owned() }, |mode| mode.to_owned())
60+
));
61+
62+
/* worker huge page stack size */
63+
out.push(format!("--huge-worker-stack={}", self.huge_worker_stack));
64+
65+
/* --allow */
66+
for a in self.allow.iter() {
67+
out.push("--allow".to_string());
68+
out.push(a.to_owned());
69+
}
70+
71+
/* --log-level */
72+
for level in self.log_level.iter() {
73+
out.push("--log-level".to_string());
74+
out.push(level.to_owned());
75+
}
76+
77+
out
78+
}
79+
}

dataplane/src/main.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ use dpdk::{dev, eal, socket};
1111
use net::packet::Packet;
1212
use net::parse::Parse;
1313
use tracing::{info, warn};
14-
14+
mod args;
1515
mod nat;
1616

17+
use args::{CmdArgs, Parser};
18+
1719
#[global_allocator]
1820
static GLOBAL_ALLOCATOR: RteAllocator = RteAllocator::new_uninitialized();
1921

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

3234
fn main() {
33-
let eal: Eal = init([
34-
"--main-lcore",
35-
"2",
36-
"--lcores",
37-
"2-4",
38-
"--in-memory",
39-
"--allow",
40-
"0000:01:00.0,dv_flow_en=1",
41-
"--huge-worker-stack=8192",
42-
"--socket-mem=8192,0,0,0",
43-
"--no-telemetry",
44-
"--iova-mode=va",
45-
]);
35+
let args = CmdArgs::parse();
36+
let eal: Eal = init(args.eal_params());
4637

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

0 commit comments

Comments
 (0)