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
31namespace ns3 {
32
40{
41public:
48
49 virtual ~QueueDiscFactory () {}
50
51 // Delete default constructor to avoid misuse
52 QueueDiscFactory () = delete;
53
59 void AddInternalQueue (ObjectFactory factory);
60
66 void AddPacketFilter (ObjectFactory factory);
67
74 uint16_t AddQueueDiscClass (ObjectFactory factory);
75
82 void SetChildQueueDisc (uint16_t classId, uint16_t handle);
83
90 Ptr<QueueDisc> CreateQueueDisc (const std::vector<Ptr<QueueDisc> > & queueDiscs);
91
92private:
96 std::vector<ObjectFactory> m_internalQueuesFactory;
98 std::vector<ObjectFactory> m_packetFiltersFactory;
100 std::vector<ObjectFactory> m_queueDiscClassesFactory;
102 std::map<uint16_t, uint16_t> m_classIdChildHandleMap;
103};
104
105
116{
117public:
124
133 static TrafficControlHelper Default (std::size_t nTxQueues = 1);
134
145 template <typename... Args>
146 uint16_t SetRootQueueDisc (const std::string& type, Args&&... args);
147
158 template <typename... Args>
159 void AddInternalQueues (uint16_t handle, uint16_t count, std::string type, Args&&... args);
160
170 template <typename... Args>
171 void AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args);
172
176 typedef std::vector<uint16_t> ClassIdList;
177
189 template <typename... Args>
190 ClassIdList AddQueueDiscClasses (uint16_t handle, uint16_t count, const std::string& type, Args&&... args);
191
204 template <typename... Args>
205 uint16_t AddChildQueueDisc (uint16_t handle, uint16_t classId, const std::string& type, Args&&... args);
206
210 typedef std::vector<uint16_t> HandleList;
211
224 template <typename... Args>
225 HandleList AddChildQueueDiscs (uint16_t handle, const ClassIdList &classes,
226 const std::string& type, Args&&... args);
227
236 template <typename... Args>
237 void SetQueueLimits (std::string type, Args&&... args);
238
255
266
280
293 void Uninstall (Ptr<NetDevice> d);
294
295private:
302 uint16_t DoSetRootQueueDisc (ObjectFactory factory);
303
311 void DoAddInternalQueues (uint16_t handle, uint16_t count, ObjectFactory factory);
312
319 void DoAddPacketFilter (uint16_t handle, ObjectFactory factory);
320
329 ClassIdList DoAddQueueDiscClasses (uint16_t handle, uint16_t count, ObjectFactory factory);
330
339 uint16_t DoAddChildQueueDisc (uint16_t handle, uint16_t classId, ObjectFactory factory);
340
349 HandleList DoAddChildQueueDiscs (uint16_t handle, const ClassIdList &classes, ObjectFactory factory);
350
352 std::vector<QueueDiscFactory> m_queueDiscFactory;
354 std::vector<Ptr<QueueDisc> > m_queueDiscs;
357};
358
359} // namespace ns3
360
361
362/***************************************************************
363 * Implementation of the templates declared above.
364 ***************************************************************/
365
366namespace ns3 {
367
368template <typename... Args>
369uint16_t
370TrafficControlHelper::SetRootQueueDisc (const std::string& type, Args&&... args)
371{
373}
374
375template <typename... Args>
376void
377TrafficControlHelper::AddInternalQueues (uint16_t handle, uint16_t count,
378 std::string type, Args&&... args)
379{
381 DoAddInternalQueues (handle, count, ObjectFactory (type, args...));
382}
383
384template <typename... Args>
385void
386TrafficControlHelper::AddPacketFilter (uint16_t handle, const std::string& type, Args&&... args)
387{
389}
390
391template <typename... Args>
393TrafficControlHelper::AddQueueDiscClasses (uint16_t handle, uint16_t count,
394 const std::string& type, Args&&... args)
395{
396 return DoAddQueueDiscClasses (handle, count, ObjectFactory (type, args...));
397}
398
399template <typename... Args>
400uint16_t
401TrafficControlHelper::AddChildQueueDisc (uint16_t handle, uint16_t classId,
402 const std::string& type, Args&&... args)
403{
404 return DoAddChildQueueDisc (handle, classId, ObjectFactory (type, args...));
405}
406
407template <typename... Args>
410 const std::string& type, Args&&... args)
411{
412 return DoAddChildQueueDiscs (handle, classes, ObjectFactory (type, args...));
413}
414
415template <typename... Args>
416void
418{
421}
422
423} // namespace ns3
424
425#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 ...
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.