A Discrete-Event Network Simulator
API
ipv6-l3-protocol.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
19  */
20 
21 #ifndef IPV6_L3_PROTOCOL_H
22 #define IPV6_L3_PROTOCOL_H
23 
24 #include <list>
25 
26 #include "ns3/traced-callback.h"
27 #include "ns3/net-device.h"
28 #include "ns3/ipv6.h"
29 #include "ns3/ipv6-address.h"
30 #include "ns3/ipv6-header.h"
31 #include "ns3/ipv6-pmtu-cache.h"
32 
34 
35 namespace ns3
36 {
37 
38 class Node;
39 class Ipv6Interface;
40 class IpL4Protocol;
41 class Ipv6Route;
42 class Ipv6MulticastRoute;
43 class Ipv6RawSocketImpl;
44 class Icmpv6L4Protocol;
45 class Ipv6AutoconfiguredPrefix;
46 
62 class Ipv6L3Protocol : public Ipv6
63 {
64 public:
69  static TypeId GetTypeId ();
70 
74  static const uint16_t PROT_NUMBER;
75 
80  enum DropReason
81  {
90  };
91 
95  Ipv6L3Protocol ();
96 
100  virtual ~Ipv6L3Protocol ();
101 
106  void SetNode (Ptr<Node> node);
107 
108  virtual void Insert (Ptr<IpL4Protocol> protocol);
109  virtual void Insert (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
110 
111  virtual void Remove (Ptr<IpL4Protocol> protocol);
112  virtual void Remove (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
113 
114  virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
115  virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber, int32_t interfaceIndex) const;
116 
122 
127  void DeleteRawSocket (Ptr<Socket> socket);
128 
133  void SetDefaultTtl (uint8_t ttl);
134 
139  void SetDefaultTclass (uint8_t tclass);
140 
152  void Receive (Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType);
153 
154  virtual void Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route);
155 
160  void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol);
161 
167 
173  uint32_t AddInterface (Ptr<NetDevice> device);
174 
180  Ptr<Ipv6Interface> GetInterface (uint32_t i) const;
181 
186  uint32_t GetNInterfaces () const;
187 
193  int32_t GetInterfaceForAddress (Ipv6Address addr) const;
194 
201  int32_t GetInterfaceForPrefix (Ipv6Address addr, Ipv6Prefix mask) const;
202 
208  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
209 
217  bool AddAddress (uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute = true);
218 
225  Ipv6InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
226 
232  uint32_t GetNAddresses (uint32_t interface) const;
233 
240  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
241 
248  bool RemoveAddress (uint32_t interfaceIndex, Ipv6Address address);
249 
255  void SetMetric (uint32_t i, uint16_t metric);
256 
262  uint16_t GetMetric (uint32_t i) const;
263 
269  uint16_t GetMtu (uint32_t i) const;
270 
276  virtual void SetPmtu (Ipv6Address dst, uint32_t pmtu);
277 
283  bool IsUp (uint32_t i) const;
284 
289  void SetUp (uint32_t i);
290 
295  void SetDown (uint32_t i);
296 
302  bool IsForwarding (uint32_t i) const;
303 
309  void SetForwarding (uint32_t i, bool val);
310 
311  Ipv6Address SourceAddressSelection (uint32_t interface, Ipv6Address dest);
312 
318  Ptr<NetDevice> GetNetDevice (uint32_t i);
319 
325 
336  void AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter = Ipv6Address::GetZero ());
337 
347  void RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter);
348 
352  virtual void RegisterExtensions ();
353 
357  virtual void RegisterOptions ();
358 
369  virtual void ReportDrop (Ipv6Header ipHeader, Ptr<Packet> p, DropReason dropReason);
370 
379  typedef void (* SentTracedCallback)
380  (const Ipv6Header & header, Ptr<const Packet> packet, uint32_t interface);
381 
392  typedef void (* TxRxTracedCallback)
393  (Ptr<const Packet> packet, Ptr<Ipv6> ipv6, uint32_t interface);
394 
406  typedef void (* DropTracedCallback)
407  (const Ipv6Header & header, Ptr<const Packet> packet,
408  DropReason reason, Ptr<Ipv6> ipv6,
409  uint32_t interface);
410 
416 
422  void AddMulticastAddress (Ipv6Address address, uint32_t interface);
423 
429 
435  void RemoveMulticastAddress (Ipv6Address address, uint32_t interface);
436 
443 
450  bool IsRegisteredMulticastAddress (Ipv6Address address, uint32_t interface) const;
451 
469  bool ReachabilityHint (uint32_t ipInterfaceIndex, Ipv6Address address);
470 
471 protected:
475  virtual void DoDispose ();
476 
482  virtual void NotifyNewAggregate ();
483 
484 private:
489  friend class ::Ipv6L3ProtocolTestCase;
495 
499  typedef std::vector<Ptr<Ipv6Interface> > Ipv6InterfaceList;
500 
504  typedef std::map<Ptr<const NetDevice>, uint32_t > Ipv6InterfaceReverseContainer;
505 
509  typedef std::list<Ptr<Ipv6RawSocketImpl> > SocketList;
510 
514  typedef std::pair<int, int32_t> L4ListKey_t;
515 
519  typedef std::map<L4ListKey_t, Ptr<IpL4Protocol> > L4List_t;
520 
524  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> > Ipv6AutoconfiguredPrefixList;
525 
529  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> >::iterator Ipv6AutoconfiguredPrefixListI;
530 
541  void CallTxTrace (const Ipv6Header & ipHeader, Ptr<Packet> packet, Ptr<Ipv6> ipv6, uint32_t interface);
542 
549 
556 
563 
570 
577 
585 
596  Ipv6Header BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol,
597  uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass);
598 
605  void SendRealOut (Ptr<Ipv6Route> route, Ptr<Packet> packet, Ipv6Header const& ipHeader);
606 
614  void IpForward (Ptr<const NetDevice> idev, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
615 
624 
631  void LocalDeliver (Ptr<const Packet> p, Ipv6Header const& ip, uint32_t iif);
632 
639  void RouteInputError (Ptr<const Packet> p, const Ipv6Header& ipHeader, Socket::SocketErrno sockErrno);
640 
646  uint32_t AddIpv6Interface (Ptr<Ipv6Interface> interface);
647 
651  void SetupLoopback ();
652 
657  virtual void SetIpForward (bool forward);
658 
663  virtual bool GetIpForward () const;
664 
669  virtual void SetMtuDiscover (bool mtuDiscover);
670 
675  virtual bool GetMtuDiscover (void) const;
676 
681  virtual void SetSendIcmpv6Redirect (bool sendIcmpv6Redirect);
682 
687  virtual bool GetSendIcmpv6Redirect () const;
688 
693 
698 
703 
708 
713 
718 
723 
727  uint32_t m_nInterfaces;
728 
732  uint8_t m_defaultTtl;
733 
738 
743 
748 
753 
758 
763 
767  typedef std::pair<Ipv6Address, uint64_t> Ipv6RegisteredMulticastAddressKey_t;
768 
772  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t> Ipv6RegisteredMulticastAddress_t;
773 
777  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::iterator Ipv6RegisteredMulticastAddressIter_t;
778 
782  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::const_iterator Ipv6RegisteredMulticastAddressCIter_t;
783 
787  typedef std::map<Ipv6Address, uint32_t> Ipv6RegisteredMulticastAddressNoInterface_t;
788 
792  typedef std::map<Ipv6Address, uint32_t>::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t;
793 
797  typedef std::map<Ipv6Address, uint32_t>::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t;
798 
803 
808 };
809 
810 } /* namespace ns3 */
811 
812 #endif /* IPV6_L3_PROTOCOL_H */
813 
uint16_t GetMtu(uint32_t i) const
Get MTU for an interface.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv6 L4 keys: protocol number, interface index.
std::map< Ptr< const NetDevice >, uint32_t > Ipv6InterfaceReverseContainer
Container of NetDevices registered to IPv6 and their interface indexes.
Ipv6Header BuildHeader(Ipv6Address src, Ipv6Address dst, uint8_t protocol, uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass)
Construct an IPv6 header.
void SetForwarding(uint32_t i, bool val)
Enable or disable forwarding on interface.
Packet header for IPv6.
Definition: ipv6-header.h:34
std::map< L4ListKey_t, Ptr< IpL4Protocol > > L4List_t
Container of the IPv6 L4 instances.
uint16_t GetMetric(uint32_t i) const
Get metric for an interface.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressCIter_t
Container Const Iterator of the IPv6 multicast addresses.
virtual ~Ipv6L3Protocol()
Destructor.
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const
Get current routing protocol used.
Ipv6L3Protocol()
Constructor.
virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu)
Set the Path MTU for the specified IPv6 destination address.
bool IsUp(uint32_t i) const
Is specified interface up ?
Ptr< NetDevice > GetNetDevice(uint32_t i)
Get device by index.
Ptr< Ipv6RoutingProtocol > m_routingProtocol
Routing protocol.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
bool IsRegisteredMulticastAddress(Ipv6Address address) const
Checks if the address has been registered.
std::map< Ipv6Address, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t
Container Const Iterator of the IPv6 multicast addresses.
uint32_t AddIpv6Interface(Ptr< Ipv6Interface > interface)
Add an IPv6 interface to the stack.
virtual void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route)
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers...
IPv6 layer implementation.
Forward calls to a chain of Callback.
Interface is down so can not send packet.
IPv6 address associated with an interface.
std::list< Ptr< Ipv6RawSocketImpl > > SocketList
Container of the IPv6 Raw Sockets.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive method when a packet arrive in the stack.
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const
Get interface index which match specified address/prefix.
Ptr< Ipv6Interface > GetInterface(uint32_t i) const
Get an interface.
virtual void DoDispose()
Dispose object.
void SetMetric(uint32_t i, uint16_t metric)
Set metric for an interface.
uint32_t AddInterface(Ptr< NetDevice > device)
Add IPv6 interface for a device.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Ptr< Node > m_node
Node attached to stack.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
std::pair< Ipv6Address, uint64_t > Ipv6RegisteredMulticastAddressKey_t
IPv6 multicast addresses / interface key.
void CallTxTrace(const Ipv6Header &ipHeader, Ptr< Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
Make a copy of the packet, add the header and invoke the TX trace callback.
void AddMulticastAddress(Ipv6Address address)
Adds a multicast address to the list of addresses to pass to local deliver.
a polymophic address class
Definition: address.h:90
virtual void SetIpForward(bool forward)
Set IPv6 forwarding state.
virtual void NotifyNewAggregate()
Notify other components connected to the node that a new stack member is now connected.
Ptr< Icmpv6L4Protocol > GetIcmpv6() const
Get ICMPv6 protocol.
bool ReachabilityHint(uint32_t ipInterfaceIndex, Ipv6Address address)
Provides reachability hint for Neighbor Cache Entries from L4-L7 protocols.
uint32_t m_nInterfaces
Number of IPv6 interfaces managed by the stack.
void SetDefaultTclass(uint8_t tclass)
Set the default TCLASS.
bool m_strongEndSystemModel
Rejects packets directed to an interface with wrong address (RFC 1222).
virtual bool GetSendIcmpv6Redirect() const
Get the ICMPv6 Redirect sending state.
void(* DropTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet drop events.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Get L4 protocol by protocol number.
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
L4List_t m_protocols
List of transport protocol.
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Get an address.
void SetDefaultTtl(uint8_t ttl)
Set the default TTL.
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
void IpMulticastForward(Ptr< const NetDevice > idev, Ptr< Ipv6MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a multicast packet.
void RemoveMulticastAddress(Ipv6Address address)
Removes a multicast address from the list of addresses to pass to local deliver.
std::map< Ipv6Address, uint32_t > Ipv6RegisteredMulticastAddressNoInterface_t
Container of the IPv6 multicast addresses.
void SetUp(uint32_t i)
Set an interface up.
virtual void ReportDrop(Ipv6Header ipHeader, Ptr< Packet > p, DropReason dropReason)
Report a packet drop.
std::list< Ptr< Ipv6AutoconfiguredPrefix > > Ipv6AutoconfiguredPrefixList
Container of the IPv6 Autoconfigured addresses.
static TypeId GetTypeId()
Get the type ID of this class.
Ipv6InterfaceList m_interfaces
List of IPv6 interfaces.
bool m_ipForward
Forwarding packets (i.e.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
std::list< Ptr< Ipv6AutoconfiguredPrefix > >::iterator Ipv6AutoconfiguredPrefixListI
Iterator of the container of the IPv6 Autoconfigured addresses.
Ipv6RegisteredMulticastAddress_t m_multicastAddresses
List of multicast IP addresses of interest, divided per interface.
Ipv6AutoconfiguredPrefixList m_prefixes
List of IPv6 prefix received from RA.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LocalDeliver(Ptr< const Packet > p, Ipv6Header const &ip, uint32_t iif)
Deliver a packet.
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
address
Definition: first.py:44
Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)
Choose the source address to use with destination address.
void IpForward(Ptr< const NetDevice > idev, Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet.
uint8_t m_defaultTtl
Default TTL for outgoing packets.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, DropReason, Ptr< Ipv6 >, uint32_t > m_dropTrace
Callback to trace drop packets.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t > Ipv6RegisteredMulticastAddress_t
Container of the IPv6 multicast addresses.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
std::map< Ipv6Address, uint32_t >::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t
Container Iterator of the IPv6 multicast addresses.
Ipv6InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
IPv6 Extension Loose Routing.
uint32_t GetNInterfaces() const
Get current number of interface on this stack.
void(* SentTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, uint32_t interface)
TracedCallback signature for packet sent, forwarded or local-delivered events.
void RemoveAutoconfiguredAddress(uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter)
Remove an autoconfigured address.
void SendRealOut(Ptr< Ipv6Route > route, Ptr< Packet > packet, Ipv6Header const &ipHeader)
Send packet with route.
void SetupLoopback()
Setup loopback interface.
Ipv6L3Protocol & operator=(const Ipv6L3Protocol &)
Copy constructor.
virtual void RegisterExtensions()
Register the IPv6 Extensions.
virtual bool GetMtuDiscover(void) const
Get IPv6 MTU discover state.
Describes an IPv6 address.
Definition: ipv6-address.h:49
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
bool IsForwarding(uint32_t i) const
Is interface allows forwarding ?
virtual void Insert(Ptr< IpL4Protocol > protocol)
Add a L4 protocol.
Ipv6RegisteredMulticastAddressNoInterface_t m_multicastAddressesNoInterface
List of multicast IP addresses of interest for all the interfaces.
virtual bool GetIpForward() const
Get IPv6 forwarding state.
std::vector< Ptr< Ipv6Interface > > Ipv6InterfaceList
Container of the IPv6 Interfaces.
bool m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)
Add an address on interface.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Get interface index which is on a specified net device.
virtual void RegisterOptions()
Register the IPv6 Options.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
Describes an IPv6 prefix.
Definition: ipv6-address.h:466
void SetDown(uint32_t i)
set an interface down.
uint32_t GetNAddresses(uint32_t interface) const
Get number of address for an interface.
bool m_mtuDiscover
MTU Discover (i.e.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove an address from an interface.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
Ptr< Ipv6PmtuCache > m_pmtuCache
Path MTU Cache.
int32_t GetInterfaceForAddress(Ipv6Address addr) const
Get interface index which has specified IPv6 address.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
virtual void SetMtuDiscover(bool mtuDiscover)
Set IPv6 MTU discover state.
uint8_t m_defaultTclass
Default TCLASS for outgoing packets.
a unique identifier for an interface.
Definition: type-id.h:58
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::iterator Ipv6RegisteredMulticastAddressIter_t
Container Iterator of the IPv6 multicast addresses.
SocketList m_sockets
List of IPv6 raw sockets.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
virtual void Remove(Ptr< IpL4Protocol > protocol)
Remove a L4 protocol.
void AddAutoconfiguredAddress(uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter=Ipv6Address::GetZero())
Add an autoconfigured address with RA information.
DropReason
Reason why a packet has been dropped.
virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect)
Set the ICMPv6 Redirect sending state.
void RouteInputError(Ptr< const Packet > p, const Ipv6Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.