A Discrete-Event Network Simulator
API
dsr-gratuitous-reply-table.cc
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 
32 
33 #include "ns3/log.h"
34 
35 #include <algorithm>
36 
37 namespace ns3
38 {
39 
40 NS_LOG_COMPONENT_DEFINE("DsrGraReplyTable");
41 
42 namespace dsr
43 {
44 
45 NS_OBJECT_ENSURE_REGISTERED(DsrGraReply);
46 
47 TypeId
49 {
50  static TypeId tid = TypeId("ns3::dsr::DsrGraReply")
51  .SetParent<Object>()
52  .SetGroupName("Dsr")
53  .AddConstructor<DsrGraReply>();
54  return tid;
55 }
56 
58 {
59 }
60 
62 {
64 }
65 
66 bool
67 DsrGraReply::FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
68 {
69  Purge(); // purge the gratuitous reply table
70  for (auto i = m_graReply.begin(); i != m_graReply.end(); ++i)
71  {
72  if ((i->m_replyTo == replyTo) && (i->m_hearFrom == replyFrom))
73  {
74  NS_LOG_DEBUG("Update the reply to ip address if found the gratuitous reply entry");
75  i->m_gratReplyHoldoff =
76  std::max(gratReplyHoldoff + Simulator::Now(), i->m_gratReplyHoldoff);
77  return true;
78  }
79  }
80  return false;
81 }
82 
83 bool
85 {
86  m_graReply.push_back(graTableEntry);
87  return true;
88 }
89 
90 void
92 {
93  /*
94  * Purge the expired gratuitous reply entries
95  */
96  m_graReply.erase(remove_if(m_graReply.begin(), m_graReply.end(), IsExpired()),
97  m_graReply.end());
98 }
99 
100 } // namespace dsr
101 } // namespace ns3
#define max(a, b)
Definition: 80211b.c:42
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
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
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.
void Purge()
Remove all expired entries.
bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
Update the route entry if found.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Check if the entry is expired or not.
The gratuitous table entries, it maintains the already sent gratuitous route reply entries.