Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef _NDN_PIT_ENTRY_IMPL_H_ |
| 22 | #define _NDN_PIT_ENTRY_IMPL_H_ |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 23 | |
| 24 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 25 | namespace ndn { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 27 | class Pit; |
| 28 | |
| 29 | namespace pit { |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 31 | /** |
| 32 | * @ingroup ndn-pit |
| 33 | * @brief PIT entry implementation with additional pointers to the underlying container |
| 34 | */ |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 35 | template<class Pit> |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 36 | class EntryImpl : public Entry |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 37 | { |
Alexander Afanasyev | 8566f45 | 2012-12-10 15:21:51 -0800 | [diff] [blame] | 38 | public: |
| 39 | typedef Entry base_type; |
| 40 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | typedef Entry super; |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 42 | #define CONTAINER static_cast<Pit&> (m_container) |
| 43 | |
| 44 | public: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 45 | EntryImpl (Pit &pit, |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 46 | Ptr<const Interest> header, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 47 | Ptr<fib::Entry> fibEntry) |
| 48 | : Entry (pit, header, fibEntry) |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 49 | , item_ (0) |
| 50 | { |
| 51 | CONTAINER.i_time.insert (*this); |
| 52 | CONTAINER.RescheduleCleaning (); |
| 53 | } |
| 54 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 55 | virtual ~EntryImpl () |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 56 | { |
Alexander Afanasyev | ad82e25 | 2012-07-29 23:51:21 -0700 | [diff] [blame] | 57 | CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this)); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 58 | |
| 59 | CONTAINER.RescheduleCleaning (); |
| 60 | } |
| 61 | |
| 62 | virtual void |
| 63 | UpdateLifetime (const Time &offsetTime) |
| 64 | { |
Alexander Afanasyev | ad82e25 | 2012-07-29 23:51:21 -0700 | [diff] [blame] | 65 | CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this)); |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 66 | super::UpdateLifetime (offsetTime); |
| 67 | CONTAINER.i_time.insert (*this); |
| 68 | |
| 69 | CONTAINER.RescheduleCleaning (); |
| 70 | } |
| 71 | |
Alexander Afanasyev | 08b7d9e | 2012-08-23 10:53:46 -0700 | [diff] [blame] | 72 | virtual void |
| 73 | OffsetLifetime (const Time &offsetTime) |
| 74 | { |
| 75 | CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this)); |
| 76 | super::OffsetLifetime (offsetTime); |
| 77 | CONTAINER.i_time.insert (*this); |
| 78 | |
| 79 | CONTAINER.RescheduleCleaning (); |
| 80 | } |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 81 | |
| 82 | // to make sure policies work |
| 83 | void |
| 84 | SetTrie (typename Pit::super::iterator item) { item_ = item; } |
| 85 | |
| 86 | typename Pit::super::iterator to_iterator () { return item_; } |
| 87 | typename Pit::super::const_iterator to_iterator () const { return item_; } |
| 88 | |
| 89 | public: |
| 90 | boost::intrusive::set_member_hook<> time_hook_; |
| 91 | |
| 92 | private: |
| 93 | typename Pit::super::iterator item_; |
| 94 | }; |
| 95 | |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 96 | /// @cond include_hidden |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 97 | template<class T> |
| 98 | struct TimestampIndex |
| 99 | { |
| 100 | bool |
| 101 | operator () (const T &a, const T &b) const |
| 102 | { |
| 103 | return a.GetExpireTime () < b.GetExpireTime (); |
| 104 | } |
| 105 | }; |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 106 | /// @endcond |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 108 | } // namespace pit |
| 109 | } // namespace ndn |
| 110 | } // namespace ns3 |
Alexander Afanasyev | 413c7f1 | 2012-07-10 17:35:16 -0700 | [diff] [blame] | 111 | |
| 112 | #endif |