A Discrete-Event Network Simulator
API
qkd-manager.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 LIPTEL.ieee.org
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: Miralem Mehic <miralem.mehic@ieee.org>
19 
20 //#define NS_LOG_APPEND_CONTEXT \
21 // if (GetObject<Node> ()) { std::clog << "[node " << GetObject<Node> ()->GetId () << "] "; }
22  */
23 
24 #include "ns3/log.h"
25 #include "ns3/qkd-crypto.h"
26 #include "ns3/object-vector.h"
27 #include "ns3/qkd-internal-tag.h"
28 #include "ns3/qkd-manager.h"
29 #include "ns3/qkd-packet-filter.h"
30 #include "ns3/net-device-queue-interface.h"
31 #include "ns3/pointer.h"
32 #include "ns3/uinteger.h"
33 #include <math.h> /* exp */
34 #include <cmath>
35 
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("QKDManager");
40 
41 NS_OBJECT_ENSURE_REGISTERED (QKDManager);
42 
44 {
45  static TypeId tid = TypeId ("ns3::QKDManager")
46  .SetParent<Object> ()
47  .AddConstructor<QKDManager> ()
48  .AddAttribute ("BufferList", "The list of buffers associated to this Manager.",
51  MakeObjectVectorChecker<QKDManager> ())
52  ;
53  return tid;
54 }
56 {
57  NS_LOG_FUNCTION (this);
59 }
60 
62 {
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this);
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION (this);
76  for (std::vector<Ptr<QKDBuffer> >::iterator i = m_buffers.begin ();
77  i != m_buffers.end (); i++)
78  {
79  Ptr<QKDBuffer> device = *i;
80  device->Dispose ();
81  *i = 0;
82  }
83  m_buffers.clear ();
84 
85  std::map<Address, QKDManager::Connection >::iterator j;
86  for (j = m_destinations.begin (); !(j == m_destinations.end ()); j++){
87  j->second.QKDNetDeviceSrc = 0;
88  j->second.QKDNetDeviceDst = 0;
89  j->second.IPNetDeviceSrc = 0;
90  j->second.IPNetDeviceDst = 0;
91  j->second.buffer = 0;
92  j->second.crypto = 0;
93  j->second.socket = 0;
94  j->second.socketSink = 0;
95  }
96 
98 }
99 
100 void
101 QKDManager::UseRealStorages(const bool& useRealStorages){
102  m_useRealStorages = useRealStorages;
103 }
104 
105 void
107  Ptr<QKDNetDevice> QKDNetDeviceSrc,
108  Ptr<QKDNetDevice> QKDNetDeviceDst,
109  Ptr<NetDevice> IPNetDeviceSrc,
110  Ptr<NetDevice> IPNetDeviceDst,
111  Ptr<QKDCrypto> Crypto,
112  Ptr<Socket> socket,
113  Ptr<Socket> socketSink,
114  std::string socketType,
115  uint32_t underlayPortNumber,
116  Ipv4InterfaceAddress IPQKDSrc, //QKD IP Src Address - overlay device
117  Ipv4InterfaceAddress IPQKDDst, //QKD IP Dst Address - overlay device
118  Ipv4InterfaceAddress IPSrc, //IP Src Address - underlay device
119  Ipv4InterfaceAddress IPDst, //IP Dst Address - underlay device
120  bool isMaster,
121  uint32_t Mmin,
122  uint32_t Mthr,
123  uint32_t Mmax,
124  uint32_t Mcurrent,
125  uint32_t channelID
126 )
127 {
128  NS_LOG_FUNCTION (this);
129 
130  NS_ASSERT (IPQKDSrc.GetMask () == IPQKDDst.GetMask ());
131 
132  Ptr<Node> a = IPNetDeviceSrc->GetNode();
133  Ptr<Node> b = IPNetDeviceDst->GetNode();
134 
135  struct QKDManager::Connection newConnection;
136 
137  newConnection.QKDNetDeviceSrc = QKDNetDeviceSrc;
138  newConnection.QKDNetDeviceDst = QKDNetDeviceDst;
139  newConnection.IPNetDeviceSrc = IPNetDeviceSrc;
140  newConnection.IPNetDeviceDst = IPNetDeviceDst;
141 
142 
143 
144  newConnection.isMaster = isMaster;
145  newConnection.crypto = Crypto;
146  newConnection.socket = socket;
147  newConnection.socketSink = socketSink;
148  newConnection.socketType = socketType;
149  newConnection.underlayPortNumber = underlayPortNumber;
150  newConnection.channelID = channelID;
151 
152  newConnection.IPQKDSrc = IPQKDSrc;
153  newConnection.IPQKDDst = IPQKDDst;
154  newConnection.IPSrc = IPSrc;
155  newConnection.IPDst = IPDst;
156 
157  newConnection.publicChannelMetric = 0;
158  newConnection.quantumChannelMetric = 0;
159 
160 
161  // Only one buffer can exist per connection between two nodes!
162  // It is possible to implement multiple number of links,
163  // but if the source and the destination of the link is the same,
164  // these links belong to the same connection and they sohuld use the same buffer.
165  /*
166  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection ( IPNetDeviceSrc.GetAddress() );
167  if (i != m_destinations.end ()){
168  bufferExist = true;
169  newConnection.buffer = i->second.buffer;
170  newConnection.bufferId = i->second.bufferId;
171  NS_LOG_FUNCTION (this << "BUFFER ALREADY EXISTS!");
172  }
173  */
174 
175  NS_LOG_FUNCTION (this << "CREATE NEW BUFFER!");
176  newConnection.buffer = CreateObject<QKDBuffer> (a->GetId(), b->GetId(), m_useRealStorages );
177  newConnection.buffer->SetAttribute ("Minimal", UintegerValue (Mmin));
178  newConnection.buffer->SetAttribute ("Maximal", UintegerValue (Mmax));
179  newConnection.buffer->SetAttribute ("Threshold", UintegerValue (Mthr));
180  newConnection.buffer->SetAttribute ("Current", UintegerValue (Mcurrent));
181  m_buffers.push_back(newConnection.buffer);
182  newConnection.bufferId = newConnection.buffer->m_bufferID;
183 
184  NS_LOG_FUNCTION(this << "BUFFERID:" << newConnection.buffer->m_bufferID);
185 
186  NS_LOG_FUNCTION(this << "QKDNetDeviceSrc:" << newConnection.QKDNetDeviceSrc);
187  if(newConnection.QKDNetDeviceSrc != 0){
188  NS_LOG_FUNCTION(this << "QKDNetDeviceSrc address:" << newConnection.QKDNetDeviceSrc->GetAddress() );
189  }
190 
191  NS_LOG_FUNCTION(this << "QKDNetDeviceDst:" << newConnection.QKDNetDeviceDst);
192  if(newConnection.QKDNetDeviceDst != 0){
193  NS_LOG_FUNCTION(this << "QKDNetDeviceDst address:" << newConnection.QKDNetDeviceDst->GetAddress() );
194  }
195 
196  NS_LOG_FUNCTION(this << "IPNetDeviceSrc:" << newConnection.IPNetDeviceSrc);
197  if(newConnection.IPNetDeviceSrc != 0){
198  NS_LOG_FUNCTION(this << "IPNetDeviceSrc address:" << newConnection.IPNetDeviceSrc->GetAddress() );
199  }
200 
201  NS_LOG_FUNCTION(this << "IPNetDeviceDst:" << newConnection.IPNetDeviceDst);
202  if(newConnection.IPNetDeviceDst != 0){
203  NS_LOG_FUNCTION(this << "IPNetDeviceDst address:" << newConnection.IPNetDeviceDst->GetAddress() );
204  }
205 
206  m_destinations.insert (std::make_pair (IPNetDeviceSrc->GetAddress (), newConnection));
207 }
208 
209 
210 uint32_t
212  return m_destinations.size();
213 }
214 
215 std::vector<QKDManager::addressGroup>
217 
218  NS_LOG_FUNCTION (this);
219 
220  std::vector<addressGroup> m_links;
221 
222  std::map<Address, Connection >::const_iterator j;
223 
224  for (j = m_destinations.begin (); !(j == m_destinations.end ()); j++){
225 
226  struct QKDManager::addressGroup detail;
227 
228  //If only underlay network
229  if( j->second.QKDNetDeviceSrc == 0){
230 
231  NS_LOG_FUNCTION (this << "\t Destination address found:" << j->second.IPSrc.GetLocal() );
232 
233  detail.destinationNode = j->second.IPNetDeviceDst->GetNode();
234  detail.sourceAddress = j->second.IPSrc.GetLocal();
235  detail.destinationAddress = j->second.IPDst.GetLocal();
236  m_links.push_back(detail);
237 
238  //If overlay network
239  }else{
240 
241  NS_LOG_FUNCTION (this << "\t Destination address found:" << j->second.IPQKDDst.GetLocal() );
242 
243  detail.destinationNode = j->second.QKDNetDeviceDst->GetNode();
244  detail.sourceAddress = j->second.IPQKDSrc.GetLocal();
245  detail.destinationAddress = j->second.IPQKDDst.GetLocal();
246  m_links.push_back(detail);
247 
248  }
249 
250  }
251  return m_links;
252 }
253 
256  Ptr<Packet> p,
257  std::map<Ipv4Address, NeigborDetail> distancesToDestination,
258  uint8_t tos,
259  uint32_t& outputInterface
260 ){
261  NS_LOG_DEBUG (this << p << distancesToDestination.size() << (uint32_t) tos);
262 
263  Ipv4Address bestOutput;
264  return bestOutput;
265 }
266 
267 uint32_t
269 
272 }
273 
274 void
276 
278 }
279 
280 void
281 QKDManager::SetLinkThresholdValue( const uint32_t& proposedLaValue, const Address sourceAddress ){
282 
283  NS_LOG_FUNCTION (this << proposedLaValue << sourceAddress);
284 }
285 
286 uint32_t
288 
289  NS_LOG_FUNCTION (this << sourceAddress);
290  return 0;
291 }
292 
293 std::map<Address, QKDManager::Connection >::iterator
295 
296  NS_LOG_FUNCTION (this << sourceAddress << m_destinations.size() );
297 
298  std::map<Address, QKDManager::Connection >::iterator i = m_destinations.find (sourceAddress);
299  if (i == m_destinations.end ()){
300  std::map<Address, QKDManager::Connection >::iterator j;
301  for (j = m_destinations.begin (); !(j == m_destinations.end ()); j++){
302  if (
303  (j->second.IPNetDeviceSrc != 0 && j->second.IPNetDeviceSrc->GetAddress() == sourceAddress) ||
304  (j->second.QKDNetDeviceSrc != 0 && j->second.QKDNetDeviceSrc->GetAddress() == sourceAddress)
305  ) {
306  return j;
307  }
308  }
309  }
310  return i;
311 }
312 
313 
314 
317 
318  NS_LOG_FUNCTION (this << "\t" << address);
319 
320  std::map<Address, Connection >::const_iterator j;
321  for (j = m_destinations.begin (); !(j == m_destinations.end ()); j++){
322 
323  //if only underlay network
324  if( j->second.QKDNetDeviceSrc == 0 && j->second.IPNetDeviceSrc->GetAddress() == address){
325  NS_LOG_FUNCTION (this << "\t Destination address found:" << j->second.IPNetDeviceSrc->GetAddress() );
326  NS_LOG_FUNCTION (this << "Src" << j->second.IPSrc.GetLocal() << "Dst" << j->second.IPDst.GetLocal() );
327  return j->second.IPNetDeviceSrc;
328 
329  //if overlay network
330  }else if( j->second.QKDNetDeviceSrc != 0 && j->second.QKDNetDeviceSrc->GetAddress() == address){
331  NS_LOG_FUNCTION (this << "\t Destination address found:" << j->second.QKDNetDeviceSrc->GetAddress() );
332  NS_LOG_FUNCTION (this << "Src" << j->second.IPQKDSrc.GetLocal() << "Dst" << j->second.IPQKDDst.GetLocal() );
333  return j->second.QKDNetDeviceSrc;
334  }
335  }
336  return 0;
337 }
338 
339 bool
340 QKDManager::VirtualSendOverlay (Ptr<Packet> p, const Address& source, const Address& dst, uint16_t protocolNumber)
341 {
342  return VirtualSend (p, source, dst, protocolNumber, 0);
343 }
344 
345 bool
347  Ptr<Packet> p,
348  const Address& source,
349  const Address& destination,
350  uint16_t protocolNumber,
351  uint8_t TxQueueIndex
352 ){
353  NS_LOG_FUNCTION ( this << "\t" << p->GetUid() << "\t" << p->GetSize() );
354  NS_LOG_FUNCTION ( this << p );
355 
356  // packetCopy is unencrypted packet that is used for sniffing in netDevices (to create .pcap records that are readble)
357  Ptr<Packet> packetCopy = p->Copy ();
358 
359  /*
360  std::cout << "--------QKDManager::VirtualSend-----------\n";
361  std::cout << p->GetUid() << "\t" << p->GetSize() << "\n";
362  p->Print(std::cout);
363  std::cout << "\n\n";
364  std::cout << "--------End of QKDManager::VirtualSend-----------\n";
365  */
366 
367  //PERFORM ENCRYPTION and AUTHENTICATION
368  Ptr<NetDevice> SourceDevice = GetSourceNetDevice(source);
369  std::vector<Ptr<Packet> > processedPackets = ProcessOutgoingRequest (SourceDevice, p);
370 
371 
372  NS_LOG_DEBUG(this << "****** processedPackets size ****** " << processedPackets.size() );
373 
374  if(processedPackets.size() > 0 ){
375  typename std::vector<Ptr<Packet> >::iterator it = processedPackets.begin();
376  for( ; it != processedPackets.end(); ++it){
377 
378  Ptr<Packet> packet = *it;
379  if(packet == 0)
380  continue;
381  else {
382 
383  NS_LOG_DEBUG (this << "\t"
384  << packet->GetUid()
385  << packet->GetSize() << "\t"
386  << source << "\t"
387  << destination << "\t"
388  );
389 
390  return ForwardToSocket (packetCopy, packet, source, destination, protocolNumber, TxQueueIndex);
391  }
392  }
393  }else{
394 
395  NS_LOG_DEBUG (this << "\t"
396  << p->GetUid()
397  << p->GetSize() << "\t"
398  << source << "\t"
399  << destination
400  );
401 
402  }
403  NS_LOG_DEBUG(this << "****** WE DO NOT KNOW WHERE TO FORWARD THIS PACKET ******" << p << source << destination);
404  return false;
405 }
406 
407 bool
409  Ptr<Packet> originalPacket,
410  Ptr<Packet> packet,
411  const Address& source,
412  const Address& destination,
413  uint16_t protocolNumber,
414  uint8_t TxQueueIndex
415 ){
416 
417  NS_LOG_FUNCTION (this << "\t"
418  << originalPacket->GetUid()
419  << originalPacket->GetSize() << "\t"
420  << packet->GetUid()
421  << packet->GetSize() << "\t"
422  );
423 
424  //if unicast delivery
425  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (source);
426  if (i != m_destinations.end ()){
427 
433  if(CheckForResourcesToProcessThePacket(packet, source) == false){
434  NS_LOG_DEBUG (this << "WE DO NOT HAVE ENOUGH KEY MATERIAL TO PROCESS THIS PACKET!\n Discarding this path!" << "\n");
435  return false;
436  }
437 
438  //if only underlay network
439  if( i->second.QKDNetDeviceSrc == 0){
440 
441 
442  NS_LOG_DEBUG (this
443  << "Sending UNICAST to socket\t" << i->second.socket << "\t"
444  << "IPQKDSrc:\t" << i->second.IPQKDSrc.GetLocal() << "\t"
445  << "IPQKDDst:\t" << i->second.IPQKDDst.GetLocal() << "\t"
446  << "IPNetDeviceSrc:\t" << i->second.IPNetDeviceSrc->GetAddress() << "\t"
447  << "IPNetDeviceDst:\t" << i->second.IPNetDeviceDst->GetAddress() << "\t"
448  << "IPSrc:\t" << i->second.IPSrc.GetLocal() << "\t"
449  << "IPDst:\t" << i->second.IPDst.GetLocal() << "\t"
450  << "PORT:\t" << i->second.underlayPortNumber << "\t"
451  << "PacketID:\t" << packet->GetUid() << "\t"
452  << "From:\t" << source << "\t"
453  << "To:\t" << destination << "\t"
454  );
455 
456 
457  NS_LOG_DEBUG (this << "SINGLE TCP/IP Network" << i->second.QKDNetDeviceSrc);
458 
459  Ptr<NetDeviceQueueInterface> m_devQueueIface = i->second.IPNetDeviceSrc->GetObject<NetDeviceQueueInterface> ();
460  if ( m_devQueueIface!= 0 && m_devQueueIface->GetTxQueue (TxQueueIndex)->IsStopped ())
461  {
462  NS_LOG_DEBUG (this << "NetDevice " << i->second.IPNetDeviceSrc << " queue is stopped! Aborting!");
463  return false;
464 
465  }else{
466 
467  i->second.IPNetDeviceSrc->SniffPacket(originalPacket);
468  i->second.IPNetDeviceSrc->Send (
469  packet,
470  i->second.IPNetDeviceDst->GetAddress (),
471  protocolNumber
472  );
473 
474  NS_LOG_DEBUG(this << "******PACKET LEFT SINGLE TCP/IP NETWORK (UNICAST)******");
475 
476  }
477 
478  return true;
479 
480  //if overlay network
481  }else{
482 
483  NS_LOG_INFO (this
484  << "Sending UNICAST to socket\t" << i->second.socket << "\t"
485  << "IPQKDSrc:\t" << i->second.IPQKDSrc.GetLocal() << "\t"
486  << "IPQKDDst:\t" << i->second.IPQKDDst.GetLocal() << "\t"
487  << "IPSrc:\t" << i->second.IPSrc.GetLocal() << "\t"
488  << "IPDst:\t" << i->second.IPDst.GetLocal() << "\t"
489  << "PORT:\t" << i->second.underlayPortNumber << "\t"
490  << "PacketID:\t" << packet->GetUid() << "\t"
491  << "From:\t" << source << "\t"
492  << "To:\t" << destination << "\t"
493  );
494 
495  NS_LOG_FUNCTION (this << "OVERLAY Network" << i->second.QKDNetDeviceSrc);
496  NS_LOG_FUNCTION (this << "SocketType:" << i->second.socketType);
497 
498  if(i->second.socketType == "ns3::TcpSocketFactory"){
499  i->second.socket->Send (packet);
500 
501  }else if(i->second.socketType == "ns3::UdpSocketFactory"){
502  i->second.socket->SendTo (
503  packet,
504  0,
506  i->second.IPDst.GetLocal(),
507  i->second.underlayPortNumber
508  )
509  );
510  }
511 
512  NS_LOG_FUNCTION (this << "socketType:" << i->second.socketType);
513  NS_LOG_FUNCTION (this << "******PACKET LEFT OVERLAY NETWORK (UNICAST) ******");
514 
515  return true;
516  }
517 
518  } else{
519  NS_LOG_INFO(this << "--------- We do not have QKD link to desired destination! ------------");
520  }
521 
522  return false;
523 }
524 
525 void
527  uint16_t protocol, const Address &from, const Address &to,
528  NetDevice::PacketType packetType
529  )
530 {
531 
532  NS_LOG_DEBUG (this << device << packet->GetUid() << packet->GetSize() << protocol << from << to << packetType);
533 
534  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (device->GetAddress());
535 
536  if (i != m_destinations.end ()){
537 
538  if(i->second.IPNetDeviceSrc == device){
539 
540  //PERFORM DECRYPTION and AUTHENTICATION-CHECK
541  Ptr<Packet> packetCopy = packet->Copy ();
542  std::vector<Ptr<Packet> > processedPackets;
543 
544  //It is possible that routing protocol uses LoopbackRoute. In that case, there is no need to perform
545  //decryption/authentication operations
546  if(from == to){
547  NS_LOG_DEBUG ( this << "#### ROUTING TO MY SELF from " << from << " to " << to);
548  processedPackets.push_back(packetCopy);
549  }else{
550  processedPackets = ProcessIncomingRequest (i->second.IPNetDeviceSrc, packetCopy);
551  }
552 
553  NS_LOG_DEBUG ( this << "We have in total " << processedPackets.size() << " decrypted packets!" );
554 
555  //ForwardUP
556  typename std::vector<Ptr<Packet> >::iterator it = processedPackets.begin();
557  for( ; it != processedPackets.end(); ++it){
558 
559  Ptr<const Packet> p = *it;
560  if(p != 0){
561 
562  NS_LOG_DEBUG (this << "Starting forward up process for packet:" << p << " pid " << p->GetUid() << " of size " << p->GetSize());
563  /*
564  std::cout << "--------QKDManager::VirtualReceiveSimpleNetwork-----------\n";
565  std::cout << p->GetUid() << "\t" << p->GetSize() << "\n";
566  p->Print(std::cout);
567  std::cout << "\n\n";
568  std::cout << "--------End of QKDManager::VirtualReceiveSimpleNetwork-----------\n";
569  */
570  Ptr<Node> node = device->GetNode();
571  NS_ASSERT (node != 0);
572 
573  Ptr<TrafficControlLayer> tc = node->GetObject<TrafficControlLayer> ();
574  NS_ASSERT (tc != 0);
575 
576  device->SniffPacket(p);
577  tc->Receive(device, p, protocol, from, to, packetType);
578 
579  }else{
580  NS_LOG_FUNCTION(this << "Packet is EMPTY!" << p);
581  }
582  }
583  }
584  }
585 }
586 
587 void
589 {
590  NS_LOG_FUNCTION(this << socket);
591 
592  std::map<Address, Connection >::const_iterator i;
593  for (i = m_destinations.begin (); !(i == m_destinations.end ()); i++){
594  Ptr<NetDevice> sNetDevice = socket->GetBoundNetDevice();
595  Ptr<NetDevice> sSinkNetDevice = i->second.socketSink->GetBoundNetDevice();
596  if( sNetDevice != 0 && sSinkNetDevice != 0 && sNetDevice->GetAddress() == sSinkNetDevice->GetAddress() ){
597  NS_LOG_FUNCTION (this << "QKDNetDevice Found!");
598  break;
599  }
600  }
601 
602  if( i != m_destinations.end () ){
603 
604  NS_LOG_FUNCTION(this << i->second.socketType);
605 
607  if(i->second.socketType == "ns3::TcpSocketFactory"){
608  NS_LOG_FUNCTION (this << "It is TCP underlay socket!");
609 
610  Ptr<Packet> packet;
611  Address from;
612  while ((packet = socket->RecvFrom (from)))
613  {
614  if (packet->GetSize () == 0)
615  { //EOF
616  break;
617  }
618 
619  NS_LOG_FUNCTION(this << packet->GetUid() << packet->GetSize() );
620 
621  //PERFORM DECRYPTION and AUTHENTICATION-CHECK
622  std::vector<Ptr<Packet> > processedPackets = ProcessIncomingRequest (i->second.QKDNetDeviceSrc, packet);
623 
624  typename std::vector<Ptr<Packet> >::iterator it = processedPackets.begin();
625  for( ; it != processedPackets.end(); ++it){
626 
627  Ptr<Packet> p = *it;
628  if (p != 0){
629  i->second.QKDNetDeviceSrc->Receive (
630  p,
631  0x0800,
632  i->second.QKDNetDeviceDst->GetAddress (), //who is sending packet
633  i->second.QKDNetDeviceSrc->GetAddress (), //who is receiving packet
635  );
636 
638  {
639  NS_LOG_FUNCTION (this << "\nAt time " << Simulator::Now ().GetSeconds ()
640  << "s packet sink received "
641  << p->GetSize () << " bytes from "
643  << " port " << InetSocketAddress::ConvertFrom (from).GetPort ()
644  << " size " << p->GetSize () << " bytes");
645  }
646  NS_LOG_FUNCTION (this << " Received packet : " << p->GetUid() << " of size " << p->GetSize() << " on socket " << socket);
647  }
648  NS_LOG_FUNCTION (this << p);
649 
650 
651  }
652 
653  }
654 
656  } else if(i->second.socketType == "ns3::UdpSocketFactory"){
657 
658  NS_LOG_FUNCTION (this << "It is UDP underlay socket!");
659 
660  Ptr<Packet> packet = socket->Recv (65535, 0);
661 
662  //PERFORM DECRYPTION and AUTHENTICATION-CHECK
663  std::vector<Ptr<Packet> > processedPackets = ProcessIncomingRequest (i->second.QKDNetDeviceSrc, packet);
664 
665  typename std::vector<Ptr<Packet> >::iterator it = processedPackets.begin();
666  for( ; it != processedPackets.end(); ++it){
667 
668  Ptr<Packet> p = *it;
669 
670  NS_LOG_FUNCTION (this << "Delivering packet " << p << " to " << i->second.QKDNetDeviceSrc);
671 
672  if(p != 0){
673  i->second.QKDNetDeviceSrc->Receive (
674  p,
675  0x0800,
676  i->second.QKDNetDeviceDst->GetAddress (), //who is sending packet
677  i->second.QKDNetDeviceSrc->GetAddress (), //who is receiving packet
679  );
680  NS_LOG_FUNCTION (this << " Received packet : " << p->GetUid() << " of size " << p->GetSize() << " on socket " << socket);
681  }
682 
683  NS_LOG_FUNCTION (this << p);
684 
685  }
686 
687  }
688  }
689 
690  /*
691  std::cout << "--------QKDManager::VirtualReceive-----------\n";
692  std::cout << packet->GetUid() << "\t" << packet->GetSize() << "\n";
693  packet->Print(std::cout);
694  std::cout << "\n\n";
695  std::cout << "--------End of QKDManager::VirtualReceive-----------\n";
696  */
697 }
698 
699 void
701 {
702  NS_LOG_FUNCTION (this << s << from);
704 }
705 
706 void
708 {
709  NS_LOG_FUNCTION (this << socket);
710  NS_LOG_FUNCTION (this << "QKDManager Connection succeeded");
711 // m_connected = true;
712 }
713 
714 void
716 {
717  NS_LOG_FUNCTION (this << socket);
718  NS_LOG_FUNCTION (this << "QKDManager, Connection Failed");
719 }
720 
721 Ptr<Node>
723 {
724  NS_LOG_FUNCTION (this << sourceAddress);
725  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (sourceAddress);
726  if (i != m_destinations.end ())
727  return i->second.IPNetDeviceDst->GetNode ();
728  return 0;
729 }
730 
733 {
734  NS_LOG_FUNCTION (this << sourceAddress);
735  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (sourceAddress);
736  if (i != m_destinations.end ())
737  return i->second;
738 
739  struct QKDManager::Connection newConnection;
740  return newConnection;
741 }
742 
744 QKDManager::GetConnectionDetails (const uint32_t& bufferId)
745 {
746  NS_LOG_FUNCTION (this << bufferId);
747  std::map<Address, Connection >::const_iterator i;
748  for (i = m_destinations.begin (); !(i == m_destinations.end ()); i++){
749  if( i->second.bufferId == bufferId )
750  return i->second;
751  }
752 
753  struct QKDManager::Connection newConnection;
754  return newConnection;
755 }
756 
757 
758 uint32_t
760 {
761  NS_LOG_FUNCTION (this << sourceAddress);
762 
763  Ptr<QKDBuffer> tempBuffer;
764 
765  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (sourceAddress);
766  if (i != m_destinations.end ()){
767  tempBuffer = i->second.buffer;
768  uint32_t a = 0;
769  for (std::vector<Ptr<QKDBuffer> >::iterator i = m_buffers.begin (); !(i == m_buffers.end ()); i++){
770  if( **i == *tempBuffer ){
771  return a;
772  }
773  a++;
774  }
775  }
776 
777  return 0;
778 }
779 
780 
783 {
784  NS_LOG_FUNCTION (this << sourceAddress);
785 
786  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (sourceAddress);
787  if (i != m_destinations.end ())
788  return i->second.buffer;
789 
790  return 0;
791 }
792 
794 QKDManager::GetBufferByBufferPosition (const uint32_t& bufferPosition)
795 {
796  NS_LOG_FUNCTION (this << bufferPosition << m_buffers.size());
797 
798  if(bufferPosition < m_buffers.size())
799  return m_buffers[bufferPosition];
800 
801  return 0;
802 }
803 
804 uint32_t
806 {
807  NS_LOG_FUNCTION (this);
808  return m_buffers.size ();
809 }
810 
811 uint8_t
813 {
814  NS_LOG_FUNCTION (this << dev );
815 
816  if(dev == 0)
817  return 0;
818 
819  Ptr<Node> node = dev->GetNode();
820  if(node != 0)
821  NS_LOG_FUNCTION (this << node->GetId() << dev );
822 
823  std::map<Address, Connection >::const_iterator i;
824  for (i = m_destinations.begin (); !(i == m_destinations.end ()); i++){
825 
826  //if simple single TCP/IP network OR if overlay network
827  if( (i->second.QKDNetDeviceSrc == 0 && i->second.IPNetDeviceSrc == dev) ||
828  i->second.QKDNetDeviceSrc == dev
829  ){
830  uint32_t output = i->second.buffer->FetchState();
831  NS_LOG_FUNCTION (this << "status is " << (uint32_t) output );
832  return output;
833  }
834  }
835  NS_LOG_FUNCTION (this << "status is 0" );
836  return 0;
837 }
838 
839 std::vector<Ptr<Packet> >
841 {
842  NS_LOG_FUNCTION (this << dev->GetNode()->GetId() << dev << p->GetUid() << p->GetSize() << p );
843 
844  QKDInternalTag tag;
845  std::vector<Ptr<Packet> > packetOutput;
846 
847  if(p->PeekPacketTag(tag)) {
848  //This packet is already processed
849  NS_LOG_FUNCTION(this << "Packet " << p->GetUid() << " was already decrypted/deauthenticated!" << p->GetUid() << p);
850  return packetOutput;
851  }
852 
853  NS_LOG_FUNCTION(this << "Packet " << p->GetUid() << " is ready to be decrypted/deauthenticated!" << p->GetUid() << p);
854 
855  Ptr<Packet> packet = p->Copy ();
856 
857  std::map<Address, Connection >::const_iterator i;
858  for (i = m_destinations.begin (); !(i == m_destinations.end ()); i++){
859 
860  //if simple single TCP/IP network OR if overlay network
861  if( (i->second.QKDNetDeviceSrc == 0 && i->second.IPNetDeviceSrc == dev) ||
862  i->second.QKDNetDeviceSrc == dev
863  ){
864 
865  if(i->second.crypto == 0)
866  continue;
867 
868  packetOutput = i->second.crypto->ProcessIncomingPacket(
869  packet,
870  i->second.buffer,
871  i->second.channelID
872  );
873  UpdatePublicChannelMetric (i->first);
874  UpdateQuantumChannelMetric(i->first);
875  break;
876  }
877  }
878 
879  NS_LOG_FUNCTION(this << "Size of packet output:" << packetOutput.size() );
880  return packetOutput;
881 }
882 
883 std::vector<Ptr<Packet> >
885 {
886  NS_LOG_FUNCTION (this << dev << p->GetUid() << p->GetSize() << p );
887 
888  std::vector<Ptr<Packet> > processedPackets;
889  QKDInternalTag tag;
890  if(p->PeekPacketTag(tag)) {
891  //p->RemovePacketTag(tag);
892  } else {
893  NS_LOG_FUNCTION (
894  this << "No QKDInternalTag detected!"
895  << "No encryption/authentication needed (no MarkEncryt or MarkAuthenticated called before)"
896  );
897  tag.SetAuthenticateValue ( 0 );
898  tag.SetEncryptValue ( 0 );
899  tag.SetMaxDelayValue ( 10 );
900  p->AddPacketTag(tag);
901  }
902 
903  /*
904  std::cout << "\n###################################################\n";
905  p->Print(std::cout);
906  std::cout << "\n###################################################\n";
907  */
908 
909  NS_LOG_FUNCTION(this << "Packet is ready to be ecrypted/authenticated!" << p->GetUid() << p);
910  NS_LOG_FUNCTION(this << "Packet to be encrypted:" << (uint32_t) tag.GetEncryptValue() );
911  NS_LOG_FUNCTION(this << "Packet to be authenticated:" << (uint32_t) tag.GetAuthenticateValue() );
912  NS_LOG_FUNCTION(this << "Packet (maxDelay):" << (uint32_t) tag.GetMaxDelayValue() );
913 
914  Ptr<Packet> packet = p->Copy ();
915  std::map<Address, Connection >::const_iterator i;
916  for (i = m_destinations.begin (); !(i == m_destinations.end ()); i++){
917 
918 
919  //if simple single TCP/IP network OR if overlay network
920  if( (i->second.QKDNetDeviceSrc == 0 && i->second.IPNetDeviceSrc == dev) ||
921  i->second.QKDNetDeviceSrc == dev
922  ){
923 
924  NS_LOG_FUNCTION (this
925  << "Sending from "
926  << i->second.IPQKDSrc
927  << " to "
928  << i->second.IPQKDDst
929  << " using buffer: "
930  << i->second.buffer->m_bufferID
931  );
932 
933  if(i->second.crypto == 0)
934  continue;
935 
936  processedPackets = i->second.crypto->ProcessOutgoingPacket(
937  packet,
938  i->second.buffer,
939  i->second.channelID
940  );
941  NS_LOG_FUNCTION(this << "Encryption/Authentication completed!"
942  << "PacketID:"
943  << packet->GetUid()
944  << "PacketSize:"
945  << packet->GetSize()
946  );
947  UpdatePublicChannelMetric (i->first);
948  UpdateQuantumChannelMetric(i->first);
949  break;
950  }
951  }
952  return processedPackets;
953 }
954 
955 double
957 
958  NS_LOG_FUNCTION (this << nextHop);
959  return 0;
960 }
961 
962 uint32_t
964 
965  NS_LOG_FUNCTION (this << nextHop);
966  return 0;
967 }
968 
969 
970 
971 
972 //UPDATE PUBLIC CHANNEL METRIC OF THIS CHANNEL
973 void
975 
976  NS_LOG_FUNCTION (this << sourceAddress);
977 }
978 
979 
980 //UPDATE QUANTUM CHANNEL METRIC OF THIS CHANNEL
981 void
983 
984  NS_LOG_FUNCTION (this << sourceAddress);
985 }
986 
987 bool
988 QKDManager::AddNewKeyMaterial (const Address sourceAddress, uint32_t& newKey)
989 {
990  NS_LOG_FUNCTION (this << sourceAddress << newKey);
991 
992  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection ( sourceAddress );
993  if (i != m_destinations.end ()){
994 
995  NS_LOG_DEBUG ( this << "\t" << "sourceAddress: \t" << i->first );
996  NS_LOG_DEBUG (this << "Adding new key to the buffer! \t" << "keySize:\t" << newKey << "\n" );
997 
998  bool response = i->second.buffer->AddNewContent(newKey);
999  UpdatePublicChannelMetric (i->first);
1000  UpdateQuantumChannelMetric(i->first);
1002  return response;
1003 
1004  }
1005  return false;
1006 }
1007 
1008 bool
1010 {
1011  NS_LOG_FUNCTION (this << p->GetUid());
1012 
1013  QKDInternalTag tag;
1014  if(p->PeekPacketTag(tag)){
1015  NS_LOG_FUNCTION (this << tag.GetEncryptValue());
1016  return (tag.GetEncryptValue() > 0);
1017  }
1018  NS_LOG_FUNCTION (this << false);
1019  return false;
1020 }
1021 
1022 Ptr<Packet>
1024 {
1025  NS_LOG_FUNCTION (this << p->GetUid() << p->GetSize() );
1026 
1027  //default values are OTP and VMAC
1029 }
1030 
1031 Ptr<Packet>
1033 {
1034  NS_LOG_FUNCTION (this << p->GetUid() << p->GetSize() << delay );
1035 
1036  QKDInternalTag tag;
1037  if(p->PeekPacketTag(tag)){
1038  p->RemovePacketTag(tag);
1039  }
1040  tag.SetMaxDelayValue ( delay );
1041  p->AddPacketTag(tag);
1042  return p;
1043 }
1044 
1045 Ptr<Packet>
1047 {
1048  NS_LOG_FUNCTION (this << p->GetUid() << p->GetSize() );
1049  return MarkEncrypt(p, 0, QKDCRYPTO_AUTH_VMAC);
1050 }
1051 
1052 Ptr<Packet>
1053 QKDManager::MarkEncrypt (Ptr<Packet> p, uint8_t encryptionType, uint8_t authneticationType)
1054 {
1055  NS_LOG_FUNCTION (this << p->GetUid() << p->GetSize() << (uint32_t) encryptionType << (uint32_t) authneticationType);
1056 
1057  QKDInternalTag tag;
1058  if(p->PeekPacketTag(tag)){
1059  p->RemovePacketTag(tag);
1060  }
1061  tag.SetEncryptValue ( encryptionType );
1062  tag.SetAuthenticateValue ( authneticationType );
1063  p->AddPacketTag(tag);
1064  return p;
1065 }
1066 
1067 bool
1069  Ptr<Packet> p,
1070  const Address sourceAddress
1071 ){
1072 
1073  NS_LOG_WARN(this << "\t" << p->GetUid() << "\t" << p->GetSize() << "\t" << sourceAddress);
1074 
1075  uint32_t tos = FetchPacketTos(p);
1076  uint32_t TOSband = TosToBand(tos);
1077 
1078  NS_LOG_WARN(this << "\t" << p << "\t" << sourceAddress << "\t" << TOSband);
1079 
1081  p,
1082  sourceAddress,
1083  TOSband
1084  );
1085 }
1086 
1087 bool
1089  Ptr<Packet> p,
1090  const Address sourceAddress,
1091  const uint32_t& TOSband
1092 ){
1093 
1094  NS_LOG_WARN(this << "\tp:" << p << "\tsourceAddress:" << sourceAddress << "\tTOSband: " << TOSband);
1095 
1096  std::map<Address, QKDManager::Connection >::iterator i = FetchConnection (sourceAddress);
1097  if (i != m_destinations.end ()){
1098  NS_LOG_WARN (this << "\t Destination found!");
1099  NS_LOG_WARN (this << "\t first:\t" << i->first);
1100  NS_LOG_WARN (this << "\t IPNetDeviceSrc:\t" << i->second.IPNetDeviceSrc);
1101  NS_LOG_WARN (this << "\t IPNetDeviceDst:\t" << i->second.IPNetDeviceDst);
1102  NS_LOG_WARN (this << "\t BufferID:\t" << i->second.bufferId);
1103 
1104  NS_ASSERT (i->second.buffer != 0);
1105  NS_ASSERT (i->second.crypto != 0);
1106 
1107  NS_LOG_WARN (this << "\t BufferID:\t" << i->second.buffer);
1108  NS_LOG_WARN (this << "\t BufferID:\t" << i->second.buffer->m_bufferID);
1109 
1110  return i->second.crypto->CheckForResourcesToProcessThePacket(
1111  p,
1112  TOSband,
1113  i->second.buffer
1114  );
1115  }
1116  return false;
1117 }
1118 
1119 uint32_t
1121 
1122  NS_LOG_FUNCTION(this << p );
1123  NS_LOG_FUNCTION(this << "\t" << p->GetUid() << "\t" << p->GetSize() );
1124 
1125  uint8_t tos = 0;
1126 
1127  SocketIpTosTag ipTosTag;
1128  QKDInternalTOSTag temp_qkdNextHopTag;
1129 
1130  if ( p->PeekPacketTag (ipTosTag) )
1131  {
1132  tos = ipTosTag.GetTos ();
1133  NS_LOG_WARN(this << "\t" << "Found TOS tag using SocketIpTosTag; value:" << "\t" << (uint32_t) tos);
1134 
1135  }else if( p->PeekPacketTag(temp_qkdNextHopTag) ){
1136 
1137  tos = temp_qkdNextHopTag.GetTos();
1138  NS_LOG_WARN(this << "\t" << "Found TOS tag using QKDInternalTOSTag; value:" << "\t" << (uint32_t) tos);
1139 
1140  }
1141 
1142  NS_LOG_FUNCTION( this << "\t packet:" << p << "\t tos:" << (uint32_t) tos );
1143  return tos;
1144 }
1145 
1146 uint32_t
1147 QKDManager::TosToBand(const uint32_t& tos){
1148 
1149  NS_LOG_FUNCTION( this << "\t" << tos );
1150 
1151  Ptr<PfifoFastQKDPacketFilter> filter = CreateObject<PfifoFastQKDPacketFilter> ();
1152  uint32_t priority = filter->TosToBand(Socket::IpTos2Priority (tos));
1153 
1154  NS_LOG_WARN( this << "\t tos:" << tos << "\t priority:" << (uint32_t) Socket::IpTos2Priority(tos) << "\t band:" << filter->TosToBand(Socket::IpTos2Priority (tos)) );
1155 
1156  /*
1157 
1158  for (uint32_t i = 0; i <= 30; i++){
1159  std::cout << "tos (decimal):" << i << " - priority:" << (uint32_t) Socket::IpTos2Priority(i) << " - band:" << filter->TosToBand(Socket::IpTos2Priority (i)) << "\n";
1160  }
1161 
1162  enum SocketPriority {
1163  NS3_PRIO_BESTEFFORT = 0,
1164  NS3_PRIO_FILLER = 1,
1165  NS3_PRIO_BULK = 2,
1166  NS3_PRIO_INTERACTIVE_BULK = 4,
1167  NS3_PRIO_INTERACTIVE = 6,
1168  NS3_PRIO_CONTROL = 7
1169  };
1170 
1171  tos (decimal):0 - priority:0 - band:1
1172  tos (decimal):1 - priority:0 - band:1
1173  tos (decimal):2 - priority:0 - band:1
1174  tos (decimal):3 - priority:0 - band:1
1175  tos (decimal):4 - priority:0 - band:1
1176  tos (decimal):5 - priority:0 - band:1
1177  tos (decimal):6 - priority:0 - band:1
1178  tos (decimal):7 - priority:0 - band:1
1179  tos (decimal):8 - priority:2 - band:2
1180  tos (decimal):9 - priority:2 - band:2
1181  tos (decimal):10 - priority:2 - band:2
1182  tos (decimal):11 - priority:2 - band:2
1183  tos (decimal):12 - priority:2 - band:2
1184  tos (decimal):13 - priority:2 - band:2
1185  tos (decimal):14 - priority:2 - band:2
1186  tos (decimal):15 - priority:2 - band:2
1187  tos (decimal):16 - priority:6 - band:0
1188  tos (decimal):17 - priority:6 - band:0
1189  tos (decimal):18 - priority:6 - band:0
1190  tos (decimal):19 - priority:6 - band:0
1191  tos (decimal):20 - priority:6 - band:0
1192  tos (decimal):21 - priority:6 - band:0
1193  tos (decimal):22 - priority:6 - band:0
1194  tos (decimal):23 - priority:6 - band:0
1195  tos (decimal):24 - priority:4 - band:1
1196  tos (decimal):25 - priority:4 - band:1
1197  tos (decimal):26 - priority:4 - band:1
1198  tos (decimal):27 - priority:4 - band:1
1199  tos (decimal):28 - priority:4 - band:1
1200  tos (decimal):29 - priority:4 - band:1
1201  tos (decimal):30 - priority:4 - band:1
1202  */
1203 
1204  /*
1205  * PfifoFastQKDPacketFilter is the filter to be added to the PfifoFast
1206  * queue disc to simulate the behavior of the pfifo_fast Linux queue disc.
1207  *
1208  * Two modes of operation are provided. In PF_MODE_TOS mode, packets are
1209  * classified based on the TOS byte (originally defined by RFC 1349:
1210  * http://www.ietf.org/rfc/rfc1349.txt)
1211  *
1212  * 0 1 2 3 4 5 6 7
1213  * +-----+-----+-----+-----+-----+-----+-----+-----+
1214  * | PRECEDENCE | TOS | MBZ |
1215  * +-----+-----+-----+-----+-----+-----+-----+-----+
1216  *
1217  * where MBZ stands for 'must be zero'.
1218  *
1219  * In the eight-bit legacy TOS byte, there were five lower bits for TOS
1220  * and three upper bits for Precedence. Bit 7 was never used. Bits 6-7
1221  * are now repurposed for ECN. The below TOS values correspond to
1222  * bits 3-7 in the TOS byte (i.e. including MBZ), omitting the precedence
1223  * bits 0-2.
1224  *
1225  * TOS | TOS Decimal | Bits | Means | Linux Priority | Band
1226  * -----|-------------|------|-------------------------|----------------|-----
1227  * 0x0 | 0-7 | 0 | Normal Service | 0 Best Effort | 1
1228  * 0x8 | 8-15 | 4 | Real-time service | 2 Bulk | 2
1229  * 0x10 | 16-23 | 8 | PREMIUM Service | 6 Interactive | 0
1230  * 0x18 | 24-30 | 12 | Normal service | 4 Int. Bulk | 1
1231  */
1232  return priority;
1233 }
1234 
1235 
1236 
1237 } // namespace ns3
#define QKDCRYPTO_AUTH_VMAC
Definition: qkd-crypto.h:70
log2() macro definition; to deal with Bug 1467.
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
uint32_t GetNBuffers(void) const
Return the number of buffers connected with QKD Manager of the node.
Definition: qkd-manager.cc:805
void SetMaxDelayValue(uint32_t value)
an Inet address class
Ipv4Address GetIpv4(void) const
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void DoDispose(void)
The dispose method.
Definition: qkd-manager.cc:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< QKDBuffer > buffer
Definition: qkd-manager.h:82
Ptr< QKDBuffer > GetBufferBySourceAddress(const Address &sourceAddress)
Return QKDBuffer Position in m_buffers on the basis of source IPv4Address.
Definition: qkd-manager.cc:782
Ipv4Mask GetMask(void) const
Get the network mask.
bool VirtualSendOverlay(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Forward packet from device to the underlay network through the socket.
Definition: qkd-manager.cc:340
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool AddNewKeyMaterial(const Address sourceAddress, uint32_t &newKey)
Add new key material to the corresponding QKD Buffer.
Definition: qkd-manager.cc:988
Introspection did not find any typical Config paths.
uint8_t GetTos(void) const
Get the tag&#39;s TOS.
Definition: socket.cc:797
Introspection did not find any typical Config paths.
std::map< Address, QKDManager::Connection >::iterator FetchConnection(const Address sourceAddress)
Help function.
Definition: qkd-manager.cc:294
bool ForwardToSocket(Ptr< Packet > originalPacket, Ptr< Packet > packet, const Address &source, const Address &dst, uint16_t protocolNumber, uint8_t TxQueueIndex)
Deliver the processed packet to the underlying socket.
Definition: qkd-manager.cc:408
std::map< Address, Connection > m_destinations
Definition: qkd-manager.h:548
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:852
std::vector< Ptr< Packet > > ProcessOutgoingRequest(Ptr< NetDevice > src, Ptr< Packet > p)
Called from QKDManager::VirtualSend This function is used to encrypt the packet prior sending to the ...
Definition: qkd-manager.cc:884
uint64_t GetUid(void) const
Returns the packet&#39;s Uid.
Definition: packet.cc:390
bool CheckForResourcesToProcessThePacket(Ptr< Packet > p, const Address sourceAddress)
Help function used to call determine TOSband and call original CheckForResourcesToProcessThePacket wi...
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
Ptr< NetDevice > GetSourceNetDevice(const Address address)
Help function used to detect netDevice by using MAC address when the packet is encrypted.
Definition: qkd-manager.cc:316
#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
void UpdatePublicChannelMetric(const Address sourceAddress)
Help function.
Definition: qkd-manager.cc:974
Ipv4Address PopulateLinkStatusesForNeighbors(Ptr< Packet > p, std::map< Ipv4Address, NeigborDetail > distancesToDestination, uint8_t tos, uint32_t &outputInterface)
Help function.
Definition: qkd-manager.cc:255
std::vector< Ptr< QKDBuffer > > m_buffers
Definition: qkd-manager.h:550
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
uint32_t GetBufferPosition(const Address &sourceAddress)
Help function that returns QKDBuffer Position in m_buffers on the basis of source IPv4Address ...
Definition: qkd-manager.cc:759
std::vector< QKDManager::addressGroup > GetMapOfSourceDestinationAddresses()
Help function called from routing protocol to fetch the map of source and destination addresses...
Definition: qkd-manager.cc:216
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
uint32_t GetMaxDelayValue(void) const
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
QKDManager::Connection GetConnectionDetails(const uint32_t &bufferId)
Get connection details based on destination IPv4Address.
Definition: qkd-manager.cc:744
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
Definition: socket.cc:408
void AddNewLink(Ptr< QKDNetDevice > NetDeviceSrc, Ptr< QKDNetDevice > NetDeviceDst, Ptr< NetDevice > IPNetDeviceSrc, Ptr< NetDevice > IPNetDeviceDst, Ptr< QKDCrypto > Crypto, Ptr< Socket > socket, Ptr< Socket > socketSink, std::string socketType, uint32_t underlayPortNumber, Ipv4InterfaceAddress IPQKDSrc, Ipv4InterfaceAddress IPQKDDst, Ipv4InterfaceAddress IPSrc, Ipv4InterfaceAddress IPDst, bool isMaster, uint32_t Mmin, uint32_t Mthr, uint32_t Mmax, uint32_t Mcurrent, uint32_t channelID)
Establish new QKD connection by adding new QKD link and record connection details This function is ca...
Definition: qkd-manager.cc:106
virtual ~QKDManager()
Destructor.
Definition: qkd-manager.cc:61
a polymophic address class
Definition: address.h:90
bool m_useRealStorages
Definition: qkd-manager.h:546
Ptr< QKDCrypto > crypto
Definition: qkd-manager.h:83
uint32_t TosToBand(const uint32_t &tos)
Help function used to convert TOS value to TOS band which is used for determing the priority of the d...
Ptr< QKDBuffer > GetBufferByBufferPosition(const uint32_t &index)
Return QKDBuffer by the buffer position.
Definition: qkd-manager.cc:794
void SetLinkThresholdValue(const uint32_t &proposedLaValue, const Address sourceAddress)
Help function.
Definition: qkd-manager.cc:281
Ptr< NetDevice > GetBoundNetDevice()
Returns socket&#39;s bound NetDevice, if any.
Definition: socket.cc:351
uint8_t GetTos(void) const
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:874
Ptr< Packet > MarkAuthenticate(Ptr< Packet > p)
Mark packet to be authenticated only!
void SetAuthenticateValue(uint8_t value)
void HandleAccept(Ptr< Socket > socket, const Address &from)
Handle an incoming connection.
Definition: qkd-manager.cc:700
void VirtualReceive(Ptr< Socket > socket)
Forward packet from underlay network through the socket to the QKDNetDevice Note: USED ONLY IN OVERLA...
Definition: qkd-manager.cc:588
void VirtualReceiveSimpleNetwork(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Process packet (Decrypt and authentication check) after receiving at NetDevice, and forward it to upp...
Definition: qkd-manager.cc:526
Ptr< QKDNetDevice > QKDNetDeviceSrc
Definition: qkd-manager.h:78
bool IsMarkedAsEncrypt(Ptr< Packet > p)
Check whether packet is marked to be encrypted.
#define QKDCRYPTO_OTP
Definition: qkd-crypto.h:67
Introspection did not find any typical Config paths.
Hold an unsigned integer type.
Definition: uinteger.h:44
uint8_t GetAuthenticateValue(void) const
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
void SetRecvCallback(Callback< void, Ptr< Socket > >)
Notify application when new data is available to be read.
Definition: socket.cc:128
void UseRealStorages(const bool &useRealStorages)
Do we use real storages (save QKDKey on hard-drive)?
Definition: qkd-manager.cc:101
Network device transmission queue interface.
Ipv4InterfaceAddress IPSrc
Definition: qkd-manager.h:90
Ptr< NetDevice > IPNetDeviceDst
Definition: qkd-manager.h:81
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
Ptr< QKDNetDevice > QKDNetDeviceDst
Definition: qkd-manager.h:79
uint32_t FetchMaxNumberOfRecordedKeyChargingTimePeriods(Ipv4Address nextHop)
Help Function (not used)
Definition: qkd-manager.cc:963
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
void ConnectionSucceeded(Ptr< Socket > socket)
Indicates that the TCP connection for socket in param is established.
Definition: qkd-manager.cc:707
uint8_t GetEncryptValue(void) const
uint32_t m_linksThresholdHelpValue
Definition: qkd-manager.h:544
address
Definition: first.py:37
double FetchPublicChannelPerformance(Ipv4Address nextHop)
Fetch performances of the public channel.
Definition: qkd-manager.cc:956
virtual Ptr< Packet > Recv(uint32_t maxSize, uint32_t flags)=0
Read data from the socket.
uint8_t FetchStatusForDestinationBuffer(Ptr< NetDevice > src)
Called from traffic-control/module/qkd-pfifo-fast-queue-disc This function needs to check the status ...
Definition: qkd-manager.cc:812
std::vector< Ptr< Packet > > ProcessIncomingRequest(Ptr< NetDevice > src, Ptr< Packet > p)
Called from QKDManager::VirtualReceive This function is used to decrypt the packet after receiving fr...
Definition: qkd-manager.cc:840
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
bool VirtualSend(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber, uint8_t TxQueueIndex)
Forward packet from device to the underlay network through the socket Thus, this is L2 of Overlay net...
Definition: qkd-manager.cc:346
uint32_t FetchPacketTos(Ptr< Packet > p)
Help function used to fetch TOS value from the packet.
Ipv4InterfaceAddress IPQKDSrc
Definition: qkd-manager.h:88
Ptr< Packet > MarkMaxDelay(Ptr< Packet > p, uint32_t delay)
Mark maxDelay of packet to be tolerated (in miliseconds)
void SetEncryptValue(uint8_t value)
uint32_t GetLinkThresholdValue(const Address sourceAddress)
Help function.
Definition: qkd-manager.cc:287
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
Ptr< NetDevice > IPNetDeviceSrc
Definition: qkd-manager.h:80
uint32_t GetId(void) const
Definition: node.cc:107
a class to store IPv4 address information on an interface
void CalculateLinkThresholdHelpValue()
Help function.
Definition: qkd-manager.cc:275
Packet addressed oo us.
Definition: net-device.h:304
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:859
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
uint32_t GetNumberOfDestinations()
Help function called from routing protocol to count the number of neighbors.
Definition: qkd-manager.cc:211
void UpdateQuantumChannelMetric(const Address sourceAddress)
Help function.
Definition: qkd-manager.cc:982
Ptr< Packet > MarkEncrypt(Ptr< Packet > p)
Mark packet to be encrypted and authenticated Note: All encrypted packets MUST be authenticated as we...
Ipv4InterfaceAddress IPDst
Definition: qkd-manager.h:91
uint16_t GetPort(void) const
void ConnectionFailed(Ptr< Socket > socket)
Indicates that the TCP connection for socket in param failed to establish.
Definition: qkd-manager.cc:715
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)=0
Read a single packet from the socket and retrieve the sender address.
uint32_t FetchLinkThresholdHelpValue()
Help function.
Definition: qkd-manager.cc:268
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:302
Container for a set of ns3::Object pointers.
QKDManager()
Constructor.
Definition: qkd-manager.cc:55
indicates whether the socket has IP_TOS set.
Definition: socket.h:1257
Ipv4InterfaceAddress IPQKDDst
Definition: qkd-manager.h:89
virtual void DoInitialize(void)
function
Definition: qkd-manager.cc:66
static TypeId GetTypeId(void)
Get the type ID.
Definition: qkd-manager.cc:43
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< Node > GetDestinationNode(const Address dst)
Get destination node where destination ndoe is pointing to.
Definition: qkd-manager.cc:722
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
static bool IsMatchingType(const Address &address)