blob: b6e438828d404ed3d66652703e351580e3aa5086 [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
66 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070067 * \returns iterator to Pit entry. If record not found,
68 * return end() iterator
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070069 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070070 virtual Ptr<CcnxPitEntry>
71 Lookup (const CcnxContentObjectHeader &header) const = 0;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070072
73 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070074 * \brief Find a PIT entry for the given content interest
75 * \param header parsed interest header
76 * \returns iterator to Pit entry. If record not found,
77 * return end() iterator
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070078 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070079 virtual Ptr<CcnxPitEntry>
80 Lookup (const CcnxInterestHeader &header) = 0;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070081
82 /**
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070083 * @brief Check if the Interest carries an existent nonce.
84 * If not, nonce will be added to the list of known nonces
85 * @returns true if interest is duplicate (carries an existent nonce), false otherwise
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070086 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070087 virtual bool
88 CheckIfDuplicate (Ptr<CcnxPitEntry> entry, const CcnxInterestHeader &header) = 0;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080089
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070090 /**
91 * @brief Creates a PIT entry for the given interest
92 * @param header parsed interest header
93 * @returns iterator to Pit entry. If record could not be created (e.g., limit reached),
94 * return end() iterator
95 *
96 * Note. This call assumes that the entry does not exist (i.e., there was a Lookup call before)
97 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070098 virtual Ptr<CcnxPitEntry>
99 Create (const CcnxInterestHeader &header) = 0;
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700100
101 /**
102 * @brief Mark PIT entry deleted
103 * @param entry PIT entry
104 *
105 * Effectively, this method removes all incoming/outgoing faces and set
106 * lifetime +m_PitEntryDefaultLifetime from Now ()
107 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700108 virtual void
109 MarkErased (Ptr<CcnxPitEntry> entry) = 0;
110
111 /**
112 * @brief Print out PIT contents for debugging purposes
113 *
114 * Note that there is no definite order in which entries are printed out
115 */
116 virtual void
117 Print (std::ostream &os) const = 0;
118
119 template<class A,class M>
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700120 void
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700121 modify (A, M)
122 {
123 ;
124 }
125
126 template<class A>
127 void
128 erase (A)
129 {
130 ;
131 }
132
133 ////////////////////////////////////////////////////////////////////////////
134 ////////////////////////////////////////////////////////////////////////////
135 ////////////////////////////////////////////////////////////////////////////
136
137 /**
138 * @brief Static call to cheat python bindings
139 */
140 static inline Ptr<CcnxFib>
141 GetCcnxPit (Ptr<Object> node);
142
143 ////////////////////////////////////////////////////////////////////////////
144 ////////////////////////////////////////////////////////////////////////////
145 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700146
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800147protected:
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700148 virtual void
149 DoCleanExpired () = 0;
150
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800151private:
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700152 /**
153 * @brief Remove expired records from PIT
154 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700155 void
156 CleanExpired ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700157
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700158 /**
159 * \brief Set cleanup timeout
160 *
161 * Side effect: current clean up even (if any) will be cancelled and a new event started
162 *
163 * \param timeout cleanup timeout
164 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700165 void
166 SetCleanupTimeout (const Time &timeout);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700167
168 /**
169 * \brief Get cleanup timeout
170 *
171 * \returns cleanup timeout
172 */
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700173 Time
174 GetCleanupTimeout () const;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700175
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700176protected:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700177 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
178 EventId m_cleanupEvent; ///< \brief Cleanup event
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800179
180 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800181 Time m_PitEntryPruningTimout;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800182 Time m_PitEntryDefaultLifetime;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700183};
184
185///////////////////////////////////////////////////////////////////////////////
186///////////////////////////////////////////////////////////////////////////////
187
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700188inline std::ostream&
189operator<< (std::ostream& os, const CcnxPit &pit)
190{
191 pit.Print (os);
192 return os;
193}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700194
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700195} // namespace ns3
196
197#endif /* CCNX_PIT_H */