blob: 025ef54e56ff18df8834dbc502fc6c21d221a1be [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 Afanasyev8566f452012-12-10 15:21:51 -080034public:
35 typedef Entry base_type;
36
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070037 typedef Entry super;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070038 #define CONTAINER static_cast<Pit&> (m_container)
39
40public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070041 EntryImpl (Pit &pit,
42 Ptr<const InterestHeader> header,
43 Ptr<fib::Entry> fibEntry)
44 : Entry (pit, header, fibEntry)
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070045 , item_ (0)
46 {
47 CONTAINER.i_time.insert (*this);
48 CONTAINER.RescheduleCleaning ();
49 }
50
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051 virtual ~EntryImpl ()
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070052 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070053 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070054
55 CONTAINER.RescheduleCleaning ();
56 }
57
58 virtual void
59 UpdateLifetime (const Time &offsetTime)
60 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070061 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070062 super::UpdateLifetime (offsetTime);
63 CONTAINER.i_time.insert (*this);
64
65 CONTAINER.RescheduleCleaning ();
66 }
67
Alexander Afanasyev08b7d9e2012-08-23 10:53:46 -070068 virtual void
69 OffsetLifetime (const Time &offsetTime)
70 {
71 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
72 super::OffsetLifetime (offsetTime);
73 CONTAINER.i_time.insert (*this);
74
75 CONTAINER.RescheduleCleaning ();
76 }
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070077
78 // to make sure policies work
79 void
80 SetTrie (typename Pit::super::iterator item) { item_ = item; }
81
82 typename Pit::super::iterator to_iterator () { return item_; }
83 typename Pit::super::const_iterator to_iterator () const { return item_; }
84
85public:
86 boost::intrusive::set_member_hook<> time_hook_;
87
88private:
89 typename Pit::super::iterator item_;
90};
91
92template<class T>
93struct TimestampIndex
94{
95 bool
96 operator () (const T &a, const T &b) const
97 {
98 return a.GetExpireTime () < b.GetExpireTime ();
99 }
100};
101
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700102} // namespace pit
103} // namespace ndn
104} // namespace ns3
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700105
106#endif