A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
icmpv6-l4-protocol.h
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  * David Gross <gdavid.devel@gmail.com>
20  * Mehdi Benamor <benamor.mehdi@ensi.rnu.tn>
21  */
22 
23 #ifndef ICMPV6_L4_PROTOCOL_H
24 #define ICMPV6_L4_PROTOCOL_H
25 
26 #include <list>
27 
28 #include "ns3/ipv6-address.h"
29 #include "icmpv6-header.h"
30 #include "ip-l4-protocol.h"
31 
32 namespace ns3 {
33 
34 class NetDevice;
35 class Node;
36 class Packet;
37 class TraceContext;
38 class NdiscCache;
39 
45 {
46 public:
50  static TypeId GetTypeId ();
51 
55  static const uint8_t PROT_NUMBER;
56 
60  static const uint8_t MAX_INITIAL_RTR_ADVERT_INTERVAL;
61 
65  static const uint8_t MAX_INITIAL_RTR_ADVERTISEMENTS;
66 
70  static const uint8_t MAX_FINAL_RTR_ADVERTISEMENTS;
71 
75  static const uint8_t MIN_DELAY_BETWEEN_RAS;
76 
80  static const uint32_t MAX_RA_DELAY_TIME;
81 
85  static const uint8_t MAX_RTR_SOLICITATION_DELAY;
86 
90  static const uint8_t RTR_SOLICITATION_INTERVAL;
91 
95  static const uint8_t MAX_RTR_SOLICITATIONS;
96 
100  static const uint8_t MAX_MULTICAST_SOLICIT;
101 
105  static const uint8_t MAX_UNICAST_SOLICIT;
106 
110  static const uint8_t MAX_ANYCAST_DELAY_TIME;
111 
115  static const uint8_t MAX_NEIGHBOR_ADVERTISEMENT;
116 
120  static const uint32_t REACHABLE_TIME;
121 
125  static const uint32_t RETRANS_TIMER;
126 
130  static const uint8_t DELAY_FIRST_PROBE_TIME;
131 
135  static const double MIN_RANDOM_FACTOR;
136 
140  static const double MAX_RANDOM_FACTOR;
141 
146  static uint16_t GetStaticProtocolNumber ();
147 
151  Icmpv6L4Protocol ();
152 
156  virtual ~Icmpv6L4Protocol ();
157 
162  void SetNode (Ptr<Node> node);
163 
169  void NotifyNewAggregate ();
170 
175  virtual int GetProtocolNumber () const;
176 
181  virtual int GetVersion () const;
182 
190  void SendMessage (Ptr<Packet> packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl);
191 
200  void SendMessage (Ptr<Packet> packet, Ipv6Address dst, Icmpv6Header& icmpv6Hdr, uint8_t ttl);
201 
211  void DoDAD (Ipv6Address target, Ptr<Ipv6Interface> interface);
212 
220  void SendNA (Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags);
221 
230  void SendEchoReply (Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr<Packet> data);
231 
239  void SendNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress);
240 
247  void SendErrorDestinationUnreachable (Ptr<Packet> malformedPacket, Ipv6Address dst, uint8_t code);
248 
255  void SendErrorTooBig (Ptr<Packet> malformedPacket, Ipv6Address dst, uint32_t mtu);
256 
263  void SendErrorTimeExceeded (Ptr<Packet> malformedPacket, Ipv6Address dst, uint8_t code);
264 
272  void SendErrorParameterError (Ptr<Packet> malformedPacket, Ipv6Address dst, uint8_t code, uint32_t ptr);
273 
282  void SendRedirection (Ptr<Packet> redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget);
283 
292  Ptr<Packet> ForgeNS (Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress);
293 
302  Ptr<Packet> ForgeNA (Ipv6Address src, Ipv6Address dst, Address* hardwareAddress, uint8_t flags);
303 
311  Ptr<Packet> ForgeRS (Ipv6Address src, Ipv6Address dst, Address hardwareAddress);
312 
322  Ptr<Packet> ForgeEchoRequest (Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr<Packet> data);
323 
330  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
331  Ipv4Header const &header,
332  Ptr<Ipv4Interface> interface);
333 
341  virtual enum IpL4Protocol::RxStatus Receive (Ptr<Packet> p,
342  Ipv6Header const &header,
343  Ptr<Ipv6Interface> interface);
344 
351  static void FunctionDadTimeout (Ptr<Icmpv6L4Protocol> icmpv6, Ipv6Interface* interface, Ipv6Address addr);
352 
361  bool Lookup (Ipv6Address dst, Ptr<NetDevice> device, Ptr<NdiscCache> cache, Address* hardwareDestination);
362 
374  bool Lookup (Ptr<Packet> p, Ipv6Address dst, Ptr<NetDevice> device, Ptr<NdiscCache> cache, Address* hardwareDestination);
375 
382  void SendRS (Ipv6Address src, Ipv6Address dst, Address hardwareAddress);
383 
391 
396  bool IsAlwaysDad () const;
397 
398 protected:
402  virtual void DoDispose ();
403 
404 private:
405  typedef std::list<Ptr<NdiscCache> > CacheList;
406 
411 
415  CacheList m_cacheList;
416 
421 
430  void Forward (Ipv6Address source, Icmpv6Header icmp,
431  uint32_t info, Ipv6Header ipHeader,
432  const uint8_t payload[8]);
433 
441  void HandleNS (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
442 
450  void HandleRS (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
451 
459  void HandleRA (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
460 
468  void HandleEchoRequest (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
469 
477  void HandleNA (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
478 
486  void HandleRedirection (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
487 
495  void HandleDestinationUnreachable (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
496 
504  void HandleTimeExceeded (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
505 
513  void HandlePacketTooBig (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
514 
522  void HandleParameterError (Ptr<Packet> p, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
523 
531  void ReceiveLLA (Icmpv6OptionLinkLayerAddress lla, Ipv6Address const &src, Ipv6Address const &dst, Ptr<Ipv6Interface> interface);
532 
538 
539  // From IpL4Protocol
541  virtual void SetDownTarget6 (IpL4Protocol::DownTargetCallback6 cb);
542  // From IpL4Protocol
543  virtual IpL4Protocol::DownTargetCallback GetDownTarget (void) const;
544  virtual IpL4Protocol::DownTargetCallback6 GetDownTarget6 (void) const;
545 
547 
548 };
549 
550 } /* namespace ns3 */
551 
552 #endif /* ICMPV6_L4_PROTOCOL_H */
553 
static const uint8_t MAX_ANYCAST_DELAY_TIME
Neighbor Discovery node constants : max anycast delay.
Packet header for IPv6.
Definition: ipv6-header.h:33
bool Lookup(Ipv6Address dst, Ptr< NetDevice > device, Ptr< NdiscCache > cache, Address *hardwareDestination)
Lookup in the ND cache for the IPv6 address.
void SendNA(Ipv6Address src, Ipv6Address dst, Address *hardwareAddress, uint8_t flags)
Send a Neighbor Adverstisement.
void HandleNS(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Neighbor Solicitation method.
static const uint8_t MAX_INITIAL_RTR_ADVERTISEMENTS
Neighbor Discovery router constants : max initial RA transmission.
static const uint8_t MAX_FINAL_RTR_ADVERTISEMENTS
Neighbor Discovery router constants : max final RA transmission.
Ptr< Node > m_node
The node.
void SendRS(Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Send a Router Solicitation.
static const uint8_t PROT_NUMBER
ICMPv6 protocol number (58).
virtual ~Icmpv6L4Protocol()
Destructor.
static const uint8_t RTR_SOLICITATION_INTERVAL
Neighbor Discovery host constants : RS interval.
static const uint8_t MAX_RTR_SOLICITATIONS
Neighbor Discovery host constants : max RS transmission.
void SetNode(Ptr< Node > node)
Set the node.
virtual int GetProtocolNumber() const
Get the protocol number.
Icmpv6L4Protocol()
Constructor.
a polymophic address class
Definition: address.h:86
static void FunctionDadTimeout(Ptr< Icmpv6L4Protocol > icmpv6, Ipv6Interface *interface, Ipv6Address addr)
Function called when DAD timeout.
virtual enum IpL4Protocol::RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > interface)
Receive method.
void SendRedirection(Ptr< Packet > redirectedPacket, Ipv6Address dst, Ipv6Address redirTarget, Ipv6Address redirDestination, Address redirHardwareTarget)
Send an ICMPv6 Redirection.
void SendErrorTooBig(Ptr< Packet > malformedPacket, Ipv6Address dst, uint32_t mtu)
Send an error Too Big.
void NotifyNewAggregate()
This method is called by AddAgregate and completes the aggregation by setting the node in the ICMPv6 ...
Packet header for IPv4.
Definition: ipv4-header.h:31
The IPv6 representation of a network interface.
void HandleRedirection(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Redirection method.
ICMPv6 header.
Definition: icmpv6-header.h:37
static const uint32_t MAX_RA_DELAY_TIME
Neighbor Discovery router constants : max delay between RA.
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 SendErrorParameterError(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code, uint32_t ptr)
Send an error Parameter Error.
void HandleTimeExceeded(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Time Exceeded method.
void SendErrorTimeExceeded(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code)
Send an error Time Exceeded.
bool IsAlwaysDad() const
Is the node must do DAD.
static const uint32_t REACHABLE_TIME
Neighbor Discovery node constants : reachable time.
static const double MIN_RANDOM_FACTOR
Neighbor Discovery node constants : min random factor.
An implementation of the ICMPv6 protocol.
Ptr< NdiscCache > FindCache(Ptr< NetDevice > device)
Get the cache corresponding to the device.
Ptr< Packet > ForgeNA(Ipv6Address src, Ipv6Address dst, Address *hardwareAddress, uint8_t flags)
Forge a Neighbor Advertisement.
void HandleRS(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Router Solicitation method.
Ptr< Packet > ForgeNS(Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress)
Forge a Neighbor Solicitation.
void HandleEchoRequest(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Echo Request method.
void HandleParameterError(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Parameter Error method.
static const uint8_t MAX_MULTICAST_SOLICIT
Neighbor Discovery node constants : max multicast solicitations.
void SendErrorDestinationUnreachable(Ptr< Packet > malformedPacket, Ipv6Address dst, uint8_t code)
Send an error Destination Unreachable.
void SendEchoReply(Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr< Packet > data)
Send a Echo Reply.
static TypeId GetTypeId()
Interface ID.
static const uint8_t MAX_NEIGHBOR_ADVERTISEMENT
Neighbor Discovery node constants : max NA transmission.
virtual IpL4Protocol::DownTargetCallback GetDownTarget(void) const
static uint16_t GetStaticProtocolNumber()
Get ICMPv6 protocol number.
static const uint8_t MAX_INITIAL_RTR_ADVERT_INTERVAL
Neighbor Discovery router constants : max initial RA initial interval.
bool m_alwaysDad
Always do DAD ?
L4 Protocol abstract base class.
void SendMessage(Ptr< Packet > packet, Ipv6Address src, Ipv6Address dst, uint8_t ttl)
Send a packet via ICMPv6, note that packet already contains ICMPv6 header.
virtual void SetDownTarget(IpL4Protocol::DownTargetCallback cb)
Ptr< Packet > ForgeRS(Ipv6Address src, Ipv6Address dst, Address hardwareAddress)
Forge a Router Solicitation.
static const uint8_t MIN_DELAY_BETWEEN_RAS
Neighbor Discovery router constants : min delay between RA.
static const double MAX_RANDOM_FACTOR
Neighbor Discovery node constants : max random factor.
CacheList m_cacheList
A list of cache by device.
void DoDAD(Ipv6Address target, Ptr< Ipv6Interface > interface)
Do the Duplication Address Detection (DAD). It consists in sending a NS with our IPv6 as target...
Describes an IPv6 address.
Definition: ipv6-address.h:44
void HandleRA(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Router Advertisement method.
void ReceiveLLA(Icmpv6OptionLinkLayerAddress lla, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Link layer address option processing.
virtual int GetVersion() const
Get the version of the protocol.
static const uint32_t RETRANS_TIMER
Neighbor Discovery node constants : retransmission timer.
Ptr< Packet > ForgeEchoRequest(Ipv6Address src, Ipv6Address dst, uint16_t id, uint16_t seq, Ptr< Packet > data)
Forge an Echo Request.
virtual void DoDispose()
Dispose this object.
static const uint8_t MAX_RTR_SOLICITATION_DELAY
Neighbor Discovery host constants : max RS delay.
void HandleNA(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Neighbor Advertisement method.
static const uint8_t DELAY_FIRST_PROBE_TIME
Neighbor Discovery node constants : delay for the first probe.
void HandlePacketTooBig(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Packet Too Big method.
a unique identifier for an interface.
Definition: type-id.h:44
void SendNS(Ipv6Address src, Ipv6Address dst, Ipv6Address target, Address hardwareAddress)
Send a Neighbor Solicitation.
Ptr< NdiscCache > CreateCache(Ptr< NetDevice > device, Ptr< Ipv6Interface > interface)
Create a neighbor cache.
void HandleDestinationUnreachable(Ptr< Packet > p, Ipv6Address const &src, Ipv6Address const &dst, Ptr< Ipv6Interface > interface)
Receive Destination Unreachable method.
static const uint8_t MAX_UNICAST_SOLICIT
Neighbor Discovery node constants : max unicast solicitations.