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 | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 140 | private: |
| 141 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 142 | SetMaxSize(uint32_t maxSize); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 143 | |
| 144 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | GetMaxSize() const; |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 146 | |
| 147 | private: |
| 148 | static LogComponent g_log; ///< @brief Logging variable |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 150 | /// @brief trace of for entry additions (fired every time entry is successfully added to the |
| 151 | /// cache): first parameter is pointer to the CS entry |
| 152 | TracedCallback<Ptr<const Entry>> m_didAddEntry; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 155 | ////////////////////////////////////////// |
| 156 | ////////// Implementation //////////////// |
| 157 | ////////////////////////////////////////// |
| 158 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 159 | template<class Policy> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | LogComponent |
| 161 | ContentStoreImpl<Policy>::g_log = LogComponent(("ndn.cs." + Policy::GetName()).c_str()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 162 | |
| 163 | template<class Policy> |
| 164 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 165 | ContentStoreImpl<Policy>::GetTypeId() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 166 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 167 | static TypeId tid = |
| 168 | TypeId(("ns3::ndn::cs::" + Policy::GetName()).c_str()) |
| 169 | .SetGroupName("Ndn") |
| 170 | .SetParent<ContentStore>() |
| 171 | .AddConstructor<ContentStoreImpl<Policy>>() |
| 172 | .AddAttribute("MaxSize", |
| 173 | "Set maximum number of entries in ContentStore. If 0, limit is not enforced", |
| 174 | StringValue("100"), MakeUintegerAccessor(&ContentStoreImpl<Policy>::GetMaxSize, |
| 175 | &ContentStoreImpl<Policy>::SetMaxSize), |
| 176 | MakeUintegerChecker<uint32_t>()) |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 177 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 178 | .AddTraceSource("DidAddEntry", |
| 179 | "Trace fired every time entry is successfully added to the cache", |
| 180 | MakeTraceSourceAccessor(&ContentStoreImpl<Policy>::m_didAddEntry)); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 181 | |
| 182 | return tid; |
| 183 | } |
| 184 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 185 | struct isNotExcluded { |
| 186 | inline isNotExcluded(const Exclude& exclude) |
| 187 | : m_exclude(exclude) |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 188 | { |
| 189 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 190 | |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 191 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 192 | operator()(const name::Component& comp) const |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 193 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 194 | return !m_exclude.isExcluded(comp); |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | private: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 198 | const Exclude& m_exclude; |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 201 | template<class Policy> |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 202 | shared_ptr<Data> |
| 203 | ContentStoreImpl<Policy>::Lookup(shared_ptr<const Interest> interest) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 204 | { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 205 | NS_LOG_FUNCTION(this << interest->getName()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 206 | |
Alexander Afanasyev | eec89ba | 2013-07-19 16:34:30 -0700 | [diff] [blame] | 207 | typename super::const_iterator node; |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 208 | if (interest->getExclude().empty()) { |
| 209 | node = this->deepest_prefix_match(interest->getName()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 210 | } |
| 211 | else { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 212 | node = this->deepest_prefix_match_if_next_level(interest->getName(), |
| 213 | isNotExcluded(interest->getExclude())); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 214 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 215 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 216 | if (node != this->end()) { |
| 217 | this->m_cacheHitsTrace(interest, node->payload()->GetData()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 218 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 219 | shared_ptr<Data> copy = make_shared<Data>(*node->payload()->GetData()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 220 | return copy; |
| 221 | } |
| 222 | else { |
| 223 | this->m_cacheMissesTrace(interest); |
| 224 | return 0; |
| 225 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 228 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 229 | bool |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 230 | ContentStoreImpl<Policy>::Add(shared_ptr<const Data> data) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 231 | { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 232 | NS_LOG_FUNCTION(this << data->getName()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 234 | Ptr<entry> newEntry = Create<entry>(this, data); |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 235 | std::pair<typename super::iterator, bool> result = super::insert(data->getName(), newEntry); |
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 | if (result.first != super::end()) { |
| 238 | if (result.second) { |
| 239 | newEntry->SetTrie(result.first); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 240 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 241 | m_didAddEntry(newEntry); |
| 242 | return true; |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 243 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 244 | else { |
| 245 | // should we do anything? |
| 246 | // update payload? add new payload? |
| 247 | return false; |
| 248 | } |
| 249 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 250 | else |
| 251 | return false; // cannot insert entry |
| 252 | } |
| 253 | |
| 254 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 255 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 256 | ContentStoreImpl<Policy>::Print(std::ostream& os) const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 257 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 258 | for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); |
| 259 | item != this->getPolicy().end(); item++) { |
Spyridon Mastorakis | 1f1cd5e | 2014-12-04 11:12:40 -0800 | [diff] [blame] | 260 | os << item->payload ()->GetName () << std::endl; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 261 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 265 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 266 | ContentStoreImpl<Policy>::SetMaxSize(uint32_t maxSize) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 267 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 268 | this->getPolicy().set_max_size(maxSize); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | template<class Policy> |
| 272 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 273 | ContentStoreImpl<Policy>::GetMaxSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 274 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 275 | return this->getPolicy().get_max_size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | template<class Policy> |
| 279 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 280 | ContentStoreImpl<Policy>::GetSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 281 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 282 | return this->getPolicy().size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | template<class Policy> |
| 286 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 287 | ContentStoreImpl<Policy>::Begin() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 288 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 289 | typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0); |
| 290 | for (; item != end; item++) { |
| 291 | if (item->payload() == 0) |
| 292 | continue; |
| 293 | break; |
| 294 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 295 | |
| 296 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 297 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 298 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 299 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | template<class Policy> |
| 303 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 304 | ContentStoreImpl<Policy>::End() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 305 | { |
| 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | template<class Policy> |
| 310 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 311 | ContentStoreImpl<Policy>::Next(Ptr<Entry> from) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 312 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 313 | if (from == 0) |
| 314 | return 0; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 315 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 316 | typename super::parent_trie::recursive_iterator item(*StaticCast<entry>(from)->to_iterator()), |
| 317 | end(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 | for (item++; item != end; item++) { |
| 320 | if (item->payload() == 0) |
| 321 | continue; |
| 322 | break; |
| 323 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 324 | |
| 325 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 326 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 327 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 328 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 331 | } // namespace cs |
| 332 | } // namespace ndn |
| 333 | } // namespace ns3 |
| 334 | |
| 335 | #endif // NDN_CONTENT_STORE_IMPL_H_ |