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 * 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
25namespace ns3
26{
27namespace aodv
28{
29/**
30 * \ingroup aodv
31 *
32 * \brief Unique packets identification cache used for simple duplicate detection.
33 */
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 */
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 */
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)
84 /// The id
86 /// When record will 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
111};
112
113} // namespace aodv
114} // namespace ns3
115
116#endif /* AODV_ID_CACHE_H */
Ipv4 addresses are stored in host order in this class.
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
Unique packets identification cache used for simple duplicate detection.
std::vector< UniqueId > m_idCache
Already seen IDs.
void Purge()
Remove all expired entries.
void SetLifetime(Time lifetime)
Set lifetime for future added entries.
Time m_lifetime
Default lifetime for ID records.
Time GetLifeTime() const
Return lifetime for existing entries in cache.
bool IsDuplicate(Ipv4Address addr, uint32_t id)
Check that entry (addr, id) exists in cache.
IdCache(Time lifetime)
constructor
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator()(const UniqueId &u) const
Check if the entry is expired.
Time m_expire
When record will expire.
Ipv4Address m_context
ID is supposed to be unique in single address context (e.g. sender address)