A Discrete-Event Network Simulator
API
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 
36 namespace ns3
37 {
38 namespace aodv
39 {
45 class IdCache
46 {
47  public:
52  IdCache(Time lifetime)
53  : m_lifetime(lifetime)
54  {
55  }
56 
63  bool IsDuplicate(Ipv4Address addr, uint32_t id);
65  void Purge();
69  uint32_t GetSize();
70 
75  void SetLifetime(Time lifetime)
76  {
77  m_lifetime = lifetime;
78  }
79 
84  Time GetLifeTime() const
85  {
86  return m_lifetime;
87  }
88 
89  private:
91  struct UniqueId
92  {
96  uint32_t m_id;
99  };
100 
104  struct IsExpired
105  {
112  bool operator()(const UniqueId& u) const
113  {
114  return (u.m_expire < Simulator::Now());
115  }
116  };
117 
119  std::vector<UniqueId> m_idCache;
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