|
| 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 | +} |
0 commit comments