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
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{
64public:
69 static TypeId GetTypeId ();
70
74 static const uint16_t PROT_NUMBER;
75
81 {
90 };
91
96
100 virtual ~Ipv6L3Protocol ();
101
102 // Delete copy constructor and assignment operator to avoid misuse
103 Ipv6L3Protocol (const Ipv6L3Protocol &) = delete;
105
110 void SetNode (Ptr<Node> node);
111
112 virtual void Insert (Ptr<IpL4Protocol> protocol);
113 virtual void Insert (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
114
115 virtual void Remove (Ptr<IpL4Protocol> protocol);
116 virtual void Remove (Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex);
117
118 virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const;
119 virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber, int32_t interfaceIndex) const;
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, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType);
157
158 virtual void Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route);
159
164 void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol);
165
171
178
185
190 uint32_t GetNInterfaces () const;
191
198
206
213
221 bool AddAddress (uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute = true);
222
229 Ipv6InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
230
236 uint32_t GetNAddresses (uint32_t interface) const;
237
244 bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
245
252 bool RemoveAddress (uint32_t interfaceIndex, Ipv6Address address);
253
259 void SetMetric (uint32_t i, uint16_t metric);
260
266 uint16_t GetMetric (uint32_t i) const;
267
273 uint16_t GetMtu (uint32_t i) const;
274
280 virtual void SetPmtu (Ipv6Address dst, uint32_t pmtu);
281
287 bool IsUp (uint32_t i) const;
288
293 void SetUp (uint32_t i);
294
299 void SetDown (uint32_t i);
300
306 bool IsForwarding (uint32_t i) const;
307
313 void SetForwarding (uint32_t i, bool val);
314
316
323
329
340 void AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter = Ipv6Address::GetZero ());
341
351 void RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter);
352
356 virtual void RegisterExtensions ();
357
361 virtual void RegisterOptions ();
362
373 virtual void ReportDrop (Ipv6Header ipHeader, Ptr<Packet> p, DropReason dropReason);
374
383 typedef void (* SentTracedCallback)
384 (const Ipv6Header & header, Ptr<const Packet> packet, uint32_t interface);
385
395 typedef void (* TxRxTracedCallback)
396 (Ptr<const Packet> packet, Ptr<Ipv6> ipv6, uint32_t interface);
397
409 typedef void (* DropTracedCallback)
410 (const Ipv6Header & header, Ptr<const Packet> packet,
411 DropReason reason, Ptr<Ipv6> ipv6,
412 uint32_t interface);
413
419
426
432
439
446
454
472 bool ReachabilityHint (uint32_t ipInterfaceIndex, Ipv6Address address);
473
474protected:
478 virtual void DoDispose ();
479
485 virtual void NotifyNewAggregate ();
486
487private:
492 friend class ::Ipv6L3ProtocolTestCase;
498
502 typedef std::vector<Ptr<Ipv6Interface> > Ipv6InterfaceList;
503
507 typedef std::map<Ptr<const NetDevice>, uint32_t > Ipv6InterfaceReverseContainer;
508
512 typedef std::list<Ptr<Ipv6RawSocketImpl> > SocketList;
513
517 typedef std::pair<int, int32_t> L4ListKey_t;
518
522 typedef std::map<L4ListKey_t, Ptr<IpL4Protocol> > L4List_t;
523
527 typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> > Ipv6AutoconfiguredPrefixList;
528
532 typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> >::iterator Ipv6AutoconfiguredPrefixListI;
533
544 void CallTxTrace (const Ipv6Header & ipHeader, Ptr<Packet> packet, Ptr<Ipv6> ipv6, uint32_t interface);
545
552
559
566
573
584 Ipv6Header BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol,
585 uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass);
586
593 void SendRealOut (Ptr<Ipv6Route> route, Ptr<Packet> packet, Ipv6Header const& ipHeader);
594
602 void IpForward (Ptr<const NetDevice> idev, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
603
612
619 void LocalDeliver (Ptr<const Packet> p, Ipv6Header const& ip, uint32_t iif);
620
627 void RouteInputError (Ptr<const Packet> p, const Ipv6Header& ipHeader, Socket::SocketErrno sockErrno);
628
635
639 void SetupLoopback ();
640
645 virtual void SetIpForward (bool forward);
646
651 virtual bool GetIpForward () const;
652
657 virtual void SetMtuDiscover (bool mtuDiscover);
658
663 virtual bool GetMtuDiscover (void) const;
664
669 virtual void SetSendIcmpv6Redirect (bool sendIcmpv6Redirect);
670
675 virtual bool GetSendIcmpv6Redirect () const;
676
681
686
691
696
701
706
711
716
721
726
731
736
741
746
751
755 typedef std::pair<Ipv6Address, uint64_t> Ipv6RegisteredMulticastAddressKey_t;
756
760 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t> Ipv6RegisteredMulticastAddress_t;
761
765 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::iterator Ipv6RegisteredMulticastAddressIter_t;
766
770 typedef std::map<Ipv6RegisteredMulticastAddressKey_t, uint32_t>::const_iterator Ipv6RegisteredMulticastAddressCIter_t;
771
775 typedef std::map<Ipv6Address, uint32_t> Ipv6RegisteredMulticastAddressNoInterface_t;
776
780 typedef std::map<Ipv6Address, uint32_t>::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t;
781
785 typedef std::map<Ipv6Address, uint32_t>::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t;
786
791
796};
797
798} /* namespace ns3 */
799
800#endif /* IPV6_L3_PROTOCOL_H */
801
a polymophic address class
Definition: address.h:91
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.
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.
bool IsForwarding(uint32_t i) const
Is interface allows forwarding ?
std::map< L4ListKey_t, Ptr< IpL4Protocol > > L4List_t
Container of the IPv6 L4 instances.
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.
std::map< Ipv6RegisteredMulticastAddressKey_t, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressCIter_t
Container Const Iterator of the IPv6 multicast addresses.
virtual ~Ipv6L3Protocol()
Destructor.
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 SetForwarding(uint32_t i, bool val)
Enable or disable forwarding on interface.
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Get an address.
std::map< Ptr< const NetDevice >, uint32_t > Ipv6InterfaceReverseContainer
Container of NetDevices registered to IPv6 and their interface indexes.
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 m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
virtual void RegisterExtensions()
Register the IPv6 Extensions.
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.
TracedCallback< Ptr< const Packet >, Ptr< Ipv6 >, uint32_t > m_rxTrace
Callback to trace RX (reception) 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.
uint16_t GetMetric(uint32_t i) const
Get metric for an interface.
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.
Ipv6RegisteredMulticastAddressNoInterface_t m_multicastAddressesNoInterface
List of multicast IP addresses of interest for all the interfaces.
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const
Get interface index which match specified address/prefix.
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.
Ptr< Node > m_node
Node attached to stack.
uint32_t AddInterface(Ptr< NetDevice > device)
Add IPv6 interface for a device.
Ptr< NetDevice > GetNetDevice(uint32_t i)
Get device by index.
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const
Get current routing protocol used.
virtual bool GetIpForward() const
Get IPv6 forwarding state.
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 SetMetric(uint32_t i, uint16_t metric)
Set metric for 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.
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.
int32_t GetInterfaceForAddress(Ipv6Address addr) const
Get interface index which has specified IPv6 address.
virtual void ReportDrop(Ipv6Header ipHeader, Ptr< Packet > p, DropReason dropReason)
Report a packet drop.
void SetupLoopback()
Setup loopback interface.
Ipv6L3Protocol(const Ipv6L3Protocol &)=delete
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Get L4 protocol by protocol number.
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.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove an address from an interface.
virtual void Remove(Ptr< IpL4Protocol > protocol)
Remove a L4 protocol.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv6 > ipv6, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
Ipv6Address SourceAddressSelection(uint32_t interface, Ipv6Address dest)
Choose the source address to use with destination address.
bool m_mtuDiscover
MTU Discover (i.e.
void SetDefaultTtl(uint8_t ttl)
Set the default TTL.
void SetUp(uint32_t i)
Set an interface up.
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.
void LocalDeliver(Ptr< const Packet > p, Ipv6Header const &ip, uint32_t iif)
Deliver a packet.
std::map< Ipv6Address, uint32_t >::iterator Ipv6RegisteredMulticastAddressNoInterfaceIter_t
Container Iterator of the IPv6 multicast addresses.
std::map< Ipv6Address, uint32_t >::const_iterator Ipv6RegisteredMulticastAddressNoInterfaceCIter_t
Container Const Iterator of the IPv6 multicast addresses.
virtual bool GetMtuDiscover(void) const
Get IPv6 MTU discover state.
void RemoveMulticastAddress(Ipv6Address address)
Removes a multicast address from the list of addresses to pass to local deliver.
virtual void SetMtuDiscover(bool mtuDiscover)
Set IPv6 MTU discover state.
std::list< Ptr< Ipv6AutoconfiguredPrefix > > Ipv6AutoconfiguredPrefixList
Container of the IPv6 Autoconfigured addresses.
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
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 IpMulticastForward(Ptr< const NetDevice > idev, Ptr< Ipv6MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a multicast packet.
bool IsUp(uint32_t i) const
Is specified interface up ?
uint16_t GetMtu(uint32_t i) const
Get MTU for an interface.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Get interface index which is on a specified net device.
void SetDown(uint32_t i)
set an interface down.
uint32_t GetNAddresses(uint32_t interface) const
Get number of address for an interface.
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.
virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu)
Set the Path MTU for the specified IPv6 destination address.
Ipv6InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
bool m_strongEndSystemModel
Rejects packets directed to an interface with wrong address (RFC 1222).
TracedCallback< const Ipv6Header &, Ptr< const Packet >, DropReason, Ptr< Ipv6 >, uint32_t > m_dropTrace
Callback to trace drop packets.
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.
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.
virtual void RegisterOptions()
Register the IPv6 Options.
bool AddAddress(uint32_t i, Ipv6InterfaceAddress address, bool addOnLinkRoute=true)
Add an address on interface.
std::pair< Ipv6Address, uint64_t > Ipv6RegisteredMulticastAddressKey_t
IPv6 multicast addresses / interface key.
void SendRealOut(Ptr< Ipv6Route > route, Ptr< Packet > packet, Ipv6Header const &ipHeader)
Send packet with route.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv6 L4 keys: protocol number, interface index.
virtual void NotifyNewAggregate()
Notify other components connected to the node that a new stack member is now connected.
virtual void DoDispose()
Dispose object.
Ipv6L3Protocol()
Constructor.
virtual void SetIpForward(bool forward)
Set IPv6 forwarding state.
uint32_t GetNInterfaces() const
Get current number of interface on this stack.
Ipv6L3Protocol & operator=(const Ipv6L3Protocol &)=delete
static TypeId GetTypeId()
Get the type ID of this class.
virtual void Insert(Ptr< IpL4Protocol > protocol)
Add a L4 protocol.
TracedCallback< const Ipv6Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.