blob: 21c62a17422d5604e9a18b8f5639886df98c495f [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,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020062 std::vector<shared_ptr<ValidationRequest>>& nextSteps) override
Weiwei Liu2c5a01a2016-03-24 21:55:46 -070063 {
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,
Davide Pesaventob84bd3a2016-04-22 02:21:45 +020075 std::vector<shared_ptr<ValidationRequest>>& nextSteps) override
Weiwei Liu2c5a01a2016-03-24 21:55:46 -070076 {
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>";
Weiwei Liuace83ac2016-04-25 10:16:37 -0700246 std::cout << "<nNacks>" << status.getNInNacks()
247 << "</nNacks>";
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700248 std::cout << "</incomingPackets>";
249 std::cout << "<outgoingPackets>";
250 std::cout << "<nInterests>" << status.getNOutInterests()
251 << "</nInterests>";
252 std::cout << "<nDatas>" << status.getNOutDatas()
253 << "</nDatas>";
Weiwei Liuace83ac2016-04-25 10:16:37 -0700254 std::cout << "<nNacks>" << status.getNOutNacks()
255 << "</nNacks>";
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700256 std::cout << "</outgoingPackets>";
257 std::cout << "</packetCounters>";
258 std::cout << "</generalStatus>";
259 }
260 else {
261 std::cout << "General NFD status:" << std::endl;
262 std::cout << " nfdId="
263 << m_forwarderStatusValidator.nfdId << std::endl;
264 std::cout << " version="
265 << status.getNfdVersion() << std::endl;
266 std::cout << " startTime="
267 << time::toIsoString(status.getStartTimestamp()) << std::endl;
268 std::cout << " currentTime="
269 << time::toIsoString(status.getCurrentTimestamp()) << std::endl;
270 std::cout << " uptime="
271 << time::duration_cast<time::seconds>(status.getCurrentTimestamp() -
272 status.getStartTimestamp()) << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700273
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700274 std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl;
275 std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl;
276 std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl;
277 std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl;
278 std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl;
279 std::cout << " nInInterests=" << status.getNInInterests() << std::endl;
280 std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl;
281 std::cout << " nInDatas=" << status.getNInDatas() << std::endl;
282 std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl;
Weiwei Liuace83ac2016-04-25 10:16:37 -0700283 std::cout << " nInNacks=" << status.getNInNacks() << std::endl;
284 std::cout << " nOutNacks=" << status.getNOutNacks() << std::endl;
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700285 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300286
287 runNextStep();
288 }
289
290 //////////////////////////////////////////////////////////////////////////////////
291 //////////////////////////////////////////////////////////////////////////////////
292
293 void
294 fetchChannelStatusInformation()
295 {
296 m_buffer = make_shared<OBufferStream>();
297
298 Interest interest("/localhost/nfd/faces/channels");
299 interest.setChildSelector(1);
300 interest.setMustBeFresh(true);
301
Yukai Tu971d3c22015-06-21 12:32:03 +0800302 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500303 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800304 bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700305 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700306 }
307
308 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800309 afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700310 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700311 if (m_isOutputXml) {
312 std::cout << "<channels>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300313
Junxiao Shi78926c92015-02-28 22:56:06 -0700314 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800315 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700316 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300317 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800318 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700319 if (!isOk) {
320 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
321 break;
322 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300323
Junxiao Shi78926c92015-02-28 22:56:06 -0700324 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300325
Junxiao Shi78926c92015-02-28 22:56:06 -0700326 nfd::ChannelStatus channelStatus(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300327
Junxiao Shi78926c92015-02-28 22:56:06 -0700328 std::cout << "<channel>";
329 std::string localUri(channelStatus.getLocalUri());
330 escapeSpecialCharacters(&localUri);
331 std::cout << "<localUri>" << localUri << "</localUri>";
332 std::cout << "</channel>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300333 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300334
Junxiao Shi78926c92015-02-28 22:56:06 -0700335 std::cout << "</channels>";
336 }
337 else {
338 std::cout << "Channels:" << std::endl;
339
340 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800341 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700342 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300343 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800344 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700345 if (!isOk) {
346 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
347 break;
348 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300349
Junxiao Shi78926c92015-02-28 22:56:06 -0700350 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300351
Junxiao Shi78926c92015-02-28 22:56:06 -0700352 nfd::ChannelStatus channelStatus(block);
353 std::cout << " " << channelStatus.getLocalUri() << std::endl;
354 }
355 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300356
357 runNextStep();
358 }
359
360 //////////////////////////////////////////////////////////////////////////////////
361 //////////////////////////////////////////////////////////////////////////////////
362
363 void
364 fetchFaceStatusInformation()
365 {
366 m_buffer = make_shared<OBufferStream>();
367
368 Interest interest("/localhost/nfd/faces/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700369 interest.setChildSelector(1);
370 interest.setMustBeFresh(true);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300371
Yukai Tu971d3c22015-06-21 12:32:03 +0800372 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500373 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800374 bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700375 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700376 }
377
378 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800379 afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700380 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700381 if (m_isOutputXml) {
382 std::cout << "<faces>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600383
Junxiao Shi78926c92015-02-28 22:56:06 -0700384 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800385 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700386 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600387 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800388 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700389 if (!isOk) {
390 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
391 break;
392 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600393
Junxiao Shi78926c92015-02-28 22:56:06 -0700394 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600395
Junxiao Shi78926c92015-02-28 22:56:06 -0700396 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600397
Junxiao Shi78926c92015-02-28 22:56:06 -0700398 std::cout << "<face>";
399 std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600400
Junxiao Shi78926c92015-02-28 22:56:06 -0700401 std::string remoteUri(faceStatus.getRemoteUri());
402 escapeSpecialCharacters(&remoteUri);
403 std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600404
Junxiao Shi78926c92015-02-28 22:56:06 -0700405 std::string localUri(faceStatus.getLocalUri());
406 escapeSpecialCharacters(&localUri);
407 std::cout << "<localUri>" << localUri << "</localUri>";
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700408
Junxiao Shi78926c92015-02-28 22:56:06 -0700409 if (faceStatus.hasExpirationPeriod()) {
410 std::cout << "<expirationPeriod>PT"
411 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
412 .count() << "S"
413 << "</expirationPeriod>";
414 }
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700415
Junxiao Shi78926c92015-02-28 22:56:06 -0700416 std::cout << "<faceScope>" << faceStatus.getFaceScope()
417 << "</faceScope>";
418 std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
419 << "</facePersistency>";
420 std::cout << "<linkType>" << faceStatus.getLinkType()
421 << "</linkType>";
Chengyu Fan27d570a2014-10-09 11:52:17 -0600422
Junxiao Shi78926c92015-02-28 22:56:06 -0700423 std::cout << "<packetCounters>";
424 std::cout << "<incomingPackets>";
425 std::cout << "<nInterests>" << faceStatus.getNInInterests()
426 << "</nInterests>";
427 std::cout << "<nDatas>" << faceStatus.getNInDatas()
428 << "</nDatas>";
Weiwei Liuace83ac2016-04-25 10:16:37 -0700429 std::cout << "<nNacks>" << faceStatus.getNInNacks()
430 << "</nNacks>";
Junxiao Shi78926c92015-02-28 22:56:06 -0700431 std::cout << "</incomingPackets>";
432 std::cout << "<outgoingPackets>";
433 std::cout << "<nInterests>" << faceStatus.getNOutInterests()
434 << "</nInterests>";
435 std::cout << "<nDatas>" << faceStatus.getNOutDatas()
436 << "</nDatas>";
Weiwei Liuace83ac2016-04-25 10:16:37 -0700437 std::cout << "<nNacks>" << faceStatus.getNOutNacks()
438 << "</nNacks>";
Junxiao Shi78926c92015-02-28 22:56:06 -0700439 std::cout << "</outgoingPackets>";
440 std::cout << "</packetCounters>";
Alexander Afanasyevd3967a22014-06-30 12:22:10 -0700441
Junxiao Shi78926c92015-02-28 22:56:06 -0700442 std::cout << "<byteCounters>";
443 std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
444 << "</incomingBytes>";
445 std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
446 << "</outgoingBytes>";
447 std::cout << "</byteCounters>";
Chengyu Fan3331cfa2014-07-25 17:36:31 -0600448
Junxiao Shi78926c92015-02-28 22:56:06 -0700449 std::cout << "</face>";
jeraldabrahamb6dde382014-03-19 18:58:09 -0700450 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700451 std::cout << "</faces>";
452 }
453 else {
454 std::cout << "Faces:" << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600455
Junxiao Shi78926c92015-02-28 22:56:06 -0700456 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800457 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700458 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600459 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800460 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700461 if (!isOk) {
462 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
463 break;
464 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600465
Junxiao Shi78926c92015-02-28 22:56:06 -0700466 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600467
Junxiao Shi78926c92015-02-28 22:56:06 -0700468 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600469
Junxiao Shi78926c92015-02-28 22:56:06 -0700470 std::cout << " faceid=" << faceStatus.getFaceId()
471 << " remote=" << faceStatus.getRemoteUri()
472 << " local=" << faceStatus.getLocalUri();
473 if (faceStatus.hasExpirationPeriod()) {
474 std::cout << " expires="
475 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
476 .count() << "s";
477 }
478 std::cout << " counters={"
479 << "in={" << faceStatus.getNInInterests() << "i "
480 << faceStatus.getNInDatas() << "d "
Weiwei Liuace83ac2016-04-25 10:16:37 -0700481 << faceStatus.getNInNacks() << "n "
Junxiao Shi78926c92015-02-28 22:56:06 -0700482 << faceStatus.getNInBytes() << "B}"
483 << " out={" << faceStatus.getNOutInterests() << "i "
484 << faceStatus.getNOutDatas() << "d "
Weiwei Liuace83ac2016-04-25 10:16:37 -0700485 << faceStatus.getNOutNacks() << "n "
Junxiao Shi78926c92015-02-28 22:56:06 -0700486 << faceStatus.getNOutBytes() << "B}"
487 << "}";
488 std::cout << " " << faceStatus.getFaceScope()
489 << " " << faceStatus.getFacePersistency()
490 << " " << faceStatus.getLinkType();
491 std::cout << std::endl;
492 }
493 }
jeraldabrahamb6dde382014-03-19 18:58:09 -0700494
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300495 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700496 }
497
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300498 //////////////////////////////////////////////////////////////////////////////////
499 //////////////////////////////////////////////////////////////////////////////////
500
jeraldabrahamb6dde382014-03-19 18:58:09 -0700501 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300502 fetchFibEnumerationInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700503 {
504 m_buffer = make_shared<OBufferStream>();
505
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300506 Interest interest("/localhost/nfd/fib/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700507 interest.setChildSelector(1);
508 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800509
510 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500511 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800512 bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700513 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700514 }
515
516 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800517 afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700518 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700519 if (m_isOutputXml) {
520 std::cout << "<fib>";
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700521
Junxiao Shi78926c92015-02-28 22:56:06 -0700522 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800523 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700524 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600525 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800526 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700527 if (!isOk) {
528 std::cerr << "ERROR: cannot decode FibEntry TLV";
529 break;
530 }
531 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600532
Junxiao Shi78926c92015-02-28 22:56:06 -0700533 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600534
Junxiao Shi78926c92015-02-28 22:56:06 -0700535 std::cout << "<fibEntry>";
536 std::string prefix(fibEntry.getPrefix().toUri());
537 escapeSpecialCharacters(&prefix);
538 std::cout << "<prefix>" << prefix << "</prefix>";
539 std::cout << "<nextHops>";
540 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
541 std::cout << "<nextHop>" ;
542 std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>";
543 std::cout << "<cost>" << nextHop.getCost() << "</cost>";
544 std::cout << "</nextHop>";
545 }
546 std::cout << "</nextHops>";
547 std::cout << "</fibEntry>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600548 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600549
Junxiao Shi78926c92015-02-28 22:56:06 -0700550 std::cout << "</fib>";
551 }
552 else {
553 std::cout << "FIB:" << std::endl;
554
555 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800556 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700557 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600558 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800559 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700560 if (!isOk) {
561 std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
562 break;
563 }
564 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600565
Junxiao Shi78926c92015-02-28 22:56:06 -0700566 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600567
Junxiao Shi78926c92015-02-28 22:56:06 -0700568 std::cout << " " << fibEntry.getPrefix() << " nexthops={";
569 bool isFirst = true;
570 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
571 if (isFirst)
572 isFirst = false;
573 else
574 std::cout << ", ";
575
576 std::cout << "faceid=" << nextHop.getFaceId()
577 << " (cost=" << nextHop.getCost() << ")";
578 }
579 std::cout << "}" << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700580 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700581 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300582
583 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700584 }
585
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300586 //////////////////////////////////////////////////////////////////////////////////
587 //////////////////////////////////////////////////////////////////////////////////
588
jeraldabrahamb6dde382014-03-19 18:58:09 -0700589 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300590 fetchStrategyChoiceInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700591 {
592 m_buffer = make_shared<OBufferStream>();
593
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300594 Interest interest("/localhost/nfd/strategy-choice/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700595 interest.setChildSelector(1);
596 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800597
598 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500599 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800600 bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700601 bind(&NfdStatus::onFetchError, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700602 }
603
604 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800605 afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300606 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700607 if (m_isOutputXml) {
608 std::cout << "<strategyChoices>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300609
Junxiao Shi78926c92015-02-28 22:56:06 -0700610 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800611 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700612 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300613 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800614 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700615 if (!isOk) {
616 std::cerr << "ERROR: cannot decode StrategyChoice TLV";
617 break;
618 }
619 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300620
Junxiao Shi78926c92015-02-28 22:56:06 -0700621 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300622
Junxiao Shi78926c92015-02-28 22:56:06 -0700623 std::cout << "<strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300624
Junxiao Shi78926c92015-02-28 22:56:06 -0700625 std::string name(strategyChoice.getName().toUri());
626 escapeSpecialCharacters(&name);
627 std::cout << "<namespace>" << name << "</namespace>";
628 std::cout << "<strategy>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300629
Junxiao Shi78926c92015-02-28 22:56:06 -0700630 std::string strategy(strategyChoice.getStrategy().toUri());
631 escapeSpecialCharacters(&strategy);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300632
Junxiao Shi78926c92015-02-28 22:56:06 -0700633 std::cout << "<name>" << strategy << "</name>";
634 std::cout << "</strategy>";
635 std::cout << "</strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300636 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300637
Junxiao Shi78926c92015-02-28 22:56:06 -0700638 std::cout << "</strategyChoices>";
639 }
640 else {
641 std::cout << "Strategy choices:" << std::endl;
642
643 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800644 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700645 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300646 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800647 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700648 if (!isOk) {
649 std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
650 break;
651 }
652 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300653
Junxiao Shi78926c92015-02-28 22:56:06 -0700654 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300655
Junxiao Shi78926c92015-02-28 22:56:06 -0700656 std::cout << " " << strategyChoice.getName()
657 << " strategy=" << strategyChoice.getStrategy() << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300658 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700659 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300660
661 runNextStep();
662 }
663
664 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600665 fetchRibStatusInformation()
666 {
667 m_buffer = make_shared<OBufferStream>();
668
669 Interest interest("/localhost/nfd/rib/list");
670 interest.setChildSelector(1);
671 interest.setMustBeFresh(true);
672
Yukai Tu971d3c22015-06-21 12:32:03 +0800673 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500674 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800675 bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1),
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700676 bind(&NfdStatus::onFetchError, this, _1, _2));
Chengyu Fan30aa2072014-07-20 13:52:32 -0600677 }
678
679 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800680 afterFetchedRibStatusInformation(const ConstBufferPtr& dataset)
Chengyu Fan30aa2072014-07-20 13:52:32 -0600681 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700682 if (m_isOutputXml) {
683 std::cout << "<rib>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600684
Junxiao Shi78926c92015-02-28 22:56:06 -0700685 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800686 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700687 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600688 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800689 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700690 if (!isOk) {
691 std::cerr << "ERROR: cannot decode RibEntry TLV";
692 break;
693 }
694 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600695
Junxiao Shi78926c92015-02-28 22:56:06 -0700696 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600697
Junxiao Shi78926c92015-02-28 22:56:06 -0700698 std::cout << "<ribEntry>";
699 std::string prefix(ribEntry.getName().toUri());
700 escapeSpecialCharacters(&prefix);
701 std::cout << "<prefix>" << prefix << "</prefix>";
702 std::cout << "<routes>";
703 for (const nfd::Route& nextRoute : ribEntry) {
704 std::cout << "<route>" ;
705 std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>";
706 std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>";
707 std::cout << "<cost>" << nextRoute.getCost() << "</cost>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500708
Junxiao Shi78926c92015-02-28 22:56:06 -0700709 std::cout << "<flags>";
710 if (nextRoute.isChildInherit())
711 std::cout << "<childInherit/>";
712 if (nextRoute.isRibCapture())
713 std::cout << "<ribCapture/>";
714 std::cout << "</flags>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500715
Junxiao Shi78926c92015-02-28 22:56:06 -0700716 if (!nextRoute.hasInfiniteExpirationPeriod()) {
717 std::cout << "<expirationPeriod>PT"
718 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
719 .count() << "S"
720 << "</expirationPeriod>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600721 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700722 std::cout << "</route>";
723 }
724 std::cout << "</routes>";
725 std::cout << "</ribEntry>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600726 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600727
Junxiao Shi78926c92015-02-28 22:56:06 -0700728 std::cout << "</rib>";
729 }
730 else {
731 std::cout << "RIB:" << std::endl;
732
733 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800734 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700735 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600736 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800737 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700738 if (!isOk) {
739 std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
740 break;
741 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600742
Junxiao Shi78926c92015-02-28 22:56:06 -0700743 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600744
Junxiao Shi78926c92015-02-28 22:56:06 -0700745 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600746
Junxiao Shi78926c92015-02-28 22:56:06 -0700747 std::cout << " " << ribEntry.getName().toUri() << " route={";
748 bool isFirst = true;
749 for (const nfd::Route& nextRoute : ribEntry) {
750 if (isFirst)
751 isFirst = false;
752 else
753 std::cout << ", ";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500754
Junxiao Shi78926c92015-02-28 22:56:06 -0700755 std::cout << "faceid=" << nextRoute.getFaceId()
756 << " (origin=" << nextRoute.getOrigin()
757 << " cost=" << nextRoute.getCost();
758 if (!nextRoute.hasInfiniteExpirationPeriod()) {
759 std::cout << " expires="
760 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
761 .count() << "s";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600762 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700763
764 if (nextRoute.isChildInherit())
765 std::cout << " ChildInherit";
766 if (nextRoute.isRibCapture())
767 std::cout << " RibCapture";
768
769 std::cout << ")";
770 }
771 std::cout << "}" << std::endl;
772 }
773 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600774
775 runNextStep();
776 }
777
778
779 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700780 fetchInformation()
781 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300782 if (m_isOutputXml ||
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600783 (!m_needVersionRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300784 !m_needChannelStatusRetrieval &&
785 !m_needFaceStatusRetrieval &&
786 !m_needFibEnumerationRetrieval &&
Chengyu Fan30aa2072014-07-20 13:52:32 -0600787 !m_needRibStatusRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300788 !m_needStrategyChoiceRetrieval))
jeraldabrahamb6dde382014-03-19 18:58:09 -0700789 {
790 enableVersionRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300791 enableChannelStatusRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700792 enableFaceStatusRetrieval();
793 enableFibEnumerationRetrieval();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600794 enableRibStatusRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300795 enableStrategyChoiceRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700796 }
797
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300798 if (m_isOutputXml)
799 m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this));
800
jeraldabrahamb6dde382014-03-19 18:58:09 -0700801 if (m_needVersionRetrieval)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300802 m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700803
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300804 if (m_needChannelStatusRetrieval)
805 m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this));
806
807 if (m_needFaceStatusRetrieval)
808 m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this));
809
810 if (m_needFibEnumerationRetrieval)
811 m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this));
812
Chengyu Fan30aa2072014-07-20 13:52:32 -0600813 if (m_needRibStatusRetrieval)
814 m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this));
815
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300816 if (m_needStrategyChoiceRetrieval)
817 m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this));
818
819 if (m_isOutputXml)
820 m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this));
821
822 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700823 m_face.processEvents();
824 }
825
826private:
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300827 void
828 printXmlHeader()
829 {
830 std::cout << "<?xml version=\"1.0\"?>";
831 std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">";
832
833 runNextStep();
834 }
835
836 void
837 printXmlFooter()
838 {
839 std::cout << "</nfdStatus>";
840
841 runNextStep();
842 }
843
844 void
845 runNextStep()
846 {
847 if (m_fetchSteps.empty())
848 return;
849
850 function<void()> nextStep = m_fetchSteps.front();
851 m_fetchSteps.pop_front();
852 nextStep();
853 }
854
855private:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700856 std::string m_toolName;
857 bool m_needVersionRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300858 bool m_needChannelStatusRetrieval;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700859 bool m_needFaceStatusRetrieval;
860 bool m_needFibEnumerationRetrieval;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600861 bool m_needRibStatusRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300862 bool m_needStrategyChoiceRetrieval;
863 bool m_isOutputXml;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700864 Face m_face;
865
866 shared_ptr<OBufferStream> m_buffer;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300867
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700868 std::deque<function<void()>> m_fetchSteps;
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500869
870 ndn::ValidatorNull m_validator;
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700871
872 ForwarderStatusValidator m_forwarderStatusValidator;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700873};
874
Weiwei Liu2c5a01a2016-03-24 21:55:46 -0700875} // namespace ndn
jeraldabrahamb6dde382014-03-19 18:58:09 -0700876
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700877int main(int argc, char* argv[])
jeraldabrahamb6dde382014-03-19 18:58:09 -0700878{
879 int option;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700880 ndn::NfdStatus nfdStatus(argv[0]);
jeraldabrahamb6dde382014-03-19 18:58:09 -0700881
Chengyu Fan30aa2072014-07-20 13:52:32 -0600882 while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700883 switch (option) {
884 case 'h':
885 nfdStatus.usage();
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700886 return 0;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700887 case 'v':
888 nfdStatus.enableVersionRetrieval();
889 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300890 case 'c':
891 nfdStatus.enableChannelStatusRetrieval();
892 break;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700893 case 'f':
894 nfdStatus.enableFaceStatusRetrieval();
895 break;
896 case 'b':
897 nfdStatus.enableFibEnumerationRetrieval();
898 break;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600899 case 'r':
900 nfdStatus.enableRibStatusRetrieval();
901 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300902 case 's':
903 nfdStatus.enableStrategyChoiceRetrieval();
904 break;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600905 case 'x':
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300906 nfdStatus.enableXmlOutput();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600907 break;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700908 case 'V':
909 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
910 return 0;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700911 default:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700912 nfdStatus.usage();
913 return 1;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700914 }
915 }
916
917 try {
918 nfdStatus.fetchInformation();
919 }
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700920 catch (std::exception& e) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700921 std::cerr << "ERROR: " << e.what() << std::endl;
922 return 2;
923 }
924
925 return 0;
926}