Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2013 Mohammed J.F. Alenazi | 3 * Copyright (c) 2013 Mohammed J.F. Alenazi |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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 | 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 | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> | 18 * Author: Mohammed J.F. Alenazi <malenazi@ittc.ku.edu> |
19 * | 19 * |
20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director | 20 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director |
21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets | 21 * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets |
22 * Information and Telecommunication Technology Center (ITTC) | 22 * Information and Telecommunication Technology Center (ITTC) |
23 * and Department of Electrical Engineering and Computer Science | 23 * and Department of Electrical Engineering and Computer Science |
24 * The University of Kansas Lawrence, KS USA. | 24 * The University of Kansas Lawrence, KS USA. |
25 * | 25 * |
26 * Work supported by King Saud University and the ITTC at The University of Kans as. | 26 * Work supported by King Saud University and |
27 * the ITTC at The University of Kansas. | |
27 */ | 28 */ |
29 | |
30 | |
31 #ifndef EPIDEMIC_PACKET_H | |
32 #define EPIDEMIC_PACKET_H | |
33 | |
28 | 34 |
29 #include <iostream> | 35 #include <iostream> |
30 #include "ns3/header.h" | 36 #include "ns3/header.h" |
31 #include "ns3/ipv4-address.h" | 37 #include "ns3/ipv4-address.h" |
32 #include "ns3/nstime.h" | 38 #include "ns3/nstime.h" |
33 | 39 #include "algorithm" |
34 | 40 |
41 /** | |
42 * \file | |
43 * \ingroup epidemic | |
44 * ns3::Epidemic::TypeHeader, ns3::Epidemic::SummaryVectorHeader | |
45 * and ns3::Epidemic::EpidemicHeader declarations. | |
46 */ | |
35 | 47 |
36 namespace ns3 { | 48 namespace ns3 { |
37 namespace epidemic { | 49 namespace Epidemic { |
38 | 50 |
39 enum MessageType | 51 |
40 { | 52 |
41 EPIDEMIC_TYPE_BEACON = 1, | 53 /** |
42 EPIDEMIC_TYPE_REPLY = 2, | 54 * \ingroup epidemic |
43 EPIDEMIC_TYPE_REPLY_BACK = 3, | 55 * \brief Epidemic routing packet type header. |
44 | 56 * |
45 }; | 57 * Epidemic routing packets come in three types: |
46 | 58 * |
47 /* | 59 * 1. Beacon Packet: it is used to advertise the presence of a node |
48 * Epidemic Type Header | 60 * in the network. |
49 * Three types: | 61 * 2. Reply Packet: once a beacon packet is received, it starts |
50 * 1. Beacon Packet: it is used to advertise the presence of a node in the network. | 62 * the anti-entropy session. |
Peter Barnes
2013/10/17 22:09:33
Please use smaller indent, and wrap long lines, so
| |
51 * 2. Reply Packet: once a beacon packet is received, it starts the anti-en tropy session. | 63 * 1. Packet with smaller network ID (i.e. IP) will send a reply packet, |
52 * 1. Packet with smaller network ID (i.e. IP) will send a reply pa cket, which contains | 64 * which contains summary vector of all the packet IDs in its buffer. |
53 * summary vector of all the packet IDs in its buffer. | 65 * 3. Reply Back Packet: once a reply packet is received, |
54 * 3. Reply Back Packet: once a reply packet is received, the receiver dete rmines the disjoint | 66 * the receiver determines the disjoint packets between its buffer |
55 * packets between its buffer and the received summary vector. Then , it sends the disjoint | 67 * and the received summary vector. Then, it sends the disjoint |
56 * packets the other node. After that, it sends a reply back packet containing a summary | 68 * packets the other node. After that, it sends a reply back packet |
57 * vector of all the packet IDs in its buffer so the other host sen ds the disjoint packets | 69 * containing a summary vector of all the packet IDs in its buffer |
58 * as well. | 70 * so the other host sends the disjoint packets as well. |
59 */ | 71 * |
72 * \verbatim | |
73 0 | |
74 0 1 2 3 4 5 6 7 | |
75 +-+-+-+-+-+-+-+-+ | |
76 | Type | | |
77 +-+-+-+-+-+-+-+-+ | |
78 * \endverbatim | |
Peter Barnes
2015/04/28 23:42:33
No '*' before \endverbatiim. (The '*' gets includ
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
79 */ | |
60 class TypeHeader : public Header | 80 class TypeHeader : public Header |
61 { | 81 { |
62 public: | 82 public: |
63 TypeHeader (MessageType t = EPIDEMIC_TYPE_BEACON); | 83 /// MessageType enum, several types for epidemic control packets |
Peter Barnes
2013/10/17 22:09:33
Doxygen needed everywhere.
| |
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 */ | |
64 static TypeId GetTypeId (); | 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 | |
65 TypeId GetInstanceTypeId () const; | 112 TypeId GetInstanceTypeId () const; |
66 void SetInstanceTypeId (MessageType type); | |
67 uint32_t GetSerializedSize () const; | 113 uint32_t GetSerializedSize () const; |
68 void Serialize (Buffer::Iterator start) const; | 114 void Serialize (Buffer::Iterator start) const; |
69 uint32_t Deserialize (Buffer::Iterator start); | 115 uint32_t Deserialize (Buffer::Iterator start); |
70 void Print (std::ostream &os) const; | 116 void Print (std::ostream &os) const; |
71 | 117 |
72 /// Return type | 118 /// \returns The message type. |
73 MessageType Get () const | 119 MessageType GetMessageType () const; |
74 { | 120 /** |
Peter Barnes
2013/10/17 22:09:33
Please move all inline bodies to epidemic-packet.c
| |
75 return m_type; | 121 * Check that this is a valid MessageType. |
Peter Barnes
2015/04/28 23:42:33
"Check that this is a message of the expected type
mjf.alenazi
2017/05/13 23:57:15
Done.
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
76 } | 122 * |
77 /// Check that type if valid | 123 * \param type The expected message type. |
78 bool IsValid () const | 124 * \return true if \p type matches the MessageType of this TypeHeader |
79 { | 125 */ |
80 return m_valid; | 126 bool IsMessageType (const MessageType type) const; |
81 } | 127 /// \return true if the MessageType of this TypeHeader is valid. |
128 bool IsValid () const; | |
129 /// \return true if \p o type is equal the MessageType of this TypeHeader | |
82 bool operator== (TypeHeader const & o) const; | 130 bool operator== (TypeHeader const & o) const; |
Peter Barnes
2015/04/28 23:42:33
Explicitly document the arguments:
* \param o …
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
83 private: | 131 private: |
132 /// message type | |
84 MessageType m_type; | 133 MessageType m_type; |
134 /** | |
135 Valid flag: \c true if the message deserialized correctly. | |
136 otherwise \c false. | |
137 */ | |
85 bool m_valid; | 138 bool m_valid; |
86 }; | 139 }; |
87 | 140 |
88 std::ostream & operator<< (std::ostream & os, TypeHeader const & h); | 141 |
Peter Barnes
2015/04/28 23:42:33
Yes, that's the point. If it's only in the .cc fi
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
89 | 142 |
90 | 143 |
91 | 144 /** |
92 /* | 145 * \ingroup epidemic |
93 * Epidemic Summary Vector Header | 146 * \brief Epidemic Summary Vector Header |
94 * This packet is used to carry the packet IDs of packets located in the host's buffer | 147 * This packet is used to carry the packet IDs of packets located |
95 * to the other node. | 148 * in the host's buffer to the other node. |
96 */ | 149 \verbatim |
97 | 150 0 1 2 3 |
98 | 151 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 |
99 class EpidemicSummaryVectorHeader : public Header | 152 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
153 | 32 bit Summary Vector Length | | |
154 + + | |
155 | | | |
156 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
157 | 32 bit Global ID for Packet # 1 | | |
158 + + | |
159 | | | |
160 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
161 | 32 bit Global ID for Packet # 2 | | |
162 | | | |
163 | . | | |
164 | . | | |
165 | . | | |
166 | | | |
167 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
168 | 32 bit Global ID for Packet # n | | |
169 + + | |
170 | | | |
171 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // Inherited-+-+-+-+-+-+-+-+-+-+-+-+- + | |
Peter Barnes
2015/04/28 23:42:33
Whoops. Remove extraneous insertion.
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
172 | |
173 \endverbatim | |
174 */ | |
175 | |
176 | |
177 class SummaryVectorHeader : public Header | |
100 { | 178 { |
101 public: | 179 public: |
102 EpidemicSummaryVectorHeader (std::vector<uint64_t> sv = std::vector<uint64_t> ()); | 180 /** |
Peter Barnes
2013/10/17 22:09:33
This design can be greatly improved. As is, you'r
| |
103 virtual ~EpidemicSummaryVectorHeader (); | 181 * \brief Constructor. |
182 */ | |
183 SummaryVectorHeader (size_t size2 = 0); | |
184 /** | |
185 * \brief Destructor. | |
186 */ | |
187 virtual ~SummaryVectorHeader (); | |
188 /** | |
189 * \brief return TypeID. | |
Peter Barnes
2015/04/28 23:42:33
* \return The object TypeId.
mjf.alenazi
2017/05/13 23:57:15
Done.
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
190 */ | |
104 static TypeId GetTypeId (void); | 191 static TypeId GetTypeId (void); |
192 // Inherited | |
105 virtual TypeId GetInstanceTypeId (void) const; | 193 virtual TypeId GetInstanceTypeId (void) const; |
106 virtual uint32_t GetSerializedSize () const; | 194 virtual uint32_t GetSerializedSize () const; |
107 virtual void Serialize (Buffer::Iterator start) const; | 195 virtual void Serialize (Buffer::Iterator start) const; |
108 virtual uint32_t Deserialize (Buffer::Iterator start); | 196 virtual uint32_t Deserialize (Buffer::Iterator start); |
109 virtual void Print (std::ostream &os) const; | 197 virtual void Print (std::ostream &os) const; |
110 | 198 |
111 void SetSummaryVector (std::vector<uint64_t> value) | 199 |
112 { | 200 /** |
113 m_summary_vector = value; | 201 * Add a global packet id. |
114 } | 202 * |
115 | 203 * \param pkt_ID The global packet id to add. |
116 std::vector<uint64_t> GetSummaryVector () | 204 */ |
117 { | 205 void Add (const uint32_t pkt_ID); |
118 return m_summary_vector; | 206 /** |
119 } | 207 * Check for a global packet id. |
208 * | |
209 * \param pkt_ID The global packet id to check for. | |
210 * \return True if the packet is in this summary vector. | |
211 */ | |
212 bool Contains (const uint32_t pkt_ID) const; | |
213 /** | |
214 * Get the number of entries. | |
215 * | |
216 * \return The number of global packet IDs in this header. | |
217 */ | |
218 size_t Size (void) const; | |
120 | 219 |
121 private: | 220 private: |
122 std::vector<uint64_t> m_summary_vector; | 221 /** |
222 * A vector to store packet IDs. | |
223 */ | |
224 std::vector<uint32_t> m_packets; | |
225 | |
226 // RoutingProtocol::SendDisjointPackets | |
227 // needs to iterate through the vector | |
228 friend class RoutingProtocol; | |
229 | |
123 }; | 230 }; |
124 | 231 |
125 static inline std::ostream & operator<< (std::ostream& os, const EpidemicSummary VectorHeader & packet) | 232 /** |
126 { | 233 * \ingroup epidemic |
127 packet.Print (os); | 234 * \brief Output streamer for EpidemicSummaryVectorHeader. |
128 return os; | 235 * |
129 } | 236 * \param os The stream. |
130 | 237 * \param packet The EpidemicSummaryVectorHeader. |
131 | 238 * \returns The stream. |
132 | 239 */ |
133 /* | 240 |
134 * Epidemic Header | 241 std::ostream &operator<< (std::ostream& os, |
135 * This packet header is added to a data packet in the source node once it is r eceived from | 242 const SummaryVectorHeader & packet); |
136 * the transport layer. It is removed in the receiver node before it is deliver ed to the transport layer. | 243 |
244 /** | |
245 * \ingroup epidemic | |
246 * \brief Epidemic Summary Vector Header | |
247 * | |
248 * This packet header is added to a data packet in the source node once it is | |
249 * received from the transport layer. It is removed in the receiver node | |
250 * before it is delivered to the transport layer. | |
137 * The Epidemic Header consists of three fields: | 251 * The Epidemic Header consists of three fields: |
138 * 1. Packet ID: global packet ID | 252 * |
139 * The format of a global packet ID is a concatenation of 32 bit se nder IP and | 253 * 1. Packet ID: global packet ID |
140 * a 32 bit sender data packet counter | 254 * |
141 *» » » 32 bit : 32 Bit | 255 * The format of a global packet ID is a concatenation of 16 bit sender IP |
Peter Barnes
2015/04/28 23:42:33
It's 32 bits in the diagram below. Which value is
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
142 * SENDER IP : SENDER PACKET COUNTER | 256 * and a 16 bit sender data packet counter. We call the packet ID global |
143 * We call the packet ID global packet ID to distinguish from the n s3 packet id. | 257 * packet ID to distinguish from the ns3 packet id. |
144 * | 258 * |
145 * 2. Flood Count: It is flood control parameter used to set the number of hops | 259 * 16 bit : 16 Bit |
146 * the packet can travel before it is discarded. It is similar to T TL field but | 260 * SENDER IP : SENDER PACKET COUNTER |
147 * with higher size limit. | 261 * 2. Hop Count: |
148 * 3. Timestampe : It show when the packet is generated. This field is use d to discard | 262 * |
149 * old packets with a time threshold limit set by the user. | 263 * It is flood control parameter used to set the number of hops |
264 * the packet can travel before it is discarded. It is similar to TTL | |
265 * field but with higher size limit. | |
266 * 3. Timestamp: | |
267 * | |
268 * It show when the packet is generated. This field is used | |
269 * to discard old packets with a time threshold limit set by the user. | |
270 * | |
271 * The complete header is formatted as follows: | |
272 \verbatim | |
273 0 1 2 3 | |
274 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 | |
275 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
276 | Sender IP Address | | |
277 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
278 | Sender Packet Counter | | |
279 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
280 | Hop Count | | |
281 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
282 | 64 Bit Timestamp | | |
283 | | | |
284 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
285 \endverbatim | |
150 */ | 286 */ |
151 | |
152 | |
153 | |
154 class EpidemicHeader : public Header | 287 class EpidemicHeader : public Header |
Peter Barnes
2015/04/28 23:42:33
This is only a problem if there is "using namespac
mjf.alenazi
2017/05/13 23:57:15
Acknowledged.
| |
155 { | 288 { |
156 public: | 289 public: |
157 EpidemicHeader (uint64_t pkt_ID = 0,uint32_t floodcount = 0, Time timeStamp = Seconds (0)); | 290 /** |
291 * \brief Destructor. | |
292 */ | |
158 virtual ~EpidemicHeader (); | 293 virtual ~EpidemicHeader (); |
294 /** | |
295 * \brief Get the registered TypeId for this class. | |
296 * \return The object TypeId. | |
297 */ | |
159 static TypeId GetTypeId (void); | 298 static TypeId GetTypeId (void); |
299 // Inherited | |
160 virtual TypeId GetInstanceTypeId (void) const; | 300 virtual TypeId GetInstanceTypeId (void) const; |
161 virtual uint32_t GetSerializedSize () const; | 301 virtual uint32_t GetSerializedSize () const; |
162 virtual void Serialize (Buffer::Iterator start) const; | 302 virtual void Serialize (Buffer::Iterator start) const; |
163 virtual uint32_t Deserialize (Buffer::Iterator start); | 303 virtual uint32_t Deserialize (Buffer::Iterator start); |
164 virtual void Print (std::ostream &os) const; | 304 virtual void Print (std::ostream &os) const; |
165 | 305 /** |
166 | 306 * \brief Set Packet ID for current packet |
167 void SetPacketID (uint64_t pktID) | 307 */ |
168 { | 308 void SetPacketID (uint32_t pktID); |
169 m_packetID = pktID; | 309 /** |
170 } | 310 * \brief Get Packet ID for current packet |
171 | 311 * \return packet ID |
172 uint64_t GetPacketID () const | 312 */ |
173 { | 313 uint32_t GetPacketID () const; |
174 return m_packetID; | 314 |
175 } | 315 /** |
176 | 316 * \brief Set Hop count for current packet |
177 | 317 */ |
178 | 318 void SetHopCount (uint32_t floodCount); |
179 void SetFloodCount (uint32_t floodCount) | 319 /** |
180 { | 320 * \brief Get Hop count for current packet |
181 m_hopCount = floodCount; | 321 * \return hop count |
182 } | 322 */ |
183 | 323 uint32_t GetHopCount () const; |
184 uint32_t GetFloodCount () const | 324 |
185 { | 325 /** |
186 return m_hopCount; | 326 * \brief Set Timestamp current packet |
187 } | 327 */ |
188 | 328 void SetTimeStamp (Time timeStamp); |
189 | 329 |
190 void SetTimeStamp (Time timeStamp) | 330 /** |
191 { | 331 * \brief Get Timestamp for current packet |
192 m_timeStamp = timeStamp; | 332 * \return timestamp |
193 } | 333 */ |
194 | 334 Time GetTimeStamp () const; |
195 Time GetTimeStamp () const | |
196 { | |
197 return m_timeStamp; | |
198 } | |
199 | 335 |
200 | 336 |
201 | 337 |
202 private: | 338 private: |
203 uint64_t m_packetID; // global packet ID | 339 uint32_t m_packetID; ///< global packet ID |
204 uint32_t m_hopCount; // Count to keep track of number of traveled hops | 340 uint32_t m_hopCount; ///< Count to keep track of number of traveled hops |
205 Time m_timeStamp; // Time at which packet was originated | 341 Time m_timeStamp; ///< Time at which packet was originated |
206 | 342 |
207 | 343 |
208 }; | 344 }; |
Peter Barnes
2015/04/28 23:42:33
It's not useful in the .cc file without a public d
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
209 | |
210 static inline std::ostream & operator<< (std::ostream& os, const EpidemicHeader & packet) | |
211 { | |
212 packet.Print (os); | |
213 return os; | |
214 } | |
215 } //end namespace epidemic | 345 } //end namespace epidemic |
216 } //end namespace ns3 | 346 } //end namespace ns3 |
347 #endif | |
LEFT | RIGHT |