-
Notifications
You must be signed in to change notification settings - Fork 46
/
dce-iperf.cc
164 lines (142 loc) · 4.68 KB
/
dce-iperf.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "ns3/network-module.h"
#include "ns3/core-module.h"
#include "ns3/internet-module.h"
#include "ns3/dce-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
#include "ns3/netanim-module.h"
#include "ns3/constant-position-mobility-model.h"
#include "ccnx/misc-tools.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("DceIperf");
// ===========================================================================
//
// node 0 node 1
// +----------------+ +----------------+
// | | | |
// +----------------+ +----------------+
// | 10.1.1.1 | | 10.1.1.2 |
// +----------------+ +----------------+
// | point-to-point | | point-to-point |
// +----------------+ +----------------+
// | |
// +---------------------+
// 5 Mbps, 2 ms
//
// 2 nodes : iperf client en iperf server ....
//
// Note : Tested with iperf 2.0.5, you need to modify iperf source in order to
// 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....
// ===========================================================================
int main (int argc, char *argv[])
{
std::string stack = "ns3";
bool useUdp = 0;
std::string bandWidth = "1m";
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.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
DceManagerHelper dceManager;
dceManager.SetTaskManagerAttribute ("FiberManagerType", StringValue ("UcontextFiberManager"));
if (stack == "ns3")
{
InternetStackHelper stack;
stack.Install (nodes);
dceManager.Install (nodes);
}
else if (stack == "linux")
{
#ifdef KERNEL_STACK
dceManager.SetNetworkStack ("ns3::LinuxSocketFdFactory", "Library", StringValue ("liblinux.so"));
dceManager.Install (nodes);
LinuxStackHelper stack;
stack.Install (nodes);
#else
NS_LOG_ERROR ("Linux kernel stack for DCE is not available. build with dce-linux module.");
// silently exit
return 0;
#endif
}
else if (stack == "freebsd")
{
#ifdef KERNEL_STACK
dceManager.SetNetworkStack ("ns3::FreeBSDSocketFdFactory", "Library", StringValue ("libfreebsd.so"));
dceManager.Install (nodes);
FreeBSDStackHelper stack;
stack.Install (nodes);
#else
NS_LOG_ERROR ("FreeBSD kernel stack for DCE is not available. build with dce-freebsd module.");
// silently exit
return 0;
#endif
}
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.252");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// setup ip routes
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
#ifdef KERNEL_STACK
if (stack == "linux")
{
LinuxStackHelper::PopulateRoutingTables ();
}
#endif
DceApplicationHelper dce;
ApplicationContainer apps;
std::ostringstream serverIp;
dce.SetStackSize (1 << 20);
// Launch iperf client on node 0
dce.SetBinary ("iperf");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("-c");
// Extract server IP address
Ptr<Ipv4> ipv4Server = nodes.Get (1)->GetObject<Ipv4> ();
Ipv4Address serverAddress = ipv4Server->GetAddress (1, 0).GetLocal ();
serverAddress.Print (serverIp);
dce.AddArgument (serverIp.str());
dce.AddArgument ("-i");
dce.AddArgument ("1");
dce.AddArgument ("--time");
dce.AddArgument ("10");
if (useUdp)
{
dce.AddArgument ("-u");
dce.AddArgument ("-b");
dce.AddArgument (bandWidth);
}
apps = dce.Install (nodes.Get (0));
apps.Start (Seconds (0.7));
apps.Stop (Seconds (20));
// Launch iperf server on node 1
dce.SetBinary ("iperf");
dce.ResetArguments ();
dce.ResetEnvironment ();
dce.AddArgument ("-s");
dce.AddArgument ("-P");
dce.AddArgument ("1");
if (useUdp)
{
dce.AddArgument ("-u");
}
apps = dce.Install (nodes.Get (1));
pointToPoint.EnablePcapAll ("iperf-" + stack, false);
apps.Start (Seconds (0.6));
setPos (nodes.Get (0), 1, 10, 0);
setPos (nodes.Get (1), 50,10, 0);
Simulator::Stop (Seconds (40.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}