Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 3 | * Copyright (c) 2011-2013 University of California, Los Angeles |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 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 Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #ifndef _NDN_FIB_H_ |
| 22 | #define _NDN_FIB_H_ |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 24 | #include "ns3/simple-ref-count.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 25 | #include "ns3/node.h" |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 27 | #include "ns3/ndn-fib-entry.h" |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 28 | |
| 29 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 30 | namespace ndn { |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 31 | |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 32 | class Interest; |
Alexander Afanasyev | 73f06f6 | 2013-03-15 15:41:38 -0700 | [diff] [blame] | 33 | typedef Interest InterestHeader; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 36 | * @ingroup ndn |
| 37 | * @defgroup ndn-fib FIB |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | * @ingroup ndn-fib |
| 42 | * @brief Class implementing FIB functionality |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 43 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 44 | class Fib : public Object |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 45 | { |
| 46 | public: |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 47 | /** |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 48 | * \brief Interface ID |
| 49 | * |
| 50 | * \return interface ID |
| 51 | */ |
| 52 | static TypeId GetTypeId (); |
| 53 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 54 | * @brief Default constructor |
| 55 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 56 | Fib () {} |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 58 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 59 | * @brief Virtual destructor |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 60 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 61 | virtual ~Fib () { }; |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 63 | /** |
| 64 | * \brief Perform longest prefix match |
| 65 | * |
| 66 | * \todo Implement exclude filters |
| 67 | * |
| 68 | * \param interest Interest packet header |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 69 | * \returns If entry found a valid iterator (Ptr<fib::Entry>) will be returned, otherwise End () (==0) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 70 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 71 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 72 | LongestPrefixMatch (const Interest &interest) = 0; |
Alexander Afanasyev | e5a8b5a | 2013-03-15 15:15:26 -0700 | [diff] [blame] | 73 | |
| 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 Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 84 | * \brief Add or update FIB entry |
| 85 | * |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 90 | * @param name Prefix |
| 91 | * @param face Forwarding face |
| 92 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 93 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 94 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 95 | Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 97 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 98 | * \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 Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 108 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 109 | Add (const Ptr<const Name> &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 110 | |
| 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 Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 119 | virtual void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 120 | Remove (const Ptr<const Name> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 121 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 122 | // /** |
| 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 Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 129 | // Invalidate (const Ptr<const Name> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * @brief Invalidate all FIB entries |
| 133 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 134 | virtual void |
| 135 | InvalidateAll () = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 138 | * @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 Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 141 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 142 | RemoveFromAll (Ptr<Face> face) = 0; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 143 | |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 144 | /** |
| 145 | * @brief Print out entries in FIB |
| 146 | */ |
| 147 | virtual void |
| 148 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 151 | * @brief Get number of entries in FIB |
| 152 | */ |
| 153 | virtual uint32_t |
| 154 | GetSize () const = 0; |
| 155 | |
| 156 | /** |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 157 | * @brief Return first element of FIB (no order guaranteed) |
| 158 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 159 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 160 | 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 Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
| 169 | * @brief Return item next after last (no order guaranteed) |
| 170 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 171 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 172 | End () const = 0; |
| 173 | |
| 174 | /** |
| 175 | * @brief Return item next after last (no order guaranteed) |
| 176 | */ |
| 177 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 178 | End () = 0; |
| 179 | |
| 180 | /** |
| 181 | * @brief Advance the iterator |
| 182 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 183 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 184 | 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 Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 191 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 192 | //////////////////////////////////////////////////////////////////////////// |
| 193 | //////////////////////////////////////////////////////////////////////////// |
| 194 | //////////////////////////////////////////////////////////////////////////// |
| 195 | |
| 196 | /** |
| 197 | * @brief Static call to cheat python bindings |
| 198 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 199 | static inline Ptr<Fib> |
| 200 | GetFib (Ptr<Object> node); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 201 | |
| 202 | //////////////////////////////////////////////////////////////////////////// |
| 203 | //////////////////////////////////////////////////////////////////////////// |
| 204 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 205 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 206 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 207 | Fib (const Fib&) {} ; ///< \brief copy constructor is disabled |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | /////////////////////////////////////////////////////////////////////////////// |
| 211 | /////////////////////////////////////////////////////////////////////////////// |
| 212 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 213 | std::ostream& operator<< (std::ostream& os, const Fib &fib); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 214 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 215 | Ptr<Fib> |
| 216 | Fib::GetFib (Ptr<Object> node) |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 217 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 218 | return node->GetObject<Fib> (); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 221 | } // namespace ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 222 | } // namespace ns3 |
| 223 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 224 | #endif // _NDN_FIB_H_ |