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 "ipv6-header.h"
24#include "ipv6-pmtu-cache.h"
26#include "ipv6.h"
27
28#include "ns3/ipv6-address.h"
29#include "ns3/net-device.h"
30#include "ns3/traced-callback.h"
31
32#include <list>
33
35
36namespace ns3
37{
38
39class Node;
40class Ipv6Interface;
41class IpL4Protocol;
42class Ipv6Route;
43class Ipv6MulticastRoute;
44class Ipv6RawSocketImpl;
45class Icmpv6L4Protocol;
46class Ipv6AutoconfiguredPrefix;
47
63class Ipv6L3Protocol : public Ipv6
64{
65 public:
70 static TypeId GetTypeId();
71
75 static const uint16_t PROT_NUMBER;
76
82 {
91 };
92
97
101 ~Ipv6L3Protocol() override;
102
103 // Delete copy constructor and assignment operator to avoid misuse
106
111 void SetNode(Ptr<Node> node);
112
113 void Insert(Ptr<IpL4Protocol> protocol) override;
114 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
115
116 void Remove(Ptr<IpL4Protocol> protocol) override;
117 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
118
119 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
120 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
121
127
132 void DeleteRawSocket(Ptr<Socket> socket);
133
138 void SetDefaultTtl(uint8_t ttl);
139
144 void SetDefaultTclass(uint8_t tclass);
145
157 void Receive(Ptr<NetDevice> device,
159 uint16_t protocol,
160 const Address& from,
161 const Address& to,
162 NetDevice::PacketType packetType);
163
164 void Send(Ptr<Packet> packet,
165 Ipv6Address source,
166 Ipv6Address destination,
167 uint8_t protocol,
168 Ptr<Ipv6Route> route) override;
169
174 void SetRoutingProtocol(Ptr<Ipv6RoutingProtocol> routingProtocol) override;
175
181
187 uint32_t AddInterface(Ptr<NetDevice> device) override;
188
195
200 uint32_t GetNInterfaces() const override;
201
207 int32_t GetInterfaceForAddress(Ipv6Address addr) const override;
208
215 int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const override;
216
223
231 bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute = true) override;
232
239 Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
240
246 uint32_t GetNAddresses(uint32_t interface) const override;
247
254 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
255
262 bool RemoveAddress(uint32_t interfaceIndex, Ipv6Address address) override;
263
269 void SetMetric(uint32_t i, uint16_t metric) override;
270
276 uint16_t GetMetric(uint32_t i) const override;
277
283 uint16_t GetMtu(uint32_t i) const override;
284
290 void SetPmtu(Ipv6Address dst, uint32_t pmtu) override;
291
297 bool IsUp(uint32_t i) const override;
298
303 void SetUp(uint32_t i) override;
304
309 void SetDown(uint32_t i) override;
310
316 bool IsForwarding(uint32_t i) const override;
317
323 void SetForwarding(uint32_t i, bool val) override;
324
325 Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest) override;
326
333
339
350 void AddAutoconfiguredAddress(uint32_t interface,
351 Ipv6Address network,
352 Ipv6Prefix mask,
353 uint8_t flags,
354 uint32_t validTime,
355 uint32_t preferredTime,
356 Ipv6Address defaultRouter = Ipv6Address::GetZero());
357
368 Ipv6Address network,
369 Ipv6Prefix mask,
370 Ipv6Address defaultRouter);
371
372 void RegisterExtensions() override;
373 void RegisterOptions() override;
374
385 virtual void ReportDrop(Ipv6Header ipHeader, Ptr<Packet> p, DropReason dropReason);
386
395 typedef void (*SentTracedCallback)(const Ipv6Header& header,
396 Ptr<const Packet> packet,
397 uint32_t interface);
398
408 typedef void (*TxRxTracedCallback)(Ptr<const Packet> packet,
409 Ptr<Ipv6> ipv6,
410 uint32_t interface);
411
423 typedef void (*DropTracedCallback)(const Ipv6Header& header,
424 Ptr<const Packet> packet,
425 DropReason reason,
426 Ptr<Ipv6> ipv6,
427 uint32_t interface);
428
433 void AddMulticastAddress(Ipv6Address address);
434
440 void AddMulticastAddress(Ipv6Address address, uint32_t interface);
441
447
453 void RemoveMulticastAddress(Ipv6Address address, uint32_t interface);
454
460 bool IsRegisteredMulticastAddress(Ipv6Address address) const;
461
468 bool IsRegisteredMulticastAddress(Ipv6Address address, uint32_t interface) const;
469
487 bool ReachabilityHint(uint32_t ipInterfaceIndex, Ipv6Address address);
488
489 protected:
493 void DoDispose() override;
494
502 void NotifyNewAggregate() override;
503
504 private:
509 friend class ::Ipv6L3ProtocolTestCase;
515
519 typedef std::vector<Ptr<Ipv6Interface>> Ipv6InterfaceList;
520
524 typedef std::map<Ptr<const NetDevice>, uint32_t> Ipv6InterfaceReverseContainer;
525
529 typedef std::list<Ptr<Ipv6RawSocketImpl>> SocketList;
530
534 typedef std::pair<int, int32_t> L4ListKey_t;
535
539 typedef std::map<L4ListKey_t, Ptr<IpL4Protocol>> L4List_t;
540
544 typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>> Ipv6AutoconfiguredPrefixList;
545
549 typedef std::list<Ptr<Ipv6AutoconfiguredPrefix>>::iterator Ipv6AutoconfiguredPrefixListI;
550
561 void CallTxTrace(const Ipv6Header& ipHeader,
562 Ptr<Packet> packet,
563 Ptr<Ipv6> ipv6,
564 uint32_t interface);
565
572
579
587
594
606 Ipv6Address dst,
607 uint8_t protocol,
608 uint16_t payloadSize,
609 uint8_t hopLimit,
610 uint8_t tclass);
611
618 void SendRealOut(Ptr<Ipv6Route> route, Ptr<Packet> packet, const Ipv6Header& ipHeader);
619
628 Ptr<Ipv6Route> rtentry,
630 const Ipv6Header& header);
631
642 const Ipv6Header& header);
643
650 void LocalDeliver(Ptr<const Packet> p, const Ipv6Header& ip, uint32_t iif);
651
659 const Ipv6Header& ipHeader,
660 Socket::SocketErrno sockErrno);
661
668
672 void SetupLoopback();
673
678 void SetIpForward(bool forward) override;
679
684 bool GetIpForward() const override;
685
690 void SetMtuDiscover(bool mtuDiscover) override;
691
696 bool GetMtuDiscover() const override;
697
702 virtual void SetSendIcmpv6Redirect(bool sendIcmpv6Redirect);
703
708 virtual bool GetSendIcmpv6Redirect() const;
709
710 void SetStrongEndSystemModel(bool model) override;
711 bool GetStrongEndSystemModel() const override;
712
717
722
727
732
737
742
747
752
757
762
767
772
777
782
787
791 typedef std::pair<Ipv6Address, uint64_t> Ipv6RegisteredMulticastAddressKey_t;
792
796 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>
798
802 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::iterator
804
808 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::const_iterator
810
814 typedef std::map<Ipv6Address, uint32_t> Ipv6RegisteredMulticastAddressNoInterface_t;
815
819 typedef std::map<Ipv6Address, uint32_t>::iterator
821
825 typedef std::map<Ipv6Address, uint32_t>::const_iterator
827
832
837
842};
843
844} /* namespace ns3 */
845
846#endif /* IPV6_L3_PROTOCOL_H */
a polymophic address class
Definition: address.h:101
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 ?
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
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.
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
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:77
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.