A Discrete-Event Network Simulator
API
 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 
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 
94  pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
95  pointToPoint.SetChannelAttribute ("Delay", StringValue ("1ns"));
96 
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),
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);
138 
140 
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 
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 
179  return 0;
180 }
holds a vector of ns3::Application pointers.
tuple pointToPoint
Definition: first.py:28
an Inet address class
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
int main(int argc, char *argv[])
Hold a bool native type.
Definition: boolean.h:38
holds a vector of std::pair of Ptr 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:18
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
bool enablePcap
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:662
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:42
double stopTime
tuple nodes
Definition: first.py:25
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
hold variables of type 'enum'
Definition: enum.h:37
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
double startTime
tuple interfaces
Definition: first.py:40
holds a vector of ns3::NetDevice pointers
static void Bind(std::string name, const AttributeValue &value)
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:177
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
hold objects of type Ptr
Definition: pointer.h:33
int m_seed
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
uint32_t GetTotalRx() const
Definition: packet-sink.cc:72
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
hold objects of type ns3::Address
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:435
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
void Parse(int argc, char *argv[])
Parse the program arguments.
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.
tuple address
Definition: first.py:37
Receive and consume traffic generated to an IP address and port.
Definition: packet-sink.h:68
Hold a floating point type.
Definition: double.h:41
std::string sock_factory
std::string m_stack
Ptr< T > GetObject(void) const
Definition: object.h:362
ApplicationContainer Install(NodeContainer c) const
Install an ns3::OnOffApplication on each node of the input container configured with all the attribut...
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
uint32_t m_nNodes