diff options
| author | diogo464 <[email protected]> | 2025-08-18 10:21:41 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-08-18 10:21:41 +0100 |
| commit | 040dc303921d1a29402014ce410e98aa1be6f959 (patch) | |
| tree | ee1dc666fa53e6e9cc802154a1613a7742490195 | |
| parent | 5adf3d03e5fbc3b2d4abdacdd848659fb7015b06 (diff) | |
added the --matrix-wrap flag
I got to the point of needed more than 10k rows and since my biggest
latency matrix is 10k in size this option allows the values to wrap so
we can create a network bigger than the matrix.
| -rw-r--r-- | src/main.rs | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 303d4f3..9f50595 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -114,6 +114,9 @@ struct NetUpArgs { | |||
| 114 | /// 99.91315 110.71518 93.90618 84.67561 0.0 {n} | 114 | /// 99.91315 110.71518 93.90618 84.67561 0.0 {n} |
| 115 | #[clap(long)] | 115 | #[clap(long)] |
| 116 | latency_matrix: PathBuf, | 116 | latency_matrix: PathBuf, |
| 117 | |||
| 118 | #[clap(long)] | ||
| 119 | matrix_wrap: bool, | ||
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | #[derive(Debug, Args)] | 122 | #[derive(Debug, Args)] |
| @@ -141,6 +144,9 @@ struct NetPreviewArgs { | |||
| 141 | 144 | ||
| 142 | #[clap(long)] | 145 | #[clap(long)] |
| 143 | latency_matrix: PathBuf, | 146 | latency_matrix: PathBuf, |
| 147 | |||
| 148 | #[clap(long)] | ||
| 149 | matrix_wrap: bool, | ||
| 144 | } | 150 | } |
| 145 | 151 | ||
| 146 | #[derive(Debug, Args)] | 152 | #[derive(Debug, Args)] |
| @@ -245,7 +251,7 @@ async fn cmd_net_up(args: NetUpArgs) -> Result<()> { | |||
| 245 | let matrix = LatencyMatrix::parse(&matrix_content, latency_matrix::TimeUnit::Milliseconds) | 251 | let matrix = LatencyMatrix::parse(&matrix_content, latency_matrix::TimeUnit::Milliseconds) |
| 246 | .context("parsing latency matrix")?; | 252 | .context("parsing latency matrix")?; |
| 247 | let machines = oar::job_list_machines(&context).await?; | 253 | let machines = oar::job_list_machines(&context).await?; |
| 248 | let configs = machine_generate_configs(&matrix, &machines, &args.addresses)?; | 254 | let configs = machine_generate_configs(&matrix, args.matrix_wrap, &machines, &args.addresses)?; |
| 249 | machines_net_container_build(&context, &machines).await?; | 255 | machines_net_container_build(&context, &machines).await?; |
| 250 | machines_clean(&context, &machines).await?; | 256 | machines_clean(&context, &machines).await?; |
| 251 | machines_configure(&context, &configs).await?; | 257 | machines_configure(&context, &configs).await?; |
| @@ -307,7 +313,7 @@ async fn cmd_net_preview(args: NetPreviewArgs) -> Result<()> { | |||
| 307 | let matrix = LatencyMatrix::parse(&matrix_content, latency_matrix::TimeUnit::Milliseconds) | 313 | let matrix = LatencyMatrix::parse(&matrix_content, latency_matrix::TimeUnit::Milliseconds) |
| 308 | .context("parsing latency matrix")?; | 314 | .context("parsing latency matrix")?; |
| 309 | let machines = args.machine; | 315 | let machines = args.machine; |
| 310 | let configs = machine_generate_configs(&matrix, &machines, &args.addresses)?; | 316 | let configs = machine_generate_configs(&matrix, args.matrix_wrap, &machines, &args.addresses)?; |
| 311 | 317 | ||
| 312 | for config in configs { | 318 | for config in configs { |
| 313 | (0..20).for_each(|_| print!("-")); | 319 | (0..20).for_each(|_| print!("-")); |
| @@ -955,6 +961,7 @@ fn machine_address_for_idx(machine: Machine, idx: u32) -> Ipv4Addr { | |||
| 955 | 961 | ||
| 956 | fn machine_generate_configs( | 962 | fn machine_generate_configs( |
| 957 | matrix: &LatencyMatrix, | 963 | matrix: &LatencyMatrix, |
| 964 | matrix_wrap: bool, | ||
| 958 | machines: &[Machine], | 965 | machines: &[Machine], |
| 959 | addr_policy: &AddressAllocationPolicy, | 966 | addr_policy: &AddressAllocationPolicy, |
| 960 | ) -> Result<Vec<MachineConfig>> { | 967 | ) -> Result<Vec<MachineConfig>> { |
| @@ -1003,12 +1010,14 @@ fn machine_generate_configs( | |||
| 1003 | .push(address); | 1010 | .push(address); |
| 1004 | } | 1011 | } |
| 1005 | 1012 | ||
| 1006 | if addresses.len() > matrix.dimension() { | 1013 | if !matrix_wrap { |
| 1007 | return Err(eyre::eyre!( | 1014 | if addresses.len() > matrix.dimension() { |
| 1008 | "latency matrix is too small, size is {} but {} was required", | 1015 | return Err(eyre::eyre!( |
| 1009 | matrix.dimension(), | 1016 | "latency matrix is too small, size is {} but {} was required", |
| 1010 | addresses.len() | 1017 | matrix.dimension(), |
| 1011 | )); | 1018 | addresses.len() |
| 1019 | )); | ||
| 1020 | } | ||
| 1012 | } | 1021 | } |
| 1013 | 1022 | ||
| 1014 | for &machine in machines { | 1023 | for &machine in machines { |
| @@ -1029,7 +1038,13 @@ fn machine_generate_configs( | |||
| 1029 | let addr_idx = address_to_index[&addr]; | 1038 | let addr_idx = address_to_index[&addr]; |
| 1030 | for other_idx in (0..addresses.len()).filter(|i| *i != addr_idx) { | 1039 | for other_idx in (0..addresses.len()).filter(|i| *i != addr_idx) { |
| 1031 | let other = addresses[other_idx]; | 1040 | let other = addresses[other_idx]; |
| 1032 | let latency = matrix.latency(addr_idx, other_idx); | 1041 | let latency = match matrix_wrap { |
| 1042 | true => matrix.latency( | ||
| 1043 | addr_idx % matrix.dimension(), | ||
| 1044 | other_idx % matrix.dimension(), | ||
| 1045 | ), | ||
| 1046 | false => matrix.latency(addr_idx, other_idx), | ||
| 1047 | }; | ||
| 1033 | let latency_millis = u32::try_from(latency.as_millis()).unwrap(); | 1048 | let latency_millis = u32::try_from(latency.as_millis()).unwrap(); |
| 1034 | if !latencies_set.contains(&latency_millis) { | 1049 | if !latencies_set.contains(&latency_millis) { |
| 1035 | latencies_set.insert(latency_millis); | 1050 | latencies_set.insert(latency_millis); |
