blob: 6a0556b6a22a6ef0c699a5a7f3965c4a92cc251c [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 {
31
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070032class Ndn;
33class NdnFace;
34class NdnContentObjectHeader;
35class NdnInterestHeader;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070036
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037////////////////////////////////////////////////////////////////////////
38////////////////////////////////////////////////////////////////////////
39
40/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070041 * \ingroup ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070042 * \brief Class implementing Pending Interests Table
43 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044class NdnPit : 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 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 NdnPit ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070058
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -080059 /**
60 * \brief Destructor
61 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062 virtual ~NdnPit ();
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 Afanasyev4aac5572012-08-09 10:49:55 -070075 virtual Ptr<NdnPitEntry>
76 Lookup (const NdnContentObjectHeader &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 Afanasyev4aac5572012-08-09 10:49:55 -070084 virtual Ptr<NdnPitEntry>
85 Lookup (const NdnInterestHeader &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 Afanasyev4aac5572012-08-09 10:49:55 -070095 virtual Ptr<NdnPitEntry>
96 Create (Ptr<const NdnInterestHeader> 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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700106 MarkErased (Ptr<NdnPitEntry> entry) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700107
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 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700125 virtual Ptr<NdnPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700126 Begin () = 0;
127
128 /**
129 * @brief Return item next after last (no order guaranteed)
130 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700131 virtual Ptr<NdnPitEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700132 End () = 0;
133
134 /**
135 * @brief Advance the iterator
136 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700137 virtual Ptr<NdnPitEntry>
138 Next (Ptr<NdnPitEntry>) = 0;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700139
140 ////////////////////////////////////////////////////////////////////////////
141 ////////////////////////////////////////////////////////////////////////////
142 ////////////////////////////////////////////////////////////////////////////
143
144 /**
145 * @brief Static call to cheat python bindings
146 */
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700147 static inline Ptr<NdnPit>
148 GetNdnPit (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700149
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700150protected:
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800151 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800152 Time m_PitEntryPruningTimout;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700153};
154
155///////////////////////////////////////////////////////////////////////////////
156///////////////////////////////////////////////////////////////////////////////
157
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700158inline std::ostream&
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700159operator<< (std::ostream& os, const NdnPit &pit)
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700160{
161 pit.Print (os);
162 return os;
163}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700164
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700165inline Ptr<NdnPit>
166NdnPit::GetNdnPit (Ptr<Object> node)
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700167{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700168 return node->GetObject<NdnPit> ();
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700169}
170
171
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700172} // namespace ns3
173
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700174#endif /* NDN_PIT_H */