A Discrete-Event Network Simulator
API
pfifo-vs-red.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  * Author: John Abraham <john.abraham@gatech.edu>
17  * Modified by: Pasquale Imputato <p.imputato@gmail.com>
18  *
19  */
20 
21 
22 #include "ns3/core-module.h"
23 #include "ns3/network-module.h"
24 #include "ns3/internet-module.h"
25 #include "ns3/point-to-point-module.h"
26 #include "ns3/applications-module.h"
27 #include "ns3/point-to-point-layout-module.h"
28 #include "ns3/traffic-control-module.h"
29 
30 #include <iostream>
31 #include <iomanip>
32 #include <map>
33 
34 using namespace ns3;
35 
36 
37 int main (int argc, char *argv[])
38 {
39  uint32_t nLeaf = 5;
40  uint32_t maxPackets = 100;
41  uint32_t modeBytes = 0;
42  uint32_t queueDiscLimitPackets = 1000;
43  double minTh = 50;
44  double maxTh = 80;
45  uint32_t pktSize = 512;
46  std::string appDataRate = "10Mbps";
47  std::string queueDiscType = "PfifoFast";
48  uint16_t port = 5001;
49  std::string bottleNeckLinkBw = "1Mbps";
50  std::string bottleNeckLinkDelay = "50ms";
51 
53  cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
54  cmd.AddValue ("maxPackets","Max Packets allowed in the device queue", maxPackets);
55  cmd.AddValue ("queueDiscLimitPackets","Max Packets allowed in the queue disc", queueDiscLimitPackets);
56  cmd.AddValue ("queueDiscType", "Set QueueDisc type to PfifoFast or RED", queueDiscType);
57  cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize);
58  cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate);
59  cmd.AddValue ("modeBytes", "Set QueueDisc mode to Packets <0> or bytes <1>", modeBytes);
60 
61  cmd.AddValue ("redMinTh", "RED queue minimum threshold", minTh);
62  cmd.AddValue ("redMaxTh", "RED queue maximum threshold", maxTh);
63  cmd.Parse (argc,argv);
64 
65  if ((queueDiscType != "RED") && (queueDiscType != "PfifoFast"))
66  {
67  NS_ABORT_MSG ("Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=PfifoFast");
68  }
69 
70  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSize));
71  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRate));
72 
73  Config::SetDefault ("ns3::Queue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
74  Config::SetDefault ("ns3::Queue::MaxPackets", UintegerValue (maxPackets));
75 
76  if (!modeBytes)
77  {
78  Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_PACKETS"));
79  Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueDiscLimitPackets));
80  Config::SetDefault ("ns3::PfifoFastQueueDisc::Limit", UintegerValue (queueDiscLimitPackets));
81  }
82  else
83  {
84  Config::SetDefault ("ns3::RedQueueDisc::Mode", StringValue ("QUEUE_MODE_BYTES"));
85  Config::SetDefault ("ns3::RedQueueDisc::QueueLimit", UintegerValue (queueDiscLimitPackets * pktSize));
86  minTh *= pktSize;
87  maxTh *= pktSize;
88  }
89 
90  Config::SetDefault ("ns3::RedQueueDisc::MinTh", DoubleValue (minTh));
91  Config::SetDefault ("ns3::RedQueueDisc::MaxTh", DoubleValue (maxTh));
92  Config::SetDefault ("ns3::RedQueueDisc::LinkBandwidth", StringValue (bottleNeckLinkBw));
93  Config::SetDefault ("ns3::RedQueueDisc::LinkDelay", StringValue (bottleNeckLinkDelay));
94 
95  // Create the point-to-point link helpers
96  PointToPointHelper bottleNeckLink;
97  bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue (bottleNeckLinkBw));
98  bottleNeckLink.SetChannelAttribute ("Delay", StringValue (bottleNeckLinkDelay));
99 
100  PointToPointHelper pointToPointLeaf;
101  pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
102  pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
103 
104  PointToPointDumbbellHelper d (nLeaf, pointToPointLeaf,
105  nLeaf, pointToPointLeaf,
106  bottleNeckLink);
107 
108  // Install Stack
110  for (uint32_t i = 0; i < d.LeftCount (); ++i)
111  {
112  stack.Install (d.GetLeft (i));
113  }
114  for (uint32_t i = 0; i < d.RightCount (); ++i)
115  {
116  stack.Install (d.GetRight (i));
117  }
118 
119  if (queueDiscType == "PfifoFast")
120  {
121  stack.Install (d.GetLeft ());
122  stack.Install (d.GetRight ());
123  }
124  else if (queueDiscType == "RED")
125  {
126  stack.Install (d.GetLeft ());
127  stack.Install (d.GetRight ());
128  TrafficControlHelper tchBottleneck;
129  tchBottleneck.SetRootQueueDisc ("ns3::RedQueueDisc");
130  tchBottleneck.Install (d.GetLeft ()->GetDevice (0));
131  tchBottleneck.Install (d.GetRight ()->GetDevice (0));
132  }
133 
134  // Assign IP Addresses
135  d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
136  Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
137  Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
138 
139  // Install on/off app on all right side nodes
140  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
141  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
142  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
143  Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
144  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
145  ApplicationContainer sinkApps;
146  for (uint32_t i = 0; i < d.LeftCount (); ++i)
147  {
148  sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i)));
149  }
150  sinkApps.Start (Seconds (0.0));
151  sinkApps.Stop (Seconds (30.0));
152 
154  for (uint32_t i = 0; i < d.RightCount (); ++i)
155  {
156  // Create an on/off app sending packets to the left side
157  AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), port));
158  clientHelper.SetAttribute ("Remote", remoteAddress);
159  clientApps.Add (clientHelper.Install (d.GetRight (i)));
160  }
161  clientApps.Start (Seconds (1.0)); // Start 1 second after sink
162  clientApps.Stop (Seconds (15.0)); // Stop before the sink
163 
165 
166  std::cout << "Running the simulation" << std::endl;
167  Simulator::Run ();
168 
169  uint32_t totalRxBytesCounter = 0;
170  for (uint32_t i = 0; i < sinkApps.GetN (); i++)
171  {
172  Ptr <Application> app = sinkApps.Get (i);
173  Ptr <PacketSink> pktSink = DynamicCast <PacketSink> (app);
174  totalRxBytesCounter += pktSink->GetTotalRx ();
175  }
176  NS_LOG_UNCOND ("----------------------------\nQueueDisc Type:"
177  << queueDiscType
178  << "\nGoodput Bytes/sec:"
179  << totalRxBytesCounter/Simulator::Now ().GetSeconds ());
180  NS_LOG_UNCOND ("----------------------------");
181 
182 
183  std::cout << "Destroying the simulation" << std::endl;
185  return 0;
186 }
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
QueueDiscContainer Install(NetDeviceContainer c)
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
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 Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
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
tuple cmd
Definition: second.py:35
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
tuple clientApps
Definition: first.py:54
Hold an unsigned integer type.
Definition: uinteger.h:44
Build a set of QueueDisc objects.
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:205
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Application > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
uint16_t SetRootQueueDisc(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to set a root queue disc of the given type and with the given attributes...
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionaly.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
tuple stack
Definition: first.py:34
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
AttributeValue implementation for Address.
Definition: address.h:278
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
void AddValue(const std::string &name, const std::string &help, T &value)
Add a program argument, assigning to POD.
Definition: command-line.h:495
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
A helper to make it easier to create a dumbbell topology with p2p links.
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.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
uint64_t GetTotalRx() const
Definition: packet-sink.cc:78