From: Richard Whitehouse Date: Fri, 20 May 2011 14:26:16 +0000 (+0100) Subject: Add randomness to prevent dropped packets due to incast X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=ns-moose.git Add randomness to prevent dropped packets due to incast --- diff --git a/src/simulation/simulation.cc b/src/simulation/simulation.cc index 3e49af2..e429e7c 100644 --- a/src/simulation/simulation.cc +++ b/src/simulation/simulation.cc @@ -51,7 +51,7 @@ void capture_state(std::ostream& file, LinkLayerHelper::Network& n){ } } -void setup(LinkLayerHelper::Network& n, Topology& t, std::istream& file){ +void setup(LinkLayerHelper::Network& n, Topology& t, std::istream& file, bool random){ uint16_t port = 9; // Discard port (RFC 863) @@ -106,8 +106,14 @@ void setup(LinkLayerHelper::Network& n, Topology& t, std::istream& file){ UdpClientHelper helper(n.interfaces[destination].GetAddress(0), port); helper.SetAttribute("MaxPackets", UintegerValue(packets)); ApplicationContainer app = helper.Install(n.hostNodes.Get(source)); - app.Start (Seconds (time)); + if(random){ + long ntime = rand() % 1000; + Time rtime = Seconds(time) + MilliSeconds(source) + NanoSeconds(ntime); + app.Start (rtime); + } else { + app.Start (Seconds (time)); + } } } @@ -135,6 +141,7 @@ try { std::string dataFile; std::string stateFile; std::string linkLayer = "moose"; + std::string randomize = "yes"; CommandLine cmd; // Allow CommandLine args cmd.AddValue("link", "Link Layer? (moose|ethernet) [moose]", linkLayer); @@ -144,6 +151,7 @@ try { cmd.AddValue("network", "Network Topology File", networkFile); cmd.AddValue("data", "Network Data File", dataFile); cmd.AddValue("state", "Bridge State File", stateFile); + cmd.AddValue("randomize", "Randomize Start Times", randomize); cmd.Parse (argc, argv); std::ifstream networkStream(networkFile.c_str(), std::ifstream::in); @@ -189,7 +197,17 @@ try { } - setup(n, t, dataStream); + bool random; + + if(randomize == "yes"){ + random = true; + } else if(randomize == "no"){ + random = false; + } else { + throw new std::runtime_error("Unknown randomize setting."); + } + + setup(n, t, dataStream, random); // Tracing