A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
red-vs-nlred.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Phani Kiran S V S <phanikiran.harithas@gmail.com>
7 * Nichit Bodhak Goel <nichit93@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 *
10 */
11
12#include "ns3/applications-module.h"
13#include "ns3/core-module.h"
14#include "ns3/internet-module.h"
15#include "ns3/network-module.h"
16#include "ns3/point-to-point-layout-module.h"
17#include "ns3/point-to-point-module.h"
18#include "ns3/traffic-control-module.h"
19
20#include <iomanip>
21#include <iostream>
22#include <map>
23
24using namespace ns3;
25
26int
27main(int argc, char* argv[])
28{
29 uint32_t nLeaf = 10;
30 uint32_t maxPackets = 100;
31 bool modeBytes = false;
32 uint32_t queueDiscLimitPackets = 1000;
33 double minTh = 5;
34 double maxTh = 15;
35 uint32_t pktSize = 512;
36 std::string appDataRate = "10Mbps";
37 std::string queueDiscType = "RED";
38 uint16_t port = 5001;
39 std::string bottleNeckLinkBw = "1Mbps";
40 std::string bottleNeckLinkDelay = "50ms";
41
42 CommandLine cmd(__FILE__);
43 cmd.AddValue("nLeaf", "Number of left and right side leaf nodes", nLeaf);
44 cmd.AddValue("maxPackets", "Max Packets allowed in the device queue", maxPackets);
45 cmd.AddValue("queueDiscLimitPackets",
46 "Max Packets allowed in the queue disc",
47 queueDiscLimitPackets);
48 cmd.AddValue("queueDiscType", "Set Queue disc type to RED or NLRED", queueDiscType);
49 cmd.AddValue("appPktSize", "Set OnOff App Packet Size", pktSize);
50 cmd.AddValue("appDataRate", "Set OnOff App DataRate", appDataRate);
51 cmd.AddValue("modeBytes", "Set Queue disc mode to Packets (false) or bytes (true)", modeBytes);
52
53 cmd.AddValue("redMinTh", "RED queue minimum threshold", minTh);
54 cmd.AddValue("redMaxTh", "RED queue maximum threshold", maxTh);
55 cmd.Parse(argc, argv);
56
57 if ((queueDiscType != "RED") && (queueDiscType != "NLRED"))
58 {
59 std::cout << "Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=NLRED"
60 << std::endl;
61 exit(1);
62 }
63
64 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(pktSize));
65 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(appDataRate));
66
67 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize",
68 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, maxPackets)));
69
70 if (!modeBytes)
71 {
73 "ns3::RedQueueDisc::MaxSize",
74 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, queueDiscLimitPackets)));
75 }
76 else
77 {
79 "ns3::RedQueueDisc::MaxSize",
80 QueueSizeValue(QueueSize(QueueSizeUnit::BYTES, queueDiscLimitPackets * pktSize)));
81 minTh *= pktSize;
82 maxTh *= pktSize;
83 }
84
85 Config::SetDefault("ns3::RedQueueDisc::MinTh", DoubleValue(minTh));
86 Config::SetDefault("ns3::RedQueueDisc::MaxTh", DoubleValue(maxTh));
87 Config::SetDefault("ns3::RedQueueDisc::LinkBandwidth", StringValue(bottleNeckLinkBw));
88 Config::SetDefault("ns3::RedQueueDisc::LinkDelay", StringValue(bottleNeckLinkDelay));
89 Config::SetDefault("ns3::RedQueueDisc::MeanPktSize", UintegerValue(pktSize));
90
91 if (queueDiscType == "NLRED")
92 {
93 // Turn on NLRED
94 Config::SetDefault("ns3::RedQueueDisc::NLRED", BooleanValue(true));
95 }
96
97 // Create the point-to-point link helpers
98 PointToPointHelper bottleNeckLink;
99 bottleNeckLink.SetDeviceAttribute("DataRate", StringValue(bottleNeckLinkBw));
100 bottleNeckLink.SetChannelAttribute("Delay", StringValue(bottleNeckLinkDelay));
101
102 PointToPointHelper pointToPointLeaf;
103 pointToPointLeaf.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
104 pointToPointLeaf.SetChannelAttribute("Delay", StringValue("1ms"));
105
106 PointToPointDumbbellHelper d(nLeaf, pointToPointLeaf, nLeaf, pointToPointLeaf, 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 stack.Install(d.GetLeft());
120 stack.Install(d.GetRight());
121 TrafficControlHelper tchBottleneck;
122 QueueDiscContainer queueDiscs;
123 tchBottleneck.SetRootQueueDisc("ns3::RedQueueDisc");
124 tchBottleneck.Install(d.GetLeft()->GetDevice(0));
125 queueDiscs = tchBottleneck.Install(d.GetRight()->GetDevice(0));
126
127 // Assign IP Addresses
128 d.AssignIpv4Addresses(Ipv4AddressHelper("10.1.1.0", "255.255.255.0"),
129 Ipv4AddressHelper("10.2.1.0", "255.255.255.0"),
130 Ipv4AddressHelper("10.3.1.0", "255.255.255.0"));
131
132 // Install on/off app on all right side nodes
133 OnOffHelper clientHelper("ns3::TcpSocketFactory", Address());
134 clientHelper.SetAttribute("OnTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
135 clientHelper.SetAttribute("OffTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
137 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", sinkLocalAddress);
138 ApplicationContainer sinkApps;
139 for (uint32_t i = 0; i < d.LeftCount(); ++i)
140 {
141 sinkApps.Add(packetSinkHelper.Install(d.GetLeft(i)));
142 }
143 sinkApps.Start(Seconds(0.0));
144 sinkApps.Stop(Seconds(30.0));
145
147 for (uint32_t i = 0; i < d.RightCount(); ++i)
148 {
149 // Create an on/off app sending packets to the left side
150 AddressValue remoteAddress(InetSocketAddress(d.GetLeftIpv4Address(i), port));
151 clientHelper.SetAttribute("Remote", remoteAddress);
152 clientApps.Add(clientHelper.Install(d.GetRight(i)));
153 }
154 clientApps.Start(Seconds(1.0)); // Start 1 second after sink
155 clientApps.Stop(Seconds(15.0)); // Stop before the sink
156
158
159 std::cout << "Running the simulation" << std::endl;
161
162 QueueDisc::Stats st = queueDiscs.Get(0)->GetStats();
163
165 {
166 std::cout << "There should be some unforced drops" << std::endl;
167 exit(1);
168 }
169
171 {
172 std::cout << "There should be zero drops due to queue full" << std::endl;
173 exit(1);
174 }
175
176 std::cout << "*** Stats from the bottleneck queue disc ***" << std::endl;
177 std::cout << st << std::endl;
178 std::cout << "Destroying the simulation" << std::endl;
179
181 return 0;
182}
a polymophic address class
Definition address.h:90
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
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.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
A helper to make it easier to instantiate an ns3::OnOffApplication on a set of nodes.
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.
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition queue-disc.h:511
const Stats & GetStats()
Retrieve all the collected statistics.
Class for representing queue sizes.
Definition queue-size.h:85
static constexpr const char * UNFORCED_DROP
Early probability drops.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
Hold variables of type string.
Definition string.h:45
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:34
uint16_t port
Definition dsdv-manet.cc:33
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
clientApps
Definition first.py:53
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure that keeps the queue disc statistics.
Definition queue-disc.h:177
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
uint32_t pktSize
packet size used for the simulation (in bytes)