blob: 071c07d3ee77346f9bd7dd545c3461ad5edee89a [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"
28#include "../utils/empty-policy.h"
29
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>,
38 ndnSIM::empty_policy_traits
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
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 Afanasyev78057c32012-07-06 15:18:46 -070065 ndnSIM::empty_policy_traits
66 > 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
91 /**
92 * \brief Perform longest prefix match
93 *
94 * \todo Implement exclude filters
95 *
96 * \param interest Interest packet header
97 * \returns If entry found a valid iterator will be returned, otherwise end ()
98 */
99 CcnxFib::iterator
100 LongestPrefixMatch (const CcnxInterestHeader &interest) const;
101
102 /**
103 * \brief Add or update FIB entry
104 *
105 * If the entry exists, metric will be updated. Otherwise, new entry will be created
106 *
107 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
108 *
109 * @param name Prefix
110 * @param face Forwarding face
111 * @param metric Routing metric
112 */
113 CcnxFib::iterator
114 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric);
115
116 /**
117 * \brief Add or update FIB entry using smart pointer to prefix
118 *
119 * If the entry exists, metric will be updated. Otherwise, new entry will be created
120 *
121 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
122 *
123 * @param name Smart pointer to prefix
124 * @param face Forwarding face
125 * @param metric Routing metric
126 */
127 CcnxFib::iterator
128 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric);
129
130 /**
131 * @brief Remove FIB entry
132 *
133 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
134 * So, simulation may crash.
135 *
136 * @param name Smart pointer to prefix
137 */
138 void
139 Remove (const Ptr<const CcnxNameComponents> &prefix);
140
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700141 // /**
142 // * @brief Invalidate FIB entry ("Safe" version of Remove)
143 // *
144 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
145 // * @param name Smart pointer to prefix
146 // */
147 // void
148 // Invalidate (const Ptr<const CcnxNameComponents> &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700149
150 /**
151 * @brief Invalidate all FIB entries
152 */
153 void
154 InvalidateAll ();
155
156 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700157 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
158 * this FIB entry will be removed.
159 */
160 void
161 RemoveFromAll (Ptr<CcnxFace> face);
162
163 void
164 Print (std::ostream &os) const;
165
166 /**
167 * @brief Modify element in container
168 */
169 template<typename Modifier>
170 bool
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -0700171 modify (CcnxFib::iterator item, Modifier mod)
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700172 {
Alexander Afanasyev1ba09b82012-07-09 09:16:14 -0700173 return super::modify (StaticCast<CcnxFibEntryImpl> (item)->to_iterator (), mod);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700174 }
175
176protected:
177 // inherited from Object class
178 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
179 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700180
181private:
182 /**
183 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
184 * entry will be removed
185 */
186 void
187 Remove (super::parent_trie &item, Ptr<CcnxFace> face);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700188
189private:
190 Ptr<Node> m_node;
191};
192
193} // namespace ns3
194
195#endif /* _CCNX_FIB_IMPL_H_ */