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"
|
|
39 |
#include "ns3/global-route-manager.h"
|
|
40 |
#include "ns3/simulator-module.h"
|
|
41 |
|
|
42 |
using namespace ns3;
|
|
43 |
|
|
44 |
NS_LOG_COMPONENT_DEFINE ("TcpNscLfn");
|
|
45 |
|
|
46 |
|
|
47 |
int main (int argc, char *argv[])
|
|
48 |
{
|
|
49 |
RandomVariable::UseGlobalSeed (1, 1, 2, 3, 5, 8);
|
|
50 |
|
|
51 |
Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (4096));
|
|
52 |
Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("6Mbps"));
|
|
53 |
|
|
54 |
// cubic is the default congestion algorithm in Linux 2.6.26
|
|
55 |
std::string tcpCong = "cubic";
|
|
56 |
// this is the default error rate of our link, that is, the the probability of a single
|
|
57 |
// byte being 'corrupted' during transfer.
|
|
58 |
double errRate = 0.000001;
|
|
59 |
// how long the sender should be running, in seconds.
|
|
60 |
unsigned int runtime = 120;
|
|
61 |
// the name of the NSC stack library that should be used
|
|
62 |
std::string nscStack = "liblinux2.6.26.so";
|
|
63 |
|
|
64 |
CommandLine cmd;
|
|
65 |
// Here, we define additional command line options.
|
|
66 |
// This allows a user to override the defaults set above from the command line.
|
|
67 |
cmd.AddValue("TCP_CONGESTION", "Linux 2.6.26 Tcp Congestion control algorithm to use", tcpCong);
|
|
68 |
cmd.AddValue("error-rate", "Error rate to apply to link", errRate);
|
|
69 |
cmd.AddValue("runtime", "How long the applications should send data (default 120 seconds)", runtime);
|
|
70 |
cmd.AddValue("nscstack", "Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)", nscStack);
|
|
71 |
cmd.Parse (argc, argv);
|
|
72 |
|
|
73 |
NodeContainer n;
|
|
74 |
n.Create (2);
|
|
75 |
|
|
76 |
PointToPointHelper p2p;
|
|
77 |
// create point-to-point link with a bandwidth of 6MBit/s and a large delay (0.5 seconds)
|
|
78 |
p2p.SetDeviceAttribute ("DataRate", DataRateValue (DataRate(6 * 1000 * 1000)));
|
|
79 |
p2p.SetChannelAttribute ("Delay", TimeValue (MilliSeconds(500)));
|
|
80 |
|
|
81 |
NetDeviceContainer p2pInterfaces = p2p.Install (n);
|
|
82 |
// The default MTU of the p2p link would be 65535, which doesn't work
|
|
83 |
// well with our default errRate (most packets would arrive corrupted).
|
|
84 |
p2pInterfaces.Get(0)->SetMtu(1500);
|
|
85 |
p2pInterfaces.Get(1)->SetMtu(1500);
|
|
86 |
|
|
87 |
InternetStackHelper internet;
|
|
88 |
// The next statement switches the nodes to 'NSC'-Mode.
|
|
89 |
// It disables the native ns-3 TCP model and loads the NSC library.
|
|
90 |
internet.SetNscStack (nscStack);
|
|
91 |
internet.Install (n);
|
|
92 |
|
|
93 |
if (tcpCong != "cubic") // make sure we only fail if both --nscstack and --TCP_CONGESTION are used
|
|
94 |
{
|
|
95 |
// This uses ns-3s attribute system to set the 'net.ipv4.tcp_congestion_control' sysctl of the
|
|
96 |
// stack.
|
|
97 |
// The same mechanism could be used to e.g. disable TCP timestamps:
|
|
98 |
// Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
|
|
99 |
Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_congestion_control", StringValue (tcpCong));
|
|
100 |
}
|
|
101 |
Ipv4AddressHelper ipv4;
|
|
102 |
ipv4.SetBase ("10.0.0.0", "255.255.255.0");
|
|
103 |
Ipv4InterfaceContainer ipv4Interfaces = ipv4.Assign (p2pInterfaces);
|
|
104 |
|
|
105 |
DoubleValue rate(errRate);
|
|
106 |
RandomVariableValue u01(UniformVariable (0.0, 1.0));
|
|
107 |
Ptr<RateErrorModel> em1 =
|
|
108 |
CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
|
|
109 |
Ptr<RateErrorModel> em2 =
|
|
110 |
CreateObject<RateErrorModel> ("RanVar", u01, "ErrorRate", rate);
|
|
111 |
|
|
112 |
// This enables the specified errRate on both link endpoints.
|
|
113 |
p2pInterfaces.Get(0)->SetAttribute("ReceiveErrorModel", PointerValue (em1));
|
|
114 |
p2pInterfaces.Get(1)->SetAttribute("ReceiveErrorModel", PointerValue (em2));
|
|
115 |
|
|
116 |
GlobalRouteManager::PopulateRoutingTables ();
|
|
117 |
|
|
118 |
uint16_t servPort = 8080;
|
|
119 |
PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), servPort));
|
|
120 |
ApplicationContainer sinkApp = sinkHelper.Install (n);
|
|
121 |
sinkApp.Start (Seconds (0.0));
|
|
122 |
// this makes sure that the receiver will run one minute longer than the sender applicaton.
|
|
123 |
sinkApp.Stop (Seconds (runtime + 60.0));
|
|
124 |
|
|
125 |
// This sets up two TCP flows, one from A -> B, one from B -> A.
|
|
126 |
for (int i = 0, j = 1; i < 2; j--, i++)
|
|
127 |
{
|
|
128 |
Address remoteAddress(InetSocketAddress(ipv4Interfaces.GetAddress (i), servPort));
|
|
129 |
OnOffHelper clientHelper ("ns3::TcpSocketFactory", remoteAddress);
|
|
130 |
clientHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
|
|
131 |
clientHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
|
|
132 |
ApplicationContainer clientApp = clientHelper.Install(n.Get(j));
|
|
133 |
clientApp.Start (Seconds (1.0 + i));
|
|
134 |
clientApp.Stop (Seconds (runtime + 1.0 + i));
|
|
135 |
}
|
|
136 |
|
|
137 |
// This tells ns-3 to generate pcap traces.
|
|
138 |
PointToPointHelper::EnablePcapAll ("tcp-nsc-lfn");
|
|
139 |
|
|
140 |
Simulator::Stop (Seconds(900));
|
|
141 |
Simulator::Run ();
|
|
142 |
Simulator::Destroy ();
|
|
143 |
|
|
144 |
return 0;
|
|
145 |
}
|