blob: b221d482e3fbab55fe03f0f9e5ac6b24eff15795 [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 Afanasyev79206512013-07-27 16:49:12 -070034/**
35 * @ingroup ndn-fib
36 * @brief FIB entry implementation with with additional references to the base container
37 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038class EntryImpl : public Entry
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070039{
40public:
41 typedef ndnSIM::trie_with_policy<
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070042 Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043 ndnSIM::smart_pointer_payload_traits<EntryImpl>,
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070044 ndnSIM::counting_policy_traits
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070045 > trie;
46
Alexander Afanasyevff0d9ca2013-04-14 23:13:46 -070047 EntryImpl (Ptr<Fib> fib, const Ptr<const Name> &prefix)
48 : Entry (fib, prefix)
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070049 , item_ (0)
50 {
51 }
52
53 void
54 SetTrie (trie::iterator item)
55 {
56 item_ = item;
57 }
58
59 trie::iterator to_iterator () { return item_; }
60 trie::const_iterator to_iterator () const { return item_; }
61
62private:
63 trie::iterator item_;
64};
65
Alexander Afanasyev78057c32012-07-06 15:18:46 -070066/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070067 * @ingroup ndn-fib
Alexander Afanasyev78057c32012-07-06 15:18:46 -070068 * \brief Class implementing FIB functionality
69 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070070class FibImpl : public Fib,
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070071 protected ndnSIM::trie_with_policy< Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070072 ndnSIM::smart_pointer_payload_traits< EntryImpl >,
73 ndnSIM::counting_policy_traits >
Alexander Afanasyev78057c32012-07-06 15:18:46 -070074{
75public:
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070076 typedef ndnSIM::trie_with_policy< Name,
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 ndnSIM::smart_pointer_payload_traits<EntryImpl>,
78 ndnSIM::counting_policy_traits > super;
Alexander Afanasyev78057c32012-07-06 15:18:46 -070079
80 /**
81 * \brief Interface ID
82 *
83 * \return interface ID
84 */
85 static TypeId GetTypeId ();
86
87 /**
88 * \brief Constructor
89 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070090 FibImpl ();
Alexander Afanasyev78057c32012-07-06 15:18:46 -070091
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070092 virtual Ptr<Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070093 LongestPrefixMatch (const Interest &interest);
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070094
95 virtual Ptr<fib::Entry>
96 Find (const Name &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070097
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 virtual Ptr<Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070099 Add (const Name &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101 virtual Ptr<Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700102 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700103
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700104 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700105 Remove (const Ptr<const Name> &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700106
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700107 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700108 InvalidateAll ();
109
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700110 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700111 RemoveFromAll (Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700112
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700113 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700114 Print (std::ostream &os) const;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700115
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700116 virtual uint32_t
117 GetSize () const;
118
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700119 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700120 Begin () const;
121
122 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700123 Begin ();
124
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700125 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700126 End () const;
127
128 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700129 End ();
130
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700131 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700132 Next (Ptr<const Entry> item) const;
133
134 virtual Ptr<Entry>
135 Next (Ptr<Entry> item);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700136
137protected:
138 // inherited from Object class
139 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
140 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700141
142private:
143 /**
144 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
145 * entry will be removed
146 */
147 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700148 RemoveFace (super::parent_trie &item, Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700149};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700150
151} // namespace fib
152} // namespace ndn
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700153} // namespace ns3
154
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700155#endif /* _NDN_FIB_IMPL_H_ */