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 | |
29 #include <iostream> | |
30 #include "ns3/header.h" | |
31 #include "ns3/ipv4-address.h" | |
32 #include "ns3/nstime.h" | |
33 | |
34 | |
35 | |
36 namespace ns3 { | |
37 namespace epidemic { | |
38 | |
39 enum MessageType | |
40 { | |
41 EPIDEMIC_TYPE_BEACON = 1, //!< EPIDEMIC_TYPE_BEACON | |
Peter Barnes
2014/01/07 23:57:09
1. Not helpful to just repeat the symbol name. W
mjf.alenazi
2014/01/18 02:23:04
It is not assigned in the paper.
On 2014/01/07 23
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
42 EPIDEMIC_TYPE_REPLY = 2, //!< EPIDEMIC_TYPE_REPLY | |
Peter Barnes
2014/01/07 23:57:09
//!< Reply to a beacon, with the packet Id summary
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
43 EPIDEMIC_TYPE_REPLY_BACK = 3, //!< EPIDEMIC_TYPE_REPLY_BACK | |
Peter Barnes
2014/01/07 23:57:09
//!< Response to a Reply packet, with the list of
mjf.alenazi
2014/01/18 02:23:04
Done.
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
44 | |
45 }; | |
46 | |
47 | |
48 /** | |
49 * \ingroup epidemic | |
50 * \brief Epidemic routing packets come in three types:: | |
Peter Barnes
2014/01/07 23:57:09
See previous comment on this line. Your edit now
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
51 * 1. Beacon Packet: it is used to advertise the presence of a node in the net work. | |
52 * 2. Reply Packet: once a beacon packet is received, it starts the anti-entro py session. | |
53 * 1. Packet with smaller network ID (i.e. IP) will send a reply packet, wh ich contains | |
54 * summary vector of all the packet IDs in its buffer. | |
55 * 3. Reply Back Packet: once a reply packet is received, the receiver determi nes the disjoint | |
56 * packets between its buffer and the received summary vector. Then, it sen ds the disjoint | |
57 * packets the other node. After that, it sends a reply back packet contain ing a summary | |
58 * vector of all the packet IDs in its buffer so the other host sends the d isjoint packets | |
59 * as well. | |
60 \verbatim | |
61 0 | |
62 0 1 2 3 4 5 6 7 | |
63 +-+-+-+-+-+-+-+-+ | |
64 | Type | | |
65 +-+-+-+-+-+-+-+-+ | |
66 \endverbatim | |
67 * \ingroup epidemic | |
68 * \brief Epidemic types | |
Peter Barnes
2014/01/07 23:57:09
A single \brief, please, at the beginning of the c
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
69 */ | |
70 class TypeHeader : public Header | |
Peter Barnes
2014/01/07 23:57:09
Seems like TypeHeader and EpidemicHeader could/sho
mjf.alenazi
2014/01/18 02:23:04
No, Type header is for identifying which header is
| |
71 { | |
72 public: | |
73 /** | |
74 * \brief Constructor. | |
75 */ | |
76 TypeHeader (MessageType t = EPIDEMIC_TYPE_BEACON); | |
77 /** | |
78 * \brief Destructor. | |
79 */ | |
80 ~TypeHeader (); | |
81 /** | |
82 * \brief Get the type identificator. | |
83 * \return type identificator | |
84 */ | |
85 static TypeId GetTypeId (); | |
86 /** | |
87 * \brief Get the instance type ID. | |
88 * \return instance type ID | |
89 */ | |
90 TypeId GetInstanceTypeId () const; | |
91 /** | |
92 * \brief Set the instance type ID. | |
93 */ | |
94 void SetInstanceTypeId (MessageType type); | |
Peter Barnes
2014/01/07 23:57:09
SetMessageType ()
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
95 /** | |
96 * \brief Get the serialized size of the packet. | |
97 * \return size | |
98 */ | |
99 uint32_t GetSerializedSize () const; | |
100 /** | |
101 * \brief Serialize all added options. | |
102 * \param start Buffer iterator | |
103 */ | |
104 void Serialize (Buffer::Iterator start) const; | |
105 /** | |
106 * \brief Deserialize the packet. | |
107 * \param start Buffer iterator | |
108 * \return size of the packet | |
109 */ | |
110 uint32_t Deserialize (Buffer::Iterator start); | |
111 /** | |
112 * \brief Print some informations about the packet. | |
113 * \param os output stream | |
114 * \return info about this packet | |
Peter Barnes
2014/01/07 23:57:09
No return
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
115 */ | |
116 void Print (std::ostream &os) const; | |
117 | |
118 /// Return type | |
119 MessageType Get () const; | |
Peter Barnes
2014/01/07 23:57:09
GetMessageType ()
mjf.alenazi
2014/01/18 02:23:04
Done.
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
120 /// Check that type if valid | |
121 bool IsValid () const; | |
122 /// Compare the type header | |
123 bool operator== (TypeHeader const & o) const; | |
124 private: | |
125 /// message type | |
126 MessageType m_type; | |
127 /// flag | |
Peter Barnes
2014/01/07 23:57:09
What defines "valid"?
mjf.alenazi
2014/01/18 02:23:04
In the TypeHeader::Deserialize fucntions
On 2014/0
| |
128 bool m_valid; | |
129 }; | |
130 | |
131 std::ostream & operator<< (std::ostream & os, TypeHeader const & h); | |
132 | |
133 | |
134 /** | |
135 * \ingroup epidemic | |
136 * \brief Epidemic Summary Vector Header | |
137 * This packet is used to carry the packet IDs of packets located | |
138 * in the host's buffer to the other node. | |
139 \verbatim | |
140 0 1 2 3 | |
141 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 | |
142 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
143 | 64 bit Summary Vector Length | | |
144 + + | |
145 | | | |
146 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
147 | 64 bit Global ID for Packet # 1 | | |
148 + + | |
149 | | | |
150 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
151 | 64 bit Global ID for Packet # 2 | | |
152 + + | |
153 | | | |
154 | . | | |
155 | . | | |
156 | . | | |
157 | | | |
158 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
159 | 64 bit Global ID for Packet # n | | |
160 + + | |
161 | | | |
162 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
163 | |
164 \endverbatim | |
165 */ | |
166 | |
167 | |
168 class EpidemicSummaryVectorHeader : public Header | |
Peter Barnes
2014/01/07 23:57:09
Since this is already in namespace ns3::epidemic,
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
169 { | |
170 public: | |
171 /** | |
172 * \brief Constructor. | |
173 */ | |
174 EpidemicSummaryVectorHeader (std::vector<uint64_t> sv = std::vector<uint64_t> ()); | |
175 /** | |
176 * \brief Destructor. | |
177 */ | |
178 virtual ~EpidemicSummaryVectorHeader (); | |
179 ///\name Fields | |
180 //\{ | |
181 static TypeId GetTypeId (void); | |
182 virtual TypeId GetInstanceTypeId (void) const; | |
183 virtual uint32_t GetSerializedSize () const; | |
184 virtual void Serialize (Buffer::Iterator start) const; | |
185 virtual uint32_t Deserialize (Buffer::Iterator start); | |
186 virtual void Print (std::ostream &os) const; | |
187 //\} | |
188 /** | |
189 * \brief Set SummaryVector | |
190 */ | |
191 void SetSummaryVector (std::vector<uint64_t> value); | |
192 /** | |
193 * \brief Get SummaryVector | |
194 */ | |
195 std::vector<uint64_t> GetSummaryVector (); | |
196 private: | |
197 /// List of packets in the epidemic buffer | |
198 std::vector<uint64_t> m_summary_vector; | |
199 }; | |
200 | |
201 static inline std::ostream & operator<< (std::ostream& os, const EpidemicSummary VectorHeader & packet) | |
Peter Barnes
2014/01/07 23:57:09
static std::ostream & operator<< (…)
Move the imp
mjf.alenazi
2014/01/18 02:23:04
Done.
| |
202 { | |
203 packet.Print (os); | |
204 return os; | |
205 } | |
206 | |
207 /** | |
208 * \ingroup epidemic | |
209 * \brief Epidemic Packet Header | |
210 * This packet header is added to a data packet in the source node once it is | |
211 * received from the transport layer. It is removed in the receiver node before it | |
212 * is delivered to the transport layer. | |
213 * The Epidemic Header consists of three fields: | |
214 * 1. Packet ID: global packet ID | |
215 * The format of a global packet ID is a concatenation of 32 bit sender IP and | |
216 * a 32 bit sender data packet counter | |
217 * 32 bit : 32 Bit | |
218 * SENDER IP : SENDER PACKET COUNTER | |
219 * We call the packet ID global packet ID to distinguish from the ns3 packe t id. | |
220 * | |
221 * 2. Hop Count: It is flood control parameter used to set the number of hops | |
222 * the packet can travel before it is discarded. It is similar to TTL fiel d but | |
223 * with higher size limit. | |
224 * 3. Timestampe : It show when the packet is generated. This field is used to discard | |
225 * old packets with a time threshold limit set by the user. | |
226 \verbatim | |
227 0 1 2 3 | |
228 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 | |
229 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
230 | Sender IP Address | | |
231 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
232 | Sender Packet Counter | | |
233 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
234 | Hop Count | | |
235 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| | |
236 | 64 Bit Timestamp | | |
237 + + | |
238 | | | |
239 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
240 \endverbatim | |
241 */ | |
242 | |
243 class EpidemicHeader : public Header | |
Peter Barnes
2014/01/07 23:57:09
Seems like TypeHeader and EpidemicHeader could/sho
mjf.alenazi
2014/01/18 02:23:04
No, Type header is for identifying which header is
| |
244 { | |
245 public: | |
246 /** | |
247 * \brief Constructor. | |
248 */ | |
249 EpidemicHeader (uint64_t pkt_ID = 0,uint32_t hopCount = 0, Time timeStamp = Se conds (0)); | |
250 /** | |
251 * \brief Destructor. | |
252 */ | |
253 virtual ~EpidemicHeader (); | |
254 ///\name Header serialization/deserialization | |
255 //\{ | |
256 static TypeId GetTypeId (void); | |
257 virtual TypeId GetInstanceTypeId (void) const; | |
258 virtual uint32_t GetSerializedSize () const; | |
259 virtual void Serialize (Buffer::Iterator start) const; | |
260 virtual uint32_t Deserialize (Buffer::Iterator start); | |
261 virtual void Print (std::ostream &os) const; | |
262 //\} | |
263 /** | |
264 * \brief Set Packet ID for current packet | |
265 */ | |
266 void SetPacketID (uint64_t pktID); | |
267 /** | |
268 * \brief Get Packet ID for current packet | |
269 * \return packet ID | |
270 */ | |
271 uint64_t GetPacketID () const; | |
272 | |
273 /** | |
274 * \brief Set Hop count for current packet | |
275 */ | |
276 void SetHopCount (uint32_t floodCount); | |
277 /** | |
278 * \brief Get Hop count for current packet | |
279 * \return hop count | |
280 */ | |
281 uint32_t GetHopCount () const; | |
282 | |
283 /** | |
284 * \brief Set Timestamp current packet | |
285 */ | |
286 void SetTimeStamp (Time timeStamp); | |
287 | |
288 /** | |
289 * \brief Get Timestamp for current packet | |
290 * \return timestamp | |
291 */ | |
292 Time GetTimeStamp () const; | |
293 | |
294 | |
295 | |
296 private: | |
297 uint64_t m_packetID; ///< global packet ID | |
298 uint32_t m_hopCount; ///< Count to keep track of number of tr aveled hops | |
299 Time m_timeStamp; ///< Time at which packet was originated | |
300 | |
301 | |
302 }; | |
303 | |
304 static inline std::ostream & operator<< (std::ostream& os, const EpidemicHeader & packet) | |
305 { | |
306 packet.Print (os); | |
307 return os; | |
308 } | |
309 } //end namespace epidemic | |
310 } //end namespace ns3 | |
OLD | NEW |