Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 1 | /* -*- 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_PRODUCER_H |
| 22 | #define CCNX_PRODUCER_H |
| 23 | |
| 24 | #include "ns3/application.h" |
| 25 | #include "ns3/log.h" |
| 26 | #include "ns3/random-variable.h" |
| 27 | #include "ns3/nstime.h" |
| 28 | #include "ns3/event-id.h" |
| 29 | #include "ns3/ptr.h" |
| 30 | #include "ns3/simulator.h" |
| 31 | #include "ns3/ccnx-interest-header.h" |
| 32 | #include "ns3/ccnx-local-face.h" |
| 33 | #include "ns3/ccnx-name-components.h" |
| 34 | #include "ns3/packet.h" |
| 35 | #include "ns3/boolean.h" |
| 36 | #include "ns3/integer.h" |
| 37 | #include "ns3/uinteger.h" |
| 38 | #include "ns3/random-variable.h" |
| 39 | #include <limits> |
| 40 | #include "ns3/pointer.h" |
| 41 | #include "ns3/traced-callback.h" |
| 42 | #include "ns3/ccnx-header-helper.h" |
| 43 | |
| 44 | #include "ns3/packet.h" |
| 45 | #include "ns3/header.h" |
| 46 | #include "ns3/ccnx.h" |
| 47 | #include "ns3/ccnx-content-object-header.h" |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 48 | #include "ns3/ccnx-name-components.h" |
| 49 | #include "ns3/ccnx-fib.h" |
| 50 | |
| 51 | #include <boost/multi_index_container.hpp> |
| 52 | #include <boost/multi_index/tag.hpp> |
| 53 | #include <boost/multi_index/ordered_index.hpp> |
| 54 | #include <boost/multi_index/sequenced_index.hpp> |
| 55 | #include <boost/multi_index/hashed_index.hpp> |
| 56 | #include <boost/multi_index/mem_fun.hpp> |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 57 | |
| 58 | namespace ns3 |
| 59 | { |
| 60 | |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 61 | class DataStoreEntry |
| 62 | { |
| 63 | public: |
| 64 | /** |
| 65 | * \brief Construct data store entry |
| 66 | * |
| 67 | * \param header Parsed CcnxContentObject header |
| 68 | * \param packet Original CCNx packet |
| 69 | * |
| 70 | * The constructor will make a copy of the supplied packet and calls |
| 71 | * RemoveHeader and RemoveTail on the copy. |
| 72 | */ |
| 73 | DataStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
| 74 | |
| 75 | /** |
| 76 | * \brief Get prefix of the stored entry |
| 77 | * \returns prefix of the stored entry |
| 78 | */ |
| 79 | inline const CcnxNameComponents& |
| 80 | GetName () const; |
| 81 | |
| 82 | /** |
| 83 | * \brief Get CcnxContentObjectHeader of the stored entry |
| 84 | * \returns CcnxContentObjectHeader of the stored entry |
| 85 | */ |
| 86 | inline Ptr<const CcnxContentObjectHeader> |
| 87 | GetHeader () const; |
| 88 | |
| 89 | /** |
| 90 | * \brief Get content of the stored entry |
| 91 | * \returns content of the stored entry |
| 92 | */ |
| 93 | inline Ptr<const Packet> |
| 94 | GetPacket () const; |
| 95 | |
| 96 | /** |
| 97 | * \brief Convenience method to create a fully formed CCNx packet from stored header and content |
| 98 | * \returns A read-write copy of the packet with CcnxContentObjectHeader and CcxnContentObjectTail |
| 99 | */ |
| 100 | Ptr<Packet> |
| 101 | GetFullyFormedCcnxPacket () const; |
| 102 | |
| 103 | // Copy constructor is required by the container. Though, we're |
| 104 | // storing only two pointers, so shouldn't be a problem |
| 105 | // private: |
| 106 | // CcnxContentStoreEntry (const CcnxContentStoreEntry &); ///< disabled copy constructor |
| 107 | // CcnxContentStoreEntry& operator= (const CcnxContentStoreEntry&); ///< disabled copy operator |
| 108 | |
| 109 | private: |
| 110 | //Ptr<CcnxContentObjectHeader> m_header; ///< \brief non-modifiable CcnxContentObjectHeader |
| 111 | //Ptr<Packet> m_packet; ///< \brief non-modifiable content of the ContentObject packet |
| 112 | }; |
| 113 | |
| 114 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 115 | class CcnxProducer: public Application |
| 116 | { |
| 117 | public: |
| 118 | static TypeId GetTypeId (void); |
| 119 | |
| 120 | CcnxProducer (); |
| 121 | |
| 122 | virtual ~CcnxProducer (); |
| 123 | |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 124 | //void HandlePacket (const Ptr<CcnxFace> &face, const Ptr<const Packet> &packet); |
| 125 | //uint32_t GetStoreCapacity(); |
| 126 | //void SetStoreCapacity(uint32_t capacity); |
| 127 | //void AddContentStoreEntry (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
| 128 | |
| 129 | void OnInterest(const Ptr<const CcnxInterestHeader> &interest); |
| 130 | |
| 131 | CcnxNameComponents GetPrefix() const; |
| 132 | /** |
| 133 | * \brief Add a new content to the data 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) |
| 138 | * |
| 139 | * If entry with the same prefix exists, the old entry will be |
| 140 | * promoted to the top of the MRU hash |
| 141 | */ |
| 142 | //void |
| 143 | //Add (Ptr<CcnxContentObjectHeader> header, Ptr<const Packet> packet); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 144 | |
| 145 | protected: |
| 146 | virtual void DoDispose (void); |
| 147 | private: |
| 148 | // inherited from Application base class. |
| 149 | virtual void StartApplication (void); // Called at time specified by Start |
| 150 | virtual void StopApplication (void); // Called at time specified by Stop |
| 151 | |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 152 | /** |
| 153 | * \brief Find corresponding CS entry for the given interest |
| 154 | * |
| 155 | * \param interest Interest for which matching content store entry |
| 156 | * will be searched |
| 157 | * |
| 158 | * If an entry is found, it is promoted to the top of most recent |
| 159 | * used entries index, \see m_contentStore |
| 160 | */ |
| 161 | //Ptr<Packet> |
| 162 | //Lookup (Ptr<const CcnxInterestHeader> interest); |
| 163 | |
| 164 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 165 | Ptr<Ccnx> m_ccnx; |
| 166 | Time m_offTime; |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 167 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 168 | //EventId m_sendEvent; // Eventid of pending "send packet" event |
| 169 | TypeId m_tid; |
| 170 | Ptr<CcnxLocalFace> m_face; |
| 171 | |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 172 | /*struct DataStoreContainer |
| 173 | { |
| 174 | typedef |
| 175 | boost::multi_index::multi_index_container< |
| 176 | DataStoreEntry, |
| 177 | boost::multi_index::indexed_by< |
| 178 | boost::multi_index::hashed_unique< |
| 179 | boost::multi_index::tag<__ccnx_private::i_prefix>, |
| 180 | boost::multi_index::const_mem_fun<DataStoreEntry, |
| 181 | const CcnxNameComponents&, |
| 182 | &DataStoreEntry::GetName>, |
| 183 | CcnxPrefixHash>, |
| 184 | boost::multi_index::sequenced<boost::multi_index::tag<__ccnx_private::i_mru> > |
| 185 | #ifdef _DEBUG |
| 186 | , |
| 187 | boost::multi_index::ordered_unique< |
| 188 | boost::multi_index::tag<__ccnx_private::i_ordered>, |
| 189 | boost::multi_index::const_mem_fun<DataStoreEntry, |
| 190 | const CcnxNameComponents&, |
| 191 | &CcnxContentStoreEntry::GetName> |
| 192 | > |
| 193 | #endif |
| 194 | > |
| 195 | > type; |
| 196 | };*/ |
| 197 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 198 | //helpers |
| 199 | void CancelEvents (); |
Ilya Moiseenko | b62c740 | 2011-10-28 13:02:18 -0700 | [diff] [blame] | 200 | |
| 201 | //DataStoreContainer::type m_availableData; |
| 202 | //uint32_t m_storeCapacity; |
| 203 | uint32_t m_virtualPayloadSize; |
| 204 | CcnxNameComponents m_prefix; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 205 | TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_interestsTrace; |
| 206 | TracedCallback<const Ptr<CcnxFace>&,const Ptr<const Packet>& > m_contentObjectsTrace; |
| 207 | }; |
| 208 | } |
| 209 | #endif |