blob: b10d558f2af976e2d970b235eefa6943f55bc715 [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
113 /**
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);
121
122 /**
123 * @brief Invalidate all FIB entries
124 */
125 void
126 InvalidateAll ();
127
128 /**
129 * @brief Remove reference to a face from the entry. If entry had only this face, the whole
130 * entry will be removed
131 */
132 void
133 Remove (const CcnxFibEntry &entry, Ptr<CcnxFace> face);
134
135 /**
136 * @brief Remove all references to a face from FIB. If for some enty that face was the only element,
137 * this FIB entry will be removed.
138 */
139 void
140 RemoveFromAll (Ptr<CcnxFace> face);
141
142 void
143 Print (std::ostream &os) const;
144
145 /**
146 * @brief Modify element in container
147 */
148 template<typename Modifier>
149 bool
150 modify (CcnxFib::iterator position, Modifier mod)
151 {
152 return this->modify (position, mod);
153 }
154
155protected:
156 // inherited from Object class
157 virtual void NotifyNewAggregate (); ///< @brief Notify when object is aggregated
158 virtual void DoDispose (); ///< @brief Perform cleanup
159
160private:
161 Ptr<Node> m_node;
162};
163
164} // namespace ns3
165
166#endif /* _CCNX_FIB_IMPL_H_ */