A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("DsrGraReplyTable");
37 
38 namespace ns3 {
39 namespace dsr {
40 
42 
44 {
45  static TypeId tid = TypeId ("ns3::dsr::GraReply")
46  .SetParent<Object> ()
47  .AddConstructor<GraReply> ()
48  ;
49  return tid;
50 }
51 
53 {
54 }
55 
57 {
59 }
60 
61 bool
62 GraReply::FindAndUpdate (Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
63 {
64  Purge (); // purge the gratuitous reply table
65  for (std::vector<GraReplyEntry>::iterator i = m_graReply.begin ();
66  i != m_graReply.end (); ++i)
67  {
68  if ((i->m_replyTo == replyTo) && (i->m_hearFrom == replyFrom))
69  {
70  NS_LOG_DEBUG ("Update the reply to ip address if found the gratuitous reply entry");
71  i->m_gratReplyHoldoff = std::max (gratReplyHoldoff + Simulator::Now (), i->m_gratReplyHoldoff);
72  return true;
73  }
74  }
75  return false;
76 }
77 
78 bool
80 {
81  m_graReply.push_back (graTableEntry);
82  return true;
83 }
84 
85 void
87 {
88  /*
89  * Purge the expired gratuitous reply entries
90  */
91  m_graReply.erase (remove_if (m_graReply.begin (), m_graReply.end (),
92  IsExpired ()), m_graReply.end ());
93 }
94 
95 } // namespace dsr
96 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#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.
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
bool FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
Update the route entry if found, create a new one if not.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
a base class which provides memory management and object aggregation
Definition: object.h:64
bool AddEntry(GraReplyEntry &graTableEntry)
Add a new gratuitous reply entry.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void Purge()
Remove all expired entries.