OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2013 Mohammed J.F. Alenazi |
| 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: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> |
| 19 * |
| 20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
| 21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
| 22 * Information and Telecommunication Technology Center (ITTC) |
| 23 * and Department of Electrical Engineering and Computer Science |
| 24 * The University of Kansas Lawrence, KS USA. |
| 25 * |
| 26 * Work supported by King Saud University and |
| 27 * the ITTC at The University of Kansas. |
| 28 */ |
| 29 |
| 30 |
| 31 #ifndef EPIDEMIC_PACKET_H |
| 32 #define EPIDEMIC_PACKET_H |
| 33 |
| 34 |
| 35 #include <iostream> |
| 36 #include "ns3/header.h" |
| 37 #include "ns3/ipv4-address.h" |
| 38 #include "ns3/nstime.h" |
| 39 #include "algorithm" |
| 40 |
| 41 /** |
| 42 * \file |
| 43 * \ingroup epidemic |
| 44 * ns3::Epidemic::TypeHeader, ns3::Epidemic::SummaryVectorHeader |
| 45 * and ns3::Epidemic::EpidemicHeader declarations. |
| 46 */ |
| 47 |
| 48 namespace ns3 { |
| 49 namespace Epidemic { |
| 50 |
| 51 |
| 52 |
| 53 /** |
| 54 * \ingroup epidemic |
| 55 * \brief Epidemic routing packet type header. |
| 56 * |
| 57 * Epidemic routing packets come in three types: |
| 58 * |
| 59 * 1. Beacon Packet: it is used to advertise the presence of a node |
| 60 * in the network. |
| 61 * 2. Reply Packet: once a beacon packet is received, it starts |
| 62 * the anti-entropy session. |
| 63 * 1. Packet with smaller network ID (i.e. IP) will send a reply packet, |
| 64 * which contains summary vector of all the packet IDs in its buffer. |
| 65 * 3. Reply Back Packet: once a reply packet is received, |
| 66 * the receiver determines the disjoint packets between its buffer |
| 67 * and the received summary vector. Then, it sends the disjoint |
| 68 * packets the other node. After that, it sends a reply back packet |
| 69 * containing a summary vector of all the packet IDs in its buffer |
| 70 * so the other host sends the disjoint packets as well. |
| 71 * |
| 72 \verbatim |
| 73 0 |
| 74 0 1 2 3 4 5 6 7 |
| 75 +-+-+-+-+-+-+-+-+ |
| 76 | Type | |
| 77 +-+-+-+-+-+-+-+-+ |
| 78 \endverbatim |
| 79 */ |
| 80 class TypeHeader : public Header |
| 81 { |
| 82 public: |
| 83 /// MessageType enum, several types for epidemic control packets |
| 84 enum MessageType |
| 85 { |
| 86 BEACON, //!< Advertise the presence of a node |
| 87 REPLY, //!< Reply to a beacon, with the packet Id summary vector |
| 88 REPLY_BACK, //!< Response to a Reply packet, as list of disjoint packets. |
| 89 |
| 90 }; |
| 91 |
| 92 /** |
| 93 * \brief Constructor. |
| 94 * \param t Header message type. |
| 95 */ |
| 96 TypeHeader (MessageType t = BEACON); |
| 97 /** |
| 98 * \brief Destructor. |
| 99 */ |
| 100 ~TypeHeader (); |
| 101 /** |
| 102 * Get the registered TypeId for this class. |
| 103 * \return The object TypeId. |
| 104 */ |
| 105 static TypeId GetTypeId (); |
| 106 /** |
| 107 * \brief Set the instance type ID. |
| 108 * \param type message type to be set. |
| 109 */ |
| 110 void SetMessageType (MessageType type); |
| 111 // Inherited |
| 112 TypeId GetInstanceTypeId () const; |
| 113 uint32_t GetSerializedSize () const; |
| 114 void Serialize (Buffer::Iterator start) const; |
| 115 uint32_t Deserialize (Buffer::Iterator start); |
| 116 void Print (std::ostream &os) const; |
| 117 |
| 118 /// \returns The message type. |
| 119 MessageType GetMessageType () const; |
| 120 /** |
| 121 * Check that this is a message of the expected type. |
| 122 * |
| 123 * \param type The expected message type. |
| 124 * \return true if \p type matches the MessageType of this TypeHeader |
| 125 */ |
| 126 bool IsMessageType (const MessageType type) const; |
| 127 /// \return true if the MessageType of this TypeHeader is valid. |
| 128 bool IsValid () const; |
| 129 /** |
| 130 * \brief Comparison operator |
| 131 * \param o header to compare |
| 132 * \return true if the headers are equal |
| 133 */ |
| 134 bool operator== (TypeHeader const & o) const; |
| 135 private: |
| 136 /// message type |
| 137 MessageType m_type; |
| 138 /** |
| 139 Valid flag: \c true if the message deserialized correctly. |
| 140 otherwise \c false. |
| 141 */ |
| 142 bool m_valid; |
| 143 }; |
| 144 |
| 145 /** |
| 146 * \brief Stream output operator |
| 147 * \param os output stream |
| 148 * \return updated stream |
| 149 */ |
| 150 std::ostream & operator<< (std::ostream & os, TypeHeader const & h); |
| 151 |
| 152 |
| 153 /** |
| 154 * \ingroup epidemic |
| 155 * \brief Epidemic Summary Vector Header |
| 156 * This packet is used to carry the packet IDs of packets located |
| 157 * in the host's buffer to the other node. |
| 158 \verbatim |
| 159 0 1 2 3 |
| 160 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 161 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 162 | 32 bit Summary Vector Length | |
| 163 + + |
| 164 | | |
| 165 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 166 | 32 bit Global ID for Packet # 1 | |
| 167 + + |
| 168 | | |
| 169 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 170 | 32 bit Global ID for Packet # 2 | |
| 171 | | |
| 172 | . | |
| 173 | . | |
| 174 | . | |
| 175 | | |
| 176 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 177 | 32 bit Global ID for Packet # n | |
| 178 + + |
| 179 | | |
| 180 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 181 \endverbatim |
| 182 */ |
| 183 |
| 184 |
| 185 class SummaryVectorHeader : public Header |
| 186 { |
| 187 public: |
| 188 /** |
| 189 * \brief Constructor. |
| 190 */ |
| 191 SummaryVectorHeader (size_t size2 = 0); |
| 192 /** |
| 193 * \brief Destructor. |
| 194 */ |
| 195 virtual ~SummaryVectorHeader (); |
| 196 /** |
| 197 * \return The object TypeId. |
| 198 */ |
| 199 static TypeId GetTypeId (void); |
| 200 // Inherited |
| 201 virtual TypeId GetInstanceTypeId (void) const; |
| 202 virtual uint32_t GetSerializedSize () const; |
| 203 virtual void Serialize (Buffer::Iterator start) const; |
| 204 virtual uint32_t Deserialize (Buffer::Iterator start); |
| 205 virtual void Print (std::ostream &os) const; |
| 206 |
| 207 |
| 208 /** |
| 209 * Add a global packet id. |
| 210 * |
| 211 * \param pkt_ID The global packet id to add. |
| 212 */ |
| 213 void Add (const uint32_t pkt_ID); |
| 214 /** |
| 215 * Check for a global packet id. |
| 216 * |
| 217 * \param pkt_ID The global packet id to check for. |
| 218 * \return True if the packet is in this summary vector. |
| 219 */ |
| 220 bool Contains (const uint32_t pkt_ID) const; |
| 221 /** |
| 222 * Get the number of entries. |
| 223 * |
| 224 * \return The number of global packet IDs in this header. |
| 225 */ |
| 226 size_t Size (void) const; |
| 227 |
| 228 private: |
| 229 /** |
| 230 * A vector to store packet IDs. |
| 231 */ |
| 232 std::vector<uint32_t> m_packets; |
| 233 |
| 234 // RoutingProtocol::SendDisjointPackets |
| 235 // needs to iterate through the vector |
| 236 friend class RoutingProtocol; |
| 237 |
| 238 }; |
| 239 |
| 240 /** |
| 241 * \ingroup epidemic |
| 242 * \brief Output streamer for EpidemicSummaryVectorHeader. |
| 243 * |
| 244 * \param os The stream. |
| 245 * \param packet The EpidemicSummaryVectorHeader. |
| 246 * \returns The stream. |
| 247 */ |
| 248 |
| 249 std::ostream &operator<< (std::ostream& os, |
| 250 const SummaryVectorHeader & packet); |
| 251 |
| 252 /** |
| 253 * \ingroup epidemic |
| 254 * \brief Epidemic Summary Vector Header |
| 255 * |
| 256 * This packet header is added to a data packet in the source node once it is |
| 257 * received from the transport layer. It is removed in the receiver node |
| 258 * before it is delivered to the transport layer. |
| 259 * The Epidemic Header consists of three fields: |
| 260 * |
| 261 * 1. Packet ID: global packet ID |
| 262 * |
| 263 * The format of a global packet ID is a concatenation of 16 bit sender IP |
| 264 * and a 16 bit sender data packet counter. We call the packet ID global |
| 265 * packet ID to distinguish from the ns3 packet id. |
| 266 * |
| 267 * 16 bit : 16 Bit |
| 268 * SENDER IP : SENDER PACKET COUNTER |
| 269 * 2. Hop Count: |
| 270 * |
| 271 * It is flood control parameter used to set the number of hops |
| 272 * the packet can travel before it is discarded. It is similar to TTL |
| 273 * field but with higher size limit. |
| 274 * 3. Timestamp: |
| 275 * |
| 276 * It show when the packet is generated. This field is used |
| 277 * to discard old packets with a time threshold limit set by the user. |
| 278 * |
| 279 * The complete header is formatted as follows: |
| 280 \verbatim |
| 281 0 1 2 3 |
| 282 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 283 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 284 | Packet ID | |
| 285 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 286 | Hop Count | |
| 287 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 288 | 64 Bit Timestamp | |
| 289 | | |
| 290 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 291 \endverbatim |
| 292 */ |
| 293 class EpidemicHeader : public Header |
| 294 { |
| 295 public: |
| 296 /** |
| 297 * \brief Destructor. |
| 298 */ |
| 299 virtual ~EpidemicHeader (); |
| 300 /** |
| 301 * \brief Get the registered TypeId for this class. |
| 302 * \return The object TypeId. |
| 303 */ |
| 304 static TypeId GetTypeId (void); |
| 305 // Inherited |
| 306 virtual TypeId GetInstanceTypeId (void) const; |
| 307 virtual uint32_t GetSerializedSize () const; |
| 308 virtual void Serialize (Buffer::Iterator start) const; |
| 309 virtual uint32_t Deserialize (Buffer::Iterator start); |
| 310 virtual void Print (std::ostream &os) const; |
| 311 /** |
| 312 * \brief Set Packet ID for current packet |
| 313 */ |
| 314 void SetPacketID (uint32_t pktID); |
| 315 /** |
| 316 * \brief Get Packet ID for current packet |
| 317 * \return packet ID |
| 318 */ |
| 319 uint32_t GetPacketID () const; |
| 320 |
| 321 /** |
| 322 * \brief Set Hop count for current packet |
| 323 */ |
| 324 void SetHopCount (uint32_t floodCount); |
| 325 /** |
| 326 * \brief Get Hop count for current packet |
| 327 * \return hop count |
| 328 */ |
| 329 uint32_t GetHopCount () const; |
| 330 |
| 331 /** |
| 332 * \brief Set Timestamp current packet |
| 333 */ |
| 334 void SetTimeStamp (Time timeStamp); |
| 335 |
| 336 /** |
| 337 * \brief Get Timestamp for current packet |
| 338 * \return timestamp |
| 339 */ |
| 340 Time GetTimeStamp () const; |
| 341 |
| 342 |
| 343 |
| 344 private: |
| 345 uint32_t m_packetID; ///< global packet ID |
| 346 uint32_t m_hopCount; ///< Count to keep track of number of traveled hops |
| 347 Time m_timeStamp; ///< Time at which packet was originated |
| 348 |
| 349 |
| 350 }; |
| 351 /** |
| 352 * \ingroup epidemic |
| 353 * \brief Output streamer for EpidemicHeader. |
| 354 * |
| 355 * \param os The stream. |
| 356 * \param header The EpidemicHeader. |
| 357 * \returns The stream. |
| 358 */ |
| 359 |
| 360 std::ostream &operator<< (std::ostream& os, |
| 361 const EpidemicHeader & header); |
| 362 |
| 363 } //end namespace epidemic |
| 364 } //end namespace ns3 |
| 365 #endif |
OLD | NEW |