blob: 11858922ee325e0aad20ccfdc36d5982b1062ced [file] [log] [blame]
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -07001/* -*- 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 Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef _NDN_PIT_H_
22#define _NDN_PIT_H_
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070023
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070024#include "ns3/object.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070025#include "ns3/nstime.h"
26#include "ns3/event-id.h"
27
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070028#include "ndn-pit-entry.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070029
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070030namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070031namespace ndn {
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070032
Alexander Afanasyev79206512013-07-27 16:49:12 -070033/**
34 * @ingroup ndn
35 * @defgroup ndn-pit PIT
36 */
37
38/**
39 * @ingroup ndn-pit
40 * @brief Namespace for PIT operations
41 */
42namespace pit {
43}
44
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045class L3Protocol;
46class Face;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070047class Data;
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070048class Interest;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070049
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070050typedef Interest InterestHeader;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070051typedef Data DataHeader;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070052
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070053////////////////////////////////////////////////////////////////////////
54////////////////////////////////////////////////////////////////////////
55
56/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070057 * @ingroup ndn-pit
58 * @brief Class implementing Pending Interests Table
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070059 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060class Pit : public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070061{
62public:
63 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070064 * \brief Interface ID
65 *
66 * \return interface ID
67 */
68 static TypeId GetTypeId ();
69
70 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070071 * \brief PIT constructor
72 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 Pit ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070074
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080075 /**
76 * \brief Destructor
77 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070078 virtual ~Pit ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -070079
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070080 /**
81 * \brief Find corresponding PIT entry for the given content name
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070082 *
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 Afanasyeva98cdd22011-08-29 17:32:37 -070087 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070088 * \returns smart pointer to PIT entry. If record not found,
89 * returns 0
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070090 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091 virtual Ptr<pit::Entry>
Alexander Afanasyev772f51b2013-08-01 18:53:25 -070092 Lookup (const Data &header) = 0;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070093
94 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070095 * \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 Afanasyeva98cdd22011-08-29 17:32:37 -070099 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700100 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700101 Lookup (const Interest &header) = 0;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700102
103 /**
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -0700104 * @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 Afanasyevf034cbd2012-06-29 14:28:31 -0700113 * @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 Afanasyev2b4c9472012-08-09 15:00:38 -0700120 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700121 Create (Ptr<const Interest> header) = 0;
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700122
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700123 /**
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700130 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131 MarkErased (Ptr<pit::Entry> entry) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700132
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 Afanasyevf1e013f2012-07-11 17:59:40 -0700141 /**
142 * @brief Get number of entries in PIT
143 */
144 virtual uint32_t
145 GetSize () const = 0;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700146
147 /**
148 * @brief Return first element of FIB (no order guaranteed)
149 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700150 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700151 Begin () = 0;
152
153 /**
154 * @brief Return item next after last (no order guaranteed)
155 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700157 End () = 0;
158
159 /**
160 * @brief Advance the iterator
161 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700162 virtual Ptr<pit::Entry>
163 Next (Ptr<pit::Entry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700164
165 ////////////////////////////////////////////////////////////////////////////
166 ////////////////////////////////////////////////////////////////////////////
167 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700168
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700169 /**
170 * @brief Static call to cheat python bindings
171 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700172 static inline Ptr<Pit>
173 GetPit (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700174
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700175 /**
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700187protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800188 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700189 Time m_PitEntryPruningTimout;
190
191 Time m_maxPitEntryLifetime;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700192};
193
194///////////////////////////////////////////////////////////////////////////////
195///////////////////////////////////////////////////////////////////////////////
196
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700197inline std::ostream&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700198operator<< (std::ostream& os, const Pit &pit)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700199{
200 pit.Print (os);
201 return os;
202}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700203
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700204inline Ptr<Pit>
205Pit::GetPit (Ptr<Object> node)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700206{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700207 return node->GetObject<Pit> ();
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700208}
209
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700210inline const Time&
211Pit::GetMaxPitEntryLifetime () const
212{
213 return m_maxPitEntryLifetime;
214}
215
216inline void
217Pit::SetMaxPitEntryLifetime (const Time &maxLifetime)
218{
219 m_maxPitEntryLifetime = maxLifetime;
220}
221
222
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700223} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700224} // namespace ns3
225
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700226#endif /* NDN_PIT_H */