Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 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 | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 32 | class InterestHeader; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 35 | * \ingroup ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 36 | * \brief Class implementing FIB functionality |
| 37 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 38 | class Fib : public Object |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 39 | { |
| 40 | public: |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 41 | /** |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 42 | * \brief Interface ID |
| 43 | * |
| 44 | * \return interface ID |
| 45 | */ |
| 46 | static TypeId GetTypeId (); |
| 47 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 48 | * @brief Default constructor |
| 49 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 50 | Fib () {} |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 52 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 53 | * @brief Virtual destructor |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 54 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 55 | virtual ~Fib () { }; |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 56 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 57 | /** |
| 58 | * \brief Perform longest prefix match |
| 59 | * |
| 60 | * \todo Implement exclude filters |
| 61 | * |
| 62 | * \param interest Interest packet header |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 63 | * \returns If entry found a valid iterator will be returned, otherwise end () |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 64 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 65 | virtual Ptr<fib::Entry> |
| 66 | LongestPrefixMatch (const InterestHeader &interest) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 69 | * \brief Add or update FIB entry |
| 70 | * |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 71 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 72 | * |
| 73 | * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE |
| 74 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 75 | * @param name Prefix |
| 76 | * @param face Forwarding face |
| 77 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 78 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 79 | virtual Ptr<fib::Entry> |
| 80 | Add (const NameComponents &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 81 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 82 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 83 | * \brief Add or update FIB entry using smart pointer to prefix |
| 84 | * |
| 85 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 86 | * |
| 87 | * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE |
| 88 | * |
| 89 | * @param name Smart pointer to prefix |
| 90 | * @param face Forwarding face |
| 91 | * @param metric Routing metric |
| 92 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 93 | virtual Ptr<fib::Entry> |
| 94 | Add (const Ptr<const NameComponents> &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * @brief Remove FIB entry |
| 98 | * |
| 99 | * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid. |
| 100 | * So, simulation may crash. |
| 101 | * |
| 102 | * @param name Smart pointer to prefix |
| 103 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 104 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 105 | Remove (const Ptr<const NameComponents> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 106 | |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 107 | // /** |
| 108 | // * @brief Invalidate FIB entry ("Safe" version of Remove) |
| 109 | // * |
| 110 | // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status |
| 111 | // * @param name Smart pointer to prefix |
| 112 | // */ |
| 113 | // virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 114 | // Invalidate (const Ptr<const NameComponents> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * @brief Invalidate all FIB entries |
| 118 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 119 | virtual void |
| 120 | InvalidateAll () = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 123 | * @brief Remove all references to a face from FIB. If for some enty that face was the only element, |
| 124 | * this FIB entry will be removed. |
| 125 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 126 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 127 | RemoveFromAll (Ptr<Face> face) = 0; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 128 | |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 129 | /** |
| 130 | * @brief Print out entries in FIB |
| 131 | */ |
| 132 | virtual void |
| 133 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 136 | * @brief Get number of entries in FIB |
| 137 | */ |
| 138 | virtual uint32_t |
| 139 | GetSize () const = 0; |
| 140 | |
| 141 | /** |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 142 | * @brief Return first element of FIB (no order guaranteed) |
| 143 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 144 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 145 | Begin () const = 0; |
| 146 | |
| 147 | /** |
| 148 | * @brief Return first element of FIB (no order guaranteed) |
| 149 | */ |
| 150 | virtual Ptr<fib::Entry> |
| 151 | Begin () = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * @brief Return item next after last (no order guaranteed) |
| 155 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 156 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 157 | End () const = 0; |
| 158 | |
| 159 | /** |
| 160 | * @brief Return item next after last (no order guaranteed) |
| 161 | */ |
| 162 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 163 | End () = 0; |
| 164 | |
| 165 | /** |
| 166 | * @brief Advance the iterator |
| 167 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 168 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 169 | Next (Ptr<const fib::Entry>) const = 0; |
| 170 | |
| 171 | /** |
| 172 | * @brief Advance the iterator |
| 173 | */ |
| 174 | virtual Ptr<fib::Entry> |
| 175 | Next (Ptr<fib::Entry>) = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 176 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 177 | //////////////////////////////////////////////////////////////////////////// |
| 178 | //////////////////////////////////////////////////////////////////////////// |
| 179 | //////////////////////////////////////////////////////////////////////////// |
| 180 | |
| 181 | /** |
| 182 | * @brief Static call to cheat python bindings |
| 183 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 184 | static inline Ptr<Fib> |
| 185 | GetFib (Ptr<Object> node); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 186 | |
| 187 | //////////////////////////////////////////////////////////////////////////// |
| 188 | //////////////////////////////////////////////////////////////////////////// |
| 189 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 190 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 191 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 192 | Fib (const Fib&) {} ; ///< \brief copy constructor is disabled |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /////////////////////////////////////////////////////////////////////////////// |
| 196 | /////////////////////////////////////////////////////////////////////////////// |
| 197 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 198 | std::ostream& operator<< (std::ostream& os, const Fib &fib); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 200 | Ptr<Fib> |
| 201 | Fib::GetFib (Ptr<Object> node) |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 202 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 203 | return node->GetObject<Fib> (); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 206 | } // namespace ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 207 | } // namespace ns3 |
| 208 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 209 | #endif // _NDN_FIB_H_ |