blob: e515e646c6e655dee6b7e8844ef17a2c267b99d6 [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 Pesaventod1a415c2017-02-20 00:41:42 -050025#include "route-flags-traits.hpp"
Davide Pesavento484bbe52017-02-15 00:03:46 -050026#include "../../encoding/block.hpp"
Junxiao Shi7357ef22016-09-07 02:39:37 +000027#include "../../name.hpp"
28#include "../../util/time.hpp"
29
Junxiao Shi7357ef22016-09-07 02:39:37 +000030namespace ndn {
31namespace nfd {
32
33/**
Davide Pesavento484bbe52017-02-15 00:03:46 -050034 * \ingroup management
35 * \brief represents a route in a RibEntry
Junxiao Shi7357ef22016-09-07 02:39:37 +000036 *
37 * A route indicates the availability of content via a certain face and
38 * provides meta-information about the face.
39 *
Davide Pesavento484bbe52017-02-15 00:03:46 -050040 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#Route
Junxiao Shi7357ef22016-09-07 02:39:37 +000041 */
Davide Pesaventod1a415c2017-02-20 00:41:42 -050042class Route : public RouteFlagsTraits<Route>
Junxiao Shi7357ef22016-09-07 02:39:37 +000043{
44public:
45 class Error : public tlv::Error
46 {
47 public:
48 explicit
Davide Pesavento6ad3d532017-02-17 01:43:57 -050049 Error(const std::string& what)
50 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +000051 {
52 }
53 };
54
55 Route();
56
57 explicit
58 Route(const Block& block);
59
60 uint64_t
61 getFaceId() const
62 {
63 return m_faceId;
64 }
65
66 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050067 setFaceId(uint64_t faceId);
Junxiao Shi7357ef22016-09-07 02:39:37 +000068
Davide Pesaventoe8e48c22017-04-13 00:35:33 -040069 RouteOrigin
Junxiao Shi7357ef22016-09-07 02:39:37 +000070 getOrigin() const
71 {
72 return m_origin;
73 }
74
Junxiao Shi7357ef22016-09-07 02:39:37 +000075 Route&
Davide Pesaventoe8e48c22017-04-13 00:35:33 -040076 setOrigin(RouteOrigin origin);
Junxiao Shi7357ef22016-09-07 02:39:37 +000077
78 uint64_t
79 getCost() const
80 {
81 return m_cost;
82 }
83
84 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050085 setCost(uint64_t cost);
Junxiao Shi7357ef22016-09-07 02:39:37 +000086
87 uint64_t
88 getFlags() const
89 {
90 return m_flags;
91 }
92
Junxiao Shi7357ef22016-09-07 02:39:37 +000093 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050094 setFlags(uint64_t flags);
Junxiao Shi7357ef22016-09-07 02:39:37 +000095
Davide Pesavento484bbe52017-02-15 00:03:46 -050096 bool
97 hasExpirationPeriod() const
98 {
99 return !!m_expirationPeriod;
100 }
Junxiao Shi7357ef22016-09-07 02:39:37 +0000101
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500102 time::milliseconds
Junxiao Shi7357ef22016-09-07 02:39:37 +0000103 getExpirationPeriod() const
104 {
Davide Pesavento484bbe52017-02-15 00:03:46 -0500105 return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000106 }
107
108 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500109 setExpirationPeriod(time::milliseconds expirationPeriod);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000110
Davide Pesavento484bbe52017-02-15 00:03:46 -0500111 Route&
112 unsetExpirationPeriod();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000113
114 template<encoding::Tag TAG>
115 size_t
116 wireEncode(EncodingImpl<TAG>& block) const;
117
118 const Block&
119 wireEncode() const;
120
121 void
Davide Pesavento484bbe52017-02-15 00:03:46 -0500122 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000123
124private:
125 uint64_t m_faceId;
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400126 RouteOrigin m_origin;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000127 uint64_t m_cost;
128 uint64_t m_flags;
Davide Pesavento484bbe52017-02-15 00:03:46 -0500129 optional<time::milliseconds> m_expirationPeriod;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000130
131 mutable Block m_wire;
132};
133
Davide Pesavento484bbe52017-02-15 00:03:46 -0500134bool
135operator==(const Route& a, const Route& b);
136
137inline bool
138operator!=(const Route& a, const Route& b)
139{
140 return !(a == b);
141}
142
Junxiao Shi7357ef22016-09-07 02:39:37 +0000143std::ostream&
144operator<<(std::ostream& os, const Route& route);
145
Davide Pesavento484bbe52017-02-15 00:03:46 -0500146
Junxiao Shi7357ef22016-09-07 02:39:37 +0000147/**
Davide Pesavento484bbe52017-02-15 00:03:46 -0500148 * \ingroup management
149 * \brief represents an item in NFD RIB dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000150 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500151 * A RIB entry contains one or more routes for a name prefix
Junxiao Shi7357ef22016-09-07 02:39:37 +0000152 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500153 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000154 */
155class RibEntry
156{
157public:
158 class Error : public tlv::Error
159 {
160 public:
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500161 explicit
162 Error(const std::string& what)
163 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000164 {
165 }
166 };
167
Junxiao Shi7357ef22016-09-07 02:39:37 +0000168 RibEntry();
169
170 explicit
171 RibEntry(const Block& block);
172
173 const Name&
174 getName() const
175 {
176 return m_prefix;
177 }
178
179 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500180 setName(const Name& prefix);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000181
Davide Pesavento484bbe52017-02-15 00:03:46 -0500182 const std::vector<Route>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000183 getRoutes() const
184 {
185 return m_routes;
186 }
187
Davide Pesavento484bbe52017-02-15 00:03:46 -0500188 template<typename InputIt>
189 RibEntry&
190 setRoutes(InputIt first, InputIt last)
191 {
192 m_routes.assign(first, last);
193 m_wire.reset();
194 return *this;
195 }
196
Junxiao Shi7357ef22016-09-07 02:39:37 +0000197 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500198 addRoute(const Route& route);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000199
200 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500201 clearRoutes();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000202
203 template<encoding::Tag TAG>
204 size_t
205 wireEncode(EncodingImpl<TAG>& block) const;
206
207 const Block&
208 wireEncode() const;
209
210 void
Davide Pesavento484bbe52017-02-15 00:03:46 -0500211 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000212
213private:
214 Name m_prefix;
Davide Pesavento484bbe52017-02-15 00:03:46 -0500215 std::vector<Route> m_routes;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000216
217 mutable Block m_wire;
218};
219
Davide Pesavento484bbe52017-02-15 00:03:46 -0500220bool
221operator==(const RibEntry& a, const RibEntry& b);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000222
Davide Pesavento484bbe52017-02-15 00:03:46 -0500223inline bool
224operator!=(const RibEntry& a, const RibEntry& b)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000225{
Davide Pesavento484bbe52017-02-15 00:03:46 -0500226 return !(a == b);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000227}
228
229std::ostream&
230operator<<(std::ostream& os, const RibEntry& entry);
231
232} // namespace nfd
233} // namespace ndn
234
235#endif // NDN_MGMT_NFD_RIB_ENTRY_HPP