blob: a04ffa12495751b277cbc6b2efa83133818e81ac [file] [log] [blame]
Junxiao Shi7357ef22016-09-07 02:39:37 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento88a0d812017-08-19 21:31:42 -04002/*
Junxiao Shi68b53852018-07-25 13:56:38 -06003 * Copyright (c) 2013-2018 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:
Junxiao Shi68b53852018-07-25 13:56:38 -060048 using tlv::Error::Error;
Junxiao Shi7357ef22016-09-07 02:39:37 +000049 };
50
51 Route();
52
53 explicit
54 Route(const Block& block);
55
56 uint64_t
57 getFaceId() const
58 {
59 return m_faceId;
60 }
61
62 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050063 setFaceId(uint64_t faceId);
Junxiao Shi7357ef22016-09-07 02:39:37 +000064
Davide Pesaventoe8e48c22017-04-13 00:35:33 -040065 RouteOrigin
Junxiao Shi7357ef22016-09-07 02:39:37 +000066 getOrigin() const
67 {
68 return m_origin;
69 }
70
Junxiao Shi7357ef22016-09-07 02:39:37 +000071 Route&
Davide Pesaventoe8e48c22017-04-13 00:35:33 -040072 setOrigin(RouteOrigin origin);
Junxiao Shi7357ef22016-09-07 02:39:37 +000073
74 uint64_t
75 getCost() const
76 {
77 return m_cost;
78 }
79
80 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050081 setCost(uint64_t cost);
Junxiao Shi7357ef22016-09-07 02:39:37 +000082
83 uint64_t
84 getFlags() const
85 {
86 return m_flags;
87 }
88
Junxiao Shi7357ef22016-09-07 02:39:37 +000089 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -050090 setFlags(uint64_t flags);
Junxiao Shi7357ef22016-09-07 02:39:37 +000091
Davide Pesavento484bbe52017-02-15 00:03:46 -050092 bool
93 hasExpirationPeriod() const
94 {
95 return !!m_expirationPeriod;
96 }
Junxiao Shi7357ef22016-09-07 02:39:37 +000097
Davide Pesavento6ad3d532017-02-17 01:43:57 -050098 time::milliseconds
Junxiao Shi7357ef22016-09-07 02:39:37 +000099 getExpirationPeriod() const
100 {
Davide Pesavento484bbe52017-02-15 00:03:46 -0500101 return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000102 }
103
104 Route&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500105 setExpirationPeriod(time::milliseconds expirationPeriod);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000106
Davide Pesavento484bbe52017-02-15 00:03:46 -0500107 Route&
108 unsetExpirationPeriod();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000109
110 template<encoding::Tag TAG>
111 size_t
112 wireEncode(EncodingImpl<TAG>& block) const;
113
114 const Block&
115 wireEncode() const;
116
117 void
Davide Pesavento484bbe52017-02-15 00:03:46 -0500118 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000119
120private:
121 uint64_t m_faceId;
Davide Pesaventoe8e48c22017-04-13 00:35:33 -0400122 RouteOrigin m_origin;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000123 uint64_t m_cost;
124 uint64_t m_flags;
Davide Pesavento484bbe52017-02-15 00:03:46 -0500125 optional<time::milliseconds> m_expirationPeriod;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000126
127 mutable Block m_wire;
128};
129
Davide Pesavento88a0d812017-08-19 21:31:42 -0400130NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Route);
131
Davide Pesavento484bbe52017-02-15 00:03:46 -0500132bool
133operator==(const Route& a, const Route& b);
134
135inline bool
136operator!=(const Route& a, const Route& b)
137{
138 return !(a == b);
139}
140
Junxiao Shi7357ef22016-09-07 02:39:37 +0000141std::ostream&
142operator<<(std::ostream& os, const Route& route);
143
Davide Pesavento484bbe52017-02-15 00:03:46 -0500144
Junxiao Shi7357ef22016-09-07 02:39:37 +0000145/**
Davide Pesavento484bbe52017-02-15 00:03:46 -0500146 * \ingroup management
147 * \brief represents an item in NFD RIB dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000148 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500149 * A RIB entry contains one or more routes for a name prefix
Junxiao Shi7357ef22016-09-07 02:39:37 +0000150 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500151 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000152 */
153class RibEntry
154{
155public:
156 class Error : public tlv::Error
157 {
158 public:
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500159 explicit
160 Error(const std::string& what)
161 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000162 {
163 }
164 };
165
Junxiao Shi7357ef22016-09-07 02:39:37 +0000166 RibEntry();
167
168 explicit
169 RibEntry(const Block& block);
170
171 const Name&
172 getName() const
173 {
174 return m_prefix;
175 }
176
177 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500178 setName(const Name& prefix);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000179
Davide Pesavento484bbe52017-02-15 00:03:46 -0500180 const std::vector<Route>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000181 getRoutes() const
182 {
183 return m_routes;
184 }
185
Davide Pesavento484bbe52017-02-15 00:03:46 -0500186 template<typename InputIt>
187 RibEntry&
188 setRoutes(InputIt first, InputIt last)
189 {
190 m_routes.assign(first, last);
191 m_wire.reset();
192 return *this;
193 }
194
Junxiao Shi7357ef22016-09-07 02:39:37 +0000195 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500196 addRoute(const Route& route);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000197
198 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500199 clearRoutes();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000200
201 template<encoding::Tag TAG>
202 size_t
203 wireEncode(EncodingImpl<TAG>& block) const;
204
205 const Block&
206 wireEncode() const;
207
208 void
Davide Pesavento484bbe52017-02-15 00:03:46 -0500209 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000210
211private:
212 Name m_prefix;
Davide Pesavento484bbe52017-02-15 00:03:46 -0500213 std::vector<Route> m_routes;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000214
215 mutable Block m_wire;
216};
217
Davide Pesavento88a0d812017-08-19 21:31:42 -0400218NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RibEntry);
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