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_INTERFACE_H 22 #define IPV6_INTERFACE_H 23 24 #include <list> 25 #include "ns3/ptr.h" 26 #include "ns3/object.h" 27 #include "ipv6-interface-address.h" 28 29 namespace ns3 30 { 31 32 class NetDevice; 33 class Packet; 34 class Node; 35 class NdiscCache; 36 class Ipv6InterfaceAddress; 37 class Ipv6Address; 38 class Ipv6Header; 39 class TrafficControlLayer; 40 41 /** 42 * \ingroup ipv6 43 * 44 * \brief The IPv6 representation of a network interface. 45 * 46 * By default IPv6 interfaces are created in the "down" state 47 * with IP "fe80::1" and a /64 prefix. Before becoming usable, 48 * the user must invoke SetUp on them once the final IPv6 address 49 * and mask has been set. 50 */ 51 class Ipv6Interface : public Object 52 { 53 public: 54 /** 55 * \brief Get the type ID 56 * \return type ID 57 */ 58 static TypeId GetTypeId (); 59 60 /** 61 * \brief Constructs an Ipv6Interface. 62 */ 63 Ipv6Interface (); 64 65 /** 66 * \brief Destructor. 67 */ 68 virtual ~Ipv6Interface (); 69 70 /** 71 * \brief Set node associated with interface. 72 * \param node node 73 */ 74 void SetNode (Ptr<Node> node); 75 76 /** 77 * \brief Set the NetDevice. 78 * \param device NetDevice 79 */ 80 void SetDevice (Ptr<NetDevice> device); 81 82 /** 83 * \brief Set the TrafficControlLayer. 84 * \param tc TrafficControlLayer object 85 */ 86 void SetTrafficControl (Ptr<TrafficControlLayer> tc); 87 88 /** 89 * \brief Get the NetDevice. 90 * \return the NetDevice associated with this interface 91 */ 92 virtual Ptr<NetDevice> GetDevice () const; 93 94 /** 95 * \brief Set the metric. 96 * \param metric configured routing metric (cost) of this interface 97 */ 98 void SetMetric (uint16_t metric); 99 100 /** 101 * \brief Get the metric 102 * \return the metric 103 */ 104 uint16_t GetMetric () const; 105 106 /** 107 * \brief Is the interface UP ? 108 * \return true if interface is enabled, false otherwise. 109 */ 110 bool IsUp () const; 111 112 /** 113 * \brief Is the interface DOWN ? 114 * \return true if interface is disabled, false otherwise. 115 */ 116 bool IsDown () const; 117 118 /** 119 * \brief Enable this interface. 120 */ 121 void SetUp (); 122 123 /** 124 * \brief Disable this interface. 125 */ 126 void SetDown (); 127 128 /** 129 * \brief If the interface allows forwarding packets. 130 * \return true if forwarding is enabled, false otherwise 131 */ 132 bool IsForwarding () const; 133 134 /** 135 * \brief Set forwarding enabled or not. 136 * \param forward forwarding state 137 */ 138 void SetForwarding (bool forward); 139 140 /** 141 * \brief Set the current hop limit. 142 * \param curHopLimit the value to set 143 */ 144 void SetCurHopLimit (uint8_t curHopLimit); 145 146 /** 147 * \brief Get the current hop limit value. 148 * \return current hop limit 149 */ 150 uint8_t GetCurHopLimit () const; 151 152 /** 153 * \brief Set the base reachable time. 154 * \param baseReachableTime the value to set 155 */ 156 void SetBaseReachableTime (uint16_t baseReachableTime); 157 158 /** 159 * \brief Get the base reachable time. 160 * \return base reachable time 161 */ 162 uint16_t GetBaseReachableTime () const; 163 164 /** 165 * \brief Set the reachable time. 166 * \param reachableTime value to set 167 */ 168 void SetReachableTime (uint16_t reachableTime); 169 170 /** 171 * \brief Get the reachable time. 172 * \return reachable time 173 */ 174 uint16_t GetReachableTime () const; 175 176 /** 177 * \brief Set the retransmission timer. 178 * \param retransTimer value to set 179 */ 180 void SetRetransTimer (uint16_t retransTimer); 181 182 /** 183 * \brief Get the retransmission timer. 184 * \return retransmission timer 185 */ 186 uint16_t GetRetransTimer () const; 187 188 /** 189 * \brief Send a packet through this interface. 190 * \param p packet to send 191 * \param hdr IPv6 header 192 * \param dest next hop address of packet. 193 * 194 * \note This method will eventually call the private SendTo 195 * method which must be implemented by subclasses. 196 */ 197 void Send (Ptr<Packet> p, const Ipv6Header & hdr, Ipv6Address dest); 198 199 /** 200 * \brief Add an IPv6 address. 201 * \param iface address to add 202 * \return true if address was added, false otherwise 203 */ 204 bool AddAddress (Ipv6InterfaceAddress iface); 205 206 /** 207 * \brief Get link-local address from IPv6 interface. 208 * \return link-local Ipv6InterfaceAddress, assert if not found 209 */ 210 Ipv6InterfaceAddress GetLinkLocalAddress () const; 211 212 /** 213 * \brief Checks if the address is a Solicited Multicast address for this interface. 214 * \param address the address to check. 215 * \return true if it is a solicited multicast address. 216 */ 217 bool IsSolicitedMulticastAddress (Ipv6Address address) const; 218 219 /** 220 * \brief Get an address from IPv6 interface. 221 * \param index index 222 * \return Ipv6InterfaceAddress address whose index is i 223 */ 224 Ipv6InterfaceAddress GetAddress (uint32_t index) const; 225 226 /** 227 * \brief Get an address which is in the same network prefix as destination. 228 * \param dst destination address 229 * \return Corresponding Ipv6InterfaceAddress or assert if not found 230 */ 231 Ipv6InterfaceAddress GetAddressMatchingDestination (Ipv6Address dst); 232 233 /** 234 * \brief Get number of addresses on this IPv6 interface. 235 * \return number of address 236 */ 237 uint32_t GetNAddresses (void) const; 238 239 /** 240 * \brief Remove an address from interface. 241 * \param index index to remove 242 * \return Ipv6InterfaceAddress address whose index is index 243 */ 244 Ipv6InterfaceAddress RemoveAddress (uint32_t index); 245 246 /** 247 * \brief Remove the given Ipv6 address from the interface. 248 * \param address The Ipv6 address to remove 249 * \returns The removed Ipv6 interface address 250 * \returns The null interface address if the interface did not contain the 251 * address or if loopback address was passed as argument 252 */ 253 Ipv6InterfaceAddress RemoveAddress (Ipv6Address address); 254 255 /** 256 * \brief Update state of an interface address. 257 * \param address IPv6 address 258 * \param state new state 259 */ 260 void SetState (Ipv6Address address, Ipv6InterfaceAddress::State_e state); 261 262 /** 263 * \brief Update NS DAD packet UID of an interface address. 264 * \param address IPv6 address 265 * \param uid packet UID 266 */ 267 void SetNsDadUid (Ipv6Address address, uint32_t uid); 268 269 /** 270 * \return NDISC cache used by this interface 271 */ 272 Ptr<NdiscCache> GetNdiscCache () const; 273 274 275 protected: 276 /** 277 * \brief Dispose this object. 278 */ 279 virtual void DoDispose (); 280 281 private: 282 /** 283 * \brief Copy constructor 284 * \param o object to copy 285 * 286 * Defined and unimplemented to avoid misuse 287 */ 288 Ipv6Interface (const Ipv6Interface &o); 289 290 /** 291 * \brief Assignment operator 292 * \param o object to copy 293 * \returns the copied object 294 * 295 * Defined and unimplemented to avoid misuse 296 */ 297 Ipv6Interface &operator = (const Ipv6Interface &o); 298 299 /** 300 * \brief Container for the Ipv6InterfaceAddresses. 301 */ 302 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address> > Ipv6InterfaceAddressList; 303 304 /** 305 * \brief Container Iterator for the Ipv6InterfaceAddresses. 306 */ 307 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address> >::iterator Ipv6InterfaceAddressListI; 308 309 /** 310 * \brief Const Container Iterator for the Ipv6InterfaceAddresses. 311 */ 312 typedef std::list<std::pair<Ipv6InterfaceAddress, Ipv6Address> >::const_iterator Ipv6InterfaceAddressListCI; 313 314 /** 315 * \brief Initialize interface. 316 */ 317 void DoSetup (); 318 319 /** 320 * \brief The addresses assigned to this interface. 321 */ 322 Ipv6InterfaceAddressList m_addresses; 323 324 /** 325 * \brief The link-local addresses assigned to this interface. 326 */ 327 Ipv6InterfaceAddress m_linkLocalAddress; 328 329 /** 330 * \brief The state of this interface. 331 */ 332 bool m_ifup; 333 334 /** 335 * \brief Forwarding state. 336 */ 337 bool m_forwarding; 338 339 /** 340 * \brief The metric. 341 */ 342 uint16_t m_metric; 343 344 /** 345 * \brief Node associated with this interface. 346 */ 347 Ptr<Node> m_node; 348 349 /** 350 * \brief NetDevice associated with this interface. 351 */ 352 Ptr<NetDevice> m_device; 353 354 /** 355 * \brief TrafficControlLayer associated with this interface. 356 */ 357 Ptr<TrafficControlLayer> m_tc; 358 359 /** 360 * \brief Neighbor cache. 361 */ 362 Ptr<NdiscCache> m_ndCache; 363 364 /** 365 * \brief Current hop limit. 366 */ 367 uint8_t m_curHopLimit; 368 369 /** 370 * \brief Base value used for computing the random reachable time value (in millisecond). 371 */ 372 uint16_t m_baseReachableTime; 373 374 /** 375 * \brief Reachable time (in millisecond). 376 * The time a neighbor is considered reachable after receiving a reachability confirmation. 377 */ 378 uint16_t m_reachableTime; 379 380 /** 381 * \brief Retransmission timer (in millisecond). 382 * Time between retransmission of NS. 383 */ 384 uint16_t m_retransTimer; 385 }; 386 387 } /* namespace ns3 */ 388 389 #endif /* IPV6_INTERFACE_H */ 390 391