A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
icmpv6-l4-protocol.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
7 * David Gross <gdavid.devel@gmail.com>
8 * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
9 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
10 */
11
12#include "icmpv6-l4-protocol.h"
13
14#include "ipv4-interface.h"
15#include "ipv6-interface.h"
16#include "ipv6-l3-protocol.h"
17#include "ipv6-route.h"
19
20#include "ns3/assert.h"
21#include "ns3/boolean.h"
22#include "ns3/double.h"
23#include "ns3/integer.h"
24#include "ns3/log.h"
25#include "ns3/node.h"
26#include "ns3/packet.h"
27#include "ns3/pointer.h"
28#include "ns3/string.h"
29#include "ns3/uinteger.h"
30
31namespace ns3
32{
33
34NS_LOG_COMPONENT_DEFINE("Icmpv6L4Protocol");
35
37
38// const uint8_t Icmpv6L4Protocol::MAX_INITIAL_RTR_ADVERT_INTERVAL = 16; // max initial RA initial
39// interval. const uint8_t Icmpv6L4Protocol::MAX_INITIAL_RTR_ADVERTISEMENTS = 3; // max initial RA
40// transmission. const uint8_t Icmpv6L4Protocol::MAX_FINAL_RTR_ADVERTISEMENTS = 3; // max final
41// RA transmission. const uint8_t Icmpv6L4Protocol::MIN_DELAY_BETWEEN_RAS = 3; // min
42// delay between RA. const uint32_t Icmpv6L4Protocol::MAX_RA_DELAY_TIME = 500; //
43// millisecond - max delay between RA.
44
45// const uint8_t Icmpv6L4Protocol::MAX_RTR_SOLICITATION_DELAY = 1; // max RS delay.
46// const uint8_t Icmpv6L4Protocol::RTR_SOLICITATION_INTERVAL = 4; // RS interval.
47// const uint8_t Icmpv6L4Protocol::MAX_RTR_SOLICITATIONS = 3; // max RS transmission.
48
49// const uint8_t Icmpv6L4Protocol::MAX_ANYCAST_DELAY_TIME = 1; // max anycast delay.
50// const uint8_t Icmpv6L4Protocol::MAX_NEIGHBOR_ADVERTISEMENT = 3; // max NA transmission.
51
52// const double Icmpv6L4Protocol::MIN_RANDOM_FACTOR = 0.5; // min random factor.
53// const double Icmpv6L4Protocol::MAX_RANDOM_FACTOR = 1.5; // max random factor.
54
57{
58 static TypeId tid =
59 TypeId("ns3::Icmpv6L4Protocol")
61 .SetGroupName("Internet")
62 .AddConstructor<Icmpv6L4Protocol>()
63 .AddAttribute("DAD",
64 "Always do DAD check.",
65 BooleanValue(true),
68 .AddAttribute(
69 "SolicitationJitter",
70 "The jitter in ms a node is allowed to wait before sending any solicitation. Some "
71 "jitter aims to prevent collisions. By default, the model will wait for a duration "
72 "in ms defined by a uniform random-variable between 0 and SolicitationJitter",
73 StringValue("ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
76 .AddAttribute("MaxMulticastSolicit",
77 "Neighbor Discovery node constants: max multicast solicitations.",
78 IntegerValue(3),
81 .AddAttribute("MaxUnicastSolicit",
82 "Neighbor Discovery node constants: max unicast solicitations.",
83 IntegerValue(3),
86 .AddAttribute("ReachableTime",
87 "Neighbor Discovery node constants: reachable time.",
88 TimeValue(Seconds(30)),
91 .AddAttribute("RetransmissionTime",
92 "Neighbor Discovery node constants: retransmission timer.",
96 .AddAttribute("DelayFirstProbe",
97 "Neighbor Discovery node constants: delay for the first probe.",
101 .AddAttribute("DadTimeout",
102 "Duplicate Address Detection (DAD) timeout",
103 TimeValue(Seconds(1)),
106 .AddAttribute("RsRetransmissionJitter",
107 "Multicast RS retransmission randomization quantity",
108 StringValue("ns3::UniformRandomVariable[Min=-0.1|Max=0.1]"),
111 .AddAttribute("RsInitialRetransmissionTime",
112 "Multicast RS initial retransmission time.",
113 TimeValue(Seconds(4)),
116 .AddAttribute("RsMaxRetransmissionTime",
117 "Multicast RS maximum retransmission time (0 means unbound).",
118 TimeValue(Seconds(3600)),
121 .AddAttribute(
122 "RsMaxRetransmissionCount",
123 "Multicast RS maximum retransmission count (0 means unbound). "
124 "Note: RFC 7559 suggest a zero value (infinite). The default is 4 to avoid "
125 "non-terminating simulations.",
126 UintegerValue(4),
129 .AddAttribute("RsMaxRetransmissionDuration",
130 "Multicast RS maximum retransmission duration (0 means unbound).",
131 TimeValue(Seconds(0)),
134 .AddTraceSource("DadFailure",
135 "Duplicate Address detected during DAD, the address is now INVALID",
137 "ns3::Ipv6Address::TracedCallback")
138 .AddTraceSource(
139 "DadSuccess",
140 "Duplicate Address not detected during DAD, the address is now PREFERRED",
142 "ns3::Ipv6Address::TracedCallback");
143 return tid;
144}
145
147 : m_node(nullptr)
148{
149 NS_LOG_FUNCTION(this);
150}
151
156
157void
159{
160 NS_LOG_FUNCTION(this);
161 for (auto it = m_cacheList.begin(); it != m_cacheList.end(); it++)
162 {
163 Ptr<NdiscCache> cache = *it;
164 cache->Dispose();
165 cache = nullptr;
166 }
167 m_cacheList.clear();
168 m_downTarget.Nullify();
169 m_startDhcpv6.Nullify();
170
171 m_node = nullptr;
173}
174
175int64_t
177{
178 NS_LOG_FUNCTION(this << stream);
179 m_solicitationJitter->SetStream(stream);
180 m_rsRetransmissionJitter->SetStream(stream + 1);
181 return 2;
182}
183
184void
186{
187 NS_LOG_FUNCTION(this);
188 if (!m_node)
189 {
190 Ptr<Node> node = this->GetObject<Node>();
191 if (node)
192 {
193 Ptr<Ipv6> ipv6 = this->GetObject<Ipv6>();
194 if (ipv6 && m_downTarget.IsNull())
195 {
196 SetNode(node);
197 ipv6->Insert(this);
199 }
200 }
201 }
203}
204
205void
207{
208 NS_LOG_FUNCTION(this << node);
209 m_node = node;
210}
211
214{
215 NS_LOG_FUNCTION(this);
216 return m_node;
217}
218
219uint16_t
225
226int
228{
229 NS_LOG_FUNCTION(this);
230 return PROT_NUMBER;
231}
232
233int
235{
236 NS_LOG_FUNCTION(this);
237 return 1;
238}
239
240bool
242{
243 NS_LOG_FUNCTION(this);
244 return m_alwaysDad;
245}
246
247void
249{
250 NS_LOG_FUNCTION(this << target << interface);
251 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
252
253 NS_ASSERT(ipv6);
254
255 if (!m_alwaysDad)
256 {
257 return;
258 }
259
260 /** @todo disable multicast loopback to prevent NS probing to be received by the sender */
261
264 target,
265 interface->GetDevice()->GetAddress());
266
267 /* update last packet UID */
268 interface->SetNsDadUid(target, p.first->GetUid());
271 interface,
272 p.first,
273 p.second,
275}
276
279 const Ipv4Header& header,
280 Ptr<Ipv4Interface> interface)
281{
282 NS_LOG_FUNCTION(this << packet << header);
284}
285
288 const Ipv6Header& header,
289 Ptr<Ipv6Interface> interface)
290{
291 NS_LOG_FUNCTION(this << packet << header.GetSource() << header.GetDestination() << interface);
292 Ptr<Packet> p = packet->Copy();
293 Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6>();
294
295 /* very ugly! try to find something better in the future */
296 uint8_t type;
297 p->CopyData(&type, sizeof(type));
298
299 switch (type)
300 {
302 if (ipv6->IsForwarding(ipv6->GetInterfaceForDevice(interface->GetDevice())))
303 {
304 HandleRS(p, header.GetSource(), header.GetDestination(), interface);
305 }
306 break;
308 if (!ipv6->IsForwarding(ipv6->GetInterfaceForDevice(interface->GetDevice())))
309 {
310 HandleRA(p, header.GetSource(), header.GetDestination(), interface);
311 }
312 break;
314 HandleNS(p, header.GetSource(), header.GetDestination(), interface);
315 break;
317 HandleNA(p, header.GetSource(), header.GetDestination(), interface);
318 break;
320 HandleRedirection(p, header.GetSource(), header.GetDestination(), interface);
321 break;
323 HandleEchoRequest(p, header.GetSource(), header.GetDestination(), interface);
324 break;
326 // EchoReply does not contain any info about L4
327 // so we can not forward it up.
328 /// @todo implement request / reply consistency check.
329 break;
331 HandleDestinationUnreachable(p, header.GetSource(), header.GetDestination(), interface);
332 break;
334 HandlePacketTooBig(p, header.GetSource(), header.GetDestination(), interface);
335 break;
337 HandleTimeExceeded(p, header.GetSource(), header.GetDestination(), interface);
338 break;
340 HandleParameterError(p, header.GetSource(), header.GetDestination(), interface);
341 break;
342 default:
343 NS_LOG_LOGIC("Unknown ICMPv6 message type=" << type);
344 break;
345 }
346
347 return IpL4Protocol::RX_OK;
348}
349
350void
352 Icmpv6Header icmp,
353 uint32_t info,
354 Ipv6Header ipHeader,
355 const uint8_t payload[8])
356{
357 NS_LOG_FUNCTION(this << source << icmp << info << ipHeader << payload);
358
359 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
360
361 /// @todo assuming the ICMP is carrying a extensionless IP packet
362
363 uint8_t nextHeader = ipHeader.GetNextHeader();
364
365 if (nextHeader != Icmpv6L4Protocol::PROT_NUMBER)
366 {
367 Ptr<IpL4Protocol> l4 = ipv6->GetProtocol(nextHeader);
368 if (l4)
369 {
370 l4->ReceiveIcmp(source,
371 ipHeader.GetHopLimit(),
372 icmp.GetType(),
373 icmp.GetCode(),
374 info,
375 ipHeader.GetSource(),
376 ipHeader.GetDestination(),
377 payload);
378 }
379 }
380}
381
382void
384 const Ipv6Address& src,
385 const Ipv6Address& dst,
386 Ptr<Ipv6Interface> interface)
387{
388 NS_LOG_FUNCTION(this << packet << src << dst << interface);
389 Icmpv6Echo request;
390 auto buf = new uint8_t[packet->GetSize()];
391
392 packet->RemoveHeader(request);
393 /* XXX IPv6 extension: obtain a fresh copy of data otherwise it crash... */
394 packet->CopyData(buf, packet->GetSize());
395 Ptr<Packet> p = Create<Packet>(buf, packet->GetSize());
396
397 /* if we send message from ff02::* (link-local multicast), we use our link-local address */
398 SendEchoReply(dst.IsMulticast() ? interface->GetLinkLocalAddress().GetAddress() : dst,
399 src,
400 request.GetId(),
401 request.GetSeq(),
402 p);
403 delete[] buf;
404}
405
406void
408 const Ipv6Address& src,
409 const Ipv6Address& dst,
410 Ptr<Ipv6Interface> interface)
411{
412 NS_LOG_FUNCTION(this << packet << src << dst << interface);
413
414 if (m_handleRsTimeoutEvent.IsPending())
415 {
416 m_handleRsTimeoutEvent.Cancel();
417 // We need to update this in case we need to restart RS retransmissions.
419 }
420
421 Ptr<Packet> p = packet->Copy();
422 Icmpv6RA raHeader;
423 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
425 Icmpv6OptionMtu mtuHdr;
427 bool next = true;
428 bool hasLla = false;
429 bool hasMtu = false;
430 Ipv6Address defaultRouter = Ipv6Address::GetZero();
431
432 p->RemoveHeader(raHeader);
433
434 // If 'M' flag is set, we need to start DHCPv6.
435 if (raHeader.GetFlagM())
436 {
437 if (!m_startDhcpv6.IsNull())
438 {
439 m_startDhcpv6(ipv6->GetInterfaceForDevice(interface->GetDevice()));
440 }
441 }
442
443 if (raHeader.GetLifeTime())
444 {
445 defaultRouter = src;
446 }
447
448 while (next)
449 {
450 uint8_t type = 0;
451 p->CopyData(&type, sizeof(type));
452
453 switch (type)
454 {
456 p->RemoveHeader(prefixHdr);
457 ipv6->AddAutoconfiguredAddress(ipv6->GetInterfaceForDevice(interface->GetDevice()),
458 prefixHdr.GetPrefix(),
459 prefixHdr.GetPrefixLength(),
460 prefixHdr.GetFlags(),
461 prefixHdr.GetValidTime(),
462 prefixHdr.GetPreferredTime(),
463 defaultRouter);
464 break;
466 /* take in account the first MTU option */
467 if (!hasMtu)
468 {
469 p->RemoveHeader(mtuHdr);
470 hasMtu = true;
471 /** @todo case of multiple prefix on single interface */
472 /* interface->GetDevice ()->SetMtu (m.GetMtu ()); */
473 }
474 break;
476 /* take in account the first LLA option */
477 if (!hasLla)
478 {
479 p->RemoveHeader(llaHdr);
480 ReceiveLLA(llaHdr, src, dst, interface);
481 hasLla = true;
482 }
483 break;
484 default:
485 /* unknown option, quit */
486 next = false;
487 }
488 }
489}
490
491void
493 const Ipv6Address& src,
494 const Ipv6Address& dst,
495 Ptr<Ipv6Interface> interface)
496{
497 NS_LOG_FUNCTION(this << lla << src << dst << interface);
498 NdiscCache::Entry* entry = nullptr;
499 Ptr<NdiscCache> cache = FindCache(interface->GetDevice());
500
501 /* check if we have this address in our cache */
502 entry = cache->Lookup(src);
503
504 if (!entry)
505 {
506 entry = cache->Add(src);
507 entry->SetRouter(true);
508 entry->SetMacAddress(lla.GetAddress());
509 entry->MarkReachable();
510 entry->StartReachableTimer();
511 }
512 else
513 {
514 std::list<NdiscCache::Ipv6PayloadHeaderPair> waiting;
515 switch (entry->m_state)
516 {
518 entry->StopNudTimer();
519 // mark it to reachable
520 waiting = entry->MarkReachable(lla.GetAddress());
521 entry->StartReachableTimer();
522 // send out waiting packet
523 for (auto it = waiting.begin(); it != waiting.end(); it++)
524 {
525 cache->GetInterface()->Send(it->first, it->second, src);
526 }
527 entry->ClearWaitingPacket();
528 return;
529 }
532 if (entry->GetMacAddress() != lla.GetAddress())
533 {
534 entry->SetMacAddress(lla.GetAddress());
535 entry->MarkStale();
536 entry->SetRouter(true);
537 }
538 else
539 {
540 entry->StopNudTimer();
541 waiting = entry->MarkReachable(lla.GetAddress());
542 entry->StartReachableTimer();
543 }
544 return;
545 }
547 if (entry->GetMacAddress() != lla.GetAddress())
548 {
549 entry->SetMacAddress(lla.GetAddress());
550 entry->MarkStale();
551 entry->SetRouter(true);
552 }
553 else
554 {
555 entry->StopNudTimer();
556 waiting = entry->MarkReachable(lla.GetAddress());
557 for (auto it = waiting.begin(); it != waiting.end(); it++)
558 {
559 cache->GetInterface()->Send(it->first, it->second, src);
560 }
561 entry->StartReachableTimer();
562 }
563 return;
564 }
566 if (entry->GetMacAddress() != lla.GetAddress())
567 {
568 entry->SetMacAddress(lla.GetAddress());
569 entry->MarkStale();
570 entry->SetRouter(true);
571 }
572 entry->StartReachableTimer();
573 return;
574 }
577 if (entry->GetMacAddress() != lla.GetAddress())
578 {
579 entry->SetMacAddress(lla.GetAddress());
580 entry->MarkStale();
581 entry->SetRouter(true);
582 }
583 return;
584 }
585 }
586 return; // Silence compiler warning
587 }
588}
589
590void
592 const Ipv6Address& src,
593 const Ipv6Address& dst,
594 Ptr<Ipv6Interface> interface)
595{
596 NS_LOG_FUNCTION(this << packet << src << dst << interface);
597 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
598 Icmpv6RS rsHeader;
599 packet->RemoveHeader(rsHeader);
601 NdiscCache::Entry* entry = nullptr;
602 Ptr<NdiscCache> cache = FindCache(interface->GetDevice());
603
604 if (src != Ipv6Address::GetAny())
605 {
606 /* XXX search all options following the RS header */
607 /* test if the next option is SourceLinkLayerAddress */
608 uint8_t type;
609 packet->CopyData(&type, sizeof(type));
610
612 {
613 return;
614 }
615 packet->RemoveHeader(lla);
616 NS_LOG_LOGIC("Cache updated by RS");
617
618 entry = cache->Lookup(src);
619 if (!entry)
620 {
621 entry = cache->Add(src);
622 entry->SetRouter(false);
623 entry->MarkStale(lla.GetAddress());
624 }
625 else if (entry->GetMacAddress() != lla.GetAddress())
626 {
627 entry->MarkStale(lla.GetAddress());
628 }
629 }
630}
631
632void
634 const Ipv6Address& src,
635 const Ipv6Address& dst,
636 Ptr<Ipv6Interface> interface)
637{
638 NS_LOG_FUNCTION(this << packet << src << dst << interface);
639 Icmpv6NS nsHeader("::");
641 uint32_t nb = interface->GetNAddresses();
642 uint32_t i = 0;
643 bool found = false;
644
645 packet->RemoveHeader(nsHeader);
646
647 Ipv6Address target = nsHeader.GetIpv6Target();
648
649 for (i = 0; i < nb; i++)
650 {
651 ifaddr = interface->GetAddress(i);
652
653 if (ifaddr.GetAddress() == target)
654 {
655 found = true;
656 break;
657 }
658 }
659
660 if (!found)
661 {
662 NS_LOG_LOGIC("Not a NS for us");
663 return;
664 }
665
666 if (packet->GetUid() == ifaddr.GetNsDadUid())
667 {
668 /* don't process our own DAD probe */
669 NS_LOG_LOGIC("Hey we receive our DAD probe!");
670 return;
671 }
672
673 NdiscCache::Entry* entry = nullptr;
674 Ptr<NdiscCache> cache = FindCache(interface->GetDevice());
675 uint8_t flags = 0;
676
677 /* search all options following the NS header */
678 Icmpv6OptionLinkLayerAddress sllaoHdr(true);
679
680 bool next = true;
681 bool hasSllao = false;
682
683 while (next)
684 {
685 uint8_t type;
686 packet->CopyData(&type, sizeof(type));
687
688 switch (type)
689 {
691 if (!hasSllao)
692 {
693 packet->RemoveHeader(sllaoHdr);
694 hasSllao = true;
695 }
696 break;
697 default:
698 /* unknown option, quit */
699 next = false;
700 }
701 if (packet->GetSize() == 0)
702 {
703 next = false;
704 }
705 }
706
707 Address replyMacAddress;
708
709 if (src != Ipv6Address::GetAny())
710 {
711 entry = cache->Lookup(src);
712 if (!entry)
713 {
714 if (!hasSllao)
715 {
716 NS_LOG_LOGIC("Icmpv6L4Protocol::HandleNS: NS without SLLAO and we do not have a "
717 "NCE, discarding.");
718 return;
719 }
720 entry = cache->Add(src);
721 entry->SetRouter(false);
722 entry->MarkStale(sllaoHdr.GetAddress());
723 replyMacAddress = sllaoHdr.GetAddress();
724 }
725 else if (hasSllao && (entry->GetMacAddress() != sllaoHdr.GetAddress()))
726 {
727 entry->MarkStale(sllaoHdr.GetAddress());
728 replyMacAddress = sllaoHdr.GetAddress();
729 }
730 else
731 {
732 replyMacAddress = entry->GetMacAddress();
733 }
734
735 flags = 3; /* S + O flags */
736 }
737 else
738 {
739 /* it's a DAD */
740 flags = 1; /* O flag */
741 replyMacAddress = interface->GetDevice()->GetMulticast(dst);
742 }
743
744 /* send a NA to src */
745 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
746
747 if (ipv6->IsForwarding(ipv6->GetInterfaceForDevice(interface->GetDevice())))
748 {
749 flags += 4; /* R flag */
750 }
751
752 // DAD replies are sent to a multicast address. Otherwise, use the interface address that is
753 // valid for the unicast receiver, as the device may have multiple link-layer addresses.
754 Address hardwareAddress = src.IsAny() ? interface->GetDevice()->GetAddress()
755 : interface->GetDevice()->GetAddressFor(replyMacAddress);
757 target.IsLinkLocal() ? interface->GetLinkLocalAddress().GetAddress() : ifaddr.GetAddress(),
758 src.IsAny() ? dst : src, // DAD replies must go to the multicast group it was sent to.
759 &hardwareAddress,
760 flags);
761
762 // We must bypass the IPv6 layer, as a NA must be sent regardless of the NCE status (and not
763 // change it beyond what we did already).
764 Ptr<Packet> pkt = p.first;
765 pkt->AddHeader(p.second);
766 interface->GetDevice()->Send(pkt, replyMacAddress, Ipv6L3Protocol::PROT_NUMBER);
767}
768
771{
772 NS_LOG_FUNCTION(this << src << dst << hardwareAddress);
774 Ipv6Header ipHeader;
775 Icmpv6RS rs;
776
777 NS_LOG_LOGIC("Forge RS (from " << src << " to " << dst << ")");
778 // RFC 4861:
779 // The link-layer address of the sender MUST NOT be included if the Source Address is the
780 // unspecified address. Otherwise, it SHOULD be included on link layers that have addresses.
781 if (!src.IsAny())
782 {
784 true,
785 hardwareAddress); /* we give our mac address in response */
786 p->AddHeader(llOption);
787 }
788
789 rs.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + rs.GetSerializedSize(), PROT_NUMBER);
790 p->AddHeader(rs);
791
792 ipHeader.SetSource(src);
793 ipHeader.SetDestination(dst);
794 ipHeader.SetNextHeader(PROT_NUMBER);
795 ipHeader.SetPayloadLength(p->GetSize());
796 ipHeader.SetHopLimit(255);
797
798 return NdiscCache::Ipv6PayloadHeaderPair(p, ipHeader);
799}
800
803 Ipv6Address dst,
804 uint16_t id,
805 uint16_t seq,
807{
808 NS_LOG_FUNCTION(this << src << dst << id << seq << data);
809 Ptr<Packet> p = data->Copy();
810 Ipv6Header ipHeader;
811 Icmpv6Echo req(true);
812
813 req.SetId(id);
814 req.SetSeq(seq);
815
817 dst,
818 p->GetSize() + req.GetSerializedSize(),
820 p->AddHeader(req);
821
822 ipHeader.SetSource(src);
823 ipHeader.SetDestination(dst);
824 ipHeader.SetNextHeader(PROT_NUMBER);
825 ipHeader.SetPayloadLength(p->GetSize());
826 ipHeader.SetHopLimit(255);
827
828 return NdiscCache::Ipv6PayloadHeaderPair(p, ipHeader);
829}
830
831void
833 const Ipv6Address& src,
834 const Ipv6Address& dst,
835 Ptr<Ipv6Interface> interface)
836{
837 NS_LOG_FUNCTION(this << packet << src << dst << interface);
838 Icmpv6NA naHeader;
840
841 packet->RemoveHeader(naHeader);
842 Ipv6Address target = naHeader.GetIpv6Target();
843
844 NdiscCache::Entry* entry = nullptr;
845 Ptr<NdiscCache> cache = FindCache(interface->GetDevice());
846 std::list<NdiscCache::Ipv6PayloadHeaderPair> waiting;
847
848 /* check if we have something in our cache */
849 entry = cache->Lookup(target);
850
851 if (!entry)
852 {
853 /* ouch!! we might be victim of a DAD */
854
856 bool found = false;
857 uint32_t i = 0;
858 uint32_t nb = interface->GetNAddresses();
859
860 for (i = 0; i < nb; i++)
861 {
862 ifaddr = interface->GetAddress(i);
863 if (ifaddr.GetAddress() == target)
864 {
865 found = true;
866 break;
867 }
868 }
869
870 if (found)
871 {
874 {
876 interface->SetState(ifaddr.GetAddress(), Ipv6InterfaceAddress::INVALID);
877 }
878 }
879
880 /* we have not initiated any communication with the target so... discard the NA */
881 return;
882 }
883
884 /* XXX search all options following the NA header */
885 /* Get LLA */
886 uint8_t type;
887 packet->CopyData(&type, sizeof(type));
888
890 {
891 return;
892 }
893 packet->RemoveHeader(lla);
894
895 /* we receive a NA so stop the probe timer or delay timer if any */
896 entry->StopNudTimer();
897 switch (entry->m_state)
898 {
900 /* we receive a NA so stop the retransmission timer */
901 entry->StopNudTimer();
902
903 if (naHeader.GetFlagS())
904 {
905 /* mark it to reachable */
906 waiting = entry->MarkReachable(lla.GetAddress());
907 entry->StartReachableTimer();
908 /* send out waiting packet */
909 for (auto it = waiting.begin(); it != waiting.end(); it++)
910 {
911 cache->GetInterface()->Send(it->first, it->second, src);
912 }
913 entry->ClearWaitingPacket();
914 }
915 else
916 {
917 entry->MarkStale(lla.GetAddress());
918 }
919
920 if (naHeader.GetFlagR())
921 {
922 entry->SetRouter(true);
923 }
924 return;
925 }
927 /* if the Flag O is clear and mac address differs from the cache */
928 if (!naHeader.GetFlagO() && lla.GetAddress() != entry->GetMacAddress())
929 {
930 entry->MarkStale();
931 return;
932 }
933 else
934 {
935 entry->SetMacAddress(lla.GetAddress());
936 if (naHeader.GetFlagS())
937 {
938 entry->StartReachableTimer();
939 }
940 else if (lla.GetAddress() != entry->GetMacAddress())
941 {
942 entry->MarkStale();
943 }
944 entry->SetRouter(naHeader.GetFlagR());
945 }
946 break;
947 }
950 /* if the Flag O is clear and mac address differs from the cache */
951 if (naHeader.GetFlagO() || lla.GetAddress() == entry->GetMacAddress())
952 {
953 entry->SetMacAddress(lla.GetAddress());
954 if (naHeader.GetFlagS())
955 {
956 entry->MarkReachable(lla.GetAddress());
957 entry->StartReachableTimer();
958 }
959 else if (lla.GetAddress() != entry->GetMacAddress())
960 {
961 entry->MarkStale();
962 }
963 entry->SetRouter(naHeader.GetFlagR());
964 }
965 return;
966 }
968 if (naHeader.GetFlagO() || lla.GetAddress() == entry->GetMacAddress())
969 {
970 entry->SetMacAddress(lla.GetAddress());
971 if (naHeader.GetFlagS())
972 {
973 waiting = entry->MarkReachable(lla.GetAddress());
974 for (auto it = waiting.begin(); it != waiting.end(); it++)
975 {
976 cache->GetInterface()->Send(it->first, it->second, src);
977 }
978 entry->ClearWaitingPacket();
979 entry->StartReachableTimer();
980 }
981 else if (lla.GetAddress() != entry->GetMacAddress())
982 {
983 entry->MarkStale();
984 }
985 entry->SetRouter(naHeader.GetFlagR());
986 }
987 return;
988 }
991 if (naHeader.GetFlagO() || lla.GetAddress() == entry->GetMacAddress())
992 {
993 entry->SetMacAddress(lla.GetAddress());
994 if (lla.GetAddress() != entry->GetMacAddress())
995 {
996 entry->MarkStale();
997 }
998 entry->SetRouter(naHeader.GetFlagR());
999 }
1000 return;
1001 }
1002 }
1003 // Silence compiler warning
1004}
1005
1006void
1008 const Ipv6Address& src,
1009 const Ipv6Address& dst,
1010 Ptr<Ipv6Interface> interface)
1011{
1012 NS_LOG_FUNCTION(this << packet << src << dst << interface);
1013 bool hasLla = false;
1014 Ptr<Packet> p = packet->Copy();
1015 Icmpv6OptionLinkLayerAddress llOptionHeader(false);
1016
1017 Icmpv6Redirection redirectionHeader;
1018 p->RemoveHeader(redirectionHeader);
1019
1020 /* little ugly try to find a better way */
1021 uint8_t type;
1022 p->CopyData(&type, sizeof(type));
1024 {
1025 hasLla = true;
1026 p->RemoveHeader(llOptionHeader);
1027 }
1028
1029 Icmpv6OptionRedirected redirectedOptionHeader;
1030 p->RemoveHeader(redirectedOptionHeader);
1031
1032 Ipv6Address redirTarget = redirectionHeader.GetTarget();
1033 Ipv6Address redirDestination = redirectionHeader.GetDestination();
1034
1035 if (hasLla)
1036 {
1037 /* update the cache if needed */
1038 NdiscCache::Entry* entry = nullptr;
1039 Ptr<NdiscCache> cache = FindCache(interface->GetDevice());
1040
1041 entry = cache->Lookup(redirTarget);
1042 if (!entry)
1043 {
1044 entry = cache->Add(redirTarget);
1045 /* destination and target different => necessarily a router */
1046 entry->SetRouter(redirTarget != redirDestination);
1047 entry->SetMacAddress(llOptionHeader.GetAddress());
1048 entry->MarkStale();
1049 }
1050 else
1051 {
1052 if (entry->IsIncomplete() || entry->GetMacAddress() != llOptionHeader.GetAddress())
1053 {
1054 /* update entry to STALE */
1055 if (entry->GetMacAddress() != llOptionHeader.GetAddress())
1056 {
1057 entry->SetMacAddress(llOptionHeader.GetAddress());
1058 entry->MarkStale();
1059 }
1060 }
1061 else
1062 {
1063 /* stay unchanged */
1064 }
1065 }
1066 }
1067
1068 /* add redirection in routing table */
1069 Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6>();
1070
1071 if (redirTarget == redirDestination)
1072 {
1073 ipv6->GetRoutingProtocol()->NotifyAddRoute(redirDestination,
1074 Ipv6Prefix(128),
1075 Ipv6Address("::"),
1076 ipv6->GetInterfaceForAddress(dst));
1077 }
1078 else
1079 {
1080 uint32_t ifIndex = ipv6->GetInterfaceForAddress(dst);
1081 ipv6->GetRoutingProtocol()->NotifyAddRoute(redirDestination,
1082 Ipv6Prefix(128),
1083 redirTarget,
1084 ifIndex);
1085 }
1086}
1087
1088void
1090 const Ipv6Address& src,
1091 const Ipv6Address& dst,
1092 Ptr<Ipv6Interface> interface)
1093{
1094 NS_LOG_FUNCTION(this << *p << src << dst << interface);
1095 Ptr<Packet> pkt = p->Copy();
1096
1098 pkt->RemoveHeader(unreach);
1099
1100 Ipv6Header ipHeader;
1101 if (pkt->GetSize() > ipHeader.GetSerializedSize())
1102 {
1103 pkt->RemoveHeader(ipHeader);
1104 uint8_t payload[8];
1105 pkt->CopyData(payload, 8);
1106 Forward(src, unreach, unreach.GetCode(), ipHeader, payload);
1107 }
1108}
1109
1110void
1112 const Ipv6Address& src,
1113 const Ipv6Address& dst,
1114 Ptr<Ipv6Interface> interface)
1115{
1116 NS_LOG_FUNCTION(this << *p << src << dst << interface);
1117 Ptr<Packet> pkt = p->Copy();
1118
1119 Icmpv6TimeExceeded timeexceeded;
1120 pkt->RemoveHeader(timeexceeded);
1121
1122 Ipv6Header ipHeader;
1123 if (pkt->GetSize() > ipHeader.GetSerializedSize())
1124 {
1125 Ipv6Header ipHeader;
1126 pkt->RemoveHeader(ipHeader);
1127 uint8_t payload[8];
1128 pkt->CopyData(payload, 8);
1129 Forward(src, timeexceeded, timeexceeded.GetCode(), ipHeader, payload);
1130 }
1131}
1132
1133void
1135 const Ipv6Address& src,
1136 const Ipv6Address& dst,
1137 Ptr<Ipv6Interface> interface)
1138{
1139 NS_LOG_FUNCTION(this << *p << src << dst << interface);
1140 Ptr<Packet> pkt = p->Copy();
1141
1142 Icmpv6TooBig tooBig;
1143 pkt->RemoveHeader(tooBig);
1144
1145 Ipv6Header ipHeader;
1146 if (pkt->GetSize() > ipHeader.GetSerializedSize())
1147 {
1148 pkt->RemoveHeader(ipHeader);
1149 uint8_t payload[8];
1150 pkt->CopyData(payload, 8);
1151
1152 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
1153 ipv6->SetPmtu(ipHeader.GetDestination(), tooBig.GetMtu());
1154
1155 Forward(src, tooBig, tooBig.GetMtu(), ipHeader, payload);
1156 }
1157}
1158
1159void
1161 const Ipv6Address& src,
1162 const Ipv6Address& dst,
1163 Ptr<Ipv6Interface> interface)
1164{
1165 NS_LOG_FUNCTION(this << *p << src << dst << interface);
1166 Ptr<Packet> pkt = p->Copy();
1167
1168 Icmpv6ParameterError paramErr;
1169 pkt->RemoveHeader(paramErr);
1170
1171 Ipv6Header ipHeader;
1172 if (pkt->GetSize() > ipHeader.GetSerializedSize())
1173 {
1174 pkt->RemoveHeader(ipHeader);
1175 uint8_t payload[8];
1176 pkt->CopyData(payload, 8);
1177 Forward(src, paramErr, paramErr.GetCode(), ipHeader, payload);
1178 }
1179}
1180
1181void
1183{
1184 NS_LOG_FUNCTION(this << packet << src << dst << (uint32_t)ttl);
1185 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
1187 NS_ASSERT(ipv6);
1188
1189 tag.SetHopLimit(ttl);
1190 packet->AddPacketTag(tag);
1191 m_downTarget(packet, src, dst, PROT_NUMBER, nullptr);
1192}
1193
1194void
1196 Ipv6Address src,
1197 Ipv6Address dst,
1198 uint8_t ttl)
1199{
1200 NS_LOG_FUNCTION(this << packet << src << dst << (uint32_t)ttl);
1201 SendMessage(packet, src, dst, ttl);
1202}
1203
1204void
1206 Ipv6Address dst,
1207 Icmpv6Header& icmpv6Hdr,
1208 uint8_t ttl)
1209{
1210 NS_LOG_FUNCTION(this << packet << dst << icmpv6Hdr << (uint32_t)ttl);
1211 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
1212 NS_ASSERT(ipv6 && ipv6->GetRoutingProtocol());
1213 Ipv6Header header;
1216 Ptr<Ipv6Route> route;
1217 Ptr<NetDevice> oif(nullptr); // specify non-zero if bound to a source address
1218
1219 header.SetDestination(dst);
1220 route = ipv6->GetRoutingProtocol()->RouteOutput(packet, header, oif, err);
1221
1222 if (route)
1223 {
1224 NS_LOG_LOGIC("Route exists");
1225 tag.SetHopLimit(ttl);
1226 packet->AddPacketTag(tag);
1227 Ipv6Address src = route->GetSource();
1228
1229 icmpv6Hdr.CalculatePseudoHeaderChecksum(src,
1230 dst,
1231 packet->GetSize() + icmpv6Hdr.GetSerializedSize(),
1232 PROT_NUMBER);
1233 packet->AddHeader(icmpv6Hdr);
1234 m_downTarget(packet, src, dst, PROT_NUMBER, route);
1235 }
1236 else
1237 {
1238 NS_LOG_WARN("drop icmp message");
1239 }
1240}
1241
1242void
1243Icmpv6L4Protocol::SendNA(Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags)
1244{
1245 NS_LOG_FUNCTION(this << src << dst << hardwareAddress << static_cast<uint32_t>(flags));
1247 Icmpv6NA na;
1248 Icmpv6OptionLinkLayerAddress llOption(false, *hardwareAddress); /* not a source link layer */
1249
1250 NS_LOG_LOGIC("Send NA ( from " << src << " to " << dst << " target " << src << ")");
1251 na.SetIpv6Target(src);
1252
1253 if (flags & 1)
1254 {
1255 na.SetFlagO(true);
1256 }
1257 if ((flags & 2) && src != Ipv6Address::GetAny())
1258 {
1259 na.SetFlagS(true);
1260 }
1261 if (flags & 4)
1262 {
1263 na.SetFlagR(true);
1264 }
1265
1266 p->AddHeader(llOption);
1267 na.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + na.GetSerializedSize(), PROT_NUMBER);
1268 p->AddHeader(na);
1269
1270 SendMessage(p, src, dst, 255);
1271}
1272
1273void
1275 Ipv6Address dst,
1276 uint16_t id,
1277 uint16_t seq,
1279{
1280 NS_LOG_FUNCTION(this << src << dst << id << seq << data);
1281 Ptr<Packet> p = data->Copy();
1282 Icmpv6Echo reply(false); /* echo reply */
1283
1284 reply.SetId(id);
1285 reply.SetSeq(seq);
1286
1288 dst,
1289 p->GetSize() + reply.GetSerializedSize(),
1290 PROT_NUMBER);
1291 p->AddHeader(reply);
1292 SendMessage(p, src, dst, 64);
1293}
1294
1295void
1297 Ipv6Address dst,
1298 Ipv6Address target,
1299 Address hardwareAddress)
1300{
1301 NS_LOG_FUNCTION(this << src << dst << target << hardwareAddress);
1303 /* Ipv6Header ipHeader; */
1304 Icmpv6NS ns(target);
1306 true,
1307 hardwareAddress); /* we give our mac address in response */
1308
1309 /* if the source is unspec, multicast the NA to all-nodes multicast */
1310 if (src == Ipv6Address::GetAny())
1311 {
1313 }
1314
1315 NS_LOG_LOGIC("Send NS ( from " << src << " to " << dst << " target " << target << ")");
1316
1317 p->AddHeader(llOption);
1318 ns.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + ns.GetSerializedSize(), PROT_NUMBER);
1319 p->AddHeader(ns);
1320 if (!dst.IsMulticast())
1321 {
1322 SendMessage(p, src, dst, 255);
1323 }
1324 else
1325 {
1326 NS_LOG_LOGIC("Destination is Multicast, using DelayedSendMessage");
1329 this,
1330 p,
1331 src,
1332 dst,
1333 255);
1334 }
1335}
1336
1337void
1339{
1340 NS_LOG_FUNCTION(this << src << dst << hardwareAddress);
1342 Icmpv6RS rs;
1343
1344 // RFC 4861:
1345 // The link-layer address of the sender MUST NOT be included if the Source Address is the
1346 // unspecified address. Otherwise, it SHOULD be included on link layers that have addresses.
1347 if (!src.IsAny())
1348 {
1349 Icmpv6OptionLinkLayerAddress llOption(true, hardwareAddress);
1350 p->AddHeader(llOption);
1351 }
1352
1353 if (!src.IsAny())
1354 {
1355 Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol>();
1356 if (ipv6->GetInterfaceForAddress(src) == -1)
1357 {
1358 NS_LOG_INFO("Preventing RS from being sent or rescheduled because the source address "
1359 << src << " has been removed");
1360 return;
1361 }
1362 }
1363
1364 NS_LOG_LOGIC("Send RS (from " << src << " to " << dst << ")");
1365
1366 rs.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + rs.GetSerializedSize(), PROT_NUMBER);
1367 p->AddHeader(rs);
1368 if (!dst.IsMulticast())
1369 {
1370 SendMessage(p, src, dst, 255);
1371 }
1372 else
1373 {
1374 NS_LOG_LOGIC("Destination is Multicast, using DelayedSendMessage");
1375 Time rsDelay = Time(0);
1376 Time rsTimeout = Time(0);
1377
1378 if (m_rsRetransmissionCount == 0)
1379 {
1380 // First RS transmission - also add some jitter to desynchronize nodes.
1382 rsTimeout = m_rsInitialRetransmissionTime * (1 + m_rsRetransmissionJitter->GetValue());
1383 rsDelay = MilliSeconds(m_solicitationJitter->GetValue());
1384 }
1385 else
1386 {
1387 // Following RS transmission - adding further jitter is unnecessary.
1388 rsTimeout = m_rsPrevRetransmissionTimeout * (2 + m_rsRetransmissionJitter->GetValue());
1389 if (rsTimeout > m_rsMaxRetransmissionTime)
1390 {
1391 rsTimeout = m_rsMaxRetransmissionTime * (1 + m_rsRetransmissionJitter->GetValue());
1392 }
1393 }
1395 Simulator::Schedule(rsDelay, &Icmpv6L4Protocol::DelayedSendMessage, this, p, src, dst, 255);
1398 this,
1399 src,
1400 dst,
1401 hardwareAddress);
1402 }
1403}
1404
1405void
1407{
1408 NS_LOG_FUNCTION(this << src << dst << hardwareAddress);
1409
1411 {
1412 // Unbound number of retransmissions - just add one to signal that we're in retransmission
1413 // mode.
1415 }
1416 else
1417 {
1420 {
1421 NS_LOG_LOGIC("Maximum number of multicast RS reached, giving up.");
1422 return;
1423 }
1424 }
1425
1426 if (!m_rsMaxRetransmissionDuration.IsZero() &&
1428 {
1429 NS_LOG_LOGIC("Maximum RS retransmission time reached, giving up.");
1430 return;
1431 }
1432
1433 SendRS(src, dst, hardwareAddress);
1434}
1435
1436void
1438 Ipv6Address dst,
1439 uint8_t code)
1440{
1441 NS_LOG_FUNCTION(this << malformedPacket << dst << (uint32_t)code);
1442 uint32_t malformedPacketSize = malformedPacket->GetSize();
1444 header.SetCode(code);
1445
1446 NS_LOG_LOGIC("Send Destination Unreachable ( to " << dst << " code " << (uint32_t)code << " )");
1447
1448 /* 48 = sizeof IPv6 header + sizeof ICMPv6 error header */
1449 if (malformedPacketSize <= 1280 - 48)
1450 {
1451 header.SetPacket(malformedPacket);
1452 SendMessage(malformedPacket, dst, header, 255);
1453 }
1454 else
1455 {
1456 Ptr<Packet> fragment = malformedPacket->CreateFragment(0, 1280 - 48);
1457 header.SetPacket(fragment);
1458 SendMessage(fragment, dst, header, 255);
1459 }
1460}
1461
1462void
1464{
1465 NS_LOG_FUNCTION(this << malformedPacket << dst << mtu);
1466 uint32_t malformedPacketSize = malformedPacket->GetSize();
1467 Icmpv6TooBig header;
1468 header.SetCode(0);
1469 header.SetMtu(mtu);
1470
1471 NS_LOG_LOGIC("Send Too Big ( to " << dst << " )");
1472
1473 /* 48 = sizeof IPv6 header + sizeof ICMPv6 error header */
1474 if (malformedPacketSize <= 1280 - 48)
1475 {
1476 header.SetPacket(malformedPacket);
1477 SendMessage(malformedPacket, dst, header, 255);
1478 }
1479 else
1480 {
1481 Ptr<Packet> fragment = malformedPacket->CreateFragment(0, 1280 - 48);
1482 header.SetPacket(fragment);
1483 SendMessage(fragment, dst, header, 255);
1484 }
1485}
1486
1487void
1489{
1490 NS_LOG_FUNCTION(this << malformedPacket << dst << static_cast<uint32_t>(code));
1491 uint32_t malformedPacketSize = malformedPacket->GetSize();
1492 Icmpv6TimeExceeded header;
1493 header.SetCode(code);
1494
1495 NS_LOG_LOGIC("Send Time Exceeded ( to " << dst << " code " << (uint32_t)code << " )");
1496
1497 /* 48 = sizeof IPv6 header + sizeof ICMPv6 error header */
1498 if (malformedPacketSize <= 1280 - 48)
1499 {
1500 header.SetPacket(malformedPacket);
1501 SendMessage(malformedPacket, dst, header, 255);
1502 }
1503 else
1504 {
1505 Ptr<Packet> fragment = malformedPacket->CreateFragment(0, 1280 - 48);
1506 header.SetPacket(fragment);
1507 SendMessage(fragment, dst, header, 255);
1508 }
1509}
1510
1511void
1513 Ipv6Address dst,
1514 uint8_t code,
1515 uint32_t ptr)
1516{
1517 NS_LOG_FUNCTION(this << malformedPacket << dst << static_cast<uint32_t>(code) << ptr);
1518 uint32_t malformedPacketSize = malformedPacket->GetSize();
1519 Icmpv6ParameterError header;
1520 header.SetCode(code);
1521 header.SetPtr(ptr);
1522
1523 NS_LOG_LOGIC("Send Parameter Error ( to " << dst << " code " << (uint32_t)code << " )");
1524
1525 /* 48 = sizeof IPv6 header + sizeof ICMPv6 error header */
1526 if (malformedPacketSize <= 1280 - 48)
1527 {
1528 header.SetPacket(malformedPacket);
1529 SendMessage(malformedPacket, dst, header, 255);
1530 }
1531 else
1532 {
1533 Ptr<Packet> fragment = malformedPacket->CreateFragment(0, 1280 - 48);
1534 header.SetPacket(fragment);
1535 SendMessage(fragment, dst, header, 255);
1536 }
1537}
1538
1539void
1541 Ipv6Address src,
1542 Ipv6Address dst,
1543 Ipv6Address redirTarget,
1544 Ipv6Address redirDestination,
1545 Address redirHardwareTarget)
1546{
1547 NS_LOG_FUNCTION(this << redirectedPacket << dst << redirTarget << redirDestination
1548 << redirHardwareTarget);
1549 uint32_t llaSize = 0;
1551 uint32_t redirectedPacketSize = redirectedPacket->GetSize();
1552 Icmpv6OptionLinkLayerAddress llOption(false);
1553
1554 NS_LOG_LOGIC("Send Redirection ( to " << dst << " target " << redirTarget << " destination "
1555 << redirDestination << " )");
1556
1557 Icmpv6OptionRedirected redirectedOptionHeader;
1558
1559 if ((redirectedPacketSize % 8) != 0)
1560 {
1561 Ptr<Packet> pad = Create<Packet>(8 - (redirectedPacketSize % 8));
1562 redirectedPacket->AddAtEnd(pad);
1563 }
1564
1565 if (redirHardwareTarget.GetLength())
1566 {
1567 llOption.SetAddress(redirHardwareTarget);
1568 llaSize = llOption.GetSerializedSize();
1569 }
1570
1571 /* 56 = sizeof IPv6 header + sizeof ICMPv6 error header + sizeof redirected option */
1572 if (redirectedPacketSize <= (1280 - 56 - llaSize))
1573 {
1574 redirectedOptionHeader.SetPacket(redirectedPacket);
1575 }
1576 else
1577 {
1578 Ptr<Packet> fragment = redirectedPacket->CreateFragment(0, 1280 - 56 - llaSize);
1579 redirectedOptionHeader.SetPacket(fragment);
1580 }
1581
1582 p->AddHeader(redirectedOptionHeader);
1583
1584 if (llaSize)
1585 {
1586 p->AddHeader(llOption);
1587 }
1588
1589 Icmpv6Redirection redirectionHeader;
1590 redirectionHeader.SetTarget(redirTarget);
1591 redirectionHeader.SetDestination(redirDestination);
1592 redirectionHeader.CalculatePseudoHeaderChecksum(src,
1593 dst,
1594 p->GetSize() +
1595 redirectionHeader.GetSerializedSize(),
1596 PROT_NUMBER);
1597 p->AddHeader(redirectionHeader);
1598
1599 SendMessage(p, src, dst, 64);
1600}
1601
1603Icmpv6L4Protocol::ForgeNA(Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags)
1604{
1605 NS_LOG_FUNCTION(this << src << dst << hardwareAddress << (uint32_t)flags);
1607 Ipv6Header ipHeader;
1608 Icmpv6NA na;
1610 false,
1611 *hardwareAddress); /* we give our mac address in response */
1612
1613 NS_LOG_LOGIC("Send NA ( from " << src << " to " << dst << ")");
1614
1615 /* forge the entire NA packet from IPv6 header to ICMPv6 link-layer option, so that the packet
1616 * does not pass by Icmpv6L4Protocol::Lookup again */
1617
1618 p->AddHeader(llOption);
1619 na.SetIpv6Target(src);
1620
1621 if (flags & 1)
1622 {
1623 na.SetFlagO(true);
1624 }
1625 if ((flags & 2) && src != Ipv6Address::GetAny())
1626 {
1627 na.SetFlagS(true);
1628 }
1629 if (flags & 4)
1630 {
1631 na.SetFlagR(true);
1632 }
1633
1634 na.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + na.GetSerializedSize(), PROT_NUMBER);
1635 p->AddHeader(na);
1636
1637 ipHeader.SetSource(src);
1638 ipHeader.SetDestination(dst);
1639 ipHeader.SetNextHeader(PROT_NUMBER);
1640 ipHeader.SetPayloadLength(p->GetSize());
1641 ipHeader.SetHopLimit(255);
1642
1643 return NdiscCache::Ipv6PayloadHeaderPair(p, ipHeader);
1644}
1645
1648 Ipv6Address dst,
1649 Ipv6Address target,
1650 Address hardwareAddress)
1651{
1652 NS_LOG_FUNCTION(this << src << dst << target << hardwareAddress);
1654 Ipv6Header ipHeader;
1655 Icmpv6NS ns(target);
1657 true,
1658 hardwareAddress); /* we give our mac address in response */
1659
1660 NS_LOG_LOGIC("Send NS ( from " << src << " to " << dst << " target " << target << ")");
1661
1662 p->AddHeader(llOption);
1663 ns.CalculatePseudoHeaderChecksum(src, dst, p->GetSize() + ns.GetSerializedSize(), PROT_NUMBER);
1664 p->AddHeader(ns);
1665
1666 ipHeader.SetSource(src);
1667 ipHeader.SetDestination(dst);
1668 ipHeader.SetNextHeader(PROT_NUMBER);
1669 ipHeader.SetPayloadLength(p->GetSize());
1670 ipHeader.SetHopLimit(255);
1671
1672 return NdiscCache::Ipv6PayloadHeaderPair(p, ipHeader);
1673}
1674
1677{
1678 NS_LOG_FUNCTION(this << device);
1679
1680 for (auto i = m_cacheList.begin(); i != m_cacheList.end(); i++)
1681 {
1682 if ((*i)->GetDevice() == device)
1683 {
1684 return *i;
1685 }
1686 }
1687
1688 NS_ASSERT_MSG(false, "Icmpv6L4Protocol can not find a NDIS Cache for device " << device);
1689 /* quiet compiler */
1690 return nullptr;
1691}
1692
1695{
1696 NS_LOG_FUNCTION(this << device << interface);
1697
1699
1700 cache->SetDevice(device, interface, this);
1701 device->AddLinkChangeCallback(MakeCallback(&NdiscCache::Flush, cache));
1702 m_cacheList.push_back(cache);
1703 return cache;
1704}
1705
1706bool
1708 Ptr<NetDevice> device,
1709 Ptr<NdiscCache> cache,
1710 Address* hardwareDestination)
1711{
1712 NS_LOG_FUNCTION(this << dst << device << cache << hardwareDestination);
1713
1714 if (!cache)
1715 {
1716 /* try to find the cache */
1717 cache = FindCache(device);
1718 }
1719 if (cache)
1720 {
1721 NdiscCache::Entry* entry = cache->Lookup(dst);
1722 if (entry)
1723 {
1724 if (entry->IsReachable() || entry->IsDelay() || entry->IsPermanent() ||
1725 entry->IsAutoGenerated())
1726 {
1727 *hardwareDestination = entry->GetMacAddress();
1728 return true;
1729 }
1730 else if (entry->IsStale())
1731 {
1732 entry->StartDelayTimer();
1733 entry->MarkDelay();
1734 *hardwareDestination = entry->GetMacAddress();
1735 return true;
1736 }
1737 }
1738 }
1739 return false;
1740}
1741
1742bool
1744 const Ipv6Header& ipHeader,
1745 Ipv6Address dst,
1746 Ptr<NetDevice> device,
1747 Ptr<NdiscCache> cache,
1748 Address* hardwareDestination)
1749{
1750 NS_LOG_FUNCTION(this << p << ipHeader << dst << device << cache << hardwareDestination);
1751
1752 if (!cache)
1753 {
1754 /* try to find the cache */
1755 cache = FindCache(device);
1756 }
1757 if (!cache)
1758 {
1759 return false;
1760 }
1761
1762 NdiscCache::Entry* entry = cache->Lookup(dst);
1763 if (entry)
1764 {
1765 if (entry->IsReachable() || entry->IsDelay() || entry->IsPermanent() ||
1766 entry->IsAutoGenerated())
1767 {
1768 /* XXX check reachability time */
1769 /* send packet */
1770 *hardwareDestination = entry->GetMacAddress();
1771 return true;
1772 }
1773 else if (entry->IsStale())
1774 {
1775 /* start delay timer */
1776 entry->StartDelayTimer();
1777 entry->MarkDelay();
1778 *hardwareDestination = entry->GetMacAddress();
1779 return true;
1780 }
1781 else /* INCOMPLETE or PROBE */
1782 {
1783 /* queue packet */
1785 return false;
1786 }
1787 }
1788 else
1789 {
1790 /* we contact this node for the first time
1791 * add it to the cache and send an NS
1792 */
1793 Ipv6Address addr;
1794 NdiscCache::Entry* entry = cache->Add(dst);
1796 entry->SetRouter(false);
1797
1798 if (dst.IsLinkLocal())
1799 {
1800 addr = cache->GetInterface()->GetLinkLocalAddress().GetAddress();
1801 }
1802 else if (cache->GetInterface()->GetNAddresses() ==
1803 1) /* an interface have at least one address (link-local) */
1804 {
1805 /* try to resolve global address without having global address so return! */
1806 cache->Remove(entry);
1807 return false;
1808 }
1809 else
1810 {
1811 /* find source address that match destination */
1812 addr = cache->GetInterface()->GetAddressMatchingDestination(dst).GetAddress();
1813 }
1814
1815 SendNS(addr, Ipv6Address::MakeSolicitedAddress(dst), dst, cache->GetDevice()->GetAddress());
1816
1817 /* start retransmit timer */
1818 entry->StartRetransmitTimer();
1819 return false;
1820 }
1821
1822 return false;
1823}
1824
1825void
1827{
1828 NS_LOG_FUNCTION(this << interface << addr);
1829
1830 Ipv6InterfaceAddress ifaddr;
1831 bool found = false;
1832 uint32_t i = 0;
1833 uint32_t nb = interface->GetNAddresses();
1834
1835 for (i = 0; i < nb; i++)
1836 {
1837 ifaddr = interface->GetAddress(i);
1838
1839 if (ifaddr.GetAddress() == addr)
1840 {
1841 found = true;
1842 break;
1843 }
1844 }
1845
1846 if (!found)
1847 {
1848 NS_LOG_LOGIC("Can not find the address in the interface.");
1849 }
1850
1851 /* for the moment, this function is always called, if we was victim of a DAD the address is
1852 * INVALID and we do not set it to PREFERRED
1853 */
1854 if (found && ifaddr.GetState() != Ipv6InterfaceAddress::INVALID)
1855 {
1858 NS_LOG_LOGIC("DAD OK, interface in state PREFERRED");
1859
1860 /* send an RS if our interface is not forwarding (router) and if address is a link-local
1861 * ones (because we will send RS with it)
1862 */
1863 Ptr<Ipv6> ipv6 = m_node->GetObject<Ipv6>();
1864
1865 if (!ipv6->IsForwarding(ipv6->GetInterfaceForDevice(interface->GetDevice())) &&
1866 addr.IsLinkLocal())
1867 {
1868 /* \todo Add random delays before sending RS
1869 * because all nodes start at the same time, there will be many of RS around 1 second of
1870 * simulation time
1871 */
1872 NS_LOG_LOGIC("Scheduled a first Router Solicitation");
1876 this,
1877 ifaddr.GetAddress(),
1879 interface->GetDevice()->GetAddress());
1880 }
1881 else
1882 {
1883 NS_LOG_LOGIC("Did not schedule a Router Solicitation because the interface is in "
1884 "forwarding mode");
1885 }
1886 }
1887}
1888
1889void
1894
1895void
1897{
1898 NS_LOG_FUNCTION(this << &callback);
1899 m_downTarget = callback;
1900}
1901
1908
1911{
1912 NS_LOG_FUNCTION(this);
1913 return m_downTarget;
1914}
1915
1916uint8_t
1921
1922uint8_t
1927
1928Time
1933
1934Time
1939
1940Time
1945
1946Time
1948{
1949 return m_dadTimeout;
1950}
1951
1952} /* namespace ns3 */
a polymophic address class
Definition address.h:114
uint8_t GetLength() const
Get the length of the underlying address.
Definition address.cc:62
ICMPv6 Error Destination Unreachable header.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
ICMPv6 Echo message.
void SetId(uint16_t id)
Set the ID of the packet.
uint16_t GetId() const
Get the ID of the packet.
void SetSeq(uint16_t seq)
Set the sequence number.
uint32_t GetSerializedSize() const override
Get the serialized size.
uint16_t GetSeq() const
Get the sequence number.
ICMPv6 header.
uint8_t GetCode() const
Get the code field.
uint8_t GetType() const
Get the type field.
void CalculatePseudoHeaderChecksum(Ipv6Address src, Ipv6Address dst, uint16_t length, uint8_t protocol)
Calculate pseudo header checksum for IPv6.
void SetCode(uint8_t code)
Set the code field.
uint32_t GetSerializedSize() const override
Get the serialized size.
@ ICMPV6_ERROR_DESTINATION_UNREACHABLE
An implementation of the ICMPv6 protocol.
Time GetRetransmissionTime() const
Neighbor Discovery node constants: retransmission timer.
int GetProtocolNumber() const override
Get the protocol number.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void Forward(Ipv6Address source, Icmpv6Header icmp, uint32_t info, Ipv6Header ipHeader, const uint8_t payload[8])
Notify an ICMPv6 reception to upper layers (if requested).
void ReceiveLLA(Icmpv6OptionLinkLayerAddress lla, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Link layer address option processing.
void SendErrorTimeExceeded(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code)
Send an error Time Exceeded.
IpL4Protocol::RxStatus Receive(Ptr< Packet > p, const Ipv4Header &header, Ptr< Ipv4Interface > interface) override
Receive method.
void DoDispose() override
Dispose this object.
void SendErrorTooBig(Ptr< Packet > malformedPacket, Ipv6Address dst, uint32_t mtu)
Send an error Too Big.
uint8_t m_maxMulticastSolicit
Neighbor Discovery node constants: max multicast solicitations.
void NotifyNewAggregate() override
This method is called by AggregateObject and completes the aggregation by setting the node in the ICM...
Time m_reachableTime
Neighbor Discovery node constants: reachable time.
NdiscCache::Ipv6PayloadHeaderPair ForgeEchoRequest(Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr< Packet > data)
Forge an Echo Request.
Time m_rsMaxRetransmissionTime
Maximum time between multicast RS retransmissions [RFC 7559].
uint32_t m_rsMaxRetransmissionCount
Maximum number of multicast RS retransmissions [RFC 7559].
ns3::TracedCallback< const Ipv6Address & > m_dadSuccessAddressTrace
The trace fired when a DAD completes and no duplicate address has been detected.
virtual Ptr< NdiscCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface)
Create a neighbor cache.
~Icmpv6L4Protocol() override
Destructor.
IpL4Protocol::DownTargetCallback6 GetDownTarget6() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv6 ca...
void SetDownTarget6(IpL4Protocol::DownTargetCallback6 cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv6 ca...
uint32_t m_rsRetransmissionCount
Multicast RS retransmissions counter [RFC 7559].
void DelayedSendMessage(Ptr< Packet > packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl)
Helper function used during delayed solicitation.
Ptr< Node > GetNode()
Get the node.
void HandleTimeExceeded(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Time Exceeded method.
void HandleDestinationUnreachable(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Destination Unreachable method.
void HandlePacketTooBig(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Packet Too Big method.
Callback< void, uint32_t > m_startDhcpv6
The DHCPv6 callback when the M flag is set in a Router Advertisement.
Ptr< UniformRandomVariable > m_rsRetransmissionJitter
Random jitter for RS retransmissions.
bool IsAlwaysDad() const
Is the node must do DAD.
void HandleRA(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Router Advertisement method.
void SetDownTarget(IpL4Protocol::DownTargetCallback cb) override
This method allows a caller to set the current down target callback set for this L4 protocol (IPv4 ca...
void SendErrorParameterError(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code, uint32_t ptr)
Send an error Parameter Error.
static constexpr uint8_t PROT_NUMBER
ICMPv6 protocol number (58).
Time GetDadTimeout() const
Get the DAD timeout.
Time GetDelayFirstProbe() const
Neighbor Discovery node constants : delay for the first probe.
NdiscCache::Ipv6PayloadHeaderPair ForgeNA(Ipv6Address src, Ipv6Address dst, Address *hardwareAddress, uint8_t flags)
Forge a Neighbor Advertisement.
void HandleRS(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Router Solicitation method.
virtual void FunctionDadTimeout(Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
uint8_t m_maxUnicastSolicit
Neighbor Discovery node constants: max unicast solicitations.
void SendRedirection(Ptr< Packet > redirectedPacket, Ipv6Address src, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
Send an ICMPv6 Redirection.
Time m_dadTimeout
DAD timeout.
Ptr< Node > m_node
The node.
IpL4Protocol::DownTargetCallback6 m_downTarget
callback to Ipv6::Send
Ptr< NdiscCache > FindCache(Ptr< NetDevice > device)
Get the cache corresponding to the device.
void DoDAD(Ipv6Address target, Ptr< Ipv6Interface > interface)
Do the Duplication Address Detection (DAD).
virtual void HandleRsTimeout(Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Router Solicitation Timeout handler.
bool m_alwaysDad
Always do DAD ?
void SendErrorDestinationUnreachable(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code)
Send an error Destination Unreachable.
ns3::TracedCallback< const Ipv6Address & > m_dadFailureAddressTrace
The trace fired when a DAD fails, changing the address state to INVALID.
virtual void SendNS(Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress)
Send a Neighbor Solicitation.
void SendRS(Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Send a Router Solicitation.
Time m_retransmissionTime
Neighbor Discovery node constants: retransmission timer.
uint8_t GetMaxUnicastSolicit() const
Neighbor Discovery node constants: max unicast solicitations.
void HandleEchoRequest(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Echo Request method.
void HandleParameterError(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Parameter Error method.
void HandleNS(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Neighbor Solicitation method.
Time m_rsMaxRetransmissionDuration
Maximum duration of multicast RS retransmissions [RFC 7559].
void HandleRedirection(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Redirection method.
virtual bool Lookup(Ipv6Address dst, Ptr< NetDevice > device, Ptr< NdiscCache > cache, Address *hardwareDestination)
Lookup in the ND cache for the IPv6 address.
Time m_rsPrevRetransmissionTimeout
Previous multicast RS retransmissions timeout [RFC 7559].
IpL4Protocol::DownTargetCallback GetDownTarget() const override
This method allows a caller to get the current down target callback set for this L4 protocol (IPv4 ca...
EventId m_handleRsTimeoutEvent
RS timeout handler event.
virtual int GetVersion() const
Get the version of the protocol.
Ptr< RandomVariableStream > m_solicitationJitter
Random jitter before sending solicitations.
void SendMessage(Ptr< Packet > packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl)
Send a packet via ICMPv6, note that packet already contains ICMPv6 header.
Time m_delayFirstProbe
Neighbor Discovery node constants: delay for the first probe.
void SendEchoReply(Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr< Packet > data)
Send a Echo Reply.
NdiscCache::Ipv6PayloadHeaderPair ForgeRS(Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Forge a Router Solicitation.
NdiscCache::Ipv6PayloadHeaderPair ForgeNS(Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress)
Forge a Neighbor Solicitation.
void SendNA(Ipv6Address src, Ipv6Address dst, Address *hardwareAddress, uint8_t flags)
Send a Neighbor Advertisement.
Time m_rsInitialRetransmissionTime
Initial multicast RS retransmission time [RFC 7559].
static TypeId GetTypeId()
Get the type ID.
Time GetReachableTime() const
Neighbor Discovery node constants: reachable time.
CacheList m_cacheList
A list of cache by device.
uint8_t GetMaxMulticastSolicit() const
Neighbor Discovery node constants: max multicast solicitations.
void SetNode(Ptr< Node > node)
Set the node.
static uint16_t GetStaticProtocolNumber()
Get ICMPv6 protocol number.
void HandleNA(Ptr< Packet > p, const Ipv6Address &src, const Ipv6Address &dst, Ptr< Ipv6Interface > interface)
Receive Neighbor Advertisement method.
ICMPv6 Neighbor Advertisement header.
bool GetFlagS() const
Get the S flag.
void SetFlagS(bool s)
Set the S flag.
void SetIpv6Target(Ipv6Address target)
Set the IPv6 target field.
void SetFlagR(bool r)
Set the R flag.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
bool GetFlagR() const
Get the R flag.
uint32_t GetSerializedSize() const override
Get the serialized size.
bool GetFlagO() const
Get the O flag.
void SetFlagO(bool o)
Set the O flag.
ICMPv6 Neighbor Solicitation header.
Ipv6Address GetIpv6Target() const
Get the IPv6 target field.
ICMPv6 MTU option.
ICMPv6 Option Prefix Information.
ICMPv6 redirected option.
void SetPacket(Ptr< Packet > packet)
Set the redirected packet.
ICMPv6 Error Parameter Error header.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
void SetPtr(uint32_t ptr)
Set the pointer field.
ICMPv6 Router Advertisement header.
uint16_t GetLifeTime() const
Get the node Life time (Neighbor Discovery).
bool GetFlagM() const
Get the M flag.
ICMPv6 Router Solicitation header.
uint32_t GetSerializedSize() const override
Get the serialized size.
ICMPv6 Redirection header.
Ipv6Address GetTarget() const
Get the IPv6 target address.
uint32_t GetSerializedSize() const override
Get the serialized size.
void SetDestination(Ipv6Address destination)
Set the IPv6 destination address.
Ipv6Address GetDestination() const
Get the IPv6 destination address.
void SetTarget(Ipv6Address target)
Set the IPv6 target address.
ICMPv6 Error Time Exceeded header.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
ICMPv6 Error Too Big header.
void SetMtu(uint32_t mtu)
Set the MTU.
void SetPacket(Ptr< Packet > p)
Set the incorrect packet.
uint32_t GetMtu() const
Get the MTU field.
Hold a signed integer type.
Definition integer.h:34
L4 Protocol abstract base class.
Callback< void, Ptr< Packet >, Ipv4Address, Ipv4Address, uint8_t, Ptr< Ipv4Route > > DownTargetCallback
callback to send packets over IPv4
Callback< void, Ptr< Packet >, Ipv6Address, Ipv6Address, uint8_t, Ptr< Ipv6Route > > DownTargetCallback6
callback to send packets over IPv6
RxStatus
Rx status codes.
Packet header for IPv4.
Definition ipv4-header.h:23
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
static Ipv6Address GetAllNodesMulticast()
Get the "all nodes multicast" address.
static Ipv6Address MakeSolicitedAddress(Ipv6Address addr)
Make the solicited IPv6 address.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
bool IsAny() const
If the IPv6 address is the "Any" address.
static Ipv6Address GetAllRoutersMulticast()
Get the "all routers multicast" address.
Packet header for IPv6.
Definition ipv6-header.h:24
void SetDestination(Ipv6Address dst)
Set the "Destination address" field.
void SetSource(Ipv6Address src)
Set the "Source address" field.
uint8_t GetHopLimit() const
Get the "Hop limit" field (TTL).
uint8_t GetNextHeader() const
Get the next header.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Ipv6Address GetDestination() const
Get the "Destination address" field.
void SetPayloadLength(uint16_t len)
Set the "Payload length" field.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Ipv6Address GetSource() const
Get the "Source address" field.
void SetNextHeader(uint8_t next)
Set the "Next header" field.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)=0
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers.
IPv6 address associated with an interface.
Ipv6Address GetAddress() const
Get the IPv6 address.
uint32_t GetNsDadUid() const
Get the latest DAD probe packet UID.
Ipv6InterfaceAddress::State_e GetState() const
Get the address state.
@ TENTATIVE_OPTIMISTIC
Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished.
@ INVALID
Invalid state (after a DAD failed).
@ TENTATIVE
Address is tentative, no packet can be sent unless DAD finished.
The IPv6 representation of a network interface.
uint32_t GetNAddresses() const
Get number of addresses on this IPv6 interface.
Ipv6InterfaceAddress GetAddress(uint32_t index) const
Get an address from IPv6 interface.
void Send(Ptr< Packet > p, const Ipv6Header &hdr, Ipv6Address dest)
Send a packet through this interface.
virtual Ptr< NetDevice > GetDevice() const
Get the NetDevice.
void SetState(Ipv6Address address, Ipv6InterfaceAddress::State_e state)
Update state of an interface address.
IPv6 layer implementation.
static constexpr uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Describes an IPv6 prefix.
A record that holds information about a NdiscCache entry.
bool IsPermanent() const
Is the entry PERMANENT.
NdiscCacheEntryState_e m_state
The state of the entry.
@ PROBE
Try to contact IPv6 address to know again its L2 address.
@ STALE
Mapping is stale.
@ REACHABLE
Mapping exists between IPv6 and L2 addresses.
@ PERMANENT
Permanent Mapping exists between IPv6 and L2 addresses.
@ DELAY
Try to wait contact from remote host.
@ INCOMPLETE
No mapping between IPv6 and L2 addresses.
@ STATIC_AUTOGENERATED
Permanent entries generate by NeighborCacheHelper.
void ClearWaitingPacket()
Clear the waiting packet list.
std::list< Ipv6PayloadHeaderPair > MarkStale(Address mac)
Changes the state to this entry to STALE.
void StartReachableTimer()
Start the reachable timer.
Address GetMacAddress() const
Get the MAC address of this entry.
void StartDelayTimer()
Start delay timer.
std::list< Ipv6PayloadHeaderPair > MarkReachable(Address mac)
Changes the state to this entry to REACHABLE.
bool IsIncomplete() const
Is the entry INCOMPLETE.
bool IsDelay() const
Is the entry DELAY.
void StartRetransmitTimer()
Start retransmit timer.
void MarkIncomplete(Ipv6PayloadHeaderPair p)
Changes the state to this entry to INCOMPLETE.
bool IsStale() const
Is the entry STALE.
void SetMacAddress(Address mac)
Set the MAC address of this entry.
void MarkDelay()
Change the state to this entry to DELAY.
void SetRouter(bool router)
Set the node type.
bool IsAutoGenerated() const
Is the entry STATIC_AUTOGENERATED.
void AddWaitingPacket(Ipv6PayloadHeaderPair p)
Add a packet (or replace old value) in the queue.
bool IsReachable() const
Is the entry REACHABLE.
void StopNudTimer()
Stop NUD timer and reset the NUD retransmission counter.
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv4 header.
void Flush()
Clear the cache of all entries except auto-generated entries.
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition object.cc:409
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:518
virtual void DoDispose()
Destructor implementation.
Definition object.cc:430
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
This class implements a tag that carries the socket-specific HOPLIMIT of a packet to the IPv6 layer.
Definition socket.h:1162
void SetHopLimit(uint8_t hopLimit)
Set the tag's Hop Limit.
Definition socket.cc:657
Hold variables of type string.
Definition string.h:45
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition pointer.h:250
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:273
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition callback.h:690
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:274
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:253
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:267
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:492
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1290
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition boolean.cc:113
Ptr< const AttributeChecker > MakeIntegerChecker()
Definition integer.h:99
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Definition integer.h:35
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1376
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition boolean.h:70
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1396
uint8_t data[writeSize]