blob: 490cdfdb0d539b76687cd2799bd0c6ef1ec19973 [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 Afanasyev4aac5572012-08-09 10:49:55 -070036 * \ingroup ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070037 * \brief Class implementing FIB functionality
38 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070039class Fib : public Object
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070040{
41public:
Alexander Afanasyev78057c32012-07-06 15:18:46 -070042 /**
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -070043 * \brief Interface ID
44 *
45 * \return interface ID
46 */
47 static TypeId GetTypeId ();
48 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070049 * @brief Default constructor
50 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051 Fib () {}
Alexander Afanasyevf034cbd2012-06-29 14:28:31 -070052
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070053 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -070054 * @brief Virtual destructor
Alexander Afanasyevcf133f02011-09-06 12:13:48 -070055 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070056 virtual ~Fib () { };
Alexander Afanasyev78057c32012-07-06 15:18:46 -070057
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070058 /**
59 * \brief Perform longest prefix match
60 *
61 * \todo Implement exclude filters
62 *
63 * \param interest Interest packet header
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070064 * \returns If entry found a valid iterator (Ptr<fib::Entry>) will be returned, otherwise End () (==0)
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070065 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070066 virtual Ptr<fib::Entry>
Alexander Afanasyeveae83ee2013-03-15 15:01:10 -070067 LongestPrefixMatch (const Interest &interest) = 0;
Alexander Afanasyeve5a8b5a2013-03-15 15:15:26 -070068
69 /**
70 * @brief Get FIB entry for the prefix (exact match)
71 *
72 * @param prefix Name for FIB entry
73 * @returns If entry is found, a valid iterator (Ptr<fib::Entry>) will be returned. Otherwise End () (==0)
74 */
75 virtual Ptr<fib::Entry>
76 Find (const Name &prefix) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070077
78 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070079 * \brief Add or update FIB entry
80 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070081 * If the entry exists, metric will be updated. Otherwise, new entry will be created
82 *
83 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
84 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070085 * @param name Prefix
86 * @param face Forwarding face
87 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070088 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070089 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070090 Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070091
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080092 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070093 * \brief Add or update FIB entry using smart pointer to prefix
94 *
95 * If the entry exists, metric will be updated. Otherwise, new entry will be created
96 *
97 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
98 *
99 * @param name Smart pointer to prefix
100 * @param face Forwarding face
101 * @param metric Routing metric
102 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700103 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700104 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700105
106 /**
107 * @brief Remove FIB entry
108 *
109 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
110 * So, simulation may crash.
111 *
112 * @param name Smart pointer to prefix
113 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700114 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700115 Remove (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700116
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700117 // /**
118 // * @brief Invalidate FIB entry ("Safe" version of Remove)
119 // *
120 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
121 // * @param name Smart pointer to prefix
122 // */
123 // virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700124 // Invalidate (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700125
126 /**
127 * @brief Invalidate all FIB entries
128 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129 virtual void
130 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700131
132 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800133 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
134 * this FIB entry will be removed.
135 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700136 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700137 RemoveFromAll (Ptr<Face> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700138
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700139 /**
140 * @brief Print out entries in FIB
141 */
142 virtual void
143 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700144
145 /**
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700146 * @brief Get number of entries in FIB
147 */
148 virtual uint32_t
149 GetSize () const = 0;
150
151 /**
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700152 * @brief Return first element of FIB (no order guaranteed)
153 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700154 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700155 Begin () const = 0;
156
157 /**
158 * @brief Return first element of FIB (no order guaranteed)
159 */
160 virtual Ptr<fib::Entry>
161 Begin () = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700162
163 /**
164 * @brief Return item next after last (no order guaranteed)
165 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700166 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700167 End () const = 0;
168
169 /**
170 * @brief Return item next after last (no order guaranteed)
171 */
172 virtual Ptr<fib::Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700173 End () = 0;
174
175 /**
176 * @brief Advance the iterator
177 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700178 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700179 Next (Ptr<const fib::Entry>) const = 0;
180
181 /**
182 * @brief Advance the iterator
183 */
184 virtual Ptr<fib::Entry>
185 Next (Ptr<fib::Entry>) = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700186
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700187 ////////////////////////////////////////////////////////////////////////////
188 ////////////////////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////////////////////
190
191 /**
192 * @brief Static call to cheat python bindings
193 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700194 static inline Ptr<Fib>
195 GetFib (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700196
197 ////////////////////////////////////////////////////////////////////////////
198 ////////////////////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700200
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700201private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700202 Fib (const Fib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700203};
204
205///////////////////////////////////////////////////////////////////////////////
206///////////////////////////////////////////////////////////////////////////////
207
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700208std::ostream& operator<< (std::ostream& os, const Fib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700209
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700210Ptr<Fib>
211Fib::GetFib (Ptr<Object> node)
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700212{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213 return node->GetObject<Fib> ();
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700214}
215
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700216} // namespace ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700217} // namespace ns3
218
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700219#endif // _NDN_FIB_H_