status-dataset.cpp
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 
23 
24 namespace ndn::nfd {
25 
26 Name
28 {
29  return Name(prefix).append(m_datasetName);
30 }
31 
38 template<typename T>
39 static std::vector<T>
40 parseDatasetVector(const ConstBufferPtr& payload)
41 {
42  std::vector<T> result;
43 
44  size_t offset = 0;
45  while (offset < payload->size()) {
46  auto [isOk, block] = Block::fromBuffer(payload, offset);
47  if (!isOk) {
48  NDN_THROW(StatusDatasetParseError("Cannot decode a valid TLV at offset " + std::to_string(offset)));
49  }
50 
51  try {
52  result.emplace_back(block);
53  }
54  catch (const tlv::Error& e) {
55  NDN_THROW_NESTED(StatusDatasetParseError(e.what()));
56  }
57 
58  offset += block.size();
59  }
60 
61  return result;
62 }
63 
65  : StatusDatasetBase("status/general")
66 {
67 }
68 
71 {
72  return ForwarderStatus(Block(tlv::Content, std::move(payload)));
73 }
74 
76  : StatusDatasetBase("faces/list")
77 {
78 }
79 
80 std::vector<FaceStatus>
82 {
83  return parseDatasetVector<FaceStatus>(payload);
84 }
85 
87  : StatusDatasetBase("faces/query")
88  , m_filter(filter)
89 {
90 }
91 
92 Name
94 {
96  .append(m_filter.wireEncode());
97 }
98 
99 std::vector<FaceStatus>
101 {
102  return parseDatasetVector<FaceStatus>(payload);
103 }
104 
106  : StatusDatasetBase("faces/channels")
107 {
108 }
109 
110 std::vector<ChannelStatus>
112 {
113  return parseDatasetVector<ChannelStatus>(payload);
114 }
115 
117  : StatusDatasetBase("fib/list")
118 {
119 }
120 
121 std::vector<FibEntry>
123 {
124  return parseDatasetVector<FibEntry>(payload);
125 }
126 
128  : StatusDatasetBase("cs/info")
129 {
130 }
131 
132 CsInfo
134 {
135  return CsInfo(Block(payload));
136 }
137 
139  : StatusDatasetBase("strategy-choice/list")
140 {
141 }
142 
143 std::vector<StrategyChoice>
145 {
146  return parseDatasetVector<StrategyChoice>(payload);
147 }
148 
150  : StatusDatasetBase("rib/list")
151 {
152 }
153 
154 std::vector<RibEntry>
156 {
157  return parseDatasetVector<RibEntry>(payload);
158 }
159 
160 } // namespace ndn::nfd
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset=0)
Try to parse Block from a wire buffer.
Definition: block.cpp:165
Represents an absolute name.
Definition: name.hpp:45
Name & append(const Component &component)
Append a name component.
Definition: name.hpp:308
std::vector< ChannelStatus > parseResult(ConstBufferPtr payload) const
CsInfo parseResult(ConstBufferPtr payload) const
Represents the CS Information dataset.
Definition: cs-info.hpp:37
std::vector< FaceStatus > parseResult(ConstBufferPtr payload) const
std::vector< FaceStatus > parseResult(ConstBufferPtr payload) const
Name getDatasetPrefix(const Name &prefix) const
FaceQueryDataset(const FaceQueryFilter &filter)
Represents Face Query Filter.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend FaceQueryFilter to the encoder.
std::vector< FibEntry > parseResult(ConstBufferPtr payload) const
ForwarderStatus parseResult(ConstBufferPtr payload) const
Represents NFD General Status dataset.
std::vector< RibEntry > parseResult(ConstBufferPtr payload) const
Base class of NFD StatusDataset.
Name getDatasetPrefix(const Name &prefix) const
Constructs a name prefix for the dataset.
Exception raised when the fetched payload cannot be parsed as a StatusDataset.
std::vector< StrategyChoice > parseResult(ConstBufferPtr payload) const
#define NDN_THROW_NESTED(e)
Definition: exception.hpp:65
#define NDN_THROW(e)
Definition: exception.hpp:56
std::string to_string(const errinfo_stacktrace &x)
Definition: exception.cpp:30
Contains classes and functions related to the NFD Management protocol.
@ Name
Definition: tlv.hpp:71
@ Content
Definition: tlv.hpp:93
std::shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:140