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> |
| 37 | |
| 38 | #include <iostream> |
| 39 | |
| 40 | namespace ns3 { |
| 41 | |
| 42 | class CcnxFace; |
| 43 | class CcnxNameComponents; |
| 44 | |
| 45 | namespace __ccnx_private |
| 46 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 47 | // class i_face {}; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | /** |
| 51 | * \ingroup ccnx |
| 52 | * \brief Typedef for indexed face container of CcnxPitEntryIncomingFace |
| 53 | * |
| 54 | * Indexes: |
| 55 | * - by face (may be it will be possible to replace with just the std::map) |
| 56 | */ |
| 57 | struct CcnxPitEntryIncomingFaceContainer |
| 58 | { |
| 59 | typedef boost::multi_index::multi_index_container< |
| 60 | CcnxPitEntryIncomingFace, |
| 61 | boost::multi_index::indexed_by< |
| 62 | // For fast access to elements using CcnxFace |
| 63 | boost::multi_index::ordered_unique< |
| 64 | boost::multi_index::tag<__ccnx_private::i_face>, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 65 | boost::multi_index::member<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 66 | > |
| 67 | > |
| 68 | > type; |
| 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * \ingroup ccnx |
| 73 | * \brief Typedef for indexed face container of CcnxPitEntryOutgoingFace |
| 74 | * |
| 75 | * Indexes: |
| 76 | * - by face (may be it will be possible to replace with just the std::map) |
| 77 | */ |
| 78 | struct CcnxPitEntryOutgoingFaceContainer |
| 79 | { |
| 80 | typedef boost::multi_index::multi_index_container< |
| 81 | CcnxPitEntryOutgoingFace, |
| 82 | boost::multi_index::indexed_by< |
| 83 | // For fast access to elements using CcnxFace |
| 84 | boost::multi_index::ordered_unique< |
| 85 | boost::multi_index::tag<__ccnx_private::i_face>, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 86 | boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 87 | > |
| 88 | > |
| 89 | > type; |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | /** |
| 94 | * \ingroup ccnx |
| 95 | * \brief structure for PIT entry |
| 96 | */ |
| 97 | struct CcnxPitEntry |
| 98 | { |
| 99 | public: |
| 100 | /** |
| 101 | * \brief PIT entry constructor |
| 102 | * \param prefix Prefix of the PIT entry |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 103 | * \param fibEntry A FIB entry associated with the PIT entry |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 104 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 105 | CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const CcnxFibEntry &fibEntry); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 106 | |
| 107 | // // Get number of outgoing interests that we're expecting data from |
| 108 | // inline size_t numberOfPromisingInterests( ) const; |
| 109 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 110 | // /** |
| 111 | // * \brief Unary function to set or update FIB entry with this PIT entry |
| 112 | // * \param fib smart pointer to FIB entry |
| 113 | // */ |
| 114 | // struct SetFibEntry |
| 115 | // { |
| 116 | // SetFibEntry (Ptr<CcnxFibEntry> fib); |
| 117 | // void operator() (CcnxPitEntry &entry); |
| 118 | // private: |
| 119 | // Ptr<CcnxFibEntry> m_fib; |
| 120 | // }; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * \brief Unary Function to add incoming interest to the PIT entry |
| 124 | * |
| 125 | * \param incomingFace smart pointer to the face of the incoming interest |
| 126 | * \returns const iterator to a newly added or updated |
| 127 | * CcnxPitIncomingInterest entry |
| 128 | */ |
| 129 | struct AddIncoming |
| 130 | { |
| 131 | AddIncoming (Ptr<CcnxFace> incomingFace) : m_face (incomingFace) {} |
| 132 | void operator() (CcnxPitEntry &entry); |
| 133 | |
| 134 | private: |
| 135 | Ptr<CcnxFace> m_face; |
| 136 | Time m_lifeTime; |
| 137 | }; |
| 138 | |
| 139 | /** |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 140 | * \brief Unary function to delete incoming interest for the interface |
| 141 | * \param face face that should be removed from the list of incoming interests |
| 142 | */ |
| 143 | struct DeleteIncoming |
| 144 | { |
| 145 | DeleteIncoming (Ptr<CcnxFace> face) : m_face (face) {} |
| 146 | void operator() (CcnxPitEntry &entry); |
| 147 | private: |
| 148 | Ptr<CcnxFace> m_face; |
| 149 | }; |
| 150 | |
| 151 | /** |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 152 | * \brief Unary function to add outgoing interest to PIT entry |
| 153 | * |
| 154 | * \param outgoingFace smart pointer to the face of the outgoing interest |
| 155 | * \returns const iterator to a newly added or updated |
| 156 | * CcnxPitOutgoingInterest entry |
| 157 | */ |
| 158 | struct AddOutgoing |
| 159 | { |
| 160 | AddOutgoing (Ptr<CcnxFace> outgoingFace) : m_face (outgoingFace) {} |
| 161 | void operator() (CcnxPitEntry &entry); |
| 162 | private: |
| 163 | Ptr<CcnxFace> m_face; |
| 164 | }; |
| 165 | |
| 166 | /** |
| 167 | * \brief Unary function to delete incoming interest for the interface |
| 168 | * \param face face that should be removed from the list of incoming interests |
| 169 | */ |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 170 | struct DeleteOutgoing |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 171 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 172 | DeleteOutgoing (Ptr<CcnxFace> face) : m_face (face) {} |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 173 | void operator() (CcnxPitEntry &entry); |
| 174 | private: |
| 175 | Ptr<CcnxFace> m_face; |
| 176 | }; |
| 177 | |
| 178 | /** |
| 179 | * \brief Unary function to remove all incoming interests |
| 180 | */ |
| 181 | struct ClearIncoming |
| 182 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 183 | ClearIncoming () {}; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 184 | void operator() (CcnxPitEntry &entry); |
| 185 | }; |
| 186 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 187 | /** |
| 188 | * \brief Unary function to update FIB status |
| 189 | */ |
| 190 | struct UpdateFibStatus |
| 191 | { |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 192 | UpdateFibStatus (Ptr<CcnxFace> face, CcnxFibFaceMetric::Status status, Ptr<CcnxFib> fib); |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 193 | void operator() (CcnxPitEntry &entry); |
| 194 | private: |
| 195 | Ptr<CcnxFace> m_face; |
| 196 | CcnxFibFaceMetric::Status m_status; |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 197 | Ptr<CcnxFib> m_fib; |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | /** |
| 201 | * \brief Unary function to estimate RTT and update smoothed RTT value in FIB |
| 202 | * \param outFace iterator of the outgoing face entry |
| 203 | */ |
| 204 | struct EstimateRttAndRemoveFace |
| 205 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 206 | EstimateRttAndRemoveFace (CcnxPitEntryOutgoingFaceContainer::type::iterator outFace, Ptr<CcnxFib> fib) |
| 207 | : m_outFace (outFace), m_fib (fib) { }; |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 208 | void operator() (CcnxPitEntry &entry); |
| 209 | private: |
| 210 | CcnxPitEntryOutgoingFaceContainer::type::iterator m_outFace; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 211 | Ptr<CcnxFib> m_fib; |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 214 | const CcnxNameComponents & |
| 215 | GetPrefix () const; |
| 216 | |
| 217 | const Time & |
| 218 | GetExpireTime () const { return m_expireTime; } |
| 219 | |
| 220 | private: |
| 221 | friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 222 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 223 | public: |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 224 | Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 225 | const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 226 | |
| 227 | CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests |
| 228 | CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests |
| 229 | |
| 230 | Time m_expireTime; ///< \brief Time when PIT entry will be removed |
| 231 | bool m_timerExpired; ///< \brief flag indicating that PIT timer has expired |
| 232 | int m_counterExpirations; ///< \brief whether timer is expired (+ number of times timer expired) |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | } // namespace ns3 |
| 237 | |
| 238 | #endif // _CCNX_PIT_ENTRY_H_ |