A Discrete-Event Network Simulator
API
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  * By default, TCP timestamps, window scale, and SACK are disabled because
25  * they were not supported in ns-3 at the time of this paper. TCP timestamp
26  * and window scale can be enabled by command line arguments.
27  *
28  */
29 
30 #include "ns3/log.h"
31 #include "ns3/core-module.h"
32 #include "ns3/network-module.h"
33 #include "ns3/internet-module.h"
34 #include "ns3/point-to-point-module.h"
35 #include "ns3/applications-module.h"
36 #include "ns3/flow-monitor-module.h"
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("TcpNscComparison");
41 
42 std::string m_stack = "nsc-linux";
43 std::string sock_factory;
44 uint32_t m_seed = 1;
45 double startTime = 4.0;
46 double stopTime = 20.0;
47 uint32_t m_nNodes = 2;
48 bool enablePcap = false;
49 bool enableTimestamps = false;
50 bool enableWindowScale = false;
51 
52 int
53 main (int argc, char *argv[])
54 {
55 
56  //ensure the ns3 TCP default values match what nsc is using
57  Config::SetDefault ("ns3::TcpSocket::SegmentSize", UintegerValue (1448));
58  Config::SetDefault ("ns3::TcpSocket::DelAckCount", UintegerValue (1));
59 
61  cmd.AddValue ("stack", "choose network stack", m_stack);
62  cmd.AddValue ("seed", "randomize seed", m_seed);
63  cmd.AddValue ("nNodes", "the number of source and sink nodes", m_nNodes);
64  cmd.AddValue ("stopTime", "duration", stopTime);
65  cmd.AddValue ("enablePcap", "pcap", enablePcap);
66  cmd.AddValue ("enableTimestamps", "use TCP Timestamps option", enableTimestamps);
67  cmd.AddValue ("enableWindowScale", "use TCP Window Scale option", enableWindowScale);
68  cmd.Parse (argc, argv);
69 
71 
72  if (m_stack != "nsc-linux" && m_stack != "ns3")
73  {
74  NS_FATAL_ERROR ("Error, stack named " << m_stack << " is not supported");
75  }
76 
77  NodeContainer lefts, routers, rights, nodes;
78  lefts.Create (m_nNodes);
79  routers.Create (2);
80  rights.Create (m_nNodes);
81  nodes = NodeContainer (lefts, routers, rights);
82 
83  InternetStackHelper internetStack;
84 
85  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
86  if (m_stack == "ns3")
87  {
88  sock_factory = "ns3::TcpSocketFactory";
89  if (enableTimestamps == false)
90  {
91  Config::SetDefault ("ns3::TcpSocketBase::WindowScaling", BooleanValue (false));
92  }
93  if (enableWindowScale == false)
94  {
95  Config::SetDefault ("ns3::TcpSocketBase::Timestamp", BooleanValue (false));
96  }
97  internetStack.Install (nodes);
98  }
99  else if (m_stack == "nsc-linux")
100  {
101  internetStack.Install (routers);
102  sock_factory = "ns3::TcpSocketFactory";
103  internetStack.SetTcp ("ns3::NscTcpL4Protocol",
104  "Library", StringValue ("liblinux2.6.26.so"));
105  internetStack.Install (lefts);
106  internetStack.Install (rights);
107 
108  // at the time this program was written, these were not implemented
109  // in ns3 tcp, so disable for comparison
110  Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_sack", StringValue ("0"));
111  if (enableTimestamps == false)
112  {
113  Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_timestamps", StringValue ("0"));
114  }
115  if (enableWindowScale == false)
116  {
117  Config::Set ("/NodeList/*/$ns3::Ns3NscStack<linux2.6.26>/net.ipv4.tcp_window_scaling", StringValue ("0"));
118  }
119  }
120 
122  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
123  pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ns"));
124 
127 
128  NetDeviceContainer dev0, dev1, dev2;
129  for (uint32_t i = 0; i < m_nNodes; i++)
130  {
131  std::ostringstream oss;
132  oss << "10.0." << i << ".0";
133  address.SetBase (oss.str ().c_str (), "255.255.255.0");
134  dev0 = pointToPoint.Install (NodeContainer (lefts.Get (i), routers.Get (0)));
135  address.Assign (dev0);
136  }
137 
138  // bottle neck link
139  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("2Mbps"));
140  pointToPoint.SetChannelAttribute ("Delay", StringValue ("100ms"));
141  dev1 = pointToPoint.Install (NodeContainer (routers.Get (0), routers.Get (1)));
142 
143  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
144  pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ns"));
145  // for right links
146  for (uint32_t i = 0; i < m_nNodes; i++)
147  {
148  std::ostringstream oss;
149  oss << "10.2." << i << ".0";
150  address.SetBase (oss.str ().c_str (), "255.255.255.0");
151  dev2 = pointToPoint.Install (NodeContainer (routers.Get (1), rights.Get (i)));
152  address.Assign (dev2);
153  }
154 
155  // bottle neck link
156  Ptr<RateErrorModel> em1 =
157  CreateObjectWithAttributes<RateErrorModel> (
158  "ErrorRate", DoubleValue (0.05),
160  );
161  dev1.Get (1)->SetAttribute ("ReceiveErrorModel", PointerValue (em1));
162 
163  address.SetBase ("10.1.0.0", "255.255.255.0");
164  address.Assign (dev1);
166 
168 
170  InetSocketAddress (Ipv4Address ("10.2.0.2"), 2000));
171  onoff.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
172  onoff.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
173 
174  // Flow 1 - n
175  for (uint32_t i = 0; i < m_nNodes; i++)
176  {
177  std::ostringstream oss;
178  oss << "10.2." << i << ".2";
179  onoff.SetAttribute ("Remote", AddressValue (InetSocketAddress (Ipv4Address (oss.str ().c_str ()), 2000)));
180  onoff.SetAttribute ("PacketSize", StringValue ("1024"));
181  onoff.SetAttribute ("DataRate", StringValue ("1Mbps"));
182  onoff.SetAttribute ("StartTime", TimeValue (Seconds (startTime)));
183  apps = onoff.Install (lefts.Get (i));
184  }
185 
188  apps = sink.Install (rights);
189  apps.Start (Seconds (3.9999));
190 
191  if (enablePcap)
192  {
193  pointToPoint.EnablePcapAll ("nsc.pcap");
194  }
195 
197  Simulator::Run ();
198 
199  Ptr<PacketSink> pktsink;
200  std::cout << "Total ";
201  for (uint32_t i = 0; i < m_nNodes; i++)
202  {
203  pktsink = apps.Get (i)->GetObject<PacketSink> ();
204  std::cout << "Rx(" << i << ") = " << pktsink->GetTotalRx () <<
205  " bytes (" << pktsink->GetTotalRx () * 8 / (stopTime - startTime) << " bps), ";
206  }
207  std::cout << std::endl;
208 
210  return 0;
211 }
Ptr< PacketSink > sink
Definition: wifi-tcp.cc:56
holds a vector of ns3::Application pointers.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
an Inet address class
static Ipv4Address GetAny(void)
AttributeValue implementation for Boolean.
Definition: boolean.h:36
holds a vector of std::pair of Ptr<Ipv4> and interface index.
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation.
Hold variables of type string.
Definition: string.h:41
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:777
bool enablePcap
uint64_t GetTotalRx() const
Definition: packet-sink.cc:81
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
cmd
Definition: second.py:35
Build a set of PointToPointNetDevice objects.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
double stopTime
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
nodes
Definition: first.py:25
Hold variables of type enum.
Definition: enum.h:54
AttributeValue implementation for Time.
Definition: nstime.h:1076
Hold an unsigned integer type.
Definition: uinteger.h:44
double startTime
pointToPoint
Definition: first.py:28
holds a vector of ns3::NetDevice pointers
bool enableWindowScale
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
address
Definition: first.py:37
uint32_t m_seed
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter.
static void SetSeed(uint32_t seed)
Set the seed.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
AttributeValue implementation for Address.
Definition: address.h:278
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
interfaces
Definition: first.py:41
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Receive and consume traffic generated to an IP address and port.
Definition: packet-sink.h:68
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
bool enableTimestamps
std::string sock_factory
std::string m_stack
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
uint32_t m_nNodes