A Discrete-Event Network Simulator
API
traffic-control-helper.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Universita' degli Studi di Napoli Federico II
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Stefano Avallone <stavallo@unina.it>
19  */
20 #ifndef TRAFFIC_CONTROL_HELPER_H
21 #define TRAFFIC_CONTROL_HELPER_H
22 
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include "ns3/object-factory.h"
27 #include "ns3/net-device-container.h"
28 #include "ns3/queue-disc-container.h"
29 #include "ns3/queue.h"
30 
31 namespace ns3 {
32 
40 {
41 public:
48 
49  virtual ~QueueDiscFactory () {}
50 
56  void AddInternalQueue (ObjectFactory factory);
57 
63  void AddPacketFilter (ObjectFactory factory);
64 
71  uint16_t AddQueueDiscClass (ObjectFactory factory);
72 
79  void SetChildQueueDisc (uint16_t classId, uint16_t handle);
80 
87  Ptr<QueueDisc> CreateQueueDisc (const std::vector<Ptr<QueueDisc> > & queueDiscs);
88 
89 private:
96 
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 
109 
120 {
121 public:
127  virtual ~TrafficControlHelper () {}
128 
137  static TrafficControlHelper Default (std::size_t nTxQueues = 1);
138 
149  template <typename... Args>
150  uint16_t SetRootQueueDisc (const std::string& type, Args&&... args);
151 
162  template <typename... Args>
163  void AddInternalQueues (uint16_t handle, uint16_t count, std::string type, Args&&... args);
164 
174  template <typename... Args>
175  void AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args);
176 
180  typedef std::vector<uint16_t> ClassIdList;
181 
193  template <typename... Args>
194  ClassIdList AddQueueDiscClasses (uint16_t handle, uint16_t count, const std::string& type, Args&&... args);
195 
208  template <typename... Args>
209  uint16_t AddChildQueueDisc (uint16_t handle, uint16_t classId, const std::string& type, Args&&... args);
210 
214  typedef std::vector<uint16_t> HandleList;
215 
228  template <typename... Args>
229  HandleList AddChildQueueDiscs (uint16_t handle, const ClassIdList &classes,
230  const std::string& type, Args&&... args);
231 
240  template <typename... Args>
241  void SetQueueLimits (std::string type, Args&&... args);
242 
259 
270 
277  void Uninstall (NetDeviceContainer c);
278 
285  void Uninstall (Ptr<NetDevice> d);
286 
287 private:
294  uint16_t DoSetRootQueueDisc (ObjectFactory factory);
295 
303  void DoAddInternalQueues (uint16_t handle, uint16_t count, ObjectFactory factory);
304 
311  void DoAddPacketFilter (uint16_t handle, ObjectFactory factory);
312 
321  ClassIdList DoAddQueueDiscClasses (uint16_t handle, uint16_t count, ObjectFactory factory);
322 
331  uint16_t DoAddChildQueueDisc (uint16_t handle, uint16_t classId, ObjectFactory factory);
332 
341  HandleList DoAddChildQueueDiscs (uint16_t handle, const ClassIdList &classes, ObjectFactory factory);
342 
344  std::vector<QueueDiscFactory> m_queueDiscFactory;
346  std::vector<Ptr<QueueDisc> > m_queueDiscs;
349 };
350 
351 } // namespace ns3
352 
353 
354 /***************************************************************
355  * Implementation of the templates declared above.
356  ***************************************************************/
357 
358 namespace ns3 {
359 
360 template <typename... Args>
361 uint16_t
362 TrafficControlHelper::SetRootQueueDisc (const std::string& type, Args&&... args)
363 {
364  return DoSetRootQueueDisc (ObjectFactory (type, args...));
365 }
366 
367 template <typename... Args>
368 void
369 TrafficControlHelper::AddInternalQueues (uint16_t handle, uint16_t count,
370  std::string type, Args&&... args)
371 {
372  QueueBase::AppendItemTypeIfNotPresent (type, "QueueDiscItem");
373  DoAddInternalQueues (handle, count, ObjectFactory (type, args...));
374 }
375 
376 template <typename... Args>
377 void
378 TrafficControlHelper::AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args)
379 {
380  DoAddPacketFilter (handle, ObjectFactory (type, args...));
381 }
382 
383 template <typename... Args>
385 TrafficControlHelper::AddQueueDiscClasses (uint16_t handle, uint16_t count,
386  const std::string& type, Args&&... args)
387 {
388  return DoAddQueueDiscClasses (handle, count, ObjectFactory (type, args...));
389 }
390 
391 template <typename... Args>
392 uint16_t
393 TrafficControlHelper::AddChildQueueDisc (uint16_t handle, uint16_t classId,
394  const std::string& type, Args&&... args)
395 {
396  return DoAddChildQueueDisc (handle, classId, ObjectFactory (type, args...));
397 }
398 
399 template <typename... Args>
401 TrafficControlHelper::AddChildQueueDiscs (uint16_t handle, const ClassIdList &classes,
402  const std::string& type, Args&&... args)
403 {
404  return DoAddChildQueueDiscs (handle, classes, ObjectFactory (type, args...));
405 }
406 
407 template <typename... Args>
408 void
409 TrafficControlHelper::SetQueueLimits (std::string type, Args&&... args)
410 {
412  m_queueLimitsFactory.Set (args...);
413 }
414 
415 } // namespace ns3
416 
417 #endif /* TRAFFIC_CONTROL_HELPER_H */
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition: net-device-container.h:42
ns3::TrafficControlHelper::SetRootQueueDisc
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.
Definition: traffic-control-helper.h:362
ns3::QueueDiscFactory::m_queueDiscClassesFactory
std::vector< ObjectFactory > m_queueDiscClassesFactory
Vector of factories to create queue disc classes.
Definition: traffic-control-helper.h:104
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::QueueDiscFactory::m_classIdChildHandleMap
std::map< uint16_t, uint16_t > m_classIdChildHandleMap
Map storing the associations between class IDs and child queue disc handles.
Definition: traffic-control-helper.h:106
ns3::QueueDiscFactory::AddPacketFilter
void AddPacketFilter(ObjectFactory factory)
Add a factory to create a packet filter.
Definition: traffic-control-helper.cc:46
ns3::TrafficControlHelper::DoAddQueueDiscClasses
ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory)
Actual implementation of the AddQueueDiscClasses method.
Definition: traffic-control-helper.cc:160
ns3::QueueBase::AppendItemTypeIfNotPresent
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
ns3::TrafficControlHelper::m_queueDiscs
std::vector< Ptr< QueueDisc > > m_queueDiscs
Vector of all the created queue discs.
Definition: traffic-control-helper.h:346
ns3::Ptr< QueueDisc >
ns3::QueueDiscFactory::AddQueueDiscClass
uint16_t AddQueueDiscClass(ObjectFactory factory)
Add a factory to create a queue disc class.
Definition: traffic-control-helper.cc:52
ns3::TrafficControlHelper::TrafficControlHelper
TrafficControlHelper()
Create a TrafficControlHelper to make life easier when creating QueueDisc objects.
Definition: traffic-control-helper.cc:105
ns3::TrafficControlHelper::AddChildQueueDiscs
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...
Definition: traffic-control-helper.h:401
ns3::TrafficControlHelper::SetQueueLimits
void SetQueueLimits(std::string type, Args &&... args)
Helper function used to add a queue limits object to the transmission queues of the devices.
Definition: traffic-control-helper.h:409
ns3::QueueDiscFactory::m_queueDiscFactory
ObjectFactory m_queueDiscFactory
Factory to create this queue disc.
Definition: traffic-control-helper.h:98
ns3::TrafficControlHelper::Install
QueueDiscContainer Install(NetDeviceContainer c)
Definition: traffic-control-helper.cc:248
ns3::QueueDiscContainer
Holds a vector of ns3::QueueDisc pointers.
Definition: queue-disc-container.h:45
ns3::TrafficControlHelper::DoSetRootQueueDisc
uint16_t DoSetRootQueueDisc(ObjectFactory factory)
Actual implementation of the SetRootQueueDisc method.
Definition: traffic-control-helper.cc:130
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition: object-factory.h:48
ns3::TrafficControlHelper::DoAddPacketFilter
void DoAddPacketFilter(uint16_t handle, ObjectFactory factory)
Actual implementation of the AddPacketFilter method.
Definition: traffic-control-helper.cc:151
ns3::TrafficControlHelper::DoAddInternalQueues
void DoAddInternalQueues(uint16_t handle, uint16_t count, ObjectFactory factory)
Actual implementation of the AddInternalQueues method.
Definition: traffic-control-helper.cc:139
ns3::TrafficControlHelper::DoAddChildQueueDiscs
HandleList DoAddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, ObjectFactory factory)
Actual implementation of the AddChildQueueDiscs method.
Definition: traffic-control-helper.cc:190
ns3::QueueDiscFactory::QueueDiscFactory
QueueDiscFactory()
Default constructor.
ns3::TrafficControlHelper::AddInternalQueues
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...
Definition: traffic-control-helper.h:369
ns3::QueueDiscFactory::SetChildQueueDisc
void SetChildQueueDisc(uint16_t classId, uint16_t handle)
Set the (child) queue disc to attach to a class.
Definition: traffic-control-helper.cc:59
ns3::QueueDiscFactory::CreateQueueDisc
Ptr< QueueDisc > CreateQueueDisc(const std::vector< Ptr< QueueDisc > > &queueDiscs)
Create a queue disc with the currently stored configuration.
Definition: traffic-control-helper.cc:67
ns3::TrafficControlHelper::Uninstall
void Uninstall(NetDeviceContainer c)
Definition: traffic-control-helper.cc:279
ns3::QueueDiscFactory::AddInternalQueue
void AddInternalQueue(ObjectFactory factory)
Add a factory to create an internal queue.
Definition: traffic-control-helper.cc:40
ns3::TrafficControlHelper
Build a set of QueueDisc objects.
Definition: traffic-control-helper.h:120
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition: object-factory.h:223
ns3::QueueDiscFactory::m_packetFiltersFactory
std::vector< ObjectFactory > m_packetFiltersFactory
Vector of factories to create packet filters.
Definition: traffic-control-helper.h:102
ns3::TrafficControlHelper::AddPacketFilter
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 ...
Definition: traffic-control-helper.h:378
ns3::QueueDiscFactory::~QueueDiscFactory
virtual ~QueueDiscFactory()
Definition: traffic-control-helper.h:49
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition: object-factory.cc:40
ns3::QueueDiscFactory
This class stores object factories required to create a queue disc and all of its components (packet ...
Definition: traffic-control-helper.h:40
ns3::QueueDiscFactory::m_internalQueuesFactory
std::vector< ObjectFactory > m_internalQueuesFactory
Vector of factories to create internal queues.
Definition: traffic-control-helper.h:100
ns3::TrafficControlHelper::AddQueueDiscClasses
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...
Definition: traffic-control-helper.h:385
ns3::TrafficControlHelper::~TrafficControlHelper
virtual ~TrafficControlHelper()
Definition: traffic-control-helper.h:127
ns3::TrafficControlHelper::AddChildQueueDisc
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...
Definition: traffic-control-helper.h:393
ns3::TrafficControlHelper::Default
static TrafficControlHelper Default(std::size_t nTxQueues=1)
Definition: traffic-control-helper.cc:110
ns3::TrafficControlHelper::HandleList
std::vector< uint16_t > HandleList
Container type for Handlers.
Definition: traffic-control-helper.h:214
ns3::TrafficControlHelper::m_queueDiscFactory
std::vector< QueueDiscFactory > m_queueDiscFactory
QueueDisc factory, stores the configuration of all the queue discs.
Definition: traffic-control-helper.h:344
ns3::TrafficControlHelper::ClassIdList
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
Definition: traffic-control-helper.h:180
ns3::TrafficControlHelper::m_queueLimitsFactory
ObjectFactory m_queueLimitsFactory
Factory to create a queue limits object.
Definition: traffic-control-helper.h:348
ns3::TrafficControlHelper::DoAddChildQueueDisc
uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory)
Actual implementation of the AddChildQueueDisc method.
Definition: traffic-control-helper.cc:177