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