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 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 88 | * @param name Prefix |
| 89 | * @param face Forwarding face |
| 90 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 91 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 93 | Add (const Name &prefix, Ptr<Face> face, int32_t metric) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 95 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 96 | * \brief Add or update FIB entry using smart pointer to prefix |
| 97 | * |
| 98 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 99 | * |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 100 | * @param name Smart pointer to prefix |
| 101 | * @param face Forwarding face |
| 102 | * @param metric Routing metric |
| 103 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 104 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 105 | 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] | 106 | |
| 107 | /** |
| 108 | * @brief Remove FIB entry |
| 109 | * |
| 110 | * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid. |
| 111 | * So, simulation may crash. |
| 112 | * |
| 113 | * @param name Smart pointer to prefix |
| 114 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 115 | virtual void |
Alexander Afanasyev | cfdc14f | 2013-03-15 14:38:44 -0700 | [diff] [blame] | 116 | Remove (const Ptr<const Name> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 118 | /** |
| 119 | * @brief Invalidate all FIB entries |
| 120 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 121 | virtual void |
| 122 | InvalidateAll () = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 125 | * @brief Remove all references to a face from FIB. If for some enty that face was the only element, |
| 126 | * this FIB entry will be removed. |
| 127 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 128 | virtual void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 129 | RemoveFromAll (Ptr<Face> face) = 0; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 131 | /** |
| 132 | * @brief Print out entries in FIB |
| 133 | */ |
| 134 | virtual void |
| 135 | Print (std::ostream &os) const = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 138 | * @brief Get number of entries in FIB |
| 139 | */ |
| 140 | virtual uint32_t |
| 141 | GetSize () const = 0; |
| 142 | |
| 143 | /** |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 144 | * @brief Return first element of FIB (no order guaranteed) |
| 145 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 146 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 147 | Begin () const = 0; |
| 148 | |
| 149 | /** |
| 150 | * @brief Return first element of FIB (no order guaranteed) |
| 151 | */ |
| 152 | virtual Ptr<fib::Entry> |
| 153 | Begin () = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 154 | |
| 155 | /** |
| 156 | * @brief Return item next after last (no order guaranteed) |
| 157 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 158 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 159 | End () const = 0; |
| 160 | |
| 161 | /** |
| 162 | * @brief Return item next after last (no order guaranteed) |
| 163 | */ |
| 164 | virtual Ptr<fib::Entry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 165 | End () = 0; |
| 166 | |
| 167 | /** |
| 168 | * @brief Advance the iterator |
| 169 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 170 | virtual Ptr<const fib::Entry> |
Alexander Afanasyev | ea9b3e6 | 2012-08-13 19:02:54 -0700 | [diff] [blame] | 171 | Next (Ptr<const fib::Entry>) const = 0; |
| 172 | |
| 173 | /** |
| 174 | * @brief Advance the iterator |
| 175 | */ |
| 176 | virtual Ptr<fib::Entry> |
| 177 | Next (Ptr<fib::Entry>) = 0; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 178 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 179 | //////////////////////////////////////////////////////////////////////////// |
| 180 | //////////////////////////////////////////////////////////////////////////// |
| 181 | //////////////////////////////////////////////////////////////////////////// |
| 182 | |
| 183 | /** |
| 184 | * @brief Static call to cheat python bindings |
| 185 | */ |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 186 | static inline Ptr<Fib> |
| 187 | GetFib (Ptr<Object> node); |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 188 | |
| 189 | //////////////////////////////////////////////////////////////////////////// |
| 190 | //////////////////////////////////////////////////////////////////////////// |
| 191 | //////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 193 | private: |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 194 | Fib (const Fib&) {} ; ///< \brief copy constructor is disabled |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | /////////////////////////////////////////////////////////////////////////////// |
| 198 | /////////////////////////////////////////////////////////////////////////////// |
| 199 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 200 | std::ostream& operator<< (std::ostream& os, const Fib &fib); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 201 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 202 | Ptr<Fib> |
| 203 | Fib::GetFib (Ptr<Object> node) |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 204 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 205 | return node->GetObject<Fib> (); |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 208 | } // namespace ndn |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 209 | } // namespace ns3 |
| 210 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 211 | #endif // _NDN_FIB_H_ |