blob: eaedeeec4169d73b2d8387f81548d1715de9c123 [file] [log] [blame]
Alexander Afanasyev78057c32012-07-06 15:18:46 -07001/* -*- 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
27#include "../utils/trie-with-policy.h"
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070028#include "../utils/counting-policy.h"
Alexander Afanasyev78057c32012-07-06 15:18:46 -070029
30namespace ns3 {
31
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070032class CcnxFibEntryImpl : public CcnxFibEntry
33{
34public:
35 typedef ndnSIM::trie_with_policy<
36 CcnxNameComponents,
37 ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>,
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070038 ndnSIM::counting_policy_traits
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070039 > 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
56private:
57 trie::iterator item_;
58};
59
Alexander Afanasyev78057c32012-07-06 15:18:46 -070060struct CcnxFibEntryContainer
61{
62 typedef ndnSIM::trie_with_policy<
63 CcnxNameComponents,
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -070064 ndnSIM::smart_pointer_payload_traits<CcnxFibEntryImpl>,
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -070065 ndnSIM::counting_policy_traits
Alexander Afanasyev78057c32012-07-06 15:18:46 -070066 > type;
67};
68
69/**
70 * \ingroup ccnx
71 * \brief Class implementing FIB functionality
72 */
73class CcnxFibImpl : public CcnxFib,
74 private CcnxFibEntryContainer::type
75{
76public:
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 Afanasyev11f7bb42012-07-09 17:06:30 -070091 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev30f60e32012-07-10 14:21:16 -070092 LongestPrefixMatch (const CcnxInterestHeader &interest);
Alexander Afanasyev78057c32012-07-06 15:18:46 -070093
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070094 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev78057c32012-07-06 15:18:46 -070095 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric);
96
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -070097 virtual Ptr<CcnxFibEntry>
Alexander Afanasyev78057c32012-07-06 15:18:46 -070098 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric);
99
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700100 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700101 Remove (const Ptr<const CcnxNameComponents> &prefix);
102
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700103 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700104 InvalidateAll ();
105
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700106 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700107 RemoveFromAll (Ptr<CcnxFace> face);
108
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700109 virtual void
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700110 Print (std::ostream &os) const;
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700111
Alexander Afanasyevf1e013f2012-07-11 17:59:40 -0700112 virtual uint32_t
113 GetSize () const;
114
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700115 virtual Ptr<const CcnxFibEntry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700116 Begin ();
117
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700118 virtual Ptr<const CcnxFibEntry>
Alexander Afanasyev95a4fa32012-07-09 15:23:59 -0700119 End ();
120
Alexander Afanasyev11f7bb42012-07-09 17:06:30 -0700121 virtual Ptr<const CcnxFibEntry>
122 Next (Ptr<const CcnxFibEntry> item);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700123
Alexander Afanasyev1aa4bbc2012-07-09 17:17:25 -0700124 // /**
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 Afanasyev78057c32012-07-06 15:18:46 -0700133
134protected:
135 // inherited from Object class
136 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
137 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700138
139private:
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
145 Remove (super::parent_trie &item, Ptr<CcnxFace> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700146
147private:
148 Ptr<Node> m_node;
149};
150
151} // namespace ns3
152
153#endif /* _CCNX_FIB_IMPL_H_ */