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 | typedef ns3::Ptr<CcnxFibEntry> iterator; // not sure, but let's see what will happen |
| 41 | typedef ns3::Ptr<CcnxFibEntry> const_iterator; |
| 42 | |
| 43 | /** |
| 44 | * @brief Default constructor |
| 45 | */ |
| 46 | CcnxFib () {} |
Alexander Afanasyev | f034cbd | 2012-06-29 14:28:31 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 48 | /** |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 49 | * @brief Virtual destructor |
Alexander Afanasyev | cf133f0 | 2011-09-06 12:13:48 -0700 | [diff] [blame] | 50 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 51 | virtual ~CcnxFib () { }; |
| 52 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 53 | /** |
| 54 | * \brief Perform longest prefix match |
| 55 | * |
| 56 | * \todo Implement exclude filters |
| 57 | * |
| 58 | * \param interest Interest packet header |
Alexander Afanasyev | 8accdf6 | 2011-09-20 11:33:59 -0700 | [diff] [blame] | 59 | * \returns If entry found a valid iterator will be returned, otherwise end () |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 60 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 61 | virtual iterator |
| 62 | LongestPrefixMatch (const CcnxInterestHeader &interest) const = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 65 | * \brief Add or update FIB entry |
| 66 | * |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 67 | * If the entry exists, metric will be updated. Otherwise, new entry will be created |
| 68 | * |
| 69 | * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE |
| 70 | * |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 71 | * @param name Prefix |
| 72 | * @param face Forwarding face |
| 73 | * @param metric Routing metric |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 74 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 75 | virtual iterator |
| 76 | Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric) = 0; |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 78 | /** |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 79 | * \brief Add or update FIB entry using smart pointer to prefix |
| 80 | * |
| 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 | * |
| 85 | * @param name Smart pointer to prefix |
| 86 | * @param face Forwarding face |
| 87 | * @param metric Routing metric |
| 88 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 89 | virtual iterator |
| 90 | 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] | 91 | |
| 92 | /** |
| 93 | * @brief Remove FIB entry |
| 94 | * |
| 95 | * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid. |
| 96 | * So, simulation may crash. |
| 97 | * |
| 98 | * @param name Smart pointer to prefix |
| 99 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 100 | virtual void |
| 101 | Remove (const Ptr<const CcnxNameComponents> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * @brief Invalidate FIB entry ("Safe" version of Remove) |
| 105 | * |
| 106 | * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status |
| 107 | * @param name Smart pointer to prefix |
| 108 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 109 | virtual void |
| 110 | Invalidate (const Ptr<const CcnxNameComponents> &prefix) = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * @brief Invalidate all FIB entries |
| 114 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 115 | virtual void |
| 116 | InvalidateAll () = 0; |
Alexander Afanasyev | 8e2f112 | 2012-04-17 15:01:11 -0700 | [diff] [blame] | 117 | |
| 118 | /** |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 119 | * @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] | 120 | * entry will be removed |
| 121 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 122 | virtual void |
| 123 | Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face) = 0; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 124 | |
| 125 | /** |
| 126 | * @brief Remove all references to a face from FIB. If for some enty that face was the only element, |
| 127 | * this FIB entry will be removed. |
| 128 | */ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 129 | virtual void |
| 130 | RemoveFromAll (Ptr<CcnxFace> face) = 0; |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 131 | |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame^] | 132 | /** |
| 133 | * @brief Print out entries in FIB |
| 134 | */ |
| 135 | virtual void |
| 136 | Print (std::ostream &os) const = 0; |
| 137 | |
| 138 | // /** |
| 139 | // * @brief Modify element in container |
| 140 | // */ |
| 141 | // template<typename Modifier> |
| 142 | // virtual bool |
| 143 | // modify (iterator position, Modifier mod) = 0; |
| 144 | // // { |
| 145 | // // return this->m_fib.modify (position, mod); |
| 146 | // // } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 147 | |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 148 | private: |
| 149 | friend std::ostream& operator<< (std::ostream& os, const CcnxFib &fib); |
Alexander Afanasyev | a67e28c | 2011-08-31 21:16:25 -0700 | [diff] [blame] | 150 | CcnxFib(const CcnxFib&) {} ; ///< \brief copy constructor is disabled |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | /////////////////////////////////////////////////////////////////////////////// |
| 154 | /////////////////////////////////////////////////////////////////////////////// |
| 155 | |
| 156 | std::ostream& operator<< (std::ostream& os, const CcnxFib &fib); |
Alexander Afanasyev | 7fd74f9 | 2011-08-25 19:40:17 -0700 | [diff] [blame] | 157 | |
| 158 | } // namespace ns3 |
| 159 | |
| 160 | #endif /* NDN_FIB_H */ |