blob: 62f7e3fcd2e6bcf4a9c7aba576abc4b94b004ee8 [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"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070025#include "ns3/simple-ref-count.h"
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070026
27#include "ccnx-pit-entry-incoming-face.h"
28#include "ccnx-pit-entry-outgoing-face.h"
29#include "ccnx-fib.h"
30
31#include <boost/multi_index_container.hpp>
32#include <boost/multi_index/tag.hpp>
33#include <boost/multi_index/ordered_index.hpp>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070034// #include <boost/multi_index/composite_key.hpp>
35// #include <boost/multi_index/hashed_index.hpp>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070036#include <boost/multi_index/member.hpp>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070037// #include <boost/multi_index/mem_fun.hpp>
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080038#include <set>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070039
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070040namespace ns3 {
41
42class CcnxFace;
43class CcnxNameComponents;
44
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070045/// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070046namespace __ccnx_private
47{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080048class i_retx {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070049}
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070050/// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070051
52/**
53 * \ingroup ccnx
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070054 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
55 *
56 * Indexes:
57 * - by face (may be it will be possible to replace with just the std::map)
58 */
59struct CcnxPitEntryOutgoingFaceContainer
60{
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070061 /// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070062 typedef boost::multi_index::multi_index_container<
63 CcnxPitEntryOutgoingFace,
64 boost::multi_index::indexed_by<
65 // For fast access to elements using CcnxFace
66 boost::multi_index::ordered_unique<
67 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070068 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080069 >,
70 boost::multi_index::ordered_non_unique<
71 boost::multi_index::tag<__ccnx_private::i_retx>,
72 boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount>
73 >
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070074 >
75 > type;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070076 /// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070077};
78
79
80/**
81 * \ingroup ccnx
82 * \brief structure for PIT entry
83 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070084struct CcnxPitEntry : SimpleRefCount<CcnxPitEntry>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070085{
86public:
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070087 typedef std::set< CcnxPitEntryIncomingFace > in_container; ///< @brief incoming faces container type
88 typedef in_container::iterator in_iterator; ///< @brief iterator to incoming faces
89
90 typedef CcnxPitEntryOutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type
91 typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces
92
93 typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type
94
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070095 /**
96 * \brief PIT entry constructor
97 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080098 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070099 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700100 */
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700101 CcnxPitEntry (Ptr<const CcnxNameComponents> prefix, const Time &offsetTime, Ptr<CcnxFibEntry> fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700102
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800103 /**
104 * @brief Update lifetime of PIT entry
105 *
106 * This function will update PIT entry lifetime to the maximum of the current lifetime and
107 * the lifetime Simulator::Now () + offsetTime
108 *
109 * @param offsetTime Relative time to the current moment, representing PIT entry lifetime
110 */
111 void
112 UpdateLifetime (const Time &offsetTime);
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700113
114 /**
115 * @brief Get prefix of the PIT entry
116 */
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800117 const CcnxNameComponents &
118 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800119 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700120
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800121 /**
122 * @brief Get current expiration time of the record
123 *
124 * @returns current expiration time of the record
125 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700126 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800127 GetExpireTime () const
128 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700129
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800130 /**
131 * @brief Set expiration time on record as `expireTime` (absolute time)
132 *
133 * @param expireTime absolute simulation time of when the record should expire
134 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800135 void
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -0700136 SetExpireTime (const Time &expireTime);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800137
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800138 /**
139 * @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
144 IsNonceSeen (uint32_t nonce) const
145 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
146
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800147 /**
148 * @brief Add `nonce` to the list of seen nonces
149 *
150 * @param nonce nonce to add to the list of seen nonces
151 *
152 * All nonces are stored for the lifetime of the PIT entry
153 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800154 void
155 AddSeenNonce (uint32_t nonce)
156 { m_seenNonces.insert (nonce); }
157
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800158 /**
159 * @brief Add `face` to the list of incoming faces
160 *
161 * @param face Face to add to the list of incoming faces
162 * @returns iterator to the added entry
163 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700164 in_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800165 AddIncoming (Ptr<CcnxFace> face);
166
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800167 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800168 * @brief Remove incoming entry for face `face`
169 */
170 void
171 RemoveIncoming (Ptr<CcnxFace> face);
172
173 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800174 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
175 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800176 void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800177 ClearIncoming ()
178 { m_incoming.clear (); }
179
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800180 /**
181 * @brief Add `face` to the list of outgoing faces
182 *
183 * @param face Face to add to the list of outgoing faces
184 * @returns iterator to the added entry
185 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700186 out_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800187 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800188
189 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800190 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
191 */
192 void
193 ClearOutgoing ()
194 { m_outgoing.clear (); }
195
196 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800197 * @brief Remove all references to face.
198 *
199 * This method should be called before face is completely removed from the stack.
200 * Face is removed from the lists of incoming and outgoing faces
201 */
202 void
203 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
204
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800205 /**
206 * @brief Flag outgoing face as hopeless
207 */
208 void
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700209 SetWaitingInVain (out_iterator face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800210
211 /**
212 * @brief Check if all outgoing faces are NACKed
213 */
214 bool
215 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800216
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700217 /**
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800218 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
219 * \see AreAllOutgoingInVain
220 **/
221 bool
222 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800223
224 /**
225 * @brief Increase maximum limit of allowed retransmission per outgoing face
226 */
227 void
228 IncreaseAllowedRetxCount ();
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800229
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800230protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800231
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700232private:
233 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
Alexander Afanasyev07827182011-12-13 01:07:32 -0800234 /**
235 * \brief Default constructor
236 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700237 CcnxPitEntry () {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700238
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700239public:
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700240 Ptr<const CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
241 Ptr<CcnxFibEntry> m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700242
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700243 nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
244 in_container m_incoming; ///< \brief container for incoming interests
245 out_container m_outgoing; ///< \brief container for outgoing interests
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700246
247 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800248
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700249 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800250 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700251};
252
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800253std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
254
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700255} // namespace ns3
256
257#endif // _CCNX_PIT_ENTRY_H_