A Discrete-Event Network Simulator
API
ipv6-l3-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  */
19 
20 #ifndef IPV6_L3_PROTOCOL_H
21 #define IPV6_L3_PROTOCOL_H
22 
23 #include "ns3/ipv6-address.h"
24 #include "ns3/ipv6-header.h"
25 #include "ns3/ipv6-pmtu-cache.h"
26 #include "ns3/ipv6.h"
27 #include "ns3/net-device.h"
28 #include "ns3/traced-callback.h"
29 
30 #include <list>
31 
33 
34 namespace ns3
35 {
36 
37 class Node;
38 class Ipv6Interface;
39 class IpL4Protocol;
40 class Ipv6Route;
41 class Ipv6MulticastRoute;
42 class Ipv6RawSocketImpl;
43 class Icmpv6L4Protocol;
44 class Ipv6AutoconfiguredPrefix;
45 
61 class Ipv6L3Protocol : public Ipv6
62 {
63  public:
68  static TypeId GetTypeId();
69 
73  static const uint16_t PROT_NUMBER;
74 
80  {
89  };
90 
95 
99  ~Ipv6L3Protocol() override;
100 
101  // Delete copy constructor and assignment operator to avoid misuse
102  Ipv6L3Protocol(const Ipv6L3Protocol&) = delete;
104 
109  void SetNode(Ptr<Node> node);
110 
111  void Insert(Ptr<IpL4Protocol> protocol) override;
112  void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
113 
114  void Remove(Ptr<IpL4Protocol> protocol) override;
115  void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
116 
117  Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
118  Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
119 
125 
130  void DeleteRawSocket(Ptr<Socket> socket);
131 
136  void SetDefaultTtl(uint8_t ttl);
137 
142  void SetDefaultTclass(uint8_t tclass);
143 
155  void Receive(Ptr<NetDevice> device,
157  uint16_t protocol,
158  const Address& from,
159  const Address& to,
160  NetDevice::PacketType packetType);
161 
162  void Send(Ptr<Packet> packet,
163  Ipv6Address source,
164  Ipv6Address destination,
165  uint8_t protocol,
166  Ptr<Ipv6Route> route) override;
167 
172  void SetRoutingProtocol(Ptr<Ipv6RoutingProtocol> routingProtocol) override;
173 
179 
185  uint32_t AddInterface(Ptr<NetDevice> device) override;
186 
192  Ptr<Ipv6Interface> GetInterface(uint32_t i) const;
193 
198  uint32_t GetNInterfaces() const override;
199 
205  int32_t GetInterfaceForAddress(Ipv6Address addr) const override;
206 
213  int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const override;
214 
220  int32_t GetInterfaceForDevice(Ptr<const NetDevice> device) const override;
221 
229  bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute = true) override;
230 
237  Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
238 
244  uint32_t GetNAddresses(uint32_t interface) const override;
245 
252  bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
253 
260  bool RemoveAddress(uint32_t interfaceIndex, Ipv6Address address) override;
261 
267  void SetMetric(uint32_t i, uint16_t metric) override;
268 
274  uint16_t GetMetric(uint32_t i) const override;
275 
281  uint16_t GetMtu(uint32_t i) const override;
282 
288  void SetPmtu(Ipv6Address dst, uint32_t pmtu) override;
289 
295  bool IsUp(uint32_t i) const override;
296 
301  void SetUp(uint32_t i) override;
302 
307  void SetDown(uint32_t i) override;
308 
314  bool IsForwarding(uint32_t i) const override;
315 
321  void SetForwarding(uint32_t i, bool val) override;
322 
323  Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest) override;
324 
330  Ptr<NetDevice> GetNetDevice(uint32_t i) override;
331 
337 
348  void AddAutoconfiguredAddress(uint32_t interface,
349  Ipv6Address network,
350  Ipv6Prefix mask,
351  uint8_t flags,
352  uint32_t validTime,
353  uint32_t preferredTime,
354  Ipv6Address defaultRouter = Ipv6Address::GetZero());
355 
365  void RemoveAutoconfiguredAddress(uint32_t interface,
366  Ipv6Address network,
367  Ipv6Prefix mask,
368  Ipv6Address defaultRouter);
369 
373  void RegisterExtensions() override;
374 
378  void RegisterOptions() override;
379 
390  virtual void ReportDrop(Ipv6Header ipHeader, Ptr<Packet> p, DropReason dropReason);
391 
400  typedef void (*SentTracedCallback)(const Ipv6Header& header,
401  Ptr<const Packet> packet,
402  uint32_t interface);
403 
413  typedef void (*TxRxTracedCallback)(Ptr<const Packet> packet,
414  Ptr<Ipv6> ipv6,
415  uint32_t interface);
416 
428  typedef void (*DropTracedCallback)(const Ipv6Header& header,
429  Ptr<const Packet> packet,
430  DropReason reason,
431  Ptr<Ipv6> ipv6,
432  uint32_t interface);
433 
439 
445  void AddMulticastAddress(Ipv6Address address, uint32_t interface);
446 
452 
458  void RemoveMulticastAddress(Ipv6Address address, uint32_t interface);
459 
466 
473  bool IsRegisteredMulticastAddress(Ipv6Address address, uint32_t interface) const;
474 
492  bool ReachabilityHint(uint32_t ipInterfaceIndex, Ipv6Address address);
493 
494  protected:
498  void DoDispose() override;
499 
507  void NotifyNewAggregate() override;
508 
509  private:
514  friend class ::Ipv6L3ProtocolTestCase;
520 
524  typedef std::vector<Ptr<Ipv6Interface>> Ipv6InterfaceList;
525 
529  typedef std::map<Ptr<const NetDevice>, uint32_t> Ipv6InterfaceReverseContainer;
530 
534  typedef std::list<Ptr<Ipv6RawSocketImpl>> SocketList;
535 
539  typedef std::pair<int, int32_t> L4ListKey_t;
540 
544  typedef std::map<L4ListKey_t, Ptr<IpL4Protocol>> L4List_t;
545 
549  typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>> Ipv6AutoconfiguredPrefixList;
550 
554  typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>>::iterator Ipv6AutoconfiguredPrefixListI;
555 
566  void CallTxTrace(const Ipv6Header& ipHeader,
567  Ptr<Packet> packet,
568  Ptr<Ipv6> ipv6,
569  uint32_t interface);
570 
577 
584 
592 
599 
611  Ipv6Address dst,
612  uint8_t protocol,
613  uint16_t payloadSize,
614  uint8_t hopLimit,
615  uint8_t tclass);
616 
623  void SendRealOut(Ptr<Ipv6Route> route, Ptr<Packet> packet, const Ipv6Header& ipHeader);
624 
633  Ptr<Ipv6Route> rtentry,
635  const Ipv6Header& header);
636 
645  Ptr<Ipv6MulticastRoute> mrtentry,
647  const Ipv6Header& header);
648 
655  void LocalDeliver(Ptr<const Packet> p, const Ipv6Header& ip, uint32_t iif);
656 
664  const Ipv6Header& ipHeader,
665  Socket::SocketErrno sockErrno);
666 
672  uint32_t AddIpv6Interface(Ptr<Ipv6Interface> interface);
673 
677  void SetupLoopback();
678 
683  void SetIpForward(bool forward) override;
684 
689  bool GetIpForward() const override;
690 
695  void SetMtuDiscover(bool mtuDiscover) override;
696 
701  bool GetMtuDiscover() const override;
702 
707  virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect);
708 
713  virtual bool GetSendIcmpv6Redirect() const;
714 
719 
724 
729 
734 
739 
744 
749 
753  uint32_t m_nInterfaces;
754 
758  uint8_t m_defaultTtl;
759 
764 
769 
774 
779 
784 
789 
793  typedef std::pair<Ipv6Address, uint64_t> Ipv6RegisteredMulticastAddressKey_t;
794 
798  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>
800 
804  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::iterator
806 
810  typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::const_iterator
812 
816  typedef std::map<Ipv6Address, uint32_t> Ipv6RegisteredMulticastAddressNoInterface_t;
817 
821  typedef std::map<Ipv6Address, uint32_t>::iterator
823 
827  typedef std::map<Ipv6Address, uint32_t>::const_iterator
829 
834 
839 };
840 
841 } /* namespace ns3 */
842 
843 #endif /* IPV6_L3_PROTOCOL_H */
a polymophic address class
Definition: address.h:100
Describes an IPv6 address.
Definition: ipv6-address.h:50
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
IPv6 Extension Loose Routing.
Packet header for IPv6.
Definition: ipv6-header.h:36
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
IPv6 address associated with an interface.
IPv6 layer implementation.
bool GetIpForward() const override
Get IPv6 forwarding state.
Ptr< Ipv6PmtuCache > m_pmtuCache
Path MTU Cache.
void(* SentTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, uint32_t interface)
TracedCallback signature for packet sent, forwarded or local-delivered events.
void SetForwarding(uint32_t i, bool val) override
Enable or disable forwarding on interface.
void SetPmtu(Ipv6Address dst, uint32_t pmtu) override
Set the Path MTU for the specified IPv6 destination address.
std::map< L4ListKey_t, Ptr< IpL4Protocol > > L4List_t
Container of the IPv6 L4 instances.
void RegisterOptions() override
Register the IPv6 Options.
void RouteInputError(Ptr< const Packet > p, const Ipv6Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.
uint8_t m_defaultTclass
Default TCLASS for outgoing packets.
bool IsRegisteredMulticastAddress(Ipv6Address address) const
Checks if the address has been registered.
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const override
Get current routing protocol used.
bool GetMtuDiscover() const override
Get IPv6 MTU discover state.
bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute=true) override
Add an address on interface.
uint16_t GetMetric(uint32_t i) const override
Get metric for an interface.
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.
void SetUp(uint32_t i) override
Set an interface up.
std::list< Ptr< Ipv6AutoconfiguredPrefix > > Ipv6AutoconfiguredPrefixList
Container of the IPv6 Autoconfigured addresses.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
std::map< Ipv6Address, uint32_t > Ipv6RegisteredMulticastAddressNoInterface_t
Container of the IPv6 multicast addresses.
bool IsForwarding(uint32_t i) const override
Is interface allows forwarding ?
bool m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
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.
uint8_t m_defaultTtl
Default TTL for outgoing packets.
void SetMetric(uint32_t i, uint16_t metric) override
Set metric for an interface.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, DropReason, Ptr< Ipv6 >, uint32_t > m_dropTrace
Callback to trace drop packets.
std::vector< Ptr< Ipv6Interface > > Ipv6InterfaceList
Container of the IPv6 Interfaces.
DropReason
Reason why a packet has been dropped.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout.
@ DROP_ROUTE_ERROR
Route error.
@ DROP_TTL_EXPIRED
Packet TTL has expired.
@ DROP_INTERFACE_DOWN
Interface is down so can not send packet.
@ DROP_UNKNOWN_OPTION
Unknown option.
@ DROP_NO_ROUTE
No route to host.
@ DROP_UNKNOWN_PROTOCOL
Unknown L4 protocol.
@ DROP_MALFORMED_HEADER
Malformed header.
uint32_t GetNAddresses(uint32_t interface) const override
Get number of address for an interface.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
Get interface index which is on a specified net device.
void RegisterExtensions() override
Register the IPv6 Extensions.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
bool m_ipForward
Forwarding packets (i.e.
Ipv6AutoconfiguredPrefixList m_prefixes
List of IPv6 prefix received from RA.
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.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t > Ipv6RegisteredMulticastAddress_t
Container of the IPv6 multicast addresses.
Ipv6InterfaceList m_interfaces
List of IPv6 interfaces.
std::list< Ptr< Ipv6AutoconfiguredPrefix > >::iterator Ipv6AutoconfiguredPrefixListI
Iterator of the container of the IPv6 Autoconfigured addresses.
void Remove(Ptr< IpL4Protocol > protocol) override
Remove a L4 protocol.
Ipv6RegisteredMulticastAddressNoInterface_t m_multicastAddressesNoInterface
List of multicast IP addresses of interest for all the interfaces.
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override
Get an address.
SocketList m_sockets
List of IPv6 raw sockets.
Ipv6Header BuildHeader(Ipv6Address src, Ipv6Address dst, uint8_t protocol, uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass)
Construct an IPv6 header.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest) override
Choose the source address to use with destination address.
Ptr< Node > m_node
Node attached to stack.
virtual bool GetSendIcmpv6Redirect() const
Get the ICMPv6 Redirect sending state.
L4List_t m_protocols
List of transport protocol.
Ptr< Ipv6Interface > GetInterface(uint32_t i) const
Get an interface.
void(* DropTracedCallback)(const Ipv6Header &header, Ptr< const Packet > packet, DropReason reason, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet drop events.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
uint32_t m_nInterfaces
Number of IPv6 interfaces managed by the stack.
std::map< Ipv6Address, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t
Container Const Iterator of the IPv6 multicast addresses.
void AddMulticastAddress(Ipv6Address address)
Adds a multicast address to the list of addresses to pass to local deliver.
virtual void ReportDrop(Ipv6Header ipHeader, Ptr< Packet > p, DropReason dropReason)
Report a packet drop.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressCIter_t
Container Const Iterator of the IPv6 multicast addresses.
void Send(Ptr< Packet > packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr< Ipv6Route > route) override
Higher-level layers call this method to send a packet down the stack to the MAC and PHY layers.
void SetupLoopback()
Setup loopback interface.
Ipv6L3Protocol(const Ipv6L3Protocol &)=delete
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
Get L4 protocol by protocol number.
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
Ipv6RegisteredMulticastAddress_t m_multicastAddresses
List of multicast IP addresses of interest, divided per interface.
void RemoveAutoconfiguredAddress(uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter)
Remove an autoconfigured address.
uint16_t GetMtu(uint32_t i) const override
Get MTU for an interface.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
void Insert(Ptr< IpL4Protocol > protocol) override
Add a L4 protocol.
bool m_mtuDiscover
MTU Discover (i.e.
void SetDefaultTtl(uint8_t ttl)
Set the default TTL.
uint32_t AddInterface(Ptr< NetDevice > device) override
Add IPv6 interface for a device.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove an address from an interface.
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.
std::map< Ptr< const NetDevice >, uint32_t > Ipv6InterfaceReverseContainer
Container of NetDevices registered to IPv6 and their interface indexes.
Ptr< NetDevice > GetNetDevice(uint32_t i) override
Get device by index.
void RemoveMulticastAddress(Ipv6Address address)
Removes a multicast address from the list of addresses to pass to local deliver.
void SetDown(uint32_t i) override
set an interface down.
void DoDispose() override
Dispose object.
uint32_t AddIpv6Interface(Ptr< Ipv6Interface > interface)
Add an IPv6 interface to the stack.
Ptr< Ipv6RoutingProtocol > m_routingProtocol
Routing protocol.
virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect)
Set the ICMPv6 Redirect sending state.
void NotifyNewAggregate() override
Notify other components connected to the node that a new stack member is now connected.
void IpMulticastForward(Ptr< const NetDevice > idev, Ptr< Ipv6MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a multicast packet.
~Ipv6L3Protocol() override
Destructor.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::iterator Ipv6RegisteredMulticastAddressIter_t
Container Iterator of the IPv6 multicast addresses.
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
std::list< Ptr< Ipv6RawSocketImpl > > SocketList
Container of the IPv6 Raw Sockets.
Ipv6InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
void SendRealOut(Ptr< Ipv6Route > route, Ptr< Packet > packet, const Ipv6Header &ipHeader)
Send packet with route.
bool m_strongEndSystemModel
Rejects packets directed to an interface with wrong address (RFC 1222).
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const override
Get interface index which match specified address/prefix.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
void SetDefaultTclass(uint8_t tclass)
Set the default TCLASS.
void IpForward(Ptr< const NetDevice > idev, Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet.
uint32_t GetNInterfaces() const override
Get current number of interface on this stack.
bool IsUp(uint32_t i) const override
Is specified interface up ?
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol) override
Set routing protocol for this stack.
Ipv6L3Protocol & operator=(const Ipv6L3Protocol &)=delete
std::pair< Ipv6Address, uint64_t > Ipv6RegisteredMulticastAddressKey_t
IPv6 multicast addresses / interface key.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv6 L4 keys: protocol number, interface index.
int32_t GetInterfaceForAddress(Ipv6Address addr) const override
Get interface index which has specified IPv6 address.
std::map< Ipv6Address, uint32_t >::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t
Container Iterator of the IPv6 multicast addresses.
Ipv6L3Protocol()
Constructor.
void SetIpForward(bool forward) override
Set IPv6 forwarding state.
void LocalDeliver(Ptr< const Packet > p, const Ipv6Header &ip, uint32_t iif)
Deliver a packet.
static TypeId GetTypeId()
Get the type ID of this class.
void SetMtuDiscover(bool mtuDiscover) override
Set IPv6 MTU discover state.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:84
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:60
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.