author | Vedran Miletić <rivanvx@gmail.com> |
Tue, 26 Mar 2013 22:11:05 +0100 | |
changeset 9270 | 58b23c49c456 |
parent 8986 | 3391f6a7fb3b |
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 <iostream> |
|
30 |
#include <fstream> |
|
31 |
#include <string> |
|
32 |
||
33 |
#include "ns3/core-module.h" |
|
6823
a27f86fb4e55
Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents:
6821
diff
changeset
|
34 |
#include "ns3/network-module.h" |
6848
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
35 |
#include "ns3/internet-module.h" |
1f453ad50ef3
Converts csma, emu, tap-bridge, point-to-point, wifi and wimax modules into modular format
Lalith Suresh <suresh.lalith@gmail.com>
parents:
6847
diff
changeset
|
36 |
#include "ns3/point-to-point-module.h" |
6847
138f00c56381
Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents:
6823
diff
changeset
|
37 |
#include "ns3/applications-module.h" |
6649
f5413d463948
Missing ipv4-global-routing-helper.h include
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6012
diff
changeset
|
38 |
#include "ns3/ipv4-global-routing-helper.h" |
3580 | 39 |
|
40 |
using namespace ns3; |
|
41 |
||
42 |
NS_LOG_COMPONENT_DEFINE ("TcpNscLfn"); |
|
43 |
||
44 |
int main (int argc, char *argv[]) |
|
45 |
{ |
|
46 |
||
47 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096)); |
|
48 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps")); |
|
49 |
||
50 |
// cubic is the default congestion algorithm in Linux 2.6.26 |
|
51 |
std::string tcpCong = "cubic"; |
|
52 |
// this is the default error rate of our link, that is, the the probability of a single |
|
53 |
// byte being 'corrupted' during transfer. |
|
54 |
double errRate = 0.000001; |
|
55 |
// how long the sender should be running, in seconds. |
|
56 |
unsigned int runtime = 120; |
|
57 |
// the name of the NSC stack library that should be used |
|
58 |
std::string nscStack = "liblinux2.6.26.so"; |
|
59 |
||
60 |
CommandLine cmd; |
|
61 |
// Here, we define additional command line options. |
|
62 |
// This allows a user to override the defaults set above from the command line. |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
63 |
cmd.AddValue ("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
64 |
cmd.AddValue ("error-rate", "Error rate to apply to link", errRate); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
65 |
cmd.AddValue ("runtime", "How long the applications should send data (default 120 seconds)", runtime); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
66 |
cmd.AddValue ("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack); |
3580 | 67 |
cmd.Parse (argc, argv); |
68 |
||
69 |
NodeContainer n; |
|
70 |
n.Create (2); |
|
71 |
||
72 |
PointToPointHelper p2p; |
|
73 |
// create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds) |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
74 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate (6 * 1000 * 1000))); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
75 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (500))); |
3580 | 76 |
|
77 |
NetDeviceContainer p2pInterfaces = p2p.Install (n); |
|
78 |
// The default MTU of the p2p link would be 65535, which doesn't work |
|
79 |
// well with our default errRate (most packets would arrive corrupted). |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
80 |
p2pInterfaces.Get (0)->SetMtu (1500); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
81 |
p2pInterfaces.Get (1)->SetMtu (1500); |
3580 | 82 |
|
83 |
InternetStackHelper internet; |
|
84 |
// The next statement switches the nodes to 'NSC'-Mode. |
|
85 |
// It disables the native ns-3 TCP model and loads the NSC library. |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
86 |
internet.SetTcp ("ns3::NscTcpL4Protocol","Library",StringValue (nscStack)); |
3580 | 87 |
internet.Install (n); |
88 |
||
89 |
if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used |
|
90 |
{ |
|
91 |
// This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the |
|
92 |
// stack. |
|
93 |
// The same mechanism could be used to e.g. disable TCP timestamps: |
|
94 |
// Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0")); |
|
95 |
Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong)); |
|
96 |
} |
|
97 |
Ipv4AddressHelper ipv4; |
|
98 |
ipv4.SetBase ("10.0.0.0", "255.255.255.0"); |
|
99 |
Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces); |
|
100 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
101 |
DoubleValue rate (errRate); |
3580 | 102 |
Ptr<RateErrorModel> em1 = |
8986
3391f6a7fb3b
Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
8966
diff
changeset
|
103 |
CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0,Max=1.0]"), "ErrorRate", rate); |
3580 | 104 |
Ptr<RateErrorModel> em2 = |
8986
3391f6a7fb3b
Replace src/network usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
8966
diff
changeset
|
105 |
CreateObjectWithAttributes<RateErrorModel> ("RanVar", StringValue ("ns3::UniformRandomVariable[Min=0.0,Max=1.0]"), "ErrorRate", rate); |
3580 | 106 |
|
107 |
// This enables the specified errRate on both link endpoints. |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
108 |
p2pInterfaces.Get (0)->SetAttribute ("ReceiveErrorModel", PointerValue (em1)); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
109 |
p2pInterfaces.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em2)); |
3580 | 110 |
|
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
|
111 |
Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
3580 | 112 |
|
113 |
uint16_t servPort = 8080; |
|
114 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort)); |
|
115 |
ApplicationContainer sinkApp = sinkHelper.Install (n); |
|
116 |
sinkApp.Start (Seconds (0.0)); |
|
117 |
// this makes sure that the receiver will run one minute longer than the sender applicaton. |
|
118 |
sinkApp.Stop (Seconds (runtime + 60.0)); |
|
119 |
||
120 |
// This sets up two TCP flows, one from A -> B, one from B -> A. |
|
121 |
for (int i = 0, j = 1; i < 2; j--, i++) |
|
7196
0f12b1572bca
general examples coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6865
diff
changeset
|
122 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
123 |
Address remoteAddress (InetSocketAddress (ipv4Interfaces.GetAddress (i), servPort)); |
3580 | 124 |
OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress); |
8966
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7256
diff
changeset
|
125 |
clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]")); |
060dba23e9bb
Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents:
7256
diff
changeset
|
126 |
clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]")); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
127 |
ApplicationContainer clientApp = clientHelper.Install (n.Get (j)); |
3580 | 128 |
clientApp.Start (Seconds (1.0 + i)); |
129 |
clientApp.Stop (Seconds (runtime + 1.0 + i)); |
|
130 |
} |
|
131 |
||
132 |
// This tells ns-3 to generate pcap traces. |
|
6009
e1b696a1ed28
redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
5369
diff
changeset
|
133 |
p2p.EnablePcapAll ("tcp-nsc-lfn"); |
3580 | 134 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7196
diff
changeset
|
135 |
Simulator::Stop (Seconds (900)); |
3580 | 136 |
Simulator::Run (); |
137 |
Simulator::Destroy (); |
|
138 |
||
139 |
return 0; |
|
140 |
} |