ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
cs.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include "ndn/common.hpp"
15#include "ndn/data.hpp"
16
17namespace ndn {
18
20constexpr size_t CS_DEFAULT_ENTRIES = 15;
21
23constexpr size_t CS_MANET_ENTRIES = 100;
24
26constexpr size_t CS_LARGE_MANET_ENTRIES = 200;
27
33class CsEntry {
34public:
39 const Data& data() const { return data_; }
40
48 TimeMs staleTime() const { return staleTime_; }
49
56 bool isFresh(TimeMs now) const;
57
58private:
59 friend class ContentStore;
60 Data data_;
61 TimeMs staleTime_ = 0;
62 TimeMs lastUsed_ = 0;
63 bool inUse_ = false;
64};
65
93public:
97 ContentStore() = default;
98
105
106 // Copy and move prohibited (due to pointer management)
107 ContentStore(const ContentStore&) = delete;
108 ContentStore& operator=(const ContentStore&) = delete;
109 ContentStore(ContentStore&&) = delete;
110 ContentStore& operator=(ContentStore&&) = delete;
111
123 Error init(size_t maxEntries = CS_DEFAULT_ENTRIES);
124
139 Error insert(const Data& data, TimeMs now);
140
149 const CsEntry* find(const Name& name, bool mustBeFresh = false, TimeMs now = 0) const;
150
155 void remove(const Name& name);
156
164 void evictStale(TimeMs now);
175 size_t size() const { return size_; }
176
181 size_t capacity() const { return capacity_; }
182
186 struct Stats {
187 uint32_t hits = 0;
188 uint32_t misses = 0;
189 uint32_t insertions = 0;
190 uint32_t evictions = 0;
191 };
192
197 const Stats& stats() const { return stats_; }
200private:
201 CsEntry* entries_ = nullptr;
202 size_t capacity_ = 0;
203 size_t size_ = 0;
204 Stats stats_{};
205
210 CsEntry* findLruEntry();
211};
212
213} // namespace ndn
Content Store.
Definition cs.hpp:92
size_t size() const
Get the current number of entries.
Definition cs.hpp:175
Error init(size_t maxEntries=CS_DEFAULT_ENTRIES)
Initialize the Content Store.
Definition cs.cpp:33
size_t capacity() const
Get the maximum number of entries.
Definition cs.hpp:181
~ContentStore()
Destructor.
Definition cs.cpp:26
const Stats & stats() const
Get statistics.
Definition cs.hpp:197
Error insert(const Data &data, TimeMs now)
Insert Data into the cache.
Definition cs.cpp:61
ContentStore()=default
Default constructor.
const CsEntry * find(const Name &name, bool mustBeFresh=false, TimeMs now=0) const
Search the cache by Name.
Definition cs.cpp:115
void remove(const Name &name)
Remove the entry with the specified Name.
Definition cs.cpp:133
void evictStale(TimeMs now)
Remove stale entries.
Definition cs.cpp:144
Content Store entry.
Definition cs.hpp:33
bool isFresh(TimeMs now) const
Check if the Data is fresh.
Definition cs.cpp:15
const Data & data() const
Get the cached Data.
Definition cs.hpp:39
TimeMs staleTime() const
Get the freshness expiration timestamp.
Definition cs.hpp:48
NDN Data packet.
Definition data.hpp:49
NDN Name class.
Definition name.hpp:64
Common definitions for the NDN protocol stack.
uint64_t TimeMs
Timestamp type (milliseconds)
Definition common.hpp:107
Error
Error codes.
Definition common.hpp:24
constexpr size_t CS_LARGE_MANET_ENTRIES
Number of CS entries for large-scale MANET.
Definition cs.hpp:26
constexpr size_t CS_MANET_ENTRIES
Number of CS entries for MANET.
Definition cs.hpp:23
constexpr size_t CS_DEFAULT_ENTRIES
Default number of CS entries.
Definition cs.hpp:20
NDN Data packet.
CS statistics.
Definition cs.hpp:186
uint32_t misses
Cache miss count.
Definition cs.hpp:188
uint32_t evictions
Eviction count.
Definition cs.hpp:190
uint32_t insertions
Insertion count.
Definition cs.hpp:189
uint32_t hits
Cache hit count.
Definition cs.hpp:187