blob: 8fa1704561fae67b36a298b6945829b0a0d2214b [file] [log] [blame]
Vince Lehmandbf3f702014-07-15 13:00:43 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2014 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#ifndef NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
23#define NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP
24
Junxiao Shi65f1a712014-11-20 14:59:36 -070025#include "nfd-rib-flags.hpp" // include this first, to ensure it compiles on its own.
Vince Lehmandbf3f702014-07-15 13:00:43 -050026#include "../name.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070027#include "../util/time.hpp"
Vince Lehmandbf3f702014-07-15 13:00:43 -050028
29#include <list>
30
31namespace ndn {
32namespace nfd {
33
34/**
35 * @ingroup management
36 *
37 * @brief Data abstraction for Route
38 *
39 * A route indicates the availability of content via a certain face and
40 * provides meta-information about the face.
41 *
42 * Route := ROUTE-TYPE TLV-LENGTH
43 * FaceId
44 * Origin
45 * Cost
46 * Flags
47 * ExpirationPeriod?
48 *
49 * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
50 */
Chengyu Fana14d4912014-08-18 22:30:29 -050051class Route : public RibFlagsTraits<Route>
Vince Lehmandbf3f702014-07-15 13:00:43 -050052{
53public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060054 class Error : public tlv::Error
Vince Lehmandbf3f702014-07-15 13:00:43 -050055 {
56 public:
57 explicit
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060058 Error(const std::string& what) : tlv::Error(what)
Vince Lehmandbf3f702014-07-15 13:00:43 -050059 {
60 }
61 };
62
63 Route();
64
65 explicit
66 Route(const Block& block);
67
68 uint64_t
69 getFaceId() const
70 {
71 return m_faceId;
72 }
73
74 Route&
75 setFaceId(uint64_t faceId)
76 {
77 m_faceId = faceId;
78 m_wire.reset();
79 return *this;
80 }
81
82 uint64_t
83 getOrigin() const
84 {
85 return m_origin;
86 }
87
Junxiao Shi65f1a712014-11-20 14:59:36 -070088 /** @brief set Origin
89 * @param origin a code defined in ndn::nfd::RouteOrigin
90 */
Vince Lehmandbf3f702014-07-15 13:00:43 -050091 Route&
92 setOrigin(uint64_t origin)
93 {
94 m_origin = origin;
95 m_wire.reset();
96 return *this;
97 }
98
99 uint64_t
100 getCost() const
101 {
102 return m_cost;
103 }
104
105 Route&
106 setCost(uint64_t cost)
107 {
108 m_cost = cost;
109 m_wire.reset();
110 return *this;
111 }
112
113 uint64_t
114 getFlags() const
115 {
116 return m_flags;
117 }
118
Junxiao Shi65f1a712014-11-20 14:59:36 -0700119 /** @brief set route inheritance flags
120 * @param flags a bitwise OR'ed code from ndn::nfd::RouteFlags
121 */
Vince Lehmandbf3f702014-07-15 13:00:43 -0500122 Route&
123 setFlags(uint64_t flags)
124 {
125 m_flags = flags;
126 m_wire.reset();
127 return *this;
128 }
129
130 static const time::milliseconds INFINITE_EXPIRATION_PERIOD;
131
132 const time::milliseconds&
133 getExpirationPeriod() const
134 {
135 return m_expirationPeriod;
136 }
137
138 Route&
139 setExpirationPeriod(const time::milliseconds& expirationPeriod)
140 {
141 m_expirationPeriod = expirationPeriod;
142
143 m_hasInfiniteExpirationPeriod = m_expirationPeriod == INFINITE_EXPIRATION_PERIOD;
144
145 m_wire.reset();
146 return *this;
147 }
148
149 bool
150 hasInfiniteExpirationPeriod() const
151 {
152 return m_hasInfiniteExpirationPeriod;
153 }
154
155 template<bool T>
156 size_t
157 wireEncode(EncodingImpl<T>& block) const;
158
159 const Block&
160 wireEncode() const;
161
162 void
163 wireDecode(const Block& wire);
164
165private:
166 uint64_t m_faceId;
167 uint64_t m_origin;
168 uint64_t m_cost;
169 uint64_t m_flags;
170 time::milliseconds m_expirationPeriod;
171 bool m_hasInfiniteExpirationPeriod;
172
173 mutable Block m_wire;
174};
175
176std::ostream&
177operator<<(std::ostream& os, const Route& route);
178
179/**
180 * @ingroup management
181 *
182 * @brief Data abstraction for RIB entry
183 *
184 * A RIB entry contains one or more routes for the name prefix
185 *
186 * RibEntry := RIB-ENTRY-TYPE TLV-LENGTH
187 * Name
188 * Route+
189 *
190 * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
191 */
192class RibEntry
193{
194public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600195 class Error : public tlv::Error
Vince Lehmandbf3f702014-07-15 13:00:43 -0500196 {
197 public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600198 Error(const std::string& what) : tlv::Error(what)
Vince Lehmandbf3f702014-07-15 13:00:43 -0500199 {
200 }
201 };
202
203 typedef std::list<Route> RouteList;
204 typedef RouteList::const_iterator iterator;
205
206 RibEntry();
207
208 explicit
209 RibEntry(const Block& block);
210
211 const Name&
212 getName() const
213 {
214 return m_prefix;
215 }
216
217 RibEntry&
218 setName(const Name& prefix)
219 {
220 m_prefix = prefix;
221 m_wire.reset();
222 return *this;
223 }
224
225 const std::list<Route>&
226 getRoutes() const
227 {
228 return m_routes;
229 }
230
231 RibEntry&
232 addRoute(const Route& route)
233 {
234 m_routes.push_back(route);
235 m_wire.reset();
236 return *this;
237 }
238
239 RibEntry&
240 clearRoutes()
241 {
242 m_routes.clear();
243 return *this;
244 }
245
246 template<bool T>
247 size_t
248 wireEncode(EncodingImpl<T>& block) const;
249
250 const Block&
251 wireEncode() const;
252
253 void
254 wireDecode(const Block& wire);
255
256 iterator
257 begin() const;
258
259 iterator
260 end() const;
261
262private:
263 Name m_prefix;
264 RouteList m_routes;
265
266 mutable Block m_wire;
267};
268
269inline RibEntry::iterator
270RibEntry::begin() const
271{
272 return m_routes.begin();
273}
274
275inline RibEntry::iterator
276RibEntry::end() const
277{
278 return m_routes.end();
279}
280
281std::ostream&
282operator<<(std::ostream& os, const RibEntry& entry);
283
284} // namespace nfd
285} // namespace ndn
286
287#endif // NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP