A Discrete-Event Network Simulator
API
qkd-l4-traffic-control-helper.cc
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  * Modified by: Miralem Mehic <miralem.mehic@ieee.org>
20  */
21 
22 #include "ns3/log.h"
23 #include "ns3/abort.h"
24 #include "ns3/queue-disc.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/pointer.h"
27 #include "ns3/qkd-l4-traffic-control-layer.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("QKDL4TrafficControlHelper");
33 
35 {
36 }
37 
40 {
42  uint16_t handle = helper.SetRootQueueDisc ("ns3::QKDL4PfifoFastQueueDisc");
43  helper.AddInternalQueues (handle, 3, "ns3::DropTailQueue", "MaxPackets", UintegerValue (1000));
44  helper.AddPacketFilter (handle, "ns3::PfifoFastQKDPacketFilter");
45  return helper;
46 }
47 
48 uint16_t
50  std::string n01, const AttributeValue& v01,
51  std::string n02, const AttributeValue& v02,
52  std::string n03, const AttributeValue& v03,
53  std::string n04, const AttributeValue& v04,
54  std::string n05, const AttributeValue& v05,
55  std::string n06, const AttributeValue& v06,
56  std::string n07, const AttributeValue& v07,
57  std::string n08, const AttributeValue& v08,
58  std::string n09, const AttributeValue& v09,
59  std::string n10, const AttributeValue& v10,
60  std::string n11, const AttributeValue& v11,
61  std::string n12, const AttributeValue& v12,
62  std::string n13, const AttributeValue& v13,
63  std::string n14, const AttributeValue& v14,
64  std::string n15, const AttributeValue& v15)
65 {
66  NS_ABORT_MSG_UNLESS (m_queueDiscFactory.empty (), "A root queue disc has been already added to this factory");
67 
68  ObjectFactory factory;
69  factory.SetTypeId (type);
70  factory.Set (n01, v01);
71  factory.Set (n02, v02);
72  factory.Set (n03, v03);
73  factory.Set (n04, v04);
74  factory.Set (n05, v05);
75  factory.Set (n06, v06);
76  factory.Set (n07, v07);
77  factory.Set (n08, v08);
78  factory.Set (n09, v09);
79  factory.Set (n10, v10);
80  factory.Set (n11, v11);
81  factory.Set (n12, v12);
82  factory.Set (n13, v13);
83  factory.Set (n14, v14);
84  factory.Set (n15, v15);
85 
86  m_queueDiscFactory.push_back (QueueDiscFactory (factory));
87  return 0;
88 }
89 
90 void
91 QKDL4TrafficControlHelper::AddInternalQueues (uint16_t handle, uint16_t count, std::string type,
92  std::string n01, const AttributeValue& v01,
93  std::string n02, const AttributeValue& v02,
94  std::string n03, const AttributeValue& v03,
95  std::string n04, const AttributeValue& v04,
96  std::string n05, const AttributeValue& v05,
97  std::string n06, const AttributeValue& v06,
98  std::string n07, const AttributeValue& v07,
99  std::string n08, const AttributeValue& v08)
100 {
101  NS_ABORT_MSG_IF (handle >= m_queueDiscFactory.size (), "A queue disc with handle "
102  << handle << " does not exist");
103 
104 
105  ObjectFactory factory;
106  factory.SetTypeId (type);
107  factory.Set (n01, v01);
108  factory.Set (n02, v02);
109  factory.Set (n03, v03);
110  factory.Set (n04, v04);
111  factory.Set (n05, v05);
112  factory.Set (n06, v06);
113  factory.Set (n07, v07);
114  factory.Set (n08, v08);
115 
116  for (int i = 0; i < count; i++)
117  {
118  m_queueDiscFactory[handle].AddInternalQueue (factory);
119  }
120 }
121 
122 void
123 QKDL4TrafficControlHelper::AddPacketFilter (uint16_t handle, std::string type,
124  std::string n01, const AttributeValue& v01,
125  std::string n02, const AttributeValue& v02,
126  std::string n03, const AttributeValue& v03,
127  std::string n04, const AttributeValue& v04,
128  std::string n05, const AttributeValue& v05,
129  std::string n06, const AttributeValue& v06,
130  std::string n07, const AttributeValue& v07,
131  std::string n08, const AttributeValue& v08)
132 {
133  NS_ABORT_MSG_IF (handle >= m_queueDiscFactory.size (), "A queue disc with handle "
134  << handle << " does not exist");
135 
136  ObjectFactory factory;
137  factory.SetTypeId (type);
138  factory.Set (n01, v01);
139  factory.Set (n02, v02);
140  factory.Set (n03, v03);
141  factory.Set (n04, v04);
142  factory.Set (n05, v05);
143  factory.Set (n06, v06);
144  factory.Set (n07, v07);
145  factory.Set (n08, v08);
146 
147  m_queueDiscFactory[handle].AddPacketFilter (factory);
148 }
149 
151 QKDL4TrafficControlHelper::AddQueueDiscClasses (uint16_t handle, uint16_t count, std::string type,
152  std::string n01, const AttributeValue& v01,
153  std::string n02, const AttributeValue& v02,
154  std::string n03, const AttributeValue& v03,
155  std::string n04, const AttributeValue& v04,
156  std::string n05, const AttributeValue& v05,
157  std::string n06, const AttributeValue& v06,
158  std::string n07, const AttributeValue& v07,
159  std::string n08, const AttributeValue& v08)
160 {
161  NS_ABORT_MSG_IF (handle >= m_queueDiscFactory.size (), "A queue disc with handle "
162  << handle << " does not exist");
163 
164  ObjectFactory factory;
165  factory.SetTypeId (type);
166  factory.Set (n01, v01);
167  factory.Set (n02, v02);
168  factory.Set (n03, v03);
169  factory.Set (n04, v04);
170  factory.Set (n05, v05);
171  factory.Set (n06, v06);
172  factory.Set (n07, v07);
173  factory.Set (n08, v08);
174 
176  uint16_t classId;
177 
178  for (int i = 0; i < count; i++)
179  {
180  classId = m_queueDiscFactory[handle].AddQueueDiscClass (factory);
181  list.push_back (classId);
182  }
183  return list;
184 }
185 
186 uint16_t
187 QKDL4TrafficControlHelper::AddChildQueueDisc (uint16_t handle, uint16_t classId, std::string type,
188  std::string n01, const AttributeValue& v01,
189  std::string n02, const AttributeValue& v02,
190  std::string n03, const AttributeValue& v03,
191  std::string n04, const AttributeValue& v04,
192  std::string n05, const AttributeValue& v05,
193  std::string n06, const AttributeValue& v06,
194  std::string n07, const AttributeValue& v07,
195  std::string n08, const AttributeValue& v08,
196  std::string n09, const AttributeValue& v09,
197  std::string n10, const AttributeValue& v10,
198  std::string n11, const AttributeValue& v11,
199  std::string n12, const AttributeValue& v12,
200  std::string n13, const AttributeValue& v13,
201  std::string n14, const AttributeValue& v14,
202  std::string n15, const AttributeValue& v15)
203 {
204  NS_ABORT_MSG_IF (handle >= m_queueDiscFactory.size (), "A queue disc with handle "
205  << handle << " does not exist");
206 
207  ObjectFactory factory;
208  factory.SetTypeId (type);
209  factory.Set (n01, v01);
210  factory.Set (n02, v02);
211  factory.Set (n03, v03);
212  factory.Set (n04, v04);
213  factory.Set (n05, v05);
214  factory.Set (n06, v06);
215  factory.Set (n07, v07);
216  factory.Set (n08, v08);
217  factory.Set (n09, v09);
218  factory.Set (n10, v10);
219  factory.Set (n11, v11);
220  factory.Set (n12, v12);
221  factory.Set (n13, v13);
222  factory.Set (n14, v14);
223  factory.Set (n15, v15);
224 
225  uint16_t childHandle = m_queueDiscFactory.size ();
226  m_queueDiscFactory.push_back (QueueDiscFactory (factory));
227  m_queueDiscFactory[handle].SetChildQueueDisc (classId, childHandle);
228 
229  return childHandle;
230 }
231 
234  std::string type,
235  std::string n01, const AttributeValue& v01,
236  std::string n02, const AttributeValue& v02,
237  std::string n03, const AttributeValue& v03,
238  std::string n04, const AttributeValue& v04,
239  std::string n05, const AttributeValue& v05,
240  std::string n06, const AttributeValue& v06,
241  std::string n07, const AttributeValue& v07,
242  std::string n08, const AttributeValue& v08,
243  std::string n09, const AttributeValue& v09,
244  std::string n10, const AttributeValue& v10,
245  std::string n11, const AttributeValue& v11,
246  std::string n12, const AttributeValue& v12,
247  std::string n13, const AttributeValue& v13,
248  std::string n14, const AttributeValue& v14,
249  std::string n15, const AttributeValue& v15)
250 {
252  for (ClassIdList::const_iterator c = classes.begin (); c != classes.end (); c++)
253  {
254  uint16_t childHandle = AddChildQueueDisc (handle, *c, type, n01, v01, n02, v02, n03, v03,
255  n04, v04, n05, v05, n06, v06, n07, v07, n08, v08, n09, v09,
256  n10, v10, n11, v11, n12, v12, n13, v13, n14, v14, n15, v15);
257  list.push_back (childHandle);
258  }
259  return list;
260 }
261 
262 void
264  std::string n01, const AttributeValue& v01,
265  std::string n02, const AttributeValue& v02,
266  std::string n03, const AttributeValue& v03,
267  std::string n04, const AttributeValue& v04,
268  std::string n05, const AttributeValue& v05,
269  std::string n06, const AttributeValue& v06,
270  std::string n07, const AttributeValue& v07,
271  std::string n08, const AttributeValue& v08)
272 {
274  m_queueLimitsFactory.Set (n01, v01);
275  m_queueLimitsFactory.Set (n02, v02);
276  m_queueLimitsFactory.Set (n03, v03);
277  m_queueLimitsFactory.Set (n04, v04);
278  m_queueLimitsFactory.Set (n05, v05);
279  m_queueLimitsFactory.Set (n06, v06);
280  m_queueLimitsFactory.Set (n07, v07);
281  m_queueLimitsFactory.Set (n08, v08);
282 }
283 
286 {
287  NS_LOG_FUNCTION(this << node->GetId());
288 
289  QueueDiscContainer container;
290 
291  // A QKDL4TrafficControlLayer object is aggregated by the InternetStackHelper, but check
292  // anyway because a queue disc has no effect without a QKDL4TrafficControlLayer object
294  NS_ASSERT (tc != 0);
295 
296  // Start from an empty vector of queue discs
297  m_queueDiscs.clear ();
298  m_queueDiscs.resize (m_queueDiscFactory.size ());
299 
300  // Create queue discs (from leaves to root)
301  for (int i = m_queueDiscFactory.size () - 1; i >= 0; i--)
302  {
303  Ptr<QueueDisc> q = m_queueDiscFactory[i].CreateQueueDisc (m_queueDiscs);
304  m_queueDiscs[i] = q;
305  container.Add (q);
306  }
307 
308  // Set the root queue disc (if any has been created) on the device
309  if (!m_queueDiscs.empty () && m_queueDiscs[0])
310  {
311  tc->SetRootQueueDisc (m_queueDiscs[0]);
312  }
313 
314  return container;
315 }
316 
317 
318 void
320 {
322  NS_ASSERT (tc != 0);
323 
324  tc->DeleteRootQueueDisc ();
325 }
326 
327 
328 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void AddInternalQueues(uint16_t handle, uint16_t count, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add the given number of internal queues (of the given type and with the given...
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Build a set of QueueDisc objects.
Hold a value for an Attribute.
Definition: attribute.h:68
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
QKDL4TrafficControlHelper()
Create a QKDL4TrafficControlHelper to make life easier when creating QueueDisc objects.
uint16_t SetRootQueueDisc(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to set a root queue disc of the given type and with the given attributes...
std::vector< Ptr< QueueDisc > > m_queueDiscs
Vector of all the created queue discs.
ObjectFactory m_queueLimitsFactory
Factory to create a queue limits object.
Holds a vector of ns3::QueueDisc pointers.
Hold an unsigned integer type.
Definition: uinteger.h:44
#define list
std::vector< QueueDiscFactory > m_queueDiscFactory
QueueDisc factory, stores the configuration of all the queue discs.
void Uninstall(NetDeviceContainer c)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint16_t AddChildQueueDisc(uint16_t handle, uint16_t classId, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...
static QKDL4TrafficControlHelper Default(void)
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
Instantiate subclasses of ns3::Object.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition: abort.h:144
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
uint32_t GetId(void) const
Definition: node.cc:107
void AddPacketFilter(uint16_t handle, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add a packet filter (of the given type and with the given attributes) to the ...
ClassIdList AddQueueDiscClasses(uint16_t handle, uint16_t count, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add the given number of queue disc classes (of the given type and with the gi...
This class stores object factories required to create a queue disc and all of its components (packet ...
std::vector< uint16_t > HandleList
Container type for Handlers.
std::vector< uint16_t > ClassIdList
Container type for Class IDs.
void SetQueueLimits(std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue())
Helper function used to add a queue limits object to the transmission queues of the devices...
QueueDiscContainer Install(NetDeviceContainer c)
QKD Traffic control layer definition.
HandleList AddChildQueueDiscs(uint16_t handle, const ClassIdList &classes, std::string type, std::string n01="", const AttributeValue &v01=EmptyAttributeValue(), std::string n02="", const AttributeValue &v02=EmptyAttributeValue(), std::string n03="", const AttributeValue &v03=EmptyAttributeValue(), std::string n04="", const AttributeValue &v04=EmptyAttributeValue(), std::string n05="", const AttributeValue &v05=EmptyAttributeValue(), std::string n06="", const AttributeValue &v06=EmptyAttributeValue(), std::string n07="", const AttributeValue &v07=EmptyAttributeValue(), std::string n08="", const AttributeValue &v08=EmptyAttributeValue(), std::string n09="", const AttributeValue &v09=EmptyAttributeValue(), std::string n10="", const AttributeValue &v10=EmptyAttributeValue(), std::string n11="", const AttributeValue &v11=EmptyAttributeValue(), std::string n12="", const AttributeValue &v12=EmptyAttributeValue(), std::string n13="", const AttributeValue &v13=EmptyAttributeValue(), std::string n14="", const AttributeValue &v14=EmptyAttributeValue(), std::string n15="", const AttributeValue &v15=EmptyAttributeValue())
Helper function used to attach a child queue disc (of the given type and with the given attributes) t...