blob: 9bf2768a81ca7562010c77811f75796562da6c6b [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
55 * \brief Typedef for indexed face container of CcnxPitEntryIncomingFace
56 *
57 * Indexes:
58 * - by face (may be it will be possible to replace with just the std::map)
59 */
60struct CcnxPitEntryIncomingFaceContainer
61{
62 typedef boost::multi_index::multi_index_container<
63 CcnxPitEntryIncomingFace,
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<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070069 >
70 >
71 > type;
72};
73
74/**
75 * \ingroup ccnx
76 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
77 *
78 * Indexes:
79 * - by face (may be it will be possible to replace with just the std::map)
80 */
81struct CcnxPitEntryOutgoingFaceContainer
82{
83 typedef boost::multi_index::multi_index_container<
84 CcnxPitEntryOutgoingFace,
85 boost::multi_index::indexed_by<
86 // For fast access to elements using CcnxFace
87 boost::multi_index::ordered_unique<
88 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070089 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080090 >,
91 boost::multi_index::ordered_non_unique<
92 boost::multi_index::tag<__ccnx_private::i_retx>,
93 boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount>
94 >
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070095 >
96 > type;
97};
98
99
100/**
101 * \ingroup ccnx
102 * \brief structure for PIT entry
103 */
104struct CcnxPitEntry
105{
106public:
107 /**
108 * \brief PIT entry constructor
109 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800110 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700111 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700112 */
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800113 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &offsetTime, const CcnxFibEntry &fibEntry);
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700114
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800115 /**
116 * @brief Update lifetime of PIT entry
117 *
118 * This function will update PIT entry lifetime to the maximum of the current lifetime and
119 * the lifetime Simulator::Now () + offsetTime
120 *
121 * @param offsetTime Relative time to the current moment, representing PIT entry lifetime
122 */
123 void
124 UpdateLifetime (const Time &offsetTime);
125
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800126 const CcnxNameComponents &
127 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800128 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700129
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 Afanasyeva46844b2011-11-21 19:13:26 -0800136 GetExpireTime () const
137 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700138
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800139 /**
140 * @brief Set expiration time on record as `expireTime` (absolute time)
141 *
142 * @param expireTime absolute simulation time of when the record should expire
143 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800144 void
Alexander Afanasyev1aeaf922012-04-23 13:48:09 -0700145 SetExpireTime (const Time &expireTime);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800146
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800147 /**
148 * @brief Check if nonce `nonce` for the same prefix has already been seen
149 *
150 * @param nonce Nonce to check
151 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800152 bool
153 IsNonceSeen (uint32_t nonce) const
154 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
155
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800156 /**
157 * @brief Add `nonce` to the list of seen nonces
158 *
159 * @param nonce nonce to add to the list of seen nonces
160 *
161 * All nonces are stored for the lifetime of the PIT entry
162 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800163 void
164 AddSeenNonce (uint32_t nonce)
165 { m_seenNonces.insert (nonce); }
166
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800167 /**
168 * @brief Add `face` to the list of incoming faces
169 *
170 * @param face Face to add to the list of incoming faces
171 * @returns iterator to the added entry
172 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800173 CcnxPitEntryIncomingFaceContainer::type::iterator
174 AddIncoming (Ptr<CcnxFace> face);
175
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800176 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800177 * @brief Remove incoming entry for face `face`
178 */
179 void
180 RemoveIncoming (Ptr<CcnxFace> face);
181
182 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800183 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
184 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800185 void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800186 ClearIncoming ()
187 { m_incoming.clear (); }
188
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800189 /**
190 * @brief Add `face` to the list of outgoing faces
191 *
192 * @param face Face to add to the list of outgoing faces
193 * @returns iterator to the added entry
194 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800195 CcnxPitEntryOutgoingFaceContainer::type::iterator
196 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800197
198 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800199 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
200 */
201 void
202 ClearOutgoing ()
203 { m_outgoing.clear (); }
204
205 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800206 * @brief Remove all references to face.
207 *
208 * This method should be called before face is completely removed from the stack.
209 * Face is removed from the lists of incoming and outgoing faces
210 */
211 void
212 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
213
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800214 /**
215 * @brief Flag outgoing face as hopeless
216 */
217 void
218 SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face);
219
220 /**
221 * @brief Check if all outgoing faces are NACKed
222 */
223 bool
224 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800225
226 /*
227 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
228 * \see AreAllOutgoingInVain
229 **/
230 bool
231 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800232
233 /**
234 * @brief Increase maximum limit of allowed retransmission per outgoing face
235 */
236 void
237 IncreaseAllowedRetxCount ();
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800238
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800239protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800240
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700241private:
242 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
Alexander Afanasyev07827182011-12-13 01:07:32 -0800243 /**
244 * \brief Default constructor
245 */
246 CcnxPitEntry () : m_fibEntry(*((CcnxFibEntry*)0)) {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700247
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700248public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700249 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700250 const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800251 std::set<uint32_t> m_seenNonces; ///< \brief map of nonces that were seen for this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700252
253 CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests
254 CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests
255
256 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800257
Alexander Afanasyev7f3e49e2012-04-30 00:17:07 -0700258 Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800259 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700260};
261
Alexander Afanasyeva95b7392012-03-09 10:54:10 -0800262std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
263
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700264} // namespace ns3
265
266#endif // _CCNX_PIT_ENTRY_H_