blob: 55aa7dea0ccd41d34dfd86cf7530ddf1ce56aa43 [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 Afanasyev2b4c9472012-08-09 15:00:38 -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 Afanasyev19426ef2011-11-23 20:55:28 -0800128 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800129 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700130
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800131 /**
132 * @brief Get current expiration time of the record
133 *
134 * @returns current expiration time of the record
135 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700136 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800137 GetExpireTime () const
138 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700139
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800140 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800141 * @brief Check if nonce `nonce` for the same prefix has already been seen
142 *
143 * @param nonce Nonce to check
144 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800145 bool
146 IsNonceSeen (uint32_t nonce) const
147 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
148
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800149 /**
150 * @brief Add `nonce` to the list of seen nonces
151 *
152 * @param nonce nonce to add to the list of seen nonces
153 *
154 * All nonces are stored for the lifetime of the PIT entry
155 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700156 virtual void
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800157 AddSeenNonce (uint32_t nonce)
158 { m_seenNonces.insert (nonce); }
159
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800160 /**
161 * @brief Add `face` to the list of incoming faces
162 *
163 * @param face Face to add to the list of incoming faces
164 * @returns iterator to the added entry
165 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700166 virtual in_iterator
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 AddIncoming (Ptr<Face> face);
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800168
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800169 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800170 * @brief Remove incoming entry for face `face`
171 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700172 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700173 RemoveIncoming (Ptr<Face> face);
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800174
175 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800176 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
177 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700178 virtual void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800179 ClearIncoming ()
180 { m_incoming.clear (); }
181
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800182 /**
183 * @brief Add `face` to the list of outgoing faces
184 *
185 * @param face Face to add to the list of outgoing faces
186 * @returns iterator to the added entry
187 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700188 virtual out_iterator
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700189 AddOutgoing (Ptr<Face> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800190
191 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800192 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
193 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700194 virtual void
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800195 ClearOutgoing ()
196 { m_outgoing.clear (); }
197
198 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800199 * @brief Remove all references to face.
200 *
201 * This method should be called before face is completely removed from the stack.
202 * Face is removed from the lists of incoming and outgoing faces
203 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700204 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700205 RemoveAllReferencesToFace (Ptr<Face> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800206
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800207 /**
208 * @brief Flag outgoing face as hopeless
209 */
Alexander Afanasyev786936a2012-07-17 19:48:15 -0700210 // virtual void
211 // SetWaitingInVain (out_iterator face);
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700212 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213 SetWaitingInVain (Ptr<Face> face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800214
215 /**
216 * @brief Check if all outgoing faces are NACKed
217 */
218 bool
219 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800220
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700221 /**
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800222 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
223 * \see AreAllOutgoingInVain
224 **/
225 bool
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700226 AreTherePromisingOutgoingFacesExcept (Ptr<Face> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800227
228 /**
229 * @brief Increase maximum limit of allowed retransmission per outgoing face
230 */
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700231 virtual void
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800232 IncreaseAllowedRetxCount ();
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700233
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700234 Ptr<fib::Entry>
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700235 GetFibEntry () { return m_fibEntry; };
236
237 const in_container &
238 GetIncoming () const { return m_incoming; }
239
240 const out_container &
241 GetOutgoing () const { return m_outgoing; }
242
243 uint32_t
244 GetMaxRetxCount () const { return m_maxRetxCount; }
245
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700246private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700247 friend std::ostream& operator<< (std::ostream& os, const Entry &entry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700248
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700249protected:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700250 Pit &m_container; ///< @brief Reference to the container (to rearrange indexes, if necessary)
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700251
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700252 Ptr<const NameComponents> m_prefix; ///< \brief Prefix of the PIT entry
253 Ptr<fib::Entry> m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700254
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700255 nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
256 in_container m_incoming; ///< \brief container for incoming interests
257 out_container m_outgoing; ///< \brief container for outgoing interests
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700258
259 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800260
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700261 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800262 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700263};
264
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700265std::ostream& operator<< (std::ostream& os, const Entry &entry);
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800266
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700267} // namespace pit
268} // namespace ndn
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700269} // namespace ns3
270
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700271#endif // _NDN_PIT_ENTRY_H_