blob: 02a2ac7b0ac800d2e4409ee63a5c64dae9490bd6 [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{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070055// class i_prefix{}; ///< tag for prefix hash
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070056class 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 */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700103class CcnxPit : public CcnxPitEntryContainer::type
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700104{
105public:
106 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700107 * \brief PIT constructor
108 */
109 CcnxPit ();
110
111 /**
112 * \brief Find corresponding PIT entry for the given content name
113 * \param prefix Prefix for which to lookup the entry
114 * \returns const reference to Pit entry. If record not found,
115 * CcnxPitEntryNotFound exception will be thrown
116 */
117 const CcnxPitEntry&
118 Lookup (const CcnxContentObjectHeader &header) const;
119
120 /**
121 * \brief Find corresponding PIT entry for the given content name
122 * \param prefix Prefix for which to lookup the entry
123 * \returns const reference to Pit entry. If record does not exist, it will be created
124 */
125 const CcnxPitEntry&
126 Lookup (const CcnxInterestHeader &header) const;
127
128 // remove a PIT entry
129 //void erase (const string &contentName);
130
131 // Reset pending state in outgoing interests
132 // void resetPendingState( PitEntry &pe );
133
134 // // Check if there are any interfaces that we haven't sent data to yet
135 // bool areFreeInterfaces( PitEntry &pe, int interface );
136
137 // // Periodically generate pre-calculated number of tokens (leak buckets)
138 // void LeakBuckets( );
139
140 // // Selectively leak a bucket
141 // void LeakBucket (Ptr<CcnxFace> face, int amount);
142
143 /**
144 * \brief Set cleanup timeout
145 *
146 * Side effect: current clean up even (if any) will be cancelled and a new event started
147 *
148 * \param timeout cleanup timeout
149 */
150 void SetCleanupTimeout (const Time &timeout);
151
152 /**
153 * \brief Get cleanup timeout
154 *
155 * \returns cleanup timeout
156 */
157 Time GetCleanupTimeout () const;
158
159public:
160 // PitBucket maxBucketsPerInterface; // maximum number of buckets. Automatically computed based on link capacity
161 // // averaging over 1 second (bandwidth * 1second)
162 // PitBucket leakSize; // size of a periodic bucket leak
163
164private:
165 /** \brief Remove expired records from PIT */
166 void CleanExpired ();
167
168 friend std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
169
170private:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700171 Time m_cleanupTimeout; ///< \brief Configurable timeout of how often cleanup events are working
172 EventId m_cleanupEvent; ///< \brief Cleanup event
173
174 // PitBucket m_bucketsPerInterface; ///< \brief pending interface counter per interface
175};
176
177///////////////////////////////////////////////////////////////////////////////
178///////////////////////////////////////////////////////////////////////////////
179
180std::ostream& operator<< (std::ostream& os, const CcnxPit &fib);
181std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
182// std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric);
183
184class CcnxPitEntryNotFound {};
185
186} // namespace ns3
187
188#endif /* CCNX_PIT_H */