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 | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 36 | * \ingroup ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 37 | * \brief Class implementing FIB functionality |
| 38 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 39 | class Fib : public Object |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 42 | /** |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 43 | * \brief Interface ID |
| 44 | * |
| 45 | * \return interface ID |
| 46 | */ |
| 47 | static TypeId GetTypeId (); |
| 48 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 49 | * @brief Default constructor |
| 50 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 51 | Fib () {} |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 53 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 54 | * @brief Virtual destructor |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 55 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 56 | virtual ~Fib () { }; |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 57 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 58 | /** |
| 59 | * \brief Perform longest prefix match |
| 60 | * |
| 61 | * \todo Implement exclude filters |
| 62 | * |
| 63 | * \param interest Interest packet header |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 64 | * \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] | 65 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 66 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | eae83ee | 2013-03-15 15:01:10 -0700 | [diff] [blame] | 67 | LongestPrefixMatch (const Interest &interest) = 0; |
Alexander Afanasyev | e5a8b5a | 2013-03-15 15:15:26 -0700 | [diff] [blame] | 68 | |
| 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 Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 79 | * \brief Add or update FIB entry |
| 80 | * |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 81 | * 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 Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 85 | * @param name Prefix |
| 86 | * @param face Forwarding face |
| 87 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 88 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 89 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 90 | Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 91 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 92 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 93 | * \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 Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 103 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 104 | 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] | 105 | |
| 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 Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 114 | virtual void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 115 | Remove (const Ptr<const Name> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 116 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 117 | // /** |
| 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 Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 124 | // Invalidate (const Ptr<const Name> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * @brief Invalidate all FIB entries |
| 128 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 129 | virtual void |
| 130 | InvalidateAll () = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 131 | |
| 132 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 133 | * @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 Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 136 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 137 | RemoveFromAll (Ptr<Face> face) = 0; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 138 | |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 139 | /** |
| 140 | * @brief Print out entries in FIB |
| 141 | */ |
| 142 | virtual void |
| 143 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 146 | * @brief Get number of entries in FIB |
| 147 | */ |
| 148 | virtual uint32_t |
| 149 | GetSize () const = 0; |
| 150 | |
| 151 | /** |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 152 | * @brief Return first element of FIB (no order guaranteed) |
| 153 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 154 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 155 | 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 Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * @brief Return item next after last (no order guaranteed) |
| 165 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 166 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 167 | End () const = 0; |
| 168 | |
| 169 | /** |
| 170 | * @brief Return item next after last (no order guaranteed) |
| 171 | */ |
| 172 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 173 | End () = 0; |
| 174 | |
| 175 | /** |
| 176 | * @brief Advance the iterator |
| 177 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 178 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 179 | 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 Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 186 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 187 | //////////////////////////////////////////////////////////////////////////// |
| 188 | //////////////////////////////////////////////////////////////////////////// |
| 189 | //////////////////////////////////////////////////////////////////////////// |
| 190 | |
| 191 | /** |
| 192 | * @brief Static call to cheat python bindings |
| 193 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 194 | static inline Ptr<Fib> |
| 195 | GetFib (Ptr<Object> node); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 196 | |
| 197 | //////////////////////////////////////////////////////////////////////////// |
| 198 | //////////////////////////////////////////////////////////////////////////// |
| 199 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 200 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 201 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 202 | Fib (const Fib&) {} ; ///< \brief copy constructor is disabled |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | /////////////////////////////////////////////////////////////////////////////// |
| 206 | /////////////////////////////////////////////////////////////////////////////// |
| 207 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 208 | std::ostream& operator<< (std::ostream& os, const Fib &fib); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 209 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 210 | Ptr<Fib> |
| 211 | Fib::GetFib (Ptr<Object> node) |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 212 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 213 | return node->GetObject<Fib> (); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 216 | } // namespace ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 217 | } // namespace ns3 |
| 218 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 219 | #endif // _NDN_FIB_H_ |