blob: 2fbafaa3dce9d130a1b169bd244b3ee090183cba [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
28#include "hash-helper.h"
29#include "ccnx-pit-entry.h"
30
31#include <boost/multi_index_container.hpp>
32#include <boost/multi_index/tag.hpp>
33#include <boost/multi_index/ordered_index.hpp>
34#include <boost/multi_index/composite_key.hpp>
35#include <boost/multi_index/hashed_index.hpp>
36#include <boost/multi_index/member.hpp>
37#include <boost/multi_index/mem_fun.hpp>
38#include <boost/multi_index/sequenced_index.hpp>
Ilya Moiseenko1c73cb52011-10-28 13:13:11 -070039#include <map>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070040#include <iostream>
Ilya Moiseenko1c73cb52011-10-28 13:13:11 -070041#include <algorithm>
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080042#include <boost/tuple/tuple.hpp>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070043
44namespace ns3 {
45
46class Ccnx;
47class CcnxFace;
48class CcnxContentObjectHeader;
49class CcnxInterestHeader;
50
51/**
52 * \ingroup ccnx
53 * \private
54 * \brief Private namespace for CCNx PIT implementation
55 */
56namespace __ccnx_private
57{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070058// class i_prefix{}; ///< tag for prefix hash
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070059class i_timestamp {}; ///< tag for timestamp-ordered records (for cleanup optimization)
60};
61
62/**
63 * \ingroup ccnx
64 * \brief Typedef for RIT container implemented as a Boost.MultiIndex container
65 *
66 * - First index (tag<i_prefix>) is a unique hash index based on
67 * prefixes
68 * - Second index (tag<i_timestamp>) is a sequenced index based on
69 * arrival order (for clean-up optimizations)
70 *
71 * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
72 */
73struct CcnxPitEntryContainer
74{
75 typedef
76 boost::multi_index::multi_index_container<
77 CcnxPitEntry,
78 boost::multi_index::indexed_by<
79 // indexed by hash
80 boost::multi_index::hashed_unique<
81 boost::multi_index::tag<__ccnx_private::i_prefix>,
82 boost::multi_index::const_mem_fun<CcnxPitEntry, const CcnxNameComponents&, &CcnxPitEntry::GetPrefix>,
83 CcnxPrefixHash
84 >,
85 // sequenced to implement MRU
86 boost::multi_index::sequenced<
87 boost::multi_index::tag<__ccnx_private::i_timestamp> >
88 >
89 > type;
90};
91
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070092////////////////////////////////////////////////////////////////////////
93////////////////////////////////////////////////////////////////////////
94
95/**
96 * \ingroup ccnx
97 * \brief Class implementing Pending Interests Table
98 */
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070099class CcnxPit : public CcnxPitEntryContainer::type, public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700100{
101public:
102 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700103 * \brief Interface ID
104 *
105 * \return interface ID
106 */
107 static TypeId GetTypeId ();
108
109 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700110 * \brief PIT constructor
111 */
112 CcnxPit ();
113
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800114 /**
115 * \brief Destructor
116 */
117 virtual ~CcnxPit ();
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800118
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700119 /**
120 * \brief Find corresponding PIT entry for the given content name
121 * \param prefix Prefix for which to lookup the entry
122 * \returns const reference to Pit entry. If record not found,
123 * CcnxPitEntryNotFound exception will be thrown
124 */
125 const CcnxPitEntry&
126 Lookup (const CcnxContentObjectHeader &header) const;
127
128 /**
129 * \brief Find corresponding PIT entry for the given content name
130 * \param prefix Prefix for which to lookup the entry
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800131 * \returns a tuple:
132 * get<0>: `const CcnxPitEntry&`: a valid PIT entry (if record does not exist, it will be created)
133 * get<1>: `bool`: true if a new entry was created
134 * get<2>: `bool`: true if a PIT entry exists and Nonce that present in header has been already seen
135 *
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700136 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800137 boost::tuple<const CcnxPitEntry&, bool, bool>
138 Lookup (const CcnxInterestHeader &header);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700139
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800140 Time GetPitEntryPruningTimeout () const
141 {
142 return m_PitEntryPruningTimout;
143 }
144
145 /**
146 * \brief Set FIB table
147 */
148 void SetFib (Ptr<CcnxFib> fib);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700149
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800150protected:
151 // inherited from Object class
152 virtual void NotifyNewAggregate ();
153 virtual void DoDispose ();
154
155private:
156 /** \brief Remove expired records from PIT */
157 void CleanExpired ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700158
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700159 /**
160 * \brief Set cleanup timeout
161 *
162 * Side effect: current clean up even (if any) will be cancelled and a new event started
163 *
164 * \param timeout cleanup timeout
165 */
166 void SetCleanupTimeout (const Time &timeout);
167
168 /**
169 * \brief Get cleanup timeout
170 *
171 * \returns cleanup timeout
172 */
173 Time GetCleanupTimeout () const;
174
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700175 friend std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
176
177private:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700178 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
179 EventId m_cleanupEvent; ///< \brief Cleanup event
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800180
181 // configuration variables. Check implementation of GetTypeId for more details
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800182 Time m_PitEntryPruningTimout;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800183 Time m_PitEntryDefaultLifetime;
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700184
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700185 Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800186 // PitBucket m_bucketsPerFace; ///< \brief pending interface counter per face
187
188 // /**
189 // * \brief maximum number of buckets. Automatically computed based on link capacity
190 // * averaging over 1 second (bandwidth * 1second)
191 // */
192 // PitBucket maxBucketsPerFace;
193
194 // PitBucket leakSize; ///< size of a periodic bucket leak
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700195};
196
197///////////////////////////////////////////////////////////////////////////////
198///////////////////////////////////////////////////////////////////////////////
199
200std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
201std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
202// std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric);
203
204class CcnxPitEntryNotFound {};
205
206} // namespace ns3
207
208#endif /* CCNX_PIT_H */