rib-entry.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 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_CXX_MGMT_NFD_RIB_ENTRY_HPP
23 #define NDN_CXX_MGMT_NFD_RIB_ENTRY_HPP
24 
27 #include "ndn-cxx/name.hpp"
28 #include "ndn-cxx/util/time.hpp"
29 
30 namespace ndn::nfd {
31 
41 class Route : public RouteFlagsTraits<Route>
42 {
43 public:
44  class Error : public tlv::Error
45  {
46  public:
47  using tlv::Error::Error;
48  };
49 
50  Route();
51 
52  explicit
53  Route(const Block& block);
54 
55  uint64_t
56  getFaceId() const
57  {
58  return m_faceId;
59  }
60 
61  Route&
62  setFaceId(uint64_t faceId);
63 
65  getOrigin() const
66  {
67  return m_origin;
68  }
69 
70  Route&
71  setOrigin(RouteOrigin origin);
72 
73  uint64_t
74  getCost() const
75  {
76  return m_cost;
77  }
78 
79  Route&
80  setCost(uint64_t cost);
81 
82  uint64_t
83  getFlags() const
84  {
85  return m_flags;
86  }
87 
88  Route&
89  setFlags(uint64_t flags);
90 
91  bool
93  {
94  return !!m_expirationPeriod;
95  }
96 
99  {
100  return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
101  }
102 
103  Route&
104  setExpirationPeriod(time::milliseconds expirationPeriod);
105 
106  Route&
108 
109  template<encoding::Tag TAG>
110  size_t
111  wireEncode(EncodingImpl<TAG>& block) const;
112 
113  const Block&
114  wireEncode() const;
115 
116  void
117  wireDecode(const Block& block);
118 
119 private:
120  uint64_t m_faceId = INVALID_FACE_ID;
121  RouteOrigin m_origin = ROUTE_ORIGIN_APP;
122  uint64_t m_cost = 0;
123  uint64_t m_flags = ROUTE_FLAG_CHILD_INHERIT;
124  std::optional<time::milliseconds> m_expirationPeriod;
125 
126  mutable Block m_wire;
127 };
128 
130 
131 bool
132 operator==(const Route& a, const Route& b);
133 
134 inline bool
135 operator!=(const Route& a, const Route& b)
136 {
137  return !(a == b);
138 }
139 
140 std::ostream&
141 operator<<(std::ostream& os, const Route& route);
142 
143 
152 class RibEntry
153 {
154 public:
155  class Error : public tlv::Error
156  {
157  public:
158  using tlv::Error::Error;
159  };
160 
162 
163  explicit
164  RibEntry(const Block& block);
165 
166  const Name&
167  getName() const
168  {
169  return m_prefix;
170  }
171 
172  RibEntry&
173  setName(const Name& prefix);
174 
175  const std::vector<Route>&
176  getRoutes() const
177  {
178  return m_routes;
179  }
180 
181  template<typename InputIt>
182  RibEntry&
183  setRoutes(InputIt first, InputIt last)
184  {
185  m_routes.assign(first, last);
186  m_wire.reset();
187  return *this;
188  }
189 
190  RibEntry&
191  addRoute(const Route& route);
192 
193  RibEntry&
194  clearRoutes();
195 
196  template<encoding::Tag TAG>
197  size_t
198  wireEncode(EncodingImpl<TAG>& block) const;
199 
200  const Block&
201  wireEncode() const;
202 
203  void
204  wireDecode(const Block& block);
205 
206 private:
207  Name m_prefix;
208  std::vector<Route> m_routes;
209 
210  mutable Block m_wire;
211 };
212 
214 
215 bool
216 operator==(const RibEntry& a, const RibEntry& b);
217 
218 inline bool
219 operator!=(const RibEntry& a, const RibEntry& b)
220 {
221  return !(a == b);
222 }
223 
224 std::ostream&
225 operator<<(std::ostream& os, const RibEntry& entry);
226 
227 } // namespace ndn::nfd
228 
229 #endif // NDN_CXX_MGMT_NFD_RIB_ENTRY_HPP
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
void reset() noexcept
Reset the Block to a default-constructed state.
Definition: block.cpp:293
Represents an absolute name.
Definition: name.hpp:45
Represents an item in NFD RIB dataset.
Definition: rib-entry.hpp:153
const Name & getName() const
Definition: rib-entry.hpp:167
RibEntry & setRoutes(InputIt first, InputIt last)
Definition: rib-entry.hpp:183
RibEntry & addRoute(const Route &route)
Definition: rib-entry.cpp:228
RibEntry & clearRoutes()
Definition: rib-entry.cpp:236
void wireDecode(const Block &block)
Definition: rib-entry.cpp:278
const std::vector< Route > & getRoutes() const
Definition: rib-entry.hpp:176
const Block & wireEncode() const
Definition: rib-entry.cpp:262
RibEntry & setName(const Name &prefix)
Definition: rib-entry.cpp:220
Defines getters for each route inheritance flag.
Represents a route in a RibEntry.
Definition: rib-entry.hpp:42
Route & unsetExpirationPeriod()
Definition: rib-entry.cpp:84
Route & setFlags(uint64_t flags)
Definition: rib-entry.cpp:65
bool hasExpirationPeriod() const
Definition: rib-entry.hpp:92
RouteOrigin getOrigin() const
Definition: rib-entry.hpp:65
Route & setCost(uint64_t cost)
Definition: rib-entry.cpp:57
Route & setOrigin(RouteOrigin origin)
Definition: rib-entry.cpp:49
uint64_t getFaceId() const
Definition: rib-entry.hpp:56
Route & setFaceId(uint64_t faceId)
Definition: rib-entry.cpp:41
const Block & wireEncode() const
Definition: rib-entry.cpp:114
uint64_t getFlags() const
Definition: rib-entry.hpp:83
uint64_t getCost() const
Definition: rib-entry.hpp:74
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
Definition: rib-entry.cpp:73
time::milliseconds getExpirationPeriod() const
Definition: rib-entry.hpp:98
void wireDecode(const Block &block)
Definition: rib-entry.cpp:130
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:28
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
@ ROUTE_FLAG_CHILD_INHERIT
Contains classes and functions related to the NFD Management protocol.
constexpr uint64_t INVALID_FACE_ID
bool operator!=(const ChannelStatus &a, const ChannelStatus &b)
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
::boost::chrono::milliseconds milliseconds
Definition: time.hpp:52