A Discrete-Event Network Simulator
API
icmpv6-l4-protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2009 Strasbourg University
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
18  * David Gross <gdavid.devel@gmail.com>
19  * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
20  */
21 
22 #ifndef ICMPV6_L4_PROTOCOL_H
23 #define ICMPV6_L4_PROTOCOL_H
24 
25 #include "icmpv6-header.h"
26 #include "ip-l4-protocol.h"
27 #include "ndisc-cache.h"
28 
29 #include "ns3/ipv6-address.h"
30 #include "ns3/random-variable-stream.h"
31 
32 #include <list>
33 
34 namespace ns3
35 {
36 
37 class NetDevice;
38 class Node;
39 class Packet;
40 class TraceContext;
41 
53 {
54  public:
59  static TypeId GetTypeId();
60  TypeId GetInstanceTypeId() const override;
61 
65  static const uint8_t PROT_NUMBER;
66 
71  uint8_t GetMaxMulticastSolicit() const;
72 
77  uint8_t GetMaxUnicastSolicit() const;
78 
83  Time GetReachableTime() const;
84 
90 
95  Time GetDelayFirstProbe() const;
96 
101  static uint16_t GetStaticProtocolNumber();
102 
107 
111  ~Icmpv6L4Protocol() override;
112 
117  void SetNode(Ptr<Node> node);
118 
123  Ptr<Node> GetNode();
124 
130  void NotifyNewAggregate() override;
131 
136  int GetProtocolNumber() const override;
137 
142  virtual int GetVersion() const;
143 
151  void SendMessage(Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl);
152 
160  void DelayedSendMessage(Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl);
161 
170  void SendMessage(Ptr<Packet> packet, Ipv6Address dst, Icmpv6Header& icmpv6Hdr, uint8_t ttl);
171 
181  void DoDAD(Ipv6Address target, Ptr<Ipv6Interface> interface);
182 
190  void SendNA(Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags);
191 
200  void SendEchoReply(Ipv6Address src,
201  Ipv6Address dst,
202  uint16_t id,
203  uint16_t seq,
204  Ptr<Packet> data);
205 
213  virtual void SendNS(Ipv6Address src,
214  Ipv6Address dst,
215  Ipv6Address target,
216  Address hardwareAddress);
217 
224  void SendErrorDestinationUnreachable(Ptr<Packet> malformedPacket,
225  Ipv6Address dst,
226  uint8_t code);
227 
234  void SendErrorTooBig(Ptr<Packet> malformedPacket, Ipv6Address dst, uint32_t mtu);
235 
242  void SendErrorTimeExceeded(Ptr<Packet> malformedPacket, Ipv6Address dst, uint8_t code);
243 
251  void SendErrorParameterError(Ptr<Packet> malformedPacket,
252  Ipv6Address dst,
253  uint8_t code,
254  uint32_t ptr);
255 
265  void SendRedirection(Ptr<Packet> redirectedPacket,
266  Ipv6Address src,
267  Ipv6Address dst,
268  Ipv6Address redirTarget,
269  Ipv6Address redirDestination,
270  Address redirHardwareTarget);
271 
281  Ipv6Address dst,
282  Ipv6Address target,
283  Address hardwareAddress);
284 
294  Ipv6Address dst,
295  Address* hardwareAddress,
296  uint8_t flags);
297 
306  Ipv6Address dst,
307  Address hardwareAddress);
308 
319  Ipv6Address dst,
320  uint16_t id,
321  uint16_t seq,
322  Ptr<Packet> data);
323 
332  const Ipv4Header& header,
333  Ptr<Ipv4Interface> interface) override;
334 
343  const Ipv6Header& header,
344  Ptr<Ipv6Interface> interface) override;
345 
351  virtual void FunctionDadTimeout(Ipv6Interface* interface, Ipv6Address addr);
352 
364  virtual bool Lookup(Ipv6Address dst,
365  Ptr<NetDevice> device,
366  Ptr<NdiscCache> cache,
367  Address* hardwareDestination);
368 
381  virtual bool Lookup(Ptr<Packet> p,
382  const Ipv6Header& ipHeader,
383  Ipv6Address dst,
384  Ptr<NetDevice> device,
385  Ptr<NdiscCache> cache,
386  Address* hardwareDestination);
387 
394  void SendRS(Ipv6Address src, Ipv6Address dst, Address hardwareAddress);
395 
403 
408  bool IsAlwaysDad() const;
409 
418  int64_t AssignStreams(int64_t stream);
419 
424  Time GetDadTimeout() const;
425 
426  protected:
430  void DoDispose() override;
431 
432  typedef std::list<Ptr<NdiscCache>> CacheList;
433 
442  void Forward(Ipv6Address source,
443  Icmpv6Header icmp,
444  uint32_t info,
445  Ipv6Header ipHeader,
446  const uint8_t payload[8]);
447 
455  void HandleNS(Ptr<Packet> p,
456  const Ipv6Address& src,
457  const Ipv6Address& dst,
458  Ptr<Ipv6Interface> interface);
459 
467  void HandleRS(Ptr<Packet> p,
468  const Ipv6Address& src,
469  const Ipv6Address& dst,
470  Ptr<Ipv6Interface> interface);
471 
478  virtual void HandleRsTimeout(Ipv6Address src, Ipv6Address dst, Address hardwareAddress);
479 
487  void HandleRA(Ptr<Packet> p,
488  const Ipv6Address& src,
489  const Ipv6Address& dst,
490  Ptr<Ipv6Interface> interface);
491 
500  const Ipv6Address& src,
501  const Ipv6Address& dst,
502  Ptr<Ipv6Interface> interface);
503 
511  void HandleNA(Ptr<Packet> p,
512  const Ipv6Address& src,
513  const Ipv6Address& dst,
514  Ptr<Ipv6Interface> interface);
515 
524  const Ipv6Address& src,
525  const Ipv6Address& dst,
526  Ptr<Ipv6Interface> interface);
527 
536  const Ipv6Address& src,
537  const Ipv6Address& dst,
538  Ptr<Ipv6Interface> interface);
539 
548  const Ipv6Address& src,
549  const Ipv6Address& dst,
550  Ptr<Ipv6Interface> interface);
551 
560  const Ipv6Address& src,
561  const Ipv6Address& dst,
562  Ptr<Ipv6Interface> interface);
563 
572  const Ipv6Address& src,
573  const Ipv6Address& dst,
574  Ptr<Ipv6Interface> interface);
575 
584  const Ipv6Address& src,
585  const Ipv6Address& dst,
586  Ptr<Ipv6Interface> interface);
587 
594 
595  // From IpL4Protocol
598  // From IpL4Protocol
601 
606 
611 
616 
621 
626 
631 
636 
641 
648 
653 
658 
663 
668 
673 
678 
683 
688 
693 
698 
700 };
701 
702 } /* namespace ns3 */
703 
704 #endif /* ICMPV6_L4_PROTOCOL_H */
a polymophic address class
Definition: address.h:101
An identifier for simulation events.
Definition: event-id.h:55
ICMPv6 header.
Definition: icmpv6-header.h:38
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.
Time m_rsFirstTransmissionTime
First multicast RS transmissions [RFC 7559].
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].
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.
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.
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.
static const uint8_t PROT_NUMBER
ICMPv6 protocol number (58).
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.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
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.
std::list< Ptr< NdiscCache > > CacheList
container of NdiscCaches
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.
L4 Protocol abstract base class.
RxStatus
Rx status codes.
Packet header for IPv4.
Definition: ipv4-header.h:34
Describes an IPv6 address.
Definition: ipv6-address.h:49
Packet header for IPv6.
Definition: ipv6-header.h:35
The IPv6 representation of a network interface.
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv4 header.
Definition: ndisc-cache.h:159
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]