blob: 7a346d2c0c0cac3c46fb085838d47952183357fe [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 Afanasyev7456b702013-02-01 22:41:48 -080076 // inherited from Pit
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 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 Afanasyev7456b702013-02-01 22:41:48 -080085
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070086 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 Afanasyev7456b702013-02-01 22:41:48 -0800103
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700104protected:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700105 void RescheduleCleaning ();
106 void CleanExpired ();
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800107
108 // inherited from Object class
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700109 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);
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800118
119 uint32_t
120 GetCurrentSize () const;
121
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700122private:
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700123 EventId m_cleanEvent;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 Ptr<Fib> m_fib; ///< \brief Link to FIB table
125 Ptr<ForwardingStrategy> m_forwardingStrategy;
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700126
127 // indexes
128 typedef
Alexander Afanasyev6b51b082012-07-27 16:28:34 -0700129 boost::intrusive::multiset<entry,
Alexander Afanasyev36b45772012-07-10 16:57:42 -0700130 boost::intrusive::compare < TimestampIndex< entry > >,
131 boost::intrusive::member_hook< entry,
132 boost::intrusive::set_member_hook<>,
133 &entry::time_hook_>
Alexander Afanasyev413c7f12012-07-10 17:35:16 -0700134 > time_index;
Alexander Afanasyev7456b702013-02-01 22:41:48 -0800135 time_index i_time;
136
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700137 friend class EntryImpl< PitImpl >;
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700138};
139
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700140} // namespace pit
141} // namespace ndn
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700142} // namespace ns3
143
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700144#endif /* NDN_PIT_IMPL_H */