A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
traffic-control-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8#ifndef TRAFFIC_CONTROL_HELPER_H
9#define TRAFFIC_CONTROL_HELPER_H
10
12
13#include "ns3/net-device-container.h"
14#include "ns3/object-factory.h"
15#include "ns3/queue.h"
16
17#include <map>
18#include <string>
19#include <vector>
20
21namespace ns3
22{
23
24/**
25 * \ingroup traffic-control
26 *
27 * This class stores object factories required to create a queue disc and all of
28 * its components (packet filters, internal queues, classes).
29 */
31{
32 public:
33 /**
34 * \brief Constructor
35 *
36 * \param factory the factory used to create this queue disc
37 */
39
41 {
42 }
43
44 // Delete default constructor to avoid misuse
45 QueueDiscFactory() = delete;
46
47 /**
48 * \brief Add a factory to create an internal queue
49 *
50 * \param factory the factory used to create an internal queue
51 */
52 void AddInternalQueue(ObjectFactory factory);
53
54 /**
55 * \brief Add a factory to create a packet filter
56 *
57 * \param factory the factory used to create a packet filter
58 */
59 void AddPacketFilter(ObjectFactory factory);
60
61 /**
62 * \brief Add a factory to create a queue disc class
63 *
64 * \param factory the factory used to create a queue disc class
65 * \return the class ID of the created queue disc class
66 */
67 uint16_t AddQueueDiscClass(ObjectFactory factory);
68
69 /**
70 * \brief Set the (child) queue disc to attach to a class
71 *
72 * \param classId the id of the class to attach a child queue disc to
73 * \param handle the handle of the child queue disc to attach to the class
74 */
75 void SetChildQueueDisc(uint16_t classId, uint16_t handle);
76
77 /**
78 * \brief Create a queue disc with the currently stored configuration.
79 *
80 * \param queueDiscs the vector of queue discs held by the helper
81 * \return the created queue disc
82 */
83 Ptr<QueueDisc> CreateQueueDisc(const std::vector<Ptr<QueueDisc>>& queueDiscs);
84
85 private:
86 /// Factory to create this queue disc
88 /// Vector of factories to create internal queues
89 std::vector<ObjectFactory> m_internalQueuesFactory;
90 /// Vector of factories to create packet filters
91 std::vector<ObjectFactory> m_packetFiltersFactory;
92 /// Vector of factories to create queue disc classes
93 std::vector<ObjectFactory> m_queueDiscClassesFactory;
94 /// Map storing the associations between class IDs and child queue disc handles
95 std::map<uint16_t, uint16_t> m_classIdChildHandleMap;
96};
97
98/**
99 * \ingroup traffic-control
100 *
101 * \brief Build a set of QueueDisc objects
102 *
103 * This class can help to create QueueDisc objects and map them to
104 * the corresponding devices. This map is stored at the Traffic Control
105 * layer.
106 */
108{
109 public:
110 /**
111 * Create a TrafficControlHelper to make life easier when creating QueueDisc
112 * objects.
113 */
115
117 {
118 }
119
120 /**
121 * \param nTxQueues the number of Tx queue disc classes
122 * \returns a new TrafficControlHelper with a default configuration
123 *
124 * The default configuration is an FqCoDelQueueDisc, if the device has a single
125 * queue, or an MqQueueDisc with as many FqCoDelQueueDiscs as the number of
126 * device queues, otherwise.
127 */
128 static TrafficControlHelper Default(std::size_t nTxQueues = 1);
129
130 /**
131 * Helper function used to set a root queue disc of the given type and with the
132 * given attributes. To set the InternalQueueList, PacketFilterList and ChildQueueDiscList
133 * attributes, use the AddInternalQueue, AddPacketFilter and AddChildQueueDisc methods.
134 *
135 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
136 * \param type the type of queue disc
137 * \param args A sequence of name-value pairs of the attributes to set.
138 * \return the handle of the root queue disc (zero)
139 */
140 template <typename... Args>
141 uint16_t SetRootQueueDisc(const std::string& type, Args&&... args);
142
143 /**
144 * Helper function used to add the given number of internal queues (of the given
145 * type and with the given attributes) to the queue disc having the given handle.
146 *
147 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
148 * \param handle the handle of the parent queue disc
149 * \param count the number of queues to add
150 * \param type the type of queue
151 * \param args A sequence of name-value pairs of the attributes to set.
152 */
153 template <typename... Args>
154 void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, Args&&... args);
155
156 /**
157 * Helper function used to add a packet filter (of the given type and with
158 * the given attributes) to the queue disc having the given handle.
159 *
160 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
161 * \param handle the handle of the parent queue disc
162 * \param type the type of packet filter
163 * \param args A sequence of name-value pairs of the attributes to set.
164 */
165 template <typename... Args>
166 void AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args);
167
168 /**
169 * Container type for Class IDs
170 */
171 typedef std::vector<uint16_t> ClassIdList;
172
173 /**
174 * Helper function used to add the given number of queue disc classes (of the given
175 * type and with the given attributes) to the queue disc having the given handle.
176 *
177 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
178 * \param handle the handle of the parent queue disc
179 * \param count the number of queue disc classes to add
180 * \param type the type of queue disc class
181 * \param args A sequence of name-value pairs of the attributes to set.
182 * \return the list of class IDs
183 */
184 template <typename... Args>
185 ClassIdList AddQueueDiscClasses(uint16_t handle,
186 uint16_t count,
187 const std::string& type,
188 Args&&... args);
189
190 /**
191 * Helper function used to attach a child queue disc (of the given type and with
192 * the given attributes) to a given class (included in the queue disc
193 * having the given handle).
194 *
195 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
196 * \param handle the handle of the parent queue disc
197 * \param classId the class ID of the class to attach the queue disc to
198 * \param type the type of queue disc
199 * \param args A sequence of name-value pairs of the attributes to set.
200 * \return the handle of the created child queue disc
201 */
202 template <typename... Args>
203 uint16_t AddChildQueueDisc(uint16_t handle,
204 uint16_t classId,
205 const std::string& type,
206 Args&&... args);
207
208 /**
209 * Container type for Handlers
210 */
211 typedef std::vector<uint16_t> HandleList;
212
213 /**
214 * Helper function used to attach a child queue disc (of the given type and with
215 * the given attributes) to each of the given classes (included in the queue disc
216 * having the given handle).
217 *
218 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
219 * \param handle the handle of the parent queue disc
220 * \param classes the class IDs of the classes to attach a queue disc to
221 * \param type the type of queue disc
222 * \param args A sequence of name-value pairs of the attributes to set.
223 * \return the list of handles of the created child queue discs
224 */
225 template <typename... Args>
226 HandleList AddChildQueueDiscs(uint16_t handle,
227 const ClassIdList& classes,
228 const std::string& type,
229 Args&&... args);
230
231 /**
232 * Helper function used to add a queue limits object to the transmission
233 * queues of the devices
234 *
235 * \tparam Args \deduced Template type parameter pack for the sequence of name-value pairs.
236 * \param type the type of queue
237 * \param args A sequence of name-value pairs of the attributes to set.
238 */
239 template <typename... Args>
240 void SetQueueLimits(std::string type, Args&&... args);
241
242 /**
243 * \param c set of devices
244 * \returns a QueueDisc container with the root queue discs installed on the devices
245 *
246 * This method creates a QueueDisc object of the type and with the
247 * attributes configured by TrafficControlHelper::SetQueueDisc for
248 * each device in the container. Then, stores the mapping between a
249 * device and the associated queue disc into the traffic control layer
250 * of the corresponding node.
251 * This method creates the queue discs (along with their packet filters,
252 * internal queues, classes) configured with the methods provided by this
253 * class and installs them on each device in the given container. Additionally,
254 * if configured, a queue limits object is installed on each transmission queue
255 * of the devices.
256 */
258
259 /**
260 * \param d device
261 * \returns a QueueDisc container with the root queue disc installed on the device
262 *
263 * This method creates the queue discs (along with their packet filters,
264 * internal queues, classes) configured with the methods provided by this
265 * class and installs them on the given device. Additionally, if configured,
266 * a queue limits object is installed on each transmission queue of the device.
267 */
269
270 /**
271 * \param c set of devices
272 *
273 * This method removes the root queue discs (and associated filters, classes
274 * and queues) installed on the given devices.
275 * Note that the traffic control layer will continue to perform flow control
276 * if the device has an aggregated NetDeviceQueueInterface. If you really
277 * want that the Traffic Control layer forwards packets down to the NetDevice
278 * even if there is no room for them in the NetDevice queue(s), then disable
279 * the flow control by using the DisableFlowControl method of the NetDevice
280 * helper.
281 */
283
284 /**
285 * \param d device
286 *
287 * This method removes the root queue disc (and associated filters, classes
288 * and queues) installed on the given device.
289 * Note that the traffic control layer will continue to perform flow control
290 * if the device has an aggregated NetDeviceQueueInterface. If you really
291 * want that the Traffic Control layer forwards packets down to the NetDevice
292 * even if there is no room for them in the NetDevice queue(s), then disable
293 * the flow control by using the DisableFlowControl method of the NetDevice
294 * helper.
295 */
297
298 private:
299 /**
300 * Actual implementation of the SetRootQueueDisc method.
301 *
302 * \param factory the factory used to create the root queue disc
303 * \returns zero on success
304 */
305 uint16_t DoSetRootQueueDisc(ObjectFactory factory);
306
307 /**
308 * Actual implementation of the AddInternalQueues method.
309 *
310 * \param handle the handle of the parent queue disc
311 * \param count the number of queues to add
312 * \param factory the factory used to add internal queues
313 */
314 void DoAddInternalQueues(uint16_t handle, uint16_t count, ObjectFactory factory);
315
316 /**
317 * Actual implementation of the AddPacketFilter method.
318 *
319 * \param handle the handle of the parent queue disc
320 * \param factory the factory used to add a packet filter
321 */
322 void DoAddPacketFilter(uint16_t handle, ObjectFactory factory);
323
324 /**
325 * Actual implementation of the AddQueueDiscClasses method.
326 *
327 * \param handle the handle of the parent queue disc
328 * \param count the number of queue disc classes to add
329 * \param factory the factory used to add queue disc classes
330 * \return the list of class IDs
331 */
332 ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory);
333
334 /**
335 * Actual implementation of the AddChildQueueDisc method.
336 *
337 * \param handle the handle of the parent queue disc
338 * \param classId the class ID of the class to attach the queue disc to
339 * \param factory the factory used to add a child queue disc
340 * \return the handle of the created child queue disc
341 */
342 uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory);
343
344 /**
345 * Actual implementation of the AddChildQueueDiscs method.
346 *
347 * \param handle the handle of the parent queue disc
348 * \param classes the class IDs of the classes to attach a queue disc to
349 * \param factory the factory used to add child queue discs
350 * \return the list of handles of the created child queue discs
351 */
352 HandleList DoAddChildQueueDiscs(uint16_t handle,
353 const ClassIdList& classes,
354 ObjectFactory factory);
355
356 /// QueueDisc factory, stores the configuration of all the queue discs
357 std::vector<QueueDiscFactory> m_queueDiscFactory;
358 /// Vector of all the created queue discs
359 std::vector<Ptr<QueueDisc>> m_queueDiscs;
360 /// Factory to create a queue limits object
362};
363
364} // namespace ns3
365
366/***************************************************************
367 * Implementation of the templates declared above.
368 ***************************************************************/
369
370namespace ns3
371{
372
373template <typename... Args>
374uint16_t
375TrafficControlHelper::SetRootQueueDisc(const std::string& type, Args&&... args)
376{
377 return DoSetRootQueueDisc(ObjectFactory(type, args...));
378}
379
380template <typename... Args>
381void
383 uint16_t count,
384 std::string type,
385 Args&&... args)
386{
387 QueueBase::AppendItemTypeIfNotPresent(type, "QueueDiscItem");
388 DoAddInternalQueues(handle, count, ObjectFactory(type, args...));
389}
390
391template <typename... Args>
392void
393TrafficControlHelper::AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args)
394{
395 DoAddPacketFilter(handle, ObjectFactory(type, args...));
396}
397
398template <typename... Args>
401 uint16_t count,
402 const std::string& type,
403 Args&&... args)
404{
405 return DoAddQueueDiscClasses(handle, count, ObjectFactory(type, args...));
406}
407
408template <typename... Args>
409uint16_t
411 uint16_t classId,
412 const std::string& type,
413 Args&&... args)
414{
415 return DoAddChildQueueDisc(handle, classId, ObjectFactory(type, args...));
416}
417
418template <typename... Args>
421 const ClassIdList& classes,
422 const std::string& type,
423 Args&&... args)
424{
425 return DoAddChildQueueDiscs(handle, classes, ObjectFactory(type, args...));
426}
427
428template <typename... Args>
429void
430TrafficControlHelper::SetQueueLimits(std::string type, Args&&... args)
431{
433 m_queueLimitsFactory.Set(args...);
434}
435
436} // namespace ns3
437
438#endif /* TRAFFIC_CONTROL_HELPER_H */
holds a vector of ns3::NetDevice pointers
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
static void AppendItemTypeIfNotPresent(std::string &typeId, const std::string &itemType)
Append the item type to the provided type ID if the latter does not end with '>'.
Definition queue.cc:62
Holds a vector of ns3::QueueDisc pointers.
This class stores object factories required to create a queue disc and all of its components (packet ...
std::vector< ObjectFactory > m_internalQueuesFactory
Vector of factories to create internal queues.
uint16_t AddQueueDiscClass(ObjectFactory factory)
Add a factory to create a queue disc class.
void AddInternalQueue(ObjectFactory factory)
Add a factory to create an internal queue.
void AddPacketFilter(ObjectFactory factory)
Add a factory to create a packet filter.
Ptr< QueueDisc > CreateQueueDisc(const std::vector< Ptr< QueueDisc > > &queueDiscs)
Create a queue disc with the currently stored configuration.
void SetChildQueueDisc(uint16_t classId, uint16_t handle)
Set the (child) queue disc to attach to a class.
std::map< uint16_t, uint16_t > m_classIdChildHandleMap
Map storing the associations between class IDs and child queue disc handles.
std::vector< ObjectFactory > m_packetFiltersFactory
Vector of factories to create packet filters.
ObjectFactory m_queueDiscFactory
Factory to create this queue disc.
std::vector< ObjectFactory > m_queueDiscClassesFactory
Vector of factories to create queue disc classes.
Build a set of QueueDisc objects.
std::vector< uint16_t > HandleList
Container type for Handlers.
QueueDiscContainer Install(NetDeviceContainer c)
std::vector< Ptr< QueueDisc > > m_queueDiscs
Vector of all the created queue discs.
uint16_t DoSetRootQueueDisc(ObjectFactory factory)
Actual implementation of the SetRootQueueDisc method.
uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory)
Actual implementation of the AddChildQueueDisc method.
TrafficControlHelper()
Create a TrafficControlHelper to make life easier when creating 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.
void DoAddInternalQueues(uint16_t handle, uint16_t count, ObjectFactory factory)
Actual implementation of the AddInternalQueues method.
void DoAddPacketFilter(uint16_t handle, ObjectFactory factory)
Actual implementation of the AddPacketFilter method.
void SetQueueLimits(std::string type, Args &&... args)
Helper function used to add a queue limits object to the transmission queues of the devices.
ObjectFactory m_queueLimitsFactory
Factory to create a queue limits object.
void Uninstall(NetDeviceContainer c)
ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory)
Actual implementation of the AddQueueDiscClasses method.
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
static TrafficControlHelper Default(std::size_t nTxQueues=1)
void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, Args &&... args)
Helper function used to add the given number of internal queues (of the given type and with the given...
ClassIdList AddQueueDiscClasses(uint16_t handle, uint16_t count, const std::string &type, Args &&... args)
Helper function used to add the given number of queue disc classes (of the given type and with the gi...
uint16_t AddChildQueueDisc(uint16_t handle, uint16_t classId, const std::string &type, Args &&... args)
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...
void AddPacketFilter(uint16_t handle, const std::string &type, Args &&... args)
Helper function used to add a packet filter (of the given type and with the given attributes) to the ...
std::vector< QueueDiscFactory > m_queueDiscFactory
QueueDisc factory, stores the configuration of all the queue discs.
HandleList DoAddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, ObjectFactory factory)
Actual implementation of the AddChildQueueDiscs method.
HandleList AddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, const std::string &type, Args &&... args)
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...
Every class exported by the ns3 library is enclosed in the ns3 namespace.