A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
droptail_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  *
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 using namespace std;
34 
35 
36 int main (int argc, char *argv[])
37 {
38  uint32_t nLeaf = 5;
39  uint32_t maxPackets = 100;
40  uint32_t modeBytes = 0;
41  double minTh = 50;
42  double maxTh = 80;
43  uint32_t pktSize = 512;
44  std::string appDataRate = "10Mbps";
45  std::string queueType = "DropTail";
46  uint16_t port = 5001;
47  std::string bottleNeckLinkBw = "1Mbps";
48  std::string bottleNeckLinkDelay = "50ms";
49 
50  CommandLine cmd;
51  cmd.AddValue ("nLeaf", "Number of left and right side leaf nodes", nLeaf);
52  cmd.AddValue ("maxPackets","Max Packets allowed in the queue", maxPackets);
53  cmd.AddValue ("queueType", "Set Queue type to DropTail or RED", queueType);
54  cmd.AddValue ("appPktSize", "Set OnOff App Packet Size", pktSize);
55  cmd.AddValue ("appDataRate", "Set OnOff App DataRate", appDataRate);
56  cmd.AddValue ("modeBytes", "Set Queue mode to Packets <0> or bytes <1>", modeBytes);
57 
58  cmd.AddValue ("redMinTh", "RED queue minimum threshold", minTh);
59  cmd.AddValue ("redMaxTh", "RED queue maximum threshold", maxTh);
60  cmd.Parse (argc,argv);
61 
62  if ((queueType != "RED") && (queueType != "DropTail"))
63  {
64  NS_ABORT_MSG ("Invalid queue type: Use --queueType=RED or --queueType=DropTail");
65  }
66 
67  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (pktSize));
68  Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue (appDataRate));
69 
70 
71  if (!modeBytes)
72  {
73  Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("Packets"));
74  Config::SetDefault ("ns3::DropTailQueue::MaxPackets", UintegerValue (maxPackets));
75  Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("Packets"));
76  Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets));
77  }
78  else
79  {
80  Config::SetDefault ("ns3::DropTailQueue::Mode", StringValue ("Bytes"));
81  Config::SetDefault ("ns3::DropTailQueue::MaxBytes", UintegerValue (maxPackets * pktSize));
82  Config::SetDefault ("ns3::RedQueue::Mode", StringValue ("Bytes"));
83  Config::SetDefault ("ns3::RedQueue::QueueLimit", UintegerValue (maxPackets * pktSize));
84  minTh *= pktSize;
85  maxTh *= pktSize;
86  }
87 
88  // Create the point-to-point link helpers
89  PointToPointHelper bottleNeckLink;
90  bottleNeckLink.SetDeviceAttribute ("DataRate", StringValue (bottleNeckLinkBw));
91  bottleNeckLink.SetChannelAttribute ("Delay", StringValue (bottleNeckLinkDelay));
92  if (queueType == "RED")
93  {
94  bottleNeckLink.SetQueue ("ns3::RedQueue",
95  "MinTh", DoubleValue (minTh),
96  "MaxTh", DoubleValue (maxTh),
97  "LinkBandwidth", StringValue (bottleNeckLinkBw),
98  "LinkDelay", 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
109  InternetStackHelper stack;
110  d.InstallStack (stack);
111 
112  // Assign IP Addresses
113  d.AssignIpv4Addresses (Ipv4AddressHelper ("10.1.1.0", "255.255.255.0"),
114  Ipv4AddressHelper ("10.2.1.0", "255.255.255.0"),
115  Ipv4AddressHelper ("10.3.1.0", "255.255.255.0"));
116 
117  // Install on/off app on all right side nodes
118  OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
119  clientHelper.SetAttribute ("OnTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
120  clientHelper.SetAttribute ("OffTime", StringValue ("ns3::UniformRandomVariable[Min=0.,Max=1.]"));
121  Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
122  PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
123  ApplicationContainer sinkApps;
124  for (uint32_t i = 0; i < d.LeftCount (); ++i)
125  {
126  sinkApps.Add (packetSinkHelper.Install (d.GetLeft (i)));
127  }
128  sinkApps.Start (Seconds (0.0));
129  sinkApps.Stop (Seconds (30.0));
130 
131  ApplicationContainer clientApps;
132  for (uint32_t i = 0; i < d.RightCount (); ++i)
133  {
134  // Create an on/off app sending packets to the left side
135  AddressValue remoteAddress (InetSocketAddress (d.GetLeftIpv4Address (i), port));
136  clientHelper.SetAttribute ("Remote", remoteAddress);
137  clientApps.Add (clientHelper.Install (d.GetRight (i)));
138  }
139  clientApps.Start (Seconds (1.0)); // Start 1 second after sink
140  clientApps.Stop (Seconds (15.0)); // Stop before the sink
141 
143 
144  std::cout << "Running the simulation" << std::endl;
145  Simulator::Run ();
146 
147  uint32_t totalRxBytesCounter = 0;
148  for (uint32_t i = 0; i < sinkApps.GetN (); i++)
149  {
150  Ptr <Application> app = sinkApps.Get (i);
151  Ptr <PacketSink> pktSink = DynamicCast <PacketSink> (app);
152  totalRxBytesCounter += pktSink->GetTotalRx ();
153  }
154  NS_LOG_UNCOND ("----------------------------\nQueue Type:"
155  << queueType
156  << "\nGoodput Bytes/sec:"
157  << totalRxBytesCounter/Simulator::Now ().GetSeconds ());
158  NS_LOG_UNCOND ("----------------------------");
159 
160 
161  std::cout << "Destroying the simulation" << std::endl;
163  return 0;
164 }