blob: b5e8e40fcd092b1cd2eb44376d0d2813d48e10f0 [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 Afanasyeveae83ee2013-03-15 15:01:10 -070032class Interest;
Alexander Afanasyev73f06f62013-03-15 15:41:38 -070033typedef Interest InterestHeader;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070034
35/**
Alexander Afanasyev79206512013-07-27 16:49:12 -070036 * @ingroup ndn
37 * @defgroup ndn-fib FIB
38 */
39
40/**
41 * @ingroup ndn-fib
42 * @brief Class implementing FIB functionality
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070043 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070044class Fib : public Object
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070045{
46public:
Alexander Afanasyev78057c32012-07-06 15:18:46 -070047 /**
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070048 * \brief Interface ID
49 *
50 * \return interface ID
51 */
52 static TypeId GetTypeId ();
53 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070054 * @brief Default constructor
55 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056 Fib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070057
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070058 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070059 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070060 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061 virtual ~Fib () { };
Alexander Afanasyev78057c32012-07-06 15:18:46 -070062
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070063 /**
64 * \brief Perform longest prefix match
65 *
66 * \todo Implement exclude filters
67 *
68 * \param interest Interest packet header
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070069 * \returns If entry found a valid iterator (Ptr<fib::Entry>) will be returned, otherwise End () (==0)
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070070 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071 virtual Ptr<fib::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070072 LongestPrefixMatch (const Interest &interest) = 0;
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070073
74 /**
75 * @brief Get FIB entry for the prefix (exact match)
76 *
77 * @param prefix Name for FIB entry
78 * @returns If entry is found, a valid iterator (Ptr<fib::Entry>) will be returned. Otherwise End () (==0)
79 */
80 virtual Ptr<fib::Entry>
81 Find (const Name &prefix) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070082
83 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070084 * \brief Add or update FIB entry
85 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070086 * If the entry exists, metric will be updated. Otherwise, new entry will be created
87 *
88 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
89 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070090 * @param name Prefix
91 * @param face Forwarding face
92 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070093 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070095 Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070096
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080097 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070098 * \brief Add or update FIB entry using smart pointer to prefix
99 *
100 * If the entry exists, metric will be updated. Otherwise, new entry will be created
101 *
102 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
103 *
104 * @param name Smart pointer to prefix
105 * @param face Forwarding face
106 * @param metric Routing metric
107 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700108 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700109 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700110
111 /**
112 * @brief Remove FIB entry
113 *
114 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
115 * So, simulation may crash.
116 *
117 * @param name Smart pointer to prefix
118 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700119 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700120 Remove (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700121
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700122 // /**
123 // * @brief Invalidate FIB entry ("Safe" version of Remove)
124 // *
125 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
126 // * @param name Smart pointer to prefix
127 // */
128 // virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700129 // Invalidate (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700130
131 /**
132 * @brief Invalidate all FIB entries
133 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700134 virtual void
135 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700136
137 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800138 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
139 * this FIB entry will be removed.
140 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700141 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700142 RemoveFromAll (Ptr<Face> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700143
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700144 /**
145 * @brief Print out entries in FIB
146 */
147 virtual void
148 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700149
150 /**
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700151 * @brief Get number of entries in FIB
152 */
153 virtual uint32_t
154 GetSize () const = 0;
155
156 /**
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700157 * @brief Return first element of FIB (no order guaranteed)
158 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700159 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700160 Begin () const = 0;
161
162 /**
163 * @brief Return first element of FIB (no order guaranteed)
164 */
165 virtual Ptr<fib::Entry>
166 Begin () = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700167
168 /**
169 * @brief Return item next after last (no order guaranteed)
170 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700171 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700172 End () const = 0;
173
174 /**
175 * @brief Return item next after last (no order guaranteed)
176 */
177 virtual Ptr<fib::Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700178 End () = 0;
179
180 /**
181 * @brief Advance the iterator
182 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700183 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700184 Next (Ptr<const fib::Entry>) const = 0;
185
186 /**
187 * @brief Advance the iterator
188 */
189 virtual Ptr<fib::Entry>
190 Next (Ptr<fib::Entry>) = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700191
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700192 ////////////////////////////////////////////////////////////////////////////
193 ////////////////////////////////////////////////////////////////////////////
194 ////////////////////////////////////////////////////////////////////////////
195
196 /**
197 * @brief Static call to cheat python bindings
198 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700199 static inline Ptr<Fib>
200 GetFib (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700201
202 ////////////////////////////////////////////////////////////////////////////
203 ////////////////////////////////////////////////////////////////////////////
204 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700205
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700206private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700207 Fib (const Fib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700208};
209
210///////////////////////////////////////////////////////////////////////////////
211///////////////////////////////////////////////////////////////////////////////
212
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213std::ostream& operator<< (std::ostream& os, const Fib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700214
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700215Ptr<Fib>
216Fib::GetFib (Ptr<Object> node)
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700217{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218 return node->GetObject<Fib> ();
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700219}
220
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700221} // namespace ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700222} // namespace ns3
223
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700224#endif // _NDN_FIB_H_