blob: 994839105291d613d6fbf24cd06af4eb2fc049e6 [file] [log] [blame]
Alexander Afanasyev4a771362014-04-24 21:29:33 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
jeraldabrahamb6dde382014-03-19 18:58:09 -07002/**
Weiwei Liu2c5a01a2016-03-24 21:55:46 -07003 * Copyright (c) 2014-2016, Regents of the University of California,
Junxiao Shi78926c92015-02-28 22:56:06 -07004 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
jeraldabrahamb6dde382014-03-19 18:58:09 -070010 *
Alexander Afanasyev4a771362014-04-24 21:29:33 -070011 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * @author Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
jeraldabrahamb6dde382014-03-19 18:58:09 -070026 */
27
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070028#include "version.hpp"
Weiwei Liu2c5a01a2016-03-24 21:55:46 -070029#include "common.hpp"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070030
Alexander Afanasyev4a771362014-04-24 21:29:33 -070031#include <ndn-cxx/face.hpp>
32#include <ndn-cxx/name.hpp>
33#include <ndn-cxx/interest.hpp>
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070034#include <ndn-cxx/encoding/buffer-stream.hpp>
jeraldabrahamb6dde382014-03-19 18:58:09 -070035
Alexander Afanasyev4a771362014-04-24 21:29:33 -070036#include <ndn-cxx/management/nfd-forwarder-status.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030037#include <ndn-cxx/management/nfd-channel-status.hpp>
38#include <ndn-cxx/management/nfd-face-status.hpp>
39#include <ndn-cxx/management/nfd-fib-entry.hpp>
Chengyu Fan30aa2072014-07-20 13:52:32 -060040#include <ndn-cxx/management/nfd-rib-entry.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030041#include <ndn-cxx/management/nfd-strategy-choice.hpp>
Yukai Tu971d3c22015-06-21 12:32:03 +080042#include <ndn-cxx/util/segment-fetcher.hpp>
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -050043#include <ndn-cxx/security/validator-null.hpp>
jeraldabrahamb6dde382014-03-19 18:58:09 -070044
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070045#include <boost/algorithm/string/replace.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030046#include <list>
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070047
jeraldabrahamb6dde382014-03-19 18:58:09 -070048namespace ndn {
49
Yukai Tu971d3c22015-06-21 12:32:03 +080050using util::SegmentFetcher;
51
Weiwei Liu2c5a01a2016-03-24 21:55:46 -070052/** \brief custom validator for the purpose of obtaining nfdId.
53 */
54class ForwarderStatusValidator : public Validator
55{
56protected:
57 virtual void
58 checkPolicy(const Data& data,
59 int nSteps,
60 const OnDataValidated& onValidated,
61 const OnDataValidationFailed& onValidationFailed,
62 std::vector<shared_ptr<ValidationRequest>>& nextSteps) DECL_OVERRIDE
63 {
64 const ndn::KeyLocator& locator = data.getSignature().getKeyLocator();
65 if (nfdId.empty() && locator.getType() == KeyLocator::KeyLocator_Name)
66 nfdId = locator.getName();
67 onValidated(data.shared_from_this());
68 }
69
70 virtual void
71 checkPolicy(const Interest& interest,
72 int nSteps,
73 const OnInterestValidated& onValidated,
74 const OnInterestValidationFailed& onValidationFailed,
75 std::vector<shared_ptr<ValidationRequest>>& nextSteps) DECL_OVERRIDE
76 {
77 BOOST_ASSERT(false);
78 }
79
80public:
81 Name nfdId;
82};
83
84
jeraldabrahamb6dde382014-03-19 18:58:09 -070085class NfdStatus
86{
87public:
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070088 explicit
jeraldabrahamb6dde382014-03-19 18:58:09 -070089 NfdStatus(char* toolName)
90 : m_toolName(toolName)
91 , m_needVersionRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030092 , m_needChannelStatusRetrieval(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070093 , m_needFaceStatusRetrieval(false)
94 , m_needFibEnumerationRetrieval(false)
Chengyu Fan30aa2072014-07-20 13:52:32 -060095 , m_needRibStatusRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030096 , m_needStrategyChoiceRetrieval(false)
97 , m_isOutputXml(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070098 {
99 }
100
101 void
102 usage()
103 {
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700104 std::cout << "Usage: \n " << m_toolName << " [options]\n\n"
105 "Show NFD version and status information\n\n"
106 "Options:\n"
107 " [-h] - print this help message\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -0700108 " [-v] - retrieve version information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300109 " [-c] - retrieve channel status information\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -0700110 " [-f] - retrieve face status information\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700111 " [-b] - retrieve FIB information\n"
Chengyu Fan30aa2072014-07-20 13:52:32 -0600112 " [-r] - retrieve RIB information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300113 " [-s] - retrieve configured strategy choice for NDN namespaces\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -0600114 " [-x] - output NFD status information in XML format\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700115 "\n"
116 " [-V] - show version information of nfd-status and exit\n"
117 "\n"
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700118 "If no options are provided, all information is retrieved.\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -0600119 "If -x is provided, other options(-v, -c, etc.) are ignored, and all information is printed in XML format.\n"
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700120 ;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700121 }
122
123 void
124 enableVersionRetrieval()
125 {
126 m_needVersionRetrieval = true;
127 }
128
129 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300130 enableChannelStatusRetrieval()
131 {
132 m_needChannelStatusRetrieval = true;
133 }
134
135 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700136 enableFaceStatusRetrieval()
137 {
138 m_needFaceStatusRetrieval = true;
139 }
140
141 void
142 enableFibEnumerationRetrieval()
143 {
144 m_needFibEnumerationRetrieval = true;
145 }
146
147 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300148 enableStrategyChoiceRetrieval()
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600149 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300150 m_needStrategyChoiceRetrieval = true;
151 }
152
153 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600154 enableRibStatusRetrieval()
155 {
156 m_needRibStatusRetrieval = true;
157 }
158
159 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300160 enableXmlOutput()
161 {
162 m_isOutputXml = true;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600163 }
164
165 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700166 onTimeout()
167 {
168 std::cerr << "Request timed out" << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300169
170 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700171 }
172
Yukai Tu971d3c22015-06-21 12:32:03 +0800173
jeraldabrahamb6dde382014-03-19 18:58:09 -0700174 void
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700175 onFetchError(uint32_t errorCode, const std::string& errorMsg)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700176 {
Yukai Tu971d3c22015-06-21 12:32:03 +0800177 std::cerr << "Error code:" << errorCode << ", message:" << errorMsg << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700178
Yukai Tu971d3c22015-06-21 12:32:03 +0800179 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700180 }
181
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300182 void
183 escapeSpecialCharacters(std::string *data)
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600184 {
185 using boost::algorithm::replace_all;
186 replace_all(*data, "&", "&amp;");
187 replace_all(*data, "\"", "&quot;");
188 replace_all(*data, "\'", "&apos;");
189 replace_all(*data, "<", "&lt;");
190 replace_all(*data, ">", "&gt;");
191 }
192
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300193 //////////////////////////////////////////////////////////////////////////////////
194 //////////////////////////////////////////////////////////////////////////////////
195
196 void
197 fetchVersionInformation()
198 {
Junxiao Shi498373d2015-12-29 17:51:26 -0700199 Interest interest("/localhost/nfd/status/general");
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300200 interest.setChildSelector(1);
201 interest.setMustBeFresh(true);
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700202 SegmentFetcher::fetch(m_face, interest,
203 m_forwarderStatusValidator,
204 bind(&NfdStatus::afterFetchedVersionInformation, this, _1),
205 bind(&NfdStatus::onFetchError, this, _1, _2));
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300206 }
207
jeraldabrahamb6dde382014-03-19 18:58:09 -0700208 void
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700209 afterFetchedVersionInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700210 {
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700211 Block block(tlv::Content, dataset);
212 nfd::ForwarderStatus status(block);
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600213
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700214 if (m_isOutputXml) {
215 std::cout << "<generalStatus>";
216 std::cout << "<nfdId>"
217 << m_forwarderStatusValidator.nfdId << "</nfdId>";
218 std::cout << "<version>"
219 << status.getNfdVersion() << "</version>";
220 std::cout << "<startTime>"
221 << time::toString(status.getStartTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
222 << "</startTime>";
223 std::cout << "<currentTime>"
224 << time::toString(status.getCurrentTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
225 << "</currentTime>";
226 std::cout << "<uptime>PT"
227 << time::duration_cast<time::seconds>(status.getCurrentTimestamp() -
228 status.getStartTimestamp()).count()
229 << "S</uptime>";
230 std::cout << "<nNameTreeEntries>" << status.getNNameTreeEntries()
231 << "</nNameTreeEntries>";
232 std::cout << "<nFibEntries>" << status.getNFibEntries()
233 << "</nFibEntries>";
234 std::cout << "<nPitEntries>" << status.getNPitEntries()
235 << "</nPitEntries>";
236 std::cout << "<nMeasurementsEntries>" << status.getNMeasurementsEntries()
237 << "</nMeasurementsEntries>";
238 std::cout << "<nCsEntries>" << status.getNCsEntries()
239 << "</nCsEntries>";
240 std::cout << "<packetCounters>";
241 std::cout << "<incomingPackets>";
242 std::cout << "<nInterests>" << status.getNInInterests()
243 << "</nInterests>";
244 std::cout << "<nDatas>" << status.getNInDatas()
245 << "</nDatas>";
246 std::cout << "</incomingPackets>";
247 std::cout << "<outgoingPackets>";
248 std::cout << "<nInterests>" << status.getNOutInterests()
249 << "</nInterests>";
250 std::cout << "<nDatas>" << status.getNOutDatas()
251 << "</nDatas>";
252 std::cout << "</outgoingPackets>";
253 std::cout << "</packetCounters>";
254 std::cout << "</generalStatus>";
255 }
256 else {
257 std::cout << "General NFD status:" << std::endl;
258 std::cout << " nfdId="
259 << m_forwarderStatusValidator.nfdId << std::endl;
260 std::cout << " version="
261 << status.getNfdVersion() << std::endl;
262 std::cout << " startTime="
263 << time::toIsoString(status.getStartTimestamp()) << std::endl;
264 std::cout << " currentTime="
265 << time::toIsoString(status.getCurrentTimestamp()) << std::endl;
266 std::cout << " uptime="
267 << time::duration_cast<time::seconds>(status.getCurrentTimestamp() -
268 status.getStartTimestamp()) << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700269
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700270 std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl;
271 std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl;
272 std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl;
273 std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl;
274 std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl;
275 std::cout << " nInInterests=" << status.getNInInterests() << std::endl;
276 std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl;
277 std::cout << " nInDatas=" << status.getNInDatas() << std::endl;
278 std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl;
279 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300280
281 runNextStep();
282 }
283
284 //////////////////////////////////////////////////////////////////////////////////
285 //////////////////////////////////////////////////////////////////////////////////
286
287 void
288 fetchChannelStatusInformation()
289 {
290 m_buffer = make_shared<OBufferStream>();
291
292 Interest interest("/localhost/nfd/faces/channels");
293 interest.setChildSelector(1);
294 interest.setMustBeFresh(true);
295
Yukai Tu971d3c22015-06-21 12:32:03 +0800296 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500297 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800298 bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700299 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700300 }
301
302 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800303 afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700304 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700305 if (m_isOutputXml) {
306 std::cout << "<channels>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300307
Junxiao Shi78926c92015-02-28 22:56:06 -0700308 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800309 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700310 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300311 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800312 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700313 if (!isOk) {
314 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
315 break;
316 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300317
Junxiao Shi78926c92015-02-28 22:56:06 -0700318 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300319
Junxiao Shi78926c92015-02-28 22:56:06 -0700320 nfd::ChannelStatus channelStatus(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300321
Junxiao Shi78926c92015-02-28 22:56:06 -0700322 std::cout << "<channel>";
323 std::string localUri(channelStatus.getLocalUri());
324 escapeSpecialCharacters(&localUri);
325 std::cout << "<localUri>" << localUri << "</localUri>";
326 std::cout << "</channel>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300327 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300328
Junxiao Shi78926c92015-02-28 22:56:06 -0700329 std::cout << "</channels>";
330 }
331 else {
332 std::cout << "Channels:" << std::endl;
333
334 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800335 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700336 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300337 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800338 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700339 if (!isOk) {
340 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
341 break;
342 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300343
Junxiao Shi78926c92015-02-28 22:56:06 -0700344 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300345
Junxiao Shi78926c92015-02-28 22:56:06 -0700346 nfd::ChannelStatus channelStatus(block);
347 std::cout << " " << channelStatus.getLocalUri() << std::endl;
348 }
349 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300350
351 runNextStep();
352 }
353
354 //////////////////////////////////////////////////////////////////////////////////
355 //////////////////////////////////////////////////////////////////////////////////
356
357 void
358 fetchFaceStatusInformation()
359 {
360 m_buffer = make_shared<OBufferStream>();
361
362 Interest interest("/localhost/nfd/faces/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700363 interest.setChildSelector(1);
364 interest.setMustBeFresh(true);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300365
Yukai Tu971d3c22015-06-21 12:32:03 +0800366 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500367 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800368 bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700369 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700370 }
371
372 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800373 afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700374 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700375 if (m_isOutputXml) {
376 std::cout << "<faces>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600377
Junxiao Shi78926c92015-02-28 22:56:06 -0700378 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800379 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700380 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600381 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800382 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700383 if (!isOk) {
384 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
385 break;
386 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600387
Junxiao Shi78926c92015-02-28 22:56:06 -0700388 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600389
Junxiao Shi78926c92015-02-28 22:56:06 -0700390 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600391
Junxiao Shi78926c92015-02-28 22:56:06 -0700392 std::cout << "<face>";
393 std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600394
Junxiao Shi78926c92015-02-28 22:56:06 -0700395 std::string remoteUri(faceStatus.getRemoteUri());
396 escapeSpecialCharacters(&remoteUri);
397 std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600398
Junxiao Shi78926c92015-02-28 22:56:06 -0700399 std::string localUri(faceStatus.getLocalUri());
400 escapeSpecialCharacters(&localUri);
401 std::cout << "<localUri>" << localUri << "</localUri>";
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700402
Junxiao Shi78926c92015-02-28 22:56:06 -0700403 if (faceStatus.hasExpirationPeriod()) {
404 std::cout << "<expirationPeriod>PT"
405 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
406 .count() << "S"
407 << "</expirationPeriod>";
408 }
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700409
Junxiao Shi78926c92015-02-28 22:56:06 -0700410 std::cout << "<faceScope>" << faceStatus.getFaceScope()
411 << "</faceScope>";
412 std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
413 << "</facePersistency>";
414 std::cout << "<linkType>" << faceStatus.getLinkType()
415 << "</linkType>";
Chengyu Fan27d570a2014-10-09 11:52:17 -0600416
Junxiao Shi78926c92015-02-28 22:56:06 -0700417 std::cout << "<packetCounters>";
418 std::cout << "<incomingPackets>";
419 std::cout << "<nInterests>" << faceStatus.getNInInterests()
420 << "</nInterests>";
421 std::cout << "<nDatas>" << faceStatus.getNInDatas()
422 << "</nDatas>";
423 std::cout << "</incomingPackets>";
424 std::cout << "<outgoingPackets>";
425 std::cout << "<nInterests>" << faceStatus.getNOutInterests()
426 << "</nInterests>";
427 std::cout << "<nDatas>" << faceStatus.getNOutDatas()
428 << "</nDatas>";
429 std::cout << "</outgoingPackets>";
430 std::cout << "</packetCounters>";
Alexander Afanasyevd3967a22014-06-30 12:22:10 -0700431
Junxiao Shi78926c92015-02-28 22:56:06 -0700432 std::cout << "<byteCounters>";
433 std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
434 << "</incomingBytes>";
435 std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
436 << "</outgoingBytes>";
437 std::cout << "</byteCounters>";
Chengyu Fan3331cfa2014-07-25 17:36:31 -0600438
Junxiao Shi78926c92015-02-28 22:56:06 -0700439 std::cout << "</face>";
jeraldabrahamb6dde382014-03-19 18:58:09 -0700440 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700441 std::cout << "</faces>";
442 }
443 else {
444 std::cout << "Faces:" << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600445
Junxiao Shi78926c92015-02-28 22:56:06 -0700446 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800447 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700448 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600449 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800450 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700451 if (!isOk) {
452 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
453 break;
454 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600455
Junxiao Shi78926c92015-02-28 22:56:06 -0700456 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600457
Junxiao Shi78926c92015-02-28 22:56:06 -0700458 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600459
Junxiao Shi78926c92015-02-28 22:56:06 -0700460 std::cout << " faceid=" << faceStatus.getFaceId()
461 << " remote=" << faceStatus.getRemoteUri()
462 << " local=" << faceStatus.getLocalUri();
463 if (faceStatus.hasExpirationPeriod()) {
464 std::cout << " expires="
465 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
466 .count() << "s";
467 }
468 std::cout << " counters={"
469 << "in={" << faceStatus.getNInInterests() << "i "
470 << faceStatus.getNInDatas() << "d "
471 << faceStatus.getNInBytes() << "B}"
472 << " out={" << faceStatus.getNOutInterests() << "i "
473 << faceStatus.getNOutDatas() << "d "
474 << faceStatus.getNOutBytes() << "B}"
475 << "}";
476 std::cout << " " << faceStatus.getFaceScope()
477 << " " << faceStatus.getFacePersistency()
478 << " " << faceStatus.getLinkType();
479 std::cout << std::endl;
480 }
481 }
jeraldabrahamb6dde382014-03-19 18:58:09 -0700482
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300483 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700484 }
485
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300486 //////////////////////////////////////////////////////////////////////////////////
487 //////////////////////////////////////////////////////////////////////////////////
488
jeraldabrahamb6dde382014-03-19 18:58:09 -0700489 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300490 fetchFibEnumerationInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700491 {
492 m_buffer = make_shared<OBufferStream>();
493
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300494 Interest interest("/localhost/nfd/fib/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700495 interest.setChildSelector(1);
496 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800497
498 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500499 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800500 bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700501 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700502 }
503
504 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800505 afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700506 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700507 if (m_isOutputXml) {
508 std::cout << "<fib>";
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700509
Junxiao Shi78926c92015-02-28 22:56:06 -0700510 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800511 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700512 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600513 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800514 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700515 if (!isOk) {
516 std::cerr << "ERROR: cannot decode FibEntry TLV";
517 break;
518 }
519 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600520
Junxiao Shi78926c92015-02-28 22:56:06 -0700521 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600522
Junxiao Shi78926c92015-02-28 22:56:06 -0700523 std::cout << "<fibEntry>";
524 std::string prefix(fibEntry.getPrefix().toUri());
525 escapeSpecialCharacters(&prefix);
526 std::cout << "<prefix>" << prefix << "</prefix>";
527 std::cout << "<nextHops>";
528 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
529 std::cout << "<nextHop>" ;
530 std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>";
531 std::cout << "<cost>" << nextHop.getCost() << "</cost>";
532 std::cout << "</nextHop>";
533 }
534 std::cout << "</nextHops>";
535 std::cout << "</fibEntry>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600536 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600537
Junxiao Shi78926c92015-02-28 22:56:06 -0700538 std::cout << "</fib>";
539 }
540 else {
541 std::cout << "FIB:" << std::endl;
542
543 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800544 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700545 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600546 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800547 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700548 if (!isOk) {
549 std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
550 break;
551 }
552 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600553
Junxiao Shi78926c92015-02-28 22:56:06 -0700554 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600555
Junxiao Shi78926c92015-02-28 22:56:06 -0700556 std::cout << " " << fibEntry.getPrefix() << " nexthops={";
557 bool isFirst = true;
558 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
559 if (isFirst)
560 isFirst = false;
561 else
562 std::cout << ", ";
563
564 std::cout << "faceid=" << nextHop.getFaceId()
565 << " (cost=" << nextHop.getCost() << ")";
566 }
567 std::cout << "}" << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700568 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700569 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300570
571 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700572 }
573
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300574 //////////////////////////////////////////////////////////////////////////////////
575 //////////////////////////////////////////////////////////////////////////////////
576
jeraldabrahamb6dde382014-03-19 18:58:09 -0700577 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300578 fetchStrategyChoiceInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700579 {
580 m_buffer = make_shared<OBufferStream>();
581
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300582 Interest interest("/localhost/nfd/strategy-choice/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700583 interest.setChildSelector(1);
584 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800585
586 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500587 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800588 bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700589 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700590 }
591
592 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800593 afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300594 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700595 if (m_isOutputXml) {
596 std::cout << "<strategyChoices>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300597
Junxiao Shi78926c92015-02-28 22:56:06 -0700598 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800599 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700600 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300601 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800602 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700603 if (!isOk) {
604 std::cerr << "ERROR: cannot decode StrategyChoice TLV";
605 break;
606 }
607 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300608
Junxiao Shi78926c92015-02-28 22:56:06 -0700609 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300610
Junxiao Shi78926c92015-02-28 22:56:06 -0700611 std::cout << "<strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300612
Junxiao Shi78926c92015-02-28 22:56:06 -0700613 std::string name(strategyChoice.getName().toUri());
614 escapeSpecialCharacters(&name);
615 std::cout << "<namespace>" << name << "</namespace>";
616 std::cout << "<strategy>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300617
Junxiao Shi78926c92015-02-28 22:56:06 -0700618 std::string strategy(strategyChoice.getStrategy().toUri());
619 escapeSpecialCharacters(&strategy);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300620
Junxiao Shi78926c92015-02-28 22:56:06 -0700621 std::cout << "<name>" << strategy << "</name>";
622 std::cout << "</strategy>";
623 std::cout << "</strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300624 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300625
Junxiao Shi78926c92015-02-28 22:56:06 -0700626 std::cout << "</strategyChoices>";
627 }
628 else {
629 std::cout << "Strategy choices:" << std::endl;
630
631 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800632 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700633 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300634 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800635 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700636 if (!isOk) {
637 std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
638 break;
639 }
640 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300641
Junxiao Shi78926c92015-02-28 22:56:06 -0700642 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300643
Junxiao Shi78926c92015-02-28 22:56:06 -0700644 std::cout << " " << strategyChoice.getName()
645 << " strategy=" << strategyChoice.getStrategy() << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300646 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700647 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300648
649 runNextStep();
650 }
651
652 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600653 fetchRibStatusInformation()
654 {
655 m_buffer = make_shared<OBufferStream>();
656
657 Interest interest("/localhost/nfd/rib/list");
658 interest.setChildSelector(1);
659 interest.setMustBeFresh(true);
660
Yukai Tu971d3c22015-06-21 12:32:03 +0800661 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500662 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800663 bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700664 bind(&NfdStatus::onFetchError, this, _1, _2));
Chengyu Fan30aa2072014-07-20 13:52:32 -0600665 }
666
667 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800668 afterFetchedRibStatusInformation(const ConstBufferPtr& dataset)
Chengyu Fan30aa2072014-07-20 13:52:32 -0600669 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700670 if (m_isOutputXml) {
671 std::cout << "<rib>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600672
Junxiao Shi78926c92015-02-28 22:56:06 -0700673 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800674 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700675 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600676 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800677 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700678 if (!isOk) {
679 std::cerr << "ERROR: cannot decode RibEntry TLV";
680 break;
681 }
682 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600683
Junxiao Shi78926c92015-02-28 22:56:06 -0700684 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600685
Junxiao Shi78926c92015-02-28 22:56:06 -0700686 std::cout << "<ribEntry>";
687 std::string prefix(ribEntry.getName().toUri());
688 escapeSpecialCharacters(&prefix);
689 std::cout << "<prefix>" << prefix << "</prefix>";
690 std::cout << "<routes>";
691 for (const nfd::Route& nextRoute : ribEntry) {
692 std::cout << "<route>" ;
693 std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>";
694 std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>";
695 std::cout << "<cost>" << nextRoute.getCost() << "</cost>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500696
Junxiao Shi78926c92015-02-28 22:56:06 -0700697 std::cout << "<flags>";
698 if (nextRoute.isChildInherit())
699 std::cout << "<childInherit/>";
700 if (nextRoute.isRibCapture())
701 std::cout << "<ribCapture/>";
702 std::cout << "</flags>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500703
Junxiao Shi78926c92015-02-28 22:56:06 -0700704 if (!nextRoute.hasInfiniteExpirationPeriod()) {
705 std::cout << "<expirationPeriod>PT"
706 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
707 .count() << "S"
708 << "</expirationPeriod>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600709 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700710 std::cout << "</route>";
711 }
712 std::cout << "</routes>";
713 std::cout << "</ribEntry>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600714 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600715
Junxiao Shi78926c92015-02-28 22:56:06 -0700716 std::cout << "</rib>";
717 }
718 else {
719 std::cout << "RIB:" << std::endl;
720
721 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800722 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700723 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600724 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800725 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700726 if (!isOk) {
727 std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
728 break;
729 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600730
Junxiao Shi78926c92015-02-28 22:56:06 -0700731 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600732
Junxiao Shi78926c92015-02-28 22:56:06 -0700733 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600734
Junxiao Shi78926c92015-02-28 22:56:06 -0700735 std::cout << " " << ribEntry.getName().toUri() << " route={";
736 bool isFirst = true;
737 for (const nfd::Route& nextRoute : ribEntry) {
738 if (isFirst)
739 isFirst = false;
740 else
741 std::cout << ", ";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500742
Junxiao Shi78926c92015-02-28 22:56:06 -0700743 std::cout << "faceid=" << nextRoute.getFaceId()
744 << " (origin=" << nextRoute.getOrigin()
745 << " cost=" << nextRoute.getCost();
746 if (!nextRoute.hasInfiniteExpirationPeriod()) {
747 std::cout << " expires="
748 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
749 .count() << "s";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600750 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700751
752 if (nextRoute.isChildInherit())
753 std::cout << " ChildInherit";
754 if (nextRoute.isRibCapture())
755 std::cout << " RibCapture";
756
757 std::cout << ")";
758 }
759 std::cout << "}" << std::endl;
760 }
761 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600762
763 runNextStep();
764 }
765
766
767 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700768 fetchInformation()
769 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300770 if (m_isOutputXml ||
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600771 (!m_needVersionRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300772 !m_needChannelStatusRetrieval &&
773 !m_needFaceStatusRetrieval &&
774 !m_needFibEnumerationRetrieval &&
Chengyu Fan30aa2072014-07-20 13:52:32 -0600775 !m_needRibStatusRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300776 !m_needStrategyChoiceRetrieval))
jeraldabrahamb6dde382014-03-19 18:58:09 -0700777 {
778 enableVersionRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300779 enableChannelStatusRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700780 enableFaceStatusRetrieval();
781 enableFibEnumerationRetrieval();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600782 enableRibStatusRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300783 enableStrategyChoiceRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700784 }
785
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300786 if (m_isOutputXml)
787 m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this));
788
jeraldabrahamb6dde382014-03-19 18:58:09 -0700789 if (m_needVersionRetrieval)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300790 m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700791
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300792 if (m_needChannelStatusRetrieval)
793 m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this));
794
795 if (m_needFaceStatusRetrieval)
796 m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this));
797
798 if (m_needFibEnumerationRetrieval)
799 m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this));
800
Chengyu Fan30aa2072014-07-20 13:52:32 -0600801 if (m_needRibStatusRetrieval)
802 m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this));
803
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300804 if (m_needStrategyChoiceRetrieval)
805 m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this));
806
807 if (m_isOutputXml)
808 m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this));
809
810 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700811 m_face.processEvents();
812 }
813
814private:
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300815 void
816 printXmlHeader()
817 {
818 std::cout << "<?xml version=\"1.0\"?>";
819 std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">";
820
821 runNextStep();
822 }
823
824 void
825 printXmlFooter()
826 {
827 std::cout << "</nfdStatus>";
828
829 runNextStep();
830 }
831
832 void
833 runNextStep()
834 {
835 if (m_fetchSteps.empty())
836 return;
837
838 function<void()> nextStep = m_fetchSteps.front();
839 m_fetchSteps.pop_front();
840 nextStep();
841 }
842
843private:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700844 std::string m_toolName;
845 bool m_needVersionRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300846 bool m_needChannelStatusRetrieval;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700847 bool m_needFaceStatusRetrieval;
848 bool m_needFibEnumerationRetrieval;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600849 bool m_needRibStatusRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300850 bool m_needStrategyChoiceRetrieval;
851 bool m_isOutputXml;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700852 Face m_face;
853
854 shared_ptr<OBufferStream> m_buffer;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300855
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700856 std::deque<function<void()>> m_fetchSteps;
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500857
858 ndn::ValidatorNull m_validator;
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700859
860 ForwarderStatusValidator m_forwarderStatusValidator;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700861};
862
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700863} // namespace ndn
jeraldabrahamb6dde382014-03-19 18:58:09 -0700864
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700865int main(int argc, char* argv[])
jeraldabrahamb6dde382014-03-19 18:58:09 -0700866{
867 int option;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700868 ndn::NfdStatus nfdStatus(argv[0]);
jeraldabrahamb6dde382014-03-19 18:58:09 -0700869
Chengyu Fan30aa2072014-07-20 13:52:32 -0600870 while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700871 switch (option) {
872 case 'h':
873 nfdStatus.usage();
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700874 return 0;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700875 case 'v':
876 nfdStatus.enableVersionRetrieval();
877 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300878 case 'c':
879 nfdStatus.enableChannelStatusRetrieval();
880 break;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700881 case 'f':
882 nfdStatus.enableFaceStatusRetrieval();
883 break;
884 case 'b':
885 nfdStatus.enableFibEnumerationRetrieval();
886 break;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600887 case 'r':
888 nfdStatus.enableRibStatusRetrieval();
889 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300890 case 's':
891 nfdStatus.enableStrategyChoiceRetrieval();
892 break;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600893 case 'x':
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300894 nfdStatus.enableXmlOutput();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600895 break;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700896 case 'V':
897 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
898 return 0;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700899 default:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700900 nfdStatus.usage();
901 return 1;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700902 }
903 }
904
905 try {
906 nfdStatus.fetchInformation();
907 }
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700908 catch (std::exception& e) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700909 std::cerr << "ERROR: " << e.what() << std::endl;
910 return 2;
911 }
912
913 return 0;
914}