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