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" |
| 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 Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 37 | #include <set> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 38 | |
| 39 | #include <iostream> |
| 40 | |
| 41 | namespace ns3 { |
| 42 | |
| 43 | class CcnxFace; |
| 44 | class CcnxNameComponents; |
| 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 |
| 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 | */ |
| 60 | struct CcnxPitEntryIncomingFaceContainer |
| 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 | CcnxPitEntryIncomingFace, |
| 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<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 70 | > |
| 71 | > |
| 72 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 73 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | /** |
| 77 | * \ingroup ccnx |
| 78 | * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace |
| 79 | * |
| 80 | * Indexes: |
| 81 | * - by face (may be it will be possible to replace with just the std::map) |
| 82 | */ |
| 83 | struct CcnxPitEntryOutgoingFaceContainer |
| 84 | { |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 85 | /// @cond include_hidden |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 86 | typedef boost::multi_index::multi_index_container< |
| 87 | CcnxPitEntryOutgoingFace, |
| 88 | boost::multi_index::indexed_by< |
| 89 | // For fast access to elements using CcnxFace |
| 90 | boost::multi_index::ordered_unique< |
| 91 | boost::multi_index::tag<__ccnx_private::i_face>, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 92 | boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face> |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 93 | >, |
| 94 | boost::multi_index::ordered_non_unique< |
| 95 | boost::multi_index::tag<__ccnx_private::i_retx>, |
| 96 | boost::multi_index::member<CcnxPitEntryOutgoingFace, uint32_t, &CcnxPitEntryOutgoingFace::m_retxCount> |
| 97 | > |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 98 | > |
| 99 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 100 | /// @endcond |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * \ingroup ccnx |
| 106 | * \brief structure for PIT entry |
| 107 | */ |
| 108 | struct CcnxPitEntry |
| 109 | { |
| 110 | public: |
| 111 | /** |
| 112 | * \brief PIT entry constructor |
| 113 | * \param prefix Prefix of the PIT entry |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 114 | * \param offsetTime Relative time to the current moment, representing PIT entry lifetime |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 115 | * \param fibEntry A FIB entry associated with the PIT entry |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 116 | */ |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 117 | CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &offsetTime, const CcnxFibEntry &fibEntry); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 118 | |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 119 | /** |
| 120 | * @brief Update lifetime of PIT entry |
| 121 | * |
| 122 | * This function will update PIT entry lifetime to the maximum of the current lifetime and |
| 123 | * the lifetime Simulator::Now () + offsetTime |
| 124 | * |
| 125 | * @param offsetTime Relative time to the current moment, representing PIT entry lifetime |
| 126 | */ |
| 127 | void |
| 128 | UpdateLifetime (const Time &offsetTime); |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * @brief Get prefix of the PIT entry |
| 132 | */ |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 133 | const CcnxNameComponents & |
| 134 | GetPrefix () const |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 135 | { return *m_prefix; } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 137 | /** |
| 138 | * @brief Get current expiration time of the record |
| 139 | * |
| 140 | * @returns current expiration time of the record |
| 141 | */ |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 142 | const Time & |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 143 | GetExpireTime () const |
| 144 | { return m_expireTime; } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 145 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 146 | /** |
| 147 | * @brief Set expiration time on record as `expireTime` (absolute time) |
| 148 | * |
| 149 | * @param expireTime absolute simulation time of when the record should expire |
| 150 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 151 | void |
Alexander Afanasyev | 1aeaf92 | 2012-04-23 13:48:09 -0700 | [diff] [blame] | 152 | SetExpireTime (const Time &expireTime); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 153 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 154 | /** |
| 155 | * @brief Check if nonce `nonce` for the same prefix has already been seen |
| 156 | * |
| 157 | * @param nonce Nonce to check |
| 158 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 159 | bool |
| 160 | IsNonceSeen (uint32_t nonce) const |
| 161 | { return m_seenNonces.find (nonce) != m_seenNonces.end (); } |
| 162 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 163 | /** |
| 164 | * @brief Add `nonce` to the list of seen nonces |
| 165 | * |
| 166 | * @param nonce nonce to add to the list of seen nonces |
| 167 | * |
| 168 | * All nonces are stored for the lifetime of the PIT entry |
| 169 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 170 | void |
| 171 | AddSeenNonce (uint32_t nonce) |
| 172 | { m_seenNonces.insert (nonce); } |
| 173 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 174 | /** |
| 175 | * @brief Add `face` to the list of incoming faces |
| 176 | * |
| 177 | * @param face Face to add to the list of incoming faces |
| 178 | * @returns iterator to the added entry |
| 179 | */ |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 180 | CcnxPitEntryIncomingFaceContainer::type::iterator |
| 181 | AddIncoming (Ptr<CcnxFace> face); |
| 182 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 183 | /** |
Alexander Afanasyev | 9d313d4 | 2011-11-25 13:36:15 -0800 | [diff] [blame] | 184 | * @brief Remove incoming entry for face `face` |
| 185 | */ |
| 186 | void |
| 187 | RemoveIncoming (Ptr<CcnxFace> face); |
| 188 | |
| 189 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 190 | * @brief Clear all incoming faces either after all of them were satisfied or NACKed |
| 191 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 192 | void |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 193 | ClearIncoming () |
| 194 | { m_incoming.clear (); } |
| 195 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 196 | /** |
| 197 | * @brief Add `face` to the list of outgoing faces |
| 198 | * |
| 199 | * @param face Face to add to the list of outgoing faces |
| 200 | * @returns iterator to the added entry |
| 201 | */ |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 202 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 203 | AddOutgoing (Ptr<CcnxFace> face); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 204 | |
| 205 | /** |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 206 | * @brief Clear all incoming faces either after all of them were satisfied or NACKed |
| 207 | */ |
| 208 | void |
| 209 | ClearOutgoing () |
| 210 | { m_outgoing.clear (); } |
| 211 | |
| 212 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 213 | * @brief Remove all references to face. |
| 214 | * |
| 215 | * This method should be called before face is completely removed from the stack. |
| 216 | * Face is removed from the lists of incoming and outgoing faces |
| 217 | */ |
| 218 | void |
| 219 | RemoveAllReferencesToFace (Ptr<CcnxFace> face); |
| 220 | |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 221 | /** |
| 222 | * @brief Flag outgoing face as hopeless |
| 223 | */ |
| 224 | void |
| 225 | SetWaitingInVain (CcnxPitEntryOutgoingFaceContainer::type::iterator face); |
| 226 | |
| 227 | /** |
| 228 | * @brief Check if all outgoing faces are NACKed |
| 229 | */ |
| 230 | bool |
| 231 | AreAllOutgoingInVain () const; |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 232 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 233 | /** |
Alexander Afanasyev | a7a2b8b | 2011-11-28 18:19:09 -0800 | [diff] [blame] | 234 | * @brief Similar to AreAllOutgoingInVain, but ignores `face` |
| 235 | * \see AreAllOutgoingInVain |
| 236 | **/ |
| 237 | bool |
| 238 | AreTherePromisingOutgoingFacesExcept (Ptr<CcnxFace> face) const; |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 239 | |
| 240 | /** |
| 241 | * @brief Increase maximum limit of allowed retransmission per outgoing face |
| 242 | */ |
| 243 | void |
| 244 | IncreaseAllowedRetxCount (); |
Alexander Afanasyev | 5a59507 | 2011-11-25 14:49:07 -0800 | [diff] [blame] | 245 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 246 | protected: |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 247 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 248 | private: |
| 249 | friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 250 | /** |
| 251 | * \brief Default constructor |
| 252 | */ |
| 253 | CcnxPitEntry () : m_fibEntry(*((CcnxFibEntry*)0)) {}; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 254 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 255 | public: |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 256 | Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 257 | const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 258 | std::set<uint32_t> m_seenNonces; ///< \brief map of nonces that were seen for this prefix |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 259 | |
| 260 | CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests |
| 261 | CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests |
| 262 | |
| 263 | Time m_expireTime; ///< \brief Time when PIT entry will be removed |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 264 | |
Alexander Afanasyev | 7f3e49e | 2012-04-30 00:17:07 -0700 | [diff] [blame] | 265 | Time m_lastRetransmission; ///< @brief Last time when number of retransmissions were increased |
Alexander Afanasyev | 0a61c34 | 2011-12-06 12:48:55 -0800 | [diff] [blame] | 266 | 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] | 267 | }; |
| 268 | |
Alexander Afanasyev | a95b739 | 2012-03-09 10:54:10 -0800 | [diff] [blame] | 269 | std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 270 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 271 | } // namespace ns3 |
| 272 | |
| 273 | #endif // _CCNX_PIT_ENTRY_H_ |