blob: 059786325f6f5686327d5a44def3963827505605 [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 Afanasyev30f60e32012-07-10 14:21:16 -0700116 // template<class A,class M>
117 // void
118 // modify (A, M)
119 // {
120 // ;
121 // }
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700122
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700123 // template<class A>
124 // void
125 // erase (A)
126 // {
127 // ;
128 // }
129
130 /**
131 * @brief Return first element of FIB (no order guaranteed)
132 */
133 virtual Ptr<CcnxPitEntry>
134 Begin () = 0;
135
136 /**
137 * @brief Return item next after last (no order guaranteed)
138 */
139 virtual Ptr<CcnxPitEntry>
140 End () = 0;
141
142 /**
143 * @brief Advance the iterator
144 */
145 virtual Ptr<CcnxPitEntry>
146 Next (Ptr<CcnxPitEntry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700147
148 ////////////////////////////////////////////////////////////////////////////
149 ////////////////////////////////////////////////////////////////////////////
150 ////////////////////////////////////////////////////////////////////////////
151
152 /**
153 * @brief Static call to cheat python bindings
154 */
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700155 static inline Ptr<CcnxPit>
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700156 GetCcnxPit (Ptr<Object> node);
157
158 ////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////
160 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700161
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800162protected:
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700163 virtual void
164 DoCleanExpired () = 0;
165
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800166private:
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700167 /**
168 * @brief Remove expired records from PIT
169 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700170 void
171 CleanExpired ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700172
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700173 /**
174 * \brief Set cleanup timeout
175 *
176 * Side effect: current clean up even (if any) will be cancelled and a new event started
177 *
178 * \param timeout cleanup timeout
179 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700180 void
181 SetCleanupTimeout (const Time &timeout);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700182
183 /**
184 * \brief Get cleanup timeout
185 *
186 * \returns cleanup timeout
187 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700188 Time
189 GetCleanupTimeout () const;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700190
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700191protected:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700192 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
193 EventId m_cleanupEvent; ///< \brief Cleanup event
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800194
195 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800196 Time m_PitEntryPruningTimout;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700197};
198
199///////////////////////////////////////////////////////////////////////////////
200///////////////////////////////////////////////////////////////////////////////
201
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700202inline std::ostream&
203operator<< (std::ostream& os, const CcnxPit &pit)
204{
205 pit.Print (os);
206 return os;
207}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700208
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700209inline Ptr<CcnxPit>
210CcnxPit::GetCcnxPit (Ptr<Object> node)
211{
212 return node->GetObject<CcnxPit> ();
213}
214
215
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700216} // namespace ns3
217
218#endif /* CCNX_PIT_H */