1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2008,2009 IITP RAS 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: Kirill Andreev <andreev@iitp.ru> 19 */ 20 21 #ifndef WIFI_PREQ_INFORMATION_ELEMENT_H 22 #define WIFI_PREQ_INFORMATION_ELEMENT_H 23 24 #include <vector> 25 26 #include "ns3/mac48-address.h" 27 #include "ns3/mesh-information-element-vector.h" 28 29 namespace ns3 { 30 namespace dot11s { 31 /** 32 * \ingroup dot11s 33 * \brief Describes an address unit in PREQ information element 34 * See 7.3.2.96 for more details 35 */ 36 class DestinationAddressUnit : public SimpleRefCount<DestinationAddressUnit> 37 { 38 public: 39 DestinationAddressUnit (); 40 /** 41 * Set flags function 42 * \param doFlag the DO flag 43 * \param rfFlag the RF flag 44 * \param usnFlag the USN flag 45 */ 46 void SetFlags (bool doFlag, bool rfFlag, bool usnFlag); 47 /** 48 * Set destination address function 49 * \param dest_address the destination MAC address 50 */ 51 void SetDestinationAddress (Mac48Address dest_address); 52 /** 53 * Set destination sequence number 54 * \param dest_seq_number the destination sequence number 55 */ 56 void SetDestSeqNumber (uint32_t dest_seq_number); 57 /** 58 * Is do function 59 * \returns true if DO flag is set 60 */ 61 bool IsDo (); 62 /** 63 * is RF function 64 * \returns true if RF flag is set 65 */ 66 bool IsRf (); 67 /** 68 * Is USN function 69 * \returns true if USN flag set 70 */ 71 bool IsUsn (); 72 /** 73 * Get destination address function 74 * \returns the MAC address 75 */ 76 Mac48Address GetDestinationAddress () const; 77 /** 78 * Get destination sequence number 79 * \returns the destination sequence number 80 */ 81 uint32_t GetDestSeqNumber () const; 82 private: 83 bool m_do; ///< DO 84 bool m_rf; ///< RF 85 bool m_usn; ///< USN 86 Mac48Address m_destinationAddress; ///< destination address 87 uint32_t m_destSeqNumber; ///< destination sequence number 88 89 /** 90 * equality operator 91 * 92 * \param a lhs 93 * \param b rhs 94 * \returns true if equal 95 */ 96 friend bool operator== (const DestinationAddressUnit & a, const DestinationAddressUnit & b); 97 }; 98 /** 99 * \ingroup dot11s 100 * \brief See 7.3.2.96 of 802.11s draft 2.07 101 */ 102 class IePreq : public WifiInformationElement 103 { 104 public: 105 IePreq (); 106 ~IePreq (); 107 /** 108 * Add a destination address unit: flags, destination and sequence 109 * number 110 * 111 * \param doFlag 112 * \param rfFlag 113 * \param dest_address 114 * \param dest_seq_number 115 */ 116 void AddDestinationAddressElement ( 117 bool doFlag, 118 bool rfFlag, 119 Mac48Address dest_address, 120 uint32_t dest_seq_number 121 ); 122 /** 123 * Delete a destination address unit by destination 124 * \param dest_address the destination address 125 */ 126 void DelDestinationAddressElement (Mac48Address dest_address); 127 /// Clear PREQ: remove all destinations 128 void ClearDestinationAddressElements (); 129 /** 130 * Get all destinations, which are stored in PREQ: 131 * \returns the list of destination addresses 132 */ 133 std::vector<Ptr<DestinationAddressUnit> > GetDestinationList (); 134 /// Set flag indicating that PREQ is unicast 135 void SetUnicastPreq (); 136 /** 137 * \brief Set Proactive PREP subfield to off 138 */ 139 void SetNeedNotPrep (); 140 141 // Setters for fields: 142 /** 143 * Set number of hops from originator to mesh STA transmitting this 144 * element 145 * \param hopcount the hop count 146 */ 147 void SetHopcount (uint8_t hopcount); 148 /** 149 * Set remaining number of hops allowed for this element 150 * \param ttl the TTL 151 */ 152 void SetTTL (uint8_t ttl); 153 /** 154 * Set path discovery id field 155 * \param id some unique id for this path discovery 156 */ 157 void SetPreqID (uint32_t id); 158 /** 159 * Set originator address value 160 * \param originator_address the originator MAC address 161 */ 162 void SetOriginatorAddress (Mac48Address originator_address); 163 /** 164 * Set originator sequence number 165 * \param originator_seq_number 166 */ 167 void SetOriginatorSeqNumber (uint32_t originator_seq_number); 168 /** 169 * Set lifetime in TUs for the forwarding information to be considered valid 170 * \param lifetime the lifetime in TUs 171 */ 172 void SetLifetime (uint32_t lifetime); 173 /** 174 * Set metric value 175 * \param metric the metric 176 */ 177 void SetMetric (uint32_t metric); 178 /** 179 * Set destination count value 180 * \param dest_count the destination count 181 */ 182 void SetDestCount (uint8_t dest_count); 183 184 // Getters for fields: 185 /** 186 * Is unicast PREQ function 187 * \returns true if unicast PREQ 188 */ 189 bool IsUnicastPreq () const; 190 /** 191 * Check whether Proactive PREP subfield to off 192 * \returns true if need not Proactive PREP subfield is off 193 */ 194 bool IsNeedNotPrep () const; 195 /** 196 * Get hop count value 197 * \returns the hop count 198 */ 199 uint8_t GetHopCount () const; 200 /** 201 * Get TTL value 202 * \returns the TTL 203 */ 204 uint8_t GetTtl () const; 205 /** 206 * Get path discovery id field 207 * \returns the path discovery ID 208 */ 209 uint32_t GetPreqID () const; 210 /** 211 * Get originator address value 212 * \returns the originator MAC address 213 */ 214 Mac48Address GetOriginatorAddress () const; 215 /** 216 * Get originator sequence numnber value 217 * \returns the originator sequence number 218 */ 219 uint32_t GetOriginatorSeqNumber () const; 220 /** 221 * Get lifetime value 222 * \returns the lifetime in TUs 223 */ 224 uint32_t GetLifetime () const; 225 /** 226 * Get metric value 227 * \returns the metric 228 */ 229 uint32_t GetMetric () const; 230 /** 231 * Get destination count 232 * \returns the destination count 233 */ 234 uint8_t GetDestCount () const; 235 236 /// Handle TTL 237 void DecrementTtl (); 238 /** 239 * Handle Metric: 240 * \param metric the mteric to increment 241 */ 242 void IncrementMetric (uint32_t metric); 243 /** 244 * \brief Checks that preq's originator address equals to originator, and 245 * this preq is not proactive 246 * \param originator the originator address 247 * \returns true if it may add 248 */ 249 bool MayAddAddress (Mac48Address originator); 250 /** 251 * Is full function 252 * \returns true if full 253 */ 254 bool IsFull () const; 255 256 // Inherited from WifiInformationElement 257 virtual WifiInformationElementId ElementId () const; 258 virtual void SerializeInformationField (Buffer::Iterator i) const; 259 virtual uint8_t DeserializeInformationField (Buffer::Iterator i, uint8_t length); 260 virtual uint8_t GetInformationFieldSize () const; 261 virtual void Print (std::ostream& os) const; 262 263 private: 264 /** 265 * how many destinations we support 266 * \todo make as an attribute 267 */ 268 uint8_t m_maxSize; 269 270 uint8_t m_flags; ///< flags 271 uint8_t m_hopCount; ///< hop count 272 uint8_t m_ttl; ///< TTL 273 uint32_t m_preqId; ///< PREQ ID 274 Mac48Address m_originatorAddress; ///< originator address 275 uint32_t m_originatorSeqNumber; ///< originator sequence number 276 uint32_t m_lifetime; ///< lifetime 277 uint32_t m_metric; ///< metric 278 uint8_t m_destCount; ///< destination count 279 std::vector<Ptr<DestinationAddressUnit> > m_destinations; ///< the destinations 280 281 /** 282 * equality operator 283 * 284 * \param a lhs 285 * \param b rhs 286 * \returns true if equal 287 */ 288 friend bool operator== (const IePreq & a, const IePreq & b); 289 }; 290 291 bool operator== (const DestinationAddressUnit & a, const DestinationAddressUnit & b); 292 bool operator== (const IePreq & a, const IePreq & b); 293 std::ostream &operator << (std::ostream &os, const IePreq &preq); 294 295 } // namespace dot11s 296 } // namespace ns3 297 #endif 298 299