A Discrete-Event Network Simulator
API
ipv6-l3-protocol.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
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: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/node.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/vector.h"
25 #include "ns3/boolean.h"
26 #include "ns3/callback.h"
27 #include "ns3/trace-source-accessor.h"
28 #include "ns3/object-vector.h"
29 #include "ns3/ipv6-routing-protocol.h"
30 #include "ns3/ipv6-route.h"
31 #include "ns3/mac16-address.h"
32 #include "ns3/mac64-address.h"
33 #include "ns3/traffic-control-layer.h"
34 
35 #include "loopback-net-device.h"
36 #include "ipv6-l3-protocol.h"
37 #include "ipv6-interface.h"
38 #include "ipv6-raw-socket-impl.h"
40 #include "ipv6-extension-demux.h"
41 #include "ipv6-extension.h"
42 #include "ipv6-extension-header.h"
43 #include "ipv6-option-demux.h"
44 #include "ipv6-option.h"
45 #include "icmpv6-l4-protocol.h"
46 #include "ndisc-cache.h"
48 
50 #define IPV6_MIN_MTU 1280
51 
52 namespace ns3 {
53 
54 NS_LOG_COMPONENT_DEFINE ("Ipv6L3Protocol");
55 
56 NS_OBJECT_ENSURE_REGISTERED (Ipv6L3Protocol);
57 
58 const uint16_t Ipv6L3Protocol::PROT_NUMBER = 0x86DD;
59 
61 {
62  static TypeId tid = TypeId ("ns3::Ipv6L3Protocol")
63  .SetParent<Ipv6> ()
64  .SetGroupName ("Internet")
65  .AddConstructor<Ipv6L3Protocol> ()
66  .AddAttribute ("DefaultTtl",
67  "The TTL value set by default on all "
68  "outgoing packets generated on this node.",
69  UintegerValue (64),
71  MakeUintegerChecker<uint8_t> ())
72  .AddAttribute ("DefaultTclass",
73  "The TCLASS value set by default on all "
74  "outgoing packets generated on this node.",
75  UintegerValue (0),
77  MakeUintegerChecker<uint8_t> ())
78  .AddAttribute ("InterfaceList",
79  "The set of IPv6 interfaces associated to this IPv6 stack.",
82  MakeObjectVectorChecker<Ipv6Interface> ())
83  .AddAttribute ("SendIcmpv6Redirect",
84  "Send the ICMPv6 Redirect when appropriate.",
85  BooleanValue (true),
89  .AddAttribute ("StrongEndSystemModel",
90  "Reject packets for an address not configured on the interface they're coming from (RFC1222).",
91  BooleanValue (true),
94  .AddTraceSource ("Tx",
95  "Send IPv6 packet to outgoing interface.",
97  "ns3::Ipv6L3Protocol::TxRxTracedCallback")
98  .AddTraceSource ("Rx",
99  "Receive IPv6 packet from incoming interface.",
101  "ns3::Ipv6L3Protocol::TxRxTracedCallback")
102  .AddTraceSource ("Drop",
103  "Drop IPv6 packet",
105  "ns3::Ipv6L3Protocol::DropTracedCallback")
106 
107  .AddTraceSource ("SendOutgoing",
108  "A newly-generated packet by this node is "
109  "about to be queued for transmission",
111  "ns3::Ipv6L3Protocol::SentTracedCallback")
112  .AddTraceSource ("UnicastForward",
113  "A unicast IPv6 packet was received by this node "
114  "and is being forwarded to another node",
116  "ns3::Ipv6L3Protocol::SentTracedCallback")
117  .AddTraceSource ("LocalDeliver",
118  "An IPv6 packet was received by/for this node, "
119  "and it is being forward up the stack",
121  "ns3::Ipv6L3Protocol::SentTracedCallback")
122  ;
123  return tid;
124 }
125 
127  : m_nInterfaces (0)
128 {
130  m_pmtuCache = CreateObject<Ipv6PmtuCache> ();
131 
132  Ptr<Ipv6RawSocketFactoryImpl> rawFactoryImpl = CreateObject<Ipv6RawSocketFactoryImpl> ();
133  AggregateObject (rawFactoryImpl);
134 }
135 
137 {
139 }
140 
142 {
144 
145  /* clear protocol and interface list */
146  for (L4List_t::iterator it = m_protocols.begin (); it != m_protocols.end (); ++it)
147  {
148  it->second = 0;
149  }
150  m_protocols.clear ();
151 
152  /* remove interfaces */
153  for (Ipv6InterfaceList::iterator it = m_interfaces.begin (); it != m_interfaces.end (); ++it)
154  {
155  *it = 0;
156  }
157  m_interfaces.clear ();
159 
160  /* remove raw sockets */
161  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
162  {
163  *it = 0;
164  }
165  m_sockets.clear ();
166 
167  /* remove list of prefix */
168  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
169  {
170  (*it)->StopValidTimer ();
171  (*it)->StopPreferredTimer ();
172  (*it) = 0;
173  }
174  m_prefixes.clear ();
175 
176  m_node = 0;
177  m_routingProtocol = 0;
178  m_pmtuCache = 0;
180 }
181 
183 {
184  NS_LOG_FUNCTION (this << routingProtocol);
185  m_routingProtocol = routingProtocol;
186  m_routingProtocol->SetIpv6 (this);
187 }
188 
190 {
192  return m_routingProtocol;
193 }
194 
196 {
197  NS_LOG_FUNCTION (this << device);
199 
201 
202  NS_ASSERT (tc != 0);
203 
206 
207  tc->RegisterProtocolHandler (MakeCallback (&Ipv6L3Protocol::Receive, this),
209 
210  interface->SetNode (m_node);
211  interface->SetDevice (device);
212  interface->SetTrafficControl (tc);
213  interface->SetForwarding (m_ipForward);
214  return AddIpv6Interface (interface);
215 }
216 
218 {
219  NS_LOG_FUNCTION (this << interface);
220  uint32_t index = m_nInterfaces;
221 
222  m_interfaces.push_back (interface);
223  m_reverseInterfacesContainer[interface->GetDevice ()] = index;
224  m_nInterfaces++;
225  return index;
226 }
227 
229 {
230  NS_LOG_FUNCTION (this << index);
231 
232  if (index < m_interfaces.size ())
233  {
234  return m_interfaces[index];
235  }
236  return 0;
237 }
238 
240 {
242  return m_nInterfaces;
243 }
244 
246 {
247  NS_LOG_FUNCTION (this << address);
248  int32_t index = 0;
249 
250  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
251  {
252  uint32_t j = 0;
253  uint32_t max = (*it)->GetNAddresses ();
254 
255  for (j = 0; j < max; j++)
256  {
257  if ((*it)->GetAddress (j).GetAddress () == address)
258  {
259  return index;
260  }
261  }
262  index++;
263  }
264  return -1;
265 }
266 
268 {
269  NS_LOG_FUNCTION (this << address << mask);
270  int32_t index = 0;
271 
272  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
273  {
274  uint32_t j = 0;
275  for (j = 0; j < (*it)->GetNAddresses (); j++)
276  {
277  if ((*it)->GetAddress (j).GetAddress ().CombinePrefix (mask) == address.CombinePrefix (mask))
278  {
279  return index;
280  }
281  }
282  index++;
283  }
284  return -1;
285 }
286 
288 {
289  NS_LOG_FUNCTION (this << i);
290  return GetInterface (i)->GetDevice ();
291 }
292 
294 {
295  NS_LOG_FUNCTION (this << device);
296 
297  Ipv6InterfaceReverseContainer::const_iterator iter = m_reverseInterfacesContainer.find (device);
298  if (iter != m_reverseInterfacesContainer.end ())
299  {
300  return (*iter).second;
301  }
302 
303  return -1;
304 }
305 
306 void Ipv6L3Protocol::AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter)
307 {
308  NS_LOG_FUNCTION (this << interface << network << mask << (uint32_t)flags << validTime << preferredTime);
310 
311  Address addr = GetInterface (interface)->GetDevice ()->GetAddress ();
312 
313  if (flags & (1 << 6)) /* auto flag */
314  {
315  // In case of new MacAddress types, remember to change Ipv6L3Protocol::RemoveAutoconfiguredAddress as well
316  if (Mac64Address::IsMatchingType (addr))
317  {
319  }
320  else if (Mac48Address::IsMatchingType (addr))
321  {
323  }
324  else if (Mac16Address::IsMatchingType (addr))
325  {
327  }
328  else
329  {
330  NS_FATAL_ERROR ("Unknown method to make autoconfigured address for this kind of device.");
331  return;
332  }
333 
334  /* see if we have already the prefix */
335  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
336  {
337  if ((*it)->GetInterface () == interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
338  {
339  (*it)->StopPreferredTimer ();
340  (*it)->StopValidTimer ();
341  (*it)->StartPreferredTimer ();
342  return;
343  }
344  }
345 
346  /* no prefix found, add autoconfigured address and the prefix */
347  NS_LOG_INFO ("Autoconfigured address is :" << address.GetAddress ());
348  AddAddress (interface, address);
349 
350  /* add default router
351  * if a previous default route exists, the new ones is simply added
352  */
353  if (!defaultRouter.IsAny())
354  {
355  GetRoutingProtocol ()->NotifyAddRoute (Ipv6Address::GetAny (), Ipv6Prefix ((uint8_t)0), defaultRouter, interface, network);
356  }
357 
358  Ptr<Ipv6AutoconfiguredPrefix> aPrefix = CreateObject<Ipv6AutoconfiguredPrefix> (m_node, interface, network, mask, preferredTime, validTime, defaultRouter);
359  aPrefix->StartPreferredTimer ();
360 
361  m_prefixes.push_back (aPrefix);
362  }
363 }
364 
365 void Ipv6L3Protocol::RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter)
366 {
367  NS_LOG_FUNCTION (this << interface << network << mask);
368  Ptr<Ipv6Interface> iface = GetInterface (interface);
369  Address addr = iface->GetDevice ()->GetAddress ();
370  uint32_t max = iface->GetNAddresses ();
371  uint32_t i = 0;
372  Ipv6Address toFound;
373 
374  if (Mac64Address::IsMatchingType (addr))
375  {
377  }
378  else if (Mac48Address::IsMatchingType (addr))
379  {
381  }
382  else if (Mac16Address::IsMatchingType (addr))
383  {
385  }
386  else
387  {
388  NS_FATAL_ERROR ("Unknown method to make autoconfigured address for this kind of device.");
389  return;
390  }
391 
392  for (i = 0; i < max; i++)
393  {
394  if (iface->GetAddress (i).GetAddress () == toFound)
395  {
396  RemoveAddress (interface, i);
397  break;
398  }
399  }
400 
401  /* remove from list of autoconfigured address */
402  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
403  {
404  if ((*it)->GetInterface () == interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
405  {
406  *it = 0;
407  m_prefixes.erase (it);
408  break;
409  }
410  }
411 
412  GetRoutingProtocol ()->NotifyRemoveRoute (Ipv6Address::GetAny (), Ipv6Prefix ((uint8_t)0), defaultRouter, interface, network);
413 }
414 
416 {
417  NS_LOG_FUNCTION (this << i << address);
418  Ptr<Ipv6Interface> interface = GetInterface (i);
419  bool ret = interface->AddAddress (address);
420 
421  if (m_routingProtocol != 0)
422  {
423  m_routingProtocol->NotifyAddAddress (i, address);
424  }
425  return ret;
426 }
427 
428 uint32_t Ipv6L3Protocol::GetNAddresses (uint32_t i) const
429 {
430  NS_LOG_FUNCTION (this << i);
431  Ptr<Ipv6Interface> interface = GetInterface (i);
432  return interface->GetNAddresses ();
433 }
434 
435 Ipv6InterfaceAddress Ipv6L3Protocol::GetAddress (uint32_t i, uint32_t addressIndex) const
436 {
437  NS_LOG_FUNCTION (this << i << addressIndex);
438  Ptr<Ipv6Interface> interface = GetInterface (i);
439  return interface->GetAddress (addressIndex);
440 }
441 
442 bool Ipv6L3Protocol::RemoveAddress (uint32_t i, uint32_t addressIndex)
443 {
444  NS_LOG_FUNCTION (this << i << addressIndex);
445  Ptr<Ipv6Interface> interface = GetInterface (i);
446  Ipv6InterfaceAddress address = interface->RemoveAddress (addressIndex);
447 
448  if (address != Ipv6InterfaceAddress ())
449  {
450  if (m_routingProtocol != 0)
451  {
452  m_routingProtocol->NotifyRemoveAddress (i, address);
453  }
454  return true;
455  }
456  return false;
457 }
458 
459 bool
461 {
462  NS_LOG_FUNCTION (this << i << address);
463 
465  {
466  NS_LOG_WARN ("Cannot remove loopback address.");
467  return false;
468  }
469  Ptr<Ipv6Interface> interface = GetInterface (i);
470  Ipv6InterfaceAddress ifAddr = interface->RemoveAddress (address);
471  if (ifAddr != Ipv6InterfaceAddress ())
472  {
473  if (m_routingProtocol != 0)
474  {
475  m_routingProtocol->NotifyRemoveAddress (i, ifAddr);
476  }
477  return true;
478  }
479  return false;
480 }
481 
482 void Ipv6L3Protocol::SetMetric (uint32_t i, uint16_t metric)
483 {
484  NS_LOG_FUNCTION (this << i << metric);
485  Ptr<Ipv6Interface> interface = GetInterface (i);
486  interface->SetMetric (metric);
487 }
488 
489 uint16_t Ipv6L3Protocol::GetMetric (uint32_t i) const
490 {
491  NS_LOG_FUNCTION (this << i);
492  Ptr<Ipv6Interface> interface = GetInterface (i);
493  return interface->GetMetric ();
494 }
495 
496 uint16_t Ipv6L3Protocol::GetMtu (uint32_t i) const
497 {
498  NS_LOG_FUNCTION (this << i);
499 
500  // RFC 1981, if PMTU is disabled, return the minimum MTU
501  if (!m_mtuDiscover)
502  {
503  return IPV6_MIN_MTU;
504  }
505 
506  Ptr<Ipv6Interface> interface = GetInterface (i);
507  return interface->GetDevice ()->GetMtu ();
508 }
509 
510 void Ipv6L3Protocol::SetPmtu (Ipv6Address dst, uint32_t pmtu)
511 {
512  NS_LOG_FUNCTION (this << dst << int(pmtu));
513  m_pmtuCache->SetPmtu (dst, pmtu);
514 }
515 
516 
517 bool Ipv6L3Protocol::IsUp (uint32_t i) const
518 {
519  NS_LOG_FUNCTION (this << i);
520  Ptr<Ipv6Interface> interface = GetInterface (i);
521  return interface->IsUp ();
522 }
523 
524 void Ipv6L3Protocol::SetUp (uint32_t i)
525 {
526  NS_LOG_FUNCTION (this << i);
527  Ptr<Ipv6Interface> interface = GetInterface (i);
528 
529  // RFC 2460, Section 5, pg. 24:
530  // IPv6 requires that every link in the internet have an MTU of 1280
531  // octets or greater. On any link that cannot convey a 1280-octet
532  // packet in one piece, link-specific fragmentation and reassembly must
533  // be provided at a layer below IPv6.
534  if (interface->GetDevice ()->GetMtu () >= 1280)
535  {
536  interface->SetUp ();
537 
538  if (m_routingProtocol != 0)
539  {
540  m_routingProtocol->NotifyInterfaceUp (i);
541  }
542  }
543  else
544  {
545  NS_LOG_LOGIC ("Interface " << int(i) << " is set to be down for IPv6. Reason: not respecting minimum IPv6 MTU (1280 octets)");
546  }
547 }
548 
549 void Ipv6L3Protocol::SetDown (uint32_t i)
550 {
551  NS_LOG_FUNCTION (this << i);
552  Ptr<Ipv6Interface> interface = GetInterface (i);
553 
554  interface->SetDown ();
555 
556  if (m_routingProtocol != 0)
557  {
558  m_routingProtocol->NotifyInterfaceDown (i);
559  }
560 }
561 
563 {
566  Ptr<LoopbackNetDevice> device = 0;
567  uint32_t i = 0;
568 
569  /* see if we have already an loopback NetDevice */
570  for (i = 0; i < m_node->GetNDevices (); i++)
571  {
572  if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
573  {
574  break;
575  }
576  }
577 
578  if (device == 0)
579  {
580  device = CreateObject<LoopbackNetDevice> ();
581  m_node->AddDevice (device);
582  }
583 
584  interface->SetDevice (device);
585  interface->SetNode (m_node);
587  interface->AddAddress (ifaceAddr);
588  uint32_t index = AddIpv6Interface (interface);
589  Ptr<Node> node = GetObject<Node> ();
591  interface->SetUp ();
592 
593  if (m_routingProtocol != 0)
594  {
595  m_routingProtocol->NotifyInterfaceUp (index);
596  }
597 }
598 
599 bool Ipv6L3Protocol::IsForwarding (uint32_t i) const
600 {
601  NS_LOG_FUNCTION (this << i);
602  Ptr<Ipv6Interface> interface = GetInterface (i);
603 
604  NS_LOG_LOGIC ("Forwarding state: " << interface->IsForwarding ());
605  return interface->IsForwarding ();
606 }
607 
608 void Ipv6L3Protocol::SetForwarding (uint32_t i, bool val)
609 {
610  NS_LOG_FUNCTION (this << i << val);
611  Ptr<Ipv6Interface> interface = GetInterface (i);
612  interface->SetForwarding (val);
613 }
614 
616 {
617  NS_LOG_FUNCTION (this << interface << dest);
618  Ipv6Address ret;
619 
620  if (dest.IsLinkLocal () || dest.IsLinkLocalMulticast ())
621  {
622  for (uint32_t i = 0; i < GetNAddresses (interface); i++)
623  {
624  Ipv6InterfaceAddress test = GetAddress (interface, i);
625  if (test.GetScope () == Ipv6InterfaceAddress::LINKLOCAL)
626  {
627  return test.GetAddress ();
628  }
629  }
630  NS_ASSERT_MSG (false, "No link-local address found on interface " << interface);
631  }
632 
633  for (uint32_t i = 0; i < GetNAddresses (interface); i++)
634  {
635  Ipv6InterfaceAddress test = GetAddress (interface, i);
636 
637  if (test.GetScope () == Ipv6InterfaceAddress::GLOBAL)
638  {
639  if (test.IsInSameSubnet (dest))
640  {
641  return test.GetAddress ();
642  }
643  else
644  {
645  ret = test.GetAddress ();
646  }
647  }
648  }
649 
650  // no specific match found. Use a global address (any useful is fine).
651  return ret;
652 }
653 
654 void Ipv6L3Protocol::SetIpForward (bool forward)
655 {
656  NS_LOG_FUNCTION (this << forward);
657  m_ipForward = forward;
658 
659  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
660  {
661  (*it)->SetForwarding (forward);
662  }
663 }
664 
666 {
668  return m_ipForward;
669 }
670 
671 void Ipv6L3Protocol::SetMtuDiscover (bool mtuDiscover)
672 {
673  NS_LOG_FUNCTION (this << int(mtuDiscover));
674  m_mtuDiscover = mtuDiscover;
675 }
676 
678 {
679  NS_LOG_FUNCTION (this);
680  return m_mtuDiscover;
681 }
682 
683 void Ipv6L3Protocol::SetSendIcmpv6Redirect (bool sendIcmpv6Redirect)
684 {
685  NS_LOG_FUNCTION (this << sendIcmpv6Redirect);
686  m_sendIcmpv6Redirect = sendIcmpv6Redirect;
687 }
688 
690 {
692  return m_sendIcmpv6Redirect;
693 }
694 
696 {
698 
699  if (m_node == 0)
700  {
701  Ptr<Node> node = this->GetObject<Node> ();
702  // verify that it's a valid node and that
703  // the node has not been set before
704  if (node != 0)
705  {
706  this->SetNode (node);
707  }
708  }
709 
711 }
712 
714 {
715  NS_LOG_FUNCTION (this << node);
716  m_node = node;
717  /* add LoopbackNetDevice if needed, and an Ipv6Interface on top of it */
718  SetupLoopback ();
719 }
720 
722 {
723  NS_LOG_FUNCTION (this << protocol);
724  L4ListKey_t key = std::make_pair (protocol->GetProtocolNumber (), -1);
725  if (m_protocols.find (key) != m_protocols.end ())
726  {
727  NS_LOG_WARN ("Overwriting default protocol " << int(protocol->GetProtocolNumber ()));
728  }
729  m_protocols[key] = protocol;
730 }
731 
732 void Ipv6L3Protocol::Insert (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex)
733 {
734  NS_LOG_FUNCTION (this << protocol << interfaceIndex);
735 
736  L4ListKey_t key = std::make_pair (protocol->GetProtocolNumber (), interfaceIndex);
737  if (m_protocols.find (key) != m_protocols.end ())
738  {
739  NS_LOG_WARN ("Overwriting protocol " << int(protocol->GetProtocolNumber ()) << " on interface " << int(interfaceIndex));
740  }
741  m_protocols[key] = protocol;
742 }
743 
745 {
746  NS_LOG_FUNCTION (this << protocol);
747 
748  L4ListKey_t key = std::make_pair (protocol->GetProtocolNumber (), -1);
749  L4List_t::iterator iter = m_protocols.find (key);
750  if (iter == m_protocols.end ())
751  {
752  NS_LOG_WARN ("Trying to remove an non-existent default protocol " << int(protocol->GetProtocolNumber ()));
753  }
754  else
755  {
756  m_protocols.erase (key);
757  }
758 }
759 
760 void Ipv6L3Protocol::Remove (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex)
761 {
762  NS_LOG_FUNCTION (this << protocol << interfaceIndex);
763 
764  L4ListKey_t key = std::make_pair (protocol->GetProtocolNumber (), interfaceIndex);
765  L4List_t::iterator iter = m_protocols.find (key);
766  if (iter == m_protocols.end ())
767  {
768  NS_LOG_WARN ("Trying to remove an non-existent protocol " << int(protocol->GetProtocolNumber ()) << " on interface " << int(interfaceIndex));
769  }
770  else
771  {
772  m_protocols.erase (key);
773  }
774 }
775 
777 {
778  NS_LOG_FUNCTION (this << protocolNumber);
779 
780  return GetProtocol (protocolNumber, -1);
781 }
782 
783 Ptr<IpL4Protocol> Ipv6L3Protocol::GetProtocol (int protocolNumber, int32_t interfaceIndex) const
784 {
785  NS_LOG_FUNCTION (this << protocolNumber << interfaceIndex);
786 
787  L4ListKey_t key;
788  L4List_t::const_iterator i;
789  if (interfaceIndex >= 0)
790  {
791  // try the interface-specific protocol.
792  key = std::make_pair (protocolNumber, interfaceIndex);
793  i = m_protocols.find (key);
794  if (i != m_protocols.end ())
795  {
796  return i->second;
797  }
798  }
799  // try the generic protocol.
800  key = std::make_pair (protocolNumber, -1);
801  i = m_protocols.find (key);
802  if (i != m_protocols.end ())
803  {
804  return i->second;
805  }
806 
807  return 0;
808 }
809 
811 {
813  Ptr<Ipv6RawSocketImpl> sock = CreateObject<Ipv6RawSocketImpl> ();
814  sock->SetNode (m_node);
815  m_sockets.push_back (sock);
816  return sock;
817 }
818 
820 {
821  NS_LOG_FUNCTION (this << socket);
822 
823  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
824  {
825  if ((*it) == socket)
826  {
827  m_sockets.erase (it);
828  return;
829  }
830  }
831 }
832 
834 {
837 
838  if (protocol)
839  {
840  return protocol->GetObject<Icmpv6L4Protocol> ();
841  }
842  else
843  {
844  return 0;
845  }
846 }
847 
849 {
850  NS_LOG_FUNCTION (this << ttl);
851  m_defaultTtl = ttl;
852 }
853 
854 void Ipv6L3Protocol::SetDefaultTclass (uint8_t tclass)
855 {
856  NS_LOG_FUNCTION (this << tclass);
857  m_defaultTclass = tclass;
858 }
859 
860 void Ipv6L3Protocol::Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route)
861 {
862  NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol << route);
863  Ipv6Header hdr;
864  uint8_t ttl = m_defaultTtl;
866  bool found = packet->RemovePacketTag (tag);
867 
868  if (found)
869  {
870  ttl = tag.GetHopLimit ();
871  }
872 
873  SocketIpv6TclassTag tclassTag;
874  uint8_t tclass = m_defaultTclass;
875  found = packet->RemovePacketTag (tclassTag);
876 
877  if (found)
878  {
879  tclass = tclassTag.GetTclass ();
880  }
881 
882  /* Handle 3 cases:
883  * 1) Packet is passed in with a route entry
884  * 2) Packet is passed in with a route entry but route->GetGateway is not set (e.g., same network)
885  * 3) route is NULL (e.g., a raw socket call or ICMPv6)
886  */
887 
888  /* 1) */
889  if (route && route->GetGateway () != Ipv6Address::GetZero ())
890  {
891  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 1: passed in with a route");
892  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
893  int32_t interface = GetInterfaceForDevice (route->GetOutputDevice ());
894  m_sendOutgoingTrace (hdr, packet, interface);
895  SendRealOut (route, packet, hdr);
896  return;
897  }
898 
899  /* 2) */
900  if (route && route->GetGateway () == Ipv6Address::GetZero ())
901  {
902  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 2: probably sent to machine on same IPv6 network");
903  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
904  int32_t interface = GetInterfaceForDevice (route->GetOutputDevice ());
905  m_sendOutgoingTrace (hdr, packet, interface);
906  SendRealOut (route, packet, hdr);
907  return;
908  }
909 
910  /* 3) */
911  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 3: passed in with no route " << destination);
913  Ptr<NetDevice> oif (0);
914  Ptr<Ipv6Route> newRoute = 0;
915 
916  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
917 
918  //for link-local traffic, we need to determine the interface
919  if (source.IsLinkLocal ()
920  || destination.IsLinkLocal ()
921  || destination.IsLinkLocalMulticast ())
922  {
923  int32_t index = GetInterfaceForAddress (source);
924  NS_ASSERT_MSG (index >= 0, "Can not find an outgoing interface for a packet with src " << source << " and dst " << destination);
925  oif = GetNetDevice (index);
926  }
927 
928  newRoute = m_routingProtocol->RouteOutput (packet, hdr, oif, err);
929 
930  if (newRoute)
931  {
932  int32_t interface = GetInterfaceForDevice (newRoute->GetOutputDevice ());
933  m_sendOutgoingTrace (hdr, packet, interface);
934  SendRealOut (newRoute, packet, hdr);
935  }
936  else
937  {
938  NS_LOG_WARN ("No route to host, drop!");
940  }
941 }
942 
943 void Ipv6L3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
944 {
945  NS_LOG_FUNCTION (this << device << p << protocol << from << to << packetType);
946  NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
947 
948  NS_ASSERT_MSG (GetInterfaceForDevice(device) != -1, "Received a packet from an interface that is not known to IPv6");
949  uint32_t interface = GetInterfaceForDevice(device);
950 
951  Ptr<Ipv6Interface> ipv6Interface = m_interfaces[interface];
952  Ptr<Packet> packet = p->Copy ();
953 
954  if (ipv6Interface->IsUp ())
955  {
956  m_rxTrace (packet, m_node->GetObject<Ipv6> (), interface);
957  }
958  else
959  {
960  NS_LOG_LOGIC ("Dropping received packet-- interface is down");
961  Ipv6Header hdr;
962  packet->RemoveHeader (hdr);
963  m_dropTrace (hdr, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
964  return;
965  }
966 
967  Ipv6Header hdr;
968  packet->RemoveHeader (hdr);
969 
970  // Trim any residual frame padding from underlying devices
971  if (hdr.GetPayloadLength () < packet->GetSize ())
972  {
973  packet->RemoveAtEnd (packet->GetSize () - hdr.GetPayloadLength ());
974  }
975 
976  // the packet is valid, we update the NDISC cache entry (if present)
977  Ptr<NdiscCache> ndiscCache = ipv6Interface->GetNdiscCache ();
978  if (ndiscCache)
979  {
980  // case one, it's a a direct routing.
981  NdiscCache::Entry *entry = ndiscCache->Lookup (hdr.GetSourceAddress ());
982  if (entry)
983  {
984  entry->UpdateReachableTimer ();
985  }
986  else
987  {
988  // It's not in the direct routing, so it's the router, and it could have multiple IP addresses.
989  // In doubt, update all of them.
990  // Note: it's a confirmed behavior for Linux routers.
991  std::list<NdiscCache::Entry *> entryList = ndiscCache->LookupInverse (from);
992  std::list<NdiscCache::Entry *>::iterator iter;
993  for (iter = entryList.begin (); iter != entryList.end (); iter ++)
994  {
995  (*iter)->UpdateReachableTimer ();
996  }
997  }
998  }
999 
1000 
1001 
1002  /* forward up to IPv6 raw sockets */
1003  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
1004  {
1005  Ptr<Ipv6RawSocketImpl> socket = *it;
1006  socket->ForwardUp (packet, hdr, device);
1007  }
1008 
1009  Ptr<Ipv6ExtensionDemux> ipv6ExtensionDemux = m_node->GetObject<Ipv6ExtensionDemux> ();
1010  Ptr<Ipv6Extension> ipv6Extension = 0;
1011  uint8_t nextHeader = hdr.GetNextHeader ();
1012  bool stopProcessing = false;
1013  bool isDropped = false;
1014  DropReason dropReason;
1015 
1016  if (nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
1017  {
1018  ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
1019 
1020  if (ipv6Extension)
1021  {
1022  ipv6Extension->Process (packet, 0, hdr, hdr.GetDestinationAddress (), (uint8_t *)0, stopProcessing, isDropped, dropReason);
1023  }
1024 
1025  if (isDropped)
1026  {
1027  m_dropTrace (hdr, packet, dropReason, m_node->GetObject<Ipv6> (), interface);
1028  }
1029 
1030  if (stopProcessing)
1031  {
1032  return;
1033  }
1034  }
1035 
1037  {
1038  LocalDeliver (packet, hdr, interface);
1039  return;
1040  }
1041  else if (hdr.GetDestinationAddress ().IsAllRoutersMulticast() && ipv6Interface->IsForwarding ())
1042  {
1043  LocalDeliver (packet, hdr, interface);
1044  return;
1045  }
1046  else if (hdr.GetDestinationAddress ().IsMulticast ())
1047  {
1048  bool isSolicited = ipv6Interface->IsSolicitedMulticastAddress (hdr.GetDestinationAddress ());
1049  bool isRegisteredOnInterface = IsRegisteredMulticastAddress (hdr.GetDestinationAddress (), interface);
1050  bool isRegisteredGlobally = IsRegisteredMulticastAddress (hdr.GetDestinationAddress ());
1051  if (isSolicited || isRegisteredGlobally || isRegisteredOnInterface)
1052  {
1053  LocalDeliver (packet, hdr, interface);
1054  // do not return, the packet could be handled by a routing protocol
1055  }
1056  }
1057 
1058 
1059  for (uint32_t j = 0; j < GetNInterfaces (); j++)
1060  {
1061  if (j == interface || !m_strongEndSystemModel)
1062  {
1063  for (uint32_t i = 0; i < GetNAddresses (j); i++)
1064  {
1065  Ipv6InterfaceAddress iaddr = GetAddress (j, i);
1066  Ipv6Address addr = iaddr.GetAddress ();
1067  if (addr.IsEqual (hdr.GetDestinationAddress ()))
1068  {
1069  if (j == interface)
1070  {
1071  NS_LOG_LOGIC ("For me (destination " << addr << " match)");
1072  }
1073  else
1074  {
1075  NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << hdr.GetDestinationAddress ());
1076  }
1077  LocalDeliver (packet, hdr, interface);
1078  return;
1079  }
1080  NS_LOG_LOGIC ("Address " << addr << " not a match");
1081  }
1082  }
1083  }
1084 
1085  if (!m_routingProtocol->RouteInput (packet, hdr, device,
1090  {
1091  NS_LOG_WARN ("No route found for forwarding packet. Drop.");
1092  // Drop trace and ICMPs are courtesy of RouteInputError
1093  }
1094 }
1095 
1096 void
1098  Ptr<Ipv6> ipv6, uint32_t interface)
1099 {
1100  Ptr<Packet> packetCopy = packet->Copy ();
1101  packetCopy->AddHeader (ipHeader);
1102  m_txTrace (packetCopy, ipv6, interface);
1103 }
1104 
1106 {
1107  NS_LOG_FUNCTION (this << route << packet << ipHeader);
1108 
1109  if (!route)
1110  {
1111  NS_LOG_LOGIC ("No route to host, drop!.");
1112  return;
1113  }
1114 
1115  Ptr<NetDevice> dev = route->GetOutputDevice ();
1116  int32_t interface = GetInterfaceForDevice (dev);
1117  NS_ASSERT (interface >= 0);
1118 
1119  Ptr<Ipv6Interface> outInterface = GetInterface (interface);
1120  NS_LOG_LOGIC ("Send via NetDevice ifIndex " << dev->GetIfIndex () << " Ipv6InterfaceIndex " << interface);
1121 
1122  // Check packet size
1123  std::list<Ipv6ExtensionFragment::Ipv6PayloadHeaderPair> fragments;
1124 
1125  // Check if we have a Path MTU stored. If so, use it. Else, use the link MTU.
1126  size_t targetMtu = (size_t)(m_pmtuCache->GetPmtu (ipHeader.GetDestinationAddress()));
1127  if (targetMtu == 0)
1128  {
1129  targetMtu = dev->GetMtu ();
1130  }
1131 
1132  if (packet->GetSize () > targetMtu + 40) /* 40 => size of IPv6 header */
1133  {
1134  // Router => drop
1135 
1136  bool fromMe = false;
1137  for (uint32_t i=0; i<GetNInterfaces(); i++ )
1138  {
1139  for (uint32_t j=0; j<GetNAddresses(i); j++ )
1140  {
1141  if (GetAddress(i,j).GetAddress() == ipHeader.GetSourceAddress())
1142  {
1143  fromMe = true;
1144  break;
1145  }
1146  }
1147  }
1148  if (!fromMe)
1149  {
1150  Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
1151  if ( icmpv6 )
1152  {
1153  packet->AddHeader(ipHeader);
1154  icmpv6->SendErrorTooBig (packet, ipHeader.GetSourceAddress (), dev->GetMtu ());
1155  }
1156  return;
1157  }
1158 
1159  Ptr<Ipv6ExtensionDemux> ipv6ExtensionDemux = m_node->GetObject<Ipv6ExtensionDemux> ();
1160 
1161  // To get specific method GetFragments from Ipv6ExtensionFragmentation
1162  Ipv6ExtensionFragment *ipv6Fragment = dynamic_cast<Ipv6ExtensionFragment *> (PeekPointer (ipv6ExtensionDemux->GetExtension (Ipv6Header::IPV6_EXT_FRAGMENTATION)));
1163  NS_ASSERT (ipv6Fragment != 0);
1164  ipv6Fragment->GetFragments (packet, ipHeader, targetMtu, fragments);
1165  }
1166 
1167  if (!route->GetGateway ().IsEqual (Ipv6Address::GetAny ()))
1168  {
1169  if (outInterface->IsUp ())
1170  {
1171  NS_LOG_LOGIC ("Send to gateway " << route->GetGateway ());
1172 
1173  if (fragments.size () != 0)
1174  {
1175  std::ostringstream oss;
1176 
1177  for (std::list<Ipv6ExtensionFragment::Ipv6PayloadHeaderPair>::const_iterator it = fragments.begin (); it != fragments.end (); it++)
1178  {
1179  CallTxTrace (it->second, it->first, m_node->GetObject<Ipv6> (), interface);
1180  outInterface->Send (it->first, it->second, route->GetGateway ());
1181  }
1182  }
1183  else
1184  {
1185  CallTxTrace (ipHeader, packet, m_node->GetObject<Ipv6> (), interface);
1186  outInterface->Send (packet, ipHeader, route->GetGateway ());
1187  }
1188  }
1189  else
1190  {
1191  NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route->GetGateway ());
1192  m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
1193  }
1194  }
1195  else
1196  {
1197  if (outInterface->IsUp ())
1198  {
1199  NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestinationAddress ());
1200 
1201  if (fragments.size () != 0)
1202  {
1203  std::ostringstream oss;
1204 
1205  for (std::list<Ipv6ExtensionFragment::Ipv6PayloadHeaderPair>::const_iterator it = fragments.begin (); it != fragments.end (); it++)
1206  {
1207  CallTxTrace (it->second, it->first, m_node->GetObject<Ipv6> (), interface);
1208  outInterface->Send (it->first, it->second, ipHeader.GetDestinationAddress ());
1209  }
1210  }
1211  else
1212  {
1213  CallTxTrace (ipHeader, packet, m_node->GetObject<Ipv6> (), interface);
1214  outInterface->Send (packet, ipHeader, ipHeader.GetDestinationAddress ());
1215  }
1216  }
1217  else
1218  {
1219  NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << ipHeader.GetDestinationAddress ());
1220  m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
1221  }
1222  }
1223 }
1224 
1226 {
1227  NS_LOG_FUNCTION (this << rtentry << p << header);
1228  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
1229 
1230  // Drop RFC 3849 packets: 2001:db8::/32
1231  if (header.GetDestinationAddress().IsDocumentation ())
1232  {
1233  NS_LOG_WARN ("Received a packet for 2001:db8::/32 (documentation class). Drop.");
1234  m_dropTrace (header, p, DROP_ROUTE_ERROR, m_node->GetObject<Ipv6> (), 0);
1235  return;
1236  }
1237 
1238  // Forwarding
1239  Ipv6Header ipHeader = header;
1240  Ptr<Packet> packet = p->Copy ();
1241  ipHeader.SetHopLimit (ipHeader.GetHopLimit () - 1);
1242 
1243  if (ipHeader.GetSourceAddress ().IsLinkLocal ())
1244  {
1245  /* no forward for link-local address */
1246  return;
1247  }
1248 
1249  if (ipHeader.GetHopLimit () == 0)
1250  {
1251  NS_LOG_WARN ("TTL exceeded. Drop.");
1252  m_dropTrace (ipHeader, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv6> (), 0);
1253  // Do not reply to multicast IPv6 address
1254  if (ipHeader.GetDestinationAddress ().IsMulticast () == false)
1255  {
1256  packet->AddHeader (ipHeader);
1257  GetIcmpv6 ()->SendErrorTimeExceeded (packet, ipHeader.GetSourceAddress (), Icmpv6Header::ICMPV6_HOPLIMIT);
1258  }
1259  return;
1260  }
1261 
1262  /* ICMPv6 Redirect */
1263 
1264  /* if we forward to a machine on the same network as the source,
1265  * we send him an ICMPv6 redirect message to notify him that a short route
1266  * exists.
1267  */
1268 
1269  /* Theoretically we should also check if the redirect target is on the same network
1270  * as the source node. On the other hand, we are sure that the router we're redirecting to
1271  * used a link-local address. As a consequence, they MUST be on the same network, the link-local net.
1272  */
1273 
1274  if (m_sendIcmpv6Redirect && (rtentry->GetOutputDevice ()==idev))
1275  {
1276  NS_LOG_LOGIC ("ICMPv6 redirect!");
1277  Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
1278  Address hardwareTarget;
1279  Ipv6Address dst = header.GetDestinationAddress ();
1280  Ipv6Address src = header.GetSourceAddress ();
1281  Ipv6Address target = rtentry->GetGateway ();
1282  Ptr<Packet> copy = p->Copy ();
1283 
1284  if (target.IsAny ())
1285  {
1286  target = dst;
1287  }
1288 
1289  copy->AddHeader (header);
1290  Ipv6Address linkLocal = GetInterface (GetInterfaceForDevice (rtentry->GetOutputDevice ()))->GetLinkLocalAddress ().GetAddress ();
1291 
1292  if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
1293  {
1294  icmpv6->SendRedirection (copy, linkLocal, src, target, dst, hardwareTarget);
1295  }
1296  else
1297  {
1298  icmpv6->SendRedirection (copy, linkLocal, src, target, dst, Address ());
1299  }
1300  }
1301  // in case the packet still has a priority tag attached, remove it
1302  SocketPriorityTag priorityTag;
1303  packet->RemovePacketTag (priorityTag);
1304  int32_t interface = GetInterfaceForDevice (rtentry->GetOutputDevice ());
1305  m_unicastForwardTrace (ipHeader, packet, interface);
1306  SendRealOut (rtentry, packet, ipHeader);
1307 }
1308 
1310 {
1311  NS_LOG_FUNCTION (this << mrtentry << p << header);
1312  NS_LOG_LOGIC ("Multicast forwarding logic for node: " << m_node->GetId ());
1313 
1314  std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
1315  std::map<uint32_t, uint32_t>::iterator mapIter;
1316 
1317  for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
1318  {
1319  uint32_t interfaceId = mapIter->first;
1320  //uint32_t outputTtl = mapIter->second; // Unused for now
1321  Ptr<Packet> packet = p->Copy ();
1322  Ipv6Header h = header;
1323  h.SetHopLimit (header.GetHopLimit () - 1);
1324  if (h.GetHopLimit () == 0)
1325  {
1326  NS_LOG_WARN ("TTL exceeded. Drop.");
1327  m_dropTrace (header, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv6> (), interfaceId);
1328  return;
1329  }
1330  NS_LOG_LOGIC ("Forward multicast via interface " << interfaceId);
1331  Ptr<Ipv6Route> rtentry = Create<Ipv6Route> ();
1332  rtentry->SetSource (h.GetSourceAddress ());
1333  rtentry->SetDestination (h.GetDestinationAddress ());
1334  rtentry->SetGateway (Ipv6Address::GetAny ());
1335  rtentry->SetOutputDevice (GetNetDevice (interfaceId));
1336  SendRealOut (rtentry, packet, h);
1337  continue;
1338  }
1339 }
1340 
1341 void Ipv6L3Protocol::LocalDeliver (Ptr<const Packet> packet, Ipv6Header const& ip, uint32_t iif)
1342 {
1343  NS_LOG_FUNCTION (this << packet << ip << iif);
1344  Ptr<Packet> p = packet->Copy ();
1345  Ptr<IpL4Protocol> protocol = 0;
1346  Ptr<Ipv6ExtensionDemux> ipv6ExtensionDemux = m_node->GetObject<Ipv6ExtensionDemux> ();
1347  Ptr<Ipv6Extension> ipv6Extension = 0;
1348  Ipv6Address src = ip.GetSourceAddress ();
1349  Ipv6Address dst = ip.GetDestinationAddress ();
1350  uint8_t nextHeader = ip.GetNextHeader ();
1351  uint8_t nextHeaderPosition = 0;
1352  bool isDropped = false;
1353  bool stopProcessing = false;
1354  DropReason dropReason;
1355 
1356  // check for a malformed hop-by-hop extension
1357  // this is a common case when forging IPv6 raw packets
1358  if (nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
1359  {
1360  uint8_t buf;
1361  p->CopyData (&buf, 1);
1363  {
1364  NS_LOG_WARN("Double Ipv6Header::IPV6_EXT_HOP_BY_HOP in packet, dropping packet");
1365  return;
1366  }
1367  }
1368 
1369  /* process all the extensions found and the layer 4 protocol */
1370  do
1371  {
1372  /* it return 0 for non-extension (i.e. layer 4 protocol) */
1373  ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
1374 
1375  if (ipv6Extension)
1376  {
1377  uint8_t nextHeaderStep = 0;
1378  uint8_t curHeader = nextHeader;
1379  nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, stopProcessing, isDropped, dropReason);
1380  nextHeaderPosition += nextHeaderStep;
1381 
1382  if (isDropped)
1383  {
1384  m_dropTrace (ip, packet, dropReason, m_node->GetObject<Ipv6> (), iif);
1385  }
1386 
1387  if (stopProcessing)
1388  {
1389  return;
1390  }
1391  NS_ASSERT_MSG (nextHeaderStep != 0 || curHeader == Ipv6Header::IPV6_EXT_FRAGMENTATION,
1392  "Zero-size IPv6 Option Header, aborting" << *packet );
1393  }
1394  else
1395  {
1396  protocol = GetProtocol (nextHeader, iif);
1397 
1398  if (!protocol)
1399  {
1400  NS_LOG_LOGIC ("Unknown Next Header. Drop!");
1401 
1402  // For ICMPv6 Error packets
1403  Ptr<Packet> malformedPacket = packet->Copy ();
1404  malformedPacket->AddHeader (ip);
1405 
1406  if (nextHeaderPosition == 0)
1407  {
1408  GetIcmpv6 ()->SendErrorParameterError (malformedPacket, dst, Icmpv6Header::ICMPV6_UNKNOWN_NEXT_HEADER, 40);
1409  }
1410  else
1411  {
1412  GetIcmpv6 ()->SendErrorParameterError (malformedPacket, dst, Icmpv6Header::ICMPV6_UNKNOWN_NEXT_HEADER, ip.GetSerializedSize () + nextHeaderPosition);
1413  }
1415  break;
1416  }
1417  else
1418  {
1419  p->RemoveAtStart (nextHeaderPosition);
1420  /* protocol->Receive (p, src, dst, incomingInterface); */
1421 
1422  /* L4 protocol */
1423  Ptr<Packet> copy = p->Copy ();
1424 
1425  m_localDeliverTrace (ip, p, iif);
1426 
1427  enum IpL4Protocol::RxStatus status = protocol->Receive (p, ip, GetInterface (iif));
1428 
1429  switch (status)
1430  {
1431  case IpL4Protocol::RX_OK:
1432  break;
1434  break;
1436  break;
1438  if (ip.GetDestinationAddress ().IsMulticast ())
1439  {
1440  /* do not rely on multicast address */
1441  break;
1442  }
1443 
1444  copy->AddHeader (ip);
1445  GetIcmpv6 ()->SendErrorDestinationUnreachable (copy, ip.GetSourceAddress (), Icmpv6Header::ICMPV6_PORT_UNREACHABLE);
1446  }
1447  }
1448  }
1449  }
1450  while (ipv6Extension);
1451 }
1452 
1454 {
1455  NS_LOG_FUNCTION (this << p << ipHeader << sockErrno);
1456  NS_LOG_LOGIC ("Route input failure-- dropping packet to " << ipHeader << " with errno " << sockErrno);
1457 
1458  m_dropTrace (ipHeader, p, DROP_ROUTE_ERROR, m_node->GetObject<Ipv6> (), 0);
1459 
1460  if (!ipHeader.GetDestinationAddress ().IsMulticast ())
1461  {
1462  Ptr<Packet> packet = p->Copy ();
1463  packet->AddHeader (ipHeader);
1464  GetIcmpv6 ()->SendErrorDestinationUnreachable (packet, ipHeader.GetSourceAddress (), Icmpv6Header::ICMPV6_NO_ROUTE);
1465  }
1466 }
1467 
1468 Ipv6Header Ipv6L3Protocol::BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, uint8_t tclass)
1469 {
1470  NS_LOG_FUNCTION (this << src << dst << (uint32_t)protocol << (uint32_t)payloadSize << (uint32_t)ttl << (uint32_t)tclass);
1471  Ipv6Header hdr;
1472 
1473  hdr.SetSourceAddress (src);
1474  hdr.SetDestinationAddress (dst);
1475  hdr.SetNextHeader (protocol);
1476  hdr.SetPayloadLength (payloadSize);
1477  hdr.SetHopLimit (ttl);
1478  hdr.SetTrafficClass (tclass);
1479  return hdr;
1480 }
1481 
1483 {
1484  Ptr<Ipv6ExtensionDemux> ipv6ExtensionDemux = CreateObject<Ipv6ExtensionDemux> ();
1485  ipv6ExtensionDemux->SetNode (m_node);
1486 
1487  Ptr<Ipv6ExtensionHopByHop> hopbyhopExtension = CreateObject<Ipv6ExtensionHopByHop> ();
1488  hopbyhopExtension->SetNode (m_node);
1489  Ptr<Ipv6ExtensionDestination> destinationExtension = CreateObject<Ipv6ExtensionDestination> ();
1490  destinationExtension->SetNode (m_node);
1491  Ptr<Ipv6ExtensionFragment> fragmentExtension = CreateObject<Ipv6ExtensionFragment> ();
1492  fragmentExtension->SetNode (m_node);
1493  Ptr<Ipv6ExtensionRouting> routingExtension = CreateObject<Ipv6ExtensionRouting> ();
1494  routingExtension->SetNode (m_node);
1495  // Ptr<Ipv6ExtensionESP> espExtension = CreateObject<Ipv6ExtensionESP> ();
1496  // Ptr<Ipv6ExtensionAH> ahExtension = CreateObject<Ipv6ExtensionAH> ();
1497 
1498  ipv6ExtensionDemux->Insert (hopbyhopExtension);
1499  ipv6ExtensionDemux->Insert (destinationExtension);
1500  ipv6ExtensionDemux->Insert (fragmentExtension);
1501  ipv6ExtensionDemux->Insert (routingExtension);
1502  // ipv6ExtensionDemux->Insert (espExtension);
1503  // ipv6ExtensionDemux->Insert (ahExtension);
1504 
1505  Ptr<Ipv6ExtensionRoutingDemux> routingExtensionDemux = CreateObject<Ipv6ExtensionRoutingDemux> ();
1506  routingExtensionDemux->SetNode (m_node);
1507  Ptr<Ipv6ExtensionLooseRouting> looseRoutingExtension = CreateObject<Ipv6ExtensionLooseRouting> ();
1508  looseRoutingExtension->SetNode (m_node);
1509  routingExtensionDemux->Insert (looseRoutingExtension);
1510 
1511  m_node->AggregateObject (routingExtensionDemux);
1512  m_node->AggregateObject (ipv6ExtensionDemux);
1513 }
1514 
1516 {
1517  Ptr<Ipv6OptionDemux> ipv6OptionDemux = CreateObject<Ipv6OptionDemux> ();
1518  ipv6OptionDemux->SetNode (m_node);
1519 
1520  Ptr<Ipv6OptionPad1> pad1Option = CreateObject<Ipv6OptionPad1> ();
1521  pad1Option->SetNode (m_node);
1522  Ptr<Ipv6OptionPadn> padnOption = CreateObject<Ipv6OptionPadn> ();
1523  padnOption->SetNode (m_node);
1524  Ptr<Ipv6OptionJumbogram> jumbogramOption = CreateObject<Ipv6OptionJumbogram> ();
1525  jumbogramOption->SetNode (m_node);
1526  Ptr<Ipv6OptionRouterAlert> routerAlertOption = CreateObject<Ipv6OptionRouterAlert> ();
1527  routerAlertOption->SetNode (m_node);
1528 
1529  ipv6OptionDemux->Insert (pad1Option);
1530  ipv6OptionDemux->Insert (padnOption);
1531  ipv6OptionDemux->Insert (jumbogramOption);
1532  ipv6OptionDemux->Insert (routerAlertOption);
1533 
1534  m_node->AggregateObject (ipv6OptionDemux);
1535 }
1536 
1538 {
1539  m_dropTrace (ipHeader, p, dropReason, m_node->GetObject<Ipv6> (), 0);
1540 }
1541 
1543 {
1544  NS_LOG_FUNCTION (address << interface);
1545 
1546  if (!address.IsMulticast ())
1547  {
1548  NS_LOG_WARN ("Not adding a non-multicast address " << address);
1549  return;
1550  }
1551 
1552  Ipv6RegisteredMulticastAddressKey_t key = std::make_pair (address, interface);
1553  m_multicastAddresses[key]++;
1554 }
1555 
1557 {
1559 
1560  if (!address.IsMulticast ())
1561  {
1562  NS_LOG_WARN ("Not adding a non-multicast address " << address);
1563  return;
1564  }
1565 
1567 }
1568 
1570 {
1571  NS_LOG_FUNCTION (address << interface);
1572 
1573  Ipv6RegisteredMulticastAddressKey_t key = std::make_pair (address, interface);
1574 
1575  m_multicastAddresses[key]--;
1576  if (m_multicastAddresses[key] == 0)
1577  {
1578  m_multicastAddresses.erase (key);
1579  }
1580 }
1581 
1583 {
1585 
1588  {
1590  }
1591 }
1592 
1594 {
1595  NS_LOG_FUNCTION (address << interface);
1596 
1597  Ipv6RegisteredMulticastAddressKey_t key = std::make_pair (address, interface);
1599 
1600  if (iter == m_multicastAddresses.end ())
1601  {
1602  return false;
1603  }
1604  return true;
1605 }
1606 
1608 {
1610 
1612 
1613  if (iter == m_multicastAddressesNoInterface.end ())
1614  {
1615  return false;
1616  }
1617  return true;
1618 }
1619 
1620 } /* namespace ns3 */
1621 
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint16_t GetMtu(uint32_t i) const
Get MTU for an interface.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv6 L4 keys: protocol number, interface index.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:280
static bool IsMatchingType(const Address &address)
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
Definition: ipv6-header.cc:65
static Ipv6Address GetLoopback()
Get the loopback address.
Ipv6Header BuildHeader(Ipv6Address src, Ipv6Address dst, uint8_t protocol, uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass)
Construct an IPv6 header.
uint16_t GetPayloadLength(void) const
Get the "Payload length" field.
Definition: ipv6-header.cc:70
void SetForwarding(uint32_t i, bool val)
Enable or disable forwarding on interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
Packet header for IPv6.
Definition: ipv6-header.h:34
bool AddAddress(Ipv6InterfaceAddress iface)
Add an IPv6 address.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t GetMetric(uint32_t i) const
Get metric for an interface.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressCIter_t
Container Const Iterator of the IPv6 multicast addresses.
virtual ~Ipv6L3Protocol()
Destructor.
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const
Get current routing protocol used.
void SetUp()
Enable this interface.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
Ipv6InterfaceAddress GetLinkLocalAddress() const
Get link-local address from IPv6 interface.
Ipv6L3Protocol()
Constructor.
virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu)
Set the Path MTU for the specified IPv6 destination address.
bool IsUp(uint32_t i) const
Is specified interface up ?
uint32_t GetId(void) const
Definition: node.cc:107
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:1163
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< NetDevice > GetNetDevice(uint32_t i)
Get device by index.
bool AddAddress(uint32_t i, Ipv6InterfaceAddress address)
Add an address on interface.
Ptr< Ipv6RoutingProtocol > m_routingProtocol
Routing protocol.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:852
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
bool IsRegisteredMulticastAddress(Ipv6Address address) const
Checks if the address has been registered.
Introspection did not find any typical Config paths.
static Mac16Address ConvertFrom(const Address &address)
std::map< Ipv6Address, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t
Container Const Iterator of the IPv6 multicast addresses.
static bool IsMatchingType(const Address &address)
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Definition: node.cc:142
uint32_t AddIpv6Interface(Ptr< Ipv6Interface > interface)
Add an IPv6 interface to the stack.
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers...
IPv6 layer implementation.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
Demultiplexes IPv6 extensions.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
uint8_t GetTclass(void) const
Get the tag&#39;s Tclass.
Definition: socket.cc:906
Interface is down so can not send packet.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
void SetNode(Ptr< Node > node)
Set the node.
#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
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:564
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
IPv6 address associated with an interface.
Link-local address (fe80::/64)
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:75
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive method when a packet arrive in the stack.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const
Get interface index which match specified address/prefix.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
virtual void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by NetDevices, incoming packet.
Ptr< Ipv6Interface > GetInterface(uint32_t i) const
Get an interface.
virtual void DoDispose()
Dispose object.
void SetMetric(uint32_t i, uint16_t metric)
Set metric for an interface.
virtual int GetProtocolNumber(void) const =0
Returns the protocol number of this protocol.
bool ForwardUp(Ptr< const Packet > p, Ipv6Header hdr, Ptr< NetDevice > device)
Forward up to receive method.
uint32_t AddInterface(Ptr< NetDevice > device)
Add IPv6 interface for a device.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Ptr< Node > m_node
Node attached to stack.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
std::pair< Ipv6Address, uint64_t > Ipv6RegisteredMulticastAddressKey_t
IPv6 multicast addresses / interface key.
void CallTxTrace(const Ipv6Header &ipHeader, Ptr< Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Make a copy of the packet, add the header and invoke the TX trace callback.
void AddMulticastAddress(Ipv6Address address)
Adds a multicast address to the list of addresses to pass to local deliver.
a polymophic address class
Definition: address.h:90
virtual void SetIpForward(bool forward)
Set IPv6 forwarding state.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual void NotifyNewAggregate()
Notify other components connected to the node that a new stack member is now connected.
Ptr< Icmpv6L4Protocol > GetIcmpv6() const
Get ICMPv6 protocol.
uint32_t m_nInterfaces
Number of IPv6 interfaces managed by the stack.
void SetDefaultTclass(uint8_t tclass)
Set the default TCLASS.
The IPv6 representation of a network interface.
void Send(Ptr< Packet > p, const Ipv6Header &hdr, Ipv6Address dest)
Send a packet through this interface.
bool m_strongEndSystemModel
Rejects packets directed to an interface with wrong address (RFC 1222).
void SetMetric(uint16_t metric)
Set the metric.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:362
bool IsEqual(const Ipv6Address &other) const
Comparison operation between two Ipv6Addresses.
virtual bool GetSendIcmpv6Redirect() const
Get the ICMPv6 Redirect sending state.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Get L4 protocol by protocol number.
bool IsDocumentation() const
If the IPv6 address is a documentation address (2001:DB8::/32).
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
#define IPV6_MIN_MTU
Minimum IPv6 MTU, as defined by RFC 2460
Hold an unsigned integer type.
Definition: uinteger.h:44
L4List_t m_protocols
List of transport protocol.
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Get an address.
void SetDefaultTtl(uint8_t ttl)
Set the default TTL.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
bool IsUp() const
Is the interface UP ?
void IpMulticastForward(Ptr< const NetDevice > idev, Ptr< Ipv6MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a multicast packet.
void RemoveMulticastAddress(Ipv6Address address)
Removes a multicast address from the list of addresses to pass to local deliver.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
Definition: ipv6-header.cc:143
indicates whether the socket has a priority set.
Definition: socket.h:1307
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
void SetUp(uint32_t i)
Set an interface up.
An implementation of the ICMPv6 protocol.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
virtual enum RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)=0
Called from lower-level layers to send the packet up in the stack.
virtual void ReportDrop(Ipv6Header ipHeader, Ptr< Packet > p, DropReason dropReason)
Report a packet drop.
static TypeId GetTypeId()
Get the type ID of this class.
Ipv6InterfaceList m_interfaces
List of IPv6 interfaces.
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:100
bool m_ipForward
Forwarding packets (i.e.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
static Mac48Address ConvertFrom(const Address &address)
void SetForwarding(bool forward)
Set forwarding enabled or not.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
std::list< Ptr< Ipv6AutoconfiguredPrefix > >::iterator Ipv6AutoconfiguredPrefixListI
Iterator of the container of the IPv6 Autoconfigured addresses.
Ipv6RegisteredMulticastAddress_t m_multicastAddresses
List of multicast IP addresses of interest, divided per interface.
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
Ipv6AutoconfiguredPrefixList m_prefixes
List of IPv6 prefix received from RA.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LocalDeliver(Ptr< const Packet > p, Ipv6Header const &ip, uint32_t iif)
Deliver a packet.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
address
Definition: first.py:37
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
static uint16_t GetStaticProtocolNumber()
Get ICMPv6 protocol number.
Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)
Choose the source address to use with destination address.
void IpForward(Ptr< const NetDevice > idev, Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
Definition: packet.cc:355
uint8_t m_defaultTtl
Default TTL for outgoing packets.
indicates whether the socket has IPV6_TCLASS set.
Definition: socket.h:1354
TracedCallback< const Ipv6Header &, Ptr< const Packet >, DropReason, Ptr< Ipv6 >, uint32_t > m_dropTrace
Callback to trace drop packets.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
uint8_t GetNextHeader(void) const
Get the next header.
Definition: ipv6-header.cc:80
uint32_t GetNAddresses(void) const
Get number of addresses on this IPv6 interface.
Ipv6InterfaceAddress GetAddress(uint32_t index) const
Get an address from IPv6 interface.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Ipv6InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
uint32_t GetNInterfaces() const
Get current number of interface on this stack.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
void RemoveAutoconfiguredAddress(uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter)
Remove an autoconfigured address.
void SendRealOut(Ptr< Ipv6Route > route, Ptr< Packet > packet, Ipv6Header const &ipHeader)
Send packet with route.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Definition: node.cc:227
void UpdateReachableTimer()
Update the reachable timer.
Definition: ndisc-cache.cc:431
bool IsLinkLocalMulticast() const
If the IPv6 address is link-local multicast (ff02::/16).
void SetupLoopback()
Setup loopback interface.
std::list< NdiscCache::Entry * > LookupInverse(Address dst)
Lookup in the cache for a MAC address.
Definition: ndisc-cache.cc:107
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:95
IPv6 Extension Fragment.
double max(double x, double y)
virtual void RegisterExtensions()
Register the IPv6 Extensions.
virtual bool GetMtuDiscover(void) const
Get IPv6 MTU discover state.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
uint16_t GetMetric() const
Get the metric.
bool IsForwarding(uint32_t i) const
Is interface allows forwarding ?
NdiscCache::Entry * Lookup(Ipv6Address dst)
Lookup in the cache.
Definition: ndisc-cache.cc:93
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Definition: ipv6-header.cc:85
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
Definition: node.cc:128
static Mac64Address ConvertFrom(const Address &address)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:264
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:378
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:870
virtual void Insert(Ptr< IpL4Protocol > protocol)
Add a L4 protocol.
Ipv6RegisteredMulticastAddressNoInterface_t m_multicastAddressesNoInterface
List of multicast IP addresses of interest for all the interfaces.
virtual bool GetIpForward() const
Get IPv6 forwarding state.
bool m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Get interface index which is on a specified net device.
virtual void RegisterOptions()
Register the IPv6 Options.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
Describes an IPv6 prefix.
Definition: ipv6-address.h:449
void SetDown(uint32_t i)
set an interface down.
Ptr< T > CreateObject(void)
Create an object by type, with varying number of constructor parameters.
Definition: object.h:528
void SetTrafficClass(uint8_t traffic)
Set the "Traffic class" field.
Definition: ipv6-header.cc:45
A record that holds information about a NdiscCache entry.
Definition: ndisc-cache.h:156
uint32_t GetNAddresses(uint32_t interface) const
Get number of address for an interface.
RxStatus
Rx status codes.
bool m_mtuDiscover
MTU Discover (i.e.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:325
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove an address from an interface.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
Container for a set of ns3::Object pointers.
Ptr< Ipv6PmtuCache > m_pmtuCache
Path MTU Cache.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
Definition: ipv6-header.cc:90
static bool IsMatchingType(const Address &address)
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:110
int32_t GetInterfaceForAddress(Ipv6Address addr) const
Get interface index which has specified IPv6 address.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
virtual void SetMtuDiscover(bool mtuDiscover)
Set IPv6 MTU discover state.
uint8_t m_defaultTclass
Default TCLASS for outgoing packets.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
void SetDown()
Disable this interface.
a unique identifier for an interface.
Definition: type-id.h:58
void StartPreferredTimer()
Start the preferred timer.
uint8_t GetHopLimit(void) const
Get the tag&#39;s Hop Limit.
Definition: socket.cc:671
void SetDestinationAddress(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:105
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
SocketList m_sockets
List of IPv6 raw sockets.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
void AddHeader(const Header &header)
Add header to this packet.
Definition: packet.cc:256
uint32_t GetNDevices(void) const
Definition: node.cc:150
bool IsAny() const
If the IPv6 address is the "Any" address.
virtual void Remove(Ptr< IpL4Protocol > protocol)
Remove a L4 protocol.
void AddAutoconfiguredAddress(uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter=Ipv6Address::GetZero())
Add an autoconfigured address with RA information.
DropReason
Reason why a packet has been dropped.
virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect)
Set the ICMPv6 Redirect sending state.
void RouteInputError(Ptr< const Packet > p, const Ipv6Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.