Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -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_IMPL_H_ |
| 22 | #define _CCNX_PIT_IMPL_H_ |
| 23 | |
| 24 | #include "ccnx-pit.h" |
| 25 | #include "../utils/trie-with-policy.h" |
| 26 | #include "../utils/empty-policy.h" |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 27 | #include "../utils/persistent-policy.h" |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 28 | #include "ns3/ccnx-name-components.h" |
| 29 | |
| 30 | namespace ns3 { |
| 31 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 32 | template<class Pit> |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 33 | class CcnxPitEntryImpl : public CcnxPitEntry |
| 34 | { |
| 35 | public: |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 36 | CcnxPitEntryImpl (CcnxPit &pit, |
| 37 | Ptr<const CcnxInterestHeader> header, |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 38 | Ptr<CcnxFibEntry> fibEntry) |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 39 | : CcnxPitEntry (pit, header, fibEntry) |
| 40 | , item_ (0) |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 41 | { |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 42 | static_cast<Pit&> (m_container).i_time.insert (*this); |
| 43 | } |
| 44 | |
| 45 | virtual ~CcnxPitEntryImpl () |
| 46 | { |
| 47 | static_cast<Pit&> (m_container).i_time.erase (*this); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 50 | // to make sure policies work |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 51 | void |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 52 | SetTrie (typename Pit::super::iterator item) { item_ = item; } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 54 | typename Pit::super::iterator to_iterator () { return item_; } |
| 55 | typename Pit::super::const_iterator to_iterator () const { return item_; } |
| 56 | |
| 57 | public: |
| 58 | boost::intrusive::set_member_hook<> time_hook_; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 61 | typename Pit::super::iterator item_; |
| 62 | }; |
| 63 | |
| 64 | template<class T> |
| 65 | struct TimestampIndex |
| 66 | { |
| 67 | bool |
| 68 | operator () (const T &a, const T &b) const |
| 69 | { |
| 70 | return a.GetExpireTime () < b.GetExpireTime (); |
| 71 | } |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | //////////////////////////////////////////////////////////////////////// |
| 75 | //////////////////////////////////////////////////////////////////////// |
| 76 | |
| 77 | /** |
| 78 | * \ingroup ccnx |
| 79 | * \brief Class implementing Pending Interests Table |
| 80 | */ |
| 81 | class CcnxPitImpl : public CcnxPit |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 82 | , protected ndnSIM::trie_with_policy<CcnxNameComponents, |
| 83 | ndnSIM::smart_pointer_payload_traits<CcnxPitEntryImpl< CcnxPitImpl > >, |
| 84 | ndnSIM::persistent_policy_traits |
| 85 | > |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 86 | { |
| 87 | public: |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 88 | typedef ndnSIM::trie_with_policy<CcnxNameComponents, |
| 89 | ndnSIM::smart_pointer_payload_traits<CcnxPitEntryImpl< CcnxPitImpl > >, |
| 90 | ndnSIM::persistent_policy_traits |
| 91 | > super; |
| 92 | typedef CcnxPitEntryImpl< CcnxPitImpl > entry; |
| 93 | |
| 94 | // typedef CcnxPitEntryImpl::trie super; |
Alexander Afanasyev | 1aa4bbc | 2012-07-09 17:17:25 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 96 | /** |
| 97 | * \brief Interface ID |
| 98 | * |
| 99 | * \return interface ID |
| 100 | */ |
| 101 | static TypeId GetTypeId (); |
| 102 | |
| 103 | /** |
| 104 | * \brief PIT constructor |
| 105 | */ |
| 106 | CcnxPitImpl (); |
| 107 | |
| 108 | /** |
| 109 | * \brief Destructor |
| 110 | */ |
| 111 | virtual ~CcnxPitImpl (); |
| 112 | |
| 113 | // inherited from CcnxPit |
| 114 | virtual Ptr<CcnxPitEntry> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 115 | Lookup (const CcnxContentObjectHeader &header); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 116 | |
| 117 | virtual Ptr<CcnxPitEntry> |
| 118 | Lookup (const CcnxInterestHeader &header); |
| 119 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 120 | virtual Ptr<CcnxPitEntry> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 121 | Create (Ptr<const CcnxInterestHeader> header); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 122 | |
| 123 | virtual void |
| 124 | MarkErased (Ptr<CcnxPitEntry> entry); |
| 125 | |
| 126 | virtual void |
| 127 | Print (std::ostream &os) const; |
Alexander Afanasyev | 1aa4bbc | 2012-07-09 17:17:25 -0700 | [diff] [blame] | 128 | |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 129 | virtual Ptr<CcnxPitEntry> |
| 130 | Begin (); |
| 131 | |
| 132 | virtual Ptr<CcnxPitEntry> |
| 133 | End (); |
| 134 | |
| 135 | virtual Ptr<CcnxPitEntry> |
| 136 | Next (Ptr<CcnxPitEntry>); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 137 | |
| 138 | protected: |
| 139 | // inherited from CcnxPit |
| 140 | virtual void DoCleanExpired (); |
| 141 | |
| 142 | // inherited from Object class |
| 143 | virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object |
| 144 | virtual void DoDispose (); ///< @brief Do cleanup |
| 145 | |
| 146 | private: |
| 147 | uint32_t |
| 148 | GetMaxSize () const; |
| 149 | |
| 150 | void |
| 151 | SetMaxSize (uint32_t maxSize); |
| 152 | |
| 153 | private: |
| 154 | Ptr<CcnxFib> m_fib; ///< \brief Link to FIB table |
Alexander Afanasyev | 36b4577 | 2012-07-10 16:57:42 -0700 | [diff] [blame^] | 155 | |
| 156 | // indexes |
| 157 | typedef |
| 158 | boost::intrusive::set<entry, |
| 159 | boost::intrusive::compare < TimestampIndex< entry > >, |
| 160 | boost::intrusive::member_hook< entry, |
| 161 | boost::intrusive::set_member_hook<>, |
| 162 | &entry::time_hook_> |
| 163 | > expireTimeIndexType; |
| 164 | expireTimeIndexType i_time; |
| 165 | |
| 166 | friend class CcnxPitEntryImpl< CcnxPitImpl >; |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | } // namespace ns3 |
| 170 | |
| 171 | #endif /* CCNX_PIT_IMPL_H */ |