20 #ifndef NDN_CONTENT_STORE_IMPL_H_
21 #define NDN_CONTENT_STORE_IMPL_H_
23 #include "ns3/ndnSIM/model/ndn-common.hpp"
27 #include "ns3/packet.h"
28 #include <boost/foreach.hpp>
31 #include "ns3/uinteger.h"
32 #include "ns3/string.h"
34 #include "../../utils/trie/trie-with-policy.hpp"
50 EntryImpl(Ptr<ContentStore> cs, shared_ptr<const Data> data)
57 SetTrie(
typename CS::super::iterator item)
62 typename CS::super::iterator
67 typename CS::super::const_iterator
74 typename CS::super::iterator item_;
81 template<
class Policy>
85 trie_with_policy<Name,
86 ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>,
91 trie_with_policy<Name, ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>,
105 virtual inline shared_ptr<Data>
106 Lookup(shared_ptr<const Interest> interest);
109 Add(shared_ptr<const Data> data);
115 Print(std::ostream& os)
const;
126 virtual Ptr<Entry>
Next(Ptr<Entry>);
128 const typename super::policy_container&
131 return super::getPolicy();
134 typename super::policy_container&
137 return super::getPolicy();
142 SetMaxSize(uint32_t maxSize);
148 static LogComponent g_log;
152 TracedCallback<Ptr<const Entry>> m_didAddEntry;
159 template<
class Policy>
161 ContentStoreImpl<Policy>::g_log = LogComponent((
"ndn.cs." + Policy::GetName()).c_str());
163 template<
class Policy>
168 TypeId((
"ns3::ndn::cs::" + Policy::GetName()).c_str())
172 .AddAttribute(
"MaxSize",
173 "Set maximum number of entries in ContentStore. If 0, limit is not enforced",
176 MakeUintegerChecker<uint32_t>())
178 .AddTraceSource(
"DidAddEntry",
179 "Trace fired every time entry is successfully added to the cache",
194 return !m_exclude.isExcluded(comp);
198 const Exclude& m_exclude;
201 template<
class Policy>
205 NS_LOG_FUNCTION(
this << interest->getName());
207 typename super::const_iterator node;
208 if (interest->getExclude().empty()) {
209 node = this->deepest_prefix_match(interest->getName());
212 node = this->deepest_prefix_match_if_next_level(interest->getName(),
216 if (node != this->end()) {
217 this->m_cacheHitsTrace(interest, node->payload()->GetData());
219 shared_ptr<Data> copy = make_shared<Data>(*node->payload()->GetData());
223 this->m_cacheMissesTrace(interest);
228 template<
class Policy>
232 NS_LOG_FUNCTION(
this << data->getName());
234 Ptr<entry> newEntry = Create<entry>(
this, data);
235 std::pair<typename super::iterator, bool> result = super::insert(data->getName(), newEntry);
237 if (result.first != super::end()) {
239 newEntry->SetTrie(result.first);
241 m_didAddEntry(newEntry);
254 template<
class Policy>
258 for (
typename super::policy_container::const_iterator item = this->getPolicy().begin();
259 item != this->getPolicy().end(); item++) {
260 os << item->payload ()->GetName () << std::endl;
264 template<
class Policy>
268 this->getPolicy().set_max_size(maxSize);
271 template<
class Policy>
273 ContentStoreImpl<Policy>::GetMaxSize()
const
275 return this->getPolicy().get_max_size();
278 template<
class Policy>
282 return this->getPolicy().size();
285 template<
class Policy>
289 typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0);
290 for (; item != end; item++) {
291 if (item->payload() == 0)
299 return item->payload();
302 template<
class Policy>
309 template<
class Policy>
316 typename super::parent_trie::recursive_iterator item(*StaticCast<entry>(from)->to_iterator()),
319 for (item++; item != end; item++) {
320 if (item->payload() == 0)
328 return item->payload();
335 #endif // NDN_CONTENT_STORE_IMPL_H_
virtual Ptr< Entry > Begin()
Return first element of content store (no order guaranteed)
void SetTrie(typename CS::super::iterator item)
virtual shared_ptr< Data > Lookup(shared_ptr< const Interest > interest)
Find corresponding CS entry for the given interest.
EntryImpl(Ptr< ContentStore > cs, shared_ptr< const Data > data)
EntryImpl< ContentStoreImpl< Policy > > entry
super::policy_container & GetPolicy()
static TypeId GetTypeId()
ndnSIM::trie_with_policy< Name, ndnSIM::smart_pointer_payload_traits< EntryImpl< ContentStoreImpl< Policy > >, Entry >, Policy > super
bool operator()(const name::Component &comp) const
Cache entry implementation with additional references to the base container.
const super::policy_container & GetPolicy() const
CS::super::iterator to_iterator()
CS::super::const_iterator to_iterator() const
virtual Ptr< Entry > End()
Return item next after last (no order guaranteed)
virtual bool Add(shared_ptr< const Data > data)
Add a new content to the content store.
virtual void Print(std::ostream &os) const
Print out content store entries.
isNotExcluded(const Exclude &exclude)
Base implementation of NDN content store.
virtual Ptr< Entry > Next(Ptr< Entry >)
virtual ~ContentStoreImpl()
virtual uint32_t GetSize() const
Get number of entries in content store.
Base class for NDN content store.