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 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 24 | #include "ndn-content-store.hpp" |
| 25 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 26 | #include "ns3/packet.h" |
Alexander Afanasyev | bd9c18e | 2012-11-19 15:23:41 -0800 | [diff] [blame] | 27 | #include "ns3/ndn-interest.h" |
Alexander Afanasyev | 6eba36f | 2013-08-07 17:42:54 -0700 | [diff] [blame] | 28 | #include "ns3/ndn-data.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: |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 51 | EntryImpl(Ptr<ContentStore> cs, Ptr<const Data> data) |
| 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 | |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 106 | virtual inline Ptr<Data> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 107 | Lookup(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 |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | Add(Ptr<const Data> data); |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 111 | |
| 112 | // virtual bool |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 113 | // Remove (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> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 203 | Ptr<Data> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 204 | ContentStoreImpl<Policy>::Lookup(Ptr<const Interest> interest) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 205 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -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; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 209 | if (interest->GetExclude() == 0) { |
| 210 | node = this->deepest_prefix_match(interest->GetName()); |
| 211 | } |
| 212 | else { |
| 213 | node = this->deepest_prefix_match_if_next_level(interest->GetName(), |
| 214 | isNotExcluded(*interest->GetExclude())); |
| 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 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 220 | Ptr<Data> copy = Create<Data>(*node->payload()->GetData()); |
| 221 | ConstCast<Packet>(copy->GetPayload())->RemoveAllPacketTags(); |
| 222 | return copy; |
| 223 | } |
| 224 | else { |
| 225 | this->m_cacheMissesTrace(interest); |
| 226 | return 0; |
| 227 | } |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 230 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 231 | bool |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 232 | ContentStoreImpl<Policy>::Add(Ptr<const Data> data) |
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 | NS_LOG_FUNCTION(this << data->GetName()); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 235 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 236 | Ptr<entry> newEntry = Create<entry>(this, data); |
| 237 | std::pair<typename super::iterator, bool> result = super::insert(data->GetName(), newEntry); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 238 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 239 | if (result.first != super::end()) { |
| 240 | if (result.second) { |
| 241 | newEntry->SetTrie(result.first); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 242 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 243 | m_didAddEntry(newEntry); |
| 244 | return true; |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 245 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 246 | else { |
| 247 | // should we do anything? |
| 248 | // update payload? add new payload? |
| 249 | return false; |
| 250 | } |
| 251 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 252 | else |
| 253 | return false; // cannot insert entry |
| 254 | } |
| 255 | |
| 256 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 257 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 258 | ContentStoreImpl<Policy>::Print(std::ostream& os) const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 259 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 260 | for (typename super::policy_container::const_iterator item = this->getPolicy().begin(); |
| 261 | item != this->getPolicy().end(); item++) { |
| 262 | os << item->payload()->GetName() << std::endl; |
| 263 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | template<class Policy> |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 267 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 268 | ContentStoreImpl<Policy>::SetMaxSize(uint32_t maxSize) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 269 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 270 | this->getPolicy().set_max_size(maxSize); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | template<class Policy> |
| 274 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 275 | ContentStoreImpl<Policy>::GetMaxSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 276 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 277 | return this->getPolicy().get_max_size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | template<class Policy> |
| 281 | uint32_t |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 282 | ContentStoreImpl<Policy>::GetSize() const |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 283 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 284 | return this->getPolicy().size(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | template<class Policy> |
| 288 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 289 | ContentStoreImpl<Policy>::Begin() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 290 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 291 | typename super::parent_trie::recursive_iterator item(super::getTrie()), end(0); |
| 292 | for (; item != end; item++) { |
| 293 | if (item->payload() == 0) |
| 294 | continue; |
| 295 | break; |
| 296 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 297 | |
| 298 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 299 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 300 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 301 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | template<class Policy> |
| 305 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 306 | ContentStoreImpl<Policy>::End() |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 307 | { |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | template<class Policy> |
| 312 | Ptr<Entry> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 313 | ContentStoreImpl<Policy>::Next(Ptr<Entry> from) |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 314 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 315 | if (from == 0) |
| 316 | return 0; |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 317 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 318 | typename super::parent_trie::recursive_iterator item(*StaticCast<entry>(from)->to_iterator()), |
| 319 | end(0); |
Alexander Afanasyev | 25093a3 | 2013-02-01 13:00:13 -0800 | [diff] [blame] | 320 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 321 | for (item++; item != end; item++) { |
| 322 | if (item->payload() == 0) |
| 323 | continue; |
| 324 | break; |
| 325 | } |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 326 | |
| 327 | if (item == end) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 328 | return End(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 329 | else |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 330 | return item->payload(); |
Alexander Afanasyev | 991a0cc | 2012-12-10 11:38:19 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 333 | } // namespace cs |
| 334 | } // namespace ndn |
| 335 | } // namespace ns3 |
| 336 | |
| 337 | #endif // NDN_CONTENT_STORE_IMPL_H_ |