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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef _NDN_PIT_H_ |
| 22 | #define _NDN_PIT_H_ |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 28 | #include "ndn-pit-entry.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 30 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 31 | namespace ndn { |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 33 | /** |
| 34 | * @ingroup ndn |
| 35 | * @defgroup ndn-pit PIT |
| 36 | */ |
| 37 | |
| 38 | /** |
| 39 | * @ingroup ndn-pit |
| 40 | * @brief Namespace for PIT operations |
| 41 | */ |
| 42 | namespace pit { |
| 43 | } |
| 44 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 45 | class L3Protocol; |
| 46 | class Face; |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 47 | class Data; |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 48 | class Interest; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 50 | typedef Interest InterestHeader; |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 51 | typedef Data DataHeader; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 53 | //////////////////////////////////////////////////////////////////////// |
| 54 | //////////////////////////////////////////////////////////////////////// |
| 55 | |
| 56 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 57 | * @ingroup ndn-pit |
| 58 | * @brief Class implementing Pending Interests Table |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 59 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 60 | class Pit : public Object |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 61 | { |
| 62 | public: |
| 63 | /** |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 64 | * \brief Interface ID |
| 65 | * |
| 66 | * \return interface ID |
| 67 | */ |
| 68 | static TypeId GetTypeId (); |
| 69 | |
| 70 | /** |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 71 | * \brief PIT constructor |
| 72 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 73 | Pit (); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 75 | /** |
| 76 | * \brief Destructor |
| 77 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 78 | virtual ~Pit (); |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 79 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 80 | /** |
| 81 | * \brief Find corresponding PIT entry for the given content name |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 82 | * |
| 83 | * Not that this call should be repeated enough times until it return 0. |
| 84 | * This way all records with shorter or equal prefix as in content object will be found |
| 85 | * and satisfied. |
| 86 | * |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 87 | * \param prefix Prefix for which to lookup the entry |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 88 | * \returns smart pointer to PIT entry. If record not found, |
| 89 | * returns 0 |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 90 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 91 | virtual Ptr<pit::Entry> |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 92 | Lookup (const Data &header) = 0; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 95 | * \brief Find a PIT entry for the given content interest |
| 96 | * \param header parsed interest header |
| 97 | * \returns iterator to Pit entry. If record not found, |
| 98 | * return end() iterator |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 99 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 100 | virtual Ptr<pit::Entry> |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 101 | Lookup (const Interest &header) = 0; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
Alexander Afanasyev | e5a8b5a | 2013-03-15 15:15:26 -0700 | [diff] [blame] | 104 | * @brief Get PIT entry for the prefix (exact match) |
| 105 | * |
| 106 | * @param prefix Name for PIT entry |
| 107 | * @returns If entry is found, a valid iterator (Ptr<pit::Entry>) will be returned. Otherwise End () (==0) |
| 108 | */ |
| 109 | virtual Ptr<pit::Entry> |
| 110 | Find (const Name &prefix) = 0; |
| 111 | |
| 112 | /** |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 113 | * @brief Creates a PIT entry for the given interest |
| 114 | * @param header parsed interest header |
| 115 | * @returns iterator to Pit entry. If record could not be created (e.g., limit reached), |
| 116 | * return end() iterator |
| 117 | * |
| 118 | * Note. This call assumes that the entry does not exist (i.e., there was a Lookup call before) |
| 119 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 120 | virtual Ptr<pit::Entry> |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 121 | Create (Ptr<const Interest> header) = 0; |
Alexander Afanasyev | cdeefb4 | 2013-05-01 16:04:53 -0700 | [diff] [blame] | 122 | |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 123 | /** |
| 124 | * @brief Mark PIT entry deleted |
| 125 | * @param entry PIT entry |
| 126 | * |
| 127 | * Effectively, this method removes all incoming/outgoing faces and set |
| 128 | * lifetime +m_PitEntryDefaultLifetime from Now () |
| 129 | */ |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 130 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 131 | MarkErased (Ptr<pit::Entry> entry) = 0; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * @brief Print out PIT contents for debugging purposes |
| 135 | * |
| 136 | * Note that there is no definite order in which entries are printed out |
| 137 | */ |
| 138 | virtual void |
| 139 | Print (std::ostream &os) const = 0; |
| 140 | |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 141 | /** |
| 142 | * @brief Get number of entries in PIT |
| 143 | */ |
| 144 | virtual uint32_t |
| 145 | GetSize () const = 0; |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * @brief Return first element of FIB (no order guaranteed) |
| 149 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 150 | virtual Ptr<pit::Entry> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 151 | Begin () = 0; |
| 152 | |
| 153 | /** |
| 154 | * @brief Return item next after last (no order guaranteed) |
| 155 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | virtual Ptr<pit::Entry> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 157 | End () = 0; |
| 158 | |
| 159 | /** |
| 160 | * @brief Advance the iterator |
| 161 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 162 | virtual Ptr<pit::Entry> |
| 163 | Next (Ptr<pit::Entry>) = 0; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 164 | |
| 165 | //////////////////////////////////////////////////////////////////////////// |
| 166 | //////////////////////////////////////////////////////////////////////////// |
| 167 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | cdeefb4 | 2013-05-01 16:04:53 -0700 | [diff] [blame] | 168 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 169 | /** |
| 170 | * @brief Static call to cheat python bindings |
| 171 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 172 | static inline Ptr<Pit> |
| 173 | GetPit (Ptr<Object> node); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 174 | |
Alexander Afanasyev | cdeefb4 | 2013-05-01 16:04:53 -0700 | [diff] [blame] | 175 | /** |
| 176 | * @brief Get maximum PIT entry lifetime |
| 177 | */ |
| 178 | inline const Time& |
| 179 | GetMaxPitEntryLifetime () const; |
| 180 | |
| 181 | /** |
| 182 | * @brief Set maximum PIT entry lifetime |
| 183 | */ |
| 184 | inline void |
| 185 | SetMaxPitEntryLifetime (const Time &maxLifetime); |
| 186 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 187 | protected: |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 188 | // configuration variables. Check implementation of GetTypeId for more details |
Alexander Afanasyev | cdeefb4 | 2013-05-01 16:04:53 -0700 | [diff] [blame] | 189 | Time m_PitEntryPruningTimout; |
| 190 | |
| 191 | Time m_maxPitEntryLifetime; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | /////////////////////////////////////////////////////////////////////////////// |
| 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 197 | inline std::ostream& |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 198 | operator<< (std::ostream& os, const Pit &pit) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 199 | { |
| 200 | pit.Print (os); |
| 201 | return os; |
| 202 | } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 203 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 204 | inline Ptr<Pit> |
| 205 | Pit::GetPit (Ptr<Object> node) |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 206 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 207 | return node->GetObject<Pit> (); |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Alexander Afanasyev | cdeefb4 | 2013-05-01 16:04:53 -0700 | [diff] [blame] | 210 | inline const Time& |
| 211 | Pit::GetMaxPitEntryLifetime () const |
| 212 | { |
| 213 | return m_maxPitEntryLifetime; |
| 214 | } |
| 215 | |
| 216 | inline void |
| 217 | Pit::SetMaxPitEntryLifetime (const Time &maxLifetime) |
| 218 | { |
| 219 | m_maxPitEntryLifetime = maxLifetime; |
| 220 | } |
| 221 | |
| 222 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 223 | } // namespace ndn |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 224 | } // namespace ns3 |
| 225 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 226 | #endif /* NDN_PIT_H */ |