A Discrete-Event Network Simulator
API
qkd-l4-traffic-control-layer.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 Natale Patriciello <natale.patriciello@gmail.com>
4  * 2016 Stefano Avallone <stavallo@unina.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Miralem Mehic <miralem.mehic@ieee.org>
20  */
21 
23 #include "ns3/log.h"
24 #include "ns3/object-vector.h"
25 #include "ns3/packet.h"
26 #include "ns3/queue-disc.h"
27 #include "ns3/qkd-queue-disc-item.h"
28 #include "ns3/ipv4-header.h"
29 #include "ns3/qkd-l4-pfifo-fast-queue-disc.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("QKDL4TrafficControlLayer");
34 
35 NS_OBJECT_ENSURE_REGISTERED (QKDL4TrafficControlLayer);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId ("ns3::QKDL4TrafficControlLayer")
41  .SetParent<Object> ()
42  .SetGroupName ("TrafficControl")
43  .AddConstructor<QKDL4TrafficControlLayer> ()
44  .AddAttribute ("RootQueueDiscList", "The list of root queue discs associated to this QKD Traffic Control layer.",
47  MakeObjectVectorChecker<QueueDisc> ())
48  ;
49  return tid;
50 }
51 
52 TypeId
54 {
55  return GetTypeId ();
56 }
57 
59  : Object ()
60 {
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION (this);
68  m_node = 0;
69  m_rootQueueDiscs.clear ();
70  m_handlers.clear ();
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this);
78 
79  //We have only one queue disc for all network devices!
80  //Yes, it is not a mistake. We have only one queue disc (with multiple internal queues) for all traffic
81  //This queue disc is located between L3 and L4, before IPv4 L3 layer!
82  m_rootQueueDiscs[0]->Initialize ();
83  m_rootQueueDiscs[0]->SetNode(m_node);
84 
85  /*
86  for (uint32_t j = 0; j < m_rootQueueDiscs.size (); j++)
87  {
88  if (m_rootQueueDiscs[j])
89  {
90  // initialize the queue disc
91  m_rootQueueDiscs[j]->Initialize ();
92  m_rootQueueDiscs[j]->SetNode(m_node);
93  }
94  }
95  */
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION (this);
103 
104  uint32_t index = m_rootQueueDiscs.size ();
105  NS_LOG_FUNCTION (this << "Node: " << m_node->GetId() << "QueueDisc:" << index);
106 
107  //We have only one queue disc for all network devices!
108  //Yes, it is not a mistake. We have only one queue disc (with multiple internal queues) for all traffic
109  //This queue disc is located between L3 and L4, before IPv4 L3 layer!
110  if(index == 0){
111  m_rootQueueDiscs.resize (index+1);
112  m_rootQueueDiscs[index] = qDisc;
113  }
114 
115 }
116 
119 {
120  NS_LOG_FUNCTION (this);
121 
122  NS_ASSERT_MSG (index < m_rootQueueDiscs.size () && m_rootQueueDiscs[index] != 0, "No root queue disc"
123  << " installed on node " << m_node);
124 
125  return m_rootQueueDiscs[index];
126 }
127 
128 void
130 {
131  for (uint32_t j = 0; j < m_rootQueueDiscs.size (); j++)
132  {
133  if (m_rootQueueDiscs[j])
134  {
135  // remove the root queue disc
136  m_rootQueueDiscs[j] = 0;
137  }
138  }
139 }
140 
141 void
143 {
144  NS_LOG_FUNCTION (this << node);
145  m_node = node;
146 }
147 
148 Ptr<Node>
150 {
151  NS_LOG_FUNCTION (this);
152  return m_node;
153 }
154 
155 void
157 {
158  NS_LOG_FUNCTION (this << m_node);
159  if (m_node == 0)
160  {
161  Ptr<Node> node = this->GetObject<Node> ();
162  //verify that it's a valid node and that
163  //the node was not set before
164  if (node != 0)
165  {
166  this->SetNode (node);
167  }
168  }
169  NS_LOG_FUNCTION (this << m_node);
171 }
172 
176 void
178  Ipv4Address source,
179  Ipv4Address destination,
180  uint8_t protocol,
181  Ptr<Ipv4Route> route)
182 {
183  NS_LOG_FUNCTION (this << p->GetUid() << source << destination << protocol << route);
184 
185  NS_LOG_DEBUG ("Protocol number " << protocol);
186 
187  Ptr<QKDQueueDiscItem> item = Create<QKDQueueDiscItem> (p, source, destination, protocol, route);
188  m_rootQueueDiscs[0]->Enqueue (item);
189  m_rootQueueDiscs[0]->Run ();
190 }
191 
195 void
197  Ipv4Address source,
198  Ipv4Address destination,
199  uint8_t protocol,
200  Ptr<Ipv4Route> route)
201 {
202  NS_LOG_FUNCTION (this << p->GetUid() << source << destination << protocol << route);
203 
204  if(m_downTarget.IsNull ()){
205  NS_LOG_FUNCTION(this << "m_downTarget on node " << m_node->GetId() << " is EMPTY!!!");
206  }else{
207  NS_LOG_FUNCTION(this << "m_downTarget on node " << m_node->GetId() << " is valid!");
208  m_downTarget (p, source, destination, protocol, route );
209  }
210 
211 }
212 
216 void
218 {
219  NS_LOG_FUNCTION (this << " on node " << m_node->GetId());
220  m_downTarget = callback;
221 }
222 
225 {
226  NS_LOG_FUNCTION (this);
227  return m_downTarget;
228 }
229 
230 } // namespace ns3
virtual void DoInitialize(void)
Initialize() implementation.
virtual void SetRootQueueDisc(Ptr< QueueDisc > qDisc)
This method can be used to set the root queue disc installed on a device.
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
IpL4Protocol::DownTargetCallback m_downTarget
Callback to send packets over IPv4.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void DeleteRootQueueDisc()
This method can be used to remove the root queue disc (and associated filters, classes and queues) in...
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
Called from upper layer (L4) to queue a packet for the transmission.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
IpL4Protocol::DownTargetCallback GetDownTarget(void) const
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
virtual void DoDispose(void)
Destructor implementation.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static TypeId GetTypeId(void)
Get the type ID.
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
Ptr< Node > GetNode()
Set node associated with this stack.
QueueDiscVector m_rootQueueDiscs
This vector stores the root queue discs installed on all the devices of the node. ...
void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
Define Down target which can be IPv4 or Virtual IPv4.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ProtocolHandlerList m_handlers
This map plays the role of the qdisc field of the netdev_queue struct in Linux.
Ptr< Node > m_node
The node this QKDL4TrafficControlLayer object is aggregated to.
virtual Ptr< QueueDisc > GetRootQueueDisc(uint32_t index)
This method can be used to get the root queue disc installed on a device.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
uint32_t GetId(void) const
Definition: node.cc:107
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
void DeliverToL3(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
FORWARD FROM QUEUE TO LOWER LAERS.
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:325
Container for a set of ns3::Object pointers.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID for the instance.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
a unique identifier for an interface.
Definition: type-id.h:58
void SetNode(Ptr< Node > node)
Set node associated with this stack.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
QKD Traffic control layer definition.