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