blob: 5ef96104b0feae92602e421f698d5f086fc4c0f1 [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
32struct CcnxFibEntryContainer
33{
34 typedef ndnSIM::trie_with_policy<
35 CcnxNameComponents,
36 ndnSIM::smart_pointer_payload_traits<CcnxFibEntry>,
37 ndnSIM::empty_policy_traits
38 > type;
39};
40
41/**
42 * \ingroup ccnx
43 * \brief Class implementing FIB functionality
44 */
45class CcnxFibImpl : public CcnxFib,
46 private CcnxFibEntryContainer::type
47{
48public:
49 typedef CcnxFibEntryContainer::type super;
50
51 /**
52 * \brief Interface ID
53 *
54 * \return interface ID
55 */
56 static TypeId GetTypeId ();
57
58 /**
59 * \brief Constructor
60 */
61 CcnxFibImpl ();
62
63 /**
64 * \brief Perform longest prefix match
65 *
66 * \todo Implement exclude filters
67 *
68 * \param interest Interest packet header
69 * \returns If entry found a valid iterator will be returned, otherwise end ()
70 */
71 CcnxFib::iterator
72 LongestPrefixMatch (const CcnxInterestHeader &interest) const;
73
74 /**
75 * \brief Add or update FIB entry
76 *
77 * If the entry exists, metric will be updated. Otherwise, new entry will be created
78 *
79 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
80 *
81 * @param name Prefix
82 * @param face Forwarding face
83 * @param metric Routing metric
84 */
85 CcnxFib::iterator
86 Add (const CcnxNameComponents &prefix, Ptr<CcnxFace> face, int32_t metric);
87
88 /**
89 * \brief Add or update FIB entry using smart pointer to prefix
90 *
91 * If the entry exists, metric will be updated. Otherwise, new entry will be created
92 *
93 * Entries in FIB never deleted. They can be invalidated with metric==NETWORK_UNREACHABLE
94 *
95 * @param name Smart pointer to prefix
96 * @param face Forwarding face
97 * @param metric Routing metric
98 */
99 CcnxFib::iterator
100 Add (const Ptr<const CcnxNameComponents> &prefix, Ptr<CcnxFace> face, int32_t metric);
101
102 /**
103 * @brief Remove FIB entry
104 *
105 * ! ATTENTION ! Use with caution. All PIT entries referencing the corresponding FIB entry will become invalid.
106 * So, simulation may crash.
107 *
108 * @param name Smart pointer to prefix
109 */
110 void
111 Remove (const Ptr<const CcnxNameComponents> &prefix);
112
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700113 // /**
114 // * @brief Invalidate FIB entry ("Safe" version of Remove)
115 // *
116 // * All faces for the entry will be assigned maximum routing metric and NDN_FIB_RED status
117 // * @param name Smart pointer to prefix
118 // */
119 // void
120 // Invalidate (const Ptr<const CcnxNameComponents> &prefix);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700121
122 /**
123 * @brief Invalidate all FIB entries
124 */
125 void
126 InvalidateAll ();
127
128 /**
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700129 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
130 * this FIB entry will be removed.
131 */
132 void
133 RemoveFromAll (Ptr<CcnxFace> face);
134
135 void
136 Print (std::ostream &os) const;
137
138 /**
139 * @brief Modify element in container
140 */
141 template<typename Modifier>
142 bool
143 modify (CcnxFib::iterator position, Modifier mod)
144 {
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700145 mod (*position);
146
147 return true;
148 // somehow we need to obtain trie iterator from the payload...
149 // super::getPolicy ().
150 // return super::modify (position, mod);
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700151 }
152
153protected:
154 // inherited from Object class
155 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
156 virtual void DoDispose (); ///< @brief Perform cleanup
Alexander Afanasyev44bb6ea2012-07-09 08:44:41 -0700157
158private:
159 /**
160 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
161 * entry will be removed
162 */
163 void
164 Remove (super::parent_trie &item, Ptr<CcnxFace> face);
165
Alexander Afanasyev78057c32012-07-06 15:18:46 -0700166
167private:
168 Ptr<Node> m_node;
169};
170
171} // namespace ns3
172
173#endif /* _CCNX_FIB_IMPL_H_ */