blob: 12ffa9179acee397c29372cd79341d37296eae34 [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
46namespace __ccnx_private
47{
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080048class i_retx {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070049}
50
51/**
52 * \ingroup ccnx
53 * \brief Typedef for indexed face container of CcnxPitEntryIncomingFace
54 *
55 * Indexes:
56 * - by face (may be it will be possible to replace with just the std::map)
57 */
58struct CcnxPitEntryIncomingFaceContainer
59{
60 typedef boost::multi_index::multi_index_container<
61 CcnxPitEntryIncomingFace,
62 boost::multi_index::indexed_by<
63 // For fast access to elements using CcnxFace
64 boost::multi_index::ordered_unique<
65 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070066 boost::multi_index::member<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face>
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070067 >
68 >
69 > type;
70};
71
72/**
73 * \ingroup ccnx
74 * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace
75 *
76 * Indexes:
77 * - by face (may be it will be possible to replace with just the std::map)
78 */
79struct CcnxPitEntryOutgoingFaceContainer
80{
81 typedef boost::multi_index::multi_index_container<
82 CcnxPitEntryOutgoingFace,
83 boost::multi_index::indexed_by<
84 // For fast access to elements using CcnxFace
85 boost::multi_index::ordered_unique<
86 boost::multi_index::tag<__ccnx_private::i_face>,
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -070087 boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face>
Alexander Afanasyev0a61c342011-12-06 12:48:55 -080088 >,
89 boost::multi_index::ordered_non_unique<
90 boost::multi_index::tag<__ccnx_private::i_retx>,
91 boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount>
92 >
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070093 >
94 > type;
95};
96
97
98/**
99 * \ingroup ccnx
100 * \brief structure for PIT entry
101 */
102struct CcnxPitEntry
103{
104public:
105 /**
106 * \brief PIT entry constructor
107 * \param prefix Prefix of the PIT entry
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800108 * \param offsetTime Relative time to the current moment, representing PIT entry lifetime
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700109 * \param fibEntry A FIB entry associated with the PIT entry
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700110 */
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800111 CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &offsetTime, const CcnxFibEntry &fibEntry);
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 */
121 void
122 UpdateLifetime (const Time &offsetTime);
123
Alexander Afanasyev19426ef2011-11-23 20:55:28 -0800124 const CcnxNameComponents &
125 GetPrefix () const
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800126 { return *m_prefix; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700127
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800128 /**
129 * @brief Get current expiration time of the record
130 *
131 * @returns current expiration time of the record
132 */
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700133 const Time &
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800134 GetExpireTime () const
135 { return m_expireTime; }
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700136
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800137 /**
138 * @brief Set expiration time on record as `expireTime` (absolute time)
139 *
140 * @param expireTime absolute simulation time of when the record should expire
141 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800142 void
143 SetExpireTime (const Time &expireTime)
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800144 { m_expireTime = expireTime; }
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800145
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800146 /**
147 * @brief Check if nonce `nonce` for the same prefix has already been seen
148 *
149 * @param nonce Nonce to check
150 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800151 bool
152 IsNonceSeen (uint32_t nonce) const
153 { return m_seenNonces.find (nonce) != m_seenNonces.end (); }
154
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800155 /**
156 * @brief Add `nonce` to the list of seen nonces
157 *
158 * @param nonce nonce to add to the list of seen nonces
159 *
160 * All nonces are stored for the lifetime of the PIT entry
161 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800162 void
163 AddSeenNonce (uint32_t nonce)
164 { m_seenNonces.insert (nonce); }
165
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800166 /**
167 * @brief Add `face` to the list of incoming faces
168 *
169 * @param face Face to add to the list of incoming faces
170 * @returns iterator to the added entry
171 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800172 CcnxPitEntryIncomingFaceContainer::type::iterator
173 AddIncoming (Ptr<CcnxFace> face);
174
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800175 /**
Alexander Afanasyev9d313d42011-11-25 13:36:15 -0800176 * @brief Remove incoming entry for face `face`
177 */
178 void
179 RemoveIncoming (Ptr<CcnxFace> face);
180
181 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800182 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
183 */
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800184 void
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800185 ClearIncoming ()
186 { m_incoming.clear (); }
187
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800188 /**
189 * @brief Add `face` to the list of outgoing faces
190 *
191 * @param face Face to add to the list of outgoing faces
192 * @returns iterator to the added entry
193 */
Alexander Afanasyeva5bbe0e2011-11-22 17:28:39 -0800194 CcnxPitEntryOutgoingFaceContainer::type::iterator
195 AddOutgoing (Ptr<CcnxFace> face);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800196
197 /**
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800198 * @brief Clear all incoming faces either after all of them were satisfied or NACKed
199 */
200 void
201 ClearOutgoing ()
202 { m_outgoing.clear (); }
203
204 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800205 * @brief Remove all references to face.
206 *
207 * This method should be called before face is completely removed from the stack.
208 * Face is removed from the lists of incoming and outgoing faces
209 */
210 void
211 RemoveAllReferencesToFace (Ptr<CcnxFace> face);
212
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800213 /**
214 * @brief Flag outgoing face as hopeless
215 */
216 void
217 SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face);
218
219 /**
220 * @brief Check if all outgoing faces are NACKed
221 */
222 bool
223 AreAllOutgoingInVain () const;
Alexander Afanasyeva7a2b8b2011-11-28 18:19:09 -0800224
225 /*
226 * @brief Similar to AreAllOutgoingInVain, but ignores `face`
227 * \see AreAllOutgoingInVain
228 **/
229 bool
230 AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const;
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800231
232 /**
233 * @brief Increase maximum limit of allowed retransmission per outgoing face
234 */
235 void
236 IncreaseAllowedRetxCount ();
Alexander Afanasyev5a595072011-11-25 14:49:07 -0800237
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800238protected:
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800239
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700240private:
241 friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry);
Alexander Afanasyev07827182011-12-13 01:07:32 -0800242 /**
243 * \brief Default constructor
244 */
245 CcnxPitEntry () : m_fibEntry(*((CcnxFibEntry*)0)) {};
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700246
Alexander Afanasyev78cf0c92011-09-01 19:57:14 -0700247public:
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700248 Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700249 const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800250 std::set<uint32_t> m_seenNonces; ///< \brief map of nonces that were seen for this prefix
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700251
252 CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests
253 CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests
254
255 Time m_expireTime; ///< \brief Time when PIT entry will be removed
Alexander Afanasyev0a61c342011-12-06 12:48:55 -0800256
257 uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700258};
259
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -0700260} // namespace ns3
261
262#endif // _CCNX_PIT_ENTRY_H_