A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
pfifo-vs-red.cc
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: GPL-2.0-only
3 *
4 * Author: John Abraham <john.abraham@gatech.edu>
5 * Modified by: Pasquale Imputato <p.imputato@gmail.com>
6 *
7 */
8
9#include "ns3/applications-module.h"
10#include "ns3/core-module.h"
11#include "ns3/internet-module.h"
12#include "ns3/network-module.h"
13#include "ns3/point-to-point-layout-module.h"
14#include "ns3/point-to-point-module.h"
15#include "ns3/traffic-control-module.h"
16
17#include <iomanip>
18#include <iostream>
19#include <map>
20
21using namespace ns3;
22
23int
24main(int argc, char* argv[])
25{
26 uint32_t nLeaf = 5;
27 uint32_t maxPackets = 100;
28 uint32_t modeBytes = 0;
29 uint32_t queueDiscLimitPackets = 1000;
30 double minTh = 50;
31 double maxTh = 80;
32 uint32_t pktSize = 512;
33 std::string appDataRate = "10Mbps";
34 std::string queueDiscType = "PfifoFast";
35 uint16_t port = 5001;
36 std::string bottleNeckLinkBw = "1Mbps";
37 std::string bottleNeckLinkDelay = "50ms";
38
39 CommandLine cmd(__FILE__);
40 cmd.AddValue("nLeaf", "Number of left and right side leaf nodes", nLeaf);
41 cmd.AddValue("maxPackets", "Max Packets allowed in the device queue", maxPackets);
42 cmd.AddValue("queueDiscLimitPackets",
43 "Max Packets allowed in the queue disc",
44 queueDiscLimitPackets);
45 cmd.AddValue("queueDiscType", "Set QueueDisc type to PfifoFast or RED", queueDiscType);
46 cmd.AddValue("appPktSize", "Set OnOff App Packet Size", pktSize);
47 cmd.AddValue("appDataRate", "Set OnOff App DataRate", appDataRate);
48 cmd.AddValue("modeBytes", "Set QueueDisc mode to Packets <0> or bytes <1>", modeBytes);
49
50 cmd.AddValue("redMinTh", "RED queue minimum threshold", minTh);
51 cmd.AddValue("redMaxTh", "RED queue maximum threshold", maxTh);
52 cmd.Parse(argc, argv);
53
54 if ((queueDiscType != "RED") && (queueDiscType != "PfifoFast"))
55 {
57 "Invalid queue disc type: Use --queueDiscType=RED or --queueDiscType=PfifoFast");
58 }
59
60 Config::SetDefault("ns3::OnOffApplication::PacketSize", UintegerValue(pktSize));
61 Config::SetDefault("ns3::OnOffApplication::DataRate", StringValue(appDataRate));
62
63 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize",
64 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, maxPackets)));
65
66 if (!modeBytes)
67 {
69 "ns3::RedQueueDisc::MaxSize",
70 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, queueDiscLimitPackets)));
72 "ns3::PfifoFastQueueDisc::MaxSize",
73 QueueSizeValue(QueueSize(QueueSizeUnit::PACKETS, queueDiscLimitPackets)));
74 }
75 else
76 {
78 "ns3::RedQueueDisc::MaxSize",
79 QueueSizeValue(QueueSize(QueueSizeUnit::BYTES, queueDiscLimitPackets * pktSize)));
80 minTh *= pktSize;
81 maxTh *= pktSize;
82 }
83
84 Config::SetDefault("ns3::RedQueueDisc::MinTh", DoubleValue(minTh));
85 Config::SetDefault("ns3::RedQueueDisc::MaxTh", DoubleValue(maxTh));
86 Config::SetDefault("ns3::RedQueueDisc::LinkBandwidth", StringValue(bottleNeckLinkBw));
87 Config::SetDefault("ns3::RedQueueDisc::LinkDelay", StringValue(bottleNeckLinkDelay));
88
89 // Create the point-to-point link helpers
90 PointToPointHelper bottleNeckLink;
91 bottleNeckLink.SetDeviceAttribute("DataRate", StringValue(bottleNeckLinkBw));
92 bottleNeckLink.SetChannelAttribute("Delay", StringValue(bottleNeckLinkDelay));
93
94 PointToPointHelper pointToPointLeaf;
95 pointToPointLeaf.SetDeviceAttribute("DataRate", StringValue("10Mbps"));
96 pointToPointLeaf.SetChannelAttribute("Delay", StringValue("1ms"));
97
98 PointToPointDumbbellHelper d(nLeaf, pointToPointLeaf, nLeaf, pointToPointLeaf, bottleNeckLink);
99
100 // Install Stack
102 for (uint32_t i = 0; i < d.LeftCount(); ++i)
103 {
104 stack.Install(d.GetLeft(i));
105 }
106 for (uint32_t i = 0; i < d.RightCount(); ++i)
107 {
108 stack.Install(d.GetRight(i));
109 }
110
111 if (queueDiscType == "PfifoFast")
112 {
113 stack.Install(d.GetLeft());
114 stack.Install(d.GetRight());
115 }
116 else if (queueDiscType == "RED")
117 {
118 stack.Install(d.GetLeft());
119 stack.Install(d.GetRight());
120 TrafficControlHelper tchBottleneck;
121 tchBottleneck.SetRootQueueDisc("ns3::RedQueueDisc");
122 tchBottleneck.Install(d.GetLeft()->GetDevice(0));
123 tchBottleneck.Install(d.GetRight()->GetDevice(0));
124 }
125
126 // Assign IP Addresses
127 d.AssignIpv4Addresses(Ipv4AddressHelper("10.1.1.0", "255.255.255.0"),
128 Ipv4AddressHelper("10.2.1.0", "255.255.255.0"),
129 Ipv4AddressHelper("10.3.1.0", "255.255.255.0"));
130
131 // Install on/off app on all right side nodes
132 OnOffHelper clientHelper("ns3::TcpSocketFactory", Address());
133 clientHelper.SetAttribute("OnTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
134 clientHelper.SetAttribute("OffTime", StringValue("ns3::UniformRandomVariable[Min=0.|Max=1.]"));
136 PacketSinkHelper packetSinkHelper("ns3::TcpSocketFactory", sinkLocalAddress);
137 ApplicationContainer sinkApps;
138 for (uint32_t i = 0; i < d.LeftCount(); ++i)
139 {
140 sinkApps.Add(packetSinkHelper.Install(d.GetLeft(i)));
141 }
142 sinkApps.Start(Seconds(0.0));
143 sinkApps.Stop(Seconds(30.0));
144
146 for (uint32_t i = 0; i < d.RightCount(); ++i)
147 {
148 // Create an on/off app sending packets to the left side
149 AddressValue remoteAddress(InetSocketAddress(d.GetLeftIpv4Address(i), port));
150 clientHelper.SetAttribute("Remote", remoteAddress);
151 clientApps.Add(clientHelper.Install(d.GetRight(i)));
152 }
153 clientApps.Start(Seconds(1.0)); // Start 1 second after sink
154 clientApps.Stop(Seconds(15.0)); // Stop before the sink
155
157
158 std::cout << "Running the simulation" << std::endl;
160
161 uint64_t totalRxBytesCounter = 0;
162 for (uint32_t i = 0; i < sinkApps.GetN(); i++)
163 {
164 Ptr<Application> app = sinkApps.Get(i);
166 totalRxBytesCounter += pktSink->GetTotalRx();
167 }
168 NS_LOG_UNCOND("----------------------------\nQueueDisc Type:"
169 << queueDiscType
170 << "\nGoodput Bytes/sec:" << totalRxBytesCounter / Simulator::Now().GetSeconds());
171 NS_LOG_UNCOND("----------------------------");
172
173 std::cout << "Destroying the simulation" << std::endl;
175 return 0;
176}
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.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the 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.
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.
Smart pointer class similar to boost::intrusive_ptr.
Class for representing queue sizes.
Definition queue-size.h:85
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
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
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_UNCOND(msg)
Output the requested message unconditionally.
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.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580
uint32_t pktSize
packet size used for the simulation (in bytes)