A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-gratuitous-reply-table.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
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 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18 *
19 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20 * ResiliNets Research Group https://resilinets.org/
21 * Information and Telecommunication Technology Center (ITTC)
22 * and Department of Electrical Engineering and Computer Science
23 * The University of Kansas Lawrence, KS USA.
24 *
25 * Work supported in part by NSF FIND (Future Internet Design) Program
26 * under grant CNS-0626918 (Postmodern Internet Architecture),
27 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28 * US Department of Defense (DoD), and ITTC at The University of Kansas.
29 */
30
31#ifndef DSR_GRATUITOUS_REPLY_TABLE_H
32#define DSR_GRATUITOUS_REPLY_TABLE_H
33
34#include "ns3/callback.h"
35#include "ns3/ipv4-address.h"
36#include "ns3/simulator.h"
37#include "ns3/timer.h"
38
39#include <vector>
40
41namespace ns3
42{
43namespace dsr
44{
45/**
46 * The gratuitous table entries, it maintains the already sent gratuitous route reply entries.
47 * When the node "promiscuously" received a packet destined for other nodes, and inferred a shorter
48 * route for the data packet, it will construct a route reply and send back to the source
49 */
51{
52 Ipv4Address m_replyTo; ///< reply to address
53 Ipv4Address m_hearFrom; ///< heard from address
54 Time m_gratReplyHoldoff; ///< gratuitous reply holdoff time
55
56 /**
57 * Constructor
58 *
59 * \param t IPv4 address to reply to
60 * \param f IPv4 address to hear from
61 * \param h gratuitous hold off time
62 */
64 : m_replyTo(t),
65 m_hearFrom(f),
67 {
68 }
69};
70
71/**
72 * \ingroup dsr
73 * \brief maintain the gratuitous reply
74 */
75class DsrGraReply : public Object
76{
77 public:
78 /**
79 * \brief Get the type ID.
80 * \return the object TypeId
81 */
82 static TypeId GetTypeId();
83
85 ~DsrGraReply() override;
86
87 /// Set the gratuitous reply table size
88 /// \param g The gratuitous reply table size
90 {
92 }
93
94 /// Get the gratuitous reply table size
95 /// \returns The gratuitous reply table size
97 {
98 return GraReplyTableSize;
99 }
100
101 /// Add a new gratuitous reply entry
102 /// \param graTableEntry The gratuitous reply entry
103 /// \return true on success
104 bool AddEntry(GraReplyEntry& graTableEntry);
105 /// Update the route entry if found
106 /// \param replyTo Entry directed to
107 /// \param replyFrom Entry heard from
108 /// \param gratReplyHoldoff New gratuitous reply holdoff time
109 /// \return true on success
110 bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff);
111 /// Remove all expired entries
112 void Purge();
113
114 /// Remove all entries
115 void Clear()
116 {
117 m_graReply.clear();
118 }
119
120 private:
121 /// Vector of entries
122 std::vector<GraReplyEntry> m_graReply;
123 /// The max # of gratuitous reply entries to hold
125
126 /// Check if the entry is expired or not
128 {
129 /**
130 * Check if the entry is expired
131 *
132 * \param b GraReplyEntry entry
133 * \return true if expired, false otherwise
134 */
135 bool operator()(const GraReplyEntry& b) const
136 {
137 return (b.m_gratReplyHoldoff < Simulator::Now());
138 }
139 };
140};
141} // namespace dsr
142} // namespace ns3
143
144#endif /* DSR_GRATUITOUS_REPLY_TABLE_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
A base class which provides memory management and object aggregation.
Definition: object.h:89
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
maintain the gratuitous reply
bool AddEntry(GraReplyEntry &graTableEntry)
Add a new gratuitous reply entry.
static TypeId GetTypeId()
Get the type ID.
std::vector< GraReplyEntry > m_graReply
Vector of entries.
uint32_t GraReplyTableSize
The max # of gratuitous reply entries to hold.
void SetGraTableSize(uint32_t g)
Set the gratuitous reply table size.
void Purge()
Remove all expired entries.
uint32_t GetGraTableSize() const
Get the gratuitous reply table size.
bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
Update the route entry if found.
void Clear()
Remove all entries.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Check if the entry is expired or not.
bool operator()(const GraReplyEntry &b) const
Check if the entry is expired.
The gratuitous table entries, it maintains the already sent gratuitous route reply entries.
GraReplyEntry(Ipv4Address t, Ipv4Address f, Time h)
Constructor.
Time m_gratReplyHoldoff
gratuitous reply holdoff time
Ipv4Address m_replyTo
reply to address
Ipv4Address m_hearFrom
heard from address