A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
33 namespace ns3
34 {
35 
36 class Node;
37 class Ipv6Interface;
38 class IpL4Protocol;
39 class Ipv6Route;
40 class Ipv6MulticastRoute;
41 class Ipv6RawSocketImpl;
42 class Icmpv6L4Protocol;
43 class Ipv6AutoconfiguredPrefix;
44 
59 class Ipv6L3Protocol : public Ipv6
60 {
61 public:
66  static TypeId GetTypeId ();
67 
71  static const uint16_t PROT_NUMBER;
72 
77  enum DropReason
78  {
84  };
85 
89  Ipv6L3Protocol ();
90 
94  virtual ~Ipv6L3Protocol ();
95 
100  void SetNode (Ptr<Node> node);
101 
106  void Insert (Ptr<IpL4Protocol> protocol);
107 
112  void Remove (Ptr<IpL4Protocol> protocol);
113 
119  Ptr<IpL4Protocol> GetProtocol (int protocolNumber) 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 
168  void Send (Ptr<Packet> packet, Ipv6Address source, Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route);
169 
174  void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol);
175 
181 
187  uint32_t AddInterface (Ptr<NetDevice> device);
188 
194  Ptr<Ipv6Interface> GetInterface (uint32_t i) const;
195 
200  uint32_t GetNInterfaces () const;
201 
207  int32_t GetInterfaceForAddress (Ipv6Address addr) const;
208 
215  int32_t GetInterfaceForPrefix (Ipv6Address addr, Ipv6Prefix mask) const;
216 
222  int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
223 
230  bool AddAddress (uint32_t i, Ipv6InterfaceAddress address);
231 
238  Ipv6InterfaceAddress GetAddress (uint32_t interfaceIndex, uint32_t addressIndex) const;
239 
245  uint32_t GetNAddresses (uint32_t interface) const;
246 
253  bool RemoveAddress (uint32_t interfaceIndex, uint32_t addressIndex);
254 
261  bool RemoveAddress (uint32_t interfaceIndex, Ipv6Address address);
262 
268  void SetMetric (uint32_t i, uint16_t metric);
269 
275  uint16_t GetMetric (uint32_t i) const;
276 
282  uint16_t GetMtu (uint32_t i) const;
283 
289  virtual void SetPmtu (Ipv6Address dst, uint32_t pmtu);
290 
296  bool IsUp (uint32_t i) const;
297 
302  void SetUp (uint32_t i);
303 
308  void SetDown (uint32_t i);
309 
315  bool IsForwarding (uint32_t i) const;
316 
322  void SetForwarding (uint32_t i, bool val);
323 
329  Ptr<NetDevice> GetNetDevice (uint32_t i);
330 
336 
347  void AddAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, uint8_t flags, uint32_t validTime, uint32_t preferredTime, Ipv6Address defaultRouter = Ipv6Address::GetZero ());
348 
358  void RemoveAutoconfiguredAddress (uint32_t interface, Ipv6Address network, Ipv6Prefix mask, Ipv6Address defaultRouter);
359 
363  virtual void RegisterExtensions ();
364 
368  virtual void RegisterOptions ();
369 
370 protected:
374  virtual void DoDispose ();
375 
381  virtual void NotifyNewAggregate ();
382 
383 private:
384  /* for unit-tests */
387 
391  typedef std::list<Ptr<Ipv6Interface> > Ipv6InterfaceList;
392 
396  typedef std::list<Ptr<Ipv6RawSocketImpl> > SocketList;
397 
401  typedef std::list<Ptr<IpL4Protocol> > L4List_t;
402 
406  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> > Ipv6AutoconfiguredPrefixList;
407 
411  typedef std::list< Ptr<Ipv6AutoconfiguredPrefix> >::iterator Ipv6AutoconfiguredPrefixListI;
412 
417 
422 
427 
434 
442 
453  Ipv6Header BuildHeader (Ipv6Address src, Ipv6Address dst, uint8_t protocol,
454  uint16_t payloadSize, uint8_t hopLimit, uint8_t tclass);
455 
462  void SendRealOut (Ptr<Ipv6Route> route, Ptr<Packet> packet, Ipv6Header const& ipHeader);
463 
471  void IpForward (Ptr<const NetDevice> idev, Ptr<Ipv6Route> rtentry, Ptr<const Packet> p, const Ipv6Header& header);
472 
481 
488  void LocalDeliver (Ptr<const Packet> p, Ipv6Header const& ip, uint32_t iif);
489 
496  void RouteInputError (Ptr<const Packet> p, const Ipv6Header& ipHeader, Socket::SocketErrno sockErrno);
497 
503  uint32_t AddIpv6Interface (Ptr<Ipv6Interface> interface);
504 
508  void SetupLoopback ();
509 
514  virtual void SetIpForward (bool forward);
515 
520  virtual bool GetIpForward () const;
521 
526  virtual void SetMtuDiscover (bool mtuDiscover);
527 
532  virtual bool GetMtuDiscover (void) const;
533 
538  virtual void SetSendIcmpv6Redirect (bool sendIcmpv6Redirect);
539 
544  virtual bool GetSendIcmpv6Redirect () const;
545 
550 
555 
560 
565 
570 
575 
579  uint32_t m_nInterfaces;
580 
584  uint8_t m_defaultTtl;
585 
590 
595 
600 
605 
610 };
611 
612 } /* namespace ns3 */
613 
614 #endif /* IPV6_L3_PROTOCOL_H */
615 
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.
Doxygen introspection did not find any typical Config paths.
Definition: ipv6-header.h:33
virtual ~Ipv6L3Protocol()
Destructor.
Ipv6L3Protocol()
Constructor.
virtual void SetPmtu(Ipv6Address dst, uint32_t pmtu)
Set the Path MTU for the specified IPv6 destination address.
Ptr< NetDevice > GetNetDevice(uint32_t i)
Get device by index.
bool AddAddress(uint32_t i, Ipv6InterfaceAddress address)
Add an address on interface.
Ptr< Ipv6RoutingProtocol > m_routingProtocol
Routing protocol.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:79
Ptr< Ipv6RoutingProtocol > GetRoutingProtocol() const
Get current routing protocol used.
uint32_t AddIpv6Interface(Ptr< Ipv6Interface > interface)
Add an IPv6 interface to the stack.
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.
std::list< Ptr< IpL4Protocol > > L4List_t
Container of the IPv6 L4 instances.
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Interface is down so can not send packet.
IPv6 address associated with an interface.
uint32_t GetNAddresses(uint32_t interface) const
Get number of address for 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.
virtual bool GetSendIcmpv6Redirect() const
Get the ICMPv6 Redirect sending state.
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
std::list< Ptr< Ipv6Interface > > Ipv6InterfaceList
Container of the IPv6 Interfaces.
Ptr< Node > m_node
Node attached to stack.
a polymophic address class
Definition: address.h:86
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.
bool IsUp(uint32_t i) const
Is specified interface up ?
uint32_t m_nInterfaces
Number of IPv6 interfaces managed by the stack.
void SetDefaultTclass(uint8_t tclass)
Set the default TCLASS.
int32_t GetInterfaceForPrefix(Ipv6Address addr, Ipv6Prefix mask) const
Get interface index which match specified address/prefix.
Ptr< Socket > CreateRawSocket()
Create raw IPv6 socket.
L4List_t m_protocols
List of transport protocol.
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 SetUp(uint32_t i)
Set an interface up.
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.
uint32_t GetNInterfaces() const
Get current number of interface on this stack.
uint16_t GetMetric(uint32_t i) const
Get metric for an interface.
std::list< Ptr< Ipv6AutoconfiguredPrefix > >::iterator Ipv6AutoconfiguredPrefixListI
Iterator of the container of the IPv6 Autoconfigured addresses.
Ipv6AutoconfiguredPrefixList m_prefixes
List of IPv6 prefix received from RA.
void LocalDeliver(Ptr< const Packet > p, Ipv6Header const &ip, uint32_t iif)
Deliver a packet.
void DeleteRawSocket(Ptr< Socket > socket)
Remove raw IPv6 socket.
virtual bool GetIpForward() const
Get IPv6 forwarding state.
void IpForward(Ptr< const NetDevice > idev, Ptr< Ipv6Route > rtentry, Ptr< const Packet > p, const Ipv6Header &header)
Forward a packet.
Ipv6InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Get an address.
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.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Get interface index which is on a specified net device.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
Doxygen introspection did not find any typical Config paths.
bool IsForwarding(uint32_t i) const
Is interface allows forwarding ?
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.
Describes an IPv6 address.
Definition: ipv6-address.h:46
void SetRoutingProtocol(Ptr< Ipv6RoutingProtocol > routingProtocol)
Set routing protocol for this stack.
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Get L4 protocol by protocol number.
Ptr< Icmpv6L4Protocol > GetIcmpv6() const
Get ICMPv6 protocol.
void Insert(Ptr< IpL4Protocol > protocol)
Add an L4 protocol.
uint16_t GetMtu(uint32_t i) const
Get MTU for an interface.
bool m_sendIcmpv6Redirect
Allow ICMPv6 Redirect sending state.
virtual void RegisterOptions()
Register the IPv6 Options.
Describes an IPv6 prefix.
Definition: ipv6-address.h:387
void SetDown(uint32_t i)
set an interface down.
bool m_mtuDiscover
MTU Discover (i.e.
int32_t GetInterfaceForAddress(Ipv6Address addr) const
Get interface index which has specified IPv6 address.
tuple address
Definition: first.py:37
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:270
Ptr< Ipv6PmtuCache > m_pmtuCache
Path MTU Cache.
virtual bool GetMtuDiscover(void) const
Get IPv6 MTU discover state.
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:49
SocketList m_sockets
List of IPv6 raw sockets.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Ptr< Ipv6Interface > GetInterface(uint32_t i) const
Get an interface.
void Remove(Ptr< IpL4Protocol > protocol)
Remove an 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.