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-comparison.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2012 NICT
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Hajime Tazaki <tazaki@nict.go.jp>
19
*
20
* This code is a modified version of the code used for the the experiments in the paper
21
* "DCE Cradle: Simulate Network Protocols with Real Stacks for Better Realism"
22
* by Hajime Tazaki, Frederic Urbani and Thierry Turlett presented at WNS3 2013
23
*
24
*/
25
26
#include "ns3/log.h"
27
#include "ns3/core-module.h"
28
#include "ns3/network-module.h"
29
#include "ns3/internet-module.h"
30
#include "ns3/point-to-point-module.h"
31
#include "ns3/applications-module.h"
32
#include "ns3/flow-monitor-module.h"
33
34
using namespace
ns3;
35
36
NS_LOG_COMPONENT_DEFINE
(
"TcpNscComparison"
);
37
38
std::string
m_stack
=
"nsc-linux"
;
39
std::string
sock_factory
;
40
int
m_seed
= 1;
41
double
startTime
= 4.0;
42
double
stopTime
= 20.0;
43
uint32_t
m_nNodes
= 2;
44
bool
enablePcap
=
false
;
45
46
int
47
main
(
int
argc,
char
*argv[])
48
{
49
50
//ensure the ns3 TCP default values match what nsc is using
51
Config::SetDefault
(
"ns3::TcpSocket::SegmentSize"
,
UintegerValue
(1448));
52
Config::SetDefault
(
"ns3::TcpSocket::DelAckCount"
,
UintegerValue
(1));
53
54
CommandLine
cmd;
55
cmd.
AddValue
(
"stack"
,
"choose network stack"
,
m_stack
);
56
cmd.
AddValue
(
"seed"
,
"randomize seed"
,
m_seed
);
57
cmd.
AddValue
(
"nNodes"
,
"the number of nodes in left side"
,
m_nNodes
);
58
cmd.
AddValue
(
"stopTime"
,
"duration"
,
stopTime
);
59
cmd.
AddValue
(
"enablePcap"
,
"pcap"
,
enablePcap
);
60
cmd.
Parse
(argc, argv);
61
62
SeedManager::SetSeed
(
m_seed
);
63
64
NodeContainer
lefts, routers, rights,
nodes
;
65
lefts.
Create
(
m_nNodes
);
66
routers.
Create
(2);
67
rights.
Create
(
m_nNodes
);
68
nodes =
NodeContainer
(lefts, routers, rights);
69
70
InternetStackHelper
internetStack;
71
72
GlobalValue::Bind
(
"ChecksumEnabled"
,
BooleanValue
(
true
));
73
if
(
m_stack
==
"ns3"
)
74
{
75
sock_factory
=
"ns3::TcpSocketFactory"
;
76
internetStack.
Install
(nodes);
77
}
78
else
if
(
m_stack
==
"nsc-linux"
)
79
{
80
internetStack.
Install
(routers);
81
sock_factory
=
"ns3::TcpSocketFactory"
;
82
internetStack.
SetTcp
(
"ns3::NscTcpL4Protocol"
,
83
"Library"
,
StringValue
(
"liblinux2.6.26.so"
));
84
internetStack.
Install
(lefts);
85
internetStack.
Install
(rights);
86
87
//these are not implemented in ns3 tcp so disable for comparison
88
Config::Set
(
"/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack"
,
StringValue
(
"0"
));
89
Config::Set
(
"/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps"
,
StringValue
(
"0"
));
90
Config::Set
(
"/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling"
,
StringValue
(
"0"
));
91
}
92
93
PointToPointHelper
pointToPoint
;
94
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
95
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"1ns"
));
96
97
Ipv4AddressHelper
address
;
98
Ipv4InterfaceContainer
interfaces
;
99
100
NetDeviceContainer
dev0, dev1, dev2;
101
for
(uint32_t i = 0; i <
m_nNodes
; i++)
102
{
103
std::ostringstream oss;
104
oss <<
"10.0."
<< i <<
".0"
;
105
address.
SetBase
(oss.str ().c_str (),
"255.255.255.0"
);
106
dev0 = pointToPoint.
Install
(
NodeContainer
(lefts.
Get
(i), routers.
Get
(0)));
107
address.
Assign
(dev0);
108
}
109
110
// bottle neck link
111
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"2Mbps"
));
112
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"100ms"
));
113
dev1 = pointToPoint.
Install
(
NodeContainer
(routers.
Get
(0), routers.
Get
(1)));
114
115
pointToPoint.
SetDeviceAttribute
(
"DataRate"
,
StringValue
(
"5Mbps"
));
116
pointToPoint.
SetChannelAttribute
(
"Delay"
,
StringValue
(
"1ns"
));
117
// for right links
118
for
(uint32_t i = 0; i <
m_nNodes
; i++)
119
{
120
std::ostringstream oss;
121
oss <<
"10.2."
<< i <<
".0"
;
122
address.
SetBase
(oss.str ().c_str (),
"255.255.255.0"
);
123
dev2 = pointToPoint.
Install
(
NodeContainer
(routers.
Get
(1), rights.
Get
(i)));
124
address.
Assign
(dev2);
125
}
126
127
// bottle neck link
128
Ptr<RateErrorModel>
em1 =
129
CreateObjectWithAttributes<RateErrorModel> (
130
"ErrorRate"
,
DoubleValue
(0.05),
131
"ErrorUnit"
,
EnumValue
(
RateErrorModel::ERROR_UNIT_PACKET
)
132
);
133
dev1.
Get
(1)->
SetAttribute
(
"ReceiveErrorModel"
,
PointerValue
(em1));
134
135
address.
SetBase
(
"10.1.0.0"
,
"255.255.255.0"
);
136
address.
Assign
(dev1);
137
Ipv4GlobalRoutingHelper::PopulateRoutingTables
();
138
139
ApplicationContainer
apps;
140
141
OnOffHelper
onoff =
OnOffHelper
(
sock_factory
,
142
InetSocketAddress
(
Ipv4Address
(
"10.2.0.2"
), 2000));
143
onoff.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
144
onoff.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
145
146
// Flow 1 - n
147
for
(uint32_t i = 0; i <
m_nNodes
; i++)
148
{
149
std::ostringstream oss;
150
oss <<
"10.2."
<< i <<
".2"
;
151
onoff.
SetAttribute
(
"Remote"
,
AddressValue
(
InetSocketAddress
(
Ipv4Address
(oss.str ().c_str ()), 2000)));
152
onoff.
SetAttribute
(
"PacketSize"
,
StringValue
(
"1024"
));
153
onoff.
SetAttribute
(
"DataRate"
,
StringValue
(
"1Mbps"
));
154
onoff.
SetAttribute
(
"StartTime"
,
TimeValue
(Seconds (
startTime
)));
155
apps = onoff.
Install
(lefts.
Get
(i));
156
}
157
158
PacketSinkHelper
sink =
PacketSinkHelper
(
sock_factory
,
159
InetSocketAddress
(
Ipv4Address::GetAny
(), 2000));
160
apps = sink.
Install
(rights);
161
apps.
Start
(Seconds (3.9999));
162
163
pointToPoint.
EnablePcapAll
(
"nsc.pcap"
);
164
165
Simulator::Stop
(Seconds (
stopTime
));
166
Simulator::Run
();
167
168
Ptr<PacketSink>
pktsink;
169
std::cout <<
"Total "
;
170
for
(uint32_t i = 0; i <
m_nNodes
; i++)
171
{
172
pktsink = apps.
Get
(i)->
GetObject
<
PacketSink
> ();
173
std::cout <<
"Rx("
<< i <<
") = "
<< pktsink->
GetTotalRx
() <<
174
" bytes ("
<< pktsink->
GetTotalRx
() * 8 / (
stopTime
-
startTime
) <<
" bps), "
;
175
}
176
std::cout << std::endl;
177
178
Simulator::Destroy
();
179
return
0;
180
}
examples
tcp
tcp-nsc-comparison.cc
Generated on Fri Aug 30 2013 01:42:44 for ns-3 by
1.8.1.2