A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
aodv-packet.h
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,
44  AODVTYPE_RREP = 2,
45  AODVTYPE_RERR = 3,
46  AODVTYPE_RREP_ACK = 4
47 };
48 
53 class TypeHeader : public Header
54 {
55 public:
57  TypeHeader (MessageType t = AODVTYPE_RREQ);
58 
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 
70  MessageType Get () const { return m_type; }
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 
102 class RreqHeader : public Header
103 {
104 public:
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, uint16_t channel = 1);
110 
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 
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  void SetRXChannel (uint16_t s) { m_channelNo = s; }
136  uint16_t GetRXChannel () const { return m_channelNo; }
137  //\}
138 
140  //\{
141  void SetGratiousRrep (bool f);
142  bool GetGratiousRrep () const;
143  void SetDestinationOnly (bool f);
144  bool GetDestinationOnly () const;
145  void SetUnknownSeqno (bool f);
146  bool GetUnknownSeqno () const;
147  //\}
148 
149  bool operator== (RreqHeader const & o) const;
150 private:
151  uint8_t m_flags;
152  uint8_t m_reserved;
153  uint8_t m_hopCount;
154  uint32_t m_requestID;
156  uint32_t m_dstSeqNo;
158  uint32_t m_originSeqNo;
159  uint16_t m_channelNo;
160 };
161 
162 std::ostream & operator<< (std::ostream & os, RreqHeader const &);
163 
183 class RrepHeader : public Header
184 {
185 public:
187  RrepHeader (uint8_t prefixSize = 0, uint8_t hopCount = 0, Ipv4Address dst =
188  Ipv4Address (), uint32_t dstSeqNo = 0, Ipv4Address origin =
189  Ipv4Address (), Time lifetime = MilliSeconds (0),
190  uint16_t channel = 1);
192  //\{
193  static TypeId GetTypeId ();
194  TypeId GetInstanceTypeId () const;
195  uint32_t GetSerializedSize () const;
196  void Serialize (Buffer::Iterator start) const;
197  uint32_t Deserialize (Buffer::Iterator start);
198  void Print (std::ostream &os) const;
199  //\}
200 
202  //\{
203  void SetHopCount (uint8_t count) { m_hopCount = count; }
204  uint8_t GetHopCount () const { return m_hopCount; }
205  void SetDst (Ipv4Address a) { m_dst = a; }
206  Ipv4Address GetDst () const { return m_dst; }
207  void SetDstSeqno (uint32_t s) { m_dstSeqNo = s; }
208  uint32_t GetDstSeqno () const { return m_dstSeqNo; }
209  void SetOrigin (Ipv4Address a) { m_origin = a; }
210  Ipv4Address GetOrigin () const { return m_origin; }
211  void SetRXChannel (uint16_t s) { m_channelNo = s; }
212  uint16_t GetRXChannel () const { return m_channelNo; }
213  void SetLifeTime (Time t);
214  Time GetLifeTime () const;
215  //\}
216 
218  //\{
219  void SetAckRequired (bool f);
220  bool GetAckRequired () const;
221  void SetPrefixSize (uint8_t sz);
222  uint8_t GetPrefixSize () const;
223  //\}
224 
226  void SetHello (Ipv4Address src, uint32_t srcSeqNo, Time lifetime);
227 
228  bool operator== (RrepHeader const & o) const;
229 private:
230  uint8_t m_flags;
231  uint8_t m_prefixSize;
232  uint8_t m_hopCount;
234  uint32_t m_dstSeqNo;
236  uint32_t m_lifeTime;
237  uint16_t m_channelNo;
238 };
239 
240 std::ostream & operator<< (std::ostream & os, RrepHeader const &);
241 
253 class RrepAckHeader : public Header
254 {
255 public:
257  RrepAckHeader ();
258 
260  //\{
261  static TypeId GetTypeId ();
262  TypeId GetInstanceTypeId () const;
263  uint32_t GetSerializedSize () const;
264  void Serialize (Buffer::Iterator start) const;
265  uint32_t Deserialize (Buffer::Iterator start);
266  void Print (std::ostream &os) const;
267  //\}
268 
269  bool operator== (RrepAckHeader const & o) const;
270 private:
271  uint8_t m_reserved;
272 };
273 std::ostream & operator<< (std::ostream & os, RrepAckHeader const &);
274 
275 
295 class RerrHeader : public Header
296 {
297 public:
299  RerrHeader ();
300 
302  //\{
303  static TypeId GetTypeId ();
304  TypeId GetInstanceTypeId () const;
305  uint32_t GetSerializedSize () const;
306  void Serialize (Buffer::Iterator i) const;
307  uint32_t Deserialize (Buffer::Iterator start);
308  void Print (std::ostream &os) const;
309  //\}
310 
312  //\{
313  void SetNoDelete (bool f);
314  bool GetNoDelete () const;
315  //\}
316 
321  bool AddUnDestination (Ipv4Address dst, uint32_t seqNo);
325  bool RemoveUnDestination (std::pair<Ipv4Address, uint32_t> & un);
327  void Clear ();
329  uint8_t GetDestCount () const { return (uint8_t)m_unreachableDstSeqNo.size (); }
330  bool operator== (RerrHeader const & o) const;
331 private:
332  uint8_t m_flag;
333  uint8_t m_reserved;
334 
336  std::map<Ipv4Address, uint32_t> m_unreachableDstSeqNo;
337 };
338 
339 std::ostream & operator<< (std::ostream & os, RerrHeader const &);
340 }
341 }
342 #endif /* AODVPACKET_H */
Protocol header serialization and deserialization.
Definition: header.h:42
keep track of time unit.
Definition: nstime.h:149
TypeId GetInstanceTypeId() const
Definition: aodv-packet.cc:55
TypeId GetInstanceTypeId() const
Definition: aodv-packet.cc:448
Route Error (RERR) Message Format.
Definition: aodv-packet.h:295
void Serialize(Buffer::Iterator i) const
Definition: aodv-packet.cc:526
uint32_t m_requestID
RREQ ID.
Definition: aodv-packet.h:154
RreqHeader(uint8_t flags=0, uint8_t reserved=0, uint8_t hopCount=0, uint32_t requestID=0, Ipv4Address dst=Ipv4Address(), uint32_t dstSeqNo=0, Ipv4Address origin=Ipv4Address(), uint32_t originSeqNo=0, uint16_t channel=1)
c-tor
Definition: aodv-packet.cc:142
uint32_t m_lifeTime
Lifetime (in milliseconds)
Definition: aodv-packet.h:236
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:102
uint32_t Deserialize(Buffer::Iterator start)
Definition: aodv-packet.cc:466
iterator in a Buffer instance
Definition: buffer.h:98
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:520
void Print(std::ostream &os) const
Definition: aodv-packet.cc:207
uint32_t Deserialize(Buffer::Iterator start)
Definition: aodv-packet.cc:540
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:72
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:67
void Clear()
Clear header.
Definition: aodv-packet.cc:611
uint32_t Deserialize(Buffer::Iterator start)
Definition: aodv-packet.cc:73
uint32_t m_originSeqNo
Source Sequence Number.
Definition: aodv-packet.h:158
Ipv4Address m_origin
Source IP Address.
Definition: aodv-packet.h:235
uint32_t Deserialize(Buffer::Iterator start)
Definition: aodv-packet.cc:329
uint8_t GetDestCount() const
Return number of unreachable destinations in RERR message.
Definition: aodv-packet.h:329
uint16_t m_channelNo
RX channel of source.
Definition: aodv-packet.h:159
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Definition: aodv-packet.cc:589
uint8_t m_flag
No delete flag.
Definition: aodv-packet.h:332
void Print(std::ostream &os) const
Definition: aodv-packet.cc:348
void Print(std::ostream &os) const
Definition: aodv-packet.cc:97
Ipv4Address m_origin
Originator IP Address.
Definition: aodv-packet.h:157
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:316
uint8_t m_reserved
Not used.
Definition: aodv-packet.h:333
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:183
uint8_t m_flags
A - acknowledgment required flag.
Definition: aodv-packet.h:230
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:43
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:233
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:174
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:409
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:460
void Print(std::ostream &os) const
Definition: aodv-packet.cc:476
bool RemoveUnDestination(std::pair< Ipv4Address, uint32_t > &un)
Definition: aodv-packet.cc:600
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:234
TypeHeader(MessageType t=AODVTYPE_RREQ)
c-tor
Definition: aodv-packet.cc:39
std::map< Ipv4Address, uint32_t > m_unreachableDstSeqNo
List of Unreachable destination: IP addresses and sequence numbers.
Definition: aodv-packet.h:336
uint16_t m_channelNo
Source RX channel number.
Definition: aodv-packet.h:237
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:454
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:310
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:253
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:153
uint32_t Deserialize(Buffer::Iterator start)
Definition: aodv-packet.cc:188
void Print(std::ostream &os) const
Definition: aodv-packet.cc:562
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:168
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:155
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:61
RrepHeader(uint8_t prefixSize=0, uint8_t hopCount=0, Ipv4Address dst=Ipv4Address(), uint32_t dstSeqNo=0, Ipv4Address origin=Ipv4Address(), Time lifetime=MilliSeconds(0), uint16_t channel=1)
c-tor
Definition: aodv-packet.cc:283
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Definition: nstime.h:601
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:232
uint8_t m_reserved
Not used.
Definition: aodv-packet.h:152
TypeId GetInstanceTypeId() const
Definition: aodv-packet.cc:514
TypeId GetInstanceTypeId() const
Definition: aodv-packet.cc:162
a unique identifier for an interface.
Definition: type-id.h:44
MessageType Get() const
Return type.
Definition: aodv-packet.h:70
uint8_t m_flags
|J|R|G|D|U| bit flags, see RFC
Definition: aodv-packet.h:151
uint8_t m_prefixSize
Prefix Size.
Definition: aodv-packet.h:231
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:156
TypeId GetInstanceTypeId() const
Definition: aodv-packet.cc:304