Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef CCNX_CONTENT_STORE_LRU_H |
| 22 | #define CCNX_CONTENT_STORE_LRU_H |
| 23 | |
| 24 | #include "ccnx-content-store.h" |
| 25 | |
| 26 | #include <boost/multi_index_container.hpp> |
| 27 | #include <boost/multi_index/tag.hpp> |
| 28 | #include <boost/multi_index/ordered_index.hpp> |
| 29 | #include <boost/multi_index/sequenced_index.hpp> |
| 30 | #include <boost/multi_index/hashed_index.hpp> |
| 31 | #include <boost/multi_index/mem_fun.hpp> |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 32 | |
| 33 | #include "ccnx.h" |
| 34 | #include "ccnx-name-components-hash-helper.h" |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 35 | |
| 36 | namespace ns3 |
| 37 | { |
| 38 | /** |
| 39 | * \ingroup ccnx |
| 40 | * \brief Typedef for content store container implemented as a Boost.MultiIndex container |
| 41 | * |
| 42 | * - First index (tag<prefix>) is a unique hash index based on NDN prefix of the stored content. |
| 43 | * - Second index (tag<mru>) is a sequential index used to maintain up to m_maxSize most recent used (MRU) entries in the content store |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 44 | * |
| 45 | * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library |
| 46 | */ |
| 47 | struct CcnxContentStoreLruContainer |
| 48 | { |
| 49 | /// @cond include_hidden |
| 50 | typedef |
| 51 | boost::multi_index::multi_index_container< |
| 52 | CcnxContentStoreEntry, |
| 53 | boost::multi_index::indexed_by< |
| 54 | boost::multi_index::hashed_unique< |
| 55 | boost::multi_index::tag<__ccnx_private::i_prefix>, |
| 56 | boost::multi_index::const_mem_fun<CcnxContentStoreEntry, |
| 57 | const CcnxNameComponents&, |
| 58 | &CcnxContentStoreEntry::GetName>, |
| 59 | CcnxPrefixHash>, |
| 60 | boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::i_mru> > |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 61 | > |
| 62 | > type; |
| 63 | /// @endcond |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * \ingroup ccnx |
| 68 | * \brief NDN content store entry |
| 69 | */ |
| 70 | class CcnxContentStoreLru : public CcnxContentStore |
| 71 | { |
| 72 | public: |
| 73 | /** |
| 74 | * \brief Interface ID |
| 75 | * |
| 76 | * \return interface ID |
| 77 | */ |
| 78 | static TypeId GetTypeId (); |
| 79 | |
| 80 | /** |
| 81 | * Default constructor |
| 82 | */ |
| 83 | CcnxContentStoreLru (); |
| 84 | virtual ~CcnxContentStoreLru (); |
| 85 | |
| 86 | /** |
| 87 | * \brief Set maximum size of content store |
| 88 | * |
| 89 | * \param size size in packets |
| 90 | */ |
| 91 | void |
| 92 | SetMaxSize (uint32_t maxSize); |
| 93 | |
| 94 | /** |
| 95 | * \brief Get maximum size of content store |
| 96 | * |
| 97 | * \returns size in packets |
| 98 | */ |
| 99 | uint32_t |
| 100 | GetMaxSize () const; |
| 101 | |
| 102 | // from CcnxContentStore |
| 103 | virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> > |
| 104 | Lookup (Ptr<const CcnxInterestHeader> interest); |
| 105 | |
| 106 | virtual bool |
| 107 | Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
| 108 | |
| 109 | virtual void |
| 110 | Print () const; |
| 111 | |
| 112 | private: |
| 113 | size_t m_maxSize; ///< \brief maximum number of entries in cache |
| 114 | |
| 115 | /** |
| 116 | * \brief Content store implemented as a Boost.MultiIndex container |
| 117 | * \internal |
| 118 | */ |
| 119 | CcnxContentStoreLruContainer::type m_contentStore; |
| 120 | }; |
| 121 | |
| 122 | } //namespace ns3 |
| 123 | |
| 124 | #endif // CCNX_CONTENT_STORE_LRU_H |