A Discrete-Event Network Simulator
API
aodv-packet.h
Go to the documentation of this file.
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 
46 {
51 };
52 
57 class TypeHeader : public Header
58 {
59 public:
65 
70  static TypeId GetTypeId ();
71  TypeId GetInstanceTypeId () const;
72  uint32_t GetSerializedSize () const;
73  void Serialize (Buffer::Iterator start) const;
75  void Print (std::ostream &os) const;
76 
80  MessageType Get () const
81  {
82  return m_type;
83  }
88  bool IsValid () const
89  {
90  return m_valid;
91  }
97  bool operator== (TypeHeader const & o) const;
98 private:
100  bool m_valid;
101 };
102 
108 std::ostream & operator<< (std::ostream & os, TypeHeader const & h);
109 
131 class RreqHeader : public Header
132 {
133 public:
146  RreqHeader (uint8_t flags = 0, uint8_t reserved = 0, uint8_t hopCount = 0,
147  uint32_t requestID = 0, Ipv4Address dst = Ipv4Address (),
148  uint32_t dstSeqNo = 0, Ipv4Address origin = Ipv4Address (),
149  uint32_t originSeqNo = 0);
150 
155  static TypeId GetTypeId ();
156  TypeId GetInstanceTypeId () const;
157  uint32_t GetSerializedSize () const;
158  void Serialize (Buffer::Iterator start) const;
160  void Print (std::ostream &os) const;
161 
162  // Fields
167  void SetHopCount (uint8_t count)
168  {
169  m_hopCount = count;
170  }
175  uint8_t GetHopCount () const
176  {
177  return m_hopCount;
178  }
183  void SetId (uint32_t id)
184  {
185  m_requestID = id;
186  }
191  uint32_t GetId () const
192  {
193  return m_requestID;
194  }
200  {
201  m_dst = a;
202  }
208  {
209  return m_dst;
210  }
215  void SetDstSeqno (uint32_t s)
216  {
217  m_dstSeqNo = s;
218  }
223  uint32_t GetDstSeqno () const
224  {
225  return m_dstSeqNo;
226  }
232  {
233  m_origin = a;
234  }
240  {
241  return m_origin;
242  }
247  void SetOriginSeqno (uint32_t s)
248  {
249  m_originSeqNo = s;
250  }
255  uint32_t GetOriginSeqno () const
256  {
257  return m_originSeqNo;
258  }
259 
260  // Flags
265  void SetGratuitousRrep (bool f);
270  bool GetGratuitousRrep () const;
275  void SetDestinationOnly (bool f);
280  bool GetDestinationOnly () const;
285  void SetUnknownSeqno (bool f);
290  bool GetUnknownSeqno () const;
291 
297  bool operator== (RreqHeader const & o) const;
298 private:
299  uint8_t m_flags;
300  uint8_t m_reserved;
301  uint8_t m_hopCount;
302  uint32_t m_requestID;
304  uint32_t m_dstSeqNo;
306  uint32_t m_originSeqNo;
307 };
308 
314 std::ostream & operator<< (std::ostream & os, RreqHeader const &);
315 
335 class RrepHeader : public Header
336 {
337 public:
348  RrepHeader (uint8_t prefixSize = 0, uint8_t hopCount = 0, Ipv4Address dst =
349  Ipv4Address (), uint32_t dstSeqNo = 0, Ipv4Address origin =
350  Ipv4Address (), Time lifetime = MilliSeconds (0));
355  static TypeId GetTypeId ();
356  TypeId GetInstanceTypeId () const;
357  uint32_t GetSerializedSize () const;
358  void Serialize (Buffer::Iterator start) const;
360  void Print (std::ostream &os) const;
361 
362  // Fields
367  void SetHopCount (uint8_t count)
368  {
369  m_hopCount = count;
370  }
375  uint8_t GetHopCount () const
376  {
377  return m_hopCount;
378  }
384  {
385  m_dst = a;
386  }
392  {
393  return m_dst;
394  }
399  void SetDstSeqno (uint32_t s)
400  {
401  m_dstSeqNo = s;
402  }
407  uint32_t GetDstSeqno () const
408  {
409  return m_dstSeqNo;
410  }
416  {
417  m_origin = a;
418  }
424  {
425  return m_origin;
426  }
431  void SetLifeTime (Time t);
436  Time GetLifeTime () const;
437 
438  // Flags
443  void SetAckRequired (bool f);
448  bool GetAckRequired () const;
453  void SetPrefixSize (uint8_t sz);
458  uint8_t GetPrefixSize () const;
459 
467  void SetHello (Ipv4Address src, uint32_t srcSeqNo, Time lifetime);
468 
474  bool operator== (RrepHeader const & o) const;
475 private:
476  uint8_t m_flags;
477  uint8_t m_prefixSize;
478  uint8_t m_hopCount;
480  uint32_t m_dstSeqNo;
482  uint32_t m_lifeTime;
483 };
484 
490 std::ostream & operator<< (std::ostream & os, RrepHeader const &);
491 
503 class RrepAckHeader : public Header
504 {
505 public:
507  RrepAckHeader ();
508 
513  static TypeId GetTypeId ();
514  TypeId GetInstanceTypeId () const;
515  uint32_t GetSerializedSize () const;
516  void Serialize (Buffer::Iterator start) const;
518  void Print (std::ostream &os) const;
519 
525  bool operator== (RrepAckHeader const & o) const;
526 private:
527  uint8_t m_reserved;
528 };
529 
535 std::ostream & operator<< (std::ostream & os, RrepAckHeader const &);
536 
537 
557 class RerrHeader : public Header
558 {
559 public:
561  RerrHeader ();
562 
567  static TypeId GetTypeId ();
568  TypeId GetInstanceTypeId () const;
569  uint32_t GetSerializedSize () const;
570  void Serialize (Buffer::Iterator i) const;
572  void Print (std::ostream &os) const;
573 
574  // No delete flag
579  void SetNoDelete (bool f);
584  bool GetNoDelete () const;
585 
592  bool AddUnDestination (Ipv4Address dst, uint32_t seqNo);
598  bool RemoveUnDestination (std::pair<Ipv4Address, uint32_t> & un);
600  void Clear ();
604  uint8_t GetDestCount () const
605  {
606  return (uint8_t)m_unreachableDstSeqNo.size ();
607  }
608 
614  bool operator== (RerrHeader const & o) const;
615 private:
616  uint8_t m_flag;
617  uint8_t m_reserved;
618 
620  std::map<Ipv4Address, uint32_t> m_unreachableDstSeqNo;
621 };
622 
628 std::ostream & operator<< (std::ostream & os, RerrHeader const &);
629 
630 } // namespace aodv
631 } // namespace ns3
632 
633 #endif /* AODVPACKET_H */
double f(double x, void *params)
Definition: 80211b.c:70
iterator in a Buffer instance
Definition: buffer.h:99
Protocol header serialization and deserialization.
Definition: header.h:43
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:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
Route Error (RERR) Message Format.
Definition: aodv-packet.h:558
uint8_t GetDestCount() const
Definition: aodv-packet.h:604
bool operator==(RerrHeader const &o) const
Comparison operator.
Definition: aodv-packet.cc:653
void Clear()
Clear header.
Definition: aodv-packet.cc:645
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:529
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:617
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:613
RerrHeader()
constructor
Definition: aodv-packet.cc:520
uint8_t m_flag
No delete flag.
Definition: aodv-packet.h:616
void Print(std::ostream &os) const
Definition: aodv-packet.cc:588
void SetNoDelete(bool f)
Set the no delete flag.
Definition: aodv-packet.cc:600
bool AddUnDestination(Ipv4Address dst, uint32_t seqNo)
Add unreachable node address and its sequence number in RERR header.
Definition: aodv-packet.cc:619
std::map< Ipv4Address, uint32_t > m_unreachableDstSeqNo
List of Unreachable destination: IP addresses and sequence numbers.
Definition: aodv-packet.h:620
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:632
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:540
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:546
void Serialize(Buffer::Iterator i) const
Definition: aodv-packet.cc:552
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:504
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:484
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:478
bool operator==(RrepAckHeader const &o) const
Comparison operator.
Definition: aodv-packet.cc:505
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:472
void Print(std::ostream &os) const
Definition: aodv-packet.cc:500
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:461
RrepAckHeader()
constructor
Definition: aodv-packet.cc:453
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:527
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:336
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:337
bool GetAckRequired() const
get the ack required flag
Definition: aodv-packet.cc:405
uint8_t GetPrefixSize() const
Set the pefix size.
Definition: aodv-packet.cc:417
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:399
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:423
void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime)
Configure RREP to be a Hello message.
Definition: aodv-packet.cc:431
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:314
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:375
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:415
bool operator==(RrepHeader const &o) const
Comparison operator.
Definition: aodv-packet.cc:423
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:325
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:367
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:480
void SetLifeTime(Time t)
Set the lifetime.
Definition: aodv-packet.cc:379
void SetAckRequired(bool f)
Set the ack required flag.
Definition: aodv-packet.cc:392
void SetPrefixSize(uint8_t sz)
Set the prefix size.
Definition: aodv-packet.cc:411
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:299
Time GetLifeTime() const
Get the lifetime.
Definition: aodv-packet.cc:385
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:383
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:479
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:407
uint8_t m_flags
A - acknowledgment required flag.
Definition: aodv-packet.h:476
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:391
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:478
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:331
uint8_t m_prefixSize
Prefix Size.
Definition: aodv-packet.h:477
void Print(std::ostream &os) const
Definition: aodv-packet.cc:367
Ipv4Address m_origin
Source IP Address.
Definition: aodv-packet.h:481
uint32_t m_lifeTime
Lifetime (in milliseconds)
Definition: aodv-packet.h:482
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:132
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:191
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:199
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:175
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:306
void SetId(uint32_t id)
Set the request ID.
Definition: aodv-packet.h:183
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:255
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:181
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:142
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:301
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:239
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:305
bool GetDestinationOnly() const
Get the Destination only flag.
Definition: aodv-packet.cc:262
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:303
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:158
uint32_t m_requestID
RREQ ID.
Definition: aodv-packet.h:302
void Print(std::ostream &os) const
Definition: aodv-packet.cc:212
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:167
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:215
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:175
bool operator==(RreqHeader const &o) const
Comparison operator.
Definition: aodv-packet.cc:287
uint8_t m_reserved
Not used (must be 0)
Definition: aodv-packet.h:300
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:223
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:207
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:247
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:169
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
Definition: aodv-packet.cc:243
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:304
uint8_t m_flags
|J|R|G|D|U| bit flags, see RFC
Definition: aodv-packet.h:299
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:231
void Print(std::ostream &os) const
Definition: aodv-packet.cc:97
TypeHeader(MessageType t=AODVTYPE_RREQ)
constructor
Definition: aodv-packet.cc:37
MessageType m_type
type of the message
Definition: aodv-packet.h:99
uint32_t GetSerializedSize() const
Definition: aodv-packet.cc:61
TypeId GetInstanceTypeId() const
Get the most derived TypeId for this Object.
Definition: aodv-packet.cc:55
void Serialize(Buffer::Iterator start) const
Definition: aodv-packet.cc:67
bool m_valid
Indicates if the message is valid.
Definition: aodv-packet.h:100
bool operator==(TypeHeader const &o) const
Comparison operator.
Definition: aodv-packet.cc:127
bool IsValid() const
Check that type if valid.
Definition: aodv-packet.h:88
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:44
MessageType Get() const
Definition: aodv-packet.h:80
MessageType
MessageType enumeration.
Definition: aodv-packet.h:46
@ AODVTYPE_RREP
AODVTYPE_RREP.
Definition: aodv-packet.h:48
@ AODVTYPE_RREP_ACK
AODVTYPE_RREP_ACK.
Definition: aodv-packet.h:50
@ AODVTYPE_RERR
AODVTYPE_RERR.
Definition: aodv-packet.h:49
@ AODVTYPE_RREQ
AODVTYPE_RREQ.
Definition: aodv-packet.h:47
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
std::ostream & operator<<(std::ostream &os, TypeHeader const &h)
Stream output operator.
Definition: aodv-packet.cc:133
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1853