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-2022 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 
25 #include "ndn-cxx/name.hpp"
28 #include "ndn-cxx/util/time.hpp"
29 
30 namespace ndn {
31 namespace nfd {
32 
42 class Route : public RouteFlagsTraits<Route>
43 {
44 public:
45  class Error : public tlv::Error
46  {
47  public:
48  using tlv::Error::Error;
49  };
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&
63  setFaceId(uint64_t faceId);
64 
66  getOrigin() const
67  {
68  return m_origin;
69  }
70 
71  Route&
72  setOrigin(RouteOrigin origin);
73 
74  uint64_t
75  getCost() const
76  {
77  return m_cost;
78  }
79 
80  Route&
81  setCost(uint64_t cost);
82 
83  uint64_t
84  getFlags() const
85  {
86  return m_flags;
87  }
88 
89  Route&
90  setFlags(uint64_t flags);
91 
92  bool
94  {
95  return !!m_expirationPeriod;
96  }
97 
100  {
101  return m_expirationPeriod ? *m_expirationPeriod : time::milliseconds::max();
102  }
103 
104  Route&
105  setExpirationPeriod(time::milliseconds expirationPeriod);
106 
107  Route&
109 
110  template<encoding::Tag TAG>
111  size_t
112  wireEncode(EncodingImpl<TAG>& block) const;
113 
114  const Block&
115  wireEncode() const;
116 
117  void
118  wireDecode(const Block& block);
119 
120 private:
121  uint64_t m_faceId;
122  RouteOrigin m_origin;
123  uint64_t m_cost;
124  uint64_t m_flags;
125  optional<time::milliseconds> m_expirationPeriod;
126 
127  mutable Block m_wire;
128 };
129 
131 
132 bool
133 operator==(const Route& a, const Route& b);
134 
135 inline bool
136 operator!=(const Route& a, const Route& b)
137 {
138  return !(a == b);
139 }
140 
141 std::ostream&
142 operator<<(std::ostream& os, const Route& route);
143 
144 
153 class RibEntry
154 {
155 public:
156  class Error : public tlv::Error
157  {
158  public:
159  using tlv::Error::Error;
160  };
161 
163 
164  explicit
165  RibEntry(const Block& block);
166 
167  const Name&
168  getName() const
169  {
170  return m_prefix;
171  }
172 
173  RibEntry&
174  setName(const Name& prefix);
175 
176  const std::vector<Route>&
177  getRoutes() const
178  {
179  return m_routes;
180  }
181 
182  template<typename InputIt>
183  RibEntry&
184  setRoutes(InputIt first, InputIt last)
185  {
186  m_routes.assign(first, last);
187  m_wire.reset();
188  return *this;
189  }
190 
191  RibEntry&
192  addRoute(const Route& route);
193 
194  RibEntry&
195  clearRoutes();
196 
197  template<encoding::Tag TAG>
198  size_t
199  wireEncode(EncodingImpl<TAG>& block) const;
200 
201  const Block&
202  wireEncode() const;
203 
204  void
205  wireDecode(const Block& block);
206 
207 private:
208  Name m_prefix;
209  std::vector<Route> m_routes;
210 
211  mutable Block m_wire;
212 };
213 
215 
216 bool
217 operator==(const RibEntry& a, const RibEntry& b);
218 
219 inline bool
220 operator!=(const RibEntry& a, const RibEntry& b)
221 {
222  return !(a == b);
223 }
224 
225 std::ostream&
226 operator<<(std::ostream& os, const RibEntry& entry);
227 
228 } // namespace nfd
229 } // namespace ndn
230 
231 #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:254
Represents an absolute name.
Definition: name.hpp:44
Represents an item in NFD RIB dataset.
Definition: rib-entry.hpp:154
const Name & getName() const
Definition: rib-entry.hpp:168
RibEntry & setRoutes(InputIt first, InputIt last)
Definition: rib-entry.hpp:184
RibEntry & addRoute(const Route &route)
Definition: rib-entry.cpp:239
RibEntry & clearRoutes()
Definition: rib-entry.cpp:247
void wireDecode(const Block &block)
Definition: rib-entry.cpp:289
const std::vector< Route > & getRoutes() const
Definition: rib-entry.hpp:177
const Block & wireEncode() const
Definition: rib-entry.cpp:273
RibEntry & setName(const Name &prefix)
Definition: rib-entry.cpp:231
Defines getters for each route inheritance flag.
Represents a route in a RibEntry.
Definition: rib-entry.hpp:43
Route & unsetExpirationPeriod()
Definition: rib-entry.cpp:95
Route & setFlags(uint64_t flags)
Definition: rib-entry.cpp:76
bool hasExpirationPeriod() const
Definition: rib-entry.hpp:93
RouteOrigin getOrigin() const
Definition: rib-entry.hpp:66
Route & setCost(uint64_t cost)
Definition: rib-entry.cpp:68
Route & setOrigin(RouteOrigin origin)
Definition: rib-entry.cpp:60
uint64_t getFaceId() const
Definition: rib-entry.hpp:57
Route & setFaceId(uint64_t faceId)
Definition: rib-entry.cpp:52
const Block & wireEncode() const
Definition: rib-entry.cpp:125
uint64_t getFlags() const
Definition: rib-entry.hpp:84
uint64_t getCost() const
Definition: rib-entry.hpp:75
Route & setExpirationPeriod(time::milliseconds expirationPeriod)
Definition: rib-entry.cpp:84
time::milliseconds getExpirationPeriod() const
Definition: rib-entry.hpp:99
void wireDecode(const Block &block)
Definition: rib-entry.cpp:141
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
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:48
Definition: data.cpp:25