model/linux/ipv6-linux.h
changeset 541 de7335a01743
child 549 28471949ecd1
equal deleted inserted replaced
540:dd0000c3c11c 541:de7335a01743
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2013 Hajime Tazaki
       
     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: Hajime Tazaki <tazaki@sfc.wide.jp>
       
    19  */
       
    20 
       
    21 #ifndef IPV6_LINUX_H
       
    22 #define IPV6_LINUX_H
       
    23 
       
    24 #include "ns3/ipv6.h"
       
    25 #include "ns3/ipv6-routing-protocol.h"
       
    26 #include "ns3/ipv6-pmtu-cache.h"
       
    27 
       
    28 namespace ns3 {
       
    29 class Ipv6Interface;
       
    30 
       
    31 /**
       
    32  * \brief This implementation of Ipv6 for nodes using a real Linux Stack.
       
    33  *
       
    34  * The main goal of this class is not to do the stack job which is done by the real code ....
       
    35  * but it is used to not redo the wheel and in particular to be able to reuse these 2 standards NS-3 Helpers for two tasks:
       
    36  *   1 - assign address to devices using Ipv6AddressHelper,
       
    37  *   2 - create the static routes using Ipv6GlobalRoutingHelper
       
    38  *
       
    39  */
       
    40 class Ipv6Linux : public Ipv6
       
    41 {
       
    42 public:
       
    43   static TypeId GetTypeId (void);
       
    44   Ipv6Linux ();
       
    45   virtual ~Ipv6Linux ();
       
    46 
       
    47   /**
       
    48    * \brief Register a new routing protocol to be used by this Ipv6 stack
       
    49    *
       
    50    * This call will replace any routing protocol that has been previously
       
    51    * registered.  If you want to add multiple routing protocols, you must
       
    52    * add them to a Ipv6ListRoutingProtocol directly.
       
    53    *
       
    54    * \param routingProtocol smart pointer to Ipv6RoutingProtocol object
       
    55    */
       
    56   virtual void SetRoutingProtocol (Ptr<Ipv6RoutingProtocol> routingProtocol);
       
    57 
       
    58   /**
       
    59    * \brief Get the routing protocol to be used by this Ipv6 stack
       
    60    *
       
    61    * \returns smart pointer to Ipv6RoutingProtocol object, or null pointer if none
       
    62    */
       
    63   virtual Ptr<Ipv6RoutingProtocol> GetRoutingProtocol (void) const;
       
    64 
       
    65   /**
       
    66    * \param device device to add to the list of Ipv6 interfaces
       
    67    *        which can be used as output interfaces during packet forwarding.
       
    68    * \returns the index of the Ipv6 interface added.
       
    69    *
       
    70    * Once a device has been added, it can never be removed: if you want
       
    71    * to disable it, you can invoke Ipv6::SetDown which will
       
    72    * make sure that it is never used during packet forwarding.
       
    73    */
       
    74   virtual uint32_t AddInterface (Ptr<NetDevice> device);
       
    75 
       
    76   /**
       
    77    * \returns the number of interfaces added by the user.
       
    78    */
       
    79   virtual uint32_t GetNInterfaces (void) const;
       
    80 
       
    81   /**
       
    82    * \brief Return the interface number of the interface that has been
       
    83    *        assigned the specified IP address.
       
    84    *
       
    85    * \param address The IP address being searched for
       
    86    * \returns The interface number of the Ipv6 interface with the given
       
    87    *          address or -1 if not found.
       
    88    *
       
    89    * Each IP interface has one or more IP addresses associated with it.
       
    90    * This method searches the list of interfaces for one that holds a
       
    91    * particular address.  This call takes an IP address as a parameter and
       
    92    * returns the interface number of the first interface that has been assigned
       
    93    * that address, or -1 if not found.  There must be an exact match; this
       
    94    * method will not match broadcast or multicast addresses.
       
    95    */
       
    96   virtual int32_t GetInterfaceForAddress (Ipv6Address address) const;
       
    97 
       
    98   /**
       
    99    * Do nothing
       
   100    */
       
   101   virtual void Send (Ptr<Packet> packet, Ipv6Address source,
       
   102                      Ipv6Address destination, uint8_t protocol, Ptr<Ipv6Route> route);
       
   103 
       
   104   /**
       
   105    * Do nothing
       
   106    */
       
   107   virtual void SendWithHeader (Ptr<Packet> packet, Ipv6Header ipHeader, Ptr<Ipv6Route> route);
       
   108 
       
   109   /**
       
   110    * Do nothing
       
   111    */
       
   112   //  virtual void Insert (Ptr<IpL4Protocol> protocol);
       
   113 
       
   114   /**
       
   115    * \brief Return the interface number of first interface found that
       
   116    *  has an Ipv6 address within the prefix specified by the input
       
   117    *  address and mask parameters
       
   118    *
       
   119    * \param address The IP address assigned to the interface of interest.
       
   120    * \param mask The IP prefix to use in the mask
       
   121    * \returns The interface number of the Ipv6 interface with the given
       
   122    *          address or -1 if not found.
       
   123    *
       
   124    * Each IP interface has one or more IP addresses associated with it.
       
   125    * This method searches the list of interfaces for the first one found
       
   126    * that holds an address that is included within the prefix
       
   127    * formed by the input address and mask parameters.  The value -1 is
       
   128    * returned if no match is found.
       
   129    */
       
   130   virtual int32_t GetInterfaceForPrefix (Ipv6Address address,
       
   131                                          Ipv6Prefix mask) const;
       
   132 
       
   133   /**
       
   134    * \param interface The interface number of an Ipv6 interface.
       
   135    * \returns The NetDevice associated with the Ipv6 interface number.
       
   136    */
       
   137   virtual Ptr<NetDevice> GetNetDevice (uint32_t interface);
       
   138 
       
   139   /**
       
   140    * \param device The NetDevice for an Ipv6Interface
       
   141    * \returns The interface number of an Ipv6 interface or -1 if not found.
       
   142    */
       
   143   virtual int32_t GetInterfaceForDevice (Ptr<const NetDevice> device) const;
       
   144 
       
   145   /**
       
   146    * \param interface Interface number of an Ipv6 interface
       
   147    * \param address Ipv6InterfaceAddress address to associate with the underlying Ipv6 interface
       
   148    * \returns true if the operation succeeded
       
   149    */
       
   150   virtual bool AddAddress (uint32_t interface, Ipv6InterfaceAddress address);
       
   151 
       
   152   /**
       
   153    * \param interface Interface number of an Ipv6 interface
       
   154    * \returns the number of Ipv6InterfaceAddress entries for the interface.
       
   155    */
       
   156   virtual uint32_t GetNAddresses (uint32_t interface) const;
       
   157 
       
   158   /**
       
   159    * Because addresses can be removed, the addressIndex is not guaranteed
       
   160    * to be static across calls to this method.
       
   161    *
       
   162    * \param interface Interface number of an Ipv6 interface
       
   163    * \param addressIndex index of Ipv6InterfaceAddress
       
   164    * \returns the Ipv6InterfaceAddress associated to the interface and addressIndex
       
   165    */
       
   166   virtual Ipv6InterfaceAddress GetAddress (uint32_t interface, uint32_t addressIndex) const;
       
   167 
       
   168   /**
       
   169    * Remove the address at addressIndex on named interface.  The addressIndex
       
   170    * for all higher indices will decrement by one after this method is called;
       
   171    * so, for example, to remove 5 addresses from an interface i, one could
       
   172    * call RemoveAddress (i, 0); 5 times.
       
   173    *
       
   174    * \param interface Interface number of an Ipv6 interface
       
   175    * \param addressIndex index of Ipv6InterfaceAddress to remove
       
   176    * \returns true if the operation succeeded
       
   177    */
       
   178   virtual bool RemoveAddress (uint32_t interface, uint32_t addressIndex);
       
   179 
       
   180   /**
       
   181    * \brief Remove the given address on named Ipv6 interface
       
   182    *
       
   183    * \param interface Interface number of an IPv6 interface
       
   184    * \param address the address to remove
       
   185    * \returns true if the operation succeeded
       
   186    */
       
   187   virtual bool RemoveAddress (uint32_t interface, Ipv6Address address);
       
   188 
       
   189   /**
       
   190    * \param interface The interface number of an Ipv6 interface
       
   191    * \param metric routing metric (cost) associated to the underlying
       
   192    *          Ipv6 interface
       
   193    */
       
   194   virtual void SetMetric (uint32_t interface, uint16_t metric);
       
   195 
       
   196   /**
       
   197    * \param interface The interface number of an Ipv6 interface
       
   198    * \returns routing metric (cost) associated to the underlying
       
   199    *          Ipv6 interface
       
   200    */
       
   201   virtual uint16_t GetMetric (uint32_t interface) const;
       
   202 
       
   203   /**
       
   204    * \param interface Interface number of Ipv6 interface
       
   205    * \returns the Maximum Transmission Unit (in bytes) associated
       
   206    *          to the underlying Ipv6 interface
       
   207    */
       
   208   virtual uint16_t GetMtu (uint32_t interface) const;
       
   209 
       
   210   /**
       
   211    * \brief Set the Path MTU for the specified IPv6 destination address.
       
   212    * \param dst Ipv6 destination address
       
   213    * \param pmtu the Path MTU
       
   214    */
       
   215   virtual void SetPmtu (Ipv6Address dst, uint32_t pmtu);
       
   216 
       
   217   /**
       
   218    * \param interface Interface number of Ipv6 interface
       
   219    * \returns true if the underlying interface is in the "up" state,
       
   220    *          false otherwise.
       
   221    */
       
   222   virtual bool IsUp (uint32_t interface) const;
       
   223 
       
   224   /**
       
   225    * \param interface Interface number of Ipv6 interface
       
   226    *
       
   227    * Set the interface into the "up" state. In this state, it is
       
   228    * considered valid during Ipv6 forwarding.
       
   229    */
       
   230   virtual void SetUp (uint32_t interface);
       
   231 
       
   232   /**
       
   233    * \param interface Interface number of Ipv6 interface
       
   234    *
       
   235    * Set the interface into the "down" state. In this state, it is
       
   236    * ignored during Ipv6 forwarding.
       
   237    */
       
   238   virtual void SetDown (uint32_t interface);
       
   239 
       
   240   /**
       
   241    * \param interface Interface number of Ipv6 interface
       
   242    * \returns true if IP forwarding enabled for input datagrams on this device
       
   243    */
       
   244   virtual bool IsForwarding (uint32_t interface) const;
       
   245 
       
   246   /**
       
   247    * \param interface Interface number of Ipv6 interface
       
   248    * \param val Value to set the forwarding flag
       
   249    *
       
   250    * If set to true, IP forwarding is enabled for input datagrams on this device
       
   251    */
       
   252   virtual void SetForwarding (uint32_t interface, bool val);
       
   253 
       
   254   /**
       
   255    * Do nothing
       
   256    */
       
   257   virtual Ptr<IpL4Protocol> GetProtocol (int protocolNumber) const ;
       
   258 
       
   259   /**
       
   260    * Do nothing
       
   261    */
       
   262   virtual Ptr<Socket> CreateRawSocket (void);
       
   263 
       
   264   /**
       
   265    * Do nothing
       
   266    */
       
   267   virtual void DeleteRawSocket (Ptr<Socket> socket);
       
   268 
       
   269   static void InstallNode (Ptr<Node> node);
       
   270 
       
   271   /**
       
   272    * \brief Register the IPv6 Extensions.
       
   273    */
       
   274   virtual void RegisterExtensions ();
       
   275 
       
   276   /**
       
   277    * \brief Register the IPv6 Options.
       
   278    */
       
   279   virtual void RegisterOptions ();
       
   280 
       
   281 private:
       
   282   // Indirect the Ipv6 attributes through private pure virtual methods
       
   283   virtual void SetIpForward (bool forward);
       
   284   virtual bool GetIpForward (void) const;
       
   285   /**
       
   286    * \brief Set IPv6 MTU discover state.
       
   287    * \param mtuDiscover IPv6 MTU discover enabled or not
       
   288    */
       
   289   virtual void SetMtuDiscover (bool mtuDiscover);
       
   290 
       
   291   /**
       
   292    * \brief Get IPv6 MTU discover state.
       
   293    * \return MTU discover state (enabled or not)
       
   294    */
       
   295   virtual bool GetMtuDiscover (void) const;
       
   296 
       
   297   virtual void SetWeakEsModel (bool model);
       
   298   virtual bool GetWeakEsModel (void) const;
       
   299   uint32_t AddIpv6Interface (Ptr<Ipv6Interface> interface);
       
   300   Ptr<Ipv6Interface> GetInterface (uint32_t i) const;
       
   301 
       
   302   typedef std::vector<Ptr<Ipv6Interface> > Ipv6InterfaceList;
       
   303   Ptr<Ipv6RoutingProtocol> m_routingProtocol;
       
   304   bool m_ipForward;
       
   305   bool m_mtuDiscover;
       
   306   Ptr<Ipv6PmtuCache> m_pmtuCache;
       
   307   bool m_weakEsModel;
       
   308   Ipv6InterfaceList m_interfaces;
       
   309   uint64_t m_nanoSec;
       
   310 };
       
   311 }
       
   312 #endif // IPV6_LINUX_H