blob: bc81c896cfd21c3f92189b92f73ad81cde7e857c [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
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070046/// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070047namespace __ccnx_private
48{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080049class i_retx {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070050}
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070051/// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070052
53/**
54 * \ingroup ccnx
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070055 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
56 *
57 * Indexes:
58 * - by face (may be it will be possible to replace with just the std::map)
59 */
60struct CcnxPitEntryOutgoingFaceContainer
61{
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070062 /// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070063 typedef boost::multi_index::multi_index_container<
64 CcnxPitEntryOutgoingFace,
65 boost::multi_index::indexed_by<
66 // For fast access to elements using CcnxFace
67 boost::multi_index::ordered_unique<
68 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070069 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080070 >,
71 boost::multi_index::ordered_non_unique<
72 boost::multi_index::tag<__ccnx_private::i_retx>,
73 boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount>
74 >
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070075 >
76 > type;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070077 /// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070078};
79
80
81/**
82 * \ingroup ccnx
83 * \brief structure for PIT entry
84 */
85struct CcnxPitEntry
86{
87public:
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070088 typedef std::set< CcnxPitEntryIncomingFace > in_container; ///< @brief incoming faces container type
89 typedef in_container::iterator in_iterator; ///< @brief iterator to incoming faces
90
91 typedef CcnxPitEntryOutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type
92 typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces
93
94 typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type
95
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070096 /**
97 * \brief PIT entry constructor
98 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080099 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700100 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700101 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700102 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &offsetTime, CcnxFib::iterator fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700103
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800104 /**
105 * @brief Update lifetime of PIT entry
106 *
107 * This function will update PIT entry lifetime to the maximum of the current lifetime and
108 * the lifetime Simulator::Now () + offsetTime
109 *
110 * @param offsetTime Relative time to the current moment, representing PIT entry lifetime
111 */
112 void
113 UpdateLifetime (const Time &offsetTime);
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700114
115 /**
116 * @brief Get prefix of the PIT entry
117 */
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800118 const CcnxNameComponents &
119 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800120 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700121
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800122 /**
123 * @brief Get current expiration time of the record
124 *
125 * @returns current expiration time of the record
126 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700127 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800128 GetExpireTime () const
129 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700130
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800131 /**
132 * @brief Set expiration time on record as `expireTime` (absolute time)
133 *
134 * @param expireTime absolute simulation time of when the record should expire
135 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800136 void
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -0700137 SetExpireTime (const Time &expireTime);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800138
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800139 /**
140 * @brief Check if nonce `nonce` for the same prefix has already been seen
141 *
142 * @param nonce Nonce to check
143 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800144 bool
145 IsNonceSeen (uint32_t nonce) const
146 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
147
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800148 /**
149 * @brief Add `nonce` to the list of seen nonces
150 *
151 * @param nonce nonce to add to the list of seen nonces
152 *
153 * All nonces are stored for the lifetime of the PIT entry
154 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800155 void
156 AddSeenNonce (uint32_t nonce)
157 { m_seenNonces.insert (nonce); }
158
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800159 /**
160 * @brief Add `face` to the list of incoming faces
161 *
162 * @param face Face to add to the list of incoming faces
163 * @returns iterator to the added entry
164 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700165 in_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800166 AddIncoming (Ptr<CcnxFace> face);
167
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800168 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800169 * @brief Remove incoming entry for face `face`
170 */
171 void
172 RemoveIncoming (Ptr<CcnxFace> face);
173
174 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800175 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
176 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800177 void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800178 ClearIncoming ()
179 { m_incoming.clear (); }
180
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800181 /**
182 * @brief Add `face` to the list of outgoing faces
183 *
184 * @param face Face to add to the list of outgoing faces
185 * @returns iterator to the added entry
186 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700187 out_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800188 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800189
190 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800191 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
192 */
193 void
194 ClearOutgoing ()
195 { m_outgoing.clear (); }
196
197 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800198 * @brief Remove all references to face.
199 *
200 * This method should be called before face is completely removed from the stack.
201 * Face is removed from the lists of incoming and outgoing faces
202 */
203 void
204 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
205
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800206 /**
207 * @brief Flag outgoing face as hopeless
208 */
209 void
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700210 SetWaitingInVain (out_iterator face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800211
212 /**
213 * @brief Check if all outgoing faces are NACKed
214 */
215 bool
216 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800217
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700218 /**
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800219 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
220 * \see AreAllOutgoingInVain
221 **/
222 bool
223 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800224
225 /**
226 * @brief Increase maximum limit of allowed retransmission per outgoing face
227 */
228 void
229 IncreaseAllowedRetxCount ();
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800230
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800231protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800232
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700233private:
234 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
Alexander Afanasyev07827182011-12-13 01:07:32 -0800235 /**
236 * \brief Default constructor
237 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700238 CcnxPitEntry () {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700239
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700240public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700241 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700242 CcnxFib::iterator m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700243
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700244 nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
245 in_container m_incoming; ///< \brief container for incoming interests
246 out_container m_outgoing; ///< \brief container for outgoing interests
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700247
248 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800249
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700250 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800251 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700252};
253
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800254std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
255
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700256} // namespace ns3
257
258#endif // _CCNX_PIT_ENTRY_H_