Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #ifndef _CCNX_PIT_H_ |
| 22 | #define _CCNX_PIT_H_ |
| 23 | |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 24 | #include "ns3/object.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 25 | #include "ns3/nstime.h" |
| 26 | #include "ns3/event-id.h" |
| 27 | |
Alexander Afanasyev | 161a5c4 | 2012-04-17 15:14:04 -0700 | [diff] [blame] | 28 | #include "ccnx-name-components-hash-helper.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 29 | #include "ccnx-pit-entry.h" |
| 30 | |
| 31 | #include <boost/multi_index_container.hpp> |
| 32 | #include <boost/multi_index/tag.hpp> |
| 33 | #include <boost/multi_index/ordered_index.hpp> |
| 34 | #include <boost/multi_index/composite_key.hpp> |
| 35 | #include <boost/multi_index/hashed_index.hpp> |
| 36 | #include <boost/multi_index/member.hpp> |
| 37 | #include <boost/multi_index/mem_fun.hpp> |
Ilya Moiseenko | 1c73cb5 | 2011-10-28 13:13:11 -0700 | [diff] [blame] | 38 | #include <map> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 39 | #include <iostream> |
Ilya Moiseenko | 1c73cb5 | 2011-10-28 13:13:11 -0700 | [diff] [blame] | 40 | #include <algorithm> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 41 | #include <boost/tuple/tuple.hpp> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 42 | |
| 43 | namespace ns3 { |
| 44 | |
| 45 | class Ccnx; |
| 46 | class CcnxFace; |
| 47 | class CcnxContentObjectHeader; |
| 48 | class CcnxInterestHeader; |
| 49 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 50 | /// @cond include_hidden |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 51 | /** |
| 52 | * \ingroup ccnx |
| 53 | * \private |
| 54 | * \brief Private namespace for CCNx PIT implementation |
| 55 | */ |
| 56 | namespace __ccnx_private |
| 57 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 58 | // class i_prefix{}; ///< tag for prefix hash |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 59 | class i_timestamp {}; ///< tag for timestamp-ordered records (for cleanup optimization) |
| 60 | }; |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 61 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * \ingroup ccnx |
| 65 | * \brief Typedef for RIT container implemented as a Boost.MultiIndex container |
| 66 | * |
| 67 | * - First index (tag<i_prefix>) is a unique hash index based on |
| 68 | * prefixes |
| 69 | * - Second index (tag<i_timestamp>) is a sequenced index based on |
| 70 | * arrival order (for clean-up optimizations) |
| 71 | * |
| 72 | * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library |
| 73 | */ |
| 74 | struct CcnxPitEntryContainer |
| 75 | { |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 76 | /// @cond include_hidden |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 77 | typedef |
| 78 | boost::multi_index::multi_index_container< |
| 79 | CcnxPitEntry, |
| 80 | boost::multi_index::indexed_by< |
| 81 | // indexed by hash |
| 82 | boost::multi_index::hashed_unique< |
| 83 | boost::multi_index::tag<__ccnx_private::i_prefix>, |
| 84 | boost::multi_index::const_mem_fun<CcnxPitEntry, const CcnxNameComponents&, &CcnxPitEntry::GetPrefix>, |
| 85 | CcnxPrefixHash |
| 86 | >, |
| 87 | // sequenced to implement MRU |
Alexander Afanasyev | d76f4aa | 2011-12-15 21:30:16 -0800 | [diff] [blame] | 88 | boost::multi_index::ordered_non_unique< |
| 89 | boost::multi_index::tag<__ccnx_private::i_timestamp>, |
| 90 | boost::multi_index::member<CcnxPitEntry, Time, &CcnxPitEntry::m_expireTime> |
| 91 | > |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 92 | > |
| 93 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 94 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 97 | //////////////////////////////////////////////////////////////////////// |
| 98 | //////////////////////////////////////////////////////////////////////// |
| 99 | |
| 100 | /** |
| 101 | * \ingroup ccnx |
| 102 | * \brief Class implementing Pending Interests Table |
| 103 | */ |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 104 | class CcnxPit : public CcnxPitEntryContainer::type, public Object |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -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 | */ |
| 112 | static TypeId GetTypeId (); |
| 113 | |
| 114 | /** |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 115 | * \brief PIT constructor |
| 116 | */ |
| 117 | CcnxPit (); |
| 118 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 119 | /** |
| 120 | * \brief Destructor |
| 121 | */ |
| 122 | virtual ~CcnxPit (); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 124 | /** |
| 125 | * \brief Find corresponding PIT entry for the given content name |
| 126 | * \param prefix Prefix for which to lookup the entry |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 127 | * \returns iterator to Pit entry. If record not found, |
| 128 | * return end() iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 129 | */ |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 130 | iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 131 | Lookup (const CcnxContentObjectHeader &header) const; |
| 132 | |
| 133 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 134 | * \brief Find a PIT entry for the given content interest |
| 135 | * \param header parsed interest header |
| 136 | * \returns iterator to Pit entry. If record not found, |
| 137 | * return end() iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 138 | */ |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 139 | iterator |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 140 | Lookup (const CcnxInterestHeader &header); |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 143 | * @brief Check if the Interest carries an existent nonce. |
| 144 | * If not, nonce will be added to the list of known nonces |
| 145 | * @returns true if interest is duplicate (carries an existent nonce), false otherwise |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 146 | */ |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 147 | bool |
| 148 | CheckIfDuplicate (iterator entry, const CcnxInterestHeader &header); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 150 | /** |
| 151 | * @brief Creates a PIT entry for the given interest |
| 152 | * @param header parsed interest header |
| 153 | * @returns iterator to Pit entry. If record could not be created (e.g., limit reached), |
| 154 | * return end() iterator |
| 155 | * |
| 156 | * Note. This call assumes that the entry does not exist (i.e., there was a Lookup call before) |
| 157 | */ |
| 158 | iterator |
| 159 | Create (const CcnxInterestHeader &header); |
| 160 | |
| 161 | /** |
| 162 | * @brief Mark PIT entry deleted |
| 163 | * @param entry PIT entry |
| 164 | * |
| 165 | * Effectively, this method removes all incoming/outgoing faces and set |
| 166 | * lifetime +m_PitEntryDefaultLifetime from Now () |
| 167 | */ |
| 168 | void |
| 169 | MarkErased (iterator entry); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 170 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 171 | protected: |
| 172 | // inherited from Object class |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 173 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 174 | virtual void DoDispose (); ///< @brief Do cleanup |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 175 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 176 | private: |
| 177 | /** \brief Remove expired records from PIT */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 178 | void |
| 179 | CleanExpired (); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 181 | /** |
| 182 | * \brief Set cleanup timeout |
| 183 | * |
| 184 | * Side effect: current clean up even (if any) will be cancelled and a new event started |
| 185 | * |
| 186 | * \param timeout cleanup timeout |
| 187 | */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 188 | void |
| 189 | SetCleanupTimeout (const Time &timeout); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * \brief Get cleanup timeout |
| 193 | * |
| 194 | * \returns cleanup timeout |
| 195 | */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 196 | Time |
| 197 | GetCleanupTimeout () const; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 199 | friend std::ostream& |
| 200 | operator<< (std::ostream& os, const CcnxPit &fib); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 201 | |
| 202 | private: |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 203 | Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working |
| 204 | EventId m_cleanupEvent; ///< \brief Cleanup event |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 205 | |
| 206 | // configuration variables. Check implementation of GetTypeId for more details |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 207 | Time m_PitEntryPruningTimout; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 208 | Time m_PitEntryDefaultLifetime; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 209 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 210 | uint32_t m_maxSize; |
| 211 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 212 | Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | /////////////////////////////////////////////////////////////////////////////// |
| 216 | /////////////////////////////////////////////////////////////////////////////// |
| 217 | |
Alexander Afanasyev | a95b739 | 2012-03-09 10:54:10 -0800 | [diff] [blame] | 218 | std::ostream& operator<< (std::ostream& os, const CcnxPit &pit); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 219 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 220 | } // namespace ns3 |
| 221 | |
| 222 | #endif /* CCNX_PIT_H */ |