A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cobalt-vs-codel.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Shefali Gupta <shefaligups11@ogmail.com>
7 * Jendaipou Palmei <jendaipoupalmei@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 */
10
11#include "ns3/applications-module.h"
12#include "ns3/core-module.h"
13#include "ns3/internet-module.h"
14#include "ns3/ipv6-routing-table-entry.h"
15#include "ns3/ipv6-static-routing-helper.h"
16#include "ns3/network-module.h"
17#include "ns3/point-to-point-module.h"
18#include "ns3/tcp-header.h"
19#include "ns3/traffic-control-module.h"
20
21#include <fstream>
22#include <string>
23
24// Dumbbell topology with 7 senders and 1 receiver
25// is used for this example. On successful completion,
26// the Congestion window and Queue size traces get stored
27// in MixTraffic/ directory, inside cwndTraces and
28// queueTraces sub-directories, respectively.
29
30using namespace ns3;
31
32std::string dir = "MixTraffic/";
33
34void
36{
37 double qSize = queue->GetCurrentSize().GetValue();
38 // check queue size every 1/10 of a second
40
41 std::ofstream fPlotQueue(dir + queue_disc_type + "/queueTraces/queue.plotme",
42 std::ios::out | std::ios::app);
43 fPlotQueue << Simulator::Now().GetSeconds() << " " << qSize << std::endl;
44 fPlotQueue.close();
45}
46
47static void
49{
50 *stream->GetStream() << Simulator::Now().GetSeconds() << " " << newCwnd / 1446.0 << std::endl;
51}
52
53static void
55{
56 for (uint8_t i = 0; i < 5; i++)
57 {
59 Ptr<OutputStreamWrapper> stream = asciiTraceHelper.CreateFileStream(
60 dir + queue_disc_type + "/cwndTraces/S1-" + std::to_string(i + 1) + ".plotme");
61 Config::ConnectWithoutContext("/NodeList/" + std::to_string(i) +
62 "/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
64 }
65}
66
67void
69{
70 // Set the simulation stop time in seconds
71 double stopTime = 101;
72 std::string queue_disc = std::string("ns3::") + queue_disc_type;
73
74 std::string bottleneckBandwidth = "10Mbps";
75 std::string bottleneckDelay = "50ms";
76
77 std::string accessBandwidth = "10Mbps";
78 std::string accessDelay = "5ms";
79
80 // Create sender
83
86
87 // Create gateway
89 gateway.Create(2);
90
91 // Create sink
93 sink.Create(1);
94
95 Config::SetDefault("ns3::TcpSocket::SndBufSize", UintegerValue(1 << 20));
96 Config::SetDefault("ns3::TcpSocket::RcvBufSize", UintegerValue(1 << 20));
97 Config::SetDefault("ns3::TcpSocket::DelAckTimeout", TimeValue(Seconds(0)));
98 Config::SetDefault("ns3::TcpSocket::InitialCwnd", UintegerValue(1));
99 Config::SetDefault("ns3::TcpSocketBase::LimitedTransmit", BooleanValue(false));
100 Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(1446));
101 Config::SetDefault("ns3::TcpSocketBase::WindowScaling", BooleanValue(true));
102 Config::SetDefault(queue_disc + "::MaxSize", QueueSizeValue(QueueSize("200p")));
103
104 InternetStackHelper internet;
105 internet.InstallAll();
106
108 uint16_t handle = tchPfifo.SetRootQueueDisc("ns3::PfifoFastQueueDisc");
109 tchPfifo.AddInternalQueues(handle, 3, "ns3::DropTailQueue", "MaxSize", StringValue("1000p"));
110
113
116 accessLink.SetChannelAttribute("Delay", StringValue(accessDelay));
117
118 // Configure the senders and sinks net devices
119 // and the channels between the senders/sinks and the gateways
120 NetDeviceContainer devices[5];
121 for (uint8_t i = 0; i < 5; i++)
122 {
123 devices[i] = accessLink.Install(tcpSender.Get(i), gateway.Get(0));
124 tchPfifo.Install(devices[i]);
125 }
126
128 devices_sink = accessLink.Install(gateway.Get(1), sink.Get(0));
129 tchPfifo.Install(devices_sink);
130
133 bottleneckLink.SetChannelAttribute("Delay", StringValue(bottleneckDelay));
134
136 devices_gateway = bottleneckLink.Install(gateway.Get(0), gateway.Get(1));
137 // Install QueueDisc at gateway
139
140 Ipv4AddressHelper address;
141 address.SetBase("10.0.0.0", "255.255.255.0");
142
143 Ipv4InterfaceContainer interfaces[5];
147
149
150 for (uint8_t i = 0; i < 5; i++)
151 {
152 address.NewNetwork();
153 interfaces[i] = address.Assign(devices[i]);
154 }
155
156 for (uint8_t i = 0; i < 2; i++)
157 {
158 udpdevices[i] = accessLink.Install(udpSender.Get(i), gateway.Get(0));
159 address.NewNetwork();
160 udpinterfaces[i] = address.Assign(udpdevices[i]);
161 }
162
163 address.NewNetwork();
164 interfaces_gateway = address.Assign(devices_gateway);
165
166 address.NewNetwork();
167 interfaces_sink = address.Assign(devices_sink);
168
170
171 uint16_t port = 50000;
172 uint16_t port1 = 50001;
175 PacketSinkHelper sinkHelper("ns3::TcpSocketFactory", sinkLocalAddress);
176 PacketSinkHelper sinkHelper1("ns3::UdpSocketFactory", sinkLocalAddress1);
177
178 AddressValue remoteAddress(InetSocketAddress(interfaces_sink.GetAddress(1), port));
180
181 BulkSendHelper ftp("ns3::TcpSocketFactory", Address());
182 ftp.SetAttribute("Remote", remoteAddress);
183 ftp.SetAttribute("SendSize", UintegerValue(1000));
184
187 sourceApp.Stop(Seconds(stopTime - 1));
188
189 sinkHelper.SetAttribute("Protocol", TypeIdValue(TcpSocketFactory::GetTypeId()));
192 sinkApp.Stop(Seconds(stopTime));
193
194 OnOffHelper clientHelper6("ns3::UdpSocketFactory", Address());
195 clientHelper6.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
196 clientHelper6.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
197 clientHelper6.SetAttribute("DataRate", DataRateValue(DataRate("10Mb/s")));
198 clientHelper6.SetAttribute("PacketSize", UintegerValue(1000));
199
201 clientHelper6.SetAttribute("Remote", remoteAddress1);
202 clientApps6.Add(clientHelper6.Install(udpSender.Get(0)));
203 clientApps6.Start(Seconds(0));
204 clientApps6.Stop(Seconds(stopTime - 1));
205
206 OnOffHelper clientHelper7("ns3::UdpSocketFactory", Address());
207 clientHelper7.SetAttribute("OnTime", StringValue("ns3::ConstantRandomVariable[Constant=1]"));
208 clientHelper7.SetAttribute("OffTime", StringValue("ns3::ConstantRandomVariable[Constant=0]"));
209 clientHelper7.SetAttribute("DataRate", DataRateValue(DataRate("10Mb/s")));
210 clientHelper7.SetAttribute("PacketSize", UintegerValue(1000));
211
213 clientHelper7.SetAttribute("Remote", remoteAddress1);
214 clientApps7.Add(clientHelper7.Install(udpSender.Get(1)));
215 clientApps7.Start(Seconds(0));
216 clientApps7.Stop(Seconds(stopTime - 1));
217
218 sinkHelper1.SetAttribute("Protocol", TypeIdValue(UdpSocketFactory::GetTypeId()));
222
223 Ptr<QueueDisc> queue = queueDiscs.Get(0);
225
226 std::string dirToSave = "mkdir -p " + dir + queue_disc_type;
227 if (system((dirToSave + "/cwndTraces/").c_str()) == -1 ||
228 system((dirToSave + "/queueTraces/").c_str()) == -1)
229 {
230 exit(1);
231 }
232
234
238}
239
240int
241main(int argc, char** argv)
242{
243 std::cout << "Simulation with COBALT QueueDisc: Start\n" << std::flush;
244 experiment("CobaltQueueDisc");
245 std::cout << "Simulation with COBALT QueueDisc: End\n" << std::flush;
246 std::cout << "------------------------------------------------\n";
247 std::cout << "Simulation with CoDel QueueDisc: Start\n";
248 experiment("CoDelQueueDisc");
249 std::cout << "Simulation with CoDel QueueDisc: End\n";
250
251 return 0;
252}
a polymophic address class
Definition address.h:90
AttributeValue implementation for Address.
Definition address.h:275
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 Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Manage ASCII trace files for device models.
AttributeValue implementation for Boolean.
Definition boolean.h:26
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes.
Class for representing data rates.
Definition data-rate.h:78
AttributeValue implementation for DataRate.
Definition data-rate.h:285
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.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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.
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.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
Holds a vector of ns3::QueueDisc pointers.
Class for representing queue sizes.
Definition queue-size.h:85
AttributeValue implementation for QueueSize.
Definition queue-size.h:210
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition simulator.h:594
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
static TypeId GetTypeId()
Get the type ID.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
AttributeValue implementation for Time.
Definition nstime.h:1431
Build a set of QueueDisc objects.
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.
AttributeValue implementation for TypeId.
Definition type-id.h:641
static TypeId GetTypeId()
Get the type ID.
Hold an unsigned integer type.
Definition uinteger.h:34
void CheckQueueSize(Ptr< QueueDisc > queue, std::string queue_disc_type)
void experiment(std::string queue_disc_type)
static void TraceCwnd(std::string queue_disc_type)
static void CwndTrace(Ptr< OutputStreamWrapper > stream, uint32_t oldCwnd, uint32_t newCwnd)
std::string dir
uint16_t port
Definition dsdv-manet.cc:33
Time stopTime
std::ofstream fPlotQueue
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition config.cc:943
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:745
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< PacketSink > sink
Pointer to the packet sink application.
Definition wifi-tcp.cc:44