|
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2009 IITP RAS |
|
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 * Based on |
|
19 * NS-2 AODV model developed by the CMU/MONARCH group and optimized and |
|
20 * tuned by Samir Das and Mahesh Marina, University of Cincinnati; |
|
21 * |
|
22 * AODV-UU implementation by Erik Nordström of Uppsala University |
|
23 * http://core.it.uu.se/core/index.php/AODV-UU |
|
24 * |
|
25 * Authors: Elena Buchatskaia <borovkovaes@iitp.ru> |
|
26 * Pavel Boyko <boyko@iitp.ru> |
|
27 */ |
|
28 #ifndef AODVPACKET_H |
|
29 #define AODVPACKET_H |
|
30 |
|
31 #include <iostream> |
|
32 #include "ns3/header.h" |
|
33 #include "ns3/enum.h" |
|
34 #include "ns3/ipv4-address.h" |
|
35 #include <map> |
|
36 #include "ns3/nstime.h" |
|
37 |
|
38 namespace ns3 { |
|
39 namespace aodv { |
|
40 |
|
41 enum MessageType |
|
42 { |
|
43 AODVTYPE_RREQ = 1, //!< AODVTYPE_RREQ |
|
44 AODVTYPE_RREP = 2, //!< AODVTYPE_RREP |
|
45 AODVTYPE_RERR = 3, //!< AODVTYPE_RERR |
|
46 AODVTYPE_RREP_ACK = 4 //!< AODVTYPE_RREP_ACK |
|
47 }; |
|
48 |
|
49 /** |
|
50 * \ingroup aodv |
|
51 * \brief AODV types |
|
52 */ |
|
53 class TypeHeader : public Header |
|
54 { |
|
55 public: |
|
56 /// c-tor |
|
57 TypeHeader (MessageType t); |
|
58 |
|
59 ///\name Header serialization/deserialization |
|
60 //\{ |
|
61 static TypeId GetTypeId (); |
|
62 TypeId GetInstanceTypeId () const; |
|
63 uint32_t GetSerializedSize () const; |
|
64 void Serialize (Buffer::Iterator start) const; |
|
65 uint32_t Deserialize (Buffer::Iterator start); |
|
66 void Print (std::ostream &os) const; |
|
67 //\} |
|
68 |
|
69 /// Return type |
|
70 MessageType Get () const { return m_type; } |
|
71 /// Check that type if valid |
|
72 bool IsValid () const { return m_valid; } |
|
73 bool operator== (TypeHeader const & o) const; |
|
74 private: |
|
75 MessageType m_type; |
|
76 bool m_valid; |
|
77 }; |
|
78 |
|
79 std::ostream & operator<< (std::ostream & os, TypeHeader const & h); |
|
80 |
|
81 /** |
|
82 * \ingroup aodv |
|
83 * \brief Route Request (RREQ) Message Format |
|
84 \verbatim |
|
85 0 1 2 3 |
|
86 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 |
|
87 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
88 | Type |J|R|G|D|U| Reserved | Hop Count | |
|
89 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
90 | RREQ ID | |
|
91 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
92 | Destination IP Address | |
|
93 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
94 | Destination Sequence Number | |
|
95 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
96 | Originator IP Address | |
|
97 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
98 | Originator Sequence Number | |
|
99 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
100 \endverbatim |
|
101 */ |
|
102 class RreqHeader : public Header |
|
103 { |
|
104 public: |
|
105 /// c-tor |
|
106 RreqHeader (uint8_t flags = 0, uint8_t reserved = 0, uint8_t hopCount = 0, |
|
107 uint32_t requestID = 0, Ipv4Address dst = Ipv4Address (), |
|
108 uint32_t dstSeqNo = 0, Ipv4Address origin = Ipv4Address (), |
|
109 uint32_t originSeqNo = 0); |
|
110 |
|
111 ///\name Header serialization/deserialization |
|
112 //\{ |
|
113 static TypeId GetTypeId (); |
|
114 TypeId GetInstanceTypeId () const; |
|
115 uint32_t GetSerializedSize () const; |
|
116 void Serialize (Buffer::Iterator start) const; |
|
117 uint32_t Deserialize (Buffer::Iterator start); |
|
118 void Print (std::ostream &os) const; |
|
119 //\} |
|
120 |
|
121 ///\name Fields |
|
122 //\{ |
|
123 void SetHopCount (uint8_t count) { m_hopCount = count; } |
|
124 uint8_t GetHopCount () const { return m_hopCount; } |
|
125 void SetId (uint32_t id) { m_requestID = id; } |
|
126 uint32_t GetId () const { return m_requestID; } |
|
127 void SetDst (Ipv4Address a) { m_dst = a; } |
|
128 Ipv4Address GetDst () const { return m_dst; } |
|
129 void SetDstSeqno (uint32_t s) { m_dstSeqNo = s; } |
|
130 uint32_t GetDstSeqno () const { return m_dstSeqNo; } |
|
131 void SetOrigin (Ipv4Address a) { m_origin = a; } |
|
132 Ipv4Address GetOrigin () const { return m_origin; } |
|
133 void SetOriginSeqno (uint32_t s) { m_originSeqNo = s; } |
|
134 uint32_t GetOriginSeqno () const { return m_originSeqNo; } |
|
135 //\} |
|
136 |
|
137 ///\name Flags |
|
138 //\{ |
|
139 void SetGratiousRrep (bool f); |
|
140 bool GetGratiousRrep () const; |
|
141 void SetDestinationOnly (bool f); |
|
142 bool GetDestinationOnly () const; |
|
143 void SetUnknownSeqno (bool f); |
|
144 bool GetUnknownSeqno () const; |
|
145 //\} |
|
146 |
|
147 bool operator== (RreqHeader const & o) const; |
|
148 private: |
|
149 uint8_t m_flags; ///< |J|R|G|D|U| bit flags, see RFC |
|
150 uint8_t m_reserved; ///< Not used |
|
151 uint8_t m_hopCount; ///< Hop Count |
|
152 uint32_t m_requestID; ///< RREQ ID |
|
153 Ipv4Address m_dst; ///< Destination IP Address |
|
154 uint32_t m_dstSeqNo; ///< Destination Sequence Number |
|
155 Ipv4Address m_origin; ///< Originator IP Address |
|
156 uint32_t m_originSeqNo; ///< Source Sequence Number |
|
157 }; |
|
158 |
|
159 std::ostream & operator<< (std::ostream & os, RreqHeader const &); |
|
160 |
|
161 /** |
|
162 * \ingroup aodv |
|
163 * \brief Route Reply (RREP) Message Format |
|
164 \verbatim |
|
165 0 1 2 3 |
|
166 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 |
|
167 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
168 | Type |R|A| Reserved |Prefix Sz| Hop Count | |
|
169 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
170 | Destination IP address | |
|
171 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
172 | Destination Sequence Number | |
|
173 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
174 | Originator IP address | |
|
175 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
176 | Lifetime | |
|
177 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
178 \endverbatim |
|
179 */ |
|
180 class RrepHeader : public Header |
|
181 { |
|
182 public: |
|
183 /// c-tor |
|
184 RrepHeader (uint8_t prefixSize = 0, uint8_t hopCount = 0, Ipv4Address dst = |
|
185 Ipv4Address (), uint32_t dstSeqNo = 0, Ipv4Address origin = |
|
186 Ipv4Address (), Time lifetime = MilliSeconds (0)); |
|
187 ///\name Header serialization/deserialization |
|
188 //\{ |
|
189 static TypeId GetTypeId (); |
|
190 TypeId GetInstanceTypeId () const; |
|
191 uint32_t GetSerializedSize () const; |
|
192 void Serialize (Buffer::Iterator start) const; |
|
193 uint32_t Deserialize (Buffer::Iterator start); |
|
194 void Print (std::ostream &os) const; |
|
195 //\} |
|
196 |
|
197 ///\name Fields |
|
198 //\{ |
|
199 void SetHopCount (uint8_t count) { m_hopCount = count; } |
|
200 uint8_t GetHopCount () const { return m_hopCount; } |
|
201 void SetDst (Ipv4Address a) { m_dst = a; } |
|
202 Ipv4Address GetDst () const { return m_dst; } |
|
203 void SetDstSeqno (uint32_t s) { m_dstSeqNo = s; } |
|
204 uint32_t GetDstSeqno () const { return m_dstSeqNo; } |
|
205 void SetOrigin (Ipv4Address a) { m_origin = a; } |
|
206 Ipv4Address GetOrigin () const { return m_origin; } |
|
207 void SetLifeTime (Time t); |
|
208 Time GetLifeTime () const; |
|
209 //\} |
|
210 |
|
211 ///\name Flags |
|
212 //\{ |
|
213 void SetAckRequired (bool f); |
|
214 bool GetAckRequired () const; |
|
215 void SetPrefixSize (uint8_t sz); |
|
216 uint8_t GetPrefixSize () const; |
|
217 //\} |
|
218 |
|
219 /// Configure RREP to be a Hello message |
|
220 void SetHello (Ipv4Address src, uint32_t srcSeqNo, Time lifetime); |
|
221 |
|
222 bool operator== (RrepHeader const & o) const; |
|
223 private: |
|
224 uint8_t m_flags; ///< A - acknowledgment required flag |
|
225 uint8_t m_prefixSize; ///< Prefix Size |
|
226 uint8_t m_hopCount; ///< Hop Count |
|
227 Ipv4Address m_dst; ///< Destination IP Address |
|
228 uint32_t m_dstSeqNo; ///< Destination Sequence Number |
|
229 Ipv4Address m_origin; ///< Source IP Address |
|
230 uint32_t m_lifeTime; ///< Lifetime (in milliseconds) |
|
231 }; |
|
232 |
|
233 std::ostream & operator<< (std::ostream & os, RrepHeader const &); |
|
234 |
|
235 /** |
|
236 * \ingroup aodv |
|
237 * \brief Route Reply Acknowledgment (RREP-ACK) Message Format |
|
238 \verbatim |
|
239 0 1 |
|
240 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 |
|
241 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
242 | Type | Reserved | |
|
243 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
244 \endverbatim |
|
245 */ |
|
246 class RrepAckHeader : public Header |
|
247 { |
|
248 public: |
|
249 /// c-tor |
|
250 RrepAckHeader (); |
|
251 |
|
252 ///\name Header serialization/deserialization |
|
253 //\{ |
|
254 static TypeId GetTypeId (); |
|
255 TypeId GetInstanceTypeId () const; |
|
256 uint32_t GetSerializedSize () const; |
|
257 void Serialize (Buffer::Iterator start) const; |
|
258 uint32_t Deserialize (Buffer::Iterator start); |
|
259 void Print (std::ostream &os) const; |
|
260 //\} |
|
261 |
|
262 bool operator== (RrepAckHeader const & o) const; |
|
263 private: |
|
264 uint8_t m_reserved; |
|
265 }; |
|
266 std::ostream & operator<< (std::ostream & os, RrepAckHeader const &); |
|
267 |
|
268 |
|
269 /** |
|
270 * \ingroup aodv |
|
271 * \brief Route Error (RERR) Message Format |
|
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 | Type |N| Reserved | DestCount | |
|
277 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
278 | Unreachable Destination IP Address (1) | |
|
279 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
280 | Unreachable Destination Sequence Number (1) | |
|
281 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-| |
|
282 | Additional Unreachable Destination IP Addresses (if needed) | |
|
283 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
284 |Additional Unreachable Destination Sequence Numbers (if needed)| |
|
285 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
286 \endverbatim |
|
287 */ |
|
288 class RerrHeader : public Header |
|
289 { |
|
290 public: |
|
291 /// c-tor |
|
292 RerrHeader (); |
|
293 |
|
294 ///\name Header serialization/deserialization |
|
295 //\{ |
|
296 static TypeId GetTypeId (); |
|
297 TypeId GetInstanceTypeId () const; |
|
298 uint32_t GetSerializedSize () const; |
|
299 void Serialize (Buffer::Iterator i) const; |
|
300 uint32_t Deserialize (Buffer::Iterator start); |
|
301 void Print (std::ostream &os) const; |
|
302 //\} |
|
303 |
|
304 ///\name No delete flag |
|
305 //\{ |
|
306 void SetNoDelete (bool f); |
|
307 bool GetNoDelete () const; |
|
308 //\} |
|
309 |
|
310 /** |
|
311 * Add unreachable node address and its sequence number in RERR header |
|
312 *\return false if we already added maximum possible number of unreachable destinations |
|
313 */ |
|
314 bool AddUnDestination (Ipv4Address dst, uint32_t seqNo); |
|
315 /** Delete pair (address + sequence number) from REER header, if the number of unreachable destinations > 0 |
|
316 * \return true on success |
|
317 */ |
|
318 bool RemoveUnDestination (std::pair<Ipv4Address, uint32_t> & un); |
|
319 /// Clear header |
|
320 void Clear(); |
|
321 /// Return number of unreachable destinations in RERR message |
|
322 uint8_t GetDestCount () const { return (uint8_t)m_unreachableDstSeqNo.size(); } |
|
323 bool operator== (RerrHeader const & o) const; |
|
324 private: |
|
325 uint8_t m_flag; ///< No delete flag |
|
326 uint8_t m_reserved; ///< Not used |
|
327 |
|
328 /// List of Unreachable destination: IP addresses and sequence numbers |
|
329 std::map<Ipv4Address, uint32_t> m_unreachableDstSeqNo; |
|
330 }; |
|
331 |
|
332 std::ostream & operator<< (std::ostream & os, RerrHeader const &); |
|
333 } |
|
334 } |
|
335 #endif /* AODVPACKET_H */ |