blob: d08c09e40a625cc2e1a4d4ea8daad893a28125ef [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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef _NDN_PIT_ENTRY_H_
22#define _NDN_PIT_ENTRY_H_
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070023
24#include "ns3/ptr.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070025#include "ns3/simple-ref-count.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070026
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070027#include "ns3/ndn-fib.h"
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070028
29#include "ns3/ndn-pit-entry-incoming-face.h"
30#include "ns3/ndn-pit-entry-outgoing-face.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070031
32#include <boost/multi_index_container.hpp>
33#include <boost/multi_index/tag.hpp>
34#include <boost/multi_index/ordered_index.hpp>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070035// #include <boost/multi_index/composite_key.hpp>
36// #include <boost/multi_index/hashed_index.hpp>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070037#include <boost/multi_index/member.hpp>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070038// #include <boost/multi_index/mem_fun.hpp>
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080039#include <set>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070040
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070041namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042namespace ndn {
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070043
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044class Pit;
45
46namespace pit {
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070047
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070048/// @cond include_hidden
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070049class i_face {};
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080050class i_retx {};
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070051/// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070052
53/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054 * \ingroup ndn
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055 * \brief Typedef for indexed face container of PitEntryOutgoingFace
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070056 *
57 * Indexes:
58 * - by face (may be it will be possible to replace with just the std::map)
59 */
Alexander Afanasyevc202fd92012-09-03 21:46:00 -070060// struct OutgoingFaceContainer
61// {
62// /// @cond include_hidden
63// typedef boost::multi_index::multi_index_container<
64// OutgoingFace,
65// boost::multi_index::indexed_by<
66// // For fast access to elements using NdnFace
67// boost::multi_index::ordered_unique<
68// boost::multi_index::tag<i_face>,
69// boost::multi_index::member<OutgoingFace, Ptr<Face>, &OutgoingFace::m_face>
70// >
71// // ,
72// // boost::multi_index::ordered_non_unique<
73// // boost::multi_index::tag<i_retx>,
74// // boost::multi_index::member<OutgoingFace, uint32_t, &OutgoingFace::m_retxCount>
75// // >
76// >
77// > type;
78// /// @endcond
79// };
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070080
81
82/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083 * \ingroup ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070084 * \brief structure for PIT entry
Alexander Afanasyev36b45772012-07-10 16:57:42 -070085 *
86 * All set-methods are virtual, in case index rearrangement is necessary in the derived classes
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070087 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088class Entry : public SimpleRefCount<Entry>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070089{
90public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091 typedef std::set< IncomingFace > in_container; ///< @brief incoming faces container type
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070092 typedef in_container::iterator in_iterator; ///< @brief iterator to incoming faces
93
Alexander Afanasyevc202fd92012-09-03 21:46:00 -070094 // typedef OutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type
95 typedef std::set< OutgoingFace > out_container; ///< @brief outgoing faces container type
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070096 typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces
97
98 typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type
99
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700100 /**
101 * \brief PIT entry constructor
102 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800103 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
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 Afanasyev2b4c9472012-08-09 15:00:38 -0700106 Entry (Pit &container, Ptr<const InterestHeader> header, Ptr<fib::Entry> fibEntry);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700107
108 /**
109 * @brief Virtual destructor
110 */
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700111 virtual ~Entry ();
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700112
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800113 /**
114 * @brief Update lifetime of PIT entry
115 *
116 * This function will update PIT entry lifetime to the maximum of the current lifetime and
117 * the lifetime Simulator::Now () + offsetTime
118 *
119 * @param offsetTime Relative time to the current moment, representing PIT entry lifetime
120 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700121 virtual void
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800122 UpdateLifetime (const Time &offsetTime);
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700123
124 /**
125 * @brief Get prefix of the PIT entry
126 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127 const NameComponents &
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700128 GetPrefix () const;
129
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800130 /**
131 * @brief Get current expiration time of the record
132 *
133 * @returns current expiration time of the record
134 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700135 const Time &
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700136 GetExpireTime () const;
137
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800138 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800139 * @brief Check if nonce `nonce` for the same prefix has already been seen
140 *
141 * @param nonce Nonce to check
142 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800143 bool
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700144 IsNonceSeen (uint32_t nonce) const;
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 Afanasyev36b45772012-07-10 16:57:42 -0700153 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700154 AddSeenNonce (uint32_t nonce);
155
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800156 /**
157 * @brief Add `face` to the list of incoming faces
158 *
159 * @param face Face to add to the list of incoming faces
160 * @returns iterator to the added entry
161 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700162 virtual in_iterator
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700163 AddIncoming (Ptr<Face> face);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800164
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800165 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800166 * @brief Remove incoming entry for face `face`
167 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700168 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169 RemoveIncoming (Ptr<Face> face);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800170
171 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800172 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
173 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700174 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700175 ClearIncoming ();
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800176
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800177 /**
178 * @brief Add `face` to the list of outgoing faces
179 *
180 * @param face Face to add to the list of outgoing faces
181 * @returns iterator to the added entry
182 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700183 virtual out_iterator
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700184 AddOutgoing (Ptr<Face> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800185
186 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800187 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
188 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700189 virtual void
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700190 ClearOutgoing ();
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800191
192 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800193 * @brief Remove all references to face.
194 *
195 * This method should be called before face is completely removed from the stack.
196 * Face is removed from the lists of incoming and outgoing faces
197 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700198 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700199 RemoveAllReferencesToFace (Ptr<Face> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800200
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800201 /**
202 * @brief Flag outgoing face as hopeless
203 */
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700204 // virtual void
205 // SetWaitingInVain (out_iterator face);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700206 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700207 SetWaitingInVain (Ptr<Face> face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800208
209 /**
210 * @brief Check if all outgoing faces are NACKed
211 */
212 bool
213 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800214
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700215 /**
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800216 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
217 * \see AreAllOutgoingInVain
218 **/
219 bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700220 AreTherePromisingOutgoingFacesExcept (Ptr<Face> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800221
222 /**
223 * @brief Increase maximum limit of allowed retransmission per outgoing face
224 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700225 virtual void
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800226 IncreaseAllowedRetxCount ();
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700227
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700228 /**
229 * @brief Get maximum allowed number of retransmissions via outgoing faces
230 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700231 uint32_t
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700232 GetMaxRetxCount () const;
233
234 /**
235 * @brief Get associated FIB entry
236 */
237 Ptr<fib::Entry>
238 GetFibEntry ();
239
240 /**
241 * @brief Get associated list (const reference) of incoming faces
242 */
243 const in_container &
244 GetIncoming () const;
245
246 /**
247 * @brief Get associated list (const reference) of outgoing faces
248 */
249 const out_container &
250 GetOutgoing () const;
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700251
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700252private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700253 friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700254
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700255protected:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700256 Pit &m_container; ///< @brief Reference to the container (to rearrange indexes, if necessary)
Alexander Afanasyev31cb4692012-08-17 13:08:20 -0700257
258 Ptr<const InterestHeader> m_interest; ///< \brief Interest of the PIT entry (if several interests are received, then nonce is from the first Interest)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700259 Ptr<fib::Entry> m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700260
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700261 nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
262 in_container m_incoming; ///< \brief container for incoming interests
263 out_container m_outgoing; ///< \brief container for outgoing interests
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700264
265 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800266
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700267 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800268 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700269};
270
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700271std::ostream& operator<< (std::ostream& os, const Entry &entry);
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800272
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700273} // namespace pit
274} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700275} // namespace ns3
276
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700277#endif // _NDN_PIT_ENTRY_H_