blob: b0d72898af7a325f0bbe8bf5aa36ffdbf3062d97 [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento6ad3d532017-02-17 01:43:57 -05003 * Copyright (c) 2013-2017 Regents of the University of California.
Junxiao Shi7357ef22016-09-07 02:39:37 +00004 *
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_MGMT_NFD_RIB_ENTRY_HPP
23#define NDN_MGMT_NFD_RIB_ENTRY_HPP
24
Davide Pesavento6ad3d532017-02-17 01:43:57 -050025#include "rib-flags.hpp"
Junxiao Shi7357ef22016-09-07 02:39:37 +000026#include "../../name.hpp"
27#include "../../util/time.hpp"
28
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 */
51class Route : public RibFlagsTraits<Route>
52{
53public:
54 class Error : public tlv::Error
55 {
56 public:
57 explicit
Davide Pesavento6ad3d532017-02-17 01:43:57 -050058 Error(const std::string& what)
59 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +000060 {
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&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050076 setFaceId(uint64_t faceId);
Junxiao Shi7357ef22016-09-07 02:39:37 +000077
78 uint64_t
79 getOrigin() const
80 {
81 return m_origin;
82 }
83
84 /** @brief set Origin
85 * @param origin a code defined in ndn::nfd::RouteOrigin
86 */
87 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050088 setOrigin(uint64_t origin);
Junxiao Shi7357ef22016-09-07 02:39:37 +000089
90 uint64_t
91 getCost() const
92 {
93 return m_cost;
94 }
95
96 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050097 setCost(uint64_t cost);
Junxiao Shi7357ef22016-09-07 02:39:37 +000098
99 uint64_t
100 getFlags() const
101 {
102 return m_flags;
103 }
104
105 /** @brief set route inheritance flags
106 * @param flags a bitwise OR'ed code from ndn::nfd::RouteFlags
107 */
108 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500109 setFlags(uint64_t flags);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000110
111 static const time::milliseconds INFINITE_EXPIRATION_PERIOD;
112
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500113 time::milliseconds
Junxiao Shi7357ef22016-09-07 02:39:37 +0000114 getExpirationPeriod() const
115 {
116 return m_expirationPeriod;
117 }
118
119 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500120 setExpirationPeriod(time::milliseconds expirationPeriod);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000121
122 bool
123 hasInfiniteExpirationPeriod() const
124 {
125 return m_hasInfiniteExpirationPeriod;
126 }
127
128 template<encoding::Tag TAG>
129 size_t
130 wireEncode(EncodingImpl<TAG>& block) const;
131
132 const Block&
133 wireEncode() const;
134
135 void
136 wireDecode(const Block& wire);
137
138private:
139 uint64_t m_faceId;
140 uint64_t m_origin;
141 uint64_t m_cost;
142 uint64_t m_flags;
143 time::milliseconds m_expirationPeriod;
144 bool m_hasInfiniteExpirationPeriod;
145
146 mutable Block m_wire;
147};
148
149std::ostream&
150operator<<(std::ostream& os, const Route& route);
151
152/**
153 * @ingroup management
154 *
155 * @brief Data abstraction for RIB entry
156 *
157 * A RIB entry contains one or more routes for the name prefix
158 *
159 * RibEntry := RIB-ENTRY-TYPE TLV-LENGTH
160 * Name
161 * Route+
162 *
163 * @sa http://redmine.named-data.net/projects/nfd/wiki/RibMgmt
164 */
165class RibEntry
166{
167public:
168 class Error : public tlv::Error
169 {
170 public:
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500171 explicit
172 Error(const std::string& what)
173 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000174 {
175 }
176 };
177
178 typedef std::list<Route> RouteList;
179 typedef RouteList::const_iterator iterator;
180
181 RibEntry();
182
183 explicit
184 RibEntry(const Block& block);
185
186 const Name&
187 getName() const
188 {
189 return m_prefix;
190 }
191
192 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500193 setName(const Name& prefix);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000194
195 const std::list<Route>&
196 getRoutes() const
197 {
198 return m_routes;
199 }
200
201 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500202 addRoute(const Route& route);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000203
204 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500205 clearRoutes();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000206
207 template<encoding::Tag TAG>
208 size_t
209 wireEncode(EncodingImpl<TAG>& block) const;
210
211 const Block&
212 wireEncode() const;
213
214 void
215 wireDecode(const Block& wire);
216
217 iterator
218 begin() const;
219
220 iterator
221 end() const;
222
223private:
224 Name m_prefix;
225 RouteList m_routes;
226
227 mutable Block m_wire;
228};
229
230inline RibEntry::iterator
231RibEntry::begin() const
232{
233 return m_routes.begin();
234}
235
236inline RibEntry::iterator
237RibEntry::end() const
238{
239 return m_routes.end();
240}
241
242std::ostream&
243operator<<(std::ostream& os, const RibEntry& entry);
244
245} // namespace nfd
246} // namespace ndn
247
248#endif // NDN_MGMT_NFD_RIB_ENTRY_HPP