A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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-routing-protocol.h"
27#include "ns3/ipv6.h"
28#include "ns3/net-device.h"
29#include "ns3/traced-callback.h"
30
31#include <list>
32
34
35namespace ns3
36{
37
38class Node;
39class Ipv6Interface;
40class IpL4Protocol;
41class Ipv6Route;
42class Ipv6MulticastRoute;
43class Ipv6RawSocketImpl;
44class Icmpv6L4Protocol;
45class Ipv6AutoconfiguredPrefix;
46
62class Ipv6L3Protocol : public Ipv6
63{
64 public:
69 static TypeId GetTypeId();
70
74 static const uint16_t PROT_NUMBER;
75
81 {
90 };
91
96
100 ~Ipv6L3Protocol() override;
101
102 // Delete copy constructor and assignment operator to avoid misuse
105
110 void SetNode(Ptr<Node> node);
111
112 void Insert(Ptr<IpL4Protocol> protocol) override;
113 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
114
115 void Remove(Ptr<IpL4Protocol> protocol) override;
116 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
117
118 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
119 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
120
126
131 void DeleteRawSocket(Ptr<Socket> socket);
132
137 void SetDefaultTtl(uint8_t ttl);
138
143 void SetDefaultTclass(uint8_t tclass);
144
156 void Receive(Ptr<NetDevice> device,
158 uint16_t protocol,
159 const Address& from,
160 const Address& to,
161 NetDevice::PacketType packetType);
162
163 void Send(Ptr<Packet> packet,
164 Ipv6Address source,
165 Ipv6Address destination,
166 uint8_t protocol,
167 Ptr<Ipv6Route> route) override;
168
173 void SetRoutingProtocol(Ptr<Ipv6RoutingProtocol> routingProtocol) override;
174
180
186 uint32_t AddInterface(Ptr<NetDevice> device) override;
187
194
199 uint32_t GetNInterfaces() const override;
200
206 int32_t GetInterfaceForAddress(Ipv6Address addr) const override;
207
214 int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const override;
215
222
230 bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute = true) override;
231
238 Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
239
245 uint32_t GetNAddresses(uint32_t interface) const override;
246
253 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
254
261 bool RemoveAddress(uint32_t interfaceIndex, Ipv6Address address) override;
262
268 void SetMetric(uint32_t i, uint16_t metric) override;
269
275 uint16_t GetMetric(uint32_t i) const override;
276
282 uint16_t GetMtu(uint32_t i) const override;
283
289 void SetPmtu(Ipv6Address dst, uint32_t pmtu) override;
290
296 bool IsUp(uint32_t i) const override;
297
302 void SetUp(uint32_t i) override;
303
308 void SetDown(uint32_t i) override;
309
315 bool IsForwarding(uint32_t i) const override;
316
322 void SetForwarding(uint32_t i, bool val) override;
323
324 Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest) override;
325
332
338
349 void AddAutoconfiguredAddress(uint32_t interface,
350 Ipv6Address network,
351 Ipv6Prefix mask,
352 uint8_t flags,
353 uint32_t validTime,
354 uint32_t preferredTime,
355 Ipv6Address defaultRouter = Ipv6Address::GetZero());
356
367 Ipv6Address network,
368 Ipv6Prefix mask,
369 Ipv6Address defaultRouter);
370
371 void RegisterExtensions() override;
372 void RegisterOptions() override;
373
384 virtual void ReportDrop(Ipv6Header ipHeader, Ptr<Packet> p, DropReason dropReason);
385
394 typedef void (*SentTracedCallback)(const Ipv6Header& header,
395 Ptr<const Packet> packet,
396 uint32_t interface);
397
407 typedef void (*TxRxTracedCallback)(Ptr<const Packet> packet,
408 Ptr<Ipv6> ipv6,
409 uint32_t interface);
410
422 typedef void (*DropTracedCallback)(const Ipv6Header& header,
423 Ptr<const Packet> packet,
424 DropReason reason,
425 Ptr<Ipv6> ipv6,
426 uint32_t interface);
427
432 void AddMulticastAddress(Ipv6Address address);
433
439 void AddMulticastAddress(Ipv6Address address, uint32_t interface);
440
446
452 void RemoveMulticastAddress(Ipv6Address address, uint32_t interface);
453
459 bool IsRegisteredMulticastAddress(Ipv6Address address) const;
460
467 bool IsRegisteredMulticastAddress(Ipv6Address address, uint32_t interface) const;
468
486 bool ReachabilityHint(uint32_t ipInterfaceIndex, Ipv6Address address);
487
488 protected:
492 void DoDispose() override;
493
501 void NotifyNewAggregate() override;
502
503 private:
508 friend class ::Ipv6L3ProtocolTestCase;
514
518 typedef std::vector<Ptr<Ipv6Interface>> Ipv6InterfaceList;
519
523 typedef std::map<Ptr<const NetDevice>, uint32_t> Ipv6InterfaceReverseContainer;
524
528 typedef std::list<Ptr<Ipv6RawSocketImpl>> SocketList;
529
533 typedef std::pair<int, int32_t> L4ListKey_t;
534
538 typedef std::map<L4ListKey_t, Ptr<IpL4Protocol>> L4List_t;
539
543 typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>> Ipv6AutoconfiguredPrefixList;
544
548 typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>>::iterator Ipv6AutoconfiguredPrefixListI;
549
560 void CallTxTrace(const Ipv6Header& ipHeader,
561 Ptr<Packet> packet,
562 Ptr<Ipv6> ipv6,
563 uint32_t interface);
564
571
578
586
593
605 Ipv6Address dst,
606 uint8_t protocol,
607 uint16_t payloadSize,
608 uint8_t hopLimit,
609 uint8_t tclass);
610
617 void SendRealOut(Ptr<Ipv6Route> route, Ptr<Packet> packet, const Ipv6Header& ipHeader);
618
627 Ptr<Ipv6Route> rtentry,
629 const Ipv6Header& header);
630
641 const Ipv6Header& header);
642
649 void LocalDeliver(Ptr<const Packet> p, const Ipv6Header& ip, uint32_t iif);
650
658 const Ipv6Header& ipHeader,
659 Socket::SocketErrno sockErrno);
660
667
671 void SetupLoopback();
672
677 void SetIpForward(bool forward) override;
678
683 bool GetIpForward() const override;
684
689 void SetMtuDiscover(bool mtuDiscover) override;
690
695 bool GetMtuDiscover() const override;
696
701 virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect);
702
707 virtual bool GetSendIcmpv6Redirect() const;
708
713
718
723
728
733
738
743
748
753
758
763
768
773
778
783
787 typedef std::pair<Ipv6Address, uint64_t> Ipv6RegisteredMulticastAddressKey_t;
788
792 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>
794
798 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::iterator
800
804 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::const_iterator
806
810 typedef std::map<Ipv6Address, uint32_t> Ipv6RegisteredMulticastAddressNoInterface_t;
811
815 typedef std::map<Ipv6Address, uint32_t>::iterator
817
821 typedef std::map<Ipv6Address, uint32_t>::const_iterator
823
828
833
838};
839
840} /* namespace ns3 */
841
842#endif /* IPV6_L3_PROTOCOL_H */
a polymophic address class
Definition: address.h:100
Describes an IPv6 address.
Definition: ipv6-address.h:49
static Ipv6Address GetZero()
Get the 0 (::) Ipv6Address.
IPv6 Extension Loose Routing.
Packet header for IPv6.
Definition: ipv6-header.h:35
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.
Ipv6RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
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.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressCIter_t
Container Const Iterator of the IPv6 multicast addresses.
uint16_t GetMetric(uint32_t i) const override
Get metric for an interface.
Ipv6RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
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.
std::list< Ptr< Ipv6AutoconfiguredPrefix > >::iterator Ipv6AutoconfiguredPrefixListI
Iterator of the container of the IPv6 Autoconfigured addresses.
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.
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.
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.
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.
Ipv6RoutingProtocol::ErrorCallback m_ecb
Error callback.
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< Ipv6Address, uint32_t >::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t
Container Iterator of the IPv6 multicast addresses.
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.
std::map< Ipv6Address, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t
Container Const Iterator of the IPv6 multicast addresses.
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.
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
std::list< Ptr< Ipv6RawSocketImpl > > SocketList
Container of the IPv6 Raw Sockets.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::iterator Ipv6RegisteredMulticastAddressIter_t
Container Iterator of the IPv6 multicast addresses.
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.
std::pair< Ipv6Address, uint64_t > Ipv6RegisteredMulticastAddressKey_t
IPv6 multicast addresses / interface key.
Ipv6RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
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.
Ipv6L3Protocol()
Constructor.
void SetIpForward(bool forward) override
Set IPv6 forwarding state.
Ipv6L3Protocol & operator=(const Ipv6L3Protocol &)=delete
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:455
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.