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