blob: dcdfe50ed2be6667023a9945d5a18ab290cb1c71 [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
Chengyu Fana14d4912014-08-18 22:30:29 -050025#include "nfd-rib-flags.hpp"
26
Vince Lehmandbf3f702014-07-15 13:00:43 -050027#include "../encoding/block.hpp"
28#include "../encoding/encoding-buffer.hpp"
29#include "../encoding/tlv-nfd.hpp"
30#include "../name.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070031#include "../util/time.hpp"
Vince Lehmandbf3f702014-07-15 13:00:43 -050032
33#include <list>
34
35namespace ndn {
36namespace nfd {
37
38/**
39 * @ingroup management
40 *
41 * @brief Data abstraction for Route
42 *
43 * A route indicates the availability of content via a certain face and
44 * provides meta-information about the face.
45 *
46 * Route := ROUTE-TYPE TLV-LENGTH
47 * FaceId
48 * Origin
49 * Cost
50 * Flags
51 * ExpirationPeriod?
52 *
53 * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
54 */
Chengyu Fana14d4912014-08-18 22:30:29 -050055class Route : public RibFlagsTraits<Route>
Vince Lehmandbf3f702014-07-15 13:00:43 -050056{
57public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060058 class Error : public tlv::Error
Vince Lehmandbf3f702014-07-15 13:00:43 -050059 {
60 public:
61 explicit
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060062 Error(const std::string& what) : tlv::Error(what)
Vince Lehmandbf3f702014-07-15 13:00:43 -050063 {
64 }
65 };
66
67 Route();
68
69 explicit
70 Route(const Block& block);
71
72 uint64_t
73 getFaceId() const
74 {
75 return m_faceId;
76 }
77
78 Route&
79 setFaceId(uint64_t faceId)
80 {
81 m_faceId = faceId;
82 m_wire.reset();
83 return *this;
84 }
85
86 uint64_t
87 getOrigin() const
88 {
89 return m_origin;
90 }
91
92 Route&
93 setOrigin(uint64_t origin)
94 {
95 m_origin = origin;
96 m_wire.reset();
97 return *this;
98 }
99
100 uint64_t
101 getCost() const
102 {
103 return m_cost;
104 }
105
106 Route&
107 setCost(uint64_t cost)
108 {
109 m_cost = cost;
110 m_wire.reset();
111 return *this;
112 }
113
114 uint64_t
115 getFlags() const
116 {
117 return m_flags;
118 }
119
120 Route&
121 setFlags(uint64_t flags)
122 {
123 m_flags = flags;
124 m_wire.reset();
125 return *this;
126 }
127
128 static const time::milliseconds INFINITE_EXPIRATION_PERIOD;
129
130 const time::milliseconds&
131 getExpirationPeriod() const
132 {
133 return m_expirationPeriod;
134 }
135
136 Route&
137 setExpirationPeriod(const time::milliseconds& expirationPeriod)
138 {
139 m_expirationPeriod = expirationPeriod;
140
141 m_hasInfiniteExpirationPeriod = m_expirationPeriod == INFINITE_EXPIRATION_PERIOD;
142
143 m_wire.reset();
144 return *this;
145 }
146
147 bool
148 hasInfiniteExpirationPeriod() const
149 {
150 return m_hasInfiniteExpirationPeriod;
151 }
152
153 template<bool T>
154 size_t
155 wireEncode(EncodingImpl<T>& block) const;
156
157 const Block&
158 wireEncode() const;
159
160 void
161 wireDecode(const Block& wire);
162
163private:
164 uint64_t m_faceId;
165 uint64_t m_origin;
166 uint64_t m_cost;
167 uint64_t m_flags;
168 time::milliseconds m_expirationPeriod;
169 bool m_hasInfiniteExpirationPeriod;
170
171 mutable Block m_wire;
172};
173
174std::ostream&
175operator<<(std::ostream& os, const Route& route);
176
177/**
178 * @ingroup management
179 *
180 * @brief Data abstraction for RIB entry
181 *
182 * A RIB entry contains one or more routes for the name prefix
183 *
184 * RibEntry := RIB-ENTRY-TYPE TLV-LENGTH
185 * Name
186 * Route+
187 *
188 * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
189 */
190class RibEntry
191{
192public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600193 class Error : public tlv::Error
Vince Lehmandbf3f702014-07-15 13:00:43 -0500194 {
195 public:
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600196 Error(const std::string& what) : tlv::Error(what)
Vince Lehmandbf3f702014-07-15 13:00:43 -0500197 {
198 }
199 };
200
201 typedef std::list<Route> RouteList;
202 typedef RouteList::const_iterator iterator;
203
204 RibEntry();
205
206 explicit
207 RibEntry(const Block& block);
208
209 const Name&
210 getName() const
211 {
212 return m_prefix;
213 }
214
215 RibEntry&
216 setName(const Name& prefix)
217 {
218 m_prefix = prefix;
219 m_wire.reset();
220 return *this;
221 }
222
223 const std::list<Route>&
224 getRoutes() const
225 {
226 return m_routes;
227 }
228
229 RibEntry&
230 addRoute(const Route& route)
231 {
232 m_routes.push_back(route);
233 m_wire.reset();
234 return *this;
235 }
236
237 RibEntry&
238 clearRoutes()
239 {
240 m_routes.clear();
241 return *this;
242 }
243
244 template<bool T>
245 size_t
246 wireEncode(EncodingImpl<T>& block) const;
247
248 const Block&
249 wireEncode() const;
250
251 void
252 wireDecode(const Block& wire);
253
254 iterator
255 begin() const;
256
257 iterator
258 end() const;
259
260private:
261 Name m_prefix;
262 RouteList m_routes;
263
264 mutable Block m_wire;
265};
266
267inline RibEntry::iterator
268RibEntry::begin() const
269{
270 return m_routes.begin();
271}
272
273inline RibEntry::iterator
274RibEntry::end() const
275{
276 return m_routes.end();
277}
278
279std::ostream&
280operator<<(std::ostream& os, const RibEntry& entry);
281
282} // namespace nfd
283} // namespace ndn
284
285#endif // NDN_MANAGEMENT_NFD_RIB_ENTRY_HPP