A Discrete-Event Network Simulator
API
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 
22 #include "ns3/net-device-container.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/queue-disc-container.h"
25 #include "ns3/queue.h"
26 
27 #include <map>
28 #include <string>
29 #include <vector>
30 
31 namespace ns3
32 {
33 
41 {
42  public:
49 
51  {
52  }
53 
54  // Delete default constructor to avoid misuse
55  QueueDiscFactory() = delete;
56 
62  void AddInternalQueue(ObjectFactory factory);
63 
69  void AddPacketFilter(ObjectFactory factory);
70 
77  uint16_t AddQueueDiscClass(ObjectFactory factory);
78 
85  void SetChildQueueDisc(uint16_t classId, uint16_t handle);
86 
93  Ptr<QueueDisc> CreateQueueDisc(const std::vector<Ptr<QueueDisc>>& queueDiscs);
94 
95  private:
99  std::vector<ObjectFactory> m_internalQueuesFactory;
101  std::vector<ObjectFactory> m_packetFiltersFactory;
103  std::vector<ObjectFactory> m_queueDiscClassesFactory;
105  std::map<uint16_t, uint16_t> m_classIdChildHandleMap;
106 };
107 
118 {
119  public:
125 
127  {
128  }
129 
138  static TrafficControlHelper Default(std::size_t nTxQueues = 1);
139 
150  template <typename... Args>
151  uint16_t SetRootQueueDisc(const std::string& type, Args&&... args);
152 
163  template <typename... Args>
164  void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, Args&&... args);
165 
175  template <typename... Args>
176  void AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args);
177 
181  typedef std::vector<uint16_t> ClassIdList;
182 
194  template <typename... Args>
195  ClassIdList AddQueueDiscClasses(uint16_t handle,
196  uint16_t count,
197  const std::string& type,
198  Args&&... args);
199 
212  template <typename... Args>
213  uint16_t AddChildQueueDisc(uint16_t handle,
214  uint16_t classId,
215  const std::string& type,
216  Args&&... args);
217 
221  typedef std::vector<uint16_t> HandleList;
222 
235  template <typename... Args>
236  HandleList AddChildQueueDiscs(uint16_t handle,
237  const ClassIdList& classes,
238  const std::string& type,
239  Args&&... args);
240 
249  template <typename... Args>
250  void SetQueueLimits(std::string type, Args&&... args);
251 
268 
279 
293 
306  void Uninstall(Ptr<NetDevice> d);
307 
308  private:
315  uint16_t DoSetRootQueueDisc(ObjectFactory factory);
316 
324  void DoAddInternalQueues(uint16_t handle, uint16_t count, ObjectFactory factory);
325 
332  void DoAddPacketFilter(uint16_t handle, ObjectFactory factory);
333 
342  ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory);
343 
352  uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory);
353 
362  HandleList DoAddChildQueueDiscs(uint16_t handle,
363  const ClassIdList& classes,
364  ObjectFactory factory);
365 
367  std::vector<QueueDiscFactory> m_queueDiscFactory;
369  std::vector<Ptr<QueueDisc>> m_queueDiscs;
372 };
373 
374 } // namespace ns3
375 
376 /***************************************************************
377  * Implementation of the templates declared above.
378  ***************************************************************/
379 
380 namespace ns3
381 {
382 
383 template <typename... Args>
384 uint16_t
385 TrafficControlHelper::SetRootQueueDisc(const std::string& type, Args&&... args)
386 {
388 }
389 
390 template <typename... Args>
391 void
393  uint16_t count,
394  std::string type,
395  Args&&... args)
396 {
398  DoAddInternalQueues(handle, count, ObjectFactory(type, args...));
399 }
400 
401 template <typename... Args>
402 void
403 TrafficControlHelper::AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args)
404 {
406 }
407 
408 template <typename... Args>
411  uint16_t count,
412  const std::string& type,
413  Args&&... args)
414 {
415  return DoAddQueueDiscClasses(handle, count, ObjectFactory(type, args...));
416 }
417 
418 template <typename... Args>
419 uint16_t
421  uint16_t classId,
422  const std::string& type,
423  Args&&... args)
424 {
425  return DoAddChildQueueDisc(handle, classId, ObjectFactory(type, args...));
426 }
427 
428 template <typename... Args>
431  const ClassIdList& classes,
432  const std::string& type,
433  Args&&... args)
434 {
435  return DoAddChildQueueDiscs(handle, classes, ObjectFactory(type, args...));
436 }
437 
438 template <typename... Args>
439 void
441 {
444 }
445 
446 } // namespace ns3
447 
448 #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.
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 ...
Ptr< QueueDisc > CreateQueueDisc(const std::vector< Ptr< QueueDisc >> &queueDiscs)
Create a queue disc with the currently stored configuration.
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.
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.