Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011,2012 University of California, Los Angeles |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 22 | #ifndef CCNX_CONTENT_STORE_H |
| 23 | #define CCNX_CONTENT_STORE_H |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 25 | #include "ns3/object.h" |
| 26 | #include "ns3/ptr.h" |
Alexander Afanasyev | 39485d8 | 2012-06-08 17:51:47 -0700 | [diff] [blame] | 27 | #include "ns3/traced-callback.h" |
| 28 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 29 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 30 | |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 31 | namespace ns3 |
| 32 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 33 | |
| 34 | class Packet; |
| 35 | class CcnxContentObjectHeader; |
| 36 | class CcnxInterestHeader; |
| 37 | class CcnxNameComponents; |
| 38 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 39 | /** |
| 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 Afanasyev | b0c4389 | 2012-06-13 00:52:58 -0700 | [diff] [blame] | 50 | class CcnxContentStoreEntry : public SimpleRefCount<CcnxContentStoreEntry> |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 51 | { |
| 52 | public: |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 53 | /** |
| 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 | */ |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 62 | CcnxContentStoreEntry (Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * \brief Get prefix of the stored entry |
| 66 | * \returns prefix of the stored entry |
| 67 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 68 | const CcnxNameComponents& |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 69 | GetName () const; |
| 70 | |
| 71 | /** |
| 72 | * \brief Get CcnxContentObjectHeader of the stored entry |
| 73 | * \returns CcnxContentObjectHeader of the stored entry |
| 74 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 75 | Ptr<const CcnxContentObjectHeader> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 76 | GetHeader () const; |
| 77 | |
| 78 | /** |
| 79 | * \brief Get content of the stored entry |
| 80 | * \returns content of the stored entry |
| 81 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 82 | Ptr<const Packet> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 83 | 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 Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 92 | private: |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 93 | Ptr<const CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 94 | Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * \ingroup ccnx |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 100 | * \brief Base class for NDN content store |
| 101 | * |
| 102 | * Particular implementations should implement Lookup, Add, and Print methods |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 103 | */ |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 104 | class CcnxContentStore : public Object |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 105 | { |
| 106 | public: |
| 107 | /** |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 108 | * \brief Interface ID |
| 109 | * |
| 110 | * \return interface ID |
| 111 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 112 | static |
| 113 | TypeId GetTypeId (); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 116 | * @brief Virtual destructor |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 117 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 118 | virtual ~CcnxContentStore (); |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 119 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 120 | /** |
| 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 Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 129 | virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> > |
| 130 | Lookup (Ptr<const CcnxInterestHeader> interest) = 0; |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 132 | /** |
| 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 Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 138 | * @returns true if an existing entry was updated, false otherwise |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 139 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 140 | virtual bool |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 141 | Add (Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet) = 0; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 142 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 143 | // /** |
| 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 Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * \brief Print out content store entries |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 154 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 155 | virtual void |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 156 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 39485d8 | 2012-06-08 17:51:47 -0700 | [diff] [blame] | 157 | |
| 158 | protected: |
| 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 Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 163 | }; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 164 | |
| 165 | inline std::ostream& |
| 166 | operator<< (std::ostream &os, const CcnxContentStore &cs) |
| 167 | { |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 168 | cs.Print (os); |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 169 | return os; |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 170 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 171 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 172 | } // namespace ns3 |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 173 | |
| 174 | #endif // CCNX_CONTENT_STORE_H |