Skip to content

Commit

Permalink
Adjust defaults. 0 byte payload, bigger port range
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed Apr 26, 2017
1 parent 07ff5f0 commit 9df8217
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ip={}> <packet length={}> <mbps={}> <ports={}>", target, length, mbper_second, port_range);
println!("usage: ./puma6_fail <target ip={}> <payload length={}> <mbps={}> <ports={}>", target, length, mbper_second, port_range);

if args.len() > 1 {
target = args[1].as_str();
Expand All @@ -32,19 +32,21 @@ fn main() {
length = args[2].as_str().parse::<usize>().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::<f32>().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::<u16>().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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 9df8217

Please sign in to comment.