A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
aodv-id-cache.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
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 * Based on
18 * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
19 * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
20 *
21 * AODV-UU implementation by Erik Nordström of Uppsala University
22 * https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
23 *
24 * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
25 * Pavel Boyko <boyko@iitp.ru>
26 */
27
28#ifndef AODV_ID_CACHE_H
29#define AODV_ID_CACHE_H
30
31#include "ns3/ipv4-address.h"
32#include "ns3/simulator.h"
33
34#include <vector>
35
36namespace ns3
37{
38namespace aodv
39{
40/**
41 * \ingroup aodv
42 *
43 * \brief Unique packets identification cache used for simple duplicate detection.
44 */
46{
47 public:
48 /**
49 * constructor
50 * \param lifetime the lifetime for added entries
51 */
52 IdCache(Time lifetime)
53 : m_lifetime(lifetime)
54 {
55 }
56
57 /**
58 * Check that entry (addr, id) exists in cache. Add entry, if it doesn't exist.
59 * \param addr the IP address
60 * \param id the cache entry ID
61 * \returns true if the pair exists
62 */
63 bool IsDuplicate(Ipv4Address addr, uint32_t id);
64 /// Remove all expired entries
65 void Purge();
66 /**
67 * \returns number of entries in cache
68 */
70
71 /**
72 * Set lifetime for future added entries.
73 * \param lifetime the lifetime for entries
74 */
75 void SetLifetime(Time lifetime)
76 {
77 m_lifetime = lifetime;
78 }
79
80 /**
81 * Return lifetime for existing entries in cache
82 * \returns the lifetime
83 */
85 {
86 return m_lifetime;
87 }
88
89 private:
90 /// Unique packet ID
91 struct UniqueId
92 {
93 /// ID is supposed to be unique in single address context (e.g. sender address)
95 /// The id
97 /// When record will expire
99 };
100
101 /**
102 * \brief IsExpired structure
103 */
105 {
106 /**
107 * \brief Check if the entry is expired
108 *
109 * \param u UniqueId entry
110 * \return true if expired, false otherwise
111 */
112 bool operator()(const UniqueId& u) const
113 {
114 return (u.m_expire < Simulator::Now());
115 }
116 };
117
118 /// Already seen IDs
119 std::vector<UniqueId> m_idCache;
120 /// Default lifetime for ID records
122};
123
124} // namespace aodv
125} // namespace ns3
126
127#endif /* AODV_ID_CACHE_H */
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
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
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:46
std::vector< UniqueId > m_idCache
Already seen IDs.
void Purge()
Remove all expired entries.
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition: aodv-id-cache.h:75
Time m_lifetime
Default lifetime for ID records.
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition: aodv-id-cache.h:84
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
IdCache(Time lifetime)
constructor
Definition: aodv-id-cache.h:52
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IsExpired structure.
bool operator()(const UniqueId &u) const
Check if the entry is expired.
Time m_expire
When record will expire.
Definition: aodv-id-cache.h:98
Ipv4Address m_context
ID is supposed to be unique in single address context (e.g. sender address)
Definition: aodv-id-cache.h:94