Skip to content

Commit 1e888d3

Browse files
committed
feat(trace): add humanized format for bandwidth
1 parent e4ae6f5 commit 1e888d3

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ rust-version = "1.77"
1313
ctrlc = "3.2.5"
1414
figment = { version = "0.10", features = ["toml", "env", "json"] }
1515
futures = "0.3.29"
16-
humantime = "2.1.0"
17-
netem-trace = { version = "0.3.1", features = ["serde", "human", "mahimahi"] }
16+
human-bandwidth = { version = "0.1.1", features = ["serde"] }
17+
netem-trace = { version = "0.3.3", features = ["serde", "human", "mahimahi"] }
1818
nix = "0.26.2"
1919
once_cell = "1.19"
2020
rand = "0.8.5"
@@ -47,7 +47,8 @@ ctrlc = { workspace = true }
4747
dirs = "5.0.1"
4848
figment = { workspace = true }
4949
futures = { workspace = true }
50-
humantime = { workspace = true }
50+
human-bandwidth = { workspace = true }
51+
humantime = "2.1.0"
5152
netem-trace = { workspace = true }
5253
nix = { workspace = true }
5354
once_cell = { workspace = true }
@@ -73,4 +74,4 @@ debug = true
7374
# required for cargo flamegraph
7475
[profile.dev]
7576
debug = true
76-
opt-level = 0
77+
opt-level = 0

config.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ bw_type = "NetworkLayer"
106106
# For example, the following line means 1.2 Gbps.
107107
#
108108
# Default: Unlimited
109-
bandwidth = { gbps = 1, bps = 200000000 }
109+
bandwidth = "1Gbps 200Mbps"
110110

111111
# Queue type
112112
# Possible values:

rattan-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ figment = { workspace = true }
1717
camellia = { git = "https://github.com/minhuw/camellia.git", optional = true }
1818
etherparse = "0.14.3"
1919
futures = { workspace = true }
20+
human-bandwidth = { workspace = true }
2021
humantime-serde = { version = "1.1.1", optional = true }
2122
ipnet = "2.8.0"
2223
lazy_static = "1.4.0"

rattan-core/src/devices/bandwidth/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ where
237237
P: Packet,
238238
Q: PacketQueue<P>,
239239
{
240+
#[cfg_attr(feature = "serde", serde(with = "human_bandwidth::serde"))]
240241
pub bandwidth: Option<Bandwidth>,
241242
pub queue_config: Option<Q::Config>,
242243
pub bw_type: Option<BwType>,

src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ pub struct Arguments {
8888
downlink_delay: Option<Delay>,
8989

9090
/// Uplink bandwidth
91-
#[arg(long, global = true, value_name = "Bandwidth", group = "uplink-bw")]
92-
uplink_bandwidth: Option<u64>,
91+
#[arg(long, global = true, value_name = "Bandwidth", group = "uplink-bw", value_parser = human_bandwidth::parse_bandwidth)]
92+
uplink_bandwidth: Option<Bandwidth>,
9393
/// Uplink trace file
9494
#[arg(long, global = true, value_name = "Trace File", group = "uplink-bw")]
9595
uplink_trace: Option<String>,
@@ -107,8 +107,8 @@ pub struct Arguments {
107107
uplink_queue_args: Option<String>,
108108

109109
/// Downlink bandwidth
110-
#[arg(long, global = true, value_name = "Bandwidth", group = "downlink-bw")]
111-
downlink_bandwidth: Option<u64>,
110+
#[arg(long, global = true, value_name = "Bandwidth", group = "downlink-bw", value_parser = human_bandwidth::parse_bandwidth)]
111+
downlink_bandwidth: Option<Bandwidth>,
112112
/// Downlink trace file
113113
#[arg(long, global = true, value_name = "Trace File", group = "downlink-bw")]
114114
downlink_trace: Option<String>,
@@ -402,7 +402,6 @@ fn main() -> ExitCode {
402402
let mut downlink_count = 0;
403403

404404
if let Some(bandwidth) = opts.uplink_bandwidth {
405-
let bandwidth = Bandwidth::from_bps(bandwidth);
406405
let device_config = match opts.uplink_queue {
407406
Some(QueueType::Infinite) | None => {
408407
DeviceBuildConfig::Bw(BwDeviceBuildConfig::Infinite(
@@ -465,7 +464,6 @@ fn main() -> ExitCode {
465464
}
466465

467466
if let Some(bandwidth) = opts.downlink_bandwidth {
468-
let bandwidth = Bandwidth::from_bps(bandwidth);
469467
let device_config = match opts.downlink_queue {
470468
Some(QueueType::Infinite) | None => {
471469
DeviceBuildConfig::Bw(BwDeviceBuildConfig::Infinite(

0 commit comments

Comments
 (0)