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 | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 27 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 28 | |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 29 | namespace ns3 |
| 30 | { |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 31 | |
| 32 | class Packet; |
| 33 | class CcnxContentObjectHeader; |
| 34 | class CcnxInterestHeader; |
| 35 | class CcnxNameComponents; |
| 36 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 37 | /** |
| 38 | * \ingroup ccnx |
| 39 | * \brief NDN content store entry |
| 40 | * |
| 41 | * Content store entry stores separately pseudo header and content of |
| 42 | * ContentObject packet. It is responsibility of the caller to |
| 43 | * construct a fully formed CcnxPacket by calling Copy(), AddHeader(), |
| 44 | * AddTail() on the packet received by GetPacket() method. |
| 45 | * |
| 46 | * GetFullyFormedCcnxPacket method provided as a convenience |
| 47 | */ |
| 48 | class CcnxContentStoreEntry |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 49 | { |
| 50 | public: |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 51 | /** |
| 52 | * \brief Construct content store entry |
| 53 | * |
| 54 | * \param header Parsed CcnxContentObject header |
| 55 | * \param packet Original CCNx packet |
| 56 | * |
| 57 | * The constructor will make a copy of the supplied packet and calls |
| 58 | * RemoveHeader and RemoveTail on the copy. |
| 59 | */ |
| 60 | CcnxContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
| 61 | |
| 62 | /** |
| 63 | * \brief Get prefix of the stored entry |
| 64 | * \returns prefix of the stored entry |
| 65 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 66 | const CcnxNameComponents& |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 67 | GetName () const; |
| 68 | |
| 69 | /** |
| 70 | * \brief Get CcnxContentObjectHeader of the stored entry |
| 71 | * \returns CcnxContentObjectHeader of the stored entry |
| 72 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 73 | Ptr<const CcnxContentObjectHeader> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 74 | GetHeader () const; |
| 75 | |
| 76 | /** |
| 77 | * \brief Get content of the stored entry |
| 78 | * \returns content of the stored entry |
| 79 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 80 | Ptr<const Packet> |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 81 | GetPacket () const; |
| 82 | |
| 83 | /** |
| 84 | * \brief Convenience method to create a fully formed CCNx packet from stored header and content |
| 85 | * \returns A read-write copy of the packet with CcnxContentObjectHeader and CcxnContentObjectTail |
| 86 | */ |
| 87 | Ptr<Packet> |
| 88 | GetFullyFormedCcnxPacket () const; |
| 89 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 90 | private: |
| 91 | Ptr<CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader |
| 92 | Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * \ingroup ccnx |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 98 | * \brief Base class for NDN content store |
| 99 | * |
| 100 | * Particular implementations should implement Lookup, Add, and Print methods |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 101 | */ |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 102 | class CcnxContentStore : public Object |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 103 | { |
| 104 | public: |
| 105 | /** |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 106 | * \brief Interface ID |
| 107 | * |
| 108 | * \return interface ID |
| 109 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 110 | static |
| 111 | TypeId GetTypeId (); |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 114 | * @brief Virtual destructor |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 115 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 116 | virtual ~CcnxContentStore (); |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 118 | /** |
| 119 | * \brief Find corresponding CS entry for the given interest |
| 120 | * |
| 121 | * \param interest Interest for which matching content store entry |
| 122 | * will be searched |
| 123 | * |
| 124 | * If an entry is found, it is promoted to the top of most recent |
| 125 | * used entries index, \see m_contentStore |
| 126 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 127 | virtual boost::tuple<Ptr<Packet>, Ptr<const CcnxContentObjectHeader>, Ptr<const Packet> > |
| 128 | Lookup (Ptr<const CcnxInterestHeader> interest) = 0; |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 129 | |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 130 | /** |
| 131 | * \brief Add a new content to the content store. |
| 132 | * |
| 133 | * \param header Fully parsed CcnxContentObjectHeader |
| 134 | * \param packet Fully formed CCNx packet to add to content store |
| 135 | * (will be copied and stripped down of headers) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 136 | * @returns true if an existing entry was updated, false otherwise |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 137 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 138 | virtual bool |
| 139 | Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet) = 0; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 141 | // /** |
| 142 | // * \brief Add a new content to the content store. |
| 143 | // * |
| 144 | // * \param header Interest header for which an entry should be removed |
| 145 | // * @returns true if an existing entry was removed, false otherwise |
| 146 | // */ |
| 147 | // virtual bool |
| 148 | // Remove (Ptr<CcnxInterestHeader> header) = 0; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
| 151 | * \brief Print out content store entries |
| 152 | * |
| 153 | * Debug build provides dumping of content store entries in |
| 154 | * lexicographical order of corresponding prefixes |
| 155 | * |
| 156 | * Release build dumps everything in MRU order |
| 157 | */ |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 158 | virtual void |
| 159 | Print () const = 0; |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 160 | }; |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 161 | |
| 162 | inline std::ostream& |
| 163 | operator<< (std::ostream &os, const CcnxContentStore &cs) |
| 164 | { |
| 165 | cs.Print (); |
| 166 | return os; |
Ilya Moiseenko | 1c570bc | 2011-08-17 19:18:02 -0700 | [diff] [blame] | 167 | } |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame^] | 169 | } // namespace ns3 |
Alexander Afanasyev | 070aa48 | 2011-08-20 00:38:25 -0700 | [diff] [blame] | 170 | |
| 171 | #endif // CCNX_CONTENT_STORE_H |