Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -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_IMPL_H_ |
| 22 | #define _NDN_FIB_IMPL_H_ |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #include "ns3/ndn-fib.h" |
| 25 | #include "ns3/ndn-name-components.h" |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 27 | #include "../../utils/trie-with-policy.h" |
| 28 | #include "../../utils/counting-policy.h" |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 29 | |
| 30 | namespace ns3 { |
| 31 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 32 | class NdnFibEntryImpl : public NdnFibEntry |
Alexander Afanasyev | 1ba09b8 | 2012-07-09 09:16:14 -0700 | [diff] [blame] | 33 | { |
| 34 | public: |
| 35 | typedef ndnSIM::trie_with_policy< |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 36 | NdnNameComponents, |
| 37 | ndnSIM::smart_pointer_payload_traits<NdnFibEntryImpl>, |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 38 | ndnSIM::counting_policy_traits |
Alexander Afanasyev | 1ba09b8 | 2012-07-09 09:16:14 -0700 | [diff] [blame] | 39 | > trie; |
| 40 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 41 | NdnFibEntryImpl (const Ptr<const NdnNameComponents> &prefix) |
| 42 | : NdnFibEntry (prefix) |
Alexander Afanasyev | 1ba09b8 | 2012-07-09 09:16:14 -0700 | [diff] [blame] | 43 | , item_ (0) |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | SetTrie (trie::iterator item) |
| 49 | { |
| 50 | item_ = item; |
| 51 | } |
| 52 | |
| 53 | trie::iterator to_iterator () { return item_; } |
| 54 | trie::const_iterator to_iterator () const { return item_; } |
| 55 | |
| 56 | private: |
| 57 | trie::iterator item_; |
| 58 | }; |
| 59 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 60 | struct NdnFibEntryContainer |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 61 | { |
| 62 | typedef ndnSIM::trie_with_policy< |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 63 | NdnNameComponents, |
| 64 | ndnSIM::smart_pointer_payload_traits<NdnFibEntryImpl>, |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 65 | ndnSIM::counting_policy_traits |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 66 | > type; |
| 67 | }; |
| 68 | |
| 69 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 70 | * \ingroup ndn |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 71 | * \brief Class implementing FIB functionality |
| 72 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 73 | class NdnFibImpl : public NdnFib, |
| 74 | private NdnFibEntryContainer::type |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 75 | { |
| 76 | public: |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 77 | typedef NdnFibEntryContainer::type super; |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * \brief Interface ID |
| 81 | * |
| 82 | * \return interface ID |
| 83 | */ |
| 84 | static TypeId GetTypeId (); |
| 85 | |
| 86 | /** |
| 87 | * \brief Constructor |
| 88 | */ |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 89 | NdnFibImpl (); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 91 | virtual Ptr<NdnFibEntry> |
| 92 | LongestPrefixMatch (const NdnInterestHeader &interest); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 94 | virtual Ptr<NdnFibEntry> |
| 95 | Add (const NdnNameComponents &prefix, Ptr<NdnFace> face, int32_t metric); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 97 | virtual Ptr<NdnFibEntry> |
| 98 | Add (const Ptr<const NdnNameComponents> &prefix, Ptr<NdnFace> face, int32_t metric); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 100 | virtual void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 101 | Remove (const Ptr<const NdnNameComponents> &prefix); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 102 | |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 103 | virtual void |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 104 | InvalidateAll (); |
| 105 | |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 106 | virtual void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 107 | RemoveFromAll (Ptr<NdnFace> face); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 108 | |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 109 | virtual void |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 110 | Print (std::ostream &os) const; |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 111 | |
Alexander Afanasyev | f1e013f | 2012-07-11 17:59:40 -0700 | [diff] [blame] | 112 | virtual uint32_t |
| 113 | GetSize () const; |
| 114 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 115 | virtual Ptr<const NdnFibEntry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 116 | Begin (); |
| 117 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 118 | virtual Ptr<const NdnFibEntry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 119 | End (); |
| 120 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 121 | virtual Ptr<const NdnFibEntry> |
| 122 | Next (Ptr<const NdnFibEntry> item); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 123 | |
Alexander Afanasyev | 1aa4bbc | 2012-07-09 17:17:25 -0700 | [diff] [blame] | 124 | // /** |
| 125 | // * @brief Modify element in container |
| 126 | // */ |
| 127 | // template<typename Modifier> |
| 128 | // bool |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 129 | // modify (Ptr<NdnFibEntry> item, Modifier mod) |
Alexander Afanasyev | 1aa4bbc | 2012-07-09 17:17:25 -0700 | [diff] [blame] | 130 | // { |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 131 | // return super::modify (StaticCast<NdnFibEntryImpl> (item)->to_iterator (), mod); |
Alexander Afanasyev | 1aa4bbc | 2012-07-09 17:17:25 -0700 | [diff] [blame] | 132 | // } |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 133 | |
| 134 | protected: |
| 135 | // inherited from Object class |
| 136 | virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated |
| 137 | virtual void DoDispose (); ///< @brief Perform cleanup |
Alexander Afanasyev | 44bb6ea | 2012-07-09 08:44:41 -0700 | [diff] [blame] | 138 | |
| 139 | private: |
| 140 | /** |
| 141 | * @brief Remove reference to a face from the entry. If entry had only this face, the whole |
| 142 | * entry will be removed |
| 143 | */ |
| 144 | void |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 145 | RemoveFace (super::parent_trie &item, Ptr<NdnFace> face); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 146 | |
| 147 | private: |
| 148 | Ptr<Node> m_node; |
| 149 | }; |
| 150 | |
| 151 | } // namespace ns3 |
| 152 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 153 | #endif /* _NDN_FIB_IMPL_H_ */ |