fib-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_FIB_ENTRY_HPP
23 #define NDN_CXX_MGMT_NFD_FIB_ENTRY_HPP
24 
26 #include "ndn-cxx/name.hpp"
27 
28 namespace ndn::nfd {
29 
34 {
35 public:
36  class Error : public tlv::Error
37  {
38  public:
39  using tlv::Error::Error;
40  };
41 
43 
44  explicit
45  NextHopRecord(const Block& block);
46 
47  uint64_t
48  getFaceId() const
49  {
50  return m_faceId;
51  }
52 
54  setFaceId(uint64_t faceId);
55 
56  uint64_t
57  getCost() const
58  {
59  return m_cost;
60  }
61 
63  setCost(uint64_t cost);
64 
65  template<encoding::Tag TAG>
66  size_t
67  wireEncode(EncodingImpl<TAG>& block) const;
68 
69  const Block&
70  wireEncode() const;
71 
72  void
73  wireDecode(const Block& block);
74 
75 private:
76  uint64_t m_faceId = INVALID_FACE_ID;
77  uint64_t m_cost = 0;
78 
79  mutable Block m_wire;
80 };
81 
83 
84 bool
85 operator==(const NextHopRecord& a, const NextHopRecord& b);
86 
87 inline bool
89 {
90  return !(a == b);
91 }
92 
93 std::ostream&
94 operator<<(std::ostream& os, const NextHopRecord& nh);
95 
96 
100 class FibEntry
101 {
102 public:
103  class Error : public tlv::Error
104  {
105  public:
106  using tlv::Error::Error;
107  };
108 
110 
111  explicit
112  FibEntry(const Block& block);
113 
114  const Name&
115  getPrefix() const
116  {
117  return m_prefix;
118  }
119 
120  FibEntry&
121  setPrefix(const Name& prefix);
122 
123  const std::vector<NextHopRecord>&
125  {
126  return m_nextHopRecords;
127  }
128 
129  template<typename InputIt>
130  FibEntry&
131  setNextHopRecords(InputIt first, InputIt last)
132  {
133  m_nextHopRecords.assign(first, last);
134  m_wire.reset();
135  return *this;
136  }
137 
138  FibEntry&
139  addNextHopRecord(const NextHopRecord& nh);
140 
141  FibEntry&
143 
144  template<encoding::Tag TAG>
145  size_t
146  wireEncode(EncodingImpl<TAG>& block) const;
147 
148  const Block&
149  wireEncode() const;
150 
151  void
152  wireDecode(const Block& block);
153 
154 private:
155  Name m_prefix;
156  std::vector<NextHopRecord> m_nextHopRecords;
157 
158  mutable Block m_wire;
159 };
160 
162 
163 bool
164 operator==(const FibEntry& a, const FibEntry& b);
165 
166 inline bool
167 operator!=(const FibEntry& a, const FibEntry& b)
168 {
169  return !(a == b);
170 }
171 
172 std::ostream&
173 operator<<(std::ostream& os, const FibEntry& entry);
174 
175 } // namespace ndn::nfd
176 
177 #endif // NDN_CXX_MGMT_NFD_FIB_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
FibEntry & clearNextHopRecords()
Definition: fib-entry.cpp:159
const Block & wireEncode() const
Definition: fib-entry.cpp:185
FibEntry & setNextHopRecords(InputIt first, InputIt last)
Definition: fib-entry.hpp:131
FibEntry & setPrefix(const Name &prefix)
Definition: fib-entry.cpp:143
void wireDecode(const Block &block)
Definition: fib-entry.cpp:201
FibEntry & addNextHopRecord(const NextHopRecord &nh)
Definition: fib-entry.cpp:151
const Name & getPrefix() const
Definition: fib-entry.hpp:115
const std::vector< NextHopRecord > & getNextHopRecords() const
Definition: fib-entry.hpp:124
NextHopRecord & setFaceId(uint64_t faceId)
Definition: fib-entry.cpp:40
void wireDecode(const Block &block)
Definition: fib-entry.cpp:88
NextHopRecord & setCost(uint64_t cost)
Definition: fib-entry.cpp:48
uint64_t getFaceId() const
Definition: fib-entry.hpp:48
uint64_t getCost() const
Definition: fib-entry.hpp:57
const Block & wireEncode() const
Definition: fib-entry.cpp:72
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)
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)