blob: 57d7d50b602da6c3006fca932dd88215ad12191e [file] [log] [blame]
Alexander Afanasyev78057c32012-07-06 15:18:46 -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_FIB_IMPL_H_
22#define _NDN_FIB_IMPL_H_
Alexander Afanasyev78057c32012-07-06 15:18:46 -070023
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070024#include "ns3/ndn-fib.h"
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070025#include "ns3/ndn-name.h"
Alexander Afanasyev78057c32012-07-06 15:18:46 -070026
Alexander Afanasyev1a2df6a2012-08-17 13:21:51 -070027#include "../../utils/trie/trie-with-policy.h"
28#include "../../utils/trie/counting-policy.h"
Alexander Afanasyev78057c32012-07-06 15:18:46 -070029
30namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070031namespace ndn {
32namespace fib {
Alexander Afanasyev78057c32012-07-06 15:18:46 -070033
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034class EntryImpl : public Entry
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070035{
36public:
37 typedef ndnSIM::trie_with_policy<
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070038 Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039 ndnSIM::smart_pointer_payload_traits<EntryImpl>,
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070040 ndnSIM::counting_policy_traits
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070041 > trie;
42
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070043 EntryImpl (const Ptr<const Name> &prefix)
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044 : Entry (prefix)
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070045 , item_ (0)
46 {
47 }
48
49 void
50 SetTrie (trie::iterator item)
51 {
52 item_ = item;
53 }
54
55 trie::iterator to_iterator () { return item_; }
56 trie::const_iterator to_iterator () const { return item_; }
57
58private:
59 trie::iterator item_;
60};
61
Alexander Afanasyev78057c32012-07-06 15:18:46 -070062/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070063 * \ingroup ndn
Alexander Afanasyev78057c32012-07-06 15:18:46 -070064 * \brief Class implementing FIB functionality
65 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070066class FibImpl : public Fib,
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070067 protected ndnSIM::trie_with_policy< Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070068 ndnSIM::smart_pointer_payload_traits< EntryImpl >,
69 ndnSIM::counting_policy_traits >
Alexander Afanasyev78057c32012-07-06 15:18:46 -070070{
71public:
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070072 typedef ndnSIM::trie_with_policy< Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 ndnSIM::smart_pointer_payload_traits<EntryImpl>,
74 ndnSIM::counting_policy_traits > super;
Alexander Afanasyev78057c32012-07-06 15:18:46 -070075
76 /**
77 * \brief Interface ID
78 *
79 * \return interface ID
80 */
81 static TypeId GetTypeId ();
82
83 /**
84 * \brief Constructor
85 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086 FibImpl ();
Alexander Afanasyev78057c32012-07-06 15:18:46 -070087
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070088 virtual Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070089 LongestPrefixMatch (const Interest &interest);
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070090
91 virtual Ptr<fib::Entry>
92 Find (const Name &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070093
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 virtual Ptr<Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070095 Add (const Name &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070096
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097 virtual Ptr<Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070098 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070099
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700100 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700101 Remove (const Ptr<const Name> &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700102
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700103 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700104 InvalidateAll ();
105
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700106 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700107 RemoveFromAll (Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700108
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700109 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700110 Print (std::ostream &os) const;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700111
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700112 virtual uint32_t
113 GetSize () const;
114
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700115 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700116 Begin () const;
117
118 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700119 Begin ();
120
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700121 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700122 End () const;
123
124 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700125 End ();
126
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700128 Next (Ptr<const Entry> item) const;
129
130 virtual Ptr<Entry>
131 Next (Ptr<Entry> item);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700132
133protected:
134 // inherited from Object class
135 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
136 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700137
138private:
139 /**
140 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
141 * entry will be removed
142 */
143 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144 RemoveFace (super::parent_trie &item, Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700145};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700146
147} // namespace fib
148} // namespace ndn
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700149} // namespace ns3
150
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700151#endif /* _NDN_FIB_IMPL_H_ */