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 | |
42 EPIDEMIC_TYPE_REPLY = 2, //!< EPIDEMIC_TYPE_REPLY | |
43 EPIDEMIC_TYPE_REPLY_BACK = 3, //!< EPIDEMIC_TYPE_REPLY_BACK | |
44 | |
45 }; | |
46 | |
47 | |
48 /** | |
Peter Barnes
2013/12/10 00:02:33
This doxygen block should be merged with the one f
mjf.alenazi
2013/12/30 23:11:11
Done.
| |
49 * \ingroup epidemic | |
50 * \brief Three types: | |
Peter Barnes
2013/12/10 00:02:33
\brief Epidemic routing packet type header.
Epide
mjf.alenazi
2013/12/30 23:11:11
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 */ | |
68 | |
69 /** | |
70 * \ingroup epidemic | |
71 * \brief Epidemic types | |
72 */ | |
73 class TypeHeader : public Header | |
74 { | |
75 public: | |
76 /** | |
77 * \brief Constructor. | |
78 * \param optionsOffset option offset | |
79 */ | |
80 TypeHeader (MessageType t = EPIDEMIC_TYPE_BEACON); | |
81 /** | |
82 * \brief Destructor. | |
83 */ | |
84 ~TypeHeader (); | |
85 /** | |
86 * \brief Get the type identificator. | |
87 * \return type identificator | |
88 */ | |
89 static TypeId GetTypeId (); | |
90 /** | |
91 * \brief Get the instance type ID. | |
92 * \return instance type ID | |
93 */ | |
94 TypeId GetInstanceTypeId () const; | |
95 void SetInstanceTypeId (MessageType type); | |
96 /** | |
97 * \brief Get the serialized size of the packet. | |
98 * \return size | |
99 */ | |
100 uint32_t GetSerializedSize () const; | |
101 /** | |
102 * \brief Serialize all added options. | |
103 * \param start Buffer iterator | |
104 */ | |
105 void Serialize (Buffer::Iterator start) const; | |
106 /** | |
107 * \brief Deserialize the packet. | |
108 * \param start Buffer iterator | |
109 * \param length length | |
110 * \return size of the packet | |
111 */ | |
112 uint32_t Deserialize (Buffer::Iterator start); | |
113 /** | |
114 * \brief Print some informations about the packet. | |
115 * \param os output stream | |
116 * \return info about this packet | |
117 */ | |
118 void Print (std::ostream &os) const; | |
119 | |
120 /// Return type | |
121 MessageType Get () const; | |
122 /// Check that type if valid | |
123 bool IsValid () const; | |
124 bool operator== (TypeHeader const & o) const; | |
125 private: | |
126 MessageType m_type; | |
127 bool m_valid; | |
128 }; | |
129 | |
130 std::ostream & operator<< (std::ostream & os, TypeHeader const & h); | |
131 | |
132 | |
133 /** | |
134 * \ingroup epidemic | |
135 * \brief Epidemic Summary Vector Header | |
136 * This packet is used to carry the packet IDs of packets located | |
137 * in the host's buffer to the other node. | |
138 \verbatim | |
139 0 1 2 3 | |
140 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 | |
141 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
142 | 64 bit Summary Vector Length | | |
143 + + | |
144 | | | |
145 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
146 | 64 bit Global ID for Packet # 1 | | |
147 + + | |
148 | | | |
149 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
150 | 64 bit Global ID for Packet # 2 | | |
151 + + | |
152 | | | |
153 | . | | |
154 | . | | |
155 | . | | |
156 | | | |
157 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
158 | 64 bit Global ID for Packet # n | | |
159 + + | |
160 | | | |
161 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
162 | |
163 \endverbatim | |
164 */ | |
165 | |
166 | |
167 class EpidemicSummaryVectorHeader : public Header | |
Peter Barnes
2013/12/10 00:02:33
This design can be greatly improved. As is, you'r
mjf.alenazi
2013/12/30 23:11:11
Could you please help me with this and send it as
| |
168 { | |
169 public: | |
170 /** | |
171 * \brief Constructor. | |
172 */ | |
173 EpidemicSummaryVectorHeader (std::vector<uint64_t> sv = std::vector<uint64_t> ()); | |
174 /** | |
175 * \brief Destructor. | |
176 */ | |
177 virtual ~EpidemicSummaryVectorHeader (); | |
178 ///\name Fields | |
179 //\{ | |
180 static TypeId GetTypeId (void); | |
181 virtual TypeId GetInstanceTypeId (void) const; | |
182 virtual uint32_t GetSerializedSize () const; | |
183 virtual void Serialize (Buffer::Iterator start) const; | |
184 virtual uint32_t Deserialize (Buffer::Iterator start); | |
185 virtual void Print (std::ostream &os) const; | |
186 //\} | |
187 /** | |
188 * \brief Set SummaryVector | |
189 */ | |
190 void SetSummaryVector (std::vector<uint64_t> value); | |
191 /** | |
192 * \brief Get SummaryVector | |
193 */ | |
194 std::vector<uint64_t> GetSummaryVector (); | |
195 private: | |
196 std::vector<uint64_t> m_summary_vector; | |
197 }; | |
198 | |
199 static inline std::ostream & operator<< (std::ostream& os, const EpidemicSummary VectorHeader & packet) | |
Tom Henderson
2013/12/08 22:24:26
Why is this static and inline? See e.g. Mac48Addr
mjf.alenazi
2013/12/30 23:11:11
Followed the AODV example.
On 2013/12/08 22:24:26,
| |
200 { | |
Peter Barnes
2013/12/10 00:02:33
No inline please.
mjf.alenazi
2013/12/30 23:11:11
Should I remove the function?
On 2013/12/10 00:02:
| |
201 packet.Print (os); | |
202 return os; | |
203 } | |
204 | |
205 /** | |
206 * \ingroup epidemic | |
207 * \brief Epidemic Packet Header | |
208 * This packet header is added to a data packet in the source node once it is | |
209 * received from the transport layer. It is removed in the receiver node before it | |
210 * is delivered to the transport layer. | |
211 * The Epidemic Header consists of three fields: | |
212 * 1. Packet ID: global packet ID | |
213 * The format of a global packet ID is a concatenation of 32 bit sender IP and | |
214 * a 32 bit sender data packet counter | |
215 * 32 bit : 32 Bit | |
216 * SENDER IP : SENDER PACKET COUNTER | |
217 * We call the packet ID global packet ID to distinguish from the ns3 packe t id. | |
218 * | |
219 * 2. Hop Count: It is flood control parameter used to set the number of hops | |
220 * the packet can travel before it is discarded. It is similar to TTL fiel d but | |
221 * with higher size limit. | |
222 * 3. Timestampe : It show when the packet is generated. This field is used to discard | |
223 * old packets with a time threshold limit set by the user. | |
224 \verbatim | |
225 0 1 2 3 | |
226 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 | |
227 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
228 | Sender IP Address | | |
229 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
230 | Sender Packet Counter | | |
231 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
232 | Hop Count | | |
233 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| | |
234 | 64 Bit Timestamp | | |
235 + + | |
236 | | | |
237 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
238 \endverbatim | |
239 */ | |
240 | |
241 class EpidemicHeader : public Header | |
242 { | |
243 public: | |
244 /** | |
245 * \brief Constructor. | |
246 */ | |
247 EpidemicHeader (uint64_t pkt_ID = 0,uint32_t hopCount = 0, Time timeStamp = Se conds (0)); | |
248 /** | |
249 * \brief Destructor. | |
250 */ | |
251 virtual ~EpidemicHeader (); | |
252 ///\name Header serialization/deserialization | |
253 //\{ | |
254 static TypeId GetTypeId (void); | |
255 virtual TypeId GetInstanceTypeId (void) const; | |
256 virtual uint32_t GetSerializedSize () const; | |
257 virtual void Serialize (Buffer::Iterator start) const; | |
258 virtual uint32_t Deserialize (Buffer::Iterator start); | |
259 virtual void Print (std::ostream &os) const; | |
260 //\} | |
261 /** | |
262 * \brief Set Packet ID for current packet | |
263 */ | |
264 void SetPacketID (uint64_t pktID); | |
265 /** | |
266 * \brief Get Packet ID for current packet | |
267 * \return packet ID | |
268 */ | |
269 uint64_t GetPacketID () const; | |
270 | |
271 /** | |
272 * \brief Set Hop count for current packet | |
273 */ | |
274 void SetHopCount (uint32_t floodCount); | |
275 /** | |
276 * \brief Get Hop count for current packet | |
277 * \return hop count | |
278 */ | |
279 uint32_t GetHopCount () const; | |
280 | |
281 /** | |
282 * \brief Set Timestamp current packet | |
283 */ | |
284 void SetTimeStamp (Time timeStamp); | |
285 | |
286 /** | |
287 * \brief Get Timestamp for current packet | |
288 * \return timestamp | |
289 */ | |
290 Time GetTimeStamp () const; | |
291 | |
292 | |
293 | |
294 private: | |
295 uint64_t m_packetID; ///< global packet ID | |
296 uint32_t m_hopCount; ///< Count to keep track of number of tr aveled hops | |
297 Time m_timeStamp; ///< Time at which packet was originated | |
298 | |
299 | |
300 }; | |
301 | |
302 static inline std::ostream & operator<< (std::ostream& os, const EpidemicHeader & packet) | |
Tom Henderson
2013/12/08 22:24:26
same comment as above.
mjf.alenazi
2013/12/30 23:11:11
I followed the AODV example. Should I remove the f
| |
303 { | |
304 packet.Print (os); | |
305 return os; | |
306 } | |
307 } //end namespace epidemic | |
308 } //end namespace ns3 | |
OLD | NEW |