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 | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 28 | #include "ccnx-pit-entry.h" |
| 29 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 30 | namespace ns3 { |
| 31 | |
| 32 | class Ccnx; |
| 33 | class CcnxFace; |
| 34 | class CcnxContentObjectHeader; |
| 35 | class CcnxInterestHeader; |
| 36 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 37 | //////////////////////////////////////////////////////////////////////// |
| 38 | //////////////////////////////////////////////////////////////////////// |
| 39 | |
| 40 | /** |
| 41 | * \ingroup ccnx |
| 42 | * \brief Class implementing Pending Interests Table |
| 43 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 44 | class CcnxPit : public Object |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 45 | { |
| 46 | public: |
| 47 | /** |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 48 | * \brief Interface ID |
| 49 | * |
| 50 | * \return interface ID |
| 51 | */ |
| 52 | static TypeId GetTypeId (); |
| 53 | |
| 54 | /** |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 55 | * \brief PIT constructor |
| 56 | */ |
| 57 | CcnxPit (); |
| 58 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 59 | /** |
| 60 | * \brief Destructor |
| 61 | */ |
| 62 | virtual ~CcnxPit (); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 64 | /** |
| 65 | * \brief Find corresponding PIT entry for the given content name |
| 66 | * \param prefix Prefix for which to lookup the entry |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 67 | * \returns iterator to Pit entry. If record not found, |
| 68 | * return end() iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 69 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 70 | virtual Ptr<CcnxPitEntry> |
| 71 | Lookup (const CcnxContentObjectHeader &header) const = 0; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 74 | * \brief Find a PIT entry for the given content interest |
| 75 | * \param header parsed interest header |
| 76 | * \returns iterator to Pit entry. If record not found, |
| 77 | * return end() iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 78 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 79 | virtual Ptr<CcnxPitEntry> |
| 80 | Lookup (const CcnxInterestHeader &header) = 0; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 83 | * @brief Check if the Interest carries an existent nonce. |
| 84 | * If not, nonce will be added to the list of known nonces |
| 85 | * @returns true if interest is duplicate (carries an existent nonce), false otherwise |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 86 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 87 | virtual bool |
| 88 | CheckIfDuplicate (Ptr<CcnxPitEntry> entry, const CcnxInterestHeader &header) = 0; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 90 | /** |
| 91 | * @brief Creates a PIT entry for the given interest |
| 92 | * @param header parsed interest header |
| 93 | * @returns iterator to Pit entry. If record could not be created (e.g., limit reached), |
| 94 | * return end() iterator |
| 95 | * |
| 96 | * Note. This call assumes that the entry does not exist (i.e., there was a Lookup call before) |
| 97 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 98 | virtual Ptr<CcnxPitEntry> |
| 99 | Create (const CcnxInterestHeader &header) = 0; |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
| 102 | * @brief Mark PIT entry deleted |
| 103 | * @param entry PIT entry |
| 104 | * |
| 105 | * Effectively, this method removes all incoming/outgoing faces and set |
| 106 | * lifetime +m_PitEntryDefaultLifetime from Now () |
| 107 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 108 | virtual void |
| 109 | MarkErased (Ptr<CcnxPitEntry> entry) = 0; |
| 110 | |
| 111 | /** |
| 112 | * @brief Print out PIT contents for debugging purposes |
| 113 | * |
| 114 | * Note that there is no definite order in which entries are printed out |
| 115 | */ |
| 116 | virtual void |
| 117 | Print (std::ostream &os) const = 0; |
| 118 | |
| 119 | template<class A,class M> |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 120 | void |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 121 | modify (A, M) |
| 122 | { |
| 123 | ; |
| 124 | } |
| 125 | |
| 126 | template<class A> |
| 127 | void |
| 128 | erase (A) |
| 129 | { |
| 130 | ; |
| 131 | } |
| 132 | |
| 133 | //////////////////////////////////////////////////////////////////////////// |
| 134 | //////////////////////////////////////////////////////////////////////////// |
| 135 | //////////////////////////////////////////////////////////////////////////// |
| 136 | |
| 137 | /** |
| 138 | * @brief Static call to cheat python bindings |
| 139 | */ |
| 140 | static inline Ptr<CcnxFib> |
| 141 | GetCcnxPit (Ptr<Object> node); |
| 142 | |
| 143 | //////////////////////////////////////////////////////////////////////////// |
| 144 | //////////////////////////////////////////////////////////////////////////// |
| 145 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 146 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 147 | protected: |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 148 | virtual void |
| 149 | DoCleanExpired () = 0; |
| 150 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 151 | private: |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 152 | /** |
| 153 | * @brief Remove expired records from PIT |
| 154 | */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 155 | void |
| 156 | CleanExpired (); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 157 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 158 | /** |
| 159 | * \brief Set cleanup timeout |
| 160 | * |
| 161 | * Side effect: current clean up even (if any) will be cancelled and a new event started |
| 162 | * |
| 163 | * \param timeout cleanup timeout |
| 164 | */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 165 | void |
| 166 | SetCleanupTimeout (const Time &timeout); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * \brief Get cleanup timeout |
| 170 | * |
| 171 | * \returns cleanup timeout |
| 172 | */ |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 173 | Time |
| 174 | GetCleanupTimeout () const; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 175 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 176 | protected: |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 177 | Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working |
| 178 | EventId m_cleanupEvent; ///< \brief Cleanup event |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 179 | |
| 180 | // configuration variables. Check implementation of GetTypeId for more details |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 181 | Time m_PitEntryPruningTimout; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 182 | Time m_PitEntryDefaultLifetime; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | /////////////////////////////////////////////////////////////////////////////// |
| 186 | /////////////////////////////////////////////////////////////////////////////// |
| 187 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 188 | inline std::ostream& |
| 189 | operator<< (std::ostream& os, const CcnxPit &pit) |
| 190 | { |
| 191 | pit.Print (os); |
| 192 | return os; |
| 193 | } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 194 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 195 | } // namespace ns3 |
| 196 | |
| 197 | #endif /* CCNX_PIT_H */ |