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