A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
flent-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Universita' degli Studi di Napoli Federico II
3 * Copyright (c) 2020 Harsha Sharma : Adapt for Flent
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Harsha Sharma <harshasha256@gmail.com>
8 * Tom Henderson <tomh@tomh.org>
9 */
10
11/**
12 * @file flent-example.cc
13 * @brief A simple example demonstrating the FlentApplication
14 *
15 * This example demonstrates how to set up a basic ns-3 simulation using the
16 * FlentApplication to generate and measure network traffic. It configures
17 * a network topology, installs the Flent applications using the FlentHelper,
18 * and runs a specified network test.
19 *
20 * The simulation consists of the following topology:
21 * client <-> router1 <-> router2 <-> server
22 *
23 * The middle link (router1 <-> router2) acts as the bottleneck with
24 * configurable bandwidth and RTT, while the edge links have higher capacity.
25 *
26 * Supported Flent tests:
27 * - rrul: Realtime Response Under Load (default)
28 * - tcp_upload: TCP upload throughput test
29 * - tcp_download: TCP download throughput test
30 * - ping: Simple ICMP ping test
31 *
32 * To run this example with default parameters (rrul test):
33 * ./ns3 run flent-example
34 *
35 * To run a specific test, e.g., tcp_upload:
36 * ./ns3 run "flent-example --test=tcp_upload"
37 *
38 * To modify the bottleneck bandwidth and rtt:
39 * ./ns3 run "flent-example --bw=20Mbps --rtt=20ms"
40 */
41
42#include "ns3/applications-module.h"
43#include "ns3/core-module.h"
44#include "ns3/internet-module.h"
45#include "ns3/network-module.h"
46#include "ns3/point-to-point-module.h"
47#include "ns3/traffic-control-module.h"
48
49using namespace ns3;
50
51NS_LOG_COMPONENT_DEFINE("FlentExample");
52
53int
54main(int argc, char* argv[])
55{
56 std::string testName = "rrul";
57 Time rtt = MilliSeconds(10);
58 DataRate bw("50Mbps");
59 Time length = Seconds(60);
60 Time delay = Seconds(0);
61 bool verbose = false;
62 std::string tcpType = "TcpLinuxReno";
63
64 // 2 MB of TCP buffer
65 Config::SetDefault("ns3::TcpSocket::RcvBufSize", UintegerValue(1 << 21));
66 Config::SetDefault("ns3::TcpSocket::SndBufSize", UintegerValue(1 << 21));
67 Config::SetDefault("ns3::TcpSocket::SegmentSize", UintegerValue(1448));
68 Config::SetDefault("ns3::TcpSocketState::EnablePacing", BooleanValue(true));
69
70 CommandLine cmd(__FILE__);
71 cmd.AddValue("test", "Type of ns-3 Flent test", testName);
72 cmd.AddValue("rtt", "Delay value", rtt);
73 cmd.AddValue("bw", "Data Rate", bw);
74 cmd.AddValue("length", "Base test duration (--length in Flent)", length);
75 cmd.AddValue("delay", "Time to delay test (--delay in Flent)", delay);
76 cmd.AddValue("verbose", "Verbose output", verbose);
77 cmd.AddValue("tcpType", "TCP congestion control type (e.g. TcpCubic, TcpLinuxReno)", tcpType);
78 cmd.Parse(argc, argv);
79
80 Config::SetDefault("ns3::TcpL4Protocol::SocketType", StringValue("ns3::" + tcpType));
81
82 // Check arguments
83 if (testName != "rrul" && testName != "tcp_upload" && testName != "tcp_download" &&
84 testName != "ping")
85 {
86 NS_FATAL_ERROR("Test name must be one of 'rrul', 'tcp_upload', 'tcp_download', or 'ping'");
87 }
88
89 std::optional<ShowProgress> progress;
90 if (verbose)
91 {
92 progress.emplace(Seconds(10), std::cerr);
93 }
94
96 n.Create(4); // client <-> router1 <-> router2 <-> server
97 // Create node containers for configuring individual links
98 NodeContainer n0; // Group the client and router1 together
99 n0.Add(n.Get(0));
100 n0.Add(n.Get(1));
101 NodeContainer n1; // Group the routers together
102 n1.Add(n.Get(1));
103 n1.Add(n.Get(2));
104 NodeContainer n2; // Group the router2 and server together
105 n2.Add(n.Get(2));
106 n2.Add(n.Get(3));
107
108 PointToPointHelper deviceHelper;
109 DataRate edgeRate(100 * bw.GetBitRate());
110 deviceHelper.SetDeviceAttribute("DataRate", DataRateValue(edgeRate));
111 deviceHelper.SetChannelAttribute("Delay", TimeValue(MicroSeconds(1)));
112 deviceHelper.SetQueue("ns3::DropTailQueue", "MaxSize", StringValue("1p"));
113 NetDeviceContainer devices0;
114 devices0 = deviceHelper.Install(n0);
115 NetDeviceContainer devices2;
116 devices2 = deviceHelper.Install(n2);
117 // The middle link has the bandwidth and delay constraints
118 NetDeviceContainer devices1;
119 deviceHelper.SetDeviceAttribute("DataRate", DataRateValue(bw));
120 deviceHelper.SetChannelAttribute("Delay", TimeValue(rtt / 2));
121 devices1 = deviceHelper.Install(n1);
122
123 // Configure the IP and traffic control layers
125 stack.InstallAll();
126
128 tch.SetRootQueueDisc("ns3::FqCoDelQueueDisc");
129 Config::SetDefault("ns3::FqCoDelQueueDisc::MaxSize", QueueSizeValue(QueueSize("200p")));
130 tch.SetQueueLimits("ns3::DynamicQueueLimits"); // enable BQL
131 QueueDiscContainer qdiscs;
132 qdiscs = tch.Install(devices0);
133 qdiscs = tch.Install(devices1);
134 qdiscs = tch.Install(devices2);
135
137 address.SetBase("10.1.1.0", "255.255.255.0");
138 Ipv4InterfaceContainer interfaces0 = address.Assign(devices0);
139 address.NewNetwork();
140 Ipv4InterfaceContainer interfaces1 = address.Assign(devices1);
141 address.NewNetwork();
142 Ipv4InterfaceContainer interfaces2 = address.Assign(devices2);
143
145
146 // Configure with the help of FlentHelper
147 FlentHelper flentHelper(testName, interfaces2.GetAddress(1));
148 flentHelper.SetTestStartTime(delay);
149 flentHelper.SetTestLength(length);
150 flentHelper.SetAttribute("StepSize", TimeValue(Seconds(0.2)));
151
152 flentHelper.Install(n.Get(0));
153
154 // Stop the simulation one second after Flent ends
155 Simulator::Stop(flentHelper.GetStopTime() + Seconds(1));
156
159
160 return 0;
161}
Parse command-line arguments.
Class for representing data rates.
Definition data-rate.h:78
A helper to make it easier to instantiate an ns3::FlentApplication.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
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.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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.
void SetQueue(std::string type, Ts &&... args)
Each point to point net device must have a queue to pass packets through.
NetDeviceContainer Install(NodeContainer c)
Holds a vector of ns3::QueueDisc pointers.
Class for representing queue sizes.
Definition queue-size.h:85
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
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.
void SetQueueLimits(std::string type, Args &&... args)
Helper function used to add a queue limits object to the transmission queues of the devices.
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:201
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1347
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1330
address
Definition first.py:36
stack
Definition first.py:33
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool verbose