A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dsr-gratuitous-reply-table.cc
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 
32 #include "dsr-gratuitous-reply-table.h"
33 #include "ns3/log.h"
34 #include <algorithm>
35 
36 NS_LOG_COMPONENT_DEFINE ("DsrGraReplyTable");
37 
38 namespace ns3 {
39 namespace dsr {
40 
41 NS_OBJECT_ENSURE_REGISTERED (GraReply);
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
79 GraReply::AddEntry (GraReplyEntry & graTableEntry)
80 {
81  m_graReply.push_back (graTableEntry);
82  return true;
83 }
84 
85 void
86 GraReply::Purge ()
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
virtual ~GraReply()
Destructor.
keep track of time unit.
Definition: nstime.h:149
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
static Time Now(void)
Definition: simulator.cc:179
static TypeId GetTypeId()
Get the type identificator.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
#define NS_LOG_DEBUG(msg)
Definition: log.h:255
a base class which provides memory management and object aggregation
Definition: object.h:63
a unique identifier for an interface.
Definition: type-id.h:44
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471