blob: 00cfe3c4c01d616687661810070e3e2b0206c0bf [file] [log] [blame]
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -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_IMPL_H_
22#define _NDN_PIT_IMPL_H_
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070023
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ndn-pit.h"
Alexander Afanasyeve3d126f2012-07-16 17:07:31 -070025
Alexander Afanasyev1a2df6a2012-08-17 13:21:51 -070026#include "../../utils/trie/trie-with-policy.h"
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070027
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070028#include "ndn-pit-entry-impl.h"
Alexander Afanasyev413c7f12012-07-10 17:35:16 -070029
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070030#include "ns3/ndn-name-components.h"
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070031
32namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070033namespace ndn {
34
35class ForwardingStrategy;
36
37namespace pit {
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070038
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070039/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040 * \ingroup ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070041 * \brief Class implementing Pending Interests Table
42 */
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070043template<class Policy>
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044class PitImpl : public Pit
45 , protected ndnSIM::trie_with_policy<NameComponents,
46 ndnSIM::smart_pointer_payload_traits< EntryImpl< PitImpl< Policy > > >,
47 // ndnSIM::persistent_policy_traits
48 Policy
49 >
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070050{
51public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070052 typedef ndnSIM::trie_with_policy<NameComponents,
53 ndnSIM::smart_pointer_payload_traits< EntryImpl< PitImpl< Policy > > >,
Alexander Afanasyevbd6f3f42012-07-26 17:50:17 -070054 // ndnSIM::persistent_policy_traits
55 Policy
Alexander Afanasyev36b45772012-07-10 16:57:42 -070056 > super;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070057 typedef EntryImpl< PitImpl< Policy > > entry;
Alexander Afanasyev36b45772012-07-10 16:57:42 -070058
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070059 /**
60 * \brief Interface ID
61 *
62 * \return interface ID
63 */
64 static TypeId GetTypeId ();
65
66 /**
67 * \brief PIT constructor
68 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070069 PitImpl ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070070
71 /**
72 * \brief Destructor
73 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070074 virtual ~PitImpl ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070075
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070076 // inherited from Pit
77 virtual Ptr<Entry>
78 Lookup (const ContentObjectHeader &header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070079
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 virtual Ptr<Entry>
81 Lookup (const InterestHeader &header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070082
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 virtual Ptr<Entry>
84 Create (Ptr<const InterestHeader> header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070085
86 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070087 MarkErased (Ptr<Entry> entry);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070088
89 virtual void
90 Print (std::ostream &os) const;
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -070091
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070092 virtual uint32_t
93 GetSize () const;
94
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070095 virtual Ptr<Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070096 Begin ();
97
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 virtual Ptr<Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070099 End ();
100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 virtual Ptr<Entry>
102 Next (Ptr<Entry>);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700103
104protected:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700105 void RescheduleCleaning ();
106 void CleanExpired ();
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700107
108 // inherited from Object class
109 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
110 virtual void DoDispose (); ///< @brief Do cleanup
111
112private:
113 uint32_t
114 GetMaxSize () const;
115
116 void
117 SetMaxSize (uint32_t maxSize);
118
119private:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700120 EventId m_cleanEvent;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700121 Ptr<Fib> m_fib; ///< \brief Link to FIB table
122 Ptr<ForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700123
124 // indexes
125 typedef
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700126 boost::intrusive::multiset<entry,
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700127 boost::intrusive::compare < TimestampIndex< entry > >,
128 boost::intrusive::member_hook< entry,
129 boost::intrusive::set_member_hook<>,
130 &entry::time_hook_>
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700131 > time_index;
132 time_index i_time;
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700133
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700134 friend class EntryImpl< PitImpl >;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700135};
136
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700137} // namespace pit
138} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700139} // namespace ns3
140
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700141#endif /* NDN_PIT_IMPL_H */