blob: 6e21214dae511a181ff98a650252d74f3e2e1fa2 [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 Afanasyev7fd74f92011-08-25 19:40:17 -070068
69 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070070 * \brief Add or update FIB entry
71 *
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070072 * If the entry exists, metric will be updated. Otherwise, new entry will be created
73 *
74 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
75 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070076 * @param name Prefix
77 * @param face Forwarding face
78 * @param metric Routing metric
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070079 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070080 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070081 Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -070082
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080083 /**
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070084 * \brief Add or update FIB entry using smart pointer to prefix
85 *
86 * 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 *
90 * @param name Smart pointer to prefix
91 * @param face Forwarding face
92 * @param metric Routing metric
93 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070094 virtual Ptr<fib::Entry>
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070095 Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -070096
97 /**
98 * @brief Remove FIB entry
99 *
100 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
101 * So, simulation may crash.
102 *
103 * @param name Smart pointer to prefix
104 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700105 virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700106 Remove (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700107
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700108 // /**
109 // * @brief Invalidate FIB entry ("Safe" version of Remove)
110 // *
111 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
112 // * @param name Smart pointer to prefix
113 // */
114 // virtual void
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700115 // Invalidate (const Ptr<const Name> &prefix) = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700116
117 /**
118 * @brief Invalidate all FIB entries
119 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700120 virtual void
121 InvalidateAll () = 0;
Alexander Afanasyev8e2f1122012-04-17 15:01:11 -0700122
123 /**
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800124 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
125 * this FIB entry will be removed.
126 */
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700127 virtual void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700128 RemoveFromAll (Ptr<Face> face) = 0;
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700129
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700130 /**
131 * @brief Print out entries in FIB
132 */
133 virtual void
134 Print (std::ostream &os) const = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700135
136 /**
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700137 * @brief Get number of entries in FIB
138 */
139 virtual uint32_t
140 GetSize () const = 0;
141
142 /**
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700143 * @brief Return first element of FIB (no order guaranteed)
144 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700146 Begin () const = 0;
147
148 /**
149 * @brief Return first element of FIB (no order guaranteed)
150 */
151 virtual Ptr<fib::Entry>
152 Begin () = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700153
154 /**
155 * @brief Return item next after last (no order guaranteed)
156 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700158 End () const = 0;
159
160 /**
161 * @brief Return item next after last (no order guaranteed)
162 */
163 virtual Ptr<fib::Entry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700164 End () = 0;
165
166 /**
167 * @brief Advance the iterator
168 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700169 virtual Ptr<const fib::Entry>
Alexander Afanasyevea9b3e62012-08-13 19:02:54 -0700170 Next (Ptr<const fib::Entry>) const = 0;
171
172 /**
173 * @brief Advance the iterator
174 */
175 virtual Ptr<fib::Entry>
176 Next (Ptr<fib::Entry>) = 0;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700177
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700178 ////////////////////////////////////////////////////////////////////////////
179 ////////////////////////////////////////////////////////////////////////////
180 ////////////////////////////////////////////////////////////////////////////
181
182 /**
183 * @brief Static call to cheat python bindings
184 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700185 static inline Ptr<Fib>
186 GetFib (Ptr<Object> node);
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700187
188 ////////////////////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////////////////////
190 ////////////////////////////////////////////////////////////////////////////
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700191
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700192private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700193 Fib (const Fib&) {} ; ///< \brief copy constructor is disabled
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700194};
195
196///////////////////////////////////////////////////////////////////////////////
197///////////////////////////////////////////////////////////////////////////////
198
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700199std::ostream& operator<< (std::ostream& os, const Fib &fib);
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700200
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700201Ptr<Fib>
202Fib::GetFib (Ptr<Object> node)
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700203{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700204 return node->GetObject<Fib> ();
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700205}
206
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700207} // namespace ndn
Alexander Afanasyev7fd74f92011-08-25 19:40:17 -0700208} // namespace ns3
209
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700210#endif // _NDN_FIB_H_