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 | |
| 46 | namespace __ccnx_private |
| 47 | { |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 48 | // class i_face {}; |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 49 | } |
| 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 | */ |
| 58 | struct 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 Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 66 | boost::multi_index::member<CcnxPitEntryIncomingFace, Ptr<CcnxFace>, &CcnxPitEntryIncomingFace::m_face> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 67 | > |
| 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 | */ |
| 79 | struct 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 Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 87 | boost::multi_index::member<CcnxPitEntryOutgoingFace, Ptr<CcnxFace>, &CcnxPitEntryOutgoingFace::m_face> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 88 | > |
| 89 | > |
| 90 | > type; |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | /** |
| 95 | * \ingroup ccnx |
| 96 | * \brief structure for PIT entry |
| 97 | */ |
| 98 | struct CcnxPitEntry |
| 99 | { |
| 100 | public: |
| 101 | /** |
| 102 | * \brief PIT entry constructor |
| 103 | * \param prefix Prefix of the PIT entry |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 104 | * \param fibEntry A FIB entry associated with the PIT entry |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 105 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 106 | CcnxPitEntry (Ptr<CcnxNameComponents> prefix, const Time &expireTime, const CcnxFibEntry &fibEntry); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 107 | |
| 108 | // // Get number of outgoing interests that we're expecting data from |
| 109 | // inline size_t numberOfPromisingInterests( ) const; |
| 110 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 111 | const CcnxNameComponents & |
| 112 | GetPrefix () const; |
| 113 | |
| 114 | const Time & |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 115 | GetExpireTime () const |
| 116 | { return m_expireTime; } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 118 | void |
| 119 | SetExpireTime (const Time &expireTime) |
| 120 | { |
| 121 | m_expireTime = expireTime; |
| 122 | } |
| 123 | |
| 124 | bool |
| 125 | IsNonceSeen (uint32_t nonce) const |
| 126 | { return m_seenNonces.find (nonce) != m_seenNonces.end (); } |
| 127 | |
| 128 | void |
| 129 | AddSeenNonce (uint32_t nonce) |
| 130 | { m_seenNonces.insert (nonce); } |
| 131 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 132 | CcnxPitEntryIncomingFaceContainer::type::iterator |
| 133 | AddIncoming (Ptr<CcnxFace> face); |
| 134 | |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 135 | void |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame^] | 136 | ClearIncoming () |
| 137 | { m_incoming.clear (); } |
| 138 | |
| 139 | CcnxPitEntryOutgoingFaceContainer::type::iterator |
| 140 | AddOutgoing (Ptr<CcnxFace> face); |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 142 | private: |
| 143 | friend std::ostream& operator<< (std::ostream& os, const CcnxPitEntry &entry); |
| 144 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 145 | public: |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 146 | Ptr<CcnxNameComponents> m_prefix; ///< \brief Prefix of the PIT entry |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 147 | const CcnxFibEntry &m_fibEntry; ///< \brief FIB entry related to this prefix |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 148 | 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] | 149 | |
| 150 | CcnxPitEntryIncomingFaceContainer::type m_incoming; ///< \brief container for incoming interests |
| 151 | CcnxPitEntryOutgoingFaceContainer::type m_outgoing; ///< \brief container for outgoing interests |
| 152 | |
| 153 | Time m_expireTime; ///< \brief Time when PIT entry will be removed |
| 154 | bool m_timerExpired; ///< \brief flag indicating that PIT timer has expired |
| 155 | int m_counterExpirations; ///< \brief whether timer is expired (+ number of times timer expired) |
| 156 | }; |
| 157 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 158 | } // namespace ns3 |
| 159 | |
| 160 | #endif // _CCNX_PIT_ENTRY_H_ |