00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005,2006,2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: 00019 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>, 00020 * Tom Henderson <tomh@tomh.org> 00021 */ 00022 #ifndef IPV4_INTERFACE_H 00023 #define IPV4_INTERFACE_H 00024 00025 #include <list> 00026 #include "ns3/ipv4-address.h" 00027 #include "ns3/ptr.h" 00028 #include "ns3/object.h" 00029 00030 namespace ns3 { 00031 00032 class NetDevice; 00033 class Packet; 00034 00035 /** 00036 * \brief The IPv4 representation of a network interface 00037 * 00038 * This class roughly corresponds to the struct in_device 00039 * of Linux; the main purpose is to provide address-family 00040 * specific information (addresses) about an interface. 00041 * 00042 * This class defines two APIs: 00043 * - the public API which is expected to be used by both 00044 * the IPv4 layer and the user during forwarding and 00045 * configuration. 00046 * - the private API which is expected to be implemented 00047 * by subclasses of this base class. One such subclass 00048 * will be a Loopback interface which loops every 00049 * packet sent back to the ipv4 layer. Another such 00050 * subclass typically contains the Ipv4 <-> MAC address 00051 * translation logic which will use most of the time the 00052 * ARP/RARP protocols. 00053 * 00054 * By default, Ipv4 interface are created in the "down" state 00055 * with ip address 192.168.0.1 and a matching mask. Before 00056 * becoming useable, the user must invoke SetUp on them 00057 * once the final Ipv4 address and mask has been set. 00058 * 00059 * Subclasses must implement the two methods: 00060 * - Ipv4Interface::SendTo 00061 * - Ipv4Interface::GetDevice 00062 */ 00063 class Ipv4Interface : public Object 00064 { 00065 public: 00066 static TypeId GetTypeId (void); 00067 00068 Ipv4Interface (); 00069 virtual ~Ipv4Interface(); 00070 00071 /** 00072 * \returns the underlying NetDevice. This method can return 00073 * zero if this interface has no associated NetDevice. 00074 */ 00075 virtual Ptr<NetDevice> GetDevice (void) const = 0; 00076 00077 /** 00078 * \param a set the ipv4 address of this interface. 00079 */ 00080 void SetAddress (Ipv4Address a); 00081 /** 00082 * \param mask set the ipv4 netmask of this interface. 00083 */ 00084 void SetNetworkMask (Ipv4Mask mask); 00085 00086 /** 00087 * \returns the broadcast ipv4 address associated to this interface 00088 */ 00089 Ipv4Address GetBroadcast (void) const; 00090 /** 00091 * \returns the ipv4 netmask of this interface 00092 */ 00093 Ipv4Mask GetNetworkMask (void) const; 00094 /** 00095 * \param metric configured routing metric (cost) of this interface 00096 */ 00097 void SetMetric (uint16_t metric); 00098 /** 00099 * \returns configured routing metric (cost) of this interface 00100 */ 00101 uint16_t GetMetric (void) const; 00102 /** 00103 * \returns the ipv4 address of this interface 00104 */ 00105 Ipv4Address GetAddress (void) const; 00106 00107 /** 00108 * This function a pass-through to NetDevice GetMtu, modulo 00109 * the LLC/SNAP header i.e., ipv4MTU = NetDeviceMtu - LLCSNAPSIZE 00110 * \returns the Maximum Transmission Unit associated to this interface. 00111 */ 00112 uint16_t GetMtu (void) const; 00113 00114 /** 00115 * These are IP interface states and may be distinct from 00116 * NetDevice states, such as found in real implementations 00117 * (where the device may be down but IP interface state is still up). 00118 */ 00119 /** 00120 * \returns true if this interface is enabled, false otherwise. 00121 */ 00122 bool IsUp (void) const; 00123 /** 00124 * \returns true if this interface is disabled, false otherwise. 00125 */ 00126 bool IsDown (void) const; 00127 /** 00128 * Enable this interface 00129 */ 00130 void SetUp (void); 00131 /** 00132 * Disable this interface 00133 */ 00134 void SetDown (void); 00135 00136 /** 00137 * \param p packet to send 00138 * \param dest next hop address of packet. 00139 * 00140 * This method will eventually call the private 00141 * SendTo method which must be implemented by subclasses. 00142 */ 00143 void Send(Ptr<Packet> p, Ipv4Address dest); 00144 00145 protected: 00146 virtual void DoDispose (void); 00147 private: 00148 virtual void SendTo (Ptr<Packet> p, Ipv4Address dest) = 0; 00149 bool m_ifup; 00150 Ipv4Address m_address; 00151 Ipv4Mask m_netmask; 00152 uint16_t m_metric; 00153 }; 00154 00155 }; // namespace ns3 00156 00157 #endif