Left: | ||
Right: |
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 | |
Peter Barnes
2015/04/28 23:42:33
No '*' before \endverbatiim. (The '*' gets includ
mjf.alenazi
2017/05/13 23:57:15
Done.
| |
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 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.
| |
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 /// \return true if \p o type is equal the MessageType of this TypeHeader | |
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.
| |
131 private: | |
132 /// message type | |
133 MessageType m_type; | |
134 /** | |
135 Valid flag: \c true if the message deserialized correctly. | |
136 otherwise \c false. | |
137 */ | |
138 bool m_valid; | |
139 }; | |
140 | |
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.
| |
142 | |
143 | |
144 /** | |
145 * \ingroup epidemic | |
146 * \brief Epidemic Summary Vector Header | |
147 * This packet is used to carry the packet IDs of packets located | |
148 * in the host's buffer to the other node. | |
149 \verbatim | |
150 0 1 2 3 | |
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 | |
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 | |
178 { | |
179 public: | |
180 /** | |
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 */ | |
191 static TypeId GetTypeId (void); | |
192 // Inherited | |
193 virtual TypeId GetInstanceTypeId (void) const; | |
194 virtual uint32_t GetSerializedSize () const; | |
195 virtual void Serialize (Buffer::Iterator start) const; | |
196 virtual uint32_t Deserialize (Buffer::Iterator start); | |
197 virtual void Print (std::ostream &os) const; | |
198 | |
199 | |
200 /** | |
201 * Add a global packet id. | |
202 * | |
203 * \param pkt_ID The global packet id to add. | |
204 */ | |
205 void Add (const uint32_t pkt_ID); | |
206 /** | |
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; | |
219 | |
220 private: | |
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 | |
230 }; | |
231 | |
232 /** | |
233 * \ingroup epidemic | |
234 * \brief Output streamer for EpidemicSummaryVectorHeader. | |
235 * | |
236 * \param os The stream. | |
237 * \param packet The EpidemicSummaryVectorHeader. | |
238 * \returns The stream. | |
239 */ | |
240 | |
241 std::ostream &operator<< (std::ostream& os, | |
242 const SummaryVectorHeader & packet); | |
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. | |
251 * The Epidemic Header consists of three fields: | |
252 * | |
253 * 1. Packet ID: global packet ID | |
254 * | |
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.
| |
256 * and a 16 bit sender data packet counter. We call the packet ID global | |
257 * packet ID to distinguish from the ns3 packet id. | |
258 * | |
259 * 16 bit : 16 Bit | |
260 * SENDER IP : SENDER PACKET COUNTER | |
261 * 2. Hop Count: | |
262 * | |
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 | |
286 */ | |
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.
| |
288 { | |
289 public: | |
290 /** | |
291 * \brief Destructor. | |
292 */ | |
293 virtual ~EpidemicHeader (); | |
294 /** | |
295 * \brief Get the registered TypeId for this class. | |
296 * \return The object TypeId. | |
297 */ | |
298 static TypeId GetTypeId (void); | |
299 // Inherited | |
300 virtual TypeId GetInstanceTypeId (void) const; | |
301 virtual uint32_t GetSerializedSize () const; | |
302 virtual void Serialize (Buffer::Iterator start) const; | |
303 virtual uint32_t Deserialize (Buffer::Iterator start); | |
304 virtual void Print (std::ostream &os) const; | |
305 /** | |
306 * \brief Set Packet ID for current packet | |
307 */ | |
308 void SetPacketID (uint32_t pktID); | |
309 /** | |
310 * \brief Get Packet ID for current packet | |
311 * \return packet ID | |
312 */ | |
313 uint32_t GetPacketID () const; | |
314 | |
315 /** | |
316 * \brief Set Hop count for current packet | |
317 */ | |
318 void SetHopCount (uint32_t floodCount); | |
319 /** | |
320 * \brief Get Hop count for current packet | |
321 * \return hop count | |
322 */ | |
323 uint32_t GetHopCount () const; | |
324 | |
325 /** | |
326 * \brief Set Timestamp current packet | |
327 */ | |
328 void SetTimeStamp (Time timeStamp); | |
329 | |
330 /** | |
331 * \brief Get Timestamp for current packet | |
332 * \return timestamp | |
333 */ | |
334 Time GetTimeStamp () const; | |
335 | |
336 | |
337 | |
338 private: | |
339 uint32_t m_packetID; ///< global packet ID | |
340 uint32_t m_hopCount; ///< Count to keep track of number of traveled hops | |
341 Time m_timeStamp; ///< Time at which packet was originated | |
342 | |
343 | |
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.
| |
345 } //end namespace epidemic | |
346 } //end namespace ns3 | |
347 #endif | |
OLD | NEW |