A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-l3-protocol.cc
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 
32 #include "loopback-net-device.h"
33 #include "ipv6-l3-protocol.h"
34 #include "ipv6-interface.h"
35 #include "ipv6-raw-socket-impl.h"
36 #include "ipv6-autoconfigured-prefix.h"
37 #include "ipv6-extension-demux.h"
38 #include "ipv6-extension.h"
39 #include "ipv6-extension-header.h"
40 #include "ipv6-option-demux.h"
41 #include "ipv6-option.h"
42 #include "icmpv6-l4-protocol.h"
43 #include "ndisc-cache.h"
44 
45 namespace ns3 {
46 
47 NS_OBJECT_ENSURE_REGISTERED (Ipv6L3Protocol);
48 
49 NS_LOG_COMPONENT_DEFINE ("Ipv6L3Protocol");
50 
51 const uint16_t Ipv6L3Protocol::PROT_NUMBER = 0x86DD;
52 
54 {
55  static TypeId tid = TypeId ("ns3::Ipv6L3Protocol")
56  .SetParent<Ipv6> ()
57  .AddConstructor<Ipv6L3Protocol> ()
58  .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
59  UintegerValue (64),
60  MakeUintegerAccessor (&Ipv6L3Protocol::m_defaultTtl),
61  MakeUintegerChecker<uint8_t> ())
62  .AddAttribute ("DefaultTclass", "The TCLASS value set by default on all outgoing packets generated on this node.",
63  UintegerValue (0),
64  MakeUintegerAccessor (&Ipv6L3Protocol::m_defaultTclass),
65  MakeUintegerChecker<uint8_t> ())
66  .AddAttribute ("InterfaceList", "The set of IPv6 interfaces associated to this IPv6 stack.",
68  MakeObjectVectorAccessor (&Ipv6L3Protocol::m_interfaces),
69  MakeObjectVectorChecker<Ipv6Interface> ())
70  .AddAttribute ("SendIcmpv6Redirect", "Send the ICMPv6 Redirect when appropriate.",
71  BooleanValue (true),
72  MakeBooleanAccessor (&Ipv6L3Protocol::SetSendIcmpv6Redirect,
74  MakeBooleanChecker ())
75  .AddTraceSource ("Tx", "Send IPv6 packet to outgoing interface.",
77  .AddTraceSource ("Rx", "Receive IPv6 packet from incoming interface.",
79  .AddTraceSource ("Drop", "Drop IPv6 packet",
81  ;
82  return tid;
83 }
84 
86  : m_nInterfaces (0)
87 {
89 }
90 
92 {
94 }
95 
97 {
99 
100  /* clear protocol and interface list */
101  for (L4List_t::iterator it = m_protocols.begin (); it != m_protocols.end (); ++it)
102  {
103  *it = 0;
104  }
105  m_protocols.clear ();
106 
107  /* remove interfaces */
108  for (Ipv6InterfaceList::iterator it = m_interfaces.begin (); it != m_interfaces.end (); ++it)
109  {
110  *it = 0;
111  }
112  m_interfaces.clear ();
113 
114  /* remove raw sockets */
115  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
116  {
117  *it = 0;
118  }
119  m_sockets.clear ();
120 
121  /* remove list of prefix */
122  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
123  {
124  (*it)->StopValidTimer ();
125  (*it)->StopPreferredTimer ();
126  (*it) = 0;
127  }
128  m_prefixes.clear ();
129 
130  m_node = 0;
131  m_routingProtocol = 0;
133 }
134 
136 {
137  NS_LOG_FUNCTION (this << routingProtocol);
138  m_routingProtocol = routingProtocol;
139  m_routingProtocol->SetIpv6 (this);
140 }
141 
143 {
145  return m_routingProtocol;
146 }
147 
149 {
150  NS_LOG_FUNCTION (this << device);
151  Ptr<Node> node = GetObject<Node> ();
152  Ptr<Ipv6Interface> interface = CreateObject<Ipv6Interface> ();
153 
155  interface->SetNode (m_node);
156  interface->SetDevice (device);
157  interface->SetForwarding (m_ipForward);
158  return AddIpv6Interface (interface);
159 }
160 
162 {
163  NS_LOG_FUNCTION (this << interface);
164  uint32_t index = m_nInterfaces;
165 
166  m_interfaces.push_back (interface);
167  m_nInterfaces++;
168  return index;
169 }
170 
172 {
173  NS_LOG_FUNCTION (this << index);
174  uint32_t tmp = 0;
175 
176  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
177  {
178  if (index == tmp)
179  {
180  return *it;
181  }
182  tmp++;
183  }
184  return 0;
185 }
186 
188 {
190  return m_nInterfaces;
191 }
192 
194 {
195  NS_LOG_FUNCTION (this << address);
196  int32_t index = 0;
197 
198  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
199  {
200  uint32_t j = 0;
201  uint32_t max = (*it)->GetNAddresses ();
202 
203  for (j = 0; j < max; j++)
204  {
205  if ((*it)->GetAddress (j).GetAddress () == address)
206  {
207  return index;
208  }
209  }
210  index++;
211  }
212  return -1;
213 }
214 
216 {
217  NS_LOG_FUNCTION (this << address << mask);
218  int32_t index = 0;
219 
220  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
221  {
222  uint32_t j = 0;
223  for (j = 0; j < (*it)->GetNAddresses (); j++)
224  {
225  if ((*it)->GetAddress (j).GetAddress ().CombinePrefix (mask) == address.CombinePrefix (mask))
226  {
227  return index;
228  }
229  }
230  index++;
231  }
232  return -1;
233 }
234 
236 {
237  NS_LOG_FUNCTION (this << i);
238  return GetInterface (i)->GetDevice ();
239 }
240 
242 {
243  NS_LOG_FUNCTION (this << device);
244  int32_t index = 0;
245 
246  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
247  {
248  if ((*it)->GetDevice () == device)
249  {
250  return index;
251  }
252  index++;
253  }
254  return -1;
255 }
256 
257 void Ipv6L3Protocol::AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter)
258 {
259  NS_LOG_FUNCTION (this << interface << network << mask << (uint32_t)flags << validTime << preferredTime);
260  Ipv6InterfaceAddress address;
261 
262  Address addr = GetInterface (interface)->GetDevice ()->GetAddress ();
263 
264  if (flags & (1 << 6)) /* auto flag */
265  {
266  /* XXX : add other L2 address case */
267  if (Mac48Address::IsMatchingType (addr))
268  {
270  }
271  else
272  {
273  NS_FATAL_ERROR ("Unknown method to make autoconfigured address for this kind of device.");
274  return;
275  }
276 
277  /* see if we have already the prefix */
278  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
279  {
280  if ((*it)->GetInterface () == interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
281  {
282  (*it)->StopPreferredTimer ();
283  (*it)->StopValidTimer ();
284  (*it)->StartPreferredTimer ();
285  return;
286  }
287  }
288 
289  /* no prefix found, add autoconfigured address and the prefix */
290  NS_LOG_INFO ("Autoconfigured address is :" << address.GetAddress ());
291  AddAddress (interface, address);
292 
293  /* add default router
294  * if a previous default route exists, the new ones is simply added
295  */
296  GetRoutingProtocol ()->NotifyAddRoute (Ipv6Address::GetAny (), Ipv6Prefix ((uint8_t)0), defaultRouter, interface, network);
297 
298  Ptr<Ipv6AutoconfiguredPrefix> aPrefix = CreateObject<Ipv6AutoconfiguredPrefix> (m_node, interface, network, mask, preferredTime, validTime, defaultRouter);
299  aPrefix->StartPreferredTimer ();
300 
301  m_prefixes.push_back (aPrefix);
302  }
303 }
304 
305 void Ipv6L3Protocol::RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter)
306 {
307  NS_LOG_FUNCTION (this << interface << network << mask);
308  Ptr<Ipv6Interface> iface = GetInterface (interface);
309  Address addr = iface->GetDevice ()->GetAddress ();
310  uint32_t max = iface->GetNAddresses ();
311  uint32_t i = 0;
313 
314  for (i = 0; i < max; i++)
315  {
316  if (iface->GetAddress (i).GetAddress () == toFound)
317  {
318  RemoveAddress (interface, i);
319  break;
320  }
321  }
322 
323  /* remove from list of autoconfigured address */
324  for (Ipv6AutoconfiguredPrefixListI it = m_prefixes.begin (); it != m_prefixes.end (); ++it)
325  {
326  if ((*it)->GetInterface () == interface && (*it)->GetPrefix () == network && (*it)->GetMask () == mask)
327  {
328  *it = 0;
329  m_prefixes.erase (it);
330  break;
331  }
332  }
333 
334  GetRoutingProtocol ()->NotifyRemoveRoute (Ipv6Address::GetAny (), Ipv6Prefix ((uint8_t)0), defaultRouter, interface, network);
335 }
336 
338 {
339  NS_LOG_FUNCTION (this << i << address);
340  Ptr<Ipv6Interface> interface = GetInterface (i);
341  bool ret = interface->AddAddress (address);
342 
343  if (m_routingProtocol != 0)
344  {
345  m_routingProtocol->NotifyAddAddress (i, address);
346  }
347  return ret;
348 }
349 
350 uint32_t Ipv6L3Protocol::GetNAddresses (uint32_t i) const
351 {
352  NS_LOG_FUNCTION (this << i);
353  Ptr<Ipv6Interface> interface = GetInterface (i);
354  return interface->GetNAddresses ();
355 }
356 
357 Ipv6InterfaceAddress Ipv6L3Protocol::GetAddress (uint32_t i, uint32_t addressIndex) const
358 {
359  NS_LOG_FUNCTION (this << i << addressIndex);
360  Ptr<Ipv6Interface> interface = GetInterface (i);
361  return interface->GetAddress (addressIndex);
362 }
363 
364 bool Ipv6L3Protocol::RemoveAddress (uint32_t i, uint32_t addressIndex)
365 {
366  NS_LOG_FUNCTION (this << i << addressIndex);
367  Ptr<Ipv6Interface> interface = GetInterface (i);
368  Ipv6InterfaceAddress address = interface->RemoveAddress (addressIndex);
369 
370  if (address != Ipv6InterfaceAddress ())
371  {
372  if (m_routingProtocol != 0)
373  {
374  m_routingProtocol->NotifyRemoveAddress (i, address);
375  }
376  return true;
377  }
378  return false;
379 }
380 
381 void Ipv6L3Protocol::SetMetric (uint32_t i, uint16_t metric)
382 {
383  NS_LOG_FUNCTION (this << i << metric);
384  Ptr<Ipv6Interface> interface = GetInterface (i);
385  interface->SetMetric (metric);
386 }
387 
388 uint16_t Ipv6L3Protocol::GetMetric (uint32_t i) const
389 {
390  NS_LOG_FUNCTION (this << i);
391  Ptr<Ipv6Interface> interface = GetInterface (i);
392  return interface->GetMetric ();
393 }
394 
395 uint16_t Ipv6L3Protocol::GetMtu (uint32_t i) const
396 {
397  NS_LOG_FUNCTION (this << i);
398  Ptr<Ipv6Interface> interface = GetInterface (i);
399  return interface->GetDevice ()->GetMtu ();
400 }
401 
402 bool Ipv6L3Protocol::IsUp (uint32_t i) const
403 {
404  NS_LOG_FUNCTION (this << i);
405  Ptr<Ipv6Interface> interface = GetInterface (i);
406  return interface->IsUp ();
407 }
408 
409 void Ipv6L3Protocol::SetUp (uint32_t i)
410 {
411  NS_LOG_FUNCTION (this << i);
412  Ptr<Ipv6Interface> interface = GetInterface (i);
413 
414  interface->SetUp ();
415 
416  if (m_routingProtocol != 0)
417  {
418  m_routingProtocol->NotifyInterfaceUp (i);
419  }
420 }
421 
422 void Ipv6L3Protocol::SetDown (uint32_t i)
423 {
424  NS_LOG_FUNCTION (this << i);
425  Ptr<Ipv6Interface> interface = GetInterface (i);
426 
427  interface->SetDown ();
428 
429  if (m_routingProtocol != 0)
430  {
431  m_routingProtocol->NotifyInterfaceDown (i);
432  }
433 }
434 
436 {
438  Ptr<Ipv6Interface> interface = CreateObject<Ipv6Interface> ();
439  Ptr<LoopbackNetDevice> device = 0;
440  uint32_t i = 0;
441 
442  /* see if we have already an loopback NetDevice */
443  for (i = 0; i < m_node->GetNDevices (); i++)
444  {
445  if ((device = DynamicCast<LoopbackNetDevice> (m_node->GetDevice (i))))
446  {
447  break;
448  }
449  }
450 
451  if (device == 0)
452  {
453  device = CreateObject<LoopbackNetDevice> ();
454  m_node->AddDevice (device);
455  }
456 
457  interface->SetDevice (device);
458  interface->SetNode (m_node);
460  interface->AddAddress (ifaceAddr);
461  uint32_t index = AddIpv6Interface (interface);
462  Ptr<Node> node = GetObject<Node> ();
464  interface->SetUp ();
465 
466  if (m_routingProtocol != 0)
467  {
468  m_routingProtocol->NotifyInterfaceUp (index);
469  }
470 }
471 
472 bool Ipv6L3Protocol::IsForwarding (uint32_t i) const
473 {
474  NS_LOG_FUNCTION (this << i);
475  Ptr<Ipv6Interface> interface = GetInterface (i);
476 
477  NS_LOG_LOGIC ("Forwarding state: " << interface->IsForwarding ());
478  return interface->IsForwarding ();
479 }
480 
481 void Ipv6L3Protocol::SetForwarding (uint32_t i, bool val)
482 {
483  NS_LOG_FUNCTION (this << i << val);
484  Ptr<Ipv6Interface> interface = GetInterface (i);
485  interface->SetForwarding (val);
486 }
487 
488 void Ipv6L3Protocol::SetIpForward (bool forward)
489 {
490  NS_LOG_FUNCTION (this << forward);
491  m_ipForward = forward;
492 
493  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
494  {
495  (*it)->SetForwarding (forward);
496  }
497 }
498 
500 {
502  return m_ipForward;
503 }
504 
505 void Ipv6L3Protocol::SetSendIcmpv6Redirect (bool sendIcmpv6Redirect)
506 {
507  NS_LOG_FUNCTION (this << sendIcmpv6Redirect);
508  m_sendIcmpv6Redirect = sendIcmpv6Redirect;
509 }
510 
512 {
514  return m_sendIcmpv6Redirect;
515 }
516 
518 {
520 
521  if (m_node == 0)
522  {
523  Ptr<Node> node = this->GetObject<Node> ();
524  // verify that it's a valid node and that
525  // the node has not been set before
526  if (node != 0)
527  {
528  this->SetNode (node);
529  }
530  }
532 }
533 
535 {
536  NS_LOG_FUNCTION (this << node);
537  m_node = node;
538  /* add LoopbackNetDevice if needed, and an Ipv6Interface on top of it */
539  SetupLoopback ();
540 }
541 
543 {
544  NS_LOG_FUNCTION (this << protocol);
545  m_protocols.push_back (protocol);
546 }
547 
549 {
550  NS_LOG_FUNCTION (this << protocol);
551  m_protocols.remove (protocol);
552 }
553 
555 {
556  NS_LOG_FUNCTION (this << protocolNumber);
557 
558  for (L4List_t::const_iterator i = m_protocols.begin (); i != m_protocols.end (); ++i)
559  {
560  if ((*i)->GetProtocolNumber () == protocolNumber)
561  {
562  return *i;
563  }
564  }
565  return 0;
566 }
567 
569 {
571  Ptr<Ipv6RawSocketImpl> sock = CreateObject<Ipv6RawSocketImpl> ();
572  sock->SetNode (m_node);
573  m_sockets.push_back (sock);
574  return sock;
575 }
576 
578 {
579  NS_LOG_FUNCTION (this << socket);
580 
581  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
582  {
583  if ((*it) == socket)
584  {
585  m_sockets.erase (it);
586  return;
587  }
588  }
589 }
590 
592 {
595 
596  if (protocol)
597  {
598  return protocol->GetObject<Icmpv6L4Protocol> ();
599  }
600  else
601  {
602  return 0;
603  }
604 }
605 
607 {
608  NS_LOG_FUNCTION (this << ttl);
609  m_defaultTtl = ttl;
610 }
611 
612 void Ipv6L3Protocol::SetDefaultTclass (uint8_t tclass)
613 {
614  NS_LOG_FUNCTION (this << tclass);
615  m_defaultTclass = tclass;
616 }
617 
618 void Ipv6L3Protocol::Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route)
619 {
620  NS_LOG_FUNCTION (this << packet << source << destination << (uint32_t)protocol << route);
621  Ipv6Header hdr;
622  uint8_t ttl = m_defaultTtl;
624  bool found = packet->RemovePacketTag (tag);
625 
626  if (found)
627  {
628  ttl = tag.GetHopLimit ();
629  }
630 
631  SocketIpv6TclassTag tclassTag;
632  uint8_t tclass = m_defaultTclass;
633  found = packet->RemovePacketTag (tclassTag);
634 
635  if (found)
636  {
637  tclass = tclassTag.GetTclass ();
638  }
639 
640  /* Handle 3 cases:
641  * 1) Packet is passed in with a route entry
642  * 2) Packet is passed in with a route entry but route->GetGateway is not set (e.g., same network)
643  * 3) route is NULL (e.g., a raw socket call or ICMPv6)
644  */
645 
646  /* 1) */
647  if (route && route->GetGateway () != Ipv6Address::GetZero ())
648  {
649  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 1: passed in with a route");
650  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
651  SendRealOut (route, packet, hdr);
652  return;
653  }
654 
655  /* 2) */
656  if (route && route->GetGateway () == Ipv6Address::GetZero ())
657  {
658  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 1: probably sent to machine on same IPv6 network");
659  /* NS_FATAL_ERROR ("This case is not yet implemented"); */
660  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
661  SendRealOut (route, packet, hdr);
662  return;
663  }
664 
665  /* 3) */
666  NS_LOG_LOGIC ("Ipv6L3Protocol::Send case 3: passed in with no route " << destination);
667  Socket::SocketErrno err;
668  Ptr<NetDevice> oif (0);
669  Ptr<Ipv6Route> newRoute = 0;
670 
671  hdr = BuildHeader (source, destination, protocol, packet->GetSize (), ttl, tclass);
672 
673  //for link-local traffic, we need to determine the interface
674  if (source.IsLinkLocal ()
675  || destination.IsLinkLocal ()
676  || destination.IsAllNodesMulticast ()
677  || destination.IsAllRoutersMulticast ()
678  || destination.IsAllHostsMulticast ()
679  || destination.IsSolicitedMulticast ())
680  {
681  int32_t index = GetInterfaceForAddress (source);
682  NS_ASSERT (index >= 0);
683  oif = GetNetDevice (index);
684  }
685 
686  newRoute = m_routingProtocol->RouteOutput (packet, hdr, oif, err);
687 
688  if (newRoute)
689  {
690  SendRealOut (newRoute, packet, hdr);
691  }
692  else
693  {
694  NS_LOG_WARN ("No route to host, drop!");
696  }
697 }
698 
699 void Ipv6L3Protocol::Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
700 {
701  NS_LOG_FUNCTION (this << device << p << protocol << from << to << packetType);
702  NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
703  uint32_t interface = 0;
704  Ptr<Packet> packet = p->Copy ();
705  Ptr<Ipv6Interface> ipv6Interface = 0;
706 
707  for (Ipv6InterfaceList::const_iterator it = m_interfaces.begin (); it != m_interfaces.end (); it++)
708  {
709  ipv6Interface = *it;
710 
711  if (ipv6Interface->GetDevice () == device)
712  {
713  if (ipv6Interface->IsUp ())
714  {
715  m_rxTrace (packet, m_node->GetObject<Ipv6> (), interface);
716  break;
717  }
718  else
719  {
720  NS_LOG_LOGIC ("Dropping received packet-- interface is down");
721  Ipv6Header hdr;
722  packet->RemoveHeader (hdr);
723  m_dropTrace (hdr, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
724  return;
725  }
726  }
727  interface++;
728  }
729 
730  Ipv6Header hdr;
731  packet->RemoveHeader (hdr);
732 
733  // Trim any residual frame padding from underlying devices
734  if (hdr.GetPayloadLength () < packet->GetSize ())
735  {
736  packet->RemoveAtEnd (packet->GetSize () - hdr.GetPayloadLength ());
737  }
738 
739  /* forward up to IPv6 raw sockets */
740  for (SocketList::iterator it = m_sockets.begin (); it != m_sockets.end (); ++it)
741  {
742  Ptr<Ipv6RawSocketImpl> socket = *it;
743  socket->ForwardUp (packet, hdr, device);
744  }
745 
747  Ptr<Ipv6Extension> ipv6Extension = 0;
748  uint8_t nextHeader = hdr.GetNextHeader ();
749  bool isDropped = false;
750 
751  if (nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
752  {
753  ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
754 
755  if (ipv6Extension)
756  {
757  ipv6Extension->Process (packet, 0, hdr, hdr.GetDestinationAddress (), (uint8_t *)0, isDropped);
758  }
759 
760  if (isDropped)
761  {
762  return;
763  }
764  }
765 
766  if (!m_routingProtocol->RouteInput (packet, hdr, device,
771  {
772  NS_LOG_WARN ("No route found for forwarding packet. Drop.");
773  m_dropTrace (hdr, packet, DROP_NO_ROUTE, m_node->GetObject<Ipv6> (), interface);
774  }
775 }
776 
778 {
779  NS_LOG_FUNCTION (this << route << packet << ipHeader);
780 
781  if (!route)
782  {
783  NS_LOG_LOGIC ("No route to host, drop!.");
784  return;
785  }
786 
787  Ptr<NetDevice> dev = route->GetOutputDevice ();
788  int32_t interface = GetInterfaceForDevice (dev);
789  NS_ASSERT (interface >= 0);
790 
791  Ptr<Ipv6Interface> outInterface = GetInterface (interface);
792  NS_LOG_LOGIC ("Send via NetDevice ifIndex " << dev->GetIfIndex () << " Ipv6InterfaceIndex " << interface);
793 
794  // Check packet size
795  std::list<Ptr<Packet> > fragments;
796 
797  if (packet->GetSize () > (size_t)(dev->GetMtu () + 40)) /* 40 => size of IPv6 header */
798  {
799  // Router => drop
800  if (m_ipForward)
801  {
802  Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
803  if ( icmpv6 )
804  {
805  packet->AddHeader(ipHeader);
806  icmpv6->SendErrorTooBig (packet, ipHeader.GetSourceAddress (), dev->GetMtu ());
807  }
808  return;
809  }
810 
812 
813  packet->AddHeader (ipHeader);
814 
815  // To get specific method GetFragments from Ipv6ExtensionFragmentation
816  Ipv6ExtensionFragment *ipv6Fragment = dynamic_cast<Ipv6ExtensionFragment *> (PeekPointer (ipv6ExtensionDemux->GetExtension (Ipv6Header::IPV6_EXT_FRAGMENTATION)));
817  ipv6Fragment->GetFragments (packet, outInterface->GetDevice ()->GetMtu (), fragments);
818  }
819 
820  if (!route->GetGateway ().IsEqual (Ipv6Address::GetAny ()))
821  {
822  if (outInterface->IsUp ())
823  {
824  NS_LOG_LOGIC ("Send to gateway " << route->GetGateway ());
825 
826  if (fragments.size () != 0)
827  {
828  std::ostringstream oss;
829 
830  /* IPv6 header is already added in fragments */
831  for (std::list<Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
832  {
833  m_txTrace (*it, m_node->GetObject<Ipv6> (), interface);
834  outInterface->Send (*it, route->GetGateway ());
835  }
836  }
837  else
838  {
839  packet->AddHeader (ipHeader);
840  m_txTrace (packet, m_node->GetObject<Ipv6> (), interface);
841  outInterface->Send (packet, route->GetGateway ());
842  }
843  }
844  else
845  {
846  NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << route->GetGateway ());
847  m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
848  }
849  }
850  else
851  {
852  if (outInterface->IsUp ())
853  {
854  NS_LOG_LOGIC ("Send to destination " << ipHeader.GetDestinationAddress ());
855 
856  if (fragments.size () != 0)
857  {
858  std::ostringstream oss;
859 
860  /* IPv6 header is already added in fragments */
861  for (std::list<Ptr<Packet> >::const_iterator it = fragments.begin (); it != fragments.end (); it++)
862  {
863  m_txTrace (*it, m_node->GetObject<Ipv6> (), interface);
864  outInterface->Send (*it, ipHeader.GetDestinationAddress ());
865  }
866  }
867  else
868  {
869  packet->AddHeader (ipHeader);
870  m_txTrace (packet, m_node->GetObject<Ipv6> (), interface);
871  outInterface->Send (packet, ipHeader.GetDestinationAddress ());
872  }
873  }
874  else
875  {
876  NS_LOG_LOGIC ("Dropping-- outgoing interface is down: " << ipHeader.GetDestinationAddress ());
877  m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv6> (), interface);
878  }
879  }
880 }
881 
883 {
884  NS_LOG_FUNCTION (this << rtentry << p << header);
885  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
886 
887  // Forwarding
888  Ipv6Header ipHeader = header;
889  Ptr<Packet> packet = p->Copy ();
890  ipHeader.SetHopLimit (ipHeader.GetHopLimit () - 1);
891 
892  if (ipHeader.GetSourceAddress ().IsLinkLocal ())
893  {
894  /* no forward for link-local address */
895  return;
896  }
897 
898  if (ipHeader.GetHopLimit () == 0)
899  {
900  NS_LOG_WARN ("TTL exceeded. Drop.");
901  m_dropTrace (ipHeader, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv6> (), 0);
902  // Do not reply to ICMPv6 or to multicast IPv6 address
903  if (ipHeader.GetNextHeader () != Icmpv6L4Protocol::PROT_NUMBER
904  && ipHeader.GetDestinationAddress ().IsMulticast () == false)
905  {
906  packet->AddHeader (ipHeader);
907  GetIcmpv6 ()->SendErrorTimeExceeded (packet, ipHeader.GetSourceAddress (), Icmpv6Header::ICMPV6_HOPLIMIT);
908  }
909  return;
910  }
911 
912  /* ICMPv6 Redirect */
913 
914  /* if we forward to a machine on the same network as the source,
915  * we send him an ICMPv6 redirect message to notify him that a short route
916  * exists.
917  */
918 
919  if (m_sendIcmpv6Redirect &&
920  ((!rtentry->GetGateway ().IsAny () && rtentry->GetGateway ().CombinePrefix (Ipv6Prefix (64)) == header.GetSourceAddress ().CombinePrefix (Ipv6Prefix (64)))
921  || (rtentry->GetDestination ().CombinePrefix (Ipv6Prefix (64)) == header.GetSourceAddress ().CombinePrefix (Ipv6Prefix (64)))))
922  {
923  NS_LOG_LOGIC ("ICMPv6 redirect!");
924  Ptr<Icmpv6L4Protocol> icmpv6 = GetIcmpv6 ();
925  Address hardwareTarget;
926  Ipv6Address dst = header.GetDestinationAddress ();
927  Ipv6Address src = header.GetSourceAddress ();
928  Ipv6Address target = rtentry->GetGateway ();
929  Ptr<Packet> copy = p->Copy ();
930 
931  if (target.IsAny ())
932  {
933  target = dst;
934  }
935 
936  copy->AddHeader (header);
937 
938  if (icmpv6->Lookup (target, rtentry->GetOutputDevice (), 0, &hardwareTarget))
939  {
940  icmpv6->SendRedirection (copy, src, target, dst, hardwareTarget);
941  }
942  else
943  {
944  icmpv6->SendRedirection (copy, src, target, dst, Address ());
945  }
946  }
947 
948  SendRealOut (rtentry, packet, ipHeader);
949 }
950 
952 {
953  NS_LOG_FUNCTION (this << mrtentry << p << header);
954  NS_LOG_LOGIC ("Multicast forwarding logic for node: " << m_node->GetId ());
955 
956  std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
957  std::map<uint32_t, uint32_t>::iterator mapIter;
958 
959  for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
960  {
961  uint32_t interfaceId = mapIter->first;
962  //uint32_t outputTtl = mapIter->second; // Unused for now
963  Ptr<Packet> packet = p->Copy ();
964  Ipv6Header h = header;
965  h.SetHopLimit (header.GetHopLimit () - 1);
966  if (h.GetHopLimit () == 0)
967  {
968  NS_LOG_WARN ("TTL exceeded. Drop.");
969  m_dropTrace (header, packet, DROP_TTL_EXPIRED, m_node->GetObject<Ipv6> (), interfaceId);
970  return;
971  }
972  NS_LOG_LOGIC ("Forward multicast via interface " << interfaceId);
973  Ptr<Ipv6Route> rtentry = Create<Ipv6Route> ();
974  rtentry->SetSource (h.GetSourceAddress ());
975  rtentry->SetDestination (h.GetDestinationAddress ());
976  rtentry->SetGateway (Ipv6Address::GetAny ());
977  rtentry->SetOutputDevice (GetNetDevice (interfaceId));
978  SendRealOut (rtentry, packet, h);
979  continue;
980  }
981 }
982 
983 void Ipv6L3Protocol::LocalDeliver (Ptr<const Packet> packet, Ipv6Header const& ip, uint32_t iif)
984 {
985  NS_LOG_FUNCTION (this << packet << ip << iif);
986  Ptr<Packet> p = packet->Copy ();
987  Ptr<IpL4Protocol> protocol = 0;
989  Ptr<Ipv6Extension> ipv6Extension = 0;
990  Ipv6Address src = ip.GetSourceAddress ();
992  uint8_t nextHeader = ip.GetNextHeader ();
993  uint8_t nextHeaderPosition = 0;
994  bool isDropped = false;
995 
996  // check for a malformed hop-by-hop extension
997  // this is a common case when forging IPv6 raw packets
998  if (nextHeader == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
999  {
1000  uint8_t buf;
1001  p->CopyData (&buf, 1);
1002  if (buf == Ipv6Header::IPV6_EXT_HOP_BY_HOP)
1003  {
1004  NS_LOG_WARN("Double Ipv6Header::IPV6_EXT_HOP_BY_HOP in packet, dropping packet");
1005  return;
1006  }
1007  }
1008 
1009  /* process all the extensions found and the layer 4 protocol */
1010  do
1011  {
1012  /* it return 0 for non-extension (i.e. layer 4 protocol) */
1013  ipv6Extension = ipv6ExtensionDemux->GetExtension (nextHeader);
1014 
1015  if (ipv6Extension)
1016  {
1017  uint8_t nextHeaderStep = 0;
1018  uint8_t curHeader = nextHeader;
1019  nextHeaderStep = ipv6Extension->Process (p, nextHeaderPosition, ip, dst, &nextHeader, isDropped);
1020  nextHeaderPosition += nextHeaderStep;
1021 
1022  if (isDropped)
1023  {
1024  return;
1025  }
1026  NS_ASSERT_MSG (nextHeaderStep != 0 || curHeader == Ipv6Header::IPV6_EXT_FRAGMENTATION,
1027  "Zero-size IPv6 Option Header, aborting" << *packet );
1028  }
1029  else
1030  {
1031  protocol = GetProtocol (nextHeader);
1032  // For ICMPv6 Error packets
1033  Ptr<Packet> malformedPacket = packet->Copy ();
1034  malformedPacket->AddHeader (ip);
1035 
1036  if (!protocol)
1037  {
1038  NS_LOG_LOGIC ("Unknown Next Header. Drop!");
1039 
1040  if (nextHeaderPosition == 0)
1041  {
1042  GetIcmpv6 ()->SendErrorParameterError (malformedPacket, dst, Icmpv6Header::ICMPV6_UNKNOWN_NEXT_HEADER, 40);
1043  }
1044  else
1045  {
1046  GetIcmpv6 ()->SendErrorParameterError (malformedPacket, dst, Icmpv6Header::ICMPV6_UNKNOWN_NEXT_HEADER, ip.GetSerializedSize () + nextHeaderPosition);
1047  }
1049  break;
1050  }
1051  else
1052  {
1053  p->RemoveAtStart (nextHeaderPosition);
1054  /* protocol->Receive (p, src, dst, incomingInterface); */
1055 
1056  /* L4 protocol */
1057  Ptr<Packet> copy = p->Copy ();
1058  enum IpL4Protocol::RxStatus status = protocol->Receive (p, ip, GetInterface (iif));
1059 
1060  switch (status)
1061  {
1062  case IpL4Protocol::RX_OK:
1063  break;
1064  case IpL4Protocol::RX_CSUM_FAILED:
1065  break;
1066  case IpL4Protocol::RX_ENDPOINT_CLOSED:
1067  break;
1068  case IpL4Protocol::RX_ENDPOINT_UNREACH:
1069  if (ip.GetDestinationAddress ().IsMulticast ())
1070  {
1071  /* do not rely on multicast address */
1072  break;
1073  }
1074 
1075  copy->AddHeader (ip);
1076  GetIcmpv6 ()->SendErrorDestinationUnreachable (copy, ip.GetSourceAddress (), Icmpv6Header::ICMPV6_PORT_UNREACHABLE);
1077  }
1078  }
1079  }
1080  }
1081  while (ipv6Extension);
1082 }
1083 
1084 void Ipv6L3Protocol::RouteInputError (Ptr<const Packet> p, const Ipv6Header& ipHeader, Socket::SocketErrno sockErrno)
1085 {
1086  NS_LOG_FUNCTION (this << p << ipHeader << sockErrno);
1087  NS_LOG_LOGIC ("Route input failure-- dropping packet to " << ipHeader << " with errno " << sockErrno);
1088  m_dropTrace (ipHeader, p, DROP_ROUTE_ERROR, m_node->GetObject<Ipv6> (), 0);
1089 }
1090 
1091 Ipv6Header Ipv6L3Protocol::BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, uint8_t tclass)
1092 {
1093  NS_LOG_FUNCTION (this << src << dst << (uint32_t)protocol << (uint32_t)payloadSize << (uint32_t)ttl << (uint32_t)tclass);
1094  Ipv6Header hdr;
1095 
1096  hdr.SetSourceAddress (src);
1097  hdr.SetDestinationAddress (dst);
1098  hdr.SetNextHeader (protocol);
1099  hdr.SetPayloadLength (payloadSize);
1100  hdr.SetHopLimit (ttl);
1101  hdr.SetTrafficClass (tclass);
1102  return hdr;
1103 }
1104 
1106 {
1107  Ptr<Ipv6ExtensionDemux> ipv6ExtensionDemux = CreateObject<Ipv6ExtensionDemux> ();
1108  ipv6ExtensionDemux->SetNode (m_node);
1109 
1110  Ptr<Ipv6ExtensionHopByHop> hopbyhopExtension = CreateObject<Ipv6ExtensionHopByHop> ();
1111  hopbyhopExtension->SetNode (m_node);
1112  Ptr<Ipv6ExtensionDestination> destinationExtension = CreateObject<Ipv6ExtensionDestination> ();
1113  destinationExtension->SetNode (m_node);
1114  Ptr<Ipv6ExtensionFragment> fragmentExtension = CreateObject<Ipv6ExtensionFragment> ();
1115  fragmentExtension->SetNode (m_node);
1116  Ptr<Ipv6ExtensionRouting> routingExtension = CreateObject<Ipv6ExtensionRouting> ();
1117  routingExtension->SetNode (m_node);
1118  // Ptr<Ipv6ExtensionESP> espExtension = CreateObject<Ipv6ExtensionESP> ();
1119  // Ptr<Ipv6ExtensionAH> ahExtension = CreateObject<Ipv6ExtensionAH> ();
1120 
1121  ipv6ExtensionDemux->Insert (hopbyhopExtension);
1122  ipv6ExtensionDemux->Insert (destinationExtension);
1123  ipv6ExtensionDemux->Insert (fragmentExtension);
1124  ipv6ExtensionDemux->Insert (routingExtension);
1125  // ipv6ExtensionDemux->Insert (espExtension);
1126  // ipv6ExtensionDemux->Insert (ahExtension);
1127 
1128  Ptr<Ipv6ExtensionRoutingDemux> routingExtensionDemux = CreateObject<Ipv6ExtensionRoutingDemux> ();
1129  routingExtensionDemux->SetNode (m_node);
1130  Ptr<Ipv6ExtensionLooseRouting> looseRoutingExtension = CreateObject<Ipv6ExtensionLooseRouting> ();
1131  looseRoutingExtension->SetNode (m_node);
1132  routingExtensionDemux->Insert (looseRoutingExtension);
1133 
1134  m_node->AggregateObject (routingExtensionDemux);
1135  m_node->AggregateObject (ipv6ExtensionDemux);
1136 }
1137 
1139 {
1140  Ptr<Ipv6OptionDemux> ipv6OptionDemux = CreateObject<Ipv6OptionDemux> ();
1141  ipv6OptionDemux->SetNode (m_node);
1142 
1143  Ptr<Ipv6OptionPad1> pad1Option = CreateObject<Ipv6OptionPad1> ();
1144  pad1Option->SetNode (m_node);
1145  Ptr<Ipv6OptionPadn> padnOption = CreateObject<Ipv6OptionPadn> ();
1146  padnOption->SetNode (m_node);
1147  Ptr<Ipv6OptionJumbogram> jumbogramOption = CreateObject<Ipv6OptionJumbogram> ();
1148  jumbogramOption->SetNode (m_node);
1149  Ptr<Ipv6OptionRouterAlert> routerAlertOption = CreateObject<Ipv6OptionRouterAlert> ();
1150  routerAlertOption->SetNode (m_node);
1151 
1152  ipv6OptionDemux->Insert (pad1Option);
1153  ipv6OptionDemux->Insert (padnOption);
1154  ipv6OptionDemux->Insert (jumbogramOption);
1155  ipv6OptionDemux->Insert (routerAlertOption);
1156 
1157  m_node->AggregateObject (ipv6OptionDemux);
1158 }
1159 
1160 } /* namespace ns3 */
1161 
void SetNode(Ptr< Node > node)
Set the node.
bool IsAny() const
If the IPv6 address is the "Any" address.
void GetFragments(Ptr< Packet > packet, uint32_t fragmentSize, std::list< Ptr< Packet > > &listFragments)
Fragment a packet.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
Definition: ipv6-header.cc:143
static bool IsMatchingType(const Address &address)
uint8_t GetNextHeader(void) const
Get the next header.
Definition: ipv6-header.cc:81
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
Definition: ipv6-header.cc:66
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.
static Ipv6Address MakeAutoconfiguredAddress(Mac48Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac48Address.
void SetForwarding(uint32_t i, bool val)
Enable or disable forwarding on interface.
Packet header for IPv6.
Definition: ipv6-header.h:33
bool AddAddress(Ipv6InterfaceAddress iface)
Add an IPv6 address.
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual ~Ipv6L3Protocol()
Destructor.
void SetUp()
Enable this interface.
Hold a bool native type.
Definition: boolean.h:38
Ipv6L3Protocol()
Constructor.
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer...
Definition: socket.h:891
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.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:79
void IpForward(Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet.
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const
Get current routing protocol used.
uint32_t AddIpv6Interface(Ptr< Ipv6Interface > interface)
Add an IPv6 interface to the stack.
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...
Demultiplexes IPv6 extensions.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
bool IsAllRoutersMulticast() const
If the IPv6 address is "all routers multicast" (ff02::2/8).
void SetNode(Ptr< Node > node)
Set the node.
#define NS_ASSERT(condition)
Definition: assert.h:64
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
Ipv6InterfaceAddress GetAddress(uint32_t index) const
Get an address from IPv6 interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
IPv6 address associated with an interface.
static const uint8_t PROT_NUMBER
ICMPv6 protocol number (58).
uint32_t GetNAddresses(uint32_t interface) const
Get number of address for an interface.
uint32_t GetSize(void) const
Definition: packet.h:620
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Definition: ipv6-header.cc:76
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. This method removes IPv6 header and forward up to L...
virtual void DoDispose(void)
Definition: object.cc:335
#define NS_LOG_INFO(msg)
Definition: log.h:264
bool IsAllHostsMulticast() const
If the IPv6 address is "all hosts multicast" (ff02::3/8).
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
virtual bool GetSendIcmpv6Redirect() const
Get the ICMPv6 Redirect sending state.
bool IsAllNodesMulticast() const
If the IPv6 address is "all nodes multicast" (ff02::1/8).
virtual void DoDispose()
Dispose object.
void SetMetric(uint32_t i, uint16_t metric)
Set metric for an interface.
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.
Ptr< Node > m_node
Node attached to stack.
bool IsUp() const
Is the interface UP ?
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
a polymophic address class
Definition: address.h:86
virtual void SetIpForward(bool forward)
Set IPv6 forwarding state.
virtual void NotifyNewAggregate()
Notify other components connected to the node that a new stack member is now connected.
bool IsUp(uint32_t i) const
Is specified interface up ?
uint32_t m_nInterfaces
Number of IPv6 interfaces managed by the stack.
void SetDefaultTclass(uint8_t tclass)
Set the default TCLASS.
Ipv6Address GetAddress() const
Get the IPv6 address.
uint32_t GetNAddresses(void) const
Get number of addresses on this IPv6 interface.
void SetMetric(uint16_t metric)
Set the metric.
void RemoveAtStart(uint32_t size)
Definition: packet.cc:370
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const
Get interface index which match specified address/prefix.
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
Hold an unsigned integer type.
Definition: uinteger.h:46
L4List_t m_protocols
List of transport protocol.
void IpMulticastForward(Ptr< Ipv6MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet in multicast.
void SetDefaultTtl(uint8_t ttl)
Set the default TTL.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:133
void SetUp(uint32_t i)
Set an interface up.
An implementation of the ICMPv6 protocol.
virtual enum RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)=0
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:502
static TypeId GetTypeId()
Get the type ID of this class.
Ipv6InterfaceList m_interfaces
List of IPv6 interfaces.
void AggregateObject(Ptr< Object > other)
Definition: object.cc:242
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
bool m_ipForward
Forwarding packets (i.e. router mode) state.
uint32_t GetNInterfaces() const
Get current number of interface on this stack.
static Mac48Address ConvertFrom(const Address &address)
uint16_t GetMetric(uint32_t i) const
Get metric for an interface.
virtual void NotifyNewAggregate(void)
Definition: object.cc:314
uint32_t GetNDevices(void) const
Definition: node.cc:141
void SetForwarding(bool forward)
Set forwarding enabled or not.
Ptr< Packet > Copy(void) const
Definition: packet.cc:131
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
Definition: ipv6-header.cc:91
Ipv6AutoconfiguredPrefixList m_prefixes
List of IPv6 prefix received from RA.
void LocalDeliver(Ptr< const Packet > p, Ipv6Header const &ip, uint32_t iif)
Deliver a packet.
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
virtual bool GetIpForward() const
Get IPv6 forwarding state.
static uint16_t GetStaticProtocolNumber()
Get ICMPv6 protocol number.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Get an address.
uint8_t m_defaultTtl
Default TTL for outgoing packets.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, DropReason, Ptr< Ipv6 >, uint32_t > m_dropTrace
Callback to trace drop packets.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Get interface index which is on a specified net device.
uint16_t GetPayloadLength(void) const
Get the "Payload length" field.
Definition: ipv6-header.cc:71
void SetNode(Ptr< Node > node)
Set node for this stack.
bool IsForwarding(uint32_t i) const
Is interface allows forwarding ?
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:218
void SetupLoopback()
Setup loopback interface.
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
void SetSourceAddress(Ipv6Address src)
Set the "Source address" field.
Definition: ipv6-header.cc:96
IPv6 Extension Fragment.
virtual void RegisterExtensions()
Register the IPv6 Extensions.
Describes an IPv6 address.
Definition: ipv6-address.h:44
uint16_t GetMetric() const
Get the metric.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
bool IsSolicitedMulticast() const
If the IPv6 address is a Solicited multicast address.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Definition: ipv6-header.cc:86
uint32_t AddDevice(Ptr< NetDevice > device)
Definition: node.cc:119
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Get L4 protocol by protocol number.
uint32_t GetId(void) const
Definition: node.cc:105
Ptr< Icmpv6L4Protocol > GetIcmpv6() const
Get ICMPv6 protocol.
#define NS_LOG_WARN(msg)
Definition: log.h:246
bool RemovePacketTag(Tag &tag)
Definition: packet.cc:874
void Insert(Ptr< IpL4Protocol > protocol)
Add an L4 protocol.
Ipv6Address GetSourceAddress(void) const
Get the "Source address" field.
Definition: ipv6-header.cc:101
uint16_t GetMtu(uint32_t i) const
Get MTU for an interface.
bool m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix. It is just a bitmask like Ipv4Mask.
Definition: ipv6-address.h:326
void SetDown(uint32_t i)
set an interface down.
void SetTrafficClass(uint8_t traffic)
Set the "Traffic class" field.
Definition: ipv6-header.cc:46
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Definition: packet.cc:398
int32_t GetInterfaceForAddress(Ipv6Address addr) const
Get interface index which has specified IPv6 address.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove an address from an interface.
contain a set of ns3::Object pointers.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
Ipv6Address CombinePrefix(Ipv6Prefix const &prefix)
Combine this address with a prefix.
uint8_t m_defaultTclass
Default TCLASS for outgoing packets.
Ptr< T > GetObject(void) const
Definition: object.h:332
void SetDown()
Disable this interface.
a unique identifier for an interface.
Definition: type-id.h:44
void StartPreferredTimer()
Start the preferred timer.
void SetDestinationAddress(Ipv6Address dst)
Set the "Destination address" field.
Definition: ipv6-header.cc:106
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
SocketList m_sockets
List of IPv6 raw sockets.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Ptr< Ipv6Interface > GetInterface(uint32_t i) const
Get an interface.
void AddHeader(const Header &header)
Definition: packet.cc:270
Ipv6Address GetDestinationAddress(void) const
Get the "Destination address" field.
Definition: ipv6-header.cc:111
void Remove(Ptr< IpL4Protocol > protocol)
Remove an 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.
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.