blob: 6af9cc51b4598f3aacd9ae501cf00d0141c025cc [file] [log] [blame]
Alexander Afanasyev413c7f12012-07-10 17:35:16 -07001/* -*- 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 Afanasyev4aac5572012-08-09 10:49:55 -070021#ifndef _NDN_PIT_ENTRY_IMPL_H_
22#define _NDN_PIT_ENTRY_IMPL_H_
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070023
24namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070025namespace ndn {
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070026
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070027class Pit;
28
29namespace pit {
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070030
31template<class Pit>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032class EntryImpl : public Entry
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070033{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034 typedef Entry super;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070035 #define CONTAINER static_cast<Pit&> (m_container)
36
37public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038 EntryImpl (Pit &pit,
39 Ptr<const InterestHeader> header,
40 Ptr<fib::Entry> fibEntry)
41 : Entry (pit, header, fibEntry)
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070042 , item_ (0)
43 {
44 CONTAINER.i_time.insert (*this);
45 CONTAINER.RescheduleCleaning ();
46 }
47
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048 virtual ~EntryImpl ()
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070049 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070050 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070051
52 CONTAINER.RescheduleCleaning ();
53 }
54
55 virtual void
56 UpdateLifetime (const Time &offsetTime)
57 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070058 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070059 super::UpdateLifetime (offsetTime);
60 CONTAINER.i_time.insert (*this);
61
62 CONTAINER.RescheduleCleaning ();
63 }
64
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -070065 virtual void
66 OffsetLifetime (const Time &offsetTime)
67 {
68 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
69 super::OffsetLifetime (offsetTime);
70 CONTAINER.i_time.insert (*this);
71
72 CONTAINER.RescheduleCleaning ();
73 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070074
75 // to make sure policies work
76 void
77 SetTrie (typename Pit::super::iterator item) { item_ = item; }
78
79 typename Pit::super::iterator to_iterator () { return item_; }
80 typename Pit::super::const_iterator to_iterator () const { return item_; }
81
82public:
83 boost::intrusive::set_member_hook<> time_hook_;
84
85private:
86 typename Pit::super::iterator item_;
87};
88
89template<class T>
90struct TimestampIndex
91{
92 bool
93 operator () (const T &a, const T &b) const
94 {
95 return a.GetExpireTime () < b.GetExpireTime ();
96 }
97};
98
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070099} // namespace pit
100} // namespace ndn
101} // namespace ns3
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700102
103#endif