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 
136  static TrafficControlHelper Default (std::size_t nTxQueues = 1);
137 
148  template <typename... Args>
149  uint16_t SetRootQueueDisc (const std::string& type, Args&&... args);
150 
161  template <typename... Args>
162  void AddInternalQueues (uint16_t handle, uint16_t count, std::string type, Args&&... args);
163 
173  template <typename... Args>
174  void AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args);
175 
179  typedef std::vector<uint16_t> ClassIdList;
180 
192  template <typename... Args>
193  ClassIdList AddQueueDiscClasses (uint16_t handle, uint16_t count, const std::string& type, Args&&... args);
194 
207  template <typename... Args>
208  uint16_t AddChildQueueDisc (uint16_t handle, uint16_t classId, const std::string& type, Args&&... args);
209 
213  typedef std::vector<uint16_t> HandleList;
214 
227  template <typename... Args>
228  HandleList AddChildQueueDiscs (uint16_t handle, const ClassIdList &classes,
229  const std::string& type, Args&&... args);
230 
239  template <typename... Args>
240  void SetQueueLimits (std::string type, Args&&... args);
241 
258 
269 
276  void Uninstall (NetDeviceContainer c);
277 
284  void Uninstall (Ptr<NetDevice> d);
285 
286 private:
292  uint16_t DoSetRootQueueDisc (ObjectFactory factory);
293 
301  void DoAddInternalQueues (uint16_t handle, uint16_t count, ObjectFactory factory);
302 
309  void DoAddPacketFilter (uint16_t handle, ObjectFactory factory);
310 
319  ClassIdList DoAddQueueDiscClasses (uint16_t handle, uint16_t count, ObjectFactory factory);
320 
329  uint16_t DoAddChildQueueDisc (uint16_t handle, uint16_t classId, ObjectFactory factory);
330 
339  HandleList DoAddChildQueueDiscs (uint16_t handle, const ClassIdList &classes, ObjectFactory factory);
340 
342  std::vector<QueueDiscFactory> m_queueDiscFactory;
344  std::vector<Ptr<QueueDisc> > m_queueDiscs;
347 };
348 
349 } // namespace ns3
350 
351 
352 /***************************************************************
353  * Implementation of the templates declared above.
354  ***************************************************************/
355 
356 namespace ns3 {
357 
358 template <typename... Args>
359 uint16_t
360 TrafficControlHelper::SetRootQueueDisc (const std::string& type, Args&&... args)
361 {
362  return DoSetRootQueueDisc (ObjectFactory (type, args...));
363 }
364 
365 template <typename... Args>
366 void
367 TrafficControlHelper::AddInternalQueues (uint16_t handle, uint16_t count,
368  std::string type, Args&&... args)
369 {
370  QueueBase::AppendItemTypeIfNotPresent (type, "QueueDiscItem");
371  DoAddInternalQueues (handle, count, ObjectFactory (type, args...));
372 }
373 
374 template <typename... Args>
375 void
376 TrafficControlHelper::AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args)
377 {
378  DoAddPacketFilter (handle, ObjectFactory (type, args...));
379 }
380 
381 template <typename... Args>
383 TrafficControlHelper::AddQueueDiscClasses (uint16_t handle, uint16_t count,
384  const std::string& type, Args&&... args)
385 {
386  return DoAddQueueDiscClasses (handle, count, ObjectFactory (type, args...));
387 }
388 
389 template <typename... Args>
390 uint16_t
391 TrafficControlHelper::AddChildQueueDisc (uint16_t handle, uint16_t classId,
392  const std::string& type, Args&&... args)
393 {
394  return DoAddChildQueueDisc (handle, classId, ObjectFactory (type, args...));
395 }
396 
397 template <typename... Args>
399 TrafficControlHelper::AddChildQueueDiscs (uint16_t handle, const ClassIdList &classes,
400  const std::string& type, Args&&... args)
401 {
402  return DoAddChildQueueDiscs (handle, classes, ObjectFactory (type, args...));
403 }
404 
405 template <typename... Args>
406 void
407 TrafficControlHelper::SetQueueLimits (std::string type, Args&&... args)
408 {
410  m_queueLimitsFactory.Set (args...);
411 }
412 
413 } // namespace ns3
414 
415 #endif /* TRAFFIC_CONTROL_HELPER_H */
QueueDiscContainer Install(NetDeviceContainer c)
QueueDiscFactory()
Default constructor.
ClassIdList DoAddQueueDiscClasses(uint16_t handle, uint16_t count, ObjectFactory factory)
Actual implementation of the AddQueueDiscClasses method.
void SetQueueLimits(std::string type, Args &&... args)
Helper function used to add a queue limits object to the transmission queues of the devices...
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< ObjectFactory > m_queueDiscClassesFactory
Vector of factories to create queue disc classes.
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.
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...
std::vector< Ptr< QueueDisc > > m_queueDiscs
Vector of all the created queue discs.
void Uninstall(NetDeviceContainer c)
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 &#39;>&#39;. ...
Definition: queue.cc:73
void SetChildQueueDisc(uint16_t classId, uint16_t handle)
Set the (child) queue disc to attach to a class.
Holds a vector of ns3::QueueDisc pointers.
ObjectFactory m_queueDiscFactory
Factory to create this queue disc.
TrafficControlHelper()
Create a TrafficControlHelper to make life easier when creating QueueDisc objects.
holds a vector of ns3::NetDevice pointers
Build a set of QueueDisc objects.
Ptr< QueueDisc > CreateQueueDisc(const std::vector< Ptr< QueueDisc > > &queueDiscs)
Create a queue disc with the currently stored configuration.
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...
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
uint16_t AddQueueDiscClass(ObjectFactory factory)
Add a factory to create a queue disc class.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TrafficControlHelper Default(std::size_t nTxQueues=1)
std::vector< ObjectFactory > m_internalQueuesFactory
Vector of factories to create internal queues.
void AddInternalQueue(ObjectFactory factory)
Add a factory to create an internal queue.
ObjectFactory m_queueLimitsFactory
Factory to create a queue limits object.
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...
void AddPacketFilter(ObjectFactory factory)
Add a factory to create a packet filter.
Instantiate subclasses of ns3::Object.
std::vector< ObjectFactory > m_packetFiltersFactory
Vector of factories to create packet filters.
std::vector< QueueDiscFactory > m_queueDiscFactory
QueueDisc factory, stores the configuration of all the queue discs.
std::map< uint16_t, uint16_t > m_classIdChildHandleMap
Map storing the associations between class IDs and child queue disc handles.
uint16_t DoSetRootQueueDisc(ObjectFactory factory)
Actual implementation of the SetRootQueueDisc method.
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 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...
This class stores object factories required to create a queue disc and all of its components (packet ...
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.
uint16_t DoAddChildQueueDisc(uint16_t handle, uint16_t classId, ObjectFactory factory)
Actual implementation of the AddChildQueueDisc method.
HandleList DoAddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, ObjectFactory factory)
Actual implementation of the AddChildQueueDiscs method.
std::vector< uint16_t > HandleList
Container type for Handlers.