blob: 1ea73d3587b73fb14efa3e57cec9b1374cc4376d [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/*
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 Pesavento88a0d812017-08-19 21:31:42 -0400134NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Route);
135
Davide Pesavento484bbe52017-02-15 00:03:46 -0500136bool
137operator==(const Route& a, const Route& b);
138
139inline bool
140operator!=(const Route& a, const Route& b)
141{
142 return !(a == b);
143}
144
Junxiao Shi7357ef22016-09-07 02:39:37 +0000145std::ostream&
146operator<<(std::ostream& os, const Route& route);
147
Davide Pesavento484bbe52017-02-15 00:03:46 -0500148
Junxiao Shi7357ef22016-09-07 02:39:37 +0000149/**
Davide Pesavento484bbe52017-02-15 00:03:46 -0500150 * \ingroup management
151 * \brief represents an item in NFD RIB dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000152 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500153 * A RIB entry contains one or more routes for a name prefix
Junxiao Shi7357ef22016-09-07 02:39:37 +0000154 *
Davide Pesavento484bbe52017-02-15 00:03:46 -0500155 * \sa https://redmine.named-data.net/projects/nfd/wiki/RibMgmt#RIB-Dataset
Junxiao Shi7357ef22016-09-07 02:39:37 +0000156 */
157class RibEntry
158{
159public:
160 class Error : public tlv::Error
161 {
162 public:
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500163 explicit
164 Error(const std::string& what)
165 : tlv::Error(what)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000166 {
167 }
168 };
169
Junxiao Shi7357ef22016-09-07 02:39:37 +0000170 RibEntry();
171
172 explicit
173 RibEntry(const Block& block);
174
175 const Name&
176 getName() const
177 {
178 return m_prefix;
179 }
180
181 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500182 setName(const Name& prefix);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000183
Davide Pesavento484bbe52017-02-15 00:03:46 -0500184 const std::vector<Route>&
Junxiao Shi7357ef22016-09-07 02:39:37 +0000185 getRoutes() const
186 {
187 return m_routes;
188 }
189
Davide Pesavento484bbe52017-02-15 00:03:46 -0500190 template<typename InputIt>
191 RibEntry&
192 setRoutes(InputIt first, InputIt last)
193 {
194 m_routes.assign(first, last);
195 m_wire.reset();
196 return *this;
197 }
198
Junxiao Shi7357ef22016-09-07 02:39:37 +0000199 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500200 addRoute(const Route& route);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000201
202 RibEntry&
Davide Pesavento6ad3d532017-02-17 01:43:57 -0500203 clearRoutes();
Junxiao Shi7357ef22016-09-07 02:39:37 +0000204
205 template<encoding::Tag TAG>
206 size_t
207 wireEncode(EncodingImpl<TAG>& block) const;
208
209 const Block&
210 wireEncode() const;
211
212 void
Davide Pesavento484bbe52017-02-15 00:03:46 -0500213 wireDecode(const Block& block);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000214
215private:
216 Name m_prefix;
Davide Pesavento484bbe52017-02-15 00:03:46 -0500217 std::vector<Route> m_routes;
Junxiao Shi7357ef22016-09-07 02:39:37 +0000218
219 mutable Block m_wire;
220};
221
Davide Pesavento88a0d812017-08-19 21:31:42 -0400222NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(RibEntry);
223
Davide Pesavento484bbe52017-02-15 00:03:46 -0500224bool
225operator==(const RibEntry& a, const RibEntry& b);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000226
Davide Pesavento484bbe52017-02-15 00:03:46 -0500227inline bool
228operator!=(const RibEntry& a, const RibEntry& b)
Junxiao Shi7357ef22016-09-07 02:39:37 +0000229{
Davide Pesavento484bbe52017-02-15 00:03:46 -0500230 return !(a == b);
Junxiao Shi7357ef22016-09-07 02:39:37 +0000231}
232
233std::ostream&
234operator<<(std::ostream& os, const RibEntry& entry);
235
236} // namespace nfd
237} // namespace ndn
238
239#endif // NDN_MGMT_NFD_RIB_ENTRY_HPP