blob: 1ab4f657ae4068a820f53e51e0d1f533f1f19707 [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>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070033// #include <boost/multi_index/composite_key.hpp>
34// #include <boost/multi_index/hashed_index.hpp>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070035#include <boost/multi_index/member.hpp>
Alexander Afanasyev9a989702012-06-29 17:44:00 -070036// #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
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070039namespace ns3 {
40
41class CcnxFace;
42class CcnxNameComponents;
43
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070044/// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070045namespace __ccnx_private
46{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080047class i_retx {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070048}
Alexander Afanasyev6315ef72012-06-01 20:56:31 -070049/// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070050
51/**
52 * \ingroup ccnx
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070053 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
54 *
55 * Indexes:
56 * - by face (may be it will be possible to replace with just the std::map)
57 */
58struct CcnxPitEntryOutgoingFaceContainer
59{
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070060 /// @cond include_hidden
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070061 typedef boost::multi_index::multi_index_container<
62 CcnxPitEntryOutgoingFace,
63 boost::multi_index::indexed_by<
64 // For fast access to elements using CcnxFace
65 boost::multi_index::ordered_unique<
66 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070067 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080068 >,
69 boost::multi_index::ordered_non_unique<
70 boost::multi_index::tag<__ccnx_private::i_retx>,
71 boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount>
72 >
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070073 >
74 > type;
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -070075 /// @endcond
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070076};
77
78
79/**
80 * \ingroup ccnx
81 * \brief structure for PIT entry
82 */
83struct CcnxPitEntry
84{
85public:
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070086 typedef std::set< CcnxPitEntryIncomingFace > in_container; ///< @brief incoming faces container type
87 typedef in_container::iterator in_iterator; ///< @brief iterator to incoming faces
88
89 typedef CcnxPitEntryOutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type
90 typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces
91
92 typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type
93
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070094 /**
95 * \brief PIT entry constructor
96 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080097 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070098 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070099 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700100 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &offsetTime, CcnxFib::iterator fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700101
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800102 /**
103 * @brief Update lifetime of PIT entry
104 *
105 * This function will update PIT entry lifetime to the maximum of the current lifetime and
106 * the lifetime Simulator::Now () + offsetTime
107 *
108 * @param offsetTime Relative time to the current moment, representing PIT entry lifetime
109 */
110 void
111 UpdateLifetime (const Time &offsetTime);
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700112
113 /**
114 * @brief Get prefix of the PIT entry
115 */
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800116 const CcnxNameComponents &
117 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800118 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700119
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800120 /**
121 * @brief Get current expiration time of the record
122 *
123 * @returns current expiration time of the record
124 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700125 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800126 GetExpireTime () const
127 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700128
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800129 /**
130 * @brief Set expiration time on record as `expireTime` (absolute time)
131 *
132 * @param expireTime absolute simulation time of when the record should expire
133 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800134 void
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -0700135 SetExpireTime (const Time &expireTime);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800136
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 Afanasyevf034cbd2012-06-29 14:28:31 -0700163 in_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800164 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 Afanasyevf034cbd2012-06-29 14:28:31 -0700185 out_iterator
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800186 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800187
188 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800189 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
190 */
191 void
192 ClearOutgoing ()
193 { m_outgoing.clear (); }
194
195 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800196 * @brief Remove all references to face.
197 *
198 * This method should be called before face is completely removed from the stack.
199 * Face is removed from the lists of incoming and outgoing faces
200 */
201 void
202 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
203
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800204 /**
205 * @brief Flag outgoing face as hopeless
206 */
207 void
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700208 SetWaitingInVain (out_iterator face);
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800209
210 /**
211 * @brief Check if all outgoing faces are NACKed
212 */
213 bool
214 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800215
Alexander Afanasyevb4fee8b2012-06-06 12:54:26 -0700216 /**
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800217 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
218 * \see AreAllOutgoingInVain
219 **/
220 bool
221 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800222
223 /**
224 * @brief Increase maximum limit of allowed retransmission per outgoing face
225 */
226 void
227 IncreaseAllowedRetxCount ();
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800228
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800229protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800230
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700231private:
232 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
Alexander Afanasyev07827182011-12-13 01:07:32 -0800233 /**
234 * \brief Default constructor
235 */
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700236 CcnxPitEntry () {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700237
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700238public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700239 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700240 CcnxFib::iterator m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700241
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -0700242 nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix
243 in_container m_incoming; ///< \brief container for incoming interests
244 out_container m_outgoing; ///< \brief container for outgoing interests
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700245
246 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800247
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700248 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800249 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700250};
251
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800252std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
253
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700254} // namespace ns3
255
256#endif // _CCNX_PIT_ENTRY_H_