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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #ifndef NDN_CONTENT_STORE_H |
| 23 | #define NDN_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; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 35 | class NdnContentObjectHeader; |
| 36 | class NdnInterestHeader; |
| 37 | class NdnNameComponents; |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 38 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 39 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 40 | * \ingroup ndn |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 45 | * construct a fully formed NdnPacket by calling Copy(), AddHeader(), |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 46 | * AddTail() on the packet received by GetPacket() method. |
| 47 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 48 | * GetFullyFormedNdnPacket method provided as a convenience |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 49 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 50 | class NdnContentStoreEntry : public SimpleRefCount<NdnContentStoreEntry> |
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 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 56 | * \param header Parsed NdnContentObject header |
| 57 | * \param packet Original Ndn packet |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 58 | * |
| 59 | * The constructor will make a copy of the supplied packet and calls |
| 60 | * RemoveHeader and RemoveTail on the copy. |
| 61 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 62 | NdnContentStoreEntry (Ptr<const NdnContentObjectHeader> 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 68 | const NdnNameComponents& |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 69 | GetName () const; |
| 70 | |
| 71 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 72 | * \brief Get NdnContentObjectHeader of the stored entry |
| 73 | * \returns NdnContentObjectHeader of the stored entry |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 75 | Ptr<const NdnContentObjectHeader> |
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 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 86 | * \brief Convenience method to create a fully formed Ndn packet from stored header and content |
| 87 | * \returns A read-write copy of the packet with NdnContentObjectHeader and CcxnContentObjectTail |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 88 | */ |
| 89 | Ptr<Packet> |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 90 | GetFullyFormedNdnPacket () const; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 92 | private: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 93 | Ptr<const NdnContentObjectHeader> m_header; ///< \brief non-modifiable NdnContentObjectHeader |
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 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 99 | * \ingroup ndn |
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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 104 | class NdnContentStore : 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 118 | virtual ~NdnContentStore (); |
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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 129 | virtual boost::tuple<Ptr<Packet>, Ptr<const NdnContentObjectHeader>, Ptr<const Packet> > |
| 130 | Lookup (Ptr<const NdnInterestHeader> 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 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 135 | * \param header Fully parsed NdnContentObjectHeader |
| 136 | * \param packet Fully formed Ndn packet to add to content store |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 141 | Add (Ptr<const NdnContentObjectHeader> 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 |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 150 | // Remove (Ptr<NdnInterestHeader> 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: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 159 | TracedCallback<Ptr<const NdnInterestHeader>, |
| 160 | Ptr<const NdnContentObjectHeader> > m_cacheHitsTrace; ///< @brief trace of cache hits |
Alexander Afanasyev | 39485d8 | 2012-06-08 17:51:47 -0700 | [diff] [blame] | 161 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 162 | TracedCallback<Ptr<const NdnInterestHeader> > 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& |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 166 | operator<< (std::ostream &os, const NdnContentStore &cs) |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 174 | #endif // NDN_CONTENT_STORE_H |