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