1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2008-2009 Telecom Bretagne 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: Mehdi Benamor <benamor.mehdi@ensi.rnu.tn> 19 */ 20 21 #ifndef IPV6_AUTOCONFIGURED_PREFIX_H 22 #define IPV6_AUTOCONFIGURED_PREFIX_H 23 24 #include <stdint.h> 25 26 #include <list> 27 #include <vector> 28 #include <ostream> 29 30 #include "ns3/timer.h" 31 #include "ns3/ipv6-address.h" 32 33 namespace ns3 34 { 35 36 /** 37 * \ingroup ipv6 38 * 39 * \brief Router prefix information. 40 */ 41 class Ipv6AutoconfiguredPrefix : public Object 42 { 43 public: 44 /** 45 * \brief Constructor. 46 * \param node node 47 * \param interface interface index 48 * \param prefix IPv6 address 49 * \param mask bitmask prefix 50 * \param preferredLifeTime the preferred life time 51 * \param validLifeTime the valid life time 52 * \param router if it the prefix that configure the default gateway 53 */ 54 Ipv6AutoconfiguredPrefix (Ptr<Node> node, uint32_t interface, Ipv6Address prefix, Ipv6Prefix mask, uint32_t preferredLifeTime, uint32_t validLifeTime, Ipv6Address router = Ipv6Address ("::")); 55 56 /** 57 * \brief Destructor. 58 */ 59 ~Ipv6AutoconfiguredPrefix (); 60 61 /** 62 * \brief Set the default gateway router. 63 * \param router IPv6 link-local address of the default router 64 */ 65 void SetDefaultGatewayRouter (Ipv6Address router); 66 67 /** 68 * \brief Get the default gateway address. 69 * \return IPv6 link-local address of the default router 70 */ 71 Ipv6Address GetDefaultGatewayRouter () const; 72 73 /** 74 * \brief Get the interface index. 75 * \return interface index 76 */ 77 uint32_t GetInterface () const; 78 79 /** 80 * \brief Set the interface. 81 * \param interface interface index to set 82 */ 83 void SetInterface (uint32_t interface); 84 85 /** 86 * \brief Get the prefix preferred life time. 87 * \return preferred life time 88 */ 89 uint32_t GetPreferredLifeTime () const; 90 91 /** 92 * \brief Set the prefix preferred life time. 93 * \param p the prefix preferred life time 94 */ 95 void SetPreferredLifeTime (uint32_t p); 96 97 /** 98 * \brief Get the prefix valid life time. 99 * \return valid life time 100 */ 101 uint32_t GetValidLifeTime (void) const; 102 103 /** 104 * \brief Set the prefix valid life time. 105 * \param v the prefix valid life time 106 */ 107 void SetValidLifeTime (uint32_t v); 108 109 /** 110 * \brief Test if the prefix is preferred. 111 * \return true if prefix is in preferred state, false otherwise 112 */ 113 bool IsPreferred () const; 114 115 /** 116 * \brief Test if the prefix is valid. 117 * \return true if prefix is in valid state, false otherwise 118 */ 119 bool IsValid () const; 120 121 /** 122 * \brief Set the prefix as preferred. 123 */ 124 void SetPreferred (); 125 126 /** 127 * \brief Set the prefix as valid. 128 */ 129 void SetValid (); 130 131 /** 132 * \brief Start the preferred timer. 133 */ 134 void StartPreferredTimer (); 135 136 /** 137 * \brief Start the valid timer. 138 */ 139 void StartValidTimer (); 140 141 /** 142 * \brief Stop the preferred timer. 143 */ 144 void StopPreferredTimer (); 145 146 /** 147 * \brief Stop the valid timer. 148 */ 149 void StopValidTimer (); 150 151 /** 152 * \brief Set the prefix as preferred. 153 */ 154 void MarkPreferredTime (); 155 156 /** 157 * \brief Set the prefix as valid. 158 */ 159 void MarkValidTime (); 160 161 /** 162 * \brief Signal that the preferred time expired and start the valid timer. 163 */ 164 void FunctionPreferredTimeout (); 165 166 /** 167 * \brief Signal that the valid time expired. 168 */ 169 void FunctionValidTimeout (); 170 171 /** 172 * \brief Remove this prefix from the prefix list. 173 */ 174 void RemoveMe (); 175 176 /** 177 * \brief Get the prefix identifier. 178 * \return id of the prefix. 179 */ 180 uint32_t GetId () const; 181 182 /** 183 * \brief Get the prefix address. 184 * \return prefix address 185 */ 186 Ipv6Address GetPrefix () const; 187 188 /** 189 * \brief Set the prefix address. 190 * \param prefix prefix address to set 191 */ 192 void SetPrefix (Ipv6Address prefix); 193 194 /** 195 * \brief Get the bitmask prefix. 196 * \return bitmask prefix 197 */ 198 Ipv6Prefix GetMask () const; 199 200 /** 201 * \brief Set the bitmask prefix. 202 * \param mask prefix 203 */ 204 void SetMask (Ipv6Prefix mask); 205 206 private: 207 /** 208 * \brief a static identifier. 209 */ 210 static uint32_t m_prefixId; 211 212 /** 213 * \brief the identifier of this prefix. 214 */ 215 uint32_t m_id; 216 217 /** 218 * \brief The node. 219 */ 220 Ptr<Node> m_node; 221 222 /** 223 * \brief The prefix IPv6 address. 224 */ 225 Ipv6Address m_prefix; 226 227 /** 228 * \brief The prefix bitmask (length). 229 */ 230 Ipv6Prefix m_mask; 231 232 /** 233 * \brief Default gateway router. 234 * 235 * If the RA received also configured the default gateway, 236 * this variable has the link-local address. Otherwise this 237 * is "::" 238 */ 239 Ipv6Address m_defaultGatewayRouter; 240 241 /** 242 * \brief The interface index (which is stored the address 243 * corresponding of the prefix). 244 */ 245 uint32_t m_interface; 246 247 /** 248 * \brief the valid life time. 249 */ 250 uint32_t m_validLifeTime; 251 252 /** 253 * \brief the preferred life time. 254 */ 255 uint32_t m_preferredLifeTime; 256 257 /** 258 * \brief true if the prefix is preferred. 259 */ 260 bool m_preferred; 261 262 /** 263 * \brief true if the prefix is valid. 264 */ 265 bool m_valid; 266 267 /** 268 * \brief the timer for preferred life time. 269 */ 270 Timer m_preferredTimer; 271 272 /** 273 * \brief the timer for valid life time. 274 */ 275 Timer m_validTimer; 276 }; 277 278 } /* namespace ns3 */ 279 280 #endif /* IPV6_AUTOCONFIGURED_PREFIX_H */ 281 282