author | Tom Henderson <tomh@tomh.org> |
Fri, 18 Feb 2011 16:05:39 -0800 | |
changeset 6821 | 203367ae7433 |
parent 6649 | f5413d463948 |
child 6823 | a27f86fb4e55 |
permissions | -rw-r--r-- |
3580 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// |
|
19 |
// Network topology |
|
20 |
// |
|
21 |
// 6Mb/s, 500ms |
|
22 |
// n0-----------------n1 |
|
23 |
// |
|
24 |
// - a 'lossy' network with long delay |
|
25 |
// - TCP flow from n0 to n1 and from n1 to n0 |
|
26 |
// - pcap traces generated as tcp-nsc-lfn-0-0.pcap and tcp-nsc-lfn-1-0.pcap |
|
27 |
// Usage (e.g.): ./waf --run 'tcp-nsc-lfn --TCP_CONGESTION=hybla --runtime=30' |
|
28 |
||
29 |
#include <ctype.h> |
|
30 |
#include <iostream> |
|
31 |
#include <fstream> |
|
32 |
#include <string> |
|
33 |
#include <cassert> |
|
34 |
||
35 |
#include "ns3/core-module.h" |
|
36 |
#include "ns3/common-module.h" |
|
37 |
#include "ns3/helper-module.h" |
|
38 |
#include "ns3/node-module.h" |
|
6821
203367ae7433
merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents:
6649
diff
changeset
|
39 |
#include "ns3/core-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6012
diff
changeset
|
40 |
#include "ns3/ipv4-global-routing-helper.h" |
3580 | 41 |
|
42 |
using namespace ns3; |
|
43 |
||
44 |
NS_LOG_COMPONENT_DEFINE ("TcpNscLfn"); |
|
45 |
||
46 |
int main (int argc, char *argv[]) |
|
47 |
{ |
|
48 |
||
49 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096)); |
|
50 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps")); |
|
51 |
||
52 |
// cubic is the default congestion algorithm in Linux 2.6.26 |
|
53 |
std::string tcpCong = "cubic"; |
|
54 |
// this is the default error rate of our link, that is, the the probability of a single |
|
55 |
// byte being 'corrupted' during transfer. |
|
56 |
double errRate = 0.000001; |
|
57 |
// how long the sender should be running, in seconds. |
|
58 |
unsigned int runtime = 120; |
|
59 |
// the name of the NSC stack library that should be used |
|
60 |
std::string nscStack = "liblinux2.6.26.so"; |
|
61 |
||
62 |
CommandLine cmd; |
|
63 |
// Here, we define additional command line options. |
|
64 |
// This allows a user to override the defaults set above from the command line. |
|
65 |
cmd.AddValue("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong); |
|
66 |
cmd.AddValue("error-rate", "Error rate to apply to link", errRate); |
|
67 |
cmd.AddValue("runtime", "How long the applications should send data (default 120 seconds)", runtime); |
|
68 |
cmd.AddValue("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack); |
|
69 |
cmd.Parse (argc, argv); |
|
70 |
||
71 |
NodeContainer n; |
|
72 |
n.Create (2); |
|
73 |
||
74 |
PointToPointHelper p2p; |
|
75 |
// create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds) |
|
76 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(6 * 1000 * 1000))); |
|
77 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(500))); |
|
78 |
||
79 |
NetDeviceContainer p2pInterfaces = p2p.Install (n); |
|
80 |
// The default MTU of the p2p link would be 65535, which doesn't work |
|
81 |
// well with our default errRate (most packets would arrive corrupted). |
|
82 |
p2pInterfaces.Get(0)->SetMtu(1500); |
|
83 |
p2pInterfaces.Get(1)->SetMtu(1500); |
|
84 |
||
85 |
InternetStackHelper internet; |
|
86 |
// The next statement switches the nodes to 'NSC'-Mode. |
|
87 |
// It disables the native ns-3 TCP model and loads the NSC library. |
|
4473
39ac17168023
examples/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents:
4283
diff
changeset
|
88 |
internet.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue(nscStack)); |
3580 | 89 |
internet.Install (n); |
90 |
||
91 |
if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used |
|
92 |
{ |
|
93 |
// This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the |
|
94 |
// stack. |
|
95 |
// The same mechanism could be used to e.g. disable TCP timestamps: |
|
96 |
// Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0")); |
|
97 |
Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong)); |
|
98 |
} |
|
99 |
Ipv4AddressHelper ipv4; |
|
100 |
ipv4.SetBase ("10.0.0.0", "255.255.255.0"); |
|
101 |
Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces); |
|
102 |
||
103 |
DoubleValue rate(errRate); |
|
104 |
RandomVariableValue u01(UniformVariable (0.0, 1.0)); |
|
105 |
Ptr<RateErrorModel> em1 = |
|
4554
b1940a738981
make CreateObject<> behave like Create<>: use positional constructor arguments rather than attribute lists.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4473
diff
changeset
|
106 |
CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate); |
3580 | 107 |
Ptr<RateErrorModel> em2 = |
4554
b1940a738981
make CreateObject<> behave like Create<>: use positional constructor arguments rather than attribute lists.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4473
diff
changeset
|
108 |
CreateObjectWithAttributes<RateErrorModel> ("RanVar", u01, "ErrorRate", rate); |
3580 | 109 |
|
110 |
// This enables the specified errRate on both link endpoints. |
|
111 |
p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1)); |
|
112 |
p2pInterfaces.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em2)); |
|
113 |
||
4616
a84f60b6cd12
bug 600: lower the default routing priority of Ipv4GlobalRouting; move to helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4554
diff
changeset
|
114 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
3580 | 115 |
|
116 |
uint16_t servPort = 8080; |
|
117 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort)); |
|
118 |
ApplicationContainer sinkApp = sinkHelper.Install (n); |
|
119 |
sinkApp.Start (Seconds (0.0)); |
|
120 |
// this makes sure that the receiver will run one minute longer than the sender applicaton. |
|
121 |
sinkApp.Stop (Seconds (runtime + 60.0)); |
|
122 |
||
123 |
// This sets up two TCP flows, one from A -> B, one from B -> A. |
|
124 |
for (int i = 0, j = 1; i < 2; j--, i++) |
|
125 |
{ |
|
126 |
Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (i), servPort)); |
|
127 |
OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress); |
|
128 |
clientHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1))); |
|
129 |
clientHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0))); |
|
130 |
ApplicationContainer clientApp = clientHelper.Install(n.Get(j)); |
|
131 |
clientApp.Start (Seconds (1.0 + i)); |
|
132 |
clientApp.Stop (Seconds (runtime + 1.0 + i)); |
|
133 |
} |
|
134 |
||
135 |
// This tells ns-3 to generate pcap traces. |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
136 |
p2p.EnablePcapAll ("tcp-nsc-lfn"); |
3580 | 137 |
|
138 |
Simulator::Stop (Seconds(900)); |
|
139 |
Simulator::Run (); |
|
140 |
Simulator::Destroy (); |
|
141 |
||
142 |
return 0; |
|
143 |
} |