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