blob: 66ff69b6ee6d7008df6688e9f30809945fdc753c [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 Afanasyevcfdc14f2013-03-15 14:38:44 -070030#include "ns3/ndn-name.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
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070045 , protected ndnSIM::trie_with_policy<Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070046 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 Afanasyevcfdc14f2013-03-15 14:38:44 -070052 typedef ndnSIM::trie_with_policy<Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053 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 Afanasyev7456b702013-02-01 22:41:48 -080076 // inherited from Pit
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 virtual Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070078 Lookup (const ContentObject &header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070079
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 virtual Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070081 Lookup (const Interest &header);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070082
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070083 virtual Ptr<Entry>
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070084 Find (const Name &prefix);
85
86 virtual Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070087 Create (Ptr<const Interest> header);
Alexander Afanasyev7456b702013-02-01 22:41:48 -080088
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070089 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070090 MarkErased (Ptr<Entry> entry);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070091
92 virtual void
93 Print (std::ostream &os) const;
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -070094
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070095 virtual uint32_t
96 GetSize () const;
97
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 virtual Ptr<Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070099 Begin ();
100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 virtual Ptr<Entry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -0700102 End ();
103
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700104 virtual Ptr<Entry>
105 Next (Ptr<Entry>);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800106
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700107protected:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700108 void RescheduleCleaning ();
109 void CleanExpired ();
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800110
111 // inherited from Object class
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700112 virtual void NotifyNewAggregate (); ///< @brief Even when object is aggregated to another Object
113 virtual void DoDispose (); ///< @brief Do cleanup
114
115private:
116 uint32_t
117 GetMaxSize () const;
118
119 void
120 SetMaxSize (uint32_t maxSize);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800121
122 uint32_t
123 GetCurrentSize () const;
124
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700125private:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700126 EventId m_cleanEvent;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127 Ptr<Fib> m_fib; ///< \brief Link to FIB table
128 Ptr<ForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700129
130 // indexes
131 typedef
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700132 boost::intrusive::multiset<entry,
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700133 boost::intrusive::compare < TimestampIndex< entry > >,
134 boost::intrusive::member_hook< entry,
135 boost::intrusive::set_member_hook<>,
136 &entry::time_hook_>
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700137 > time_index;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800138 time_index i_time;
139
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140 friend class EntryImpl< PitImpl >;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700141};
142
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143} // namespace pit
144} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700145} // namespace ns3
146
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700147#endif /* NDN_PIT_IMPL_H */