blob: f8eeafb7d54161a9d221043d80206d73e6ecb9f7 [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;
35class ContentObjectHeader;
36class InterestHeader;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070038////////////////////////////////////////////////////////////////////////
39////////////////////////////////////////////////////////////////////////
40
41/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042 * \ingroup ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070043 * \brief Class implementing Pending Interests Table
44 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045class Pit : public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070046{
47public:
48 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070049 * \brief Interface ID
50 *
51 * \return interface ID
52 */
53 static TypeId GetTypeId ();
54
55 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070056 * \brief PIT constructor
57 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058 Pit ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070059
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080060 /**
61 * \brief Destructor
62 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070063 virtual ~Pit ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -070064
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070065 /**
66 * \brief Find corresponding PIT entry for the given content name
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070067 *
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 Afanasyeva98cdd22011-08-29 17:32:37 -070072 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070073 * \returns smart pointer to PIT entry. If record not found,
74 * returns 0
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070075 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076 virtual Ptr<pit::Entry>
77 Lookup (const ContentObjectHeader &header) = 0;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070078
79 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070080 * \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 Afanasyeva98cdd22011-08-29 17:32:37 -070084 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070085 virtual Ptr<pit::Entry>
86 Lookup (const InterestHeader &header) = 0;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070087
88 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070089 * @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 Afanasyev2b4c9472012-08-09 15:00:38 -070096 virtual Ptr<pit::Entry>
97 Create (Ptr<const InterestHeader> header) = 0;
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070098
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700106 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700107 MarkErased (Ptr<pit::Entry> entry) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700108
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 Afanasyevf1e013f2012-07-11 17:59:40 -0700117 /**
118 * @brief Get number of entries in PIT
119 */
120 virtual uint32_t
121 GetSize () const = 0;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700122
123 /**
124 * @brief Return first element of FIB (no order guaranteed)
125 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700126 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700127 Begin () = 0;
128
129 /**
130 * @brief Return item next after last (no order guaranteed)
131 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700132 virtual Ptr<pit::Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700133 End () = 0;
134
135 /**
136 * @brief Advance the iterator
137 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700138 virtual Ptr<pit::Entry>
139 Next (Ptr<pit::Entry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700140
141 ////////////////////////////////////////////////////////////////////////////
142 ////////////////////////////////////////////////////////////////////////////
143 ////////////////////////////////////////////////////////////////////////////
144
145 /**
146 * @brief Static call to cheat python bindings
147 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700148 static inline Ptr<Pit>
149 GetPit (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700150
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700151protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800152 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800153 Time m_PitEntryPruningTimout;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700154};
155
156///////////////////////////////////////////////////////////////////////////////
157///////////////////////////////////////////////////////////////////////////////
158
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700159inline std::ostream&
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160operator<< (std::ostream& os, const Pit &pit)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700161{
162 pit.Print (os);
163 return os;
164}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700165
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700166inline Ptr<Pit>
167Pit::GetPit (Ptr<Object> node)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700168{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169 return node->GetObject<Pit> ();
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700170}
171
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700172} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700173} // namespace ns3
174
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700175#endif /* NDN_PIT_H */