blob: 93e48696e9d4459dc1a70ea776df4d45afe70da0 [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>
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080037#include <set>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070038
39#include <iostream>
40
41namespace ns3 {
42
43class CcnxFace;
44class CcnxNameComponents;
45
46namespace __ccnx_private
47{
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070048// class i_face {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070049}
50
51/**
52 * \ingroup ccnx
53 * \brief Typedef for indexed face container of CcnxPitEntryIncomingFace
54 *
55 * Indexes:
56 * - by face (may be it will be possible to replace with just the std::map)
57 */
58struct CcnxPitEntryIncomingFaceContainer
59{
60 typedef boost::multi_index::multi_index_container<
61 CcnxPitEntryIncomingFace,
62 boost::multi_index::indexed_by<
63 // For fast access to elements using CcnxFace
64 boost::multi_index::ordered_unique<
65 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070066 boost::multi_index::member<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070067 >
68 >
69 > type;
70};
71
72/**
73 * \ingroup ccnx
74 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
75 *
76 * Indexes:
77 * - by face (may be it will be possible to replace with just the std::map)
78 */
79struct CcnxPitEntryOutgoingFaceContainer
80{
81 typedef boost::multi_index::multi_index_container<
82 CcnxPitEntryOutgoingFace,
83 boost::multi_index::indexed_by<
84 // For fast access to elements using CcnxFace
85 boost::multi_index::ordered_unique<
86 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070087 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070088 >
89 >
90 > type;
91};
92
93
94/**
95 * \ingroup ccnx
96 * \brief structure for PIT entry
97 */
98struct CcnxPitEntry
99{
100public:
101 /**
102 * \brief PIT entry constructor
103 * \param prefix Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700104 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700105 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800106 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &expireTime, const CcnxFibEntry &fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700107
108 // // Get number of outgoing interests that we're expecting data from
109 // inline size_t numberOfPromisingInterests( ) const;
110
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800111 const CcnxNameComponents &
112 GetPrefix () const
113 {
114 return *m_prefix;
115 }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700116
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800117 /**
118 * @brief Get current expiration time of the record
119 *
120 * @returns current expiration time of the record
121 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700122 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800123 GetExpireTime () const
124 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700125
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800126 /**
127 * @brief Set expiration time on record as `expireTime` (absolute time)
128 *
129 * @param expireTime absolute simulation time of when the record should expire
130 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800131 void
132 SetExpireTime (const Time &expireTime)
133 {
134 m_expireTime = expireTime;
135 }
136
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800137 /**
138 * @brief Check if nonce `nonce` for the same prefix has already been seen
139 *
140 * @param nonce Nonce to check
141 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800142 bool
143 IsNonceSeen (uint32_t nonce) const
144 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
145
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800146 /**
147 * @brief Add `nonce` to the list of seen nonces
148 *
149 * @param nonce nonce to add to the list of seen nonces
150 *
151 * All nonces are stored for the lifetime of the PIT entry
152 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800153 void
154 AddSeenNonce (uint32_t nonce)
155 { m_seenNonces.insert (nonce); }
156
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800157 /**
158 * @brief Add `face` to the list of incoming faces
159 *
160 * @param face Face to add to the list of incoming faces
161 * @returns iterator to the added entry
162 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800163 CcnxPitEntryIncomingFaceContainer::type::iterator
164 AddIncoming (Ptr<CcnxFace> face);
165
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800166 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800167 * @brief Remove incoming entry for face `face`
168 */
169 void
170 RemoveIncoming (Ptr<CcnxFace> face);
171
172 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800173 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
174 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800175 void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800176 ClearIncoming ()
177 { m_incoming.clear (); }
178
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800179 /**
180 * @brief Add `face` to the list of outgoing faces
181 *
182 * @param face Face to add to the list of outgoing faces
183 * @returns iterator to the added entry
184 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800185 CcnxPitEntryOutgoingFaceContainer::type::iterator
186 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800187
188 /**
189 * @brief Remove all references to face.
190 *
191 * This method should be called before face is completely removed from the stack.
192 * Face is removed from the lists of incoming and outgoing faces
193 */
194 void
195 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
196
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800197 /**
198 * @brief Flag outgoing face as hopeless
199 */
200 void
201 SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face);
202
203 /**
204 * @brief Check if all outgoing faces are NACKed
205 */
206 bool
207 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800208
209 /*
210 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
211 * \see AreAllOutgoingInVain
212 **/
213 bool
214 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800215
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800216protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800217
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700218private:
219 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
220
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700221public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700222 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700223 const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800224 std::set<uint32_t> m_seenNonces; ///< \brief map of nonces that were seen for this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700225
226 CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests
227 CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests
228
229 Time m_expireTime; ///< \brief Time when PIT entry will be removed
230 bool m_timerExpired; ///< \brief flag indicating that PIT timer has expired
231 int m_counterExpirations; ///< \brief whether timer is expired (+ number of times timer expired)
232};
233
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700234} // namespace ns3
235
236#endif // _CCNX_PIT_ENTRY_H_