Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 25 | #include "ns3/simple-ref-count.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 27 | #include "ns3/ccnx-fib.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 28 | #include "ccnx-pit-entry-incoming-face.h" |
| 29 | #include "ccnx-pit-entry-outgoing-face.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 30 | |
| 31 | #include <boost/multi_index_container.hpp> |
| 32 | #include <boost/multi_index/tag.hpp> |
| 33 | #include <boost/multi_index/ordered_index.hpp> |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 34 | // #include <boost/multi_index/composite_key.hpp> |
| 35 | // #include <boost/multi_index/hashed_index.hpp> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 36 | #include <boost/multi_index/member.hpp> |
Alexander Afanasyev | 9a98970 | 2012-06-29 17:44:00 -0700 | [diff] [blame] | 37 | // #include <boost/multi_index/mem_fun.hpp> |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 38 | #include <set> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 39 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 40 | namespace ns3 { |
| 41 | |
| 42 | class CcnxFace; |
| 43 | class CcnxNameComponents; |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 44 | class CcnxPit; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 46 | /// @cond include_hidden |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 47 | namespace __ccnx_private |
| 48 | { |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 49 | class i_retx {}; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 50 | } |
Alexander Afanasyev | 6315ef7 | 2012-06-01 20:56:31 -0700 | [diff] [blame] | 51 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * \ingroup ccnx |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 55 | * \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 | */ |
| 60 | struct CcnxPitEntryOutgoingFaceContainer |
| 61 | { |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 62 | /// @cond include_hidden |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 63 | 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 Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 69 | boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face> |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 70 | >, |
| 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 Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 75 | > |
| 76 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 77 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | * \ingroup ccnx |
| 83 | * \brief structure for PIT entry |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 84 | * |
| 85 | * All set-methods are virtual, in case index rearrangement is necessary in the derived classes |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 86 | */ |
Alexander Afanasyev | 0560eec | 2012-07-16 15:44:31 -0700 | [diff] [blame] | 87 | class CcnxPitEntry : public SimpleRefCount<CcnxPitEntry> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 88 | { |
| 89 | public: |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 90 | typedef std::set< CcnxPitEntryIncomingFace > in_container; ///< @brief incoming faces container type |
| 91 | typedef in_container::iterator in_iterator; ///< @brief iterator to incoming faces |
| 92 | |
| 93 | typedef CcnxPitEntryOutgoingFaceContainer::type out_container; ///< @brief outgoing faces container type |
| 94 | typedef out_container::iterator out_iterator; ///< @brief iterator to outgoing faces |
| 95 | |
| 96 | typedef std::set< uint32_t > nonce_container; ///< @brief nonce container type |
| 97 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 98 | /** |
| 99 | * \brief PIT entry constructor |
| 100 | * \param prefix Prefix of the PIT entry |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 101 | * \param offsetTime Relative time to the current moment, representing PIT entry lifetime |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 102 | * \param fibEntry A FIB entry associated with the PIT entry |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 103 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 104 | CcnxPitEntry (CcnxPit &container, Ptr<const CcnxInterestHeader> header, Ptr<CcnxFibEntry> fibEntry); |
| 105 | |
| 106 | /** |
| 107 | * @brief Virtual destructor |
| 108 | */ |
| 109 | virtual ~CcnxPitEntry () {} |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 111 | /** |
| 112 | * @brief Update lifetime of PIT entry |
| 113 | * |
| 114 | * This function will update PIT entry lifetime to the maximum of the current lifetime and |
| 115 | * the lifetime Simulator::Now () + offsetTime |
| 116 | * |
| 117 | * @param offsetTime Relative time to the current moment, representing PIT entry lifetime |
| 118 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 119 | virtual void |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 120 | UpdateLifetime (const Time &offsetTime); |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * @brief Get prefix of the PIT entry |
| 124 | */ |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 125 | const CcnxNameComponents & |
| 126 | GetPrefix () const |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 127 | { return *m_prefix; } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 128 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 129 | /** |
| 130 | * @brief Get current expiration time of the record |
| 131 | * |
| 132 | * @returns current expiration time of the record |
| 133 | */ |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 134 | const Time & |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 135 | GetExpireTime () const |
| 136 | { return m_expireTime; } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 137 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 138 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 139 | * @brief Check if nonce `nonce` for the same prefix has already been seen |
| 140 | * |
| 141 | * @param nonce Nonce to check |
| 142 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 143 | bool |
| 144 | IsNonceSeen (uint32_t nonce) const |
| 145 | { return m_seenNonces.find (nonce) != m_seenNonces.end (); } |
| 146 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 147 | /** |
| 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 Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 154 | virtual void |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 155 | AddSeenNonce (uint32_t nonce) |
| 156 | { m_seenNonces.insert (nonce); } |
| 157 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 158 | /** |
| 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 Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 164 | virtual in_iterator |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 165 | AddIncoming (Ptr<CcnxFace> face); |
| 166 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 167 | /** |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 168 | * @brief Remove incoming entry for face `face` |
| 169 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 170 | virtual void |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 171 | RemoveIncoming (Ptr<CcnxFace> face); |
| 172 | |
| 173 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 174 | * @brief Clear all incoming faces either after all of them were satisfied or NACKed |
| 175 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 176 | virtual void |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 177 | ClearIncoming () |
| 178 | { m_incoming.clear (); } |
| 179 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 180 | /** |
| 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 Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 186 | virtual out_iterator |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 187 | AddOutgoing (Ptr<CcnxFace> face); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 188 | |
| 189 | /** |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 190 | * @brief Clear all incoming faces either after all of them were satisfied or NACKed |
| 191 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 192 | virtual void |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 193 | ClearOutgoing () |
| 194 | { m_outgoing.clear (); } |
| 195 | |
| 196 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 197 | * @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 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 202 | virtual void |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 203 | RemoveAllReferencesToFace (Ptr<CcnxFace> face); |
| 204 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 205 | /** |
| 206 | * @brief Flag outgoing face as hopeless |
| 207 | */ |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 208 | // virtual void |
| 209 | // SetWaitingInVain (out_iterator face); |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 210 | virtual void |
Alexander Afanasyev | 786936a | 2012-07-17 19:48:15 -0700 | [diff] [blame] | 211 | SetWaitingInVain (Ptr<CcnxFace> face); |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * @brief Check if all outgoing faces are NACKed |
| 215 | */ |
| 216 | bool |
| 217 | AreAllOutgoingInVain () const; |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 219 | /** |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 220 | * @brief Similar to AreAllOutgoingInVain, but ignores `face` |
| 221 | * \see AreAllOutgoingInVain |
| 222 | **/ |
| 223 | bool |
| 224 | AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const; |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 225 | |
| 226 | /** |
| 227 | * @brief Increase maximum limit of allowed retransmission per outgoing face |
| 228 | */ |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 229 | virtual void |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 230 | IncreaseAllowedRetxCount (); |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 231 | |
| 232 | Ptr<CcnxFibEntry> |
| 233 | GetFibEntry () { return m_fibEntry; }; |
| 234 | |
| 235 | const in_container & |
| 236 | GetIncoming () const { return m_incoming; } |
| 237 | |
| 238 | const out_container & |
| 239 | GetOutgoing () const { return m_outgoing; } |
| 240 | |
| 241 | uint32_t |
| 242 | GetMaxRetxCount () const { return m_maxRetxCount; } |
| 243 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 244 | private: |
| 245 | friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 246 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame] | 247 | protected: |
| 248 | CcnxPit &m_container; ///< @brief Reference to the container (to rearrange indexes, if necessary) |
| 249 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 250 | Ptr<const CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry |
| 251 | Ptr<CcnxFibEntry> m_fibEntry; ///< \brief FIB entry related to this prefix |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 253 | nonce_container m_seenNonces; ///< \brief map of nonces that were seen for this prefix |
| 254 | in_container m_incoming; ///< \brief container for incoming interests |
| 255 | out_container m_outgoing; ///< \brief container for outgoing interests |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 256 | |
| 257 | Time m_expireTime; ///< \brief Time when PIT entry will be removed |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 258 | |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 259 | Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 260 | uint32_t m_maxRetxCount; ///< @brief Maximum allowed number of retransmissions via outgoing faces |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
Alexander Afanasyev | a95b739 | 2012-03-09 10:54:10 -0800 | [diff] [blame] | 263 | std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 264 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 265 | } // namespace ns3 |
| 266 | |
| 267 | #endif // _CCNX_PIT_ENTRY_H_ |