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
42{
43 public:
50
52 {
53 }
54
55 // Delete default constructor to avoid misuse
56 QueueDiscFactory() = delete;
57
63 void AddInternalQueue(ObjectFactory factory);
64
70 void AddPacketFilter(ObjectFactory factory);
71
78 uint16_t AddQueueDiscClass(ObjectFactory factory);
79
86 void SetChildQueueDisc(uint16_t classId, uint16_t handle);
87
94 Ptr<QueueDisc> CreateQueueDisc(const std::vector<Ptr<QueueDisc>>& queueDiscs);
95
96 private:
100 std::vector<ObjectFactory> m_internalQueuesFactory;
102 std::vector<ObjectFactory> m_packetFiltersFactory;
104 std::vector<ObjectFactory> m_queueDiscClassesFactory;
106 std::map<uint16_t, uint16_t> m_classIdChildHandleMap;
107};
108
119{
120 public:
126
128 {
129 }
130
139 static TrafficControlHelper Default(std::size_t nTxQueues = 1);
140
151 template <typename... Args>
152 uint16_t SetRootQueueDisc(const std::string& type, Args&&... args);
153
164 template <typename... Args>
165 void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, Args&&... args);
166
176 template <typename... Args>
177 void AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args);
178
182 typedef std::vector<uint16_t> ClassIdList;
183
195 template <typename... Args>
196 ClassIdList AddQueueDiscClasses(uint16_t handle,
197 uint16_t count,
198 const std::string& type,
199 Args&&... args);
200
213 template <typename... Args>
214 uint16_t AddChildQueueDisc(uint16_t handle,
215 uint16_t classId,
216 const std::string& type,
217 Args&&... args);
218
222 typedef std::vector<uint16_t> HandleList;
223
236 template <typename... Args>
237 HandleList AddChildQueueDiscs(uint16_t handle,
238 const ClassIdList& classes,
239 const std::string& type,
240 Args&&... args);
241
250 template <typename... Args>
251 void SetQueueLimits(std::string type, Args&&... args);
252
269
280
294
308
309 private:
316 uint16_t DoSetRootQueueDisc(ObjectFactory factory);
317
325 void DoAddInternalQueues(uint16_t handle, uint16_t count, ObjectFactory factory);
326
333 void DoAddPacketFilter(uint16_t handle, ObjectFactory factory);
334
343 ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory);
344
353 uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory);
354
363 HandleList DoAddChildQueueDiscs(uint16_t handle,
364 const ClassIdList& classes,
365 ObjectFactory factory);
366
368 std::vector<QueueDiscFactory> m_queueDiscFactory;
370 std::vector<Ptr<QueueDisc>> m_queueDiscs;
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:78
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.