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