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 | |
| 21 | #ifndef _CCNX_FIB_IMPL_H_ |
| 22 | #define _CCNX_FIB_IMPL_H_ |
| 23 | |
| 24 | #include "ns3/ccnx-fib.h" |
| 25 | #include "ns3/ccnx-name-components.h" |
| 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 | 1ba09b8 | 2012-07-09 09:16:14 -0700 | [diff] [blame] | 32 | class CcnxFibEntryImpl : public CcnxFibEntry |
| 33 | { |
| 34 | public: |
| 35 | typedef ndnSIM::trie_with_policy< |
| 36 | CcnxNameComponents, |
| 37 | ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>, |
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 | |
| 41 | CcnxFibEntryImpl (const Ptr<const CcnxNameComponents> &prefix) |
| 42 | : CcnxFibEntry (prefix) |
| 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 | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 60 | struct CcnxFibEntryContainer |
| 61 | { |
| 62 | typedef ndnSIM::trie_with_policy< |
| 63 | CcnxNameComponents, |
Alexander Afanasyev | 1ba09b8 | 2012-07-09 09:16:14 -0700 | [diff] [blame] | 64 | ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>, |
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 | /** |
| 70 | * \ingroup ccnx |
| 71 | * \brief Class implementing FIB functionality |
| 72 | */ |
| 73 | class CcnxFibImpl : public CcnxFib, |
| 74 | private CcnxFibEntryContainer::type |
| 75 | { |
| 76 | public: |
| 77 | typedef CcnxFibEntryContainer::type super; |
| 78 | |
| 79 | /** |
| 80 | * \brief Interface ID |
| 81 | * |
| 82 | * \return interface ID |
| 83 | */ |
| 84 | static TypeId GetTypeId (); |
| 85 | |
| 86 | /** |
| 87 | * \brief Constructor |
| 88 | */ |
| 89 | CcnxFibImpl (); |
| 90 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 91 | virtual Ptr<CcnxFibEntry> |
Alexander Afanasyev | 30f60e3 | 2012-07-10 14:21:16 -0700 | [diff] [blame] | 92 | LongestPrefixMatch (const CcnxInterestHeader &interest); |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 94 | virtual Ptr<CcnxFibEntry> |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 95 | Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric); |
| 96 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 97 | virtual Ptr<CcnxFibEntry> |
Alexander Afanasyev | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 98 | Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric); |
| 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 | Remove (const Ptr<const CcnxNameComponents> &prefix); |
| 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 | 78057c3 | 2012-07-06 15:18:46 -0700 | [diff] [blame] | 107 | RemoveFromAll (Ptr<CcnxFace> face); |
| 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 | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 115 | virtual Ptr<const CcnxFibEntry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 116 | Begin (); |
| 117 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 118 | virtual Ptr<const CcnxFibEntry> |
Alexander Afanasyev | 95a4fa3 | 2012-07-09 15:23:59 -0700 | [diff] [blame] | 119 | End (); |
| 120 | |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 121 | virtual Ptr<const CcnxFibEntry> |
| 122 | Next (Ptr<const CcnxFibEntry> 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 |
| 129 | // modify (Ptr<CcnxFibEntry> item, Modifier mod) |
| 130 | // { |
| 131 | // return super::modify (StaticCast<CcnxFibEntryImpl> (item)->to_iterator (), mod); |
| 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 | b310a9a | 2012-07-20 15:29:56 -0700 | [diff] [blame] | 145 | RemoveFace (super::parent_trie &item, Ptr<CcnxFace> 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 | |
| 153 | #endif /* _CCNX_FIB_IMPL_H_ */ |