blob: 186f8c461cb02a9fc9cbe3a52efcb154b6195179 [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 Afanasyevf034cbd2012-06-29 14:28:31 -070092 * @brief Creates a PIT entry for the given interest
93 * @param header parsed interest header
94 * @returns iterator to Pit entry. If record could not be created (e.g., limit reached),
95 * return end() iterator
96 *
97 * Note. This call assumes that the entry does not exist (i.e., there was a Lookup call before)
98 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070099 virtual Ptr<pit::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -0700100 Create (Ptr<const Interest> header) = 0;
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700101
102 /**
103 * @brief Mark PIT entry deleted
104 * @param entry PIT entry
105 *
106 * Effectively, this method removes all incoming/outgoing faces and set
107 * lifetime +m_PitEntryDefaultLifetime from Now ()
108 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700109 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700110 MarkErased (Ptr<pit::Entry> entry) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700111
112 /**
113 * @brief Print out PIT contents for debugging purposes
114 *
115 * Note that there is no definite order in which entries are printed out
116 */
117 virtual void
118 Print (std::ostream &os) const = 0;
119
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700120 /**
121 * @brief Get number of entries in PIT
122 */
123 virtual uint32_t
124 GetSize () const = 0;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700125
126 /**
127 * @brief Return first element of FIB (no order guaranteed)
128 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700129 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700130 Begin () = 0;
131
132 /**
133 * @brief Return item next after last (no order guaranteed)
134 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700135 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700136 End () = 0;
137
138 /**
139 * @brief Advance the iterator
140 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700141 virtual Ptr<pit::Entry>
142 Next (Ptr<pit::Entry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700143
144 ////////////////////////////////////////////////////////////////////////////
145 ////////////////////////////////////////////////////////////////////////////
146 ////////////////////////////////////////////////////////////////////////////
147
148 /**
149 * @brief Static call to cheat python bindings
150 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700151 static inline Ptr<Pit>
152 GetPit (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700153
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700154protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800155 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800156 Time m_PitEntryPruningTimout;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700157};
158
159///////////////////////////////////////////////////////////////////////////////
160///////////////////////////////////////////////////////////////////////////////
161
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700162inline std::ostream&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700163operator<< (std::ostream& os, const Pit &pit)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700164{
165 pit.Print (os);
166 return os;
167}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700168
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169inline Ptr<Pit>
170Pit::GetPit (Ptr<Object> node)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700171{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700172 return node->GetObject<Pit> ();
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700173}
174
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700175} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700176} // namespace ns3
177
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700178#endif /* NDN_PIT_H */