A Discrete-Event Network Simulator
API
pfifo-vs-red.cc
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation;
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 *
15 * Author: John Abraham <john.abraham@gatech.edu>
16 * Modified by: Pasquale Imputato <p.imputato@gmail.com>
17 *
18 */
19
20#include "ns3/applications-module.h"
21#include "ns3/core-module.h"
22#include "ns3/internet-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-layout-module.h"
25#include "ns3/point-to-point-module.h"
26#include "ns3/traffic-control-module.h"
27
28#include <iomanip>
29#include <iostream>
30#include <map>
31
32using namespace ns3;
33
34int
35main(int argc, char* argv[])
36{
37 uint32_t nLeaf = 5;
38 uint32_t maxPackets = 100;
39 uint32_t modeBytes = 0;
40 uint32_t queueDiscLimitPackets = 1000;
41 double minTh = 50;
42 double maxTh = 80;
43 uint32_t pktSize = 512;
44 std::string appDataRate = "10Mbps";
45 std::string queueDiscType = "PfifoFast";
46 uint16_t port = 5001;
47 std::string bottleNeckLinkBw = "1Mbps";
48 std::string bottleNeckLinkDelay = "50ms";
49
50 CommandLine cmd(__FILE__);
51 cmd.AddValue("nLeaf", "Number of left and right side leaf nodes", nLeaf);
52 cmd.AddValue("maxPackets", "Max Packets allowed in the device queue", maxPackets);
53 cmd.AddValue("queueDiscLimitPackets",
54 "Max Packets allowed in the queue disc",
55 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 {
68 "Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=PfifoFast");
69 }
70
71 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(pktSize));
72 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(appDataRate));
73
74 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize",
76
77 if (!modeBytes)
78 {
80 "ns3::RedQueueDisc::MaxSize",
81 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, queueDiscLimitPackets)));
83 "ns3::PfifoFastQueueDisc::MaxSize",
84 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, queueDiscLimitPackets)));
85 }
86 else
87 {
89 "ns3::RedQueueDisc::MaxSize",
90 QueueSizeValue(QueueSize(QueueSizeUnit::BYTES, queueDiscLimitPackets * pktSize)));
91 minTh *= pktSize;
92 maxTh *= pktSize;
93 }
94
95 Config::SetDefault("ns3::RedQueueDisc::MinTh", DoubleValue(minTh));
96 Config::SetDefault("ns3::RedQueueDisc::MaxTh", DoubleValue(maxTh));
97 Config::SetDefault("ns3::RedQueueDisc::LinkBandwidth", StringValue(bottleNeckLinkBw));
98 Config::SetDefault("ns3::RedQueueDisc::LinkDelay", StringValue(bottleNeckLinkDelay));
99
100 // Create the point-to-point link helpers
101 PointToPointHelper bottleNeckLink;
102 bottleNeckLink.SetDeviceAttribute("DataRate", StringValue(bottleNeckLinkBw));
103 bottleNeckLink.SetChannelAttribute("Delay", StringValue(bottleNeckLinkDelay));
104
105 PointToPointHelper pointToPointLeaf;
106 pointToPointLeaf.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
107 pointToPointLeaf.SetChannelAttribute("Delay", StringValue("1ms"));
108
109 PointToPointDumbbellHelper d(nLeaf, pointToPointLeaf, nLeaf, pointToPointLeaf, bottleNeckLink);
110
111 // Install Stack
113 for (uint32_t i = 0; i < d.LeftCount(); ++i)
114 {
115 stack.Install(d.GetLeft(i));
116 }
117 for (uint32_t i = 0; i < d.RightCount(); ++i)
118 {
119 stack.Install(d.GetRight(i));
120 }
121
122 if (queueDiscType == "PfifoFast")
123 {
124 stack.Install(d.GetLeft());
125 stack.Install(d.GetRight());
126 }
127 else if (queueDiscType == "RED")
128 {
129 stack.Install(d.GetLeft());
130 stack.Install(d.GetRight());
131 TrafficControlHelper tchBottleneck;
132 tchBottleneck.SetRootQueueDisc("ns3::RedQueueDisc");
133 tchBottleneck.Install(d.GetLeft()->GetDevice(0));
134 tchBottleneck.Install(d.GetRight()->GetDevice(0));
135 }
136
137 // Assign IP Addresses
138 d.AssignIpv4Addresses(Ipv4AddressHelper("10.1.1.0", "255.255.255.0"),
139 Ipv4AddressHelper("10.2.1.0", "255.255.255.0"),
140 Ipv4AddressHelper("10.3.1.0", "255.255.255.0"));
141
142 // Install on/off app on all right side nodes
143 OnOffHelper clientHelper("ns3::TcpSocketFactory", Address());
144 clientHelper.SetAttribute("OnTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
145 clientHelper.SetAttribute("OffTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
146 Address sinkLocalAddress(InetSocketAddress(Ipv4Address::GetAny(), port));
147 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", sinkLocalAddress);
148 ApplicationContainer sinkApps;
149 for (uint32_t i = 0; i < d.LeftCount(); ++i)
150 {
151 sinkApps.Add(packetSinkHelper.Install(d.GetLeft(i)));
152 }
153 sinkApps.Start(Seconds(0.0));
154 sinkApps.Stop(Seconds(30.0));
155
157 for (uint32_t i = 0; i < d.RightCount(); ++i)
158 {
159 // Create an on/off app sending packets to the left side
160 AddressValue remoteAddress(InetSocketAddress(d.GetLeftIpv4Address(i), port));
161 clientHelper.SetAttribute("Remote", remoteAddress);
162 clientApps.Add(clientHelper.Install(d.GetRight(i)));
163 }
164 clientApps.Start(Seconds(1.0)); // Start 1 second after sink
165 clientApps.Stop(Seconds(15.0)); // Stop before the sink
166
167 Ipv4GlobalRoutingHelper::PopulateRoutingTables();
168
169 std::cout << "Running the simulation" << std::endl;
170 Simulator::Run();
171
172 uint64_t totalRxBytesCounter = 0;
173 for (uint32_t i = 0; i < sinkApps.GetN(); i++)
174 {
175 Ptr<Application> app = sinkApps.Get(i);
176 Ptr<PacketSink> pktSink = DynamicCast<PacketSink>(app);
177 totalRxBytesCounter += pktSink->GetTotalRx();
178 }
179 NS_LOG_UNCOND("----------------------------\nQueueDisc Type:"
180 << queueDiscType
181 << "\nGoodput Bytes/sec:" << totalRxBytesCounter / Simulator::Now().GetSeconds());
182 NS_LOG_UNCOND("----------------------------");
183
184 std::cout << "Destroying the simulation" << std::endl;
185 Simulator::Destroy();
186 return 0;
187}
a polymophic address class
Definition: address.h:100
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Start(Time start)
Start all of the Applications in this container at the start time given as a parameter.
uint32_t GetN() const
Get the number of Ptr<Application> stored in this container.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Parse command-line arguments.
Definition: command-line.h:232
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
an Inet address class
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
Definition: on-off-helper.h:44
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
uint64_t GetTotalRx() const
Definition: packet-sink.cc:96
A helper to make it easier to create a dumbbell topology with p2p links.
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.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Class for representing queue sizes.
Definition: queue-size.h:96
AttributeValue implementation for QueueSize.
Hold variables of type string.
Definition: string.h:56
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
uint16_t SetRootQueueDisc(const std::string &type, Args &&... args)
Helper function used to set a root queue disc of the given type and with the given attributes.
Hold an unsigned integer type.
Definition: uinteger.h:45
uint16_t port
Definition: dsdv-manet.cc:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
@ BYTES
Use number of bytes for queue size.
Definition: queue-size.h:46
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:45
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
clientApps
Definition: first.py:58
stack
Definition: first.py:37
Every class exported by the ns3 library is enclosed in the ns3 namespace.
cmd
Definition: second.py:33
uint32_t pktSize
packet size used for the simulation (in bytes)