blob: 3ffadad0109e742537bcef14628ed0d7517bc730 [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
24#include "ns3/nstime.h"
25#include "ns3/event-id.h"
26
27#include "hash-helper.h"
28#include "ccnx-pit-entry.h"
29
30#include <boost/multi_index_container.hpp>
31#include <boost/multi_index/tag.hpp>
32#include <boost/multi_index/ordered_index.hpp>
33#include <boost/multi_index/composite_key.hpp>
34#include <boost/multi_index/hashed_index.hpp>
35#include <boost/multi_index/member.hpp>
36#include <boost/multi_index/mem_fun.hpp>
37#include <boost/multi_index/sequenced_index.hpp>
38
39#include <iostream>
40
41namespace ns3 {
42
43class Ccnx;
44class CcnxFace;
45class CcnxContentObjectHeader;
46class CcnxInterestHeader;
47
48/**
49 * \ingroup ccnx
50 * \private
51 * \brief Private namespace for CCNx PIT implementation
52 */
53namespace __ccnx_private
54{
55class i_prefix{}; ///< tag for prefix hash
56class i_timestamp {}; ///< tag for timestamp-ordered records (for cleanup optimization)
57};
58
59/**
60 * \ingroup ccnx
61 * \brief Typedef for RIT container implemented as a Boost.MultiIndex container
62 *
63 * - First index (tag<i_prefix>) is a unique hash index based on
64 * prefixes
65 * - Second index (tag<i_timestamp>) is a sequenced index based on
66 * arrival order (for clean-up optimizations)
67 *
68 * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
69 */
70struct CcnxPitEntryContainer
71{
72 typedef
73 boost::multi_index::multi_index_container<
74 CcnxPitEntry,
75 boost::multi_index::indexed_by<
76 // indexed by hash
77 boost::multi_index::hashed_unique<
78 boost::multi_index::tag<__ccnx_private::i_prefix>,
79 boost::multi_index::const_mem_fun<CcnxPitEntry, const CcnxNameComponents&, &CcnxPitEntry::GetPrefix>,
80 CcnxPrefixHash
81 >,
82 // sequenced to implement MRU
83 boost::multi_index::sequenced<
84 boost::multi_index::tag<__ccnx_private::i_timestamp> >
85 >
86 > type;
87};
88
89// typedef std::map<int,int> PitCounter;
90// typedef std::map<int,int>::iterator PitCounterIterator;
91
92// typedef std::map<int,double> PitBucket;
93// typedef std::map<int,double>::iterator PitBucketIterator;
94
95
96////////////////////////////////////////////////////////////////////////
97////////////////////////////////////////////////////////////////////////
98
99/**
100 * \ingroup ccnx
101 * \brief Class implementing Pending Interests Table
102 */
103class CcnxPit : public Object
104{
105public:
106 /**
107 * \brief Interface ID
108 *
109 * \return interface ID
110 */
111 static TypeId GetTypeId ();
112
113 /**
114 * \brief PIT constructor
115 */
116 CcnxPit ();
117
118 /**
119 * \brief Find corresponding PIT entry for the given content name
120 * \param prefix Prefix for which to lookup the entry
121 * \returns const reference to Pit entry. If record not found,
122 * CcnxPitEntryNotFound exception will be thrown
123 */
124 const CcnxPitEntry&
125 Lookup (const CcnxContentObjectHeader &header) const;
126
127 /**
128 * \brief Find corresponding PIT entry for the given content name
129 * \param prefix Prefix for which to lookup the entry
130 * \returns const reference to Pit entry. If record does not exist, it will be created
131 */
132 const CcnxPitEntry&
133 Lookup (const CcnxInterestHeader &header) const;
134
135 // remove a PIT entry
136 //void erase (const string &contentName);
137
138 // Reset pending state in outgoing interests
139 // void resetPendingState( PitEntry &pe );
140
141 // // Check if there are any interfaces that we haven't sent data to yet
142 // bool areFreeInterfaces( PitEntry &pe, int interface );
143
144 // // Periodically generate pre-calculated number of tokens (leak buckets)
145 // void LeakBuckets( );
146
147 // // Selectively leak a bucket
148 // void LeakBucket (Ptr<CcnxFace> face, int amount);
149
150 /**
151 * \brief Set cleanup timeout
152 *
153 * Side effect: current clean up even (if any) will be cancelled and a new event started
154 *
155 * \param timeout cleanup timeout
156 */
157 void SetCleanupTimeout (const Time &timeout);
158
159 /**
160 * \brief Get cleanup timeout
161 *
162 * \returns cleanup timeout
163 */
164 Time GetCleanupTimeout () const;
165
166public:
167 // PitBucket maxBucketsPerInterface; // maximum number of buckets. Automatically computed based on link capacity
168 // // averaging over 1 second (bandwidth * 1second)
169 // PitBucket leakSize; // size of a periodic bucket leak
170
171private:
172 /** \brief Remove expired records from PIT */
173 void CleanExpired ();
174
175 friend std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
176
177private:
178 CcnxPitEntryContainer::type m_pit; ///< \brief Container for PIT entries
179
180 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
181 EventId m_cleanupEvent; ///< \brief Cleanup event
182
183 // PitBucket m_bucketsPerInterface; ///< \brief pending interface counter per interface
184};
185
186///////////////////////////////////////////////////////////////////////////////
187///////////////////////////////////////////////////////////////////////////////
188
189std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
190std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
191// std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric);
192
193class CcnxPitEntryNotFound {};
194
195} // namespace ns3
196
197#endif /* CCNX_PIT_H */