A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dsr-gratuitous-reply-table.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Yufei Cheng
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Yufei Cheng <yfcheng@ittc.ku.edu>
7 *
8 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
9 * ResiliNets Research Group https://resilinets.org/
10 * Information and Telecommunication Technology Center (ITTC)
11 * and Department of Electrical Engineering and Computer Science
12 * The University of Kansas Lawrence, KS USA.
13 *
14 * Work supported in part by NSF FIND (Future Internet Design) Program
15 * under grant CNS-0626918 (Postmodern Internet Architecture),
16 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
17 * US Department of Defense (DoD), and ITTC at The University of Kansas.
18 */
19
21
22#include "ns3/log.h"
23
24#include <algorithm>
25
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE("DsrGraReplyTable");
30
31namespace dsr
32{
33
35
36TypeId
38{
39 static TypeId tid = TypeId("ns3::dsr::DsrGraReply")
41 .SetGroupName("Dsr")
42 .AddConstructor<DsrGraReply>();
43 return tid;
44}
45
49
54
55bool
56DsrGraReply::FindAndUpdate(Ipv4Address replyTo, Ipv4Address replyFrom, Time gratReplyHoldoff)
57{
58 Purge(); // purge the gratuitous reply table
59 for (auto i = m_graReply.begin(); i != m_graReply.end(); ++i)
60 {
61 if ((i->m_replyTo == replyTo) && (i->m_hearFrom == replyFrom))
62 {
63 NS_LOG_DEBUG("Update the reply to ip address if found the gratuitous reply entry");
64 i->m_gratReplyHoldoff =
65 std::max(gratReplyHoldoff + Simulator::Now(), i->m_gratReplyHoldoff);
66 return true;
67 }
68 }
69 return false;
70}
71
72bool
74{
75 m_graReply.push_back(graTableEntry);
76 return true;
77}
78
79void
81{
82 /*
83 * Purge the expired gratuitous reply entries
84 */
85 m_graReply.erase(remove_if(m_graReply.begin(), m_graReply.end(), IsExpired()),
86 m_graReply.end());
87}
88
89} // namespace dsr
90} // namespace ns3
Ipv4 addresses are stored in host order in this class.
A base class which provides memory management and object aggregation.
Definition object.h:78
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:35
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.