blob: 66a81a2f4f888f8eacfe134ac89008a16636b27a [file] [log] [blame]
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -07001/* -*- 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>
32#include <boost/tuple/tuple.hpp>
33
34#include "ccnx.h"
35#include "ccnx-name-components-hash-helper.h"
36// #include "ccnx-content-object-header.h"
37// #include "ccnx-interest-header.h"
38// #include "ccnx-name-components.h"
39
40namespace ns3
41{
42/**
43 * \ingroup ccnx
44 * \brief Typedef for content store container implemented as a Boost.MultiIndex container
45 *
46 * - First index (tag<prefix>) is a unique hash index based on NDN prefix of the stored content.
47 * - Second index (tag<mru>) is a sequential index used to maintain up to m_maxSize most recent used (MRU) entries in the content store
48 * - Third index (tag<ordered>) is just a helper to provide stored prefixes in ordered way. Should be disabled in production build
49 *
50 * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
51 */
52struct CcnxContentStoreLruContainer
53{
54 /// @cond include_hidden
55 typedef
56 boost::multi_index::multi_index_container<
57 CcnxContentStoreEntry,
58 boost::multi_index::indexed_by<
59 boost::multi_index::hashed_unique<
60 boost::multi_index::tag<__ccnx_private::i_prefix>,
61 boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
62 const CcnxNameComponents&,
63 &CcnxContentStoreEntry::GetName>,
64 CcnxPrefixHash>,
65 boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::i_mru> >
66#ifdef _DEBUG
67 ,
68 boost::multi_index::ordered_unique<
69 boost::multi_index::tag<__ccnx_private::i_ordered>,
70 boost::multi_index::const_mem_fun<CcnxContentStoreEntry,
71 const CcnxNameComponents&,
72 &CcnxContentStoreEntry::GetName>
73 >
74#endif
75 >
76 > type;
77 /// @endcond
78};
79
80/**
81 * \ingroup ccnx
82 * \brief NDN content store entry
83 */
84class CcnxContentStoreLru : public CcnxContentStore
85{
86public:
87 /**
88 * \brief Interface ID
89 *
90 * \return interface ID
91 */
92 static TypeId GetTypeId ();
93
94 /**
95 * Default constructor
96 */
97 CcnxContentStoreLru ();
98 virtual ~CcnxContentStoreLru ();
99
100 /**
101 * \brief Set maximum size of content store
102 *
103 * \param size size in packets
104 */
105 void
106 SetMaxSize (uint32_t maxSize);
107
108 /**
109 * \brief Get maximum size of content store
110 *
111 * \returns size in packets
112 */
113 uint32_t
114 GetMaxSize () const;
115
116 // from CcnxContentStore
117 virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
118 Lookup (Ptr<const CcnxInterestHeader> interest);
119
120 virtual bool
121 Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
122
123 virtual void
124 Print () const;
125
126private:
127 size_t m_maxSize; ///< \brief maximum number of entries in cache
128
129 /**
130 * \brief Content store implemented as a Boost.MultiIndex container
131 * \internal
132 */
133 CcnxContentStoreLruContainer::type m_contentStore;
134};
135
136} //namespace ns3
137
138#endif // CCNX_CONTENT_STORE_LRU_H