blob: cf00604ada2e17144988d0584c21e5c7ac867599 [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>
39
40#include <iostream>
41
42namespace ns3 {
43
44class Ccnx;
45class CcnxFace;
46class CcnxContentObjectHeader;
47class CcnxInterestHeader;
48
49/**
50 * \ingroup ccnx
51 * \private
52 * \brief Private namespace for CCNx PIT implementation
53 */
54namespace __ccnx_private
55{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070056// class i_prefix{}; ///< tag for prefix hash
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070057class i_timestamp {}; ///< tag for timestamp-ordered records (for cleanup optimization)
58};
59
60/**
61 * \ingroup ccnx
62 * \brief Typedef for RIT container implemented as a Boost.MultiIndex container
63 *
64 * - First index (tag<i_prefix>) is a unique hash index based on
65 * prefixes
66 * - Second index (tag<i_timestamp>) is a sequenced index based on
67 * arrival order (for clean-up optimizations)
68 *
69 * \see http://www.boost.org/doc/libs/1_46_1/libs/multi_index/doc/ for more information on Boost.MultiIndex library
70 */
71struct CcnxPitEntryContainer
72{
73 typedef
74 boost::multi_index::multi_index_container<
75 CcnxPitEntry,
76 boost::multi_index::indexed_by<
77 // indexed by hash
78 boost::multi_index::hashed_unique<
79 boost::multi_index::tag<__ccnx_private::i_prefix>,
80 boost::multi_index::const_mem_fun<CcnxPitEntry, const CcnxNameComponents&, &CcnxPitEntry::GetPrefix>,
81 CcnxPrefixHash
82 >,
83 // sequenced to implement MRU
84 boost::multi_index::sequenced<
85 boost::multi_index::tag<__ccnx_private::i_timestamp> >
86 >
87 > type;
88};
89
90// typedef std::map<int,int> PitCounter;
91// typedef std::map<int,int>::iterator PitCounterIterator;
92
93// typedef std::map<int,double> PitBucket;
94// typedef std::map<int,double>::iterator PitBucketIterator;
95
96
97////////////////////////////////////////////////////////////////////////
98////////////////////////////////////////////////////////////////////////
99
100/**
101 * \ingroup ccnx
102 * \brief Class implementing Pending Interests Table
103 */
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700104class CcnxPit : public CcnxPitEntryContainer::type, public Object
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700105{
106public:
107 /**
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700108 * \brief Interface ID
109 *
110 * \return interface ID
111 */
112 static TypeId GetTypeId ();
113
114 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700115 * \brief PIT constructor
116 */
117 CcnxPit ();
118
119 /**
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
131 * \returns const reference to Pit entry. If record does not exist, it will be created
132 */
133 const CcnxPitEntry&
Alexander Afanasyevcf133f02011-09-06 12:13:48 -0700134 Lookup (const CcnxInterestHeader &header);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700135
136 // remove a PIT entry
137 //void erase (const string &contentName);
138
139 // Reset pending state in outgoing interests
140 // void resetPendingState( PitEntry &pe );
141
142 // // Check if there are any interfaces that we haven't sent data to yet
143 // bool areFreeInterfaces( PitEntry &pe, int interface );
144
145 // // Periodically generate pre-calculated number of tokens (leak buckets)
146 // void LeakBuckets( );
147
148 // // Selectively leak a bucket
149 // void LeakBucket (Ptr<CcnxFace> face, int amount);
150
151 /**
152 * \brief Set cleanup timeout
153 *
154 * Side effect: current clean up even (if any) will be cancelled and a new event started
155 *
156 * \param timeout cleanup timeout
157 */
158 void SetCleanupTimeout (const Time &timeout);
159
160 /**
161 * \brief Get cleanup timeout
162 *
163 * \returns cleanup timeout
164 */
165 Time GetCleanupTimeout () const;
166
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700167 /**
168 * \brief Set FIB table
169 */
170 void SetFib (Ptr<CcnxFib> fib);
171
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700172public:
173 // PitBucket maxBucketsPerInterface; // maximum number of buckets. Automatically computed based on link capacity
174 // // averaging over 1 second (bandwidth * 1second)
175 // PitBucket leakSize; // size of a periodic bucket leak
176
177private:
178 /** \brief Remove expired records from PIT */
179 void CleanExpired ();
180
181 friend std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
182
183private:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700184 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
185 EventId m_cleanupEvent; ///< \brief Cleanup event
186
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700187 Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700188 // PitBucket m_bucketsPerInterface; ///< \brief pending interface counter per interface
189};
190
191///////////////////////////////////////////////////////////////////////////////
192///////////////////////////////////////////////////////////////////////////////
193
194std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
195std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
196// std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric);
197
198class CcnxPitEntryNotFound {};
199
200} // namespace ns3
201
202#endif /* CCNX_PIT_H */