A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
droptail_vs_red.cc
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  *
18  */
19 
20 
21 #include "ns3/core-module.h"
22 #include "ns3/network-module.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/point-to-point-module.h"
25 #include "ns3/applications-module.h"
26 #include "ns3/point-to-point-layout-module.h"
27 
28 #include <iostream>
29 #include <iomanip>
30 #include <map>
31 
32 using namespace ns3;
33 
34 
35 int main (int argc, char *argv[])
36 {
37  uint32_t nLeaf = 5;
38  uint32_t maxPackets = 100;
39  uint32_t modeBytes = 0;
40  double minTh = 50;
41  double maxTh = 80;
42  uint32_t pktSize = 512;
43  std::string appDataRate = "10Mbps";
44  std::string queueType = "DropTail";
45  uint16_t port = 5001;
46  std::string bottleNeckLinkBw = "1Mbps";
47  std::string bottleNeckLinkDelay = "50ms";
48 
49  CommandLine cmd;
50  cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
51  cmd.AddValue ("maxPackets","Max Packets allowed in the queue", maxPackets);
52  cmd.AddValue ("queueType", "Set Queue type to DropTail or RED", queueType);
53  cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize);
54  cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate);
55  cmd.AddValue ("modeBytes", "Set Queue mode to Packets <0> or bytes <1>", modeBytes);
56 
57  cmd.AddValue ("redMinTh", "RED queue minimum threshold", minTh);
58  cmd.AddValue ("redMaxTh", "RED queue maximum threshold", maxTh);
59  cmd.Parse (argc,argv);
60 
61  if ((queueType != "RED") && (queueType != "DropTail"))
62  {
63  NS_ABORT_MSG ("Invalid queue type: Use --queueType=RED or --queueType=DropTail");
64  }
65 
66  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSize));
67  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRate));
68 
69 
70  if (!modeBytes)
71  {
72  Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
73  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (maxPackets));
74  Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_PACKETS"));
75  Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets));
76  }
77  else
78  {
79  Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("QUEUE_MODE_BYTES"));
80  Config::SetDefault ("ns3::DropTailQueue::MaxBytes", UintegerValue (maxPackets * pktSize));
81  Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("QUEUE_MODE_BYTES"));
82  Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets * pktSize));
83  minTh *= pktSize;
84  maxTh *= pktSize;
85  }
86 
87  // Create the point-to-point link helpers
88  PointToPointHelper bottleNeckLink;
89  bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue (bottleNeckLinkBw));
90  bottleNeckLink.SetChannelAttribute ("Delay", StringValue (bottleNeckLinkDelay));
91  if (queueType == "RED")
92  {
93  bottleNeckLink.SetQueue ("ns3::RedQueue",
94  "MinTh", DoubleValue (minTh),
95  "MaxTh", DoubleValue (maxTh),
96  "LinkBandwidth", StringValue (bottleNeckLinkBw),
97  "LinkDelay", StringValue (bottleNeckLinkDelay));
98  }
99  PointToPointHelper pointToPointLeaf;
100  pointToPointLeaf.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
101  pointToPointLeaf.SetChannelAttribute ("Delay", StringValue ("1ms"));
102 
103  PointToPointDumbbellHelper d (nLeaf, pointToPointLeaf,
104  nLeaf, pointToPointLeaf,
105  bottleNeckLink);
106 
107  // Install Stack
108  InternetStackHelper stack;
109  d.InstallStack (stack);
110 
111  // Assign IP Addresses
112  d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
113  Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
114  Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
115 
116  // Install on/off app on all right side nodes
117  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
118  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
119  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
120  Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
121  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
122  ApplicationContainer sinkApps;
123  for (uint32_t i = 0; i < d.LeftCount (); ++i)
124  {
125  sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i)));
126  }
127  sinkApps.Start (Seconds (0.0));
128  sinkApps.Stop (Seconds (30.0));
129 
130  ApplicationContainer clientApps;
131  for (uint32_t i = 0; i < d.RightCount (); ++i)
132  {
133  // Create an on/off app sending packets to the left side
134  AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), port));
135  clientHelper.SetAttribute ("Remote", remoteAddress);
136  clientApps.Add (clientHelper.Install (d.GetRight (i)));
137  }
138  clientApps.Start (Seconds (1.0)); // Start 1 second after sink
139  clientApps.Stop (Seconds (15.0)); // Stop before the sink
140 
142 
143  std::cout << "Running the simulation" << std::endl;
144  Simulator::Run ();
145 
146  uint32_t totalRxBytesCounter = 0;
147  for (uint32_t i = 0; i < sinkApps.GetN (); i++)
148  {
149  Ptr <Application> app = sinkApps.Get (i);
150  Ptr <PacketSink> pktSink = DynamicCast <PacketSink> (app);
151  totalRxBytesCounter += pktSink->GetTotalRx ();
152  }
153  NS_LOG_UNCOND ("----------------------------\nQueue Type:"
154  << queueType
155  << "\nGoodput Bytes/sec:"
156  << totalRxBytesCounter/Simulator::Now ().GetSeconds ());
157  NS_LOG_UNCOND ("----------------------------");
158 
159 
160  std::cout << "Destroying the simulation" << std::endl;
162  return 0;
163 }
holds a vector of ns3::Application pointers.
an Inet address class
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
static void PopulateRoutingTables(void)
Build a routing database and initialize the routing tables of the nodes in the simulation. Makes all nodes in the simulation into routers.
hold variables of type string
Definition: string.h:19
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
void SetQueue(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue())
static void Run(void)
Definition: simulator.cc:157
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetN(void) const
Get the number of Ptr<Application> 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)
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:41
a polymophic address class
Definition: address.h:86
Hold an unsigned integer type.
Definition: uinteger.h:46
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 argumentsInstances of this class can be used to parse command-line arguments: user...
Definition: command-line.h:50
static void Destroy(void)
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
#define NS_LOG_UNCOND(msg)
Definition: log.h:343
static Time Now(void)
Definition: simulator.cc:179
uint32_t GetTotalRx() const
Definition: packet-sink.cc:72
void SetChannelAttribute(std::string name, const AttributeValue &value)
#define NS_ABORT_MSG(msg)
Abnormal program termination.
Definition: abort.h:43
hold objects of type ns3::Address
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void AddValue(const std::string &name, const std::string &help, T &value)
Definition: command-line.h:134
void Parse(int argc, char *argv[]) const
Definition: command-line.cc:84
A helper to make it easier to create a dumbbell topology with p2p links.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Hold an floating point type.
Definition: double.h:41