Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 93 additions & 23 deletions example/dce-iperf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include "ns3/constant-position-mobility-model.h"
#include "ccnx/misc-tools.h"

/**
* Comment to use iperf2 instead
*/
#define IPERF3

using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("DceIperf");
// ===========================================================================
//
// node 0 node 1
// +----------------+ +----------------+
// | | | |
// | Client | | Server |
// +----------------+ +----------------+
// | 10.1.1.1 | | 10.1.1.2 |
// +----------------+ +----------------+
Expand All @@ -30,20 +35,36 @@ NS_LOG_COMPONENT_DEFINE ("DceIperf");
// allow DCE to have a chance to end an endless loop in iperf as follow:
// in source named Thread.c at line 412 in method named thread_rest
// you must add a sleep (1); to break the infinite loop....
//
// Note : Tested with iperf 3.1, you need to modify source as is done in
// utils/iperf3_1.patch
// ===========================================================================



// duration of the iperf in seconds (s)
const std::string iperfDuration = "20";

int main (int argc, char *argv[])
{
std::string stack = "ns3";
Ptr<Node> clientNode;
Ptr<Node> serverNode;
std::string stack = "linux";
bool useUdp = 0;
std::string bandWidth = "1m";
std::string windowSize = "120KB";
const Time simMaxDuration = Seconds(40);
CommandLine cmd;
cmd.AddValue ("stack", "Name of IP stack: ns3/linux/freebsd.", stack);
cmd.AddValue ("udp", "Use UDP. Default false (0)", useUdp);
cmd.AddValue ("bw", "BandWidth. Default 1m.", bandWidth);
cmd.AddValue ("window", "iperf --window parameter", windowSize);
cmd.Parse (argc, argv);

NodeContainer nodes;
nodes.Create (2);
clientNode = nodes.Get(0);
serverNode = nodes.Get(1);

PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
Expand Down Expand Up @@ -72,7 +93,7 @@ int main (int argc, char *argv[])
#else
NS_LOG_ERROR ("Linux kernel stack for DCE is not available. build with dce-linux module.");
// silently exit
return 0;
return 1;
#endif
}
else if (stack == "freebsd")
Expand Down Expand Up @@ -107,52 +128,101 @@ int main (int argc, char *argv[])

DceApplicationHelper dce;
ApplicationContainer apps;
std::ostringstream oss;

dce.SetStackSize (1 << 20);

// Launch iperf client on node 0
dce.SetBinary ("iperf");

//! 'i+1' because 0 is localhost
// Ipv4Address serverAddr = serverNode->GetObject<Ipv4>()->GetAddress(i+1, 0).GetLocal();
// Ipv4Address sourceAddr = clientNode->GetObject<Ipv4>()->GetAddress(i+1, 0).GetLocal();

//! TODO, we should be able to not specify a port but it seems buggy so for now, let's set a port
// InetSocketAddress local( sourceAddr);
// InetSocketAddress local(sourceAddr, 0);
// InetSocketAddress remote(serverAddr, 5001);
#ifdef IPERF3
// Setup client on node 0
dce.SetBinary ("iperf3");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("-c");
dce.AddArgument ("10.1.1.2");
dce.AddArgument ("--interval=1"); // interval between reports
dce.AddArgument ("--time=10"); // duration of the test
dce.AddArgument ("--verbose");
dce.AddArgument ("--json"); // export to json
dce.AddArgument ("--logfile=client.res"); // into this file
// dce.AddArgument ("-P"); // number of streams to run in parallel
// dce.AddArgument ("1");

apps = dce.Install ( clientNode );
apps.Start (Seconds (5.0));
apps.Stop (simMaxDuration);

// Launch iperf server on node 1, listens on 5201 by default
dce.SetBinary ("iperf3");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("--verbose");
// dce.AddArgument ("--json"); // export to json
// dce.AddArgument ("--logfile=server.res"); // into this file
dce.AddArgument ("--bind=10.1.1.2"); //TODO get address programmatacilly from clientNode
dce.AddArgument ("--server");
if (useUdp)
{
dce.AddArgument ("--udp");
}

apps = dce.Install (serverNode);
#else
/* By default iperf2 listens on port 5001 */
oss.str("");
oss << "--window=" << windowSize;

// Launch iperf client on node 0
dce.SetBinary ("iperf");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("--client=10.1.1.2");
// dce.AddArgument ("");
dce.AddArgument ("-i");
dce.AddArgument ("1");
dce.AddArgument ("--time");
dce.AddArgument ("10");
if (useUdp)
{
dce.AddArgument ("-u");
dce.AddArgument ("-b");
dce.AddArgument (bandWidth);
}
dce.AddArgument (iperfDuration);
dce.AddArgument ("--bind=10.1.0.1"); // TODO get address from clientNode
dce.AddArgument ("--reportstyle=C"); // export as CSV
dce.AddArgument (oss.str()); // size of Rcv or send buffer

apps = dce.Install (nodes.Get (0));
apps.Start (Seconds (0.7));
apps.Stop (Seconds (20));
apps = dce.Install ( clientNode );
apps.Start (Seconds (5.0));
apps.Stop (simMaxDuration);

// Launch iperf server on node 1
dce.SetBinary ("iperf");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("-s");
dce.AddArgument ("-P");
dce.AddArgument ("1");
dce.AddArgument ("--bind=10.1.1.2"); //TODO get address programmatacilly from clientNode
dce.AddArgument ("--parallel=1");
dce.AddArgument (oss.str()); // size of Rcv or send buffer
if (useUdp)
{
dce.AddArgument ("-u");
dce.AddArgument ("--udp");
}

apps = dce.Install (nodes.Get (1));
apps = dce.Install (serverNode);
#endif
apps.Start (Seconds (0.6));

pointToPoint.EnablePcapAll ("iperf-" + stack, false);

apps.Start (Seconds (0.6));


setPos (nodes.Get (0), 1, 10, 0);
setPos (nodes.Get (1), 50,10, 0);
setPos (clientNode, 1, 10, 0);
setPos (serverNode, 50,10, 0);

Simulator::Stop (Seconds (40.0));
Simulator::Stop (simMaxDuration);
Simulator::Run ();
Simulator::Destroy ();

Expand Down
2 changes: 1 addition & 1 deletion test/test-tsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ main (void)
}
else if ((*(int **) val) != ptr)
{
free (ptr);
// free (ptr);
}
}
twalk (root, action);
Expand Down
3 changes: 2 additions & 1 deletion test/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def build(bld):
new_test(bld, 'test-random', '')
new_test(bld, 'test-ioctl', '')
new_test(bld, 'test-fork', '')
new_test(bld, 'test-tsearch', '')
new_test(bld, 'test-local-socket', 'PTHREAD')
new_test(bld, 'test-tcp-socket', 'PTHREAD')
new_test(bld, 'test-pipe', 'PTHREAD')