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 | { |
| 47 | class i_face {}; |
| 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>, |
| 65 | boost::multi_index::identity<CcnxPitEntryIncomingFace> |
| 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>, |
| 86 | boost::multi_index::identity<CcnxPitEntryOutgoingFace> |
| 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 |
| 103 | * \param fib A FIB entry associated with the PIT entry |
| 104 | */ |
| 105 | CcnxPitEntry (Ptr<CcnxNameComponents> prefix); |
| 106 | |
| 107 | // // Get number of outgoing interests that we're expecting data from |
| 108 | // inline size_t numberOfPromisingInterests( ) const; |
| 109 | |
| 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 | }; |
| 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 | /** |
| 140 | * \brief Unary function to add outgoing interest to PIT entry |
| 141 | * |
| 142 | * \param outgoingFace smart pointer to the face of the outgoing interest |
| 143 | * \returns const iterator to a newly added or updated |
| 144 | * CcnxPitOutgoingInterest entry |
| 145 | */ |
| 146 | struct AddOutgoing |
| 147 | { |
| 148 | AddOutgoing (Ptr<CcnxFace> outgoingFace) : m_face (outgoingFace) {} |
| 149 | void operator() (CcnxPitEntry &entry); |
| 150 | private: |
| 151 | Ptr<CcnxFace> m_face; |
| 152 | }; |
| 153 | |
| 154 | /** |
| 155 | * \brief Unary function to delete incoming interest for the interface |
| 156 | * \param face face that should be removed from the list of incoming interests |
| 157 | */ |
| 158 | struct DeleteIncoming |
| 159 | { |
| 160 | DeleteIncoming (Ptr<CcnxFace> face) : m_face (face) {} |
| 161 | void operator() (CcnxPitEntry &entry); |
| 162 | private: |
| 163 | Ptr<CcnxFace> m_face; |
| 164 | }; |
| 165 | |
| 166 | /** |
| 167 | * \brief Unary function to remove all incoming interests |
| 168 | */ |
| 169 | struct ClearIncoming |
| 170 | { |
| 171 | ClearIncoming (); |
| 172 | void operator() (CcnxPitEntry &entry); |
| 173 | }; |
| 174 | |
| 175 | const CcnxNameComponents & |
| 176 | GetPrefix () const; |
| 177 | |
| 178 | const Time & |
| 179 | GetExpireTime () const { return m_expireTime; } |
| 180 | |
| 181 | private: |
| 182 | friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 183 | |
| 184 | private: |
| 185 | Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry |
| 186 | Ptr<CcnxFibEntry> m_fib; ///< \brief FIB entry related to this prefix |
| 187 | |
| 188 | CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests |
| 189 | CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests |
| 190 | |
| 191 | Time m_expireTime; ///< \brief Time when PIT entry will be removed |
| 192 | bool m_timerExpired; ///< \brief flag indicating that PIT timer has expired |
| 193 | int m_counterExpirations; ///< \brief whether timer is expired (+ number of times timer expired) |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | } // namespace ns3 |
| 198 | |
| 199 | #endif // _CCNX_PIT_ENTRY_H_ |