blob: 34d209d9a4abdef244869aded395808dd9c5e636 [file] [log] [blame]
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -07003 * Copyright (c) 2011,2012 University of California, Los Angeles
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -07004 *
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 *
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070020 */
21
Alexander Afanasyev070aa482011-08-20 00:38:25 -070022#ifndef CCNX_CONTENT_STORE_H
23#define CCNX_CONTENT_STORE_H
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070024
Alexander Afanasyev070aa482011-08-20 00:38:25 -070025#include "ns3/object.h"
26#include "ns3/ptr.h"
Alexander Afanasyev39485d82012-06-08 17:51:47 -070027#include "ns3/traced-callback.h"
28
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080029#include <boost/tuple/tuple.hpp>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070030
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070031namespace ns3
32{
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070033
34class Packet;
35class CcnxContentObjectHeader;
36class CcnxInterestHeader;
37class CcnxNameComponents;
38
Alexander Afanasyev070aa482011-08-20 00:38:25 -070039/**
40 * \ingroup ccnx
41 * \brief NDN content store entry
42 *
43 * Content store entry stores separately pseudo header and content of
44 * ContentObject packet. It is responsibility of the caller to
45 * construct a fully formed CcnxPacket by calling Copy(), AddHeader(),
46 * AddTail() on the packet received by GetPacket() method.
47 *
48 * GetFullyFormedCcnxPacket method provided as a convenience
49 */
Alexander Afanasyevb0c43892012-06-13 00:52:58 -070050class CcnxContentStoreEntry : public SimpleRefCount<CcnxContentStoreEntry>
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -070051{
52public:
Alexander Afanasyev070aa482011-08-20 00:38:25 -070053 /**
54 * \brief Construct content store entry
55 *
56 * \param header Parsed CcnxContentObject header
57 * \param packet Original CCNx packet
58 *
59 * The constructor will make a copy of the supplied packet and calls
60 * RemoveHeader and RemoveTail on the copy.
61 */
62 CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet);
63
64 /**
65 * \brief Get prefix of the stored entry
66 * \returns prefix of the stored entry
67 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070068 const CcnxNameComponents&
Alexander Afanasyev070aa482011-08-20 00:38:25 -070069 GetName () const;
70
71 /**
72 * \brief Get CcnxContentObjectHeader of the stored entry
73 * \returns CcnxContentObjectHeader of the stored entry
74 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070075 Ptr<const CcnxContentObjectHeader>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070076 GetHeader () const;
77
78 /**
79 * \brief Get content of the stored entry
80 * \returns content of the stored entry
81 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -070082 Ptr<const Packet>
Alexander Afanasyev070aa482011-08-20 00:38:25 -070083 GetPacket () const;
84
85 /**
86 * \brief Convenience method to create a fully formed CCNx packet from stored header and content
87 * \returns A read-write copy of the packet with CcnxContentObjectHeader and CcxnContentObjectTail
88 */
89 Ptr<Packet>
90 GetFullyFormedCcnxPacket () const;
91
Alexander Afanasyev070aa482011-08-20 00:38:25 -070092private:
93 Ptr<CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader
94 Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet
Alexander Afanasyev070aa482011-08-20 00:38:25 -070095};
96
Alexander Afanasyev070aa482011-08-20 00:38:25 -070097
98/**
99 * \ingroup ccnx
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700100 * \brief Base class for NDN content store
101 *
102 * Particular implementations should implement Lookup, Add, and Print methods
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700103 */
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700104class CcnxContentStore : public Object
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700105{
106public:
107 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700108 * \brief Interface ID
109 *
110 * \return interface ID
111 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700112 static
113 TypeId GetTypeId ();
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700114
115 /**
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700116 * @brief Virtual destructor
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700117 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700118 virtual ~CcnxContentStore ();
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -0700119
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700120 /**
121 * \brief Find corresponding CS entry for the given interest
122 *
123 * \param interest Interest for which matching content store entry
124 * will be searched
125 *
126 * If an entry is found, it is promoted to the top of most recent
127 * used entries index, \see m_contentStore
128 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700129 virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> >
130 Lookup (Ptr<const CcnxInterestHeader> interest) = 0;
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -0700131
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700132 /**
133 * \brief Add a new content to the content store.
134 *
135 * \param header Fully parsed CcnxContentObjectHeader
136 * \param packet Fully formed CCNx packet to add to content store
137 * (will be copied and stripped down of headers)
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700138 * @returns true if an existing entry was updated, false otherwise
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700139 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700140 virtual bool
141 Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet) = 0;
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700142
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700143 // /**
144 // * \brief Add a new content to the content store.
145 // *
146 // * \param header Interest header for which an entry should be removed
147 // * @returns true if an existing entry was removed, false otherwise
148 // */
149 // virtual bool
150 // Remove (Ptr<CcnxInterestHeader> header) = 0;
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700151
152 /**
153 * \brief Print out content store entries
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700154 */
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700155 virtual void
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700156 Print (std::ostream &os) const = 0;
Alexander Afanasyev39485d82012-06-08 17:51:47 -0700157
158protected:
159 TracedCallback<Ptr<const CcnxInterestHeader>,
160 Ptr<const CcnxContentObjectHeader> > m_cacheHitsTrace; ///< @brief trace of cache hits
161
162 TracedCallback<Ptr<const CcnxInterestHeader> > m_cacheMissesTrace; ///< @brief trace of cache misses
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -0700163};
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700164
165inline std::ostream&
166operator<< (std::ostream &os, const CcnxContentStore &cs)
167{
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700168 cs.Print (os);
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700169 return os;
Ilya Moiseenko1c570bc2011-08-17 19:18:02 -0700170}
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700171
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700172} // namespace ns3
Alexander Afanasyev070aa482011-08-20 00:38:25 -0700173
174#endif // CCNX_CONTENT_STORE_H