diff --git a/bindings/modulegen__gcc_ILP32.py b/bindings/modulegen__gcc_ILP32.py index 7e539eff6..791a3bcf9 100644 --- a/bindings/modulegen__gcc_ILP32.py +++ b/bindings/modulegen__gcc_ILP32.py @@ -91,13 +91,6 @@ def reg_stackhelper(cls): param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) cls.add_method('setCsSize', retval('void'), [param('size_t', 'maxSize')]) - cls.add_method('SetOldContentStore', - retval('void'), - [param('const std::string&', 'contentStoreClass'), - param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), - param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), - param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), - param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) reg_stackhelper(root_module['ns3::ndn::StackHelper']) def reg_fibhelper(cls): diff --git a/bindings/modulegen__gcc_LP64.py b/bindings/modulegen__gcc_LP64.py index 7e539eff6..791a3bcf9 100644 --- a/bindings/modulegen__gcc_LP64.py +++ b/bindings/modulegen__gcc_LP64.py @@ -91,13 +91,6 @@ def reg_stackhelper(cls): param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) cls.add_method('setCsSize', retval('void'), [param('size_t', 'maxSize')]) - cls.add_method('SetOldContentStore', - retval('void'), - [param('const std::string&', 'contentStoreClass'), - param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), - param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), - param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), - param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) reg_stackhelper(root_module['ns3::ndn::StackHelper']) def reg_fibhelper(cls): diff --git a/helper/ndn-stack-helper.cpp b/helper/ndn-stack-helper.cpp index 863b191e2..09f0d8cdc 100644 --- a/helper/ndn-stack-helper.cpp +++ b/helper/ndn-stack-helper.cpp @@ -35,7 +35,6 @@ #include "model/ndn-net-device-transport.hpp" #include "utils/ndn-time.hpp" #include "utils/dummy-keychain.hpp" -#include "model/cs/ndn-content-store.hpp" #include #include @@ -64,7 +63,6 @@ StackHelper::StackHelper() m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"]; m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol"); - m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru"); m_netDeviceCallbacks.push_back( std::make_pair(PointToPointNetDevice::GetTypeId(), @@ -113,26 +111,6 @@ StackHelper::SetStackAttributes(const std::string& attr1, const std::string& val m_ndnFactory.Set(attr4, StringValue(value4)); } -void -StackHelper::SetOldContentStore(const std::string& contentStore, const std::string& attr1, - const std::string& value1, const std::string& attr2, - const std::string& value2, const std::string& attr3, - const std::string& value3, const std::string& attr4, - const std::string& value4) -{ - m_maxCsSize = 0; - - m_contentStoreFactory.SetTypeId(contentStore); - if (attr1 != "") - m_contentStoreFactory.Set(attr1, StringValue(value1)); - if (attr2 != "") - m_contentStoreFactory.Set(attr2, StringValue(value2)); - if (attr3 != "") - m_contentStoreFactory.Set(attr3, StringValue(value3)); - if (attr4 != "") - m_contentStoreFactory.Set(attr4, StringValue(value4)); -} - void StackHelper::setCsSize(size_t maxSize) { @@ -197,14 +175,7 @@ StackHelper::doInstall(Ptr node) const ndn->getConfig().put("tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize); - // Create and aggregate content store if NFD's contest store has been disabled - if (m_maxCsSize == 0) { - ndn->AggregateObject(m_contentStoreFactory.Create()); - } - // if NFD's CS is enabled, check if a replacement policy has been specified - else { - ndn->setCsReplacementPolicy(m_csPolicyCreationFunc); - } + ndn->setCsReplacementPolicy(m_csPolicyCreationFunc); // Aggregate L3Protocol on node (must be after setting ndnSIM CS) node->AggregateObject(ndn); diff --git a/helper/ndn-stack-helper.hpp b/helper/ndn-stack-helper.hpp index 1237a15f5..c2ab6f0a4 100644 --- a/helper/ndn-stack-helper.hpp +++ b/helper/ndn-stack-helper.hpp @@ -85,19 +85,6 @@ class StackHelper : boost::noncopyable { void setPolicy(const std::string& policy); - /** - * @brief Set ndnSIM 1.0 content store implementation and its attributes - * @param contentStoreClass string, representing class of the content store - * @note ndnSIM 1.0 content store implementation have limited support for Interest selectors - * Do not use these implementations if your scenario relies on proper selector processing. - */ - void - SetOldContentStore(const std::string& contentStoreClass, const std::string& attr1 = "", - const std::string& value1 = "", const std::string& attr2 = "", - const std::string& value2 = "", const std::string& attr3 = "", - const std::string& value3 = "", const std::string& attr4 = "", - const std::string& value4 = ""); - typedef Callback, Ptr, Ptr, Ptr> FaceCreateCallback; @@ -266,7 +253,6 @@ class StackHelper : boost::noncopyable { private: ObjectFactory m_ndnFactory; - ObjectFactory m_contentStoreFactory; bool m_needSetDefaultRoutes; size_t m_maxCsSize; diff --git a/model/cs/content-store-impl.cpp b/model/cs/content-store-impl.cpp deleted file mode 100644 index b5b00f2ab..000000000 --- a/model/cs/content-store-impl.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "content-store-impl.hpp" - -#include "../../utils/trie/random-policy.hpp" -#include "../../utils/trie/lru-policy.hpp" -#include "../../utils/trie/fifo-policy.hpp" -#include "../../utils/trie/lfu-policy.hpp" -#include "../../utils/trie/multi-policy.hpp" -#include "../../utils/trie/aggregate-stats-policy.hpp" - -#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \ - static struct X##type##templ##RegistrationClass { \ - X##type##templ##RegistrationClass() \ - { \ - ns3::TypeId tid = type::GetTypeId(); \ - tid.GetParent(); \ - } \ - } x_##type##templ##RegistrationVariable - -namespace ns3 { -namespace ndn { - -using namespace ndnSIM; - -namespace cs { - -// explicit instantiation and registering -/** - * @brief ContentStore with LRU cache replacement policy - **/ -template class ContentStoreImpl; - -/** - * @brief ContentStore with random cache replacement policy - **/ -template class ContentStoreImpl; - -/** - * @brief ContentStore with FIFO cache replacement policy - **/ -template class ContentStoreImpl; - -/** - * @brief ContentStore with Least Frequently Used (LFU) cache replacement policy - **/ -template class ContentStoreImpl; - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, lru_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, random_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, fifo_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, lfu_policy_traits); - -typedef multi_policy_traits> - LruWithCountsTraits; -typedef multi_policy_traits> - RandomWithCountsTraits; -typedef multi_policy_traits> - FifoWithCountsTraits; -typedef multi_policy_traits> - LfuWithCountsTraits; - -template class ContentStoreImpl; -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, LruWithCountsTraits); - -template class ContentStoreImpl; -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, RandomWithCountsTraits); - -template class ContentStoreImpl; -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, FifoWithCountsTraits); - -template class ContentStoreImpl; -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreImpl, LfuWithCountsTraits); - -#ifdef DOXYGEN -// /** -// * \brief Content Store implementing LRU cache replacement policy -// */ -class Lru : public ContentStoreImpl { -}; - -/** - * \brief Content Store implementing FIFO cache replacement policy - */ -class Fifo : public ContentStoreImpl { -}; - -/** - * \brief Content Store implementing Random cache replacement policy - */ -class Random : public ContentStoreImpl { -}; - -/** - * \brief Content Store implementing Least Frequently Used cache replacement policy - */ -class Lfu : public ContentStoreImpl { -}; -#endif - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/content-store-impl.hpp b/model/cs/content-store-impl.hpp deleted file mode 100644 index 5765120b1..000000000 --- a/model/cs/content-store-impl.hpp +++ /dev/null @@ -1,338 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_IMPL_H_ -#define NDN_CONTENT_STORE_IMPL_H_ - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "ndn-content-store.hpp" - -#include "ns3/packet.h" -#include - -#include "ns3/log.h" -#include "ns3/uinteger.h" -#include "ns3/string.h" - -#include "../../utils/trie/trie-with-policy.hpp" - -namespace ns3 { -namespace ndn { -namespace cs { - -/** - * @ingroup ndn-cs - * @brief Cache entry implementation with additional references to the base container - */ -template -class EntryImpl : public Entry { -public: - typedef Entry base_type; - -public: - EntryImpl(Ptr cs, shared_ptr data) - : Entry(cs, data) - , item_(0) - { - } - - void - SetTrie(typename CS::super::iterator item) - { - item_ = item; - } - - typename CS::super::iterator - to_iterator() - { - return item_; - } - typename CS::super::const_iterator - to_iterator() const - { - return item_; - } - -private: - typename CS::super::iterator item_; -}; - -/** - * @ingroup ndn-cs - * @brief Base implementation of NDN content store - */ -template -class ContentStoreImpl - : public ContentStore, - protected ndnSIM:: - trie_with_policy>, - Entry>, - Policy> { -public: - typedef ndnSIM:: - trie_with_policy>, - Entry>, - Policy> super; - - typedef EntryImpl> entry; - - static TypeId - GetTypeId(); - - ContentStoreImpl(){}; - virtual ~ContentStoreImpl(){}; - - // from ContentStore - - virtual inline shared_ptr - Lookup(shared_ptr interest); - - virtual inline bool - Add(shared_ptr data); - - // virtual bool - // Remove (shared_ptr header); - - virtual inline void - Print(std::ostream& os) const; - - virtual uint32_t - GetSize() const; - - virtual Ptr - Begin(); - - virtual Ptr - End(); - - virtual Ptr Next(Ptr); - - const typename super::policy_container& - GetPolicy() const - { - return super::getPolicy(); - } - - typename super::policy_container& - GetPolicy() - { - return super::getPolicy(); - } - -public: - typedef void (*CsEntryCallback)(Ptr); - -private: - void - SetMaxSize(uint32_t maxSize); - - uint32_t - GetMaxSize() const; - -private: - static LogComponent g_log; ///< @brief Logging variable - - /// @brief trace of for entry additions (fired every time entry is successfully added to the - /// cache): first parameter is pointer to the CS entry - TracedCallback> m_didAddEntry; -}; - -////////////////////////////////////////// -////////// Implementation //////////////// -////////////////////////////////////////// - -template -LogComponent ContentStoreImpl::g_log = LogComponent(("ndn.cs." + Policy::GetName()).c_str(), __FILE__); - -template -TypeId -ContentStoreImpl::GetTypeId() -{ - static TypeId tid = - TypeId(("ns3::ndn::cs::" + Policy::GetName()).c_str()) - .SetGroupName("Ndn") - .SetParent() - .AddConstructor>() - .AddAttribute("MaxSize", - "Set maximum number of entries in ContentStore. If 0, limit is not enforced", - StringValue("100"), MakeUintegerAccessor(&ContentStoreImpl::GetMaxSize, - &ContentStoreImpl::SetMaxSize), - MakeUintegerChecker()) - - .AddTraceSource("DidAddEntry", - "Trace fired every time entry is successfully added to the cache", - MakeTraceSourceAccessor(&ContentStoreImpl::m_didAddEntry), - "ns3::ndn::cs::ContentStoreImpl::CsEntryCallback"); - - return tid; -} - -struct isNotExcluded { - inline isNotExcluded(const Exclude& exclude) - : m_exclude(exclude) - { - } - - bool - operator()(const name::Component& comp) const - { - return !m_exclude.isExcluded(comp); - } - -private: - const Exclude& m_exclude; -}; - -template -shared_ptr -ContentStoreImpl::Lookup(shared_ptr interest) -{ - NS_LOG_FUNCTION(this << interest->getName()); - - typename super::const_iterator node; - if (interest->getExclude().empty()) { - node = this->deepest_prefix_match(interest->getName()); - } - else { - node = this->deepest_prefix_match_if_next_level(interest->getName(), - isNotExcluded(interest->getExclude())); - } - - if (node != this->end()) { - this->m_cacheHitsTrace(interest, node->payload()->GetData()); - - shared_ptr copy = make_shared(*node->payload()->GetData()); - return copy; - } - else { - this->m_cacheMissesTrace(interest); - return 0; - } -} - -template -bool -ContentStoreImpl::Add(shared_ptr data) -{ - NS_LOG_FUNCTION(this << data->getName()); - - Ptr newEntry = Create(this, data); - std::pair result = super::insert(data->getName(), newEntry); - - if (result.first != super::end()) { - if (result.second) { - newEntry->SetTrie(result.first); - - m_didAddEntry(newEntry); - return true; - } - else { - // should we do anything? - // update payload? add new payload? - return false; - } - } - else - return false; // cannot insert entry -} - -template -void -ContentStoreImpl::Print(std::ostream& os) const -{ - for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); - item != this->getPolicy().end(); item++) { - os << item->payload ()->GetName () << std::endl; - } -} - -template -void -ContentStoreImpl::SetMaxSize(uint32_t maxSize) -{ - this->getPolicy().set_max_size(maxSize); -} - -template -uint32_t -ContentStoreImpl::GetMaxSize() const -{ - return this->getPolicy().get_max_size(); -} - -template -uint32_t -ContentStoreImpl::GetSize() const -{ - return this->getPolicy().size(); -} - -template -Ptr -ContentStoreImpl::Begin() -{ - typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0); - for (; item != end; item++) { - if (item->payload() == 0) - continue; - break; - } - - if (item == end) - return End(); - else - return item->payload(); -} - -template -Ptr -ContentStoreImpl::End() -{ - return 0; -} - -template -Ptr -ContentStoreImpl::Next(Ptr from) -{ - if (from == 0) - return 0; - - typename super::parent_trie::recursive_iterator item(*StaticCast(from)->to_iterator()), - end(0); - - for (item++; item != end; item++) { - if (item->payload() == 0) - continue; - break; - } - - if (item == end) - return End(); - else - return item->payload(); -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 - -#endif // NDN_CONTENT_STORE_IMPL_H_ diff --git a/model/cs/content-store-nocache.cpp b/model/cs/content-store-nocache.cpp deleted file mode 100644 index 6b10df1a6..000000000 --- a/model/cs/content-store-nocache.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "content-store-nocache.hpp" - -#include "ns3/log.h" -#include "ns3/packet.h" - -NS_LOG_COMPONENT_DEFINE("ndn.cs.Nocache"); - -namespace ns3 { -namespace ndn { -namespace cs { - -NS_OBJECT_ENSURE_REGISTERED(Nocache); - -TypeId -Nocache::GetTypeId(void) -{ - static TypeId tid = TypeId("ns3::ndn::cs::Nocache") - .SetGroupName("Ndn") - .SetParent() - .AddConstructor(); - - return tid; -} - -Nocache::Nocache() -{ -} - -Nocache::~Nocache() -{ -} - -shared_ptr -Nocache::Lookup(shared_ptr interest) -{ - this->m_cacheMissesTrace(interest); - return 0; -} - -bool -Nocache::Add(shared_ptr data) -{ - return false; -} - -void -Nocache::Print(std::ostream& os) const -{ -} - -uint32_t -Nocache::GetSize() const -{ - return 0; -} - -Ptr -Nocache::Begin() -{ - return 0; -} - -Ptr -Nocache::End() -{ - return 0; -} - -Ptr Nocache::Next(Ptr) -{ - return 0; -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/content-store-nocache.hpp b/model/cs/content-store-nocache.hpp deleted file mode 100644 index 019926bab..000000000 --- a/model/cs/content-store-nocache.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_NOCACHE_H -#define NDN_CONTENT_STORE_NOCACHE_H - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "ns3/ndnSIM/model/cs/ndn-content-store.hpp" - -namespace ns3 { -namespace ndn { -namespace cs { - -/** - * @ingroup ndn-cs - * @brief Implementation of ContentStore that completely disables caching - */ -class Nocache : public ContentStore { -public: - /** - * \brief Interface ID - * - * \return interface ID - */ - static TypeId - GetTypeId(); - - /** - * @brief Default constructor - */ - Nocache(); - - /** - * @brief Virtual destructor - */ - virtual ~Nocache(); - - virtual shared_ptr - Lookup(shared_ptr interest); - - virtual bool - Add(shared_ptr data); - - virtual void - Print(std::ostream& os) const; - - virtual uint32_t - GetSize() const; - - virtual Ptr - Begin(); - - virtual Ptr - End(); - - virtual Ptr Next(Ptr); -}; - -} // namespace cs -} // namespace ndn -} // namespace ns3 - -#endif // NDN_CONTENT_STORE_NOCACHE_H diff --git a/model/cs/content-store-with-freshness.cpp b/model/cs/content-store-with-freshness.cpp deleted file mode 100644 index c60236b26..000000000 --- a/model/cs/content-store-with-freshness.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "content-store-with-freshness.hpp" - -#include "../../utils/trie/random-policy.hpp" -#include "../../utils/trie/lru-policy.hpp" -#include "../../utils/trie/fifo-policy.hpp" -#include "../../utils/trie/lfu-policy.hpp" - -#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \ - static struct X##type##templ##RegistrationClass { \ - X##type##templ##RegistrationClass() \ - { \ - ns3::TypeId tid = type::GetTypeId(); \ - tid.GetParent(); \ - } \ - } x_##type##templ##RegistrationVariable - -namespace ns3 { -namespace ndn { - -using namespace ndnSIM; - -namespace cs { - -// explicit instantiation and registering -/** - * @brief ContentStore with freshness and LRU cache replacement policy - **/ -template class ContentStoreWithFreshness; - -/** - * @brief ContentStore with freshness and random cache replacement policy - **/ -template class ContentStoreWithFreshness; - -/** - * @brief ContentStore with freshness and FIFO cache replacement policy - **/ -template class ContentStoreWithFreshness; - -/** - * @brief ContentStore with freshness and Least Frequently Used (LFU) cache replacement policy - **/ -template class ContentStoreWithFreshness; - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, lru_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, random_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, fifo_policy_traits); - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithFreshness, lfu_policy_traits); - -#ifdef DOXYGEN -// /** -// * \brief Content Store with freshness implementing LRU cache replacement policy -// */ -class Freshness::Lru : public ContentStoreWithFreshness { -}; - -/** - * \brief Content Store with freshness implementing FIFO cache replacement policy - */ -class Freshness::Fifo : public ContentStoreWithFreshness { -}; - -/** - * \brief Content Store with freshness implementing Random cache replacement policy - */ -class Freshness::Random : public ContentStoreWithFreshness { -}; - -/** - * \brief Content Store with freshness implementing Least Frequently Used cache replacement policy - */ -class Freshness::Lfu : public ContentStoreWithFreshness { -}; - -#endif - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/content-store-with-freshness.hpp b/model/cs/content-store-with-freshness.hpp deleted file mode 100644 index 4cfa70050..000000000 --- a/model/cs/content-store-with-freshness.hpp +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_WITH_FRESHNESS_H_ -#define NDN_CONTENT_STORE_WITH_FRESHNESS_H_ - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "content-store-impl.hpp" - -#include "../../utils/trie/multi-policy.hpp" -#include "custom-policies/freshness-policy.hpp" - -namespace ns3 { -namespace ndn { -namespace cs { - -/** - * @ingroup ndn-cs - * @brief Special content store realization that honors Freshness parameter in Data packets - */ -template -class ContentStoreWithFreshness - : public ContentStoreImpl>> { -public: - typedef ContentStoreImpl>> - super; - - typedef typename super::policy_container::template index<1>::type freshness_policy_container; - - static TypeId - GetTypeId(); - - virtual inline void - Print(std::ostream& os) const; - - virtual inline bool - Add(shared_ptr data); - -private: - inline void - CleanExpired(); - - inline void - RescheduleCleaning(); - -private: - static LogComponent g_log; ///< @brief Logging variable - - EventId m_cleanEvent; - Time m_scheduledCleaningTime; -}; - -////////////////////////////////////////// -////////// Implementation //////////////// -////////////////////////////////////////// - -template -LogComponent ContentStoreWithFreshness::g_log = LogComponent(("ndn.cs.Freshness." - + Policy::GetName()).c_str(), __FILE__); - -template -TypeId -ContentStoreWithFreshness::GetTypeId() -{ - static TypeId tid = TypeId(("ns3::ndn::cs::Freshness::" + Policy::GetName()).c_str()) - .SetGroupName("Ndn") - .SetParent() - .template AddConstructor>() - - // trace stuff here - ; - - return tid; -} - -template -inline bool -ContentStoreWithFreshness::Add(shared_ptr data) -{ - bool ok = super::Add(data); - if (!ok) - return false; - - NS_LOG_DEBUG(data->getName() << " added to cache"); - RescheduleCleaning(); - return true; -} - -template -inline void -ContentStoreWithFreshness::RescheduleCleaning() -{ - const freshness_policy_container& freshness = - this->getPolicy().template get(); - - if (freshness.size() > 0) { - Time nextStateTime = - freshness_policy_container::policy_base::get_freshness(&(*freshness.begin())); - - if (m_scheduledCleaningTime.IsZero() || // if not yet scheduled - m_scheduledCleaningTime > nextStateTime) // if new item expire sooner than already scheduled - { - if (m_cleanEvent.IsRunning()) { - Simulator::Remove(m_cleanEvent); // just canceling would not clean up list of events - } - - // NS_LOG_DEBUG ("Next event in: " << (nextStateTime - Now ()).ToDouble (Time::S) << "s"); - m_cleanEvent = Simulator::Schedule(nextStateTime - Now(), - &ContentStoreWithFreshness::CleanExpired, this); - m_scheduledCleaningTime = nextStateTime; - } - } - else { - if (m_cleanEvent.IsRunning()) { - Simulator::Remove(m_cleanEvent); // just canceling would not clean up list of events - } - } -} - -template -inline void -ContentStoreWithFreshness::CleanExpired() -{ - freshness_policy_container& freshness = - this->getPolicy().template get(); - - // NS_LOG_LOGIC (">> Cleaning: Total number of items:" << this->getPolicy ().size () << ", items - // with freshness: " << freshness.size ()); - Time now = Simulator::Now(); - - while (!freshness.empty()) { - typename freshness_policy_container::iterator entry = freshness.begin(); - - if (freshness_policy_container::policy_base::get_freshness(&(*entry)) - <= now) // is the record stale? - { - super::erase(&(*entry)); - } - else - break; // nothing else to do. All later records will not be stale - } - // NS_LOG_LOGIC ("<< Cleaning: Total number of items:" << this->getPolicy ().size () << ", items - // with freshness: " << freshness.size ()); - - m_scheduledCleaningTime = Time(); - RescheduleCleaning(); -} - -template -void -ContentStoreWithFreshness::Print(std::ostream& os) const -{ - // const freshness_policy_container &freshness = this->getPolicy ().template - // get (); - - for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); - item != this->getPolicy().end(); item++) { - Time ttl = freshness_policy_container::policy_base::get_freshness(&(*item)) - Simulator::Now(); - os << item->payload()->GetName() << "(left: " << ttl.ToDouble(Time::S) << "s)" << std::endl; - } -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 - -#endif // NDN_CONTENT_STORE_WITH_FRESHNESS_H_ diff --git a/model/cs/content-store-with-probability.cpp b/model/cs/content-store-with-probability.cpp deleted file mode 100644 index 5f28c0a98..000000000 --- a/model/cs/content-store-with-probability.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "content-store-with-probability.hpp" - -#include "../../utils/trie/random-policy.hpp" -#include "../../utils/trie/lru-policy.hpp" -#include "../../utils/trie/fifo-policy.hpp" -#include "../../utils/trie/lfu-policy.hpp" - -#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \ - static struct X##type##templ##RegistrationClass { \ - X##type##templ##RegistrationClass() \ - { \ - ns3::TypeId tid = type::GetTypeId(); \ - tid.GetParent(); \ - } \ - } x_##type##templ##RegistrationVariable - -namespace ns3 { -namespace ndn { - -using namespace ndnSIM; - -namespace cs { - -// explicit instantiation and registering -/** - * @brief ContentStore with freshness and LRU cache replacement policy - **/ -template class ContentStoreWithProbability; - -/** - * @brief ContentStore with freshness and random cache replacement policy - **/ -template class ContentStoreWithProbability; - -/** - * @brief ContentStore with freshness and FIFO cache replacement policy - **/ -template class ContentStoreWithProbability; - -/** - * @brief ContentStore with freshness and Least Frequently Used (LFU) cache replacement policy - **/ -template class ContentStoreWithProbability; - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, lru_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, random_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, fifo_policy_traits); - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithProbability, lfu_policy_traits); - -#ifdef DOXYGEN -// /** -// * \brief Content Store with freshness implementing LRU cache replacement policy -// */ -class Probability::Lru : public ContentStoreWithProbability { -}; - -/** - * \brief Content Store with freshness implementing FIFO cache replacement policy - */ -class Probability::Fifo : public ContentStoreWithProbability { -}; - -/** - * \brief Content Store with freshness implementing Random cache replacement policy - */ -class Probability::Random : public ContentStoreWithProbability { -}; - -/** - * \brief Content Store with freshness implementing Least Frequently Used cache replacement policy - */ -class Probability::Lfu : public ContentStoreWithProbability { -}; - -#endif - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/content-store-with-probability.hpp b/model/cs/content-store-with-probability.hpp deleted file mode 100644 index 5ba9b58d7..000000000 --- a/model/cs/content-store-with-probability.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_WITH_PROBABILITY_H_ -#define NDN_CONTENT_STORE_WITH_PROBABILITY_H_ - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "content-store-impl.hpp" - -#include "../../utils/trie/multi-policy.hpp" -#include "custom-policies/probability-policy.hpp" -#include "ns3/double.h" -#include "ns3/type-id.h" - -namespace ns3 { -namespace ndn { -namespace cs { - -/** - * @ingroup ndn-cs - * @brief Special content store realization that probabilistically accepts data packet - * into CS (placement policy) - */ -template -class ContentStoreWithProbability - : public ContentStoreImpl>> { -public: - typedef ContentStoreImpl>> super; - - typedef typename super::policy_container::template index<0>::type probability_policy_container; - - ContentStoreWithProbability(){}; - - static TypeId - GetTypeId(); - -private: - void - SetCacheProbability(double probability) - { - this->getPolicy().template get().set_probability(probability); - } - - double - GetCacheProbability() const - { - return this->getPolicy().template get().get_probability(); - } -}; - -////////////////////////////////////////// -////////// Implementation //////////////// -////////////////////////////////////////// - -template -TypeId -ContentStoreWithProbability::GetTypeId() -{ - static TypeId tid = - TypeId(("ns3::ndn::cs::Probability::" + Policy::GetName()).c_str()) - .SetGroupName("Ndn") - .SetParent() - .template AddConstructor>() - - .AddAttribute("CacheProbability", - "Set probability of caching in ContentStore. " - "If 1, every content is cached. If 0, no content is cached.", - DoubleValue(1.0), //(+) - MakeDoubleAccessor(&ContentStoreWithProbability::GetCacheProbability, - &ContentStoreWithProbability::SetCacheProbability), - MakeDoubleChecker()); - - return tid; -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 - -#endif // NDN_CONTENT_STORE_WITH_PROBABILITY_H_ diff --git a/model/cs/content-store-with-stats.cpp b/model/cs/content-store-with-stats.cpp deleted file mode 100644 index bcdf098c2..000000000 --- a/model/cs/content-store-with-stats.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "content-store-with-stats.hpp" - -#include "../../utils/trie/random-policy.hpp" -#include "../../utils/trie/lru-policy.hpp" -#include "../../utils/trie/fifo-policy.hpp" -#include "../../utils/trie/lfu-policy.hpp" - -#define NS_OBJECT_ENSURE_REGISTERED_TEMPL(type, templ) \ - static struct X##type##templ##RegistrationClass { \ - X##type##templ##RegistrationClass() \ - { \ - ns3::TypeId tid = type::GetTypeId(); \ - tid.GetParent(); \ - } \ - } x_##type##templ##RegistrationVariable - -namespace ns3 { -namespace ndn { - -using namespace ndnSIM; - -namespace cs { - -// explicit instantiation and registering -/** - * @brief ContentStore with stats and LRU cache replacement policy - **/ -template class ContentStoreWithStats; - -/** - * @brief ContentStore with stats and random cache replacement policy - **/ -template class ContentStoreWithStats; - -/** - * @brief ContentStore with stats and FIFO cache replacement policy - **/ -template class ContentStoreWithStats; - -/** - * @brief ContentStore with stats and Least Frequently Used (LFU) cache replacement policy - **/ -template class ContentStoreWithStats; - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, lru_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, random_policy_traits); -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, fifo_policy_traits); - -NS_OBJECT_ENSURE_REGISTERED_TEMPL(ContentStoreWithStats, lfu_policy_traits); - -#ifdef DOXYGEN -// /** -// * \brief Content Store with stats implementing LRU cache replacement policy -// */ -class Stats::Lru : public ContentStoreWithStats { -}; - -/** - * \brief Content Store with stats implementing FIFO cache replacement policy - */ -class Stats::Fifo : public ContentStoreWithStats { -}; - -/** - * \brief Content Store with stats implementing Random cache replacement policy - */ -class Stats::Random : public ContentStoreWithStats { -}; - -/** - * \brief Content Store with stats implementing Least Frequently Used cache replacement policy - */ -class Stats::Lfu : public ContentStoreWithStats { -}; - -#endif - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/content-store-with-stats.hpp b/model/cs/content-store-with-stats.hpp deleted file mode 100644 index 3b84ac2fd..000000000 --- a/model/cs/content-store-with-stats.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_WITH_STATS_H_ -#define NDN_CONTENT_STORE_WITH_STATS_H_ - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "content-store-impl.hpp" - -#include "../../utils/trie/multi-policy.hpp" -#include "custom-policies/lifetime-stats-policy.hpp" - -namespace ns3 { -namespace ndn { -namespace cs { - -/** - * @ingroup ndn-cs - * @brief Special content store realization that provides ability to track stats of CS operations - */ -template -class ContentStoreWithStats - : public ContentStoreImpl>> { -public: - typedef ContentStoreImpl>> - super; - - typedef typename super::policy_container::template index<1>::type lifetime_stats_container; - - ContentStoreWithStats() - { - // connect traceback to the policy - super::getPolicy().template get<1>().set_traced_callback(&m_willRemoveEntry); - } - - static TypeId - GetTypeId(); - - virtual inline void - Print(std::ostream& os) const; - -public: - typedef void (*RemoveCsEntryCallback)(Ptr, Time); - -private: - static LogComponent g_log; ///< @brief Logging variable - - /// @brief trace of for entry removal: first parameter is pointer to the CS entry, second is how - /// long entry was in the cache - TracedCallback, Time> m_willRemoveEntry; -}; - -////////////////////////////////////////// -////////// Implementation //////////////// -////////////////////////////////////////// - -template -LogComponent ContentStoreWithStats::g_log = LogComponent(("ndn.cs.Stats." - + Policy::GetName()).c_str(), __FILE__); - -template -TypeId -ContentStoreWithStats::GetTypeId() -{ - static TypeId tid = - TypeId(("ns3::ndn::cs::Stats::" + Policy::GetName()).c_str()) - .SetGroupName("Ndn") - .SetParent() - .template AddConstructor>() - - .AddTraceSource("WillRemoveEntry", - "Trace called just before content store entry will be removed", - MakeTraceSourceAccessor(&ContentStoreWithStats::m_willRemoveEntry), - "ns3::ndn::cs::ContentStoreWithStats::RemoveCsEntryCallback") - - // trace stuff here - ; - - return tid; -} - -template -void -ContentStoreWithStats::Print(std::ostream& os) const -{ - // const freshness_policy_container &freshness = this->getPolicy ().template - // get (); - - for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); - item != this->getPolicy().end(); item++) { - Time alive = lifetime_stats_container::policy_base::get_time(&(*item)) - Simulator::Now(); - os << item->payload()->GetName() << "(alive: " << alive.ToDouble(Time::S) << "s)" << std::endl; - } -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 - -#endif // NDN_CONTENT_STORE_IMPL_H_ diff --git a/model/cs/custom-policies/freshness-policy.hpp b/model/cs/custom-policies/freshness-policy.hpp deleted file mode 100644 index 415ab0b96..000000000 --- a/model/cs/custom-policies/freshness-policy.hpp +++ /dev/null @@ -1,173 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef FRESHNESS_POLICY_H_ -#define FRESHNESS_POLICY_H_ - -/// @cond include_hidden - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include -#include - -#include -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for freshness policy - */ -struct freshness_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Freshness"; - } - - struct policy_hook_type : public boost::intrusive::set_member_hook<> { - Time timeWhenShouldExpire; - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - static Time& - get_freshness(typename Container::iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire; - } - - static const Time& - get_freshness(typename Container::const_iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->timeWhenShouldExpire; - } - - template - struct MemberHookLess { - bool - operator()(const Key& a, const Key& b) const - { - return get_freshness(&a) < get_freshness(&b); - } - }; - - typedef boost::intrusive::multiset>, - Hook> policy_container; - - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_freshness methods from outside - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing - } - - inline bool - insert(typename parent_trie::iterator item) - { - time::milliseconds freshness = item->payload()->GetData()->getFreshnessPeriod(); - if (freshness > time::milliseconds::zero()) { - get_freshness(item) = Simulator::Now() + MilliSeconds(freshness.count()); - - // push item only if freshness is non zero. otherwise, this payload is not - // controlled by the policy. - // Note that .size() on this policy would return only the number of items with - // non-infinite freshness policy - policy_container::insert(*item); - } - - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline void - erase(typename parent_trie::iterator item) - { - time::milliseconds freshness = item->payload()->GetData()->getFreshnessPeriod(); - if (freshness > time::milliseconds::zero()) { - // erase only if freshness is positive (otherwise an item is not in the policy) - policy_container::erase(policy_container::s_iterator_to(*item)); - } - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // LIFETIME_STATS_POLICY_H diff --git a/model/cs/custom-policies/lifetime-stats-policy.hpp b/model/cs/custom-policies/lifetime-stats-policy.hpp deleted file mode 100644 index 6e8161821..000000000 --- a/model/cs/custom-policies/lifetime-stats-policy.hpp +++ /dev/null @@ -1,167 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef LIFETIME_STATS_POLICY_H_ -#define LIFETIME_STATS_POLICY_H_ - -/// @cond include_hidden - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include -#include - -#include -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for lifetime stats policy - */ -struct lifetime_stats_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "LifetimeStats"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - Time timeWhenAdded; - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - static Time& - get_time(typename Container::iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded; - } - - static const Time& - get_time(typename Container::const_iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->timeWhenAdded; - } - - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_time methods from outside - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - , m_willRemoveEntry(0) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline bool - insert(typename parent_trie::iterator item) - { - get_time(item) = Simulator::Now(); - - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline void - erase(typename parent_trie::iterator item) - { - Time lifetime = Simulator::Now() - get_time(item); - - if (m_willRemoveEntry != 0) { - (*m_willRemoveEntry)(item->payload(), lifetime); - } - - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - void - set_traced_callback( - TracedCallback* callback) - { - m_willRemoveEntry = callback; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - - TracedCallback* - m_willRemoveEntry; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // LIFETIME_STATS_POLICY_H diff --git a/model/cs/custom-policies/probability-policy.hpp b/model/cs/custom-policies/probability-policy.hpp deleted file mode 100644 index 8bfb1c67b..000000000 --- a/model/cs/custom-policies/probability-policy.hpp +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef PROBABILITY_POLICY_H_ -#define PROBABILITY_POLICY_H_ - -/// @cond include_hidden - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include -#include - -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for freshness policy - */ -struct probability_policy_traits { - static std::string - GetName() - { - return "ProbabilityImpl"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_freshness methods from outside - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - , probability_(1.0) - , ns3_rand_(CreateObject()) - { - } - - inline void - update(typename parent_trie::iterator item) - { - } - - inline bool - insert(typename parent_trie::iterator item) - { - if (ns3_rand_->GetValue() < probability_) { - policy_container::push_back(*item); - - // allow caching - return true; - } - else { - // don't allow caching - return false; - } - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - inline void - set_probability(double probability) - { - probability_ = probability; - } - - inline double - get_probability() const - { - return probability_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - double probability_; - Ptr ns3_rand_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // PROBABILITY_POLICY_H diff --git a/model/cs/ndn-content-store.cpp b/model/cs/ndn-content-store.cpp deleted file mode 100644 index 416bde344..000000000 --- a/model/cs/ndn-content-store.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#include "ndn-content-store.hpp" - -#include "ns3/log.h" -#include "ns3/packet.h" - -NS_LOG_COMPONENT_DEFINE("ndn.cs.ContentStore"); - -namespace ns3 { -namespace ndn { - -NS_OBJECT_ENSURE_REGISTERED(ContentStore); - -TypeId -ContentStore::GetTypeId(void) -{ - static TypeId tid = - TypeId("ns3::ndn::ContentStore") - .SetGroupName("Ndn") - .SetParent() - - .AddTraceSource("CacheHits", "Trace called every time there is a cache hit", - MakeTraceSourceAccessor(&ContentStore::m_cacheHitsTrace), - "ns3::ndn::ContentStore::CacheHitsCallback") - - .AddTraceSource("CacheMisses", "Trace called every time there is a cache miss", - MakeTraceSourceAccessor(&ContentStore::m_cacheMissesTrace), - "ns3::ndn::ContentStrore::CacheMissesCallback"); - - return tid; -} - -ContentStore::~ContentStore() -{ -} - -namespace cs { - -////////////////////////////////////////////////////////////////////// - -Entry::Entry(Ptr cs, shared_ptr data) - : m_cs(cs) - , m_data(data) -{ -} - -const Name& -Entry::GetName() const -{ - return m_data->getName(); -} - -shared_ptr -Entry::GetData() const -{ - return m_data; -} - -Ptr -Entry::GetContentStore() -{ - return m_cs; -} - -} // namespace cs -} // namespace ndn -} // namespace ns3 diff --git a/model/cs/ndn-content-store.hpp b/model/cs/ndn-content-store.hpp deleted file mode 100644 index 54c177bde..000000000 --- a/model/cs/ndn-content-store.hpp +++ /dev/null @@ -1,218 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef NDN_CONTENT_STORE_H -#define NDN_CONTENT_STORE_H - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "ns3/object.h" -#include "ns3/ptr.h" -#include "ns3/traced-callback.h" - -#include - -namespace ns3 { - -class Packet; - -namespace ndn { - -class ContentStore; - -/** - * @ingroup ndn - * @defgroup ndn-cs Content Store - */ - -/** - * @ingroup ndn-cs - * @brief Namespace for ContentStore operations - */ -namespace cs { - -/** - * @ingroup ndn-cs - * @brief NDN content store entry - */ -class Entry : public SimpleRefCount { -public: - /** - * \brief Construct content store entry - * - * \param header Parsed Data header - * \param packet Original Ndn packet - * - * The constructor will make a copy of the supplied packet and calls - * RemoveHeader and RemoveTail on the copy. - */ - Entry(Ptr cs, shared_ptr data); - - /** - * \brief Get prefix of the stored entry - * \returns prefix of the stored entry - */ - const Name& - GetName() const; - - /** - * \brief Get Data of the stored entry - * \returns Data of the stored entry - */ - shared_ptr - GetData() const; - - /** - * @brief Get pointer to access store, to which this entry is added - */ - Ptr - GetContentStore(); - -private: - Ptr m_cs; ///< \brief content store to which entry is added - shared_ptr m_data; ///< \brief non-modifiable Data -}; - -} // namespace cs - -/** - * @ingroup ndn-cs - * \brief Base class for NDN content store - * - * Particular implementations should implement Lookup, Add, and Print methods - */ -class ContentStore : public Object { -public: - /** - * \brief Interface ID - * - * \return interface ID - */ - static TypeId - GetTypeId(); - - /** - * @brief Virtual destructor - */ - virtual ~ContentStore(); - - /** - * \brief Find corresponding CS entry for the given interest - * - * \param interest Interest for which matching content store entry will be searched - * - * If an entry is found, it is promoted to the top of most recent - * used entries index, \see m_contentStore - */ - virtual shared_ptr - Lookup(shared_ptr interest) = 0; - - /** - * \brief Add a new content to the content store. - * \returns true if an existing entry was updated, false otherwise - */ - virtual bool - Add(shared_ptr data) = 0; - - // /* - // * \brief Add a new content to the content store. - // * - // * \param header Interest header for which an entry should be removed - // * @returns true if an existing entry was removed, false otherwise - // */ - // virtual bool - // Remove (shared_ptr header) = 0; - - /** - * \brief Print out content store entries - */ - virtual void - Print(std::ostream& os) const = 0; - - /** - * @brief Get number of entries in content store - */ - virtual uint32_t - GetSize() const = 0; - - /** - * @brief Return first element of content store (no order guaranteed) - */ - virtual Ptr - Begin() = 0; - - /** - * @brief Return item next after last (no order guaranteed) - */ - virtual Ptr - End() = 0; - - /** - * @brief Advance the iterator - */ - virtual Ptr Next(Ptr) = 0; - - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////// - - /** - * @brief Static call to cheat python bindings - */ - static inline Ptr - GetContentStore(Ptr node); - -public: - typedef void (*CacheHitsCallback)(shared_ptr, shared_ptr); - typedef void (*CacheMissesCallback)(shared_ptr); - -protected: - TracedCallback, - shared_ptr> m_cacheHitsTrace; ///< @brief trace of cache hits - - TracedCallback> m_cacheMissesTrace; ///< @brief trace of cache misses -}; - -inline std::ostream& -operator<<(std::ostream& os, const ContentStore& cs) -{ - cs.Print(os); - return os; -} - -inline Ptr -ContentStore::GetContentStore(Ptr node) -{ - return node->GetObject(); -} - -} // namespace ndn -} // namespace ns3 - -#include -namespace boost { -inline std::size_t -hash_value(const ::ndn::name::Component component) -{ - return boost::hash_range(component.wireEncode().wire(), - component.wireEncode().wire() + component.wireEncode().size()); -} -} - -#endif // NDN_CONTENT_STORE_H diff --git a/model/ndn-l3-protocol.cpp b/model/ndn-l3-protocol.cpp index c5db46c6d..47ce00cac 100644 --- a/model/ndn-l3-protocol.cpp +++ b/model/ndn-l3-protocol.cpp @@ -32,7 +32,6 @@ #include "ndn-net-device-transport.hpp" #include "../helper/ndn-stack-helper.hpp" -#include "cs/ndn-content-store.hpp" #include @@ -192,7 +191,6 @@ class L3Protocol::Impl { nfd::ConfigSection m_config; - Ptr m_csFromNdnSim; PolicyCreationCallback m_policy; }; @@ -291,11 +289,7 @@ L3Protocol::initializeManagement() ConfigFile config(&ConfigFile::ignoreUnknownSection); - // if we use NFD's CS, we have to specify a replacement policy - m_impl->m_csFromNdnSim = GetObject(); - if (m_impl->m_csFromNdnSim == nullptr) { - forwarder->getCs().setPolicy(m_impl->m_policy()); - } + forwarder->getCs().setPolicy(m_impl->m_policy()); TablesConfigSection tablesConfig(*forwarder); tablesConfig.setConfigFile(config); @@ -371,12 +365,6 @@ L3Protocol::NotifyNewAggregate() m_node = GetObject(); if (m_node != nullptr) { initialize(); - - NS_ASSERT(m_impl->m_forwarder != nullptr); - m_impl->m_csFromNdnSim = GetObject(); - if (m_impl->m_csFromNdnSim != nullptr) { - m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim); - } } } diff --git a/utils/tracers/ndn-cs-tracer.cpp b/utils/tracers/ndn-cs-tracer.cpp index ded69fe6a..e58a00553 100644 --- a/utils/tracers/ndn-cs-tracer.cpp +++ b/utils/tracers/ndn-cs-tracer.cpp @@ -25,7 +25,6 @@ #include "ns3/callback.h" #include "apps/ndn-app.hpp" -#include "model/cs/ndn-content-store.hpp" #include "ns3/simulator.h" #include "ns3/node-list.h" #include "ns3/log.h" @@ -200,9 +199,10 @@ CsTracer::~CsTracer(){}; void CsTracer::Connect() { - Ptr cs = m_nodePtr->GetObject(); - cs->TraceConnectWithoutContext("CacheHits", MakeCallback(&CsTracer::CacheHits, this)); - cs->TraceConnectWithoutContext("CacheMisses", MakeCallback(&CsTracer::CacheMisses, this)); + // // @TODO Do the same with NFD content store... + // Ptr cs = m_nodePtr->GetObject(); + // cs->TraceConnectWithoutContext("CacheHits", MakeCallback(&CsTracer::CacheHits, this)); + // cs->TraceConnectWithoutContext("CacheMisses", MakeCallback(&CsTracer::CacheMisses, this)); Reset(); } diff --git a/utils/trie/aggregate-stats-policy.hpp b/utils/trie/aggregate-stats-policy.hpp deleted file mode 100644 index 4d2673b63..000000000 --- a/utils/trie/aggregate-stats-policy.hpp +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef AGGREGATE_STATS_POLICY_H_ -#define AGGREGATE_STATS_POLICY_H_ - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/// @cond include_hidden - -/** - * @brief Traits for policy that just keeps track of number of elements - * It's doing a rather expensive job, but just in case it needs to be extended later - */ -struct aggregate_stats_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "AggregateStats"; - } - struct policy_hook_type { - }; - - template - struct container_hook { - struct type { - }; - }; - - template - struct policy { - // typedef typename boost::intrusive::list< Container, Hook > policy_container; - - // could be just typedef - class type { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , m_updates(0) - , m_inserts(0) - , m_lookups(0) - , m_erases(0) - { - } - - inline void - update(typename parent_trie::iterator item) - { - m_updates++; - // do nothing - } - - inline bool - insert(typename parent_trie::iterator item) - { - m_inserts++; - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - m_lookups++; - } - - inline void - erase(typename parent_trie::iterator item) - { - m_erases++; - } - - inline void set_max_size(uint32_t) - { - } - - inline uint32_t - get_max_size() const - { - return 0; - } - - inline void - clear() - { - // is called only at the end of simulation - } - - inline void - ResetStats() - { - m_updates = 0; - m_inserts = 0; - m_lookups = 0; - m_erases = 0; - } - - inline uint64_t - GetUpdates() const - { - return m_updates; - } - - inline uint64_t - GetInserts() const - { - return m_inserts; - } - - inline uint64_t - GetLookups() const - { - return m_lookups; - } - - inline uint64_t - GetErases() const - { - return m_erases; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - - uint64_t m_updates; - uint64_t m_inserts; - uint64_t m_lookups; - uint64_t m_erases; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // AGGREGATE_STATS_POLICY_H_ diff --git a/utils/trie/counting-policy.hpp b/utils/trie/counting-policy.hpp deleted file mode 100644 index 71331b718..000000000 --- a/utils/trie/counting-policy.hpp +++ /dev/null @@ -1,115 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef COUNTING_POLICY_H_ -#define COUNTING_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for policy that just keeps track of number of elements - * It's doing a rather expensive job, but just in case it needs to be extended later - */ -struct counting_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Counting"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - }; - - template - struct container_hook { - // could be class/struct implementation - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing - } - - inline bool - insert(typename parent_trie::iterator item) - { - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // COUNTING_POLICY_H_ diff --git a/utils/trie/detail/functor-hook.hpp b/utils/trie/detail/functor-hook.hpp deleted file mode 100644 index 17542badc..000000000 --- a/utils/trie/detail/functor-hook.hpp +++ /dev/null @@ -1,80 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef FUNCTOR_HOOK_H_ -#define FUNCTOR_HOOK_H_ - -/// @cond include_hidden - -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { -namespace detail { - -template -struct FunctorHook { - typedef typename BaseHook::template index::type hook_type; - typedef hook_type* hook_ptr; - typedef const hook_type* const_hook_ptr; - - typedef ValueType value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - - // Required static functions - static hook_ptr - to_hook_ptr(value_type& value) - { - return &value.policy_hook_.template get(); - } - - static const_hook_ptr - to_hook_ptr(const value_type& value) - { - return &value.policy_hook_.template get(); - } - - static pointer - to_value_ptr(hook_ptr n) - { - return boost::intrusive::get_parent_from_member( - static_cast( - boost::intrusive::get_parent_from_member>(n, &wrap::value_)), - &value_type::policy_hook_); - } - static const_pointer - to_value_ptr(const_hook_ptr n) - { - return boost::intrusive::get_parent_from_member( - static_cast( - boost::intrusive::get_parent_from_member>(n, &wrap::value_)), - &value_type::policy_hook_); - } -}; - -} // detail -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // FUNCTOR_HOOK_H_ diff --git a/utils/trie/detail/multi-policy-container.hpp b/utils/trie/detail/multi-policy-container.hpp deleted file mode 100644 index 5c3450b66..000000000 --- a/utils/trie/detail/multi-policy-container.hpp +++ /dev/null @@ -1,214 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef MULTI_POLICY_CONTAINER_H_ -#define MULTI_POLICY_CONTAINER_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { -namespace detail { - -template -struct policy_wrap { - policy_wrap(Base& base) - : value_(base) - { - } - Value value_; -}; - -template*/> -struct inherit_with_base : Super, Value { - inherit_with_base(Base& base) - : Super(base) - , Value(base) - { - } - - void - update(typename Base::iterator item) - { - Value::value_.update(item); - Super::update(item); - } - - bool - insert(typename Base::iterator item) - { - bool ok = Value::value_.insert(item); - if (!ok) - return false; - - ok = Super::insert(item); - if (!ok) { - Value::value_.erase(item); - return false; - } - return true; - } - - void - lookup(typename Base::iterator item) - { - Value::value_.lookup(item); - Super::lookup(item); - } - - void - erase(typename Base::iterator item) - { - Value::value_.erase(item); - Super::erase(item); - } - - void - clear() - { - Value::value_.clear(); - Super::clear(); - } -}; - -template -struct empty_policy_wrap { - empty_policy_wrap(Base& base) - { - } - - void - update(typename Base::iterator item) - { - } - bool - insert(typename Base::iterator item) - { - return true; - } - void - lookup(typename Base::iterator item) - { - } - void - erase(typename Base::iterator item) - { - } - void - clear() - { - } -}; - -template -struct multi_policy_container - : public boost::mpl:: - fold, - inherit_with_base /*element in vector*/>>::type { - typedef typename boost::mpl:: - fold, - inherit_with_base /*element in vector*/>>::type super; - - typedef typename boost::mpl::at_c::type::iterator iterator; - typedef typename boost::mpl::at_c::type::const_iterator const_iterator; - - iterator - begin() - { - return this->get<0>().begin(); - } - const_iterator - begin() const - { - return this->get<0>().begin(); - } - - iterator - end() - { - return this->get<0>().end(); - } - const_iterator - end() const - { - return this->get<0>().end(); - } - - size_t - size() const - { - return this->get<0>().size(); - } - - multi_policy_container(Base& base) - : super(base) - { - } - - template - struct index { - typedef typename boost::mpl::at_c::type type; - }; - - template - T& - get() - { - return static_cast&>(*this).value_; - } - - template - const T& - get() const - { - return static_cast&>(*this).value_; - } - - template - typename boost::mpl::at_c::type& - get() - { - typedef typename boost::mpl::at_c::type T; - return static_cast&>(*this).value_; - } - - template - const typename boost::mpl::at_c::type& - get() const - { - typedef typename boost::mpl::at_c::type T; - return static_cast&>(*this).value_; - } -}; - -} // detail -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // MULTI_POLICY_CONTAINER_H_ diff --git a/utils/trie/detail/multi-type-container.hpp b/utils/trie/detail/multi-type-container.hpp deleted file mode 100644 index 5f65aa3a2..000000000 --- a/utils/trie/detail/multi-type-container.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef MULTI_TYPE_CONTAINER_H_ -#define MULTI_TYPE_CONTAINER_H_ - -/// @cond include_hidden - -#include -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { -namespace detail { - -template -struct wrap { - T value_; -}; - -template -struct multi_type_container - : public boost::mpl::inherit_linearly, - boost::mpl::_1>>::type { - template - struct index { - typedef typename boost::mpl::at_c::type type; - }; - - template - T& - get() - { - return static_cast&>(*this).value_; - } - - template - const T& - get() const - { - return static_cast&>(*this).value_; - } - - template - typename boost::mpl::at_c::type& - get() - { - typedef typename boost::mpl::at_c::type T; - return static_cast&>(*this).value_; - } - - template - const typename boost::mpl::at_c::type& - get() const - { - typedef typename boost::mpl::at_c::type T; - return static_cast&>(*this).value_; - } -}; - -} // detail -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond include_hidden - -#endif // MULTI_TYPE_CONTAINER_H_ diff --git a/utils/trie/empty-policy.hpp b/utils/trie/empty-policy.hpp deleted file mode 100644 index 237a64740..000000000 --- a/utils/trie/empty-policy.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef EMPTY_POLICY_H_ -#define EMPTY_POLICY_H_ - -/// @cond include_hidden - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for empty (bogus) replacement policy - */ -struct empty_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return ""; - } - - typedef void* policy_hook_type; - - template - struct container_hook { - typedef void* type; - }; - - template - struct policy { - struct type { - inline type(Base& base) - { - } - - inline void update(typename Container::iterator) - { - } - inline bool insert(typename Container::iterator) - { - return true; - } - inline void - lookup(typename Container::iterator item) - { - } - inline void - erase(typename Container::iterator item) - { - } - inline void - clear() - { - } - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // EMPTY_POLICY_H_ diff --git a/utils/trie/fifo-policy.hpp b/utils/trie/fifo-policy.hpp deleted file mode 100644 index 44f335e42..000000000 --- a/utils/trie/fifo-policy.hpp +++ /dev/null @@ -1,132 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef FIFO_POLICY_H_ -#define FIFO_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for First In First Out replacement policy - */ -struct fifo_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Fifo"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - }; - - template - struct container_hook { - // could be class/struct implementation - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing - } - - inline bool - insert(typename parent_trie::iterator item) - { - if (max_size_ != 0 && policy_container::size() >= max_size_) { - base_.erase(&(*policy_container::begin())); - } - - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif diff --git a/utils/trie/lfu-policy.hpp b/utils/trie/lfu-policy.hpp deleted file mode 100644 index 62349616b..000000000 --- a/utils/trie/lfu-policy.hpp +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef LFU_POLICY_H_ -#define LFU_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for LFU replacement policy - */ -struct lfu_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Lfu"; - } - - struct policy_hook_type : public boost::intrusive::set_member_hook<> { - double frequency; - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - static double& - get_order(typename Container::iterator item) - { - return static_cast(policy_container::value_traits::to_node_ptr(*item)) - ->frequency; - } - - static const double& - get_order(typename Container::const_iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->frequency; - } - - template - struct MemberHookLess { - bool - operator()(const Key& a, const Key& b) const - { - return get_order(&a) < get_order(&b); - } - }; - - typedef boost::intrusive::multiset>, - Hook> policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_order methods from outside - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - { - } - - inline void - update(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - get_order(item) += 1; - policy_container::insert(*item); - } - - inline bool - insert(typename parent_trie::iterator item) - { - get_order(item) = 0; - - if (max_size_ != 0 && policy_container::size() >= max_size_) { - // this erases the "least frequently used item" from cache - base_.erase(&(*policy_container::begin())); - } - - policy_container::insert(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - get_order(item) += 1; - policy_container::insert(*item); - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // LFU_POLICY_H diff --git a/utils/trie/lru-policy.hpp b/utils/trie/lru-policy.hpp deleted file mode 100644 index a88b0f755..000000000 --- a/utils/trie/lru-policy.hpp +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef LRU_POLICY_H_ -#define LRU_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for Least Recently Used replacement policy - */ -struct lru_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Lru"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do relocation - policy_container::splice(policy_container::end(), *this, - policy_container::s_iterator_to(*item)); - } - - inline bool - insert(typename parent_trie::iterator item) - { - if (max_size_ != 0 && policy_container::size() >= max_size_) { - base_.erase(&(*policy_container::begin())); - } - - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do relocation - policy_container::splice(policy_container::end(), *this, - policy_container::s_iterator_to(*item)); - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif diff --git a/utils/trie/multi-policy.hpp b/utils/trie/multi-policy.hpp deleted file mode 100644 index 01c895127..000000000 --- a/utils/trie/multi-policy.hpp +++ /dev/null @@ -1,196 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef MULTI_POLICY_H_ -#define MULTI_POLICY_H_ - -/// @cond include_hidden - -#include "detail/multi-type-container.hpp" -#include "detail/multi-policy-container.hpp" -#include "detail/functor-hook.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -template // e.g., mpl::vector1< lru_policy_traits > -struct multi_policy_traits { - typedef Policies policy_traits; - - struct getHook { - template - struct apply { - typedef typename Item::policy_hook_type type; - }; - }; - typedef detail::multi_type_container< - typename boost::mpl::transform1::type> policy_hook_type; - - template - struct container_hook { - typedef policy_hook_type type; - }; - - template - struct policy { - typedef boost::mpl::range_c::type::value> - policies_range; - - struct getPolicy { - template - struct apply { - typedef typename boost::mpl::at_c::type:: - template policy>>::type - type; - }; - }; - - typedef typename boost::mpl::transform1>>::type - policies; - - typedef detail::multi_policy_container policy_container; - - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_time methods from outside - typedef Container parent_trie; - - type(Base& base) - : policy_container(base) - { - } - - inline void - update(typename parent_trie::iterator item) - { - policy_container::update(item); - } - - inline bool - insert(typename parent_trie::iterator item) - { - return policy_container::insert(item); - } - - inline void - lookup(typename parent_trie::iterator item) - { - policy_container::lookup(item); - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(item); - } - - inline void - clear() - { - policy_container::clear(); - } - - struct max_size_setter { - max_size_setter(policy_container& container, size_t size) - : m_container(container) - , m_size(size) - { - } - - template - void - operator()(U index) - { - m_container.template get().set_max_size(m_size); - } - - private: - policy_container& m_container; - size_t m_size; - }; - - inline void - set_max_size(size_t max_size) - { - boost::mpl::for_each::type::value>>( - max_size_setter(*this, max_size)); - } - - inline size_t - get_max_size() const - { - // as max size should be the same everywhere, get the value from the first available policy - return policy_container::template get<0>().get_max_size(); - } - }; - }; - - struct name_getter { - name_getter(std::string& name) - : m_name(name) - { - } - - template - void - operator()(U index) - { - if (!m_name.empty()) - m_name += "::"; - m_name += boost::mpl::at_c::type::GetName(); - } - - std::string& m_name; - }; - - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - // combine names of all internal policies - std::string name; - boost::mpl::for_each::type::value>>( - name_getter(name)); - - return name; - } -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // MULTI_POLICY_H_ diff --git a/utils/trie/payload-policy.hpp b/utils/trie/payload-policy.hpp deleted file mode 100644 index 6df4e7c9c..000000000 --- a/utils/trie/payload-policy.hpp +++ /dev/null @@ -1,129 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef PAYLOAD_POLICY_H_ -#define PAYLOAD_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for policy that keeps items in a sorted order using payload member - */ -template -struct payload_policy_traits { - struct policy_hook_type : public boost::intrusive::set_member_hook<> { - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do relocation - policy_container::splice(policy_container::end(), *this, - policy_container::s_iterator_to(*item)); - } - - inline bool - insert(typename parent_trie::iterator item) - { - if (policy_container::size() >= max_size_) { - base_.erase(&(*policy_container::begin())); - } - - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do relocation - policy_container::splice(policy_container::end(), *this, - policy_container::s_iterator_to(*item)); - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // PAYLOAD_POLICY_H diff --git a/utils/trie/payload-with-policy.hpp b/utils/trie/payload-with-policy.hpp deleted file mode 100644 index c4c904ebc..000000000 --- a/utils/trie/payload-with-policy.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef PAYLOAD_WITH_INDEX_H_ -#define PAYLOAD_WITH_INDEX_H_ - -/// @cond include_hidden - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -template -class payload_with_index { -public: - typedef PayloadTraits::pointer_type iterator; - - typedef typename IndexTraits:: - template index::type>::type - index_container; - - inline payload_with_index() - : index_(*this) - { - } - - inline std::pair - insert(typename iterator payload) - { - bool ok = policy_.insert(s_iterator_to(item.first)); - if (!ok) { - item.first->erase(); // cannot insert - return std::make_pair(end(), false); - } - - return item; - } - - // inline void - // erase (const FullKey &key) - // { - // iterator foundItem, lastItem; - // bool reachLast; - // std::tie (foundItem, reachLast, lastItem) = trie_.find (key); - - // if (!reachLast || lastItem->payload () == PayloadTraits::empty_payload) - // return; // nothing to invalidate - - // erase (lastItem); - // } - - // inline void - // erase (iterator node) - // { - // if (node == end ()) return; - - // policy_.erase (s_iterator_to (node)); - // node->erase (); // will do cleanup here - // } - - // inline void - // clear () - // { - // policy_.clear (); - // trie_.clear (); - // } - - // template - // bool - // modify (iterator position, Modifier mod) - // { - // if (position == end ()) return false; - // if (position->payload () == PayloadTraits::empty_payload) return false; - - // mod (*position->payload ()); - // policy_.update (position); - // return true; - // } - -private: - mutable index_container policy_; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // PAYLOAD_WITH_POLICY_H_ diff --git a/utils/trie/persistent-policy.hpp b/utils/trie/persistent-policy.hpp deleted file mode 100644 index 669b8b239..000000000 --- a/utils/trie/persistent-policy.hpp +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef PERSISTENT_POLICY_H_ -#define PERSISTENT_POLICY_H_ - -/// @cond include_hidden - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for persistent replacement policy - * - * In this policy entries are added until there is a space (controlled by set_max_size call). - * If maximum is reached, new entries will not be added and nothing will be removed from the - *container - */ -struct persistent_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Persistent"; - } - - struct policy_hook_type : public boost::intrusive::list_member_hook<> { - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - typedef typename boost::intrusive::list policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , max_size_(100) // when 0, policy is not enforced - { - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing - } - - inline bool - insert(typename parent_trie::iterator item) - { - if (max_size_ != 0 && policy_container::size() >= max_size_) - return false; - - policy_container::push_back(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - // type () : base_(*((Base*)0)) { }; - - private: - Base& base_; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // PERSISTENT_POLICY_H_ diff --git a/utils/trie/random-policy.hpp b/utils/trie/random-policy.hpp deleted file mode 100644 index a6e35176a..000000000 --- a/utils/trie/random-policy.hpp +++ /dev/null @@ -1,175 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef RANDOM_POLICY_H_ -#define RANDOM_POLICY_H_ - -/// @cond include_hidden - -#include "ns3/random-variable-stream.h" -#include "ns3/double.h" - -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -/** - * @brief Traits for random replacement policy - */ -struct random_policy_traits { - /// @brief Name that can be used to identify the policy (for NS-3 object model and logging) - static std::string - GetName() - { - return "Random"; - } - - struct policy_hook_type : public boost::intrusive::set_member_hook<> { - uint32_t randomOrder; - }; - - template - struct container_hook { - typedef boost::intrusive::member_hook - type; - }; - - template - struct policy { - static uint32_t& - get_order(typename Container::iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->randomOrder; - } - - static const uint32_t& - get_order(typename Container::const_iterator item) - { - return static_cast( - policy_container::value_traits::to_node_ptr(*item))->randomOrder; - } - - template - struct MemberHookLess { - bool - operator()(const Key& a, const Key& b) const - { - return get_order(&a) < get_order(&b); - } - }; - - typedef boost::intrusive::multiset>, - Hook> policy_container; - - // could be just typedef - class type : public policy_container { - public: - typedef policy policy_base; // to get access to get_order methods from outside - typedef Container parent_trie; - - type(Base& base) - : base_(base) - , u_rand(CreateObject()) - , max_size_(100) - { - u_rand->SetAttribute("Min", DoubleValue(0)); - u_rand->SetAttribute("Max", DoubleValue(std::numeric_limits::max())); - } - - inline void - update(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline bool - insert(typename parent_trie::iterator item) - { - get_order(item) = u_rand->GetValue(); - - if (max_size_ != 0 && policy_container::size() >= max_size_) { - if (MemberHookLess()(*item, *policy_container::begin())) { - // std::cout << "Cannot add. Signaling fail\n"; - // just return false. Indicating that insert "failed" - return false; - } - else { - // removing some random element - base_.erase(&(*policy_container::begin())); - } - } - - policy_container::insert(*item); - return true; - } - - inline void - lookup(typename parent_trie::iterator item) - { - // do nothing. it's random policy - } - - inline void - erase(typename parent_trie::iterator item) - { - policy_container::erase(policy_container::s_iterator_to(*item)); - } - - inline void - clear() - { - policy_container::clear(); - } - - inline void - set_max_size(size_t max_size) - { - max_size_ = max_size; - } - - inline size_t - get_max_size() const - { - return max_size_; - } - - private: - type() - : base_(*((Base*)0)){}; - - private: - Base& base_; - Ptr u_rand; - size_t max_size_; - }; - }; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // RANDOM_POLICY_H diff --git a/utils/trie/trie-with-policy.hpp b/utils/trie/trie-with-policy.hpp deleted file mode 100644 index d0d54f6f9..000000000 --- a/utils/trie/trie-with-policy.hpp +++ /dev/null @@ -1,306 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef TRIE_WITH_POLICY_H_ -#define TRIE_WITH_POLICY_H_ - -/// @cond include_hidden - -#include "trie.hpp" - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -template -class trie_with_policy { -public: - typedef trie parent_trie; - - typedef typename parent_trie::iterator iterator; - typedef typename parent_trie::const_iterator const_iterator; - - typedef typename PolicyTraits:: - template policy, parent_trie, - typename PolicyTraits::template container_hook::type>::type - policy_container; - - inline trie_with_policy(size_t bucketSize = 1, size_t bucketIncrement = 1) - : trie_(name::Component(), bucketSize, bucketIncrement) - , policy_(*this) - { - } - - inline std::pair - insert(const FullKey& key, typename PayloadTraits::insert_type payload) - { - std::pair item = trie_.insert(key, payload); - - if (item.second) // real insert - { - bool ok = policy_.insert(s_iterator_to(item.first)); - if (!ok) { - item.first->erase(); // cannot insert - return std::make_pair(end(), false); - } - } - else { - return std::make_pair(s_iterator_to(item.first), false); - } - - return item; - } - - inline void - erase(const FullKey& key) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - - if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload) - return; // nothing to invalidate - - erase(lastItem); - } - - inline void - erase(iterator node) - { - if (node == end()) - return; - - policy_.erase(s_iterator_to(node)); - node->erase(); // will do cleanup here - } - - inline void - clear() - { - policy_.clear(); - trie_.clear(); - } - - template - bool - modify(iterator position, Modifier mod) - { - if (position == end()) - return false; - if (position->payload() == PayloadTraits::empty_payload) - return false; - - mod(*position->payload()); - policy_.update(position); - return true; - } - - /** - * @brief Find a node that has the exact match with the key - */ - inline iterator - find_exact(const FullKey& key) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - - if (!reachLast || lastItem->payload() == PayloadTraits::empty_payload) - return end(); - - return lastItem; - } - - /** - * @brief Find a node that has the longest common prefix with key (FIB/PIT lookup) - */ - inline iterator - longest_prefix_match(const FullKey& key) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - if (foundItem != trie_.end()) { - policy_.lookup(s_iterator_to(foundItem)); - } - return foundItem; - } - - /** - * @brief Find a node that has the longest common prefix with key (FIB/PIT lookup) - */ - template - inline iterator - longest_prefix_match_if(const FullKey& key, Predicate pred) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find_if(key, pred); - if (foundItem != trie_.end()) { - policy_.lookup(s_iterator_to(foundItem)); - } - return foundItem; - } - - // /** - // * @brief Const version of the longest common prefix match - // * (semi-const, because there could be update of the policy anyways) - // */ - // inline const_iterator - // longest_prefix_match (const FullKey &key) const - // { - // return static_cast (this)->longest_prefix_match (key); - // } - - /** - * @brief Find a node that has prefix at least as the key (cache lookup) - */ - inline iterator - deepest_prefix_match(const FullKey& key) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - - // guard in case we don't have anything in the trie - if (lastItem == trie_.end()) - return trie_.end(); - - if (reachLast) { - if (foundItem == trie_.end()) { - foundItem = lastItem->find(); // should be something - } - policy_.lookup(s_iterator_to(foundItem)); - return foundItem; - } - else { // couldn't find a node that has prefix at least as key - return trie_.end(); - } - } - - /** - * @brief Find a node that has prefix at least as the key - */ - template - inline iterator - deepest_prefix_match_if(const FullKey& key, Predicate pred) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - - // guard in case we don't have anything in the trie - if (lastItem == trie_.end()) - return trie_.end(); - - if (reachLast) { - foundItem = lastItem->find_if(pred); // may or may not find something - if (foundItem == trie_.end()) { - return trie_.end(); - } - policy_.lookup(s_iterator_to(foundItem)); - return foundItem; - } - else { // couldn't find a node that has prefix at least as key - return trie_.end(); - } - } - - /** - * @brief Find a node that has prefix at least as the key - * - * This version of find checks predicate for the next level and if - * predicate is True, returns first deepest match available - */ - template - inline iterator - deepest_prefix_match_if_next_level(const FullKey& key, Predicate pred) - { - iterator foundItem, lastItem; - bool reachLast; - std::tie(foundItem, reachLast, lastItem) = trie_.find(key); - - // guard in case we don't have anything in the trie - if (lastItem == trie_.end()) - return trie_.end(); - - if (reachLast) { - foundItem = lastItem->find_if_next_level(pred); // may or may not find something - if (foundItem == trie_.end()) { - return trie_.end(); - } - policy_.lookup(s_iterator_to(foundItem)); - return foundItem; - } - else { // couldn't find a node that has prefix at least as key - return trie_.end(); - } - } - - iterator - end() const - { - return 0; - } - - const parent_trie& - getTrie() const - { - return trie_; - } - - parent_trie& - getTrie() - { - return trie_; - } - - const policy_container& - getPolicy() const - { - return policy_; - } - - policy_container& - getPolicy() - { - return policy_; - } - - static inline iterator - s_iterator_to(typename parent_trie::iterator item) - { - if (item == 0) - return 0; - else - return &(*item); - } - -private: - parent_trie trie_; - mutable policy_container policy_; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // TRIE_WITH_POLICY_H_ diff --git a/utils/trie/trie.hpp b/utils/trie/trie.hpp deleted file mode 100644 index 6d11ecb45..000000000 --- a/utils/trie/trie.hpp +++ /dev/null @@ -1,778 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/** - * Copyright (c) 2011-2015 Regents of the University of California. - * - * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and - * contributors. - * - * ndnSIM is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Foundation, - * either version 3 of the License, or (at your option) any later version. - * - * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * ndnSIM, e.g., in COPYING.md file. If not, see . - **/ - -#ifndef TRIE_H_ -#define TRIE_H_ - -/// @cond include_hidden - -#include "ns3/ndnSIM/model/ndn-common.hpp" - -#include "ns3/ptr.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ns3 { -namespace ndn { -namespace ndnSIM { - -///////////////////////////////////////////////////// -// Allow customization for payload -// -template -struct pointer_payload_traits { - typedef Payload payload_type; // general type of the payload - typedef Payload* storage_type; // how the payload is actually stored - typedef Payload* insert_type; // what parameter is inserted - - typedef Payload* return_type; // what is returned on access - typedef const Payload* const_return_type; // what is returned on const access - - typedef BasePayload* - base_type; // base type of the entry (when implementation details need to be hidden) - typedef const BasePayload* - const_base_type; // const base type of the entry (when implementation details need to be hidden) - - static Payload* empty_payload; -}; - -template -Payload* pointer_payload_traits::empty_payload = 0; - -template -struct smart_pointer_payload_traits { - typedef Payload payload_type; - typedef ns3::Ptr storage_type; - typedef ns3::Ptr insert_type; - - typedef ns3::Ptr return_type; - typedef ns3::Ptr const_return_type; - - typedef ns3::Ptr base_type; - typedef ns3::Ptr const_base_type; - - static ns3::Ptr empty_payload; -}; - -template -ns3::Ptr smart_pointer_payload_traits::empty_payload = 0; - -template -struct non_pointer_traits { - typedef Payload payload_type; - typedef Payload storage_type; - typedef const Payload& insert_type; // nothing to insert - - typedef Payload& return_type; - typedef const Payload& const_return_type; - - typedef BasePayload& base_type; - typedef const BasePayload& const_base_type; - - static Payload empty_payload; -}; - -template -Payload non_pointer_traits::empty_payload = Payload(); - -//////////////////////////////////////////////////// -// forward declarations -// -template -class trie; - -template -inline std::ostream& -operator<<(std::ostream& os, const trie& trie_node); - -template -bool -operator==(const trie& a, - const trie& b); - -template -std::size_t -hash_value(const trie& trie_node); - -/////////////////////////////////////////////////// -// actual definition -// -template -class trie_iterator; - -template -class trie_point_iterator; - -template -class trie { -public: - typedef typename FullKey::value_type Key; - - typedef trie* iterator; - typedef const trie* const_iterator; - - typedef trie_iterator recursive_iterator; - typedef trie_iterator const_recursive_iterator; - - typedef trie_point_iterator point_iterator; - typedef trie_point_iterator const_point_iterator; - - typedef PayloadTraits payload_traits; - - inline trie(const Key& key, size_t bucketSize = 1, size_t bucketIncrement = 1) - : key_(key) - , initialBucketSize_(bucketSize) - , bucketIncrement_(bucketIncrement) - , bucketSize_(initialBucketSize_) - , buckets_(new bucket_type[bucketSize_]) // cannot use normal pointer, because lifetime of - // buckets should be larger than lifetime of the - // container - , children_(bucket_traits(buckets_.get(), bucketSize_)) - , payload_(PayloadTraits::empty_payload) - , parent_(nullptr) - { - } - - inline ~trie() - { - payload_ = PayloadTraits::empty_payload; // necessary for smart pointers... - children_.clear_and_dispose(trie_delete_disposer()); - } - - void - clear() - { - children_.clear_and_dispose(trie_delete_disposer()); - } - - template - void - clear_if(Predicate cond) - { - recursive_iterator trieNode(this); - recursive_iterator end(0); - - while (trieNode != end) { - if (cond(*trieNode)) { - trieNode = recursive_iterator(trieNode->erase()); - } - trieNode++; - } - } - - // actual entry - friend bool operator==<>(const trie& a, - const trie& b); - - friend std::size_t - hash_value<>(const trie& trie_node); - - inline std::pair - insert(const FullKey& key, typename PayloadTraits::insert_type payload) - { - trie* trieNode = this; - - BOOST_FOREACH (const Key& subkey, key) { - typename unordered_set::iterator item = trieNode->children_.find(subkey); - if (item == trieNode->children_.end()) { - trie* newNode = new trie(subkey, initialBucketSize_, bucketIncrement_); - // std::cout << "new " << newNode << "\n"; - newNode->parent_ = trieNode; - - if (trieNode->children_.size() >= trieNode->bucketSize_) { - trieNode->bucketSize_ += trieNode->bucketIncrement_; - trieNode->bucketIncrement_ *= 2; // increase bucketIncrement exponentially - - buckets_array newBuckets(new bucket_type[trieNode->bucketSize_]); - trieNode->children_.rehash(bucket_traits(newBuckets.get(), trieNode->bucketSize_)); - trieNode->buckets_.swap(newBuckets); - } - - std::pair ret = - trieNode->children_.insert(*newNode); - - trieNode = &(*ret.first); - } - else - trieNode = &(*item); - } - - if (trieNode->payload_ == PayloadTraits::empty_payload) { - trieNode->payload_ = payload; - return std::make_pair(trieNode, true); - } - else - return std::make_pair(trieNode, false); - } - - /** - * @brief Removes payload (if it exists) and if there are no children, prunes parents trie - */ - inline iterator - erase() - { - payload_ = PayloadTraits::empty_payload; - return prune(); - } - - /** - * @brief Do exactly as erase, but without erasing the payload - */ - inline iterator - prune() - { - if (payload_ == PayloadTraits::empty_payload && children_.size() == 0) { - if (parent_ == 0) - return this; - - trie* parent = parent_; - parent->children_ - .erase_and_dispose(*this, - trie_delete_disposer()); // delete this; basically, committing a suicide - - return parent->prune(); - } - return this; - } - - /** - * @brief Perform prune of the node, but without attempting to parent of the node - */ - inline void - prune_node() - { - if (payload_ == PayloadTraits::empty_payload && children_.size() == 0) { - if (parent_ == 0) - return; - - trie* parent = parent_; - parent->children_ - .erase_and_dispose(*this, - trie_delete_disposer()); // delete this; basically, committing a suicide - } - } - - // inline std::tuple - // find (const FullKey &key) const - // { - // return const_cast (this)->find (key); - // } - - /** - * @brief Perform the longest prefix match - * @param key the key for which to perform the longest prefix match - * - * @return ->second is true if prefix in ->first is longer than key - */ - inline std::tuple - find(const FullKey& key) - { - trie* trieNode = this; - iterator foundNode = (payload_ != PayloadTraits::empty_payload) ? this : 0; - bool reachLast = true; - - BOOST_FOREACH (const Key& subkey, key) { - typename unordered_set::iterator item = trieNode->children_.find(subkey); - if (item == trieNode->children_.end()) { - reachLast = false; - break; - } - else { - trieNode = &(*item); - - if (trieNode->payload_ != PayloadTraits::empty_payload) - foundNode = trieNode; - } - } - - return std::make_tuple(foundNode, reachLast, trieNode); - } - - /** - * @brief Perform the longest prefix match satisfying preficate - * @param key the key for which to perform the longest prefix match - * - * @return ->second is true if prefix in ->first is longer than key - */ - template - inline std::tuple - find_if(const FullKey& key, Predicate pred) - { - trie* trieNode = this; - iterator foundNode = (payload_ != PayloadTraits::empty_payload) ? this : 0; - bool reachLast = true; - - BOOST_FOREACH (const Key& subkey, key) { - typename unordered_set::iterator item = trieNode->children_.find(subkey); - if (item == trieNode->children_.end()) { - reachLast = false; - break; - } - else { - trieNode = &(*item); - - if (trieNode->payload_ != PayloadTraits::empty_payload && pred(trieNode->payload_)) { - foundNode = trieNode; - } - } - } - - return std::make_tuple(foundNode, reachLast, trieNode); - } - - /** - * @brief Find next payload of the sub-trie - * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration - * ) - */ - inline iterator - find() - { - if (payload_ != PayloadTraits::empty_payload) - return this; - - typedef trie trie; - for (typename trie::unordered_set::iterator subnode = children_.begin(); - subnode != children_.end(); subnode++) - // BOOST_FOREACH (trie &subnode, children_) - { - iterator value = subnode->find(); - if (value != 0) - return value; - } - - return 0; - } - - /** - * @brief Find next payload of the sub-trie satisfying the predicate - * @param pred predicate - * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration - * ) - */ - template - inline const iterator - find_if(Predicate pred) - { - if (payload_ != PayloadTraits::empty_payload && pred(payload_)) - return this; - - typedef trie trie; - for (typename trie::unordered_set::iterator subnode = children_.begin(); - subnode != children_.end(); subnode++) - // BOOST_FOREACH (const trie &subnode, children_) - { - iterator value = subnode->find_if(pred); - if (value != 0) - return value; - } - - return 0; - } - - /** - * @brief Find next payload of the sub-trie satisfying the predicate - * @param pred predicate - * - * This version check predicate only for the next level children - * - * @returns end() or a valid iterator pointing to the trie leaf (order is not defined, enumeration - *) - */ - template - inline const iterator - find_if_next_level(Predicate pred) - { - typedef trie trie; - for (typename trie::unordered_set::iterator subnode = children_.begin(); - subnode != children_.end(); subnode++) { - if (pred(subnode->key())) { - return subnode->find(); - } - } - - return 0; - } - - iterator - end() - { - return 0; - } - - const_iterator - end() const - { - return 0; - } - - typename PayloadTraits::const_return_type - payload() const - { - return payload_; - } - - typename PayloadTraits::return_type - payload() - { - return payload_; - } - - void - set_payload(typename PayloadTraits::insert_type payload) - { - payload_ = payload; - } - - Key - key() const - { - return key_; - } - - inline void - PrintStat(std::ostream& os) const; - -private: - // The disposer object function - struct trie_delete_disposer { - void - operator()(trie* delete_this) - { - delete delete_this; - } - }; - - template - struct array_disposer { - void - operator()(D* array) - { - delete[] array; - } - }; - - friend std::ostream& operator<<<>(std::ostream& os, const trie& trie_node); - -public: - PolicyHook policy_hook_; - -private: - boost::intrusive::unordered_set_member_hook<> unordered_set_member_hook_; - - // necessary typedefs - typedef trie self_type; - typedef boost::intrusive::member_hook, - &trie::unordered_set_member_hook_> member_hook; - - typedef boost::intrusive::unordered_set unordered_set; - typedef typename unordered_set::bucket_type bucket_type; - typedef typename unordered_set::bucket_traits bucket_traits; - - template - friend class trie_iterator; - - template - friend class trie_point_iterator; - - //////////////////////////////////////////////// - // Actual data - //////////////////////////////////////////////// - - Key key_; ///< name component - - size_t initialBucketSize_; - size_t bucketIncrement_; - - size_t bucketSize_; - typedef boost::interprocess::unique_ptr> buckets_array; - buckets_array buckets_; - unordered_set children_; - - typename PayloadTraits::storage_type payload_; - trie* parent_; // to make cleaning effective -}; - -template -inline std::ostream& -operator<<(std::ostream& os, const trie& trie_node) -{ - os << "# " << trie_node.key_ << ((trie_node.payload_ != PayloadTraits::empty_payload) ? "*" : "") - << std::endl; - typedef trie trie; - - for (typename trie::unordered_set::const_iterator subnode = trie_node.children_.begin(); - subnode != trie_node.children_.end(); subnode++) - // BOOST_FOREACH (const trie &subnode, trie_node.children_) - { - os << "\"" << &trie_node << "\"" - << " [label=\"" << trie_node.key_ - << ((trie_node.payload_ != PayloadTraits::empty_payload) ? "*" : "") << "\"]\n"; - os << "\"" << &(*subnode) << "\"" - << " [label=\"" << subnode->key_ - << ((subnode->payload_ != PayloadTraits::empty_payload) ? "*" : "") << "\"]" - "\n"; - - os << "\"" << &trie_node << "\"" - << " -> " - << "\"" << &(*subnode) << "\"" - << "\n"; - os << *subnode; - } - - return os; -} - -template -inline void -trie::PrintStat(std::ostream& os) const -{ - os << "# " << key_ << ((payload_ != PayloadTraits::empty_payload) ? "*" : "") << ": " - << children_.size() << " children" << std::endl; - for (size_t bucket = 0, maxbucket = children_.bucket_count(); bucket < maxbucket; bucket++) { - os << " " << children_.bucket_size(bucket); - } - os << "\n"; - - typedef trie trie; - for (typename trie::unordered_set::const_iterator subnode = children_.begin(); - subnode != children_.end(); subnode++) - // BOOST_FOREACH (const trie &subnode, children_) - { - subnode->PrintStat(os); - } -} - -template -inline bool -operator==(const trie& a, - const trie& b) -{ - return a.key_ == b.key_; -} - -template -inline std::size_t -hash_value(const trie& trie_node) -{ - return boost::hash_value(trie_node.key_); -} - -template // hack for boost < 1.47 -class trie_iterator { -public: - trie_iterator() - : trie_(0) - { - } - trie_iterator(typename Trie::iterator item) - : trie_(item) - { - } - trie_iterator(Trie& item) - : trie_(&item) - { - } - - Trie& operator*() - { - return *trie_; - } - const Trie& operator*() const - { - return *trie_; - } - Trie* operator->() - { - return trie_; - } - const Trie* operator->() const - { - return trie_; - } - bool - operator==(trie_iterator& other) const - { - return (trie_ == other.trie_); - } - bool - operator==(trie_iterator& other) - { - return (trie_ == other.trie_); - } - bool - operator!=(trie_iterator& other) const - { - return !(*this == other); - } - bool - operator!=(trie_iterator& other) - { - return !(*this == other); - } - - trie_iterator& - operator++(int) - { - if (trie_->children_.size() > 0) - trie_ = &(*trie_->children_.begin()); - else - trie_ = goUp(); - return *this; - } - - trie_iterator& - operator++() - { - (*this)++; - return *this; - } - -private: - typedef typename boost::mpl::if_, - typename Trie::unordered_set::iterator, - typename Trie::unordered_set::const_iterator>::type set_iterator; - - Trie* - goUp() - { - if (trie_->parent_ != 0) { - // typename Trie::unordered_set::iterator item = - set_iterator item = const_cast(trie_) - ->parent_->children_.iterator_to(const_cast(*trie_)); - item++; - if (item != trie_->parent_->children_.end()) { - return &(*item); - } - else { - trie_ = trie_->parent_; - return goUp(); - } - } - else - return 0; - } - -private: - Trie* trie_; -}; - -template -class trie_point_iterator { -private: - typedef typename boost::mpl::if_, - typename Trie::unordered_set::const_iterator, - typename Trie::unordered_set::iterator>::type set_iterator; - -public: - trie_point_iterator() - : trie_(0) - { - } - trie_point_iterator(typename Trie::iterator item) - : trie_(item) - { - } - trie_point_iterator(Trie& item) - { - if (item.children_.size() != 0) - trie_ = &*item.children_.begin(); - else - trie_ = 0; - } - - Trie& operator*() - { - return *trie_; - } - const Trie& operator*() const - { - return *trie_; - } - Trie* operator->() - { - return trie_; - } - const Trie* operator->() const - { - return trie_; - } - bool - operator==(trie_point_iterator& other) const - { - return (trie_ == other.trie_); - } - bool - operator==(trie_point_iterator& other) - { - return (trie_ == other.trie_); - } - bool - operator!=(trie_point_iterator& other) const - { - return !(*this == other); - } - bool - operator!=(trie_point_iterator& other) - { - return !(*this == other); - } - - trie_point_iterator& - operator++(int) - { - if (trie_->parent_ != 0) { - set_iterator item = trie_->parent_->children_.iterator_to(*trie_); - item++; - if (item == trie_->parent_->children_.end()) - trie_ = 0; - else - trie_ = &*item; - } - else { - trie_ = 0; - } - return *this; - } - - trie_point_iterator& - operator++() - { - (*this)++; - return *this; - } - -private: - Trie* trie_; -}; - -} // ndnSIM -} // ndn -} // ns3 - -/// @endcond - -#endif // TRIE_H_