A Discrete-Event Network Simulator
API
dsr-gratuitous-reply-table.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Yufei Cheng
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  * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  * Work supported in part by NSF FIND (Future Internet Design) Program
27  * under grant CNS-0626918 (Postmodern Internet Architecture),
28  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29  * US Department of Defense (DoD), and ITTC at The University of Kansas.
30  */
31 
33 #include "ns3/log.h"
34 #include <algorithm>
35 
36 namespace ns3 {
37 
38 NS_LOG_COMPONENT_DEFINE ("DsrGraReplyTable");
39 
40 namespace dsr {
41 
42 NS_OBJECT_ENSURE_REGISTERED (DsrGraReply);
43 
45 {
46  static TypeId tid = TypeId ("ns3::dsr::DsrGraReply")
47  .SetParent<Object> ()
48  .SetGroupName ("Dsr")
49  .AddConstructor<DsrGraReply> ()
50  ;
51  return tid;
52 }
53 
55 {
56 }
57 
59 {
61 }
62 
63 bool
64 DsrGraReply::FindAndUpdate (Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
65 {
66  Purge (); // purge the gratuitous reply table
67  for (std::vector<GraReplyEntry>::iterator i = m_graReply.begin ();
68  i != m_graReply.end (); ++i)
69  {
70  if ((i->m_replyTo == replyTo) && (i->m_hearFrom == replyFrom))
71  {
72  NS_LOG_DEBUG ("Update the reply to ip address if found the gratuitous reply entry");
73  i->m_gratReplyHoldoff = std::max (gratReplyHoldoff + Simulator::Now (), i->m_gratReplyHoldoff);
74  return true;
75  }
76  }
77  return false;
78 }
79 
80 bool
82 {
83  m_graReply.push_back (graTableEntry);
84  return true;
85 }
86 
87 void
89 {
90  /*
91  * Purge the expired gratuitous reply entries
92  */
93  m_graReply.erase (remove_if (m_graReply.begin (), m_graReply.end (),
94  IsExpired ()), m_graReply.end ());
95 }
96 
97 } // namespace dsr
98 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
maintain the gratuitous reply
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
Update the route entry if found, create a new one if not.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Check if the entry is expired or not.
std::vector< GraReplyEntry > m_graReply
Vector of entries.
#define max(a, b)
Definition: 80211b.c:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Purge()
Remove all expired entries.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:224
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
bool AddEntry(GraReplyEntry &graTableEntry)
Add a new gratuitous reply entry.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904