Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
/Cargo.lock
.vscode
.vscode

.pre-commit-config.yaml
34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@ homepage = "https://github.com/stack-rs/netem-trace"
repository = "https://github.com/stack-rs/netem-trace"
keywords = ["emulation", "trace", "network", "utility", "model"]
documentation = "https://docs.rs/netem-trace"
categories = [
"network-programming",
"config",
"development-tools",
"simulation",
]

categories = ["network-programming", "config", "development-tools", "simulation"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bandwidth = "0.3.0"
dyn-clone = { version = "1.0.10", optional = true }
human-bandwidth = { version = "0.1.3", optional = true }
humantime-serde = { version = "1.1.1", optional = true }
itertools = { version = "0.14.0", optional = true }
once_cell = { version = "1.17.0", optional = true }
rand = { version = "0.9.0", optional = true }
rand_distr = { version = "0.5.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
typetag = { version = "0.2.5", optional = true }
humantime-serde = { version = "1.1.1", optional = true }
human-bandwidth = { version = "0.1.3", optional = true }
statrs = { version = "0.18.0", optional = true }
typetag = { version = "0.2.5", optional = true }

[dev-dependencies]
serde_json = "1.0"
figment = { version = "0.10.19", features = ["json"] }

serde_json = "1.0"

[features]
default = ["model"]
model = ["bw-model", "delay-model", "loss-model", "duplicate-model"]
model = [
"bw-model",
"delay-model",
"delay-per-packet-model",
"loss-model",
"duplicate-model"
]
bw-model = ["dep:rand", "dep:rand_distr", "dep:once_cell", "dep:dyn-clone"]
delay-model = ["dep:dyn-clone"]
delay-per-packet-model = ["dep:dyn-clone"]
loss-model = ["dep:dyn-clone"]
duplicate-model = ["dep:dyn-clone"]
serde = ["dep:serde", "dep:typetag", "bandwidth/serde"]
mahimahi = ["dep:itertools"]
human = [
"serde",
"dep:humantime-serde",
"dep:human-bandwidth",
"human-bandwidth/serde",
"serde",
"dep:humantime-serde",
"dep:human-bandwidth",
"human-bandwidth/serde"
]
full = ["model", "mahimahi", "human", "truncated-normal"]
truncated-normal = ["statrs"]
Expand Down
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! If you want to use the pre-defined models, please enable the `model` or `bw-model` feature.
//!
//! And if you want read configuration from file, `serde` feature should also be enabled.
//! We alse recommend you to enable `human` feature to make the configuration file more human-readable.
//! We else recommend you to enable `human` feature to make the configuration file more human-readable.
//!
//! An example to build model from configuration:
//!
Expand Down Expand Up @@ -158,7 +158,7 @@ pub type LossPattern = Vec<f64>;
/// the packet 101 is not duplicated, then the probability of packet 102 being duplicated is still 0.8.
///
/// If both packet 101 and 102 were duplicated, then the probability of packet 103 being duplicated
/// is still 0.1, and as long as the packets were duplicated, the propability of the next packet
/// is still 0.1, and as long as the packets were duplicated, the probability of the next packet
/// being duplicated is always the last element - in this case, 0.1.
pub type DuplicatePattern = Vec<f64>;

Expand Down Expand Up @@ -192,6 +192,20 @@ pub trait DelayTrace: Send {
fn next_delay(&mut self) -> Option<(Delay, Duration)>;
}

/// This is a trait that represents a trace of per-packet delays.
///
/// The trace is a sequence of `delay`.
/// The delay describes how long the packet is delayed when going through.
///
/// For example, if the sequence is [10ms, 20ms, 30ms],
/// then the delay will be 10ms for the first packet, then 20ms for second, then 30ms for third.
///
/// The next_delay function either returns **the next delay**
/// in the sequence, or **None** if the trace goes to end.
pub trait DelayPerPacketTrace: Send {
fn next_delay(&mut self) -> Option<Delay>;
}

/// This is a trait that represents a trace of loss patterns.
///
/// The trace is a sequence of `(loss_pattern, duration)` pairs.
Expand Down
2 changes: 1 addition & 1 deletion src/model/bw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ impl NormalizedBwConfig {
impl NormalizedBwConfig {
/// This is another implementation for converting NormalizedBwConfig into NormalizedBw, where the impact
/// of truncation (`lower_bound` and `upper_bound` field) on the mathematical expectation of the distribution
/// is taking account by modifing the center of the distribution.
/// is taking account by modifying the center of the distribution.
///
/// ## Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/model/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl DelayTrace for RepeatedDelayPattern {
self.current_model = Some(self.pattern[self.current_pattern].clone().into_model());
}
match self.current_model.as_mut().unwrap().next_delay() {
Some(bw) => Some(bw),
Some(delay) => Some(delay),
None => {
self.current_model = None;
self.current_pattern += 1;
Expand Down
Loading
Loading