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-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 
24 
25 namespace ndn {
26 namespace nfd {
27 
29  : m_datasetName(datasetName)
30 {
31 }
32 
34 
35 Name
37 {
38  Name name;
39  name.append(prefix).append(m_datasetName);
40  this->addParameters(name);
41  return name;
42 }
43 
44 void
45 StatusDataset::addParameters(Name&) const
46 {
47 }
48 
56 template<typename T>
57 static std::vector<T>
58 parseDatasetVector(const ConstBufferPtr& payload)
59 {
60  BOOST_CONCEPT_ASSERT((WireDecodable<T>));
61 
62  std::vector<T> result;
63 
64  size_t offset = 0;
65  while (offset < payload->size()) {
66  bool isOk = false;
67  Block block;
68  std::tie(isOk, block) = Block::fromBuffer(payload, offset);
69  if (!isOk) {
70  NDN_THROW(StatusDataset::ParseResultError("cannot decode Block"));
71  }
72 
73  offset += block.size();
74  result.emplace_back(block);
75  }
76 
77  return result;
78 }
79 
81  : StatusDataset("status/general")
82 {
83 }
84 
87 {
88  return ForwarderStatus(Block(tlv::Content, std::move(payload)));
89 }
90 
92  : StatusDataset(datasetName)
93 {
94 }
95 
98 {
99  return parseDatasetVector<FaceStatus>(payload);
100 }
101 
103  : FaceDatasetBase("faces/list")
104 {
105 }
106 
108  : FaceDatasetBase("faces/query")
109  , m_filter(filter)
110 {
111 }
112 
113 void
114 FaceQueryDataset::addParameters(Name& name) const
115 {
116  name.append(m_filter.wireEncode());
117 }
118 
120  : StatusDataset("faces/channels")
121 {
122 }
123 
126 {
127  return parseDatasetVector<ChannelStatus>(payload);
128 }
129 
131  : StatusDataset("fib/list")
132 {
133 }
134 
137 {
138  return parseDatasetVector<FibEntry>(payload);
139 }
140 
142  : StatusDataset("cs/info")
143 {
144 }
145 
148 {
149  return CsInfo(Block(payload));
150 }
151 
153  : StatusDataset("strategy-choice/list")
154 {
155 }
156 
159 {
160  return parseDatasetVector<StrategyChoice>(payload);
161 }
162 
164  : StatusDataset("rib/list")
165 {
166 }
167 
170 {
171  return parseDatasetVector<RibEntry>(payload);
172 }
173 
174 } // namespace nfd
175 } // namespace ndn
Represents a TLV element of the NDN packet format.
Definition: block.hpp:45
size_t size() const
Return the size of the encoded wire, i.e., of the whole TLV.
Definition: block.cpp:294
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset=0)
Try to parse Block from a wire buffer.
Definition: block.cpp:162
Represents an absolute name.
Definition: name.hpp:44
Name & append(const Component &component)
Append a name component.
Definition: name.hpp:283
A concept check for TLV abstraction with a wireDecode(Block) method and constructible from Block.
Definition: concepts.hpp:81
ResultType parseResult(ConstBufferPtr payload) const
std::vector< ChannelStatus > ResultType
ResultType parseResult(ConstBufferPtr payload) const
Represents the CS Information dataset.
Definition: cs-info.hpp:38
Provides common functionality among FaceDataset and FaceQueryDataset.
ResultType parseResult(ConstBufferPtr payload) const
FaceDatasetBase(const PartialName &datasetName)
std::vector< FaceStatus > ResultType
FaceQueryDataset(const FaceQueryFilter &filter)
Represents Face Query Filter.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend FaceQueryFilter to the encoder.
std::vector< FibEntry > ResultType
ResultType parseResult(ConstBufferPtr payload) const
ResultType parseResult(ConstBufferPtr payload) const
Represents NFD General Status dataset.
std::vector< RibEntry > ResultType
ResultType parseResult(ConstBufferPtr payload) const
Base class of NFD StatusDataset.
Name getDatasetPrefix(const Name &prefix) const
Constructs a name prefix for the dataset.
StatusDataset(const PartialName &datasetName)
Constructs a StatusDataset instance with given sub-prefix.
std::vector< StrategyChoice > ResultType
ResultType parseResult(ConstBufferPtr payload) const
#define NDN_THROW(e)
Definition: exception.hpp:61
@ Content
Definition: tlv.hpp:93
Definition: data.cpp:25
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:139