blob: 13cceb5960f05dda98a9806fe4bc6b38902dea35 [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 {
25
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070026class NdnPit;
27class NdnInterestHeader;
28class NdnFibEntry;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070029
30template<class Pit>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070031class NdnPitEntryImpl : public NdnPitEntry
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070032{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033 typedef NdnPitEntry super;
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070034 #define CONTAINER static_cast<Pit&> (m_container)
35
36public:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070037 NdnPitEntryImpl (NdnPit &pit,
38 Ptr<const NdnInterestHeader> header,
39 Ptr<NdnFibEntry> fibEntry)
40 : NdnPitEntry (pit, header, fibEntry)
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070041 , item_ (0)
42 {
43 CONTAINER.i_time.insert (*this);
44 CONTAINER.RescheduleCleaning ();
45 }
46
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047 virtual ~NdnPitEntryImpl ()
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070048 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070049 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070050
51 CONTAINER.RescheduleCleaning ();
52 }
53
54 virtual void
55 UpdateLifetime (const Time &offsetTime)
56 {
Alexander Afanasyevad82e252012-07-29 23:51:21 -070057 CONTAINER.i_time.erase (Pit::time_index::s_iterator_to (*this));
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070058 super::UpdateLifetime (offsetTime);
59 CONTAINER.i_time.insert (*this);
60
61 CONTAINER.RescheduleCleaning ();
62 }
63
64
65 // to make sure policies work
66 void
67 SetTrie (typename Pit::super::iterator item) { item_ = item; }
68
69 typename Pit::super::iterator to_iterator () { return item_; }
70 typename Pit::super::const_iterator to_iterator () const { return item_; }
71
72public:
73 boost::intrusive::set_member_hook<> time_hook_;
74
75private:
76 typename Pit::super::iterator item_;
77};
78
79template<class T>
80struct TimestampIndex
81{
82 bool
83 operator () (const T &a, const T &b) const
84 {
85 return a.GetExpireTime () < b.GetExpireTime ();
86 }
87};
88
89} // ns3
90
91#endif