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 | 161a5c4 | 2012-04-17 15:14:04 -0700 | [diff] [blame] | 24 | #include "ccnx-name-components-hash-helper.h" |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 25 | #include "ccnx-face.h" |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 26 | #include "ccnx.h" |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 27 | #include "ns3/nstime.h" |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 28 | #include "ns3/simple-ref-count.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 29 | #include "ns3/node.h" |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 30 | |
| 31 | #include <boost/multi_index_container.hpp> |
| 32 | #include <boost/multi_index/tag.hpp> |
| 33 | #include <boost/multi_index/ordered_index.hpp> |
| 34 | #include <boost/multi_index/composite_key.hpp> |
| 35 | #include <boost/multi_index/hashed_index.hpp> |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 36 | #include <boost/multi_index/random_access_index.hpp> |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 37 | #include <boost/multi_index/member.hpp> |
| 38 | #include <boost/multi_index/mem_fun.hpp> |
| 39 | |
| 40 | #include <iostream> |
| 41 | |
| 42 | namespace ns3 { |
| 43 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 44 | class CcnxInterestHeader; |
| 45 | |
| 46 | /** |
| 47 | * \ingroup ccnx |
| 48 | * \brief Structure holding various parameters associated with a (FibEntry, Face) tuple |
| 49 | */ |
| 50 | class CcnxFibFaceMetric |
| 51 | { |
| 52 | public: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 53 | /** |
| 54 | * @brief Color codes for FIB face status |
| 55 | */ |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 56 | enum Status { NDN_FIB_GREEN = 1, |
| 57 | NDN_FIB_YELLOW = 2, |
| 58 | NDN_FIB_RED = 3 }; |
| 59 | public: |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 60 | /** |
| 61 | * \brief Metric constructor |
| 62 | * |
| 63 | * \param face Face for which metric |
| 64 | * \param cost Initial value for routing cost |
| 65 | */ |
Alexander Afanasyev | ef05655 | 2012-01-20 16:19:12 -0800 | [diff] [blame] | 66 | CcnxFibFaceMetric (Ptr<CcnxFace> face, int32_t cost) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 67 | : m_face (face) |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 68 | , m_status (NDN_FIB_YELLOW) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 69 | , m_routingCost (cost) |
| 70 | , m_sRtt (Seconds (0)) |
| 71 | , m_rttVar (Seconds (0)) |
| 72 | { } |
| 73 | |
| 74 | /** |
| 75 | * \brief Comparison operator used by boost::multi_index::identity<> |
| 76 | */ |
| 77 | bool |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 78 | operator< (const CcnxFibFaceMetric &fm) const { return *m_face < *fm.m_face; } // return identity of the face |
| 79 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 80 | /** |
| 81 | * @brief Comparison between CcnxFibFaceMetric and CcnxFace |
| 82 | */ |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 83 | bool |
| 84 | operator< (const Ptr<CcnxFace> &face) const { return *m_face < *face; } |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 85 | |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 86 | /** |
| 87 | * @brief Return CcnxFace associated with CcnxFibFaceMetric |
| 88 | */ |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 89 | Ptr<CcnxFace> |
| 90 | GetFace () const { return m_face; } |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 91 | |
| 92 | /** |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 93 | * \brief Recalculate smoothed RTT and RTT variation |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 94 | * \param rttSample RTT sample |
| 95 | */ |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 96 | void |
| 97 | UpdateRtt (const Time &rttSample); |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 99 | private: |
| 100 | friend std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric); |
| 101 | public: |
| 102 | Ptr<CcnxFace> m_face; ///< Face |
| 103 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 104 | Status m_status; ///< \brief Status of the next hop: |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 105 | ///< - NDN_FIB_GREEN |
| 106 | ///< - NDN_FIB_YELLOW |
| 107 | ///< - NDN_FIB_RED |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 109 | int32_t m_routingCost; ///< \brief routing protocol cost (interpretation of the value depends on the underlying routing protocol) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 110 | |
| 111 | Time m_sRtt; ///< \brief smoothed round-trip time |
| 112 | Time m_rttVar; ///< \brief round-trip time variation |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * \ingroup ccnx |
| 117 | * \brief Typedef for indexed face container of CcnxFibEntry |
| 118 | * |
| 119 | * Currently, there are 2 indexes: |
| 120 | * - by face (used to find record and update metric) |
| 121 | * - by metric (face ranking) |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 122 | * - random access index (for fast lookup on nth face). Order is |
| 123 | * maintained manually to be equal to the 'by metric' order |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 124 | */ |
| 125 | struct CcnxFibFaceMetricContainer |
| 126 | { |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 127 | /// @cond include_hidden |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 128 | typedef boost::multi_index::multi_index_container< |
| 129 | CcnxFibFaceMetric, |
| 130 | boost::multi_index::indexed_by< |
| 131 | // For fast access to elements using CcnxFace |
| 132 | boost::multi_index::ordered_unique< |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 133 | boost::multi_index::tag<__ccnx_private::i_face>, |
| 134 | boost::multi_index::member<CcnxFibFaceMetric,Ptr<CcnxFace>,&CcnxFibFaceMetric::m_face> |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 135 | >, |
| 136 | |
| 137 | // List of available faces ordered by (status, m_routingCost) |
| 138 | boost::multi_index::ordered_non_unique< |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 139 | boost::multi_index::tag<__ccnx_private::i_metric>, |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 140 | boost::multi_index::composite_key< |
| 141 | CcnxFibFaceMetric, |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 142 | boost::multi_index::member<CcnxFibFaceMetric,CcnxFibFaceMetric::Status,&CcnxFibFaceMetric::m_status>, |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 143 | boost::multi_index::member<CcnxFibFaceMetric,int32_t,&CcnxFibFaceMetric::m_routingCost> |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 144 | > |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 145 | >, |
| 146 | |
| 147 | // To optimize nth candidate selection (sacrifice a little bit space to gain speed) |
| 148 | boost::multi_index::random_access< |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 149 | boost::multi_index::tag<__ccnx_private::i_nth> |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 150 | > |
| 151 | > |
| 152 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 153 | /// @endcond |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | /** |
| 157 | * \ingroup ccnx |
| 158 | * \brief Structure for FIB table entry, holding indexed list of |
| 159 | * available faces and their respective metrics |
| 160 | */ |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 161 | class CcnxFibEntry // : public SimpleRefCount<CcnxFibEntry> |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 162 | { |
| 163 | public: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 164 | class NoFaces {}; ///< @brief Exception class for the case when FIB entry is not found |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 165 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 166 | /** |
| 167 | * \brief Constructor |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 168 | * \param prefix smart pointer to the prefix for the FIB entry |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 169 | */ |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 170 | CcnxFibEntry (const Ptr<const CcnxNameComponents> &prefix) |
| 171 | : m_prefix (prefix) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 172 | , m_needsProbing (false) |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 173 | { } |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 174 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 175 | /** |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 176 | * \brief Update status of FIB next hop |
| 177 | * \param status Status to set on the FIB entry |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 178 | */ |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 179 | void UpdateStatus (Ptr<CcnxFace> face, CcnxFibFaceMetric::Status status); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 181 | /** |
| 182 | * \brief Add or update routing metric of FIB next hop |
| 183 | * |
| 184 | * Initial status of the next hop is set to YELLOW |
| 185 | */ |
| 186 | void AddOrUpdateRoutingMetric (Ptr<CcnxFace> face, int32_t metric); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 187 | |
| 188 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 189 | * @brief Invalidate face |
| 190 | * |
| 191 | * Set routing metric on all faces to max and status to RED |
| 192 | */ |
| 193 | void |
| 194 | Invalidate (); |
| 195 | |
| 196 | /** |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 197 | * @brief Update RTT averages for the face |
| 198 | */ |
| 199 | void |
| 200 | UpdateFaceRtt (Ptr<CcnxFace> face, const Time &sample); |
| 201 | |
| 202 | /** |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 203 | * \brief Get prefix for the FIB entry |
| 204 | */ |
| 205 | const CcnxNameComponents& |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 206 | GetPrefix () const { return *m_prefix; } |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 207 | |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 208 | /** |
| 209 | * \brief Find "best route" candidate, skipping `skip' first candidates (modulo # of faces) |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 210 | * |
| 211 | * throws CcnxFibEntry::NoFaces if m_faces.size()==0 |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 212 | */ |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 213 | const CcnxFibFaceMetric & |
| 214 | FindBestCandidate (uint32_t skip = 0) const; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * @brief Remove record associated with `face` |
| 218 | */ |
| 219 | void |
| 220 | RemoveFace (const Ptr<CcnxFace> &face) |
| 221 | { |
| 222 | m_faces.erase (face); |
| 223 | } |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 224 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 225 | private: |
| 226 | friend std::ostream& operator<< (std::ostream& os, const CcnxFibEntry &entry); |
| 227 | |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 228 | public: |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 229 | Ptr<const CcnxNameComponents> m_prefix; ///< \brief Prefix of the FIB entry |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 230 | CcnxFibFaceMetricContainer::type m_faces; ///< \brief Indexed list of faces |
| 231 | |
| 232 | bool m_needsProbing; ///< \brief flag indicating that probing should be performed |
| 233 | }; |
| 234 | |
| 235 | /////////////////////////////////////////////////////////////////////////////// |
| 236 | /////////////////////////////////////////////////////////////////////////////// |
| 237 | |
| 238 | /** |
| 239 | * \ingroup ccnx |
| 240 | * \brief Typedef for indexed container for FIB entries |
| 241 | * |
| 242 | * Currently, there is only one index |
| 243 | * - by prefix hash, which is used to perform prefix match |
| 244 | */ |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 245 | struct CcnxFibEntryContainer |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 246 | { |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 247 | /// @cond include_hidden |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 248 | typedef boost::multi_index::multi_index_container< |
| 249 | CcnxFibEntry, |
| 250 | boost::multi_index::indexed_by< |
| 251 | // For fast access to elements using CcnxFace |
| 252 | boost::multi_index::hashed_unique< |
Alexander Afanasyev | 78cf0c9 | 2011-09-01 19:57:14 -0700 | [diff] [blame] | 253 | boost::multi_index::tag<__ccnx_private::i_prefix>, |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 254 | boost::multi_index::const_mem_fun<CcnxFibEntry, |
| 255 | const CcnxNameComponents&, |
Alexander Afanasyev | a98cdd2 | 2011-08-29 17:32:37 -0700 | [diff] [blame] | 256 | &CcnxFibEntry::GetPrefix>, |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 257 | CcnxPrefixHash>, |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 258 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 259 | boost::multi_index::random_access< |
| 260 | boost::multi_index::tag<__ccnx_private::i_nth> |
| 261 | > |
| 262 | > |
| 263 | > type; |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 264 | /// @endcond |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 265 | }; |
| 266 | |
| 267 | /** |
| 268 | * \ingroup ccnx |
| 269 | * \brief Class implementing FIB functionality |
| 270 | */ |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 271 | class CcnxFib : public Object |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 272 | { |
| 273 | public: |
| 274 | /** |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 275 | * \brief Interface ID |
| 276 | * |
| 277 | * \return interface ID |
| 278 | */ |
| 279 | static TypeId GetTypeId (); |
| 280 | |
| 281 | /** |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 282 | * \brief Constructor |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 283 | */ |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 284 | CcnxFib (); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 285 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 286 | /** |
| 287 | * \brief Perform longest prefix match |
| 288 | * |
| 289 | * \todo Implement exclude filters |
| 290 | * |
| 291 | * \param interest Interest packet header |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 292 | * \returns If entry found a valid iterator will be returned, otherwise end () |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 293 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 294 | CcnxFibEntryContainer::type::iterator |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 295 | LongestPrefixMatch (const CcnxInterestHeader &interest) const; |
| 296 | |
| 297 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 298 | * \brief Add or update FIB entry |
| 299 | * |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 300 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 301 | * |
| 302 | * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE |
| 303 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 304 | * @param name Prefix |
| 305 | * @param face Forwarding face |
| 306 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 307 | */ |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 308 | CcnxFibEntryContainer::type::iterator |
| 309 | Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 310 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 311 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 312 | * \brief Add or update FIB entry using smart pointer to prefix |
| 313 | * |
| 314 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 315 | * |
| 316 | * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE |
| 317 | * |
| 318 | * @param name Smart pointer to prefix |
| 319 | * @param face Forwarding face |
| 320 | * @param metric Routing metric |
| 321 | */ |
| 322 | CcnxFibEntryContainer::type::iterator |
| 323 | Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric); |
| 324 | |
| 325 | /** |
| 326 | * @brief Remove FIB entry |
| 327 | * |
| 328 | * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid. |
| 329 | * So, simulation may crash. |
| 330 | * |
| 331 | * @param name Smart pointer to prefix |
| 332 | */ |
| 333 | void |
| 334 | Remove (const Ptr<const CcnxNameComponents> &prefix); |
| 335 | |
| 336 | /** |
| 337 | * @brief Invalidate FIB entry ("Safe" version of Remove) |
| 338 | * |
| 339 | * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status |
| 340 | * @param name Smart pointer to prefix |
| 341 | */ |
| 342 | void |
| 343 | Invalidate (const Ptr<const CcnxNameComponents> &prefix); |
| 344 | |
| 345 | /** |
| 346 | * @brief Invalidate all FIB entries |
| 347 | */ |
| 348 | void |
| 349 | InvalidateAll (); |
| 350 | |
| 351 | /** |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 352 | * @brief Remove reference to a face from the entry. If entry had only this face, the whole |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 353 | * entry will be removed |
| 354 | */ |
| 355 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 356 | Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 357 | |
| 358 | /** |
| 359 | * @brief Remove all references to a face from FIB. If for some enty that face was the only element, |
| 360 | * this FIB entry will be removed. |
| 361 | */ |
| 362 | void |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 363 | RemoveFromAll (Ptr<CcnxFace> face); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 364 | |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 365 | /** |
| 366 | * \brief Get number of FIB entry (for python bindings) |
| 367 | */ |
| 368 | uint32_t |
| 369 | GetCcnxFibEntryCount () const; |
| 370 | |
| 371 | /** |
| 372 | * \brief Get FIB entry by index (for python bindings) |
| 373 | */ |
| 374 | const CcnxFibEntry & |
| 375 | GetCcnxFibEntry (uint32_t index); |
| 376 | |
| 377 | public: |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 378 | CcnxFibEntryContainer::type m_fib; ///< @brief Internal container |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 379 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 380 | protected: |
| 381 | // inherited from Object class |
Alexander Afanasyev | b4fee8b | 2012-06-06 12:54:26 -0700 | [diff] [blame] | 382 | virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated |
| 383 | virtual void DoDispose (); ///< @brief Perform cleanup |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 384 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 385 | private: |
| 386 | friend std::ostream& operator<< (std::ostream& os, const CcnxFib &fib); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 387 | CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled |
| 388 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 389 | private: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 390 | Ptr<Node> m_node; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | /////////////////////////////////////////////////////////////////////////////// |
| 394 | /////////////////////////////////////////////////////////////////////////////// |
| 395 | |
| 396 | std::ostream& operator<< (std::ostream& os, const CcnxFib &fib); |
| 397 | std::ostream& operator<< (std::ostream& os, const CcnxFibEntry &entry); |
| 398 | std::ostream& operator<< (std::ostream& os, const CcnxFibFaceMetric &metric); |
| 399 | |
| 400 | } // namespace ns3 |
| 401 | |
| 402 | #endif /* NDN_FIB_H */ |