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
38namespace ns3
39{
40namespace aodv
41{
42
48{
53};
54
59class 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;
77 void Print(std::ostream& os) const override;
78
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
113std::ostream& operator<<(std::ostream& os, const TypeHeader& h);
114
136class RreqHeader : public Header
137{
138 public:
151 RreqHeader(uint8_t flags = 0,
152 uint8_t reserved = 0,
153 uint8_t hopCount = 0,
154 uint32_t requestID = 0,
155 Ipv4Address dst = Ipv4Address(),
156 uint32_t dstSeqNo = 0,
157 Ipv4Address origin = Ipv4Address(),
158 uint32_t originSeqNo = 0);
159
164 static TypeId GetTypeId();
165 TypeId GetInstanceTypeId() const override;
166 uint32_t GetSerializedSize() const override;
167 void Serialize(Buffer::Iterator start) const override;
169 void Print(std::ostream& os) const override;
170
171 // Fields
176 void SetHopCount(uint8_t count)
177 {
178 m_hopCount = count;
179 }
180
185 uint8_t GetHopCount() const
186 {
187 return m_hopCount;
188 }
189
195 {
196 m_requestID = id;
197 }
198
204 {
205 return m_requestID;
206 }
207
213 {
214 m_dst = a;
215 }
216
222 {
223 return m_dst;
224 }
225
231 {
232 m_dstSeqNo = s;
233 }
234
240 {
241 return m_dstSeqNo;
242 }
243
249 {
250 m_origin = a;
251 }
252
258 {
259 return m_origin;
260 }
261
267 {
268 m_originSeqNo = s;
269 }
270
276 {
277 return m_originSeqNo;
278 }
279
280 // Flags
285 void SetGratuitousRrep(bool f);
290 bool GetGratuitousRrep() const;
295 void SetDestinationOnly(bool f);
300 bool GetDestinationOnly() const;
305 void SetUnknownSeqno(bool f);
310 bool GetUnknownSeqno() const;
311
317 bool operator==(const RreqHeader& o) const;
318
319 private:
320 uint8_t m_flags;
321 uint8_t m_reserved;
322 uint8_t m_hopCount;
328};
329
335std::ostream& operator<<(std::ostream& os, const RreqHeader&);
336
356class RrepHeader : public Header
357{
358 public:
369 RrepHeader(uint8_t prefixSize = 0,
370 uint8_t hopCount = 0,
371 Ipv4Address dst = Ipv4Address(),
372 uint32_t dstSeqNo = 0,
373 Ipv4Address origin = Ipv4Address(),
374 Time lifetime = MilliSeconds(0));
379 static TypeId GetTypeId();
380 TypeId GetInstanceTypeId() const override;
381 uint32_t GetSerializedSize() const override;
382 void Serialize(Buffer::Iterator start) const override;
384 void Print(std::ostream& os) const override;
385
386 // Fields
391 void SetHopCount(uint8_t count)
392 {
393 m_hopCount = count;
394 }
395
400 uint8_t GetHopCount() const
401 {
402 return m_hopCount;
403 }
404
410 {
411 m_dst = a;
412 }
413
419 {
420 return m_dst;
421 }
422
428 {
429 m_dstSeqNo = s;
430 }
431
437 {
438 return m_dstSeqNo;
439 }
440
446 {
447 m_origin = a;
448 }
449
455 {
456 return m_origin;
457 }
458
463 void SetLifeTime(Time t);
468 Time GetLifeTime() const;
469
470 // Flags
475 void SetAckRequired(bool f);
480 bool GetAckRequired() const;
485 void SetPrefixSize(uint8_t sz);
490 uint8_t GetPrefixSize() const;
491
499 void SetHello(Ipv4Address src, uint32_t srcSeqNo, Time lifetime);
500
506 bool operator==(const RrepHeader& o) const;
507
508 private:
509 uint8_t m_flags;
510 uint8_t m_prefixSize;
511 uint8_t m_hopCount;
516};
517
523std::ostream& operator<<(std::ostream& os, const RrepHeader&);
524
536class RrepAckHeader : public Header
537{
538 public:
541
546 static TypeId GetTypeId();
547 TypeId GetInstanceTypeId() const override;
548 uint32_t GetSerializedSize() const override;
549 void Serialize(Buffer::Iterator start) const override;
551 void Print(std::ostream& os) const override;
552
558 bool operator==(const RrepAckHeader& o) const;
559
560 private:
561 uint8_t m_reserved;
562};
563
569std::ostream& operator<<(std::ostream& os, const RrepAckHeader&);
570
590class RerrHeader : public Header
591{
592 public:
594 RerrHeader();
595
600 static TypeId GetTypeId();
601 TypeId GetInstanceTypeId() const override;
602 uint32_t GetSerializedSize() const override;
603 void Serialize(Buffer::Iterator i) const override;
605 void Print(std::ostream& os) const override;
606
607 // No delete flag
612 void SetNoDelete(bool f);
617 bool GetNoDelete() const;
618
625 bool AddUnDestination(Ipv4Address dst, uint32_t seqNo);
632 bool RemoveUnDestination(std::pair<Ipv4Address, uint32_t>& un);
634 void Clear();
635
639 uint8_t GetDestCount() const
640 {
641 return (uint8_t)m_unreachableDstSeqNo.size();
642 }
643
649 bool operator==(const RerrHeader& o) const;
650
651 private:
652 uint8_t m_flag;
653 uint8_t m_reserved;
654
656 std::map<Ipv4Address, uint32_t> m_unreachableDstSeqNo;
657};
658
664std::ostream& operator<<(std::ostream& os, const RerrHeader&);
665
666} // namespace aodv
667} // namespace ns3
668
669#endif /* AODVPACKET_H */
double f(double x, void *params)
Definition: 80211b.c:71
iterator in a Buffer instance
Definition: buffer.h:100
Protocol header serialization and deserialization.
Definition: header.h:44
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:43
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:60
Route Error (RERR) Message Format.
Definition: aodv-packet.h:591
uint32_t Deserialize(Buffer::Iterator start) override
Definition: aodv-packet.cc:566
uint8_t GetDestCount() const
Definition: aodv-packet.h:639
void Clear()
Clear header.
Definition: aodv-packet.cc:645
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:653
bool GetNoDelete() const
Get the no delete flag.
Definition: aodv-packet.cc:613
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:652
bool operator==(const RerrHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:653
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: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:656
void Print(std::ostream &os) const override
Definition: aodv-packet.cc:588
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
Route Reply Acknowledgment (RREP-ACK) Message Format.
Definition: aodv-packet.h:537
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
uint32_t Deserialize(Buffer::Iterator start) override
Definition: aodv-packet.cc:491
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:561
Route Reply (RREP) Message Format.
Definition: aodv-packet.h:357
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 pefix size.
Definition: aodv-packet.cc:419
uint32_t Deserialize(Buffer::Iterator start) override
Definition: aodv-packet.cc:351
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:427
Ipv4Address GetOrigin() const
Get the origin address.
Definition: aodv-packet.h:454
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:400
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:445
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:391
uint32_t GetSerializedSize() const override
Definition: aodv-packet.cc:333
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:513
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:409
Ipv4Address m_dst
Destination IP Address.
Definition: aodv-packet.h:512
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:436
uint8_t m_flags
A - acknowledgment required flag.
Definition: aodv-packet.h:509
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:418
uint8_t m_hopCount
Hop Count.
Definition: aodv-packet.h:511
uint8_t m_prefixSize
Prefix Size.
Definition: aodv-packet.h:510
bool operator==(const RrepHeader &o) const
Comparison operator.
Definition: aodv-packet.cc:425
Ipv4Address m_origin
Source IP Address.
Definition: aodv-packet.h:514
uint32_t m_lifeTime
Lifetime (in milliseconds)
Definition: aodv-packet.h:515
Route Request (RREQ) Message Format.
Definition: aodv-packet.h:137
uint32_t GetId() const
Get the request ID.
Definition: aodv-packet.h:203
void SetDst(Ipv4Address a)
Set the destination address.
Definition: aodv-packet.h:212
uint8_t GetHopCount() const
Get the hop count.
Definition: aodv-packet.h:185
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:327
void SetId(uint32_t id)
Set the request ID.
Definition: aodv-packet.h:194
uint32_t GetOriginSeqno() const
Get the origin sequence number.
Definition: aodv-packet.h:275
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:322
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:257
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:326
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:324
static TypeId GetTypeId()
Get the type ID.
Definition: aodv-packet.cc:160
uint32_t m_requestID
RREQ ID.
Definition: aodv-packet.h:323
void SetHopCount(uint8_t count)
Set the hop count.
Definition: aodv-packet.h:176
void SetDstSeqno(uint32_t s)
Set the destination sequence number.
Definition: aodv-packet.h:230
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:321
uint32_t GetDstSeqno() const
Get the destination sequence number.
Definition: aodv-packet.h:239
Ipv4Address GetDst() const
Get the destination address.
Definition: aodv-packet.h:221
void SetOriginSeqno(uint32_t s)
Set the origin sequence number.
Definition: aodv-packet.h:266
bool GetGratuitousRrep() const
Get the gratuitous RREP flag.
Definition: aodv-packet.cc:243
uint32_t m_dstSeqNo
Destination Sequence Number.
Definition: aodv-packet.h:325
uint32_t Deserialize(Buffer::Iterator start) override
Definition: aodv-packet.cc:195
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:320
void SetOrigin(Ipv4Address a)
Set the origin address.
Definition: aodv-packet.h:248
uint32_t Deserialize(Buffer::Iterator start) override
Definition: aodv-packet.cc:74
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:1350
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.
def start()
Definition: core.py:1861