blob: 941b079952d6634f1077db970b8e230bc622e1e6 [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
21#ifndef _CCNX_PIT_H_
22#define _CCNX_PIT_H_
23
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 Afanasyeva98cdd22011-08-29 17:32:37 -070028#include "ccnx-pit-entry.h"
29
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070030namespace ns3 {
31
32class Ccnx;
33class CcnxFace;
34class CcnxContentObjectHeader;
35class CcnxInterestHeader;
36
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037////////////////////////////////////////////////////////////////////////
38////////////////////////////////////////////////////////////////////////
39
40/**
41 * \ingroup ccnx
42 * \brief Class implementing Pending Interests Table
43 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070044class CcnxPit : public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070045{
46public:
47 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070048 * \brief Interface ID
49 *
50 * \return interface ID
51 */
52 static TypeId GetTypeId ();
53
54 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070055 * \brief PIT constructor
56 */
57 CcnxPit ();
58
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080059 /**
60 * \brief Destructor
61 */
62 virtual ~CcnxPit ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -070063
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070064 /**
65 * \brief Find corresponding PIT entry for the given content name
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070066 *
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 Afanasyeva98cdd22011-08-29 17:32:37 -070071 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070072 * \returns smart pointer to PIT entry. If record not found,
73 * returns 0
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070074 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070075 virtual Ptr<CcnxPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070076 Lookup (const CcnxContentObjectHeader &header) = 0;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070077
78 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070079 * \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 Afanasyeva98cdd22011-08-29 17:32:37 -070083 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070084 virtual Ptr<CcnxPitEntry>
85 Lookup (const CcnxInterestHeader &header) = 0;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070086
87 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070088 * @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 Afanasyev11f7bb42012-07-09 17:06:30 -070095 virtual Ptr<CcnxPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070096 Create (Ptr<const CcnxInterestHeader> header) = 0;
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070097
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 Afanasyev11f7bb42012-07-09 17:06:30 -0700105 virtual void
106 MarkErased (Ptr<CcnxPitEntry> entry) = 0;
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 Afanasyevf1e013f2012-07-11 17:59:40 -0700116 /**
117 * @brief Get number of entries in PIT
118 */
119 virtual uint32_t
120 GetSize () const = 0;
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700121
122 /**
123 * @brief Return first element of FIB (no order guaranteed)
124 */
125 virtual Ptr<CcnxPitEntry>
126 Begin () = 0;
127
128 /**
129 * @brief Return item next after last (no order guaranteed)
130 */
131 virtual Ptr<CcnxPitEntry>
132 End () = 0;
133
134 /**
135 * @brief Advance the iterator
136 */
137 virtual Ptr<CcnxPitEntry>
138 Next (Ptr<CcnxPitEntry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700139
140 ////////////////////////////////////////////////////////////////////////////
141 ////////////////////////////////////////////////////////////////////////////
142 ////////////////////////////////////////////////////////////////////////////
143
144 /**
145 * @brief Static call to cheat python bindings
146 */
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700147 static inline Ptr<CcnxPit>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700148 GetCcnxPit (Ptr<Object> node);
149
150 ////////////////////////////////////////////////////////////////////////////
151 ////////////////////////////////////////////////////////////////////////////
152 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700153
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800154private:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700155 // /**
156 // * @brief Remove expired records from PIT
157 // */
158 // void
159 // CleanExpired ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700160
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700161 // /**
162 // * \brief Set cleanup timeout
163 // *
164 // * Side effect: current clean up even (if any) will be cancelled and a new event started
165 // *
166 // * \param timeout cleanup timeout
167 // */
168 // void
169 // SetCleanupTimeout (const Time &timeout);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700170
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700171 // /**
172 // * \brief Get cleanup timeout
173 // *
174 // * \returns cleanup timeout
175 // */
176 // Time
177 // GetCleanupTimeout () const;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700178
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700179protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800180 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800181 Time m_PitEntryPruningTimout;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700182};
183
184///////////////////////////////////////////////////////////////////////////////
185///////////////////////////////////////////////////////////////////////////////
186
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700187inline std::ostream&
188operator<< (std::ostream& os, const CcnxPit &pit)
189{
190 pit.Print (os);
191 return os;
192}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700193
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700194inline Ptr<CcnxPit>
195CcnxPit::GetCcnxPit (Ptr<Object> node)
196{
197 return node->GetObject<CcnxPit> ();
198}
199
200
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700201} // namespace ns3
202
203#endif /* CCNX_PIT_H */