blob: f47a7d15d0b417ee8c967dfd49f515c687b713a1 [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"
25#include "ns3/ndn-name-components.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 Afanasyev2b4c9472012-08-09 15:00:38 -070038 NameComponents,
39 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 Afanasyev2b4c9472012-08-09 15:00:38 -070043 EntryImpl (const Ptr<const NameComponents> &prefix)
44 : 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,
67 protected ndnSIM::trie_with_policy< NameComponents,
68 ndnSIM::smart_pointer_payload_traits< EntryImpl >,
69 ndnSIM::counting_policy_traits >
Alexander Afanasyev78057c32012-07-06 15:18:46 -070070{
71public:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070072 typedef ndnSIM::trie_with_policy< NameComponents,
73 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>
89 LongestPrefixMatch (const InterestHeader &interest);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070090
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070091 virtual Ptr<Entry>
92 Add (const NameComponents &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070093
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 virtual Ptr<Entry>
95 Add (const Ptr<const NameComponents> &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070096
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -070097 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070098 Remove (const Ptr<const NameComponents> &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070099
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700100 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700101 InvalidateAll ();
102
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700103 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700104 RemoveFromAll (Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700105
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700106 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700107 Print (std::ostream &os) const;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700108
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700109 virtual uint32_t
110 GetSize () const;
111
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700112 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700113 Begin () const;
114
115 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700116 Begin ();
117
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700118 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700119 End () const;
120
121 virtual Ptr<Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700122 End ();
123
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700124 virtual Ptr<const Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700125 Next (Ptr<const Entry> item) const;
126
127 virtual Ptr<Entry>
128 Next (Ptr<Entry> item);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129
130protected:
131 // inherited from Object class
132 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
133 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700134
135private:
136 /**
137 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
138 * entry will be removed
139 */
140 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700141 RemoveFace (super::parent_trie &item, Ptr<Face> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700142};
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700143
144} // namespace fib
145} // namespace ndn
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700146} // namespace ns3
147
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700148#endif /* _NDN_FIB_IMPL_H_ */