A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Based on
7
* NS-2 AODV model developed by the CMU/MONARCH group and optimized and
8
* tuned by Samir Das and Mahesh Marina, University of Cincinnati;
9
*
10
* AODV-UU implementation by Erik Nordström of Uppsala University
11
* https://web.archive.org/web/20100527072022/http://core.it.uu.se/core/index.php/AODV-UU
12
*
13
* Authors: Elena Buchatskaia <borovkovaes@iitp.ru>
14
* Pavel Boyko <boyko@iitp.ru>
15
*/
16
17
#ifndef AODV_ID_CACHE_H
18
#define AODV_ID_CACHE_H
19
20
#include "ns3/ipv4-address.h"
21
#include "ns3/simulator.h"
22
23
#include <vector>
24
25
namespace
ns3
26
{
27
namespace
aodv
28
{
29
/**
30
* \ingroup aodv
31
*
32
* \brief Unique packets identification cache used for simple duplicate detection.
33
*/
34
class
IdCache
35
{
36
public
:
37
/**
38
* constructor
39
* \param lifetime the lifetime for added entries
40
*/
41
IdCache
(
Time
lifetime)
42
:
m_lifetime
(lifetime)
43
{
44
}
45
46
/**
47
* Check that entry (addr, id) exists in cache. Add entry, if it doesn't exist.
48
* \param addr the IP address
49
* \param id the cache entry ID
50
* \returns true if the pair exists
51
*/
52
bool
IsDuplicate
(
Ipv4Address
addr,
uint32_t
id
);
53
/// Remove all expired entries
54
void
Purge
();
55
/**
56
* \returns number of entries in cache
57
*/
58
uint32_t
GetSize
();
59
60
/**
61
* Set lifetime for future added entries.
62
* \param lifetime the lifetime for entries
63
*/
64
void
SetLifetime
(
Time
lifetime)
65
{
66
m_lifetime
= lifetime;
67
}
68
69
/**
70
* Return lifetime for existing entries in cache
71
* \returns the lifetime
72
*/
73
Time
GetLifeTime
()
const
74
{
75
return
m_lifetime
;
76
}
77
78
private
:
79
/// Unique packet ID
80
struct
UniqueId
81
{
82
/// ID is supposed to be unique in single address context (e.g. sender address)
83
Ipv4Address
m_context
;
84
/// The id
85
uint32_t
m_id
;
86
/// When record will expire
87
Time
m_expire
;
88
};
89
90
/**
91
* \brief IsExpired structure
92
*/
93
struct
IsExpired
94
{
95
/**
96
* \brief Check if the entry is expired
97
*
98
* \param u UniqueId entry
99
* \return true if expired, false otherwise
100
*/
101
bool
operator()
(
const
UniqueId
& u)
const
102
{
103
return
(u.
m_expire
<
Simulator::Now
());
104
}
105
};
106
107
/// Already seen IDs
108
std::vector<UniqueId>
m_idCache
;
109
/// Default lifetime for ID records
110
Time
m_lifetime
;
111
};
112
113
}
// namespace aodv
114
}
// namespace ns3
115
116
#endif
/* AODV_ID_CACHE_H */
ns3::Ipv4Address
Ipv4 addresses are stored in host order in this class.
Definition
ipv4-address.h:31
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
ns3::aodv::IdCache
Unique packets identification cache used for simple duplicate detection.
Definition
aodv-id-cache.h:35
ns3::aodv::IdCache::m_idCache
std::vector< UniqueId > m_idCache
Already seen IDs.
Definition
aodv-id-cache.h:108
ns3::aodv::IdCache::Purge
void Purge()
Remove all expired entries.
Definition
aodv-id-cache.cc:41
ns3::aodv::IdCache::SetLifetime
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Definition
aodv-id-cache.h:64
ns3::aodv::IdCache::m_lifetime
Time m_lifetime
Default lifetime for ID records.
Definition
aodv-id-cache.h:110
ns3::aodv::IdCache::GetLifeTime
Time GetLifeTime() const
Return lifetime for existing entries in cache.
Definition
aodv-id-cache.h:73
ns3::aodv::IdCache::IsDuplicate
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
Definition
aodv-id-cache.cc:25
ns3::aodv::IdCache::GetSize
uint32_t GetSize()
Definition
aodv-id-cache.cc:47
ns3::aodv::IdCache::IdCache
IdCache(Time lifetime)
constructor
Definition
aodv-id-cache.h:41
uint32_t
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::aodv::IdCache::IsExpired
IsExpired structure.
Definition
aodv-id-cache.h:94
ns3::aodv::IdCache::IsExpired::operator()
bool operator()(const UniqueId &u) const
Check if the entry is expired.
Definition
aodv-id-cache.h:101
ns3::aodv::IdCache::UniqueId
Unique packet ID.
Definition
aodv-id-cache.h:81
ns3::aodv::IdCache::UniqueId::m_expire
Time m_expire
When record will expire.
Definition
aodv-id-cache.h:87
ns3::aodv::IdCache::UniqueId::m_id
uint32_t m_id
The id.
Definition
aodv-id-cache.h:85
ns3::aodv::IdCache::UniqueId::m_context
Ipv4Address m_context
ID is supposed to be unique in single address context (e.g. sender address)
Definition
aodv-id-cache.h:83
src
aodv
model
aodv-id-cache.h
Generated on Fri Nov 8 2024 13:58:58 for ns-3 by
1.11.0