A Discrete-Event Network Simulator
API
red-vs-fengadaptive.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sourabh Jain <sourabhjain560@outlook.com>
18 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
19 */
20
21#include "ns3/applications-module.h"
22#include "ns3/core-module.h"
23#include "ns3/internet-module.h"
24#include "ns3/network-module.h"
25#include "ns3/point-to-point-layout-module.h"
26#include "ns3/point-to-point-module.h"
27#include "ns3/traffic-control-module.h"
28
29#include <iomanip>
30#include <iostream>
31#include <map>
32
33using namespace ns3;
34
35int
36main(int argc, char* argv[])
37{
38 uint32_t nLeaf = 10;
39 uint32_t maxPackets = 100;
40 bool modeBytes = false;
41 uint32_t queueDiscLimitPackets = 1000;
42 double minTh = 5;
43 double maxTh = 15;
44 uint32_t pktSize = 512;
45 std::string appDataRate = "10Mbps";
46 std::string queueDiscType = "RED";
47 uint16_t port = 5001;
48 std::string bottleNeckLinkBw = "1Mbps";
49 std::string bottleNeckLinkDelay = "50ms";
50
51 CommandLine cmd(__FILE__);
52 cmd.AddValue("nLeaf", "Number of left and right side leaf nodes", nLeaf);
53 cmd.AddValue("maxPackets", "Max Packets allowed in the device queue", maxPackets);
54 cmd.AddValue("queueDiscLimitPackets",
55 "Max Packets allowed in the queue disc",
56 queueDiscLimitPackets);
57 cmd.AddValue("queueDiscType", "Set Queue disc type to RED or FengAdaptive", queueDiscType);
58 cmd.AddValue("appPktSize", "Set OnOff App Packet Size", pktSize);
59 cmd.AddValue("appDataRate", "Set OnOff App DataRate", appDataRate);
60 cmd.AddValue("modeBytes", "Set Queue disc mode to Packets (false) or bytes (true)", modeBytes);
61
62 cmd.AddValue("redMinTh", "RED queue minimum threshold", minTh);
63 cmd.AddValue("redMaxTh", "RED queue maximum threshold", maxTh);
64 cmd.Parse(argc, argv);
65
66 if ((queueDiscType != "RED") && (queueDiscType != "FengAdaptive"))
67 {
68 std::cout
69 << "Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=FengAdaptive"
70 << std::endl;
71 exit(1);
72 }
73
74 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(pktSize));
75 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(appDataRate));
76
77 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize",
79
80 if (!modeBytes)
81 {
83 "ns3::RedQueueDisc::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 Config::SetDefault("ns3::RedQueueDisc::MeanPktSize", UintegerValue(pktSize));
100
101 if (queueDiscType == "FengAdaptive")
102 {
103 // Turn on Feng's Adaptive RED
104 Config::SetDefault("ns3::RedQueueDisc::FengAdaptive", BooleanValue(true));
105 }
106
107 // Create the point-to-point link helpers
108 PointToPointHelper bottleNeckLink;
109 bottleNeckLink.SetDeviceAttribute("DataRate", StringValue(bottleNeckLinkBw));
110 bottleNeckLink.SetChannelAttribute("Delay", StringValue(bottleNeckLinkDelay));
111
112 PointToPointHelper pointToPointLeaf;
113 pointToPointLeaf.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
114 pointToPointLeaf.SetChannelAttribute("Delay", StringValue("1ms"));
115
116 PointToPointDumbbellHelper d(nLeaf, pointToPointLeaf, nLeaf, pointToPointLeaf, bottleNeckLink);
117
118 // Install Stack
120 for (uint32_t i = 0; i < d.LeftCount(); ++i)
121 {
122 stack.Install(d.GetLeft(i));
123 }
124 for (uint32_t i = 0; i < d.RightCount(); ++i)
125 {
126 stack.Install(d.GetRight(i));
127 }
128
129 stack.Install(d.GetLeft());
130 stack.Install(d.GetRight());
131 TrafficControlHelper tchBottleneck;
132 QueueDiscContainer queueDiscs;
133 tchBottleneck.SetRootQueueDisc("ns3::RedQueueDisc");
134 tchBottleneck.Install(d.GetLeft()->GetDevice(0));
135 queueDiscs = tchBottleneck.Install(d.GetRight()->GetDevice(0));
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 QueueDisc::Stats st = queueDiscs.Get(0)->GetStats();
173
174 if (st.GetNDroppedPackets(RedQueueDisc::UNFORCED_DROP) == 0)
175 {
176 std::cout << "There should be some unforced drops" << std::endl;
177 exit(1);
178 }
179
180 if (st.GetNDroppedPackets(QueueDisc::INTERNAL_QUEUE_DROP) != 0)
181 {
182 std::cout << "There should be zero drops due to queue full" << std::endl;
183 exit(1);
184 }
185
186 std::cout << "*** Stats from the bottleneck queue disc ***" << std::endl;
187 std::cout << st << std::endl;
188 std::cout << "Destroying the simulation" << std::endl;
189
190 Simulator::Destroy();
191 return 0;
192}
a polymophic address class
Definition: address.h:92
AttributeValue implementation for Address.
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
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.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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.
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.
Holds a vector of ns3::QueueDisc pointers.
Ptr< QueueDisc > Get(std::size_t i) const
Get the Ptr<QueueDisc> stored in this container at a given index.
const Stats & GetStats()
Retrieve all the collected statistics.
Definition: queue-disc.cc:416
Class for representing queue sizes.
Definition: queue-size.h:96
AttributeValue implementation for QueueSize.
Hold variables of type string.
Definition: string.h:42
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
@ 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 Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
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
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:188
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:111
uint32_t pktSize
packet size used for the simulation (in bytes)