A Discrete-Event Network Simulator
API
aodv-id-cache.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
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  * Based on
19  * NS-2 AODV model developed by the CMU/MONARCH group and optimized and
20  * tuned by Samir Das and Mahesh Marina, University of Cincinnati;
21  *
22  * AODV-UU implementation by Erik Nordström of Uppsala University
23  * http://core.it.uu.se/core/index.php/AODV-UU
24  *
25  * Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
26  * Pavel Boyko <boyko@iitp.ru>
27  */
28 
29 #ifndef AODV_ID_CACHE_H
30 #define AODV_ID_CACHE_H
31 
32 #include "ns3/ipv4-address.h"
33 #include "ns3/simulator.h"
34 #include <vector>
35 
36 namespace ns3 {
37 namespace aodv {
43 class IdCache
44 {
45 public:
50  IdCache (Time lifetime) : m_lifetime (lifetime)
51  {
52  }
59  bool IsDuplicate (Ipv4Address addr, uint32_t id);
61  void Purge ();
65  uint32_t GetSize ();
70  void SetLifetime (Time lifetime)
71  {
72  m_lifetime = lifetime;
73  }
78  Time GetLifeTime () const
79  {
80  return m_lifetime;
81  }
82 private:
84  struct UniqueId
85  {
89  uint32_t m_id;
92  };
96  struct IsExpired
97  {
104  bool operator() (const struct UniqueId & u) const
105  {
106  return (u.m_expire < Simulator::Now ());
107  }
108  };
110  std::vector<UniqueId> m_idCache;
113 };
114 
115 } // namespace aodv
116 } // namespace ns3
117 
118 #endif /* AODV_ID_CACHE_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
IsExpired structure.
Definition: aodv-id-cache.h:96
Unique packets identification cache used for simple duplicate detection.
Definition: aodv-id-cache.h:43
void Purge()
Remove all expired entries.
bool operator()(const struct UniqueId &u) const
Check if the entry is expired.
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition: aodv-id-cache.h:78
std::vector< UniqueId > m_idCache
Already seen IDs.
Ipv4Address m_context
ID is supposed to be unique in single address context (e.g. sender address)
Definition: aodv-id-cache.h:87
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IdCache(Time lifetime)
constructor
Definition: aodv-id-cache.h:50
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition: aodv-id-cache.h:70
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
Time m_expire
When record will expire.
Definition: aodv-id-cache.h:91
Time m_lifetime
Default lifetime for ID records.