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