blob: 4c07fd2a23b7643d41eab98871f003583ecd2a1a [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 Afanasyev2b4c9472012-08-09 15:00:38 -070033class L3Protocol;
34class Face;
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070035class ContentObject;
36class Interest;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070038typedef Interest InterestHeader;
39typedef ContentObject ContentObjectHeader;
40
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070041////////////////////////////////////////////////////////////////////////
42////////////////////////////////////////////////////////////////////////
43
44/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070045 * \ingroup ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070046 * \brief Class implementing Pending Interests Table
47 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048class Pit : public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070049{
50public:
51 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070052 * \brief Interface ID
53 *
54 * \return interface ID
55 */
56 static TypeId GetTypeId ();
57
58 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070059 * \brief PIT constructor
60 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061 Pit ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070062
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080063 /**
64 * \brief Destructor
65 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070066 virtual ~Pit ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -070067
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070068 /**
69 * \brief Find corresponding PIT entry for the given content name
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070070 *
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 Afanasyeva98cdd22011-08-29 17:32:37 -070075 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070076 * \returns smart pointer to PIT entry. If record not found,
77 * returns 0
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070078 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070080 Lookup (const ContentObject &header) = 0;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070081
82 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070083 * \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 Afanasyeva98cdd22011-08-29 17:32:37 -070087 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070089 Lookup (const Interest &header) = 0;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070090
91 /**
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070092 * @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 Afanasyevf034cbd2012-06-29 14:28:31 -0700101 * @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 Afanasyev2b4c9472012-08-09 15:00:38 -0700108 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700109 Create (Ptr<const Interest> header) = 0;
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700110
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700111 /**
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700118 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 MarkErased (Ptr<pit::Entry> entry) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700120
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 Afanasyevf1e013f2012-07-11 17:59:40 -0700129 /**
130 * @brief Get number of entries in PIT
131 */
132 virtual uint32_t
133 GetSize () const = 0;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700134
135 /**
136 * @brief Return first element of FIB (no order guaranteed)
137 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700139 Begin () = 0;
140
141 /**
142 * @brief Return item next after last (no order guaranteed)
143 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700145 End () = 0;
146
147 /**
148 * @brief Advance the iterator
149 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700150 virtual Ptr<pit::Entry>
151 Next (Ptr<pit::Entry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700152
153 ////////////////////////////////////////////////////////////////////////////
154 ////////////////////////////////////////////////////////////////////////////
155 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700156
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700157 /**
158 * @brief Static call to cheat python bindings
159 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160 static inline Ptr<Pit>
161 GetPit (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700162
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700163 /**
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700175protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800176 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700177 Time m_PitEntryPruningTimout;
178
179 Time m_maxPitEntryLifetime;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700180};
181
182///////////////////////////////////////////////////////////////////////////////
183///////////////////////////////////////////////////////////////////////////////
184
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700185inline std::ostream&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700186operator<< (std::ostream& os, const Pit &pit)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700187{
188 pit.Print (os);
189 return os;
190}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700191
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700192inline Ptr<Pit>
193Pit::GetPit (Ptr<Object> node)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700194{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700195 return node->GetObject<Pit> ();
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700196}
197
Alexander Afanasyevcdeefb42013-05-01 16:04:53 -0700198inline const Time&
199Pit::GetMaxPitEntryLifetime () const
200{
201 return m_maxPitEntryLifetime;
202}
203
204inline void
205Pit::SetMaxPitEntryLifetime (const Time &maxLifetime)
206{
207 m_maxPitEntryLifetime = maxLifetime;
208}
209
210
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700211} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700212} // namespace ns3
213
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700214#endif /* NDN_PIT_H */