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