Skip to content

Commit d1b7247

Browse files
committed
sim-cli: add latency interceptor option in cli
1 parent fd55010 commit d1b7247

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

sim-cli/src/main.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use std::sync::Arc;
2+
13
use clap::Parser;
24
use log::LevelFilter;
35
use sim_cli::parsing::{create_simulation, create_simulation_with_network, parse_sim_params, Cli};
6+
use simln_lib::{interceptors::LatencyIntercepor, sim_node::Interceptor};
47
use simple_logger::SimpleLogger;
58
use tokio_util::task::TaskTracker;
69

@@ -29,7 +32,12 @@ async fn main() -> anyhow::Result<()> {
2932
let (sim, validated_activities) = if sim_params.sim_network.is_empty() {
3033
create_simulation(&cli, &sim_params, tasks.clone()).await?
3134
} else {
32-
create_simulation_with_network(&cli, &sim_params, tasks.clone()).await?
35+
let interceptors = if let Some(l) = cli.latency_ms {
36+
vec![Arc::new(LatencyIntercepor::new_poisson(l)?) as Arc<dyn Interceptor>]
37+
} else {
38+
vec![]
39+
};
40+
create_simulation_with_network(&cli, &sim_params, tasks.clone(), interceptors).await?
3341
};
3442
let sim2 = sim.clone();
3543

sim-cli/src/parsing.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use log::LevelFilter;
55
use serde::{Deserialize, Serialize};
66
use simln_lib::clock::SimulationClock;
77
use simln_lib::sim_node::{
8-
ln_node_from_graph, populate_network_graph, ChannelPolicy, SimGraph, SimulatedChannel,
8+
ln_node_from_graph, populate_network_graph, ChannelPolicy, Interceptor, SimGraph,
9+
SimulatedChannel,
910
};
1011
use simln_lib::{
1112
cln, cln::ClnNode, eclair, eclair::EclairNode, lnd, lnd::LndNode, serializers,
@@ -87,6 +88,9 @@ pub struct Cli {
8788
/// simulated nodes.
8889
#[clap(long)]
8990
pub speedup_clock: Option<u16>,
91+
/// Latency to optionally introduce for simulated nodes.
92+
#[clap(long)]
93+
pub latency_ms: Option<f32>,
9094
}
9195

9296
impl Cli {
@@ -217,6 +221,7 @@ pub async fn create_simulation_with_network(
217221
cli: &Cli,
218222
sim_params: &SimParams,
219223
tasks: TaskTracker,
224+
interceptors: Vec<Arc<dyn Interceptor>>,
220225
) -> Result<(Simulation<SimulationClock>, Vec<ActivityDefinition>), anyhow::Error> {
221226
let cfg: SimulationCfg = SimulationCfg::try_from(cli)?;
222227
let SimParams {
@@ -246,7 +251,7 @@ pub async fn create_simulation_with_network(
246251
SimGraph::new(
247252
channels.clone(),
248253
tasks.clone(),
249-
vec![],
254+
interceptors,
250255
(shutdown_trigger.clone(), shutdown_listener.clone()),
251256
)
252257
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,

0 commit comments

Comments
 (0)