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