Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 19 | |
| 20 | #ifndef NDN_CONTENT_STORE_IMPL_H_ |
| 21 | #define NDN_CONTENT_STORE_IMPL_H_ |
| 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 24 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 25 | #include "ndn-content-store.hpp" |
| 26 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 27 | #include "ns3/packet.h" |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 28 | #include <boost/foreach.hpp> |
| 29 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 30 | #include "ns3/log.h" |
| 31 | #include "ns3/uinteger.h" |
| 32 | #include "ns3/string.h" |
| 33 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 34 | #include "../../utils/trie/trie-with-policy.hpp" |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 35 | |
| 36 | namespace ns3 { |
| 37 | namespace ndn { |
| 38 | namespace cs { |
| 39 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @ingroup ndn-cs |
| 42 | * @brief Cache entry implementation with additional references to the base container |
| 43 | */ |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 44 | template<class CS> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | class EntryImpl : public Entry { |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 46 | public: |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 47 | typedef Entry base_type; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 48 | |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 49 | public: |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 50 | EntryImpl(Ptr<ContentStore> cs, shared_ptr<const Data> data) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | : Entry(cs, data) |
| 52 | , item_(0) |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 53 | { |
| 54 | } |
| 55 | |
| 56 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | SetTrie(typename CS::super::iterator item) |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 58 | { |
| 59 | item_ = item; |
| 60 | } |
| 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | typename CS::super::iterator |
| 63 | to_iterator() |
| 64 | { |
| 65 | return item_; |
| 66 | } |
| 67 | typename CS::super::const_iterator |
| 68 | to_iterator() const |
| 69 | { |
| 70 | return item_; |
| 71 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 73 | private: |
| 74 | typename CS::super::iterator item_; |
| 75 | }; |
| 76 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 77 | /** |
| 78 | * @ingroup ndn-cs |
| 79 | * @brief Base implementation of NDN content store |
| 80 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 81 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | class ContentStoreImpl |
| 83 | : public ContentStore, |
| 84 | protected ndnSIM:: |
| 85 | trie_with_policy<Name, |
| 86 | ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>, |
| 87 | Entry>, |
| 88 | Policy> { |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 89 | public: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | typedef ndnSIM:: |
| 91 | trie_with_policy<Name, ndnSIM::smart_pointer_payload_traits<EntryImpl<ContentStoreImpl<Policy>>, |
| 92 | Entry>, |
| 93 | Policy> super; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 94 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | typedef EntryImpl<ContentStoreImpl<Policy>> entry; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 96 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 97 | static TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | GetTypeId(); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 99 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 100 | ContentStoreImpl(){}; |
| 101 | virtual ~ContentStoreImpl(){}; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 102 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 103 | // from ContentStore |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 104 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 105 | virtual inline shared_ptr<Data> |
| 106 | Lookup(shared_ptr<const Interest> interest); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 107 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 108 | virtual inline bool |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 109 | Add(shared_ptr<const Data> data); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 110 | |
| 111 | // virtual bool |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 112 | // Remove (shared_ptr<Interest> header); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 114 | virtual inline void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | Print(std::ostream& os) const; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 116 | |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 117 | virtual uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | GetSize() const; |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 119 | |
| 120 | virtual Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 121 | Begin(); |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 122 | |
| 123 | virtual Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 124 | End(); |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 125 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 126 | virtual Ptr<Entry> Next(Ptr<Entry>); |
Alexander Afanasyev | 29c19b9 | 2012-09-03 23:46:41 -0700 | [diff] [blame] | 127 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | const typename super::policy_container& |
| 129 | GetPolicy() const |
| 130 | { |
| 131 | return super::getPolicy(); |
| 132 | } |
Alexander Afanasyev | f21bfc1 | 2013-11-17 11:58:33 -0800 | [diff] [blame] | 133 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 134 | typename super::policy_container& |
| 135 | GetPolicy() |
| 136 | { |
| 137 | return super::getPolicy(); |
| 138 | } |
| 139 | |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 140 | public: |
| 141 | typedef void (*CsEntryCallback)(Ptr<const Entry>); |
| 142 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 143 | private: |
| 144 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | SetMaxSize(uint32_t maxSize); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 146 | |
| 147 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 148 | GetMaxSize() const; |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 149 | |
| 150 | private: |
| 151 | static LogComponent g_log; ///< @brief Logging variable |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 152 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 153 | /// @brief trace of for entry additions (fired every time entry is successfully added to the |
| 154 | /// cache): first parameter is pointer to the CS entry |
| 155 | TracedCallback<Ptr<const Entry>> m_didAddEntry; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 158 | ////////////////////////////////////////// |
| 159 | ////////// Implementation //////////////// |
| 160 | ////////////////////////////////////////// |
| 161 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 162 | template<class Policy> |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 163 | LogComponent ContentStoreImpl<Policy>::g_log = LogComponent(("ndn.cs." + Policy::GetName()).c_str(), __FILE__); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 164 | |
| 165 | template<class Policy> |
| 166 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 167 | ContentStoreImpl<Policy>::GetTypeId() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 168 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 169 | static TypeId tid = |
| 170 | TypeId(("ns3::ndn::cs::" + Policy::GetName()).c_str()) |
| 171 | .SetGroupName("Ndn") |
| 172 | .SetParent<ContentStore>() |
| 173 | .AddConstructor<ContentStoreImpl<Policy>>() |
| 174 | .AddAttribute("MaxSize", |
| 175 | "Set maximum number of entries in ContentStore. If 0, limit is not enforced", |
| 176 | StringValue("100"), MakeUintegerAccessor(&ContentStoreImpl<Policy>::GetMaxSize, |
| 177 | &ContentStoreImpl<Policy>::SetMaxSize), |
| 178 | MakeUintegerChecker<uint32_t>()) |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 179 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 180 | .AddTraceSource("DidAddEntry", |
| 181 | "Trace fired every time entry is successfully added to the cache", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 182 | MakeTraceSourceAccessor(&ContentStoreImpl<Policy>::m_didAddEntry), |
| 183 | "ns3::ndn::cs::ContentStoreImpl::CsEntryCallback"); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 184 | |
| 185 | return tid; |
| 186 | } |
| 187 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 188 | struct isNotExcluded { |
| 189 | inline isNotExcluded(const Exclude& exclude) |
| 190 | : m_exclude(exclude) |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 191 | { |
| 192 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 193 | |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 194 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 195 | operator()(const name::Component& comp) const |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 196 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 197 | return !m_exclude.isExcluded(comp); |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 201 | const Exclude& m_exclude; |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 204 | template<class Policy> |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 205 | shared_ptr<Data> |
| 206 | ContentStoreImpl<Policy>::Lookup(shared_ptr<const Interest> interest) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 207 | { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 208 | NS_LOG_FUNCTION(this << interest->getName()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 209 | |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 210 | typename super::const_iterator node; |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 211 | if (interest->getExclude().empty()) { |
| 212 | node = this->deepest_prefix_match(interest->getName()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 213 | } |
| 214 | else { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 215 | node = this->deepest_prefix_match_if_next_level(interest->getName(), |
| 216 | isNotExcluded(interest->getExclude())); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 217 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 219 | if (node != this->end()) { |
| 220 | this->m_cacheHitsTrace(interest, node->payload()->GetData()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 221 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 222 | shared_ptr<Data> copy = make_shared<Data>(*node->payload()->GetData()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 223 | return copy; |
| 224 | } |
| 225 | else { |
| 226 | this->m_cacheMissesTrace(interest); |
| 227 | return 0; |
| 228 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 231 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 232 | bool |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 233 | ContentStoreImpl<Policy>::Add(shared_ptr<const Data> data) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 234 | { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 235 | NS_LOG_FUNCTION(this << data->getName()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 236 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 237 | Ptr<entry> newEntry = Create<entry>(this, data); |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 238 | std::pair<typename super::iterator, bool> result = super::insert(data->getName(), newEntry); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 239 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 240 | if (result.first != super::end()) { |
| 241 | if (result.second) { |
| 242 | newEntry->SetTrie(result.first); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 243 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 244 | m_didAddEntry(newEntry); |
| 245 | return true; |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 246 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 247 | else { |
| 248 | // should we do anything? |
| 249 | // update payload? add new payload? |
| 250 | return false; |
| 251 | } |
| 252 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 253 | else |
| 254 | return false; // cannot insert entry |
| 255 | } |
| 256 | |
| 257 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 258 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 259 | ContentStoreImpl<Policy>::Print(std::ostream& os) const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 260 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 261 | for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); |
| 262 | item != this->getPolicy().end(); item++) { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 263 | os << item->payload ()->GetName () << std::endl; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 264 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 268 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 269 | ContentStoreImpl<Policy>::SetMaxSize(uint32_t maxSize) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 270 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 271 | this->getPolicy().set_max_size(maxSize); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | template<class Policy> |
| 275 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 276 | ContentStoreImpl<Policy>::GetMaxSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 277 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 278 | return this->getPolicy().get_max_size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | template<class Policy> |
| 282 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 283 | ContentStoreImpl<Policy>::GetSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 284 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 285 | return this->getPolicy().size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | template<class Policy> |
| 289 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 290 | ContentStoreImpl<Policy>::Begin() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 291 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 292 | typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0); |
| 293 | for (; item != end; item++) { |
| 294 | if (item->payload() == 0) |
| 295 | continue; |
| 296 | break; |
| 297 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 298 | |
| 299 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 300 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 301 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 302 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | template<class Policy> |
| 306 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 307 | ContentStoreImpl<Policy>::End() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 308 | { |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | template<class Policy> |
| 313 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 314 | ContentStoreImpl<Policy>::Next(Ptr<Entry> from) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 315 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 316 | if (from == 0) |
| 317 | return 0; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 318 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 319 | typename super::parent_trie::recursive_iterator item(*StaticCast<entry>(from)->to_iterator()), |
| 320 | end(0); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 321 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 322 | for (item++; item != end; item++) { |
| 323 | if (item->payload() == 0) |
| 324 | continue; |
| 325 | break; |
| 326 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 327 | |
| 328 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 329 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 330 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 331 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 334 | } // namespace cs |
| 335 | } // namespace ndn |
| 336 | } // namespace ns3 |
| 337 | |
| 338 | #endif // NDN_CONTENT_STORE_IMPL_H_ |