blob: fa89b5e6ea6cced58feffc2348c433c4732e7188 [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_ENTRY_H_
22#define _CCNX_PIT_ENTRY_H_
23
24#include "ns3/ptr.h"
25
26#include "ccnx-pit-entry-incoming-face.h"
27#include "ccnx-pit-entry-outgoing-face.h"
28#include "ccnx-fib.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
38#include <iostream>
39
40namespace ns3 {
41
42class CcnxFace;
43class CcnxNameComponents;
44
45namespace __ccnx_private
46{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070047// class i_face {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070048}
49
50/**
51 * \ingroup ccnx
52 * \brief Typedef for indexed face container of CcnxPitEntryIncomingFace
53 *
54 * Indexes:
55 * - by face (may be it will be possible to replace with just the std::map)
56 */
57struct CcnxPitEntryIncomingFaceContainer
58{
59 typedef boost::multi_index::multi_index_container<
60 CcnxPitEntryIncomingFace,
61 boost::multi_index::indexed_by<
62 // For fast access to elements using CcnxFace
63 boost::multi_index::ordered_unique<
64 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070065 boost::multi_index::member<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070066 >
67 >
68 > type;
69};
70
71/**
72 * \ingroup ccnx
73 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
74 *
75 * Indexes:
76 * - by face (may be it will be possible to replace with just the std::map)
77 */
78struct CcnxPitEntryOutgoingFaceContainer
79{
80 typedef boost::multi_index::multi_index_container<
81 CcnxPitEntryOutgoingFace,
82 boost::multi_index::indexed_by<
83 // For fast access to elements using CcnxFace
84 boost::multi_index::ordered_unique<
85 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070086 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070087 >
88 >
89 > type;
90};
91
92
93/**
94 * \ingroup ccnx
95 * \brief structure for PIT entry
96 */
97struct CcnxPitEntry
98{
99public:
100 /**
101 * \brief PIT entry constructor
102 * \param prefix Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700103 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700104 */
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700105 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const CcnxFibEntry &fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700106
107 // // Get number of outgoing interests that we're expecting data from
108 // inline size_t numberOfPromisingInterests( ) const;
109
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700110 // /**
111 // * \brief Unary function to set or update FIB entry with this PIT entry
112 // * \param fib smart pointer to FIB entry
113 // */
114 // struct SetFibEntry
115 // {
116 // SetFibEntry (Ptr<CcnxFibEntry> fib);
117 // void operator() (CcnxPitEntry &entry);
118 // private:
119 // Ptr<CcnxFibEntry> m_fib;
120 // };
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700121
122 /**
123 * \brief Unary Function to add incoming interest to the PIT entry
124 *
125 * \param incomingFace smart pointer to the face of the incoming interest
126 * \returns const iterator to a newly added or updated
127 * CcnxPitIncomingInterest entry
128 */
129 struct AddIncoming
130 {
131 AddIncoming (Ptr<CcnxFace> incomingFace) : m_face (incomingFace) {}
132 void operator() (CcnxPitEntry &entry);
133
134 private:
135 Ptr<CcnxFace> m_face;
136 Time m_lifeTime;
137 };
138
139 /**
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700140 * \brief Unary function to delete incoming interest for the interface
141 * \param face face that should be removed from the list of incoming interests
142 */
143 struct DeleteIncoming
144 {
145 DeleteIncoming (Ptr<CcnxFace> face) : m_face (face) {}
146 void operator() (CcnxPitEntry &entry);
147 private:
148 Ptr<CcnxFace> m_face;
149 };
150
151 /**
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700152 * \brief Unary function to add outgoing interest to PIT entry
153 *
154 * \param outgoingFace smart pointer to the face of the outgoing interest
155 * \returns const iterator to a newly added or updated
156 * CcnxPitOutgoingInterest entry
157 */
158 struct AddOutgoing
159 {
160 AddOutgoing (Ptr<CcnxFace> outgoingFace) : m_face (outgoingFace) {}
161 void operator() (CcnxPitEntry &entry);
162 private:
163 Ptr<CcnxFace> m_face;
164 };
165
166 /**
167 * \brief Unary function to delete incoming interest for the interface
168 * \param face face that should be removed from the list of incoming interests
169 */
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700170 struct DeleteOutgoing
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700171 {
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700172 DeleteOutgoing (Ptr<CcnxFace> face) : m_face (face) {}
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700173 void operator() (CcnxPitEntry &entry);
174 private:
175 Ptr<CcnxFace> m_face;
176 };
177
178 /**
179 * \brief Unary function to remove all incoming interests
180 */
181 struct ClearIncoming
182 {
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700183 ClearIncoming () {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700184 void operator() (CcnxPitEntry &entry);
185 };
186
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700187 /**
188 * \brief Unary function to update FIB status
189 */
190 struct UpdateFibStatus
191 {
Alexander Afanasyev8accdf62011-09-20 11:33:59 -0700192 UpdateFibStatus (Ptr<CcnxFace> face, CcnxFibFaceMetric::Status status, Ptr<CcnxFib> fib);
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700193 void operator() (CcnxPitEntry &entry);
194 private:
195 Ptr<CcnxFace> m_face;
196 CcnxFibFaceMetric::Status m_status;
Alexander Afanasyev8accdf62011-09-20 11:33:59 -0700197 Ptr<CcnxFib> m_fib;
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700198 };
199
200 /**
201 * \brief Unary function to estimate RTT and update smoothed RTT value in FIB
202 * \param outFace iterator of the outgoing face entry
203 */
204 struct EstimateRttAndRemoveFace
205 {
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700206 EstimateRttAndRemoveFace (CcnxPitEntryOutgoingFaceContainer::type::iterator outFace, Ptr<CcnxFib> fib)
207 : m_outFace (outFace), m_fib (fib) { };
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700208 void operator() (CcnxPitEntry &entry);
209 private:
210 CcnxPitEntryOutgoingFaceContainer::type::iterator m_outFace;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700211 Ptr<CcnxFib> m_fib;
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700212 };
213
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700214 const CcnxNameComponents &
215 GetPrefix () const;
216
217 const Time &
218 GetExpireTime () const { return m_expireTime; }
219
220private:
221 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
222
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700223public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700224 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700225 const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700226
227 CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests
228 CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests
229
230 Time m_expireTime; ///< \brief Time when PIT entry will be removed
231 bool m_timerExpired; ///< \brief flag indicating that PIT timer has expired
232 int m_counterExpirations; ///< \brief whether timer is expired (+ number of times timer expired)
233};
234
235
236} // namespace ns3
237
238#endif // _CCNX_PIT_ENTRY_H_