blob: 141a40233f158754f72441952a435140d62aa023 [file] [log] [blame]
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -07003 * Copyright (c) 2011-2013 University of California, Los Angeles
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -07004 *
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_H_
22#define _NDN_FIB_H_
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070023
Alexander Afanasyeva98cdd22011-08-29 17:32:37 -070024#include "ns3/simple-ref-count.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070025#include "ns3/node.h"
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070026
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070027#include "ns3/ndn-fib-entry.h"
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070028
29namespace ns3 {
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070030namespace ndn {
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070031
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070032class InterestHeader;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070033
34/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070035 * \ingroup ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070036 * \brief Class implementing FIB functionality
37 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070038class Fib : public Object
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070039{
40public:
Alexander Afanasyev78057c32012-07-06 15:18:46 -070041 /**
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070042 * \brief Interface ID
43 *
44 * \return interface ID
45 */
46 static TypeId GetTypeId ();
47 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070048 * @brief Default constructor
49 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070050 Fib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070051
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070052 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070053 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070054 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055 virtual ~Fib () { };
Alexander Afanasyev78057c32012-07-06 15:18:46 -070056
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070057 /**
58 * \brief Perform longest prefix match
59 *
60 * \todo Implement exclude filters
61 *
62 * \param interest Interest packet header
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070063 * \returns If entry found a valid iterator (Ptr<fib::Entry>) will be returned, otherwise End () (==0)
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070064 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070065 virtual Ptr<fib::Entry>
66 LongestPrefixMatch (const InterestHeader &interest) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070067
68 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070069 * \brief Add or update FIB entry
70 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070071 * If the entry exists, metric will be updated. Otherwise, new entry will be created
72 *
73 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
74 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070075 * @param name Prefix
76 * @param face Forwarding face
77 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070078 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070080 Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070081
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080082 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070083 * \brief Add or update FIB entry using smart pointer to prefix
84 *
85 * If the entry exists, metric will be updated. Otherwise, new entry will be created
86 *
87 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
88 *
89 * @param name Smart pointer to prefix
90 * @param face Forwarding face
91 * @param metric Routing metric
92 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070093 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070094 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070095
96 /**
97 * @brief Remove FIB entry
98 *
99 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
100 * So, simulation may crash.
101 *
102 * @param name Smart pointer to prefix
103 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700104 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700105 Remove (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700106
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700107 // /**
108 // * @brief Invalidate FIB entry ("Safe" version of Remove)
109 // *
110 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
111 // * @param name Smart pointer to prefix
112 // */
113 // virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700114 // Invalidate (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700115
116 /**
117 * @brief Invalidate all FIB entries
118 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700119 virtual void
120 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700121
122 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800123 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
124 * this FIB entry will be removed.
125 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700126 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700127 RemoveFromAll (Ptr<Face> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700128
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129 /**
130 * @brief Print out entries in FIB
131 */
132 virtual void
133 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700134
135 /**
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700136 * @brief Get number of entries in FIB
137 */
138 virtual uint32_t
139 GetSize () const = 0;
140
141 /**
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700142 * @brief Return first element of FIB (no order guaranteed)
143 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700144 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700145 Begin () const = 0;
146
147 /**
148 * @brief Return first element of FIB (no order guaranteed)
149 */
150 virtual Ptr<fib::Entry>
151 Begin () = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700152
153 /**
154 * @brief Return item next after last (no order guaranteed)
155 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700157 End () const = 0;
158
159 /**
160 * @brief Return item next after last (no order guaranteed)
161 */
162 virtual Ptr<fib::Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700163 End () = 0;
164
165 /**
166 * @brief Advance the iterator
167 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700168 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700169 Next (Ptr<const fib::Entry>) const = 0;
170
171 /**
172 * @brief Advance the iterator
173 */
174 virtual Ptr<fib::Entry>
175 Next (Ptr<fib::Entry>) = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700176
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700177 ////////////////////////////////////////////////////////////////////////////
178 ////////////////////////////////////////////////////////////////////////////
179 ////////////////////////////////////////////////////////////////////////////
180
181 /**
182 * @brief Static call to cheat python bindings
183 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700184 static inline Ptr<Fib>
185 GetFib (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700186
187 ////////////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700190
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700191private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700192 Fib (const Fib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700193};
194
195///////////////////////////////////////////////////////////////////////////////
196///////////////////////////////////////////////////////////////////////////////
197
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700198std::ostream& operator<< (std::ostream& os, const Fib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700199
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700200Ptr<Fib>
201Fib::GetFib (Ptr<Object> node)
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700202{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700203 return node->GetObject<Fib> ();
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700204}
205
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700206} // namespace ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700207} // namespace ns3
208
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700209#endif // _NDN_FIB_H_