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 "queue-disc-container.h"
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 
32 namespace 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 
307  void Uninstall(Ptr<NetDevice> d);
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 
381 namespace ns3
382 {
383 
384 template <typename... Args>
385 uint16_t
386 TrafficControlHelper::SetRootQueueDisc(const std::string& type, Args&&... args)
387 {
389 }
390 
391 template <typename... Args>
392 void
394  uint16_t count,
395  std::string type,
396  Args&&... args)
397 {
399  DoAddInternalQueues(handle, count, ObjectFactory(type, args...));
400 }
401 
402 template <typename... Args>
403 void
404 TrafficControlHelper::AddPacketFilter(uint16_t handle, const std::string& type, Args&&... args)
405 {
407 }
408 
409 template <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 
419 template <typename... Args>
420 uint16_t
422  uint16_t classId,
423  const std::string& type,
424  Args&&... args)
425 {
426  return DoAddChildQueueDisc(handle, classId, ObjectFactory(type, args...));
427 }
428 
429 template <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 
439 template <typename... Args>
440 void
442 {
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.
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.