src/internet-stack/ipv4-interface.h
changeset 3260 8c0ab08144e6
parent 3021 5b1479210da3
child 3266 1ae7df5cf87b
equal deleted inserted replaced
3259:43b3f8ecd86d 3260:8c0ab08144e6
       
     1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2005,2006,2007 INRIA
       
     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  * Authors: 
       
    19  *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
       
    20  *  Tom Henderson <tomh@tomh.org>
       
    21  */
       
    22 #ifndef IPV4_INTERFACE_H
       
    23 #define IPV4_INTERFACE_H
       
    24 
       
    25 #include <list>
       
    26 #include "ns3/ipv4-address.h"
       
    27 #include "ns3/ptr.h"
       
    28 #include "ns3/object.h"
       
    29 
       
    30 namespace ns3 {
       
    31 
       
    32 class NetDevice;
       
    33 class Packet;
       
    34 
       
    35 /**
       
    36  * \brief The IPv4 representation of a network interface
       
    37  *
       
    38  * This class roughly corresponds to the struct in_device
       
    39  * of Linux; the main purpose is to provide address-family
       
    40  * specific information (addresses) about an interface.
       
    41  *
       
    42  * This class defines two APIs:
       
    43  *  - the public API which is expected to be used by both 
       
    44  *    the IPv4 layer and the user during forwarding and 
       
    45  *    configuration.
       
    46  *  - the private API which is expected to be implemented
       
    47  *    by subclasses of this base class. One such subclass 
       
    48  *    will be a Loopback interface which loops every
       
    49  *    packet sent back to the ipv4 layer. Another such 
       
    50  *    subclass typically contains the Ipv4 <-> MAC address
       
    51  *    translation logic which will use most of the time the
       
    52  *    ARP/RARP protocols.
       
    53  *
       
    54  * By default, Ipv4 interface are created in the "down" state
       
    55  * with ip address 192.168.0.1 and a matching mask. Before
       
    56  * becoming useable, the user must invoke SetUp on them
       
    57  * once the final Ipv4 address and mask has been set.
       
    58  *
       
    59  * Subclasses must implement the two methods:
       
    60  *   - Ipv4Interface::SendTo
       
    61  */
       
    62 class Ipv4Interface  : public Object
       
    63 {
       
    64 public:
       
    65   static TypeId GetTypeId (void);
       
    66 
       
    67   Ipv4Interface ();
       
    68   virtual ~Ipv4Interface();
       
    69 
       
    70   /**
       
    71    * \returns the underlying NetDevice. This method can return
       
    72    *          zero if this interface has no associated NetDevice.
       
    73    */
       
    74   virtual Ptr<NetDevice> GetDevice (void) const = 0;
       
    75 
       
    76   /**
       
    77    * \param a set the ipv4 address of this interface.
       
    78    */
       
    79   void SetAddress (Ipv4Address a);
       
    80   /**
       
    81    * \param mask set the ipv4 netmask of this interface.
       
    82    */
       
    83   void SetNetworkMask (Ipv4Mask mask);
       
    84 
       
    85   /**
       
    86    * \returns the broadcast ipv4 address associated to this interface
       
    87    */
       
    88   Ipv4Address GetBroadcast (void) const;
       
    89   /**
       
    90    * \returns the ipv4 netmask of this interface
       
    91    */
       
    92   Ipv4Mask GetNetworkMask (void) const;
       
    93   /**
       
    94    * \param metric configured routing metric (cost) of this interface
       
    95    */
       
    96   void SetMetric (uint16_t metric);
       
    97   /**
       
    98    * \returns configured routing metric (cost) of this interface
       
    99    */
       
   100   uint16_t GetMetric (void) const;
       
   101   /**
       
   102    * \returns the ipv4 address of this interface
       
   103    */
       
   104   Ipv4Address GetAddress (void) const;
       
   105 
       
   106   /**
       
   107    * This function a pass-through to NetDevice GetMtu, modulo
       
   108    * the  LLC/SNAP header i.e., ipv4MTU = NetDeviceMtu - LLCSNAPSIZE
       
   109    * \returns the Maximum Transmission Unit associated to this interface.
       
   110    */
       
   111   uint16_t GetMtu (void) const;
       
   112 
       
   113   /**
       
   114    * These are IP interface states and may be distinct from 
       
   115    * NetDevice states, such as found in real implementations
       
   116    * (where the device may be down but IP interface state is still up).
       
   117    */
       
   118   /**
       
   119    * \returns true if this interface is enabled, false otherwise.
       
   120    */
       
   121   bool IsUp (void) const;
       
   122   /**
       
   123    * \returns true if this interface is disabled, false otherwise.
       
   124    */
       
   125   bool IsDown (void) const;
       
   126   /**
       
   127    * Enable this interface
       
   128    */
       
   129   void SetUp (void);
       
   130   /**
       
   131    * Disable this interface
       
   132    */
       
   133   void SetDown (void);
       
   134 
       
   135   /**
       
   136    * \param p packet to send
       
   137    * \param dest next hop address of packet.
       
   138    *
       
   139    * This method will eventually call the private
       
   140    * SendTo method which must be implemented by subclasses.
       
   141    */ 
       
   142   void Send(Ptr<Packet> p, Ipv4Address dest);
       
   143 
       
   144 protected:
       
   145   virtual void DoDispose (void);
       
   146 private:
       
   147   virtual void SendTo (Ptr<Packet> p, Ipv4Address dest) = 0;
       
   148   bool m_ifup;
       
   149   Ipv4Address m_address;
       
   150   Ipv4Mask m_netmask;
       
   151   uint16_t m_metric;
       
   152 };
       
   153 
       
   154 }; // namespace ns3
       
   155 
       
   156 #endif