A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
tcp-nsc-lfn.cc
Go to the documentation of this file.
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"
34
#include "ns3/network-module.h"
35
#include "ns3/internet-module.h"
36
#include "ns3/point-to-point-module.h"
37
#include "ns3/applications-module.h"
38
#include "ns3/ipv4-global-routing-helper.h"
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.
63
cmd.
AddValue
(
"TCP_CONGESTION"
,
"Linux 2.6.26 Tcp Congestion control algorithm to use"
, tcpCong);
64
cmd.
AddValue
(
"error-rate"
,
"Error rate to apply to link"
, errRate);
65
cmd.
AddValue
(
"runtime"
,
"How long the applications should send data (default 120 seconds)"
, runtime);
66
cmd.
AddValue
(
"nscstack"
,
"Set name of NSC stack (shared library) to use (default liblinux2.6.26.so)"
, nscStack);
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)
74
p2p.
SetDeviceAttribute
(
"DataRate"
,
DataRateValue
(
DataRate
(6 * 1000 * 1000)));
75
p2p.
SetChannelAttribute
(
"Delay"
,
TimeValue
(MilliSeconds (500)));
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).
80
p2pInterfaces.
Get
(0)->
SetMtu
(1500);
81
p2pInterfaces.
Get
(1)->
SetMtu
(1500);
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.
86
internet.
SetTcp
(
"ns3::NscTcpL4Protocol"
,
"Library"
,
StringValue
(nscStack));
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
101
DoubleValue
rate (errRate);
102
Ptr<RateErrorModel>
em1 =
103
CreateObjectWithAttributes<RateErrorModel> (
"RanVar"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.0,Max=1.0]"
),
"ErrorRate"
, rate);
104
Ptr<RateErrorModel>
em2 =
105
CreateObjectWithAttributes<RateErrorModel> (
"RanVar"
,
StringValue
(
"ns3::UniformRandomVariable[Min=0.0,Max=1.0]"
),
"ErrorRate"
, rate);
106
107
// This enables the specified errRate on both link endpoints.
108
p2pInterfaces.
Get
(0)->
SetAttribute
(
"ReceiveErrorModel"
,
PointerValue
(em1));
109
p2pInterfaces.
Get
(1)->
SetAttribute
(
"ReceiveErrorModel"
,
PointerValue
(em2));
110
111
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
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++)
122
{
123
Address
remoteAddress (
InetSocketAddress
(ipv4Interfaces.
GetAddress
(i), servPort));
124
OnOffHelper
clientHelper (
"ns3::TcpSocketFactory"
, remoteAddress);
125
clientHelper.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
126
clientHelper.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
127
ApplicationContainer
clientApp = clientHelper.
Install
(n.
Get
(j));
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.
133
p2p.
EnablePcapAll
(
"tcp-nsc-lfn"
);
134
135
Simulator::Stop
(Seconds (900));
136
Simulator::Run
();
137
Simulator::Destroy
();
138
139
return
0;
140
}
examples
tcp
tcp-nsc-lfn.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2