Skip to content

Commit ce86790

Browse files
committed
feat(sim): add standalone trippy-sim cli tool (WIP)
1 parent 29789f5 commit ce86790

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

Cargo.lock

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

crates/trippy-sim/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ trippy-core.workspace = true
1717
trippy-packet.workspace = true
1818
trippy-privilege.workspace = true
1919
anyhow.workspace = true
20+
clap.workspace = true
2021
ipnetwork.workspace = true
2122
serde = { workspace = true, default-features = false, features = ["derive"] }
2223
tokio = { workspace = true, features = ["full"] }

crates/trippy-sim/src/app.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
2+
3+
use anyhow::Context;
4+
use clap::Parser;
5+
use tracing_subscriber::fmt::format::FmtSpan;
6+
use trippy_privilege::Privilege;
7+
use trippy_sim::{simulate, Simulation};
8+
9+
/// Trace a route to a host and record statistics
10+
#[allow(clippy::doc_markdown)]
11+
#[derive(Parser, Debug)]
12+
#[command(name = "trip", author, version, about, long_about = None, arg_required_else_help(true))]
13+
pub struct Args {
14+
/// A simulation file to run.
15+
pub simulation: String,
16+
}
17+
18+
pub async fn run() -> anyhow::Result<()> {
19+
let args = Args::parse();
20+
tracing_subscriber::fmt()
21+
.with_span_events(FmtSpan::NONE)
22+
.with_env_filter("debug")
23+
.init();
24+
if !Privilege::discover()?.has_privileges() {
25+
return Err(anyhow::anyhow!("Privileges required to run this command"));
26+
}
27+
let simulation_file =
28+
std::fs::read_to_string(&args.simulation).context(args.simulation.to_string())?;
29+
let sim: Simulation = toml::from_str(&simulation_file)?;
30+
simulate(sim).await
31+
}

crates/trippy-sim/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod app;
2+
3+
#[tokio::main]
4+
async fn main() -> anyhow::Result<()> {
5+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
6+
app::run().await?;
7+
Ok(())
8+
}

0 commit comments

Comments
 (0)