PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/internet/model/ipv6-interface-address.h

https://github.com/scarletttu/ns-3-codel-dev
C Header | 209 lines | 65 code | 34 blank | 110 comment | 16 complexity | b8e6e72838faf33900fa5b689c60709a MD5 | raw file
Possible License(s): GPL-2.0
  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. #ifndef IPV6_INTERFACE_ADDRESS_H
  21. #define IPV6_INTERFACE_ADDRESS_H
  22. #include <stdint.h>
  23. #include "ns3/ipv6-address.h"
  24. namespace ns3
  25. {
  26. /**
  27. * \ingroup address
  28. * \class Ipv6InterfaceAddress
  29. * \brief IPv6 address associated with an interface.
  30. */
  31. class Ipv6InterfaceAddress
  32. {
  33. public:
  34. /**
  35. * \enum State_e
  36. * \brief State of an address associated with an interface.
  37. */
  38. enum State_e
  39. {
  40. TENTATIVE, /**< Address is tentative, no packet can be sent unless DAD finished */
  41. DEPRECATED, /**< Address is deprecated and should not be used */
  42. PREFERRED, /**< Preferred address */
  43. PERMANENT, /**< Permanent address */
  44. HOMEADDRESS, /**< Address is a HomeAddress */
  45. TENTATIVE_OPTIMISTIC, /**< Address is tentative but we are optimistic so we can send packet even if DAD is not yet finished */
  46. INVALID, /**< Invalid state (after a DAD failed) */
  47. };
  48. /**
  49. * \enum Scope_e
  50. * \brief Scope of address.
  51. */
  52. enum Scope_e
  53. {
  54. HOST, /**< Localhost (::1/128) */
  55. LINKLOCAL, /**< Link-local address (fe80::/64) */
  56. GLOBAL, /**< Global address (2000::/3) */
  57. };
  58. /**
  59. * \brief Default constructor.
  60. */
  61. Ipv6InterfaceAddress ();
  62. /**
  63. * \brief Constructor. Prefix is 64 by default.
  64. * \param address the IPv6 address to set
  65. */
  66. Ipv6InterfaceAddress (Ipv6Address address);
  67. /**
  68. * \brief Constructor.
  69. * \param address IPv6 address to set
  70. * \param prefix IPv6 prefix
  71. */
  72. Ipv6InterfaceAddress (Ipv6Address address, Ipv6Prefix prefix);
  73. /**
  74. * \brief Copy constructor.
  75. * \param o object to copy
  76. */
  77. Ipv6InterfaceAddress (const Ipv6InterfaceAddress& o);
  78. /**
  79. * \brief Destructor.
  80. */
  81. ~Ipv6InterfaceAddress ();
  82. /**
  83. * \brief Set IPv6 address (and scope).
  84. * \param address IPv6 address to set
  85. */
  86. void SetAddress (Ipv6Address address);
  87. /**
  88. * \brief Get the IPv6 address.
  89. * \return IPv6 address
  90. */
  91. Ipv6Address GetAddress () const;
  92. /**
  93. * \brief Get the IPv6 prefix.
  94. * \return IPv6 prefix
  95. */
  96. Ipv6Prefix GetPrefix () const;
  97. /**
  98. * \brief Set the state.
  99. * \param state the state
  100. */
  101. void SetState (Ipv6InterfaceAddress::State_e state);
  102. /**
  103. * \brief Get the address state.
  104. * \return address state
  105. */
  106. Ipv6InterfaceAddress::State_e GetState () const;
  107. /**
  108. * \brief Set the scope.
  109. * \param scope the scope of address
  110. */
  111. void SetScope (Ipv6InterfaceAddress::Scope_e scope);
  112. /**
  113. * \brief Get address scope.
  114. * \return scope
  115. */
  116. Ipv6InterfaceAddress::Scope_e GetScope () const;
  117. /**
  118. * \brief Set the latest DAD probe packet UID.
  119. * \param uid packet uid
  120. */
  121. void SetNsDadUid (uint32_t uid);
  122. /**
  123. * \brief Get the latest DAD probe packet UID.
  124. * \return uid
  125. */
  126. uint32_t GetNsDadUid () const;
  127. #if 0
  128. /**
  129. * \brief Start the DAD timer.
  130. * \param interface interface
  131. */
  132. void StartDadTimer (Ptr<Ipv6Interface> interface);
  133. /**
  134. * \brief Stop the DAD timer.
  135. */
  136. void StopDadTimer ();
  137. #endif
  138. private:
  139. /**
  140. * \brief The IPv6 address.
  141. */
  142. Ipv6Address m_address;
  143. /**
  144. * \brief The IPv6 prefix.
  145. */
  146. Ipv6Prefix m_prefix;
  147. /**
  148. * \brief State of the address.
  149. */
  150. State_e m_state;
  151. /**
  152. * \brief Scope of the address.
  153. */
  154. Scope_e m_scope;
  155. friend bool operator == (Ipv6InterfaceAddress const& a, Ipv6InterfaceAddress const& b);
  156. friend bool operator != (Ipv6InterfaceAddress const& a, Ipv6InterfaceAddress const& b);
  157. /**
  158. * \brief Last DAD probe packet UID.
  159. */
  160. uint32_t m_nsDadUid;
  161. };
  162. std::ostream& operator<< (std::ostream& os, const Ipv6InterfaceAddress &addr);
  163. /* follow Ipv4InterfaceAddress way, maybe not inline them */
  164. inline bool operator == (const Ipv6InterfaceAddress& a, const Ipv6InterfaceAddress& b)
  165. {
  166. return (a.m_address == b.m_address && a.m_prefix == b.m_prefix &&
  167. a.m_state == b.m_state && a.m_scope == b.m_scope);
  168. }
  169. inline bool operator != (const Ipv6InterfaceAddress& a, const Ipv6InterfaceAddress& b)
  170. {
  171. return (a.m_address != b.m_address || a.m_prefix != b.m_prefix ||
  172. a.m_state != b.m_state || a.m_scope != b.m_scope);
  173. }
  174. } /* namespace ns3 */
  175. #endif /* IPV6_INTERFACE_ADDRESS_H */