A Discrete-Event Network Simulator
API
aodv-packet.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 IITP RAS
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Based on
18  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
19  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
20  *
21  * AODV-UU implementation by Erik Nordström of Uppsala University
22  * https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
23  *
24  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
25  * Pavel Boyko <boyko@iitp.ru>
26  */
27 #ifndef AODVPACKET_H
28 #define AODVPACKET_H
29 
30 #include "ns3/enum.h"
31 #include "ns3/header.h"
32 #include "ns3/ipv4-address.h"
33 #include "ns3/nstime.h"
34 
35 #include <iostream>
36 #include <map>
37 
38 namespace ns3
39 {
40 namespace aodv
41 {
42 
48 {
53 };
54 
59 class TypeHeader : public Header
60 {
61  public:
67 
72  static TypeId GetTypeId();
73  TypeId GetInstanceTypeId() const override;
74  uint32_t GetSerializedSize() const override;
75  void Serialize(Buffer::Iterator start) const override;
76  uint32_t Deserialize(Buffer::Iterator start) override;
77  void Print(std::ostream& os) const override;
78 
82  MessageType Get() const
83  {
84  return m_type;
85  }
86 
91  bool IsValid() const
92  {
93  return m_valid;
94  }
95 
101  bool operator==(const TypeHeader& o) const;
102 
103  private:
105  bool m_valid;
106 };
107 
114 std::ostream& operator<<(std::ostream& os, const TypeHeader& h);
115 
137 class RreqHeader : public Header
138 {
139  public:
152  RreqHeader(uint8_t flags = 0,
153  uint8_t reserved = 0,
154  uint8_t hopCount = 0,
155  uint32_t requestID = 0,
156  Ipv4Address dst = Ipv4Address(),
157  uint32_t dstSeqNo = 0,
158  Ipv4Address origin = Ipv4Address(),
159  uint32_t originSeqNo = 0);
160 
165  static TypeId GetTypeId();
166  TypeId GetInstanceTypeId() const override;
167  uint32_t GetSerializedSize() const override;
168  void Serialize(Buffer::Iterator start) const override;
169  uint32_t Deserialize(Buffer::Iterator start) override;
170  void Print(std::ostream& os) const override;
171 
172  // Fields
177  void SetHopCount(uint8_t count)
178  {
179  m_hopCount = count;
180  }
181 
186  uint8_t GetHopCount() const
187  {
188  return m_hopCount;
189  }
190 
195  void SetId(uint32_t id)
196  {
197  m_requestID = id;
198  }
199 
204  uint32_t GetId() const
205  {
206  return m_requestID;
207  }
208 
214  {
215  m_dst = a;
216  }
217 
223  {
224  return m_dst;
225  }
226 
231  void SetDstSeqno(uint32_t s)
232  {
233  m_dstSeqNo = s;
234  }
235 
240  uint32_t GetDstSeqno() const
241  {
242  return m_dstSeqNo;
243  }
244 
250  {
251  m_origin = a;
252  }
253 
259  {
260  return m_origin;
261  }
262 
267  void SetOriginSeqno(uint32_t s)
268  {
269  m_originSeqNo = s;
270  }
271 
276  uint32_t GetOriginSeqno() const
277  {
278  return m_originSeqNo;
279  }
280 
281  // Flags
286  void SetGratuitousRrep(bool f);
291  bool GetGratuitousRrep() const;
296  void SetDestinationOnly(bool f);
301  bool GetDestinationOnly() const;
306  void SetUnknownSeqno(bool f);
311  bool GetUnknownSeqno() const;
312 
318  bool operator==(const RreqHeader& o) const;
319 
320  private:
321  uint8_t m_flags;
322  uint8_t m_reserved;
323  uint8_t m_hopCount;
324  uint32_t m_requestID;
326  uint32_t m_dstSeqNo;
328  uint32_t m_originSeqNo;
329 };
330 
336 std::ostream& operator<<(std::ostream& os, const RreqHeader&);
337 
357 class RrepHeader : public Header
358 {
359  public:
370  RrepHeader(uint8_t prefixSize = 0,
371  uint8_t hopCount = 0,
372  Ipv4Address dst = Ipv4Address(),
373  uint32_t dstSeqNo = 0,
374  Ipv4Address origin = Ipv4Address(),
375  Time lifetime = MilliSeconds(0));
380  static TypeId GetTypeId();
381  TypeId GetInstanceTypeId() const override;
382  uint32_t GetSerializedSize() const override;
383  void Serialize(Buffer::Iterator start) const override;
384  uint32_t Deserialize(Buffer::Iterator start) override;
385  void Print(std::ostream& os) const override;
386 
387  // Fields
392  void SetHopCount(uint8_t count)
393  {
394  m_hopCount = count;
395  }
396 
401  uint8_t GetHopCount() const
402  {
403  return m_hopCount;
404  }
405 
411  {
412  m_dst = a;
413  }
414 
420  {
421  return m_dst;
422  }
423 
428  void SetDstSeqno(uint32_t s)
429  {
430  m_dstSeqNo = s;
431  }
432 
437  uint32_t GetDstSeqno() const
438  {
439  return m_dstSeqNo;
440  }
441 
447  {
448  m_origin = a;
449  }
450 
456  {
457  return m_origin;
458  }
459 
464  void SetLifeTime(Time t);
469  Time GetLifeTime() const;
470 
471  // Flags
476  void SetAckRequired(bool f);
481  bool GetAckRequired() const;
486  void SetPrefixSize(uint8_t sz);
491  uint8_t GetPrefixSize() const;
492 
500  void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime);
501 
507  bool operator==(const RrepHeader& o) const;
508 
509  private:
510  uint8_t m_flags;
511  uint8_t m_prefixSize;
512  uint8_t m_hopCount;
514  uint32_t m_dstSeqNo;
516  uint32_t m_lifeTime;
517 };
518 
524 std::ostream& operator<<(std::ostream& os, const RrepHeader&);
525 
537 class RrepAckHeader : public Header
538 {
539  public:
541  RrepAckHeader();
542 
547  static TypeId GetTypeId();
548  TypeId GetInstanceTypeId() const override;
549  uint32_t GetSerializedSize() const override;
550  void Serialize(Buffer::Iterator start) const override;
551  uint32_t Deserialize(Buffer::Iterator start) override;
552  void Print(std::ostream& os) const override;
553 
559  bool operator==(const RrepAckHeader& o) const;
560 
561  private:
562  uint8_t m_reserved;
563 };
564 
570 std::ostream& operator<<(std::ostream& os, const RrepAckHeader&);
571 
591 class RerrHeader : public Header
592 {
593  public:
595  RerrHeader();
596 
601  static TypeId GetTypeId();
602  TypeId GetInstanceTypeId() const override;
603  uint32_t GetSerializedSize() const override;
604  void Serialize(Buffer::Iterator i) const override;
605  uint32_t Deserialize(Buffer::Iterator start) override;
606  void Print(std::ostream& os) const override;
607 
608  // No delete flag
613  void SetNoDelete(bool f);
618  bool GetNoDelete() const;
619 
626  bool AddUnDestination(Ipv4Address dst, uint32_t seqNo);
633  bool RemoveUnDestination(std::pair<Ipv4Address, uint32_t>& un);
635  void Clear();
636 
640  uint8_t GetDestCount() const
641  {
642  return (uint8_t)m_unreachableDstSeqNo.size();
643  }
644 
650  bool operator==(const RerrHeader& o) const;
651 
652  private:
653  uint8_t m_flag;
654  uint8_t m_reserved;
655 
657  std::map<Ipv4Address, uint32_t> m_unreachableDstSeqNo;
658 };
659 
665 std::ostream& operator<<(std::ostream& os, const RerrHeader&);
666 
667 } // namespace aodv
668 } // namespace ns3
669 
670 #endif /* AODVPACKET_H */
double f(double x, void *params)
Definition: 80211b.c:70
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Route Error (RERR) Message Format.
Definition: aodv-packet.h:592
uint8_t GetDestCount() const
Definition: aodv-packet.h:640
void Clear()
Clear header.
Definition: aodv-packet.cc:643
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:530
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:654
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:611
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:546
RerrHeader()
constructor
Definition: aodv-packet.cc:521
uint8_t m_flag
No delete flag.
Definition: aodv-packet.h:653
bool operator==(const RerrHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:651
void Serialize(Buffer::Iterator i) const override
Definition: aodv-packet.cc:552
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:540
void SetNoDelete(bool f)
Set the no delete flag.
Definition: aodv-packet.cc:598
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Definition: aodv-packet.cc:617
std::map< Ipv4Address, uint32_t > m_unreachableDstSeqNo
List of Unreachable destination: IP addresses and sequence numbers.
Definition: aodv-packet.h:657
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:587
bool RemoveUnDestination(std::pair< Ipv4Address, uint32_t > &un)
Delete pair (address + sequence number) from REER header, if the number of unreachable destinations >...
Definition: aodv-packet.cc:630
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:538
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:473
void Serialize(Buffer::Iterator start) const override
Definition: aodv-packet.cc:485
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:501
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:463
bool operator==(const RrepAckHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:506
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:479
RrepAckHeader()
constructor
Definition: aodv-packet.cc:455
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:562
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:358
bool GetAckRequired() const
get the ack required flag
Definition: aodv-packet.cc:407
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:327
uint8_t GetPrefixSize() const
Set the prefix size.
Definition: aodv-packet.cc:419
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:369
void Serialize(Buffer::Iterator start) const override
Definition: aodv-packet.cc:339
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:428
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:455
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:433
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:317
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:401
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:446
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:392
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:333
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:514
void SetLifeTime(Time t)
Set the lifetime.
Definition: aodv-packet.cc:381
void SetAckRequired(bool f)
Set the ack required flag.
Definition: aodv-packet.cc:394
void SetPrefixSize(uint8_t sz)
Set the prefix size.
Definition: aodv-packet.cc:413
RrepHeader(uint8_t prefixSize=0, uint8_t hopCount=0, Ipv4Address dst=Ipv4Address(), uint32_t dstSeqNo=0, Ipv4Address origin=Ipv4Address(), Time lifetime=MilliSeconds(0))
constructor
Definition: aodv-packet.cc:298
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-packet.cc:387
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:410
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:513
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:437
uint8_t m_flags
A - acknowledgment required flag.
Definition: aodv-packet.h:510
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:419
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:512
uint8_t m_prefixSize
Prefix Size.
Definition: aodv-packet.h:511
bool operator==(const RrepHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:425
Ipv4Address m_origin
Source IP Address.
Definition: aodv-packet.h:515
uint32_t m_lifeTime
Lifetime (in milliseconds)
Definition: aodv-packet.h:516
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:138
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:204
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:213
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:186
bool GetUnknownSeqno() const
Get the unknown sequence number flag.
Definition: aodv-packet.cc:281
uint32_t m_originSeqNo
Source Sequence Number.
Definition: aodv-packet.h:328
void SetId(uint32_t id)
Set the request ID.
Definition: aodv-packet.h:195
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:276
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)
constructor
Definition: aodv-packet.cc:138
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:323
void SetUnknownSeqno(bool f)
Set the unknown sequence number flag.
Definition: aodv-packet.cc:268
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:258
void SetGratuitousRrep(bool f)
Set the gratuitous RREP flag.
Definition: aodv-packet.cc:230
void SetDestinationOnly(bool f)
Set the Destination only flag.
Definition: aodv-packet.cc:249
Ipv4Address m_origin
Originator IP Address.
Definition: aodv-packet.h:327
bool GetDestinationOnly() const
Get the Destination only flag.
Definition: aodv-packet.cc:262
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:176
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:325
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:160
uint32_t m_requestID
RREQ ID.
Definition: aodv-packet.h:324
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:177
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:231
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:213
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:170
void Serialize(Buffer::Iterator start) const override
Definition: aodv-packet.cc:182
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:322
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:240
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:222
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:267
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
Definition: aodv-packet.cc:243
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:326
bool operator==(const RreqHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:287
uint8_t m_flags
|J|R|G|D|U| bit flags, see RFC
Definition: aodv-packet.h:321
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:249
TypeHeader(MessageType t=AODVTYPE_RREQ)
constructor
Definition: aodv-packet.cc:39
bool operator==(const TypeHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:123
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:97
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:56
void Serialize(Buffer::Iterator start) const override
Definition: aodv-packet.cc:68
MessageType m_type
type of the message
Definition: aodv-packet.h:104
bool m_valid
Indicates if the message is valid.
Definition: aodv-packet.h:105
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:91
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:62
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:46
MessageType Get() const
Definition: aodv-packet.h:82
MessageType
MessageType enumeration.
Definition: aodv-packet.h:48
@ AODVTYPE_RREP
AODVTYPE_RREP.
Definition: aodv-packet.h:50
@ AODVTYPE_RREP_ACK
AODVTYPE_RREP_ACK.
Definition: aodv-packet.h:52
@ AODVTYPE_RERR
AODVTYPE_RERR.
Definition: aodv-packet.h:51
@ AODVTYPE_RREQ
AODVTYPE_RREQ.
Definition: aodv-packet.h:49
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
std::ostream & operator<<(std::ostream &os, const TypeHeader &h)
Stream output operator.
Definition: aodv-packet.cc:129
Every class exported by the ns3 library is enclosed in the ns3 namespace.