#include "event.h" #include "strategy.h" #include "stats.h" #include "myrand.h" static long starter_time = 0; // to spread out starter times static const int start_increment = 1000; host_spewer::host_spewer() : event((starter_time += start_increment), myrand::uniform(64, 1518)) { } void host_spewer::resched_successful(long completion_time) { sched_strategy->was_successful(&x); nexttime = completion_time + myrand::uniform(50, 5000000L); nextsize = myrand::uniform(64, 1518); } void host_spewer::record_stats() { stats_record(0, nextsize, nexttime); } host_peer_pair::host_peer_pair() : event((starter_time += start_increment), myrand::uniform(64, 1518)) { } void host_peer_pair::resched_successful(long completion_time) { sched_strategy->was_successful(&x); nexttime = completion_time + myrand::uniform(50, 5000000L); int lowsize = nextsize - 10, highsize = nextsize + 10; if (lowsize < 64) lowsize = 64; if (highsize > 1518) highsize = 1518; nextsize = myrand::uniform(lowsize, highsize); } void host_peer_pair::record_stats() { stats_record(0, nextsize, nexttime); } host_client_server::host_client_server() : event((starter_time += start_increment), 0 /* fixed below */) { whos_on = 0; // client message_remaining = myrand::exp(64, 100); take_one_packet(); } void host_client_server::resched_successful(long completion_time) { sched_strategy->was_successful(&x); if (message_remaining) { nexttime = completion_time + 3; } else { whos_on = !whos_on; if (whos_on == 0) { // was just server, next is client nexttime = completion_time + myrand::exp(0, 2000000L); message_remaining = myrand::exp(64, 100); } else { // was just client, next is server nexttime = completion_time + myrand::uniform(1000, 2000); message_remaining = myrand::uniform(100, 1000000L); } } take_one_packet(); } void host_client_server::take_one_packet() { if (message_remaining < 64) { nextsize = 64; message_remaining = 0; } else if (message_remaining <= 1518) { nextsize = message_remaining; message_remaining = 0; } else { nextsize = 1518; message_remaining -= 1518; } } void host_client_server::record_stats() { stats_record(2, nextsize, nexttime); }