blob: f186c8d509365ca614939f89031bdc812a9adf3f [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/**
Junxiao Shi78926c92015-02-28 22:56:06 -07003 * Copyright (c) 2014-2015, Regents of the University of California,
4 * 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"
29
Alexander Afanasyev4a771362014-04-24 21:29:33 -070030#include <ndn-cxx/face.hpp>
31#include <ndn-cxx/name.hpp>
32#include <ndn-cxx/interest.hpp>
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070033#include <ndn-cxx/encoding/buffer-stream.hpp>
jeraldabrahamb6dde382014-03-19 18:58:09 -070034
Alexander Afanasyev4a771362014-04-24 21:29:33 -070035#include <ndn-cxx/management/nfd-forwarder-status.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030036#include <ndn-cxx/management/nfd-channel-status.hpp>
37#include <ndn-cxx/management/nfd-face-status.hpp>
38#include <ndn-cxx/management/nfd-fib-entry.hpp>
Chengyu Fan30aa2072014-07-20 13:52:32 -060039#include <ndn-cxx/management/nfd-rib-entry.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030040#include <ndn-cxx/management/nfd-strategy-choice.hpp>
Yukai Tu971d3c22015-06-21 12:32:03 +080041#include <ndn-cxx/util/segment-fetcher.hpp>
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -050042#include <ndn-cxx/security/validator-null.hpp>
jeraldabrahamb6dde382014-03-19 18:58:09 -070043
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070044#include <boost/algorithm/string/replace.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030045#include <list>
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070046
jeraldabrahamb6dde382014-03-19 18:58:09 -070047namespace ndn {
48
Yukai Tu971d3c22015-06-21 12:32:03 +080049using util::SegmentFetcher;
50
jeraldabrahamb6dde382014-03-19 18:58:09 -070051class NfdStatus
52{
53public:
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070054 explicit
jeraldabrahamb6dde382014-03-19 18:58:09 -070055 NfdStatus(char* toolName)
56 : m_toolName(toolName)
57 , m_needVersionRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030058 , m_needChannelStatusRetrieval(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070059 , m_needFaceStatusRetrieval(false)
60 , m_needFibEnumerationRetrieval(false)
Chengyu Fan30aa2072014-07-20 13:52:32 -060061 , m_needRibStatusRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030062 , m_needStrategyChoiceRetrieval(false)
63 , m_isOutputXml(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070064 {
65 }
66
67 void
68 usage()
69 {
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -070070 std::cout << "Usage: \n " << m_toolName << " [options]\n\n"
71 "Show NFD version and status information\n\n"
72 "Options:\n"
73 " [-h] - print this help message\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -070074 " [-v] - retrieve version information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030075 " [-c] - retrieve channel status information\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -070076 " [-f] - retrieve face status information\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070077 " [-b] - retrieve FIB information\n"
Chengyu Fan30aa2072014-07-20 13:52:32 -060078 " [-r] - retrieve RIB information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030079 " [-s] - retrieve configured strategy choice for NDN namespaces\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -060080 " [-x] - output NFD status information in XML format\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070081 "\n"
82 " [-V] - show version information of nfd-status and exit\n"
83 "\n"
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -070084 "If no options are provided, all information is retrieved.\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -060085 "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 -070086 ;
jeraldabrahamb6dde382014-03-19 18:58:09 -070087 }
88
89 void
90 enableVersionRetrieval()
91 {
92 m_needVersionRetrieval = true;
93 }
94
95 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030096 enableChannelStatusRetrieval()
97 {
98 m_needChannelStatusRetrieval = true;
99 }
100
101 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700102 enableFaceStatusRetrieval()
103 {
104 m_needFaceStatusRetrieval = true;
105 }
106
107 void
108 enableFibEnumerationRetrieval()
109 {
110 m_needFibEnumerationRetrieval = true;
111 }
112
113 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300114 enableStrategyChoiceRetrieval()
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600115 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300116 m_needStrategyChoiceRetrieval = true;
117 }
118
119 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600120 enableRibStatusRetrieval()
121 {
122 m_needRibStatusRetrieval = true;
123 }
124
125 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300126 enableXmlOutput()
127 {
128 m_isOutputXml = true;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600129 }
130
131 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700132 onTimeout()
133 {
134 std::cerr << "Request timed out" << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300135
136 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700137 }
138
Yukai Tu971d3c22015-06-21 12:32:03 +0800139
jeraldabrahamb6dde382014-03-19 18:58:09 -0700140 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800141 onErrorFetch(uint32_t errorCode, const std::string& errorMsg)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700142 {
Yukai Tu971d3c22015-06-21 12:32:03 +0800143 std::cerr << "Error code:" << errorCode << ", message:" << errorMsg << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700144
Yukai Tu971d3c22015-06-21 12:32:03 +0800145 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700146 }
147
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300148 void
149 escapeSpecialCharacters(std::string *data)
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600150 {
151 using boost::algorithm::replace_all;
152 replace_all(*data, "&", "&amp;");
153 replace_all(*data, "\"", "&quot;");
154 replace_all(*data, "\'", "&apos;");
155 replace_all(*data, "<", "&lt;");
156 replace_all(*data, ">", "&gt;");
157 }
158
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300159 //////////////////////////////////////////////////////////////////////////////////
160 //////////////////////////////////////////////////////////////////////////////////
161
162 void
163 fetchVersionInformation()
164 {
Junxiao Shi498373d2015-12-29 17:51:26 -0700165 Interest interest("/localhost/nfd/status/general");
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300166 interest.setChildSelector(1);
167 interest.setMustBeFresh(true);
168 m_face.expressInterest(
169 interest,
170 bind(&NfdStatus::afterFetchedVersionInformation, this, _2),
171 bind(&NfdStatus::onTimeout, this));
172 }
173
jeraldabrahamb6dde382014-03-19 18:58:09 -0700174 void
175 afterFetchedVersionInformation(const Data& data)
176 {
Junxiao Shi88d69372014-03-28 11:52:39 -0700177 nfd::ForwarderStatus status(data.getContent());
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600178 std::string nfdId;
179 if (data.getSignature().hasKeyLocator())
180 {
181 const ndn::KeyLocator& locator = data.getSignature().getKeyLocator();
182 if (locator.getType() == KeyLocator::KeyLocator_Name)
183 nfdId = locator.getName().toUri();
184 //todo: KeyDigest supporting
185 }
186
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300187 if (m_isOutputXml)
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600188 {
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600189 std::cout << "<generalStatus>";
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600190 std::cout << "<nfdId>"
191 << nfdId << "</nfdId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600192 std::cout << "<version>"
193 << status.getNfdVersion() << "</version>";
194 std::cout << "<startTime>"
195 << time::toString(status.getStartTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
196 << "</startTime>";
197 std::cout << "<currentTime>"
198 << time::toString(status.getCurrentTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
199 << "</currentTime>";
200 std::cout << "<uptime>PT"
201 << time::duration_cast<time::seconds>(status.getCurrentTimestamp()
202 - status.getStartTimestamp()).count()
203 << "S</uptime>";
204 std::cout << "<nNameTreeEntries>" << status.getNNameTreeEntries()
205 << "</nNameTreeEntries>";
206 std::cout << "<nFibEntries>" << status.getNFibEntries()
207 << "</nFibEntries>";
208 std::cout << "<nPitEntries>" << status.getNPitEntries()
209 << "</nPitEntries>";
210 std::cout << "<nMeasurementsEntries>" << status.getNMeasurementsEntries()
211 << "</nMeasurementsEntries>";
212 std::cout << "<nCsEntries>" << status.getNCsEntries()
213 << "</nCsEntries>";
214 std::cout << "<packetCounters>";
215 std::cout << "<incomingPackets>";
216 std::cout << "<nInterests>" << status.getNInInterests()
217 << "</nInterests>";
218 std::cout << "<nDatas>" << status.getNInDatas()
219 << "</nDatas>";
220 std::cout << "</incomingPackets>";
221 std::cout << "<outgoingPackets>";
222 std::cout << "<nInterests>" << status.getNOutInterests()
223 << "</nInterests>";
224 std::cout << "<nDatas>" << status.getNOutDatas()
225 << "</nDatas>";
226 std::cout << "</outgoingPackets>";
227 std::cout << "</packetCounters>";
228 std::cout << "</generalStatus>";
229 }
230 else
231 {
232 std::cout << "General NFD status:" << std::endl;
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600233 std::cout << " nfdId="
234 << nfdId << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600235 std::cout << " version="
236 << status.getNfdVersion() << std::endl;
237 std::cout << " startTime="
238 << time::toIsoString(status.getStartTimestamp()) << std::endl;
239 std::cout << " currentTime="
240 << time::toIsoString(status.getCurrentTimestamp()) << std::endl;
241 std::cout << " uptime="
242 << time::duration_cast<time::seconds>(status.getCurrentTimestamp()
243 - status.getStartTimestamp()) << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700244
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600245 std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl;
246 std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl;
247 std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl;
248 std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl;
249 std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl;
250 std::cout << " nInInterests=" << status.getNInInterests() << std::endl;
251 std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl;
252 std::cout << " nInDatas=" << status.getNInDatas() << std::endl;
253 std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl;
254 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300255
256 runNextStep();
257 }
258
259 //////////////////////////////////////////////////////////////////////////////////
260 //////////////////////////////////////////////////////////////////////////////////
261
262 void
263 fetchChannelStatusInformation()
264 {
265 m_buffer = make_shared<OBufferStream>();
266
267 Interest interest("/localhost/nfd/faces/channels");
268 interest.setChildSelector(1);
269 interest.setMustBeFresh(true);
270
Yukai Tu971d3c22015-06-21 12:32:03 +0800271 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500272 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800273 bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1),
274 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700275 }
276
277 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800278 afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700279 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700280 if (m_isOutputXml) {
281 std::cout << "<channels>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300282
Junxiao Shi78926c92015-02-28 22:56:06 -0700283 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800284 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700285 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300286 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800287 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700288 if (!isOk) {
289 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
290 break;
291 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300292
Junxiao Shi78926c92015-02-28 22:56:06 -0700293 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300294
Junxiao Shi78926c92015-02-28 22:56:06 -0700295 nfd::ChannelStatus channelStatus(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300296
Junxiao Shi78926c92015-02-28 22:56:06 -0700297 std::cout << "<channel>";
298 std::string localUri(channelStatus.getLocalUri());
299 escapeSpecialCharacters(&localUri);
300 std::cout << "<localUri>" << localUri << "</localUri>";
301 std::cout << "</channel>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300302 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300303
Junxiao Shi78926c92015-02-28 22:56:06 -0700304 std::cout << "</channels>";
305 }
306 else {
307 std::cout << "Channels:" << std::endl;
308
309 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800310 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700311 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300312 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800313 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700314 if (!isOk) {
315 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
316 break;
317 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300318
Junxiao Shi78926c92015-02-28 22:56:06 -0700319 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300320
Junxiao Shi78926c92015-02-28 22:56:06 -0700321 nfd::ChannelStatus channelStatus(block);
322 std::cout << " " << channelStatus.getLocalUri() << std::endl;
323 }
324 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300325
326 runNextStep();
327 }
328
329 //////////////////////////////////////////////////////////////////////////////////
330 //////////////////////////////////////////////////////////////////////////////////
331
332 void
333 fetchFaceStatusInformation()
334 {
335 m_buffer = make_shared<OBufferStream>();
336
337 Interest interest("/localhost/nfd/faces/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700338 interest.setChildSelector(1);
339 interest.setMustBeFresh(true);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300340
Yukai Tu971d3c22015-06-21 12:32:03 +0800341 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500342 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800343 bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1),
344 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700345 }
346
347 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800348 afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700349 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700350 if (m_isOutputXml) {
351 std::cout << "<faces>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600352
Junxiao Shi78926c92015-02-28 22:56:06 -0700353 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800354 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700355 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600356 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800357 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700358 if (!isOk) {
359 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
360 break;
361 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600362
Junxiao Shi78926c92015-02-28 22:56:06 -0700363 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600364
Junxiao Shi78926c92015-02-28 22:56:06 -0700365 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600366
Junxiao Shi78926c92015-02-28 22:56:06 -0700367 std::cout << "<face>";
368 std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600369
Junxiao Shi78926c92015-02-28 22:56:06 -0700370 std::string remoteUri(faceStatus.getRemoteUri());
371 escapeSpecialCharacters(&remoteUri);
372 std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600373
Junxiao Shi78926c92015-02-28 22:56:06 -0700374 std::string localUri(faceStatus.getLocalUri());
375 escapeSpecialCharacters(&localUri);
376 std::cout << "<localUri>" << localUri << "</localUri>";
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700377
Junxiao Shi78926c92015-02-28 22:56:06 -0700378 if (faceStatus.hasExpirationPeriod()) {
379 std::cout << "<expirationPeriod>PT"
380 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
381 .count() << "S"
382 << "</expirationPeriod>";
383 }
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700384
Junxiao Shi78926c92015-02-28 22:56:06 -0700385 std::cout << "<faceScope>" << faceStatus.getFaceScope()
386 << "</faceScope>";
387 std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
388 << "</facePersistency>";
389 std::cout << "<linkType>" << faceStatus.getLinkType()
390 << "</linkType>";
Chengyu Fan27d570a2014-10-09 11:52:17 -0600391
Junxiao Shi78926c92015-02-28 22:56:06 -0700392 std::cout << "<packetCounters>";
393 std::cout << "<incomingPackets>";
394 std::cout << "<nInterests>" << faceStatus.getNInInterests()
395 << "</nInterests>";
396 std::cout << "<nDatas>" << faceStatus.getNInDatas()
397 << "</nDatas>";
398 std::cout << "</incomingPackets>";
399 std::cout << "<outgoingPackets>";
400 std::cout << "<nInterests>" << faceStatus.getNOutInterests()
401 << "</nInterests>";
402 std::cout << "<nDatas>" << faceStatus.getNOutDatas()
403 << "</nDatas>";
404 std::cout << "</outgoingPackets>";
405 std::cout << "</packetCounters>";
Alexander Afanasyevd3967a22014-06-30 12:22:10 -0700406
Junxiao Shi78926c92015-02-28 22:56:06 -0700407 std::cout << "<byteCounters>";
408 std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
409 << "</incomingBytes>";
410 std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
411 << "</outgoingBytes>";
412 std::cout << "</byteCounters>";
Chengyu Fan3331cfa2014-07-25 17:36:31 -0600413
Junxiao Shi78926c92015-02-28 22:56:06 -0700414 std::cout << "</face>";
jeraldabrahamb6dde382014-03-19 18:58:09 -0700415 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700416 std::cout << "</faces>";
417 }
418 else {
419 std::cout << "Faces:" << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600420
Junxiao Shi78926c92015-02-28 22:56:06 -0700421 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800422 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700423 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600424 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800425 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700426 if (!isOk) {
427 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
428 break;
429 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600430
Junxiao Shi78926c92015-02-28 22:56:06 -0700431 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600432
Junxiao Shi78926c92015-02-28 22:56:06 -0700433 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600434
Junxiao Shi78926c92015-02-28 22:56:06 -0700435 std::cout << " faceid=" << faceStatus.getFaceId()
436 << " remote=" << faceStatus.getRemoteUri()
437 << " local=" << faceStatus.getLocalUri();
438 if (faceStatus.hasExpirationPeriod()) {
439 std::cout << " expires="
440 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
441 .count() << "s";
442 }
443 std::cout << " counters={"
444 << "in={" << faceStatus.getNInInterests() << "i "
445 << faceStatus.getNInDatas() << "d "
446 << faceStatus.getNInBytes() << "B}"
447 << " out={" << faceStatus.getNOutInterests() << "i "
448 << faceStatus.getNOutDatas() << "d "
449 << faceStatus.getNOutBytes() << "B}"
450 << "}";
451 std::cout << " " << faceStatus.getFaceScope()
452 << " " << faceStatus.getFacePersistency()
453 << " " << faceStatus.getLinkType();
454 std::cout << std::endl;
455 }
456 }
jeraldabrahamb6dde382014-03-19 18:58:09 -0700457
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300458 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700459 }
460
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300461 //////////////////////////////////////////////////////////////////////////////////
462 //////////////////////////////////////////////////////////////////////////////////
463
jeraldabrahamb6dde382014-03-19 18:58:09 -0700464 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300465 fetchFibEnumerationInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700466 {
467 m_buffer = make_shared<OBufferStream>();
468
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300469 Interest interest("/localhost/nfd/fib/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700470 interest.setChildSelector(1);
471 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800472
473 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500474 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800475 bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1),
476 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700477 }
478
479 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800480 afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700481 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700482 if (m_isOutputXml) {
483 std::cout << "<fib>";
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700484
Junxiao Shi78926c92015-02-28 22:56:06 -0700485 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800486 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700487 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600488 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800489 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700490 if (!isOk) {
491 std::cerr << "ERROR: cannot decode FibEntry TLV";
492 break;
493 }
494 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600495
Junxiao Shi78926c92015-02-28 22:56:06 -0700496 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600497
Junxiao Shi78926c92015-02-28 22:56:06 -0700498 std::cout << "<fibEntry>";
499 std::string prefix(fibEntry.getPrefix().toUri());
500 escapeSpecialCharacters(&prefix);
501 std::cout << "<prefix>" << prefix << "</prefix>";
502 std::cout << "<nextHops>";
503 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
504 std::cout << "<nextHop>" ;
505 std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>";
506 std::cout << "<cost>" << nextHop.getCost() << "</cost>";
507 std::cout << "</nextHop>";
508 }
509 std::cout << "</nextHops>";
510 std::cout << "</fibEntry>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600511 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600512
Junxiao Shi78926c92015-02-28 22:56:06 -0700513 std::cout << "</fib>";
514 }
515 else {
516 std::cout << "FIB:" << std::endl;
517
518 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800519 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700520 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600521 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800522 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700523 if (!isOk) {
524 std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
525 break;
526 }
527 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600528
Junxiao Shi78926c92015-02-28 22:56:06 -0700529 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600530
Junxiao Shi78926c92015-02-28 22:56:06 -0700531 std::cout << " " << fibEntry.getPrefix() << " nexthops={";
532 bool isFirst = true;
533 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
534 if (isFirst)
535 isFirst = false;
536 else
537 std::cout << ", ";
538
539 std::cout << "faceid=" << nextHop.getFaceId()
540 << " (cost=" << nextHop.getCost() << ")";
541 }
542 std::cout << "}" << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700543 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700544 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300545
546 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700547 }
548
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300549 //////////////////////////////////////////////////////////////////////////////////
550 //////////////////////////////////////////////////////////////////////////////////
551
jeraldabrahamb6dde382014-03-19 18:58:09 -0700552 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300553 fetchStrategyChoiceInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700554 {
555 m_buffer = make_shared<OBufferStream>();
556
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300557 Interest interest("/localhost/nfd/strategy-choice/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700558 interest.setChildSelector(1);
559 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800560
561 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500562 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800563 bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1),
564 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700565 }
566
567 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800568 afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300569 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700570 if (m_isOutputXml) {
571 std::cout << "<strategyChoices>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300572
Junxiao Shi78926c92015-02-28 22:56:06 -0700573 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800574 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700575 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300576 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800577 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700578 if (!isOk) {
579 std::cerr << "ERROR: cannot decode StrategyChoice TLV";
580 break;
581 }
582 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300583
Junxiao Shi78926c92015-02-28 22:56:06 -0700584 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300585
Junxiao Shi78926c92015-02-28 22:56:06 -0700586 std::cout << "<strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300587
Junxiao Shi78926c92015-02-28 22:56:06 -0700588 std::string name(strategyChoice.getName().toUri());
589 escapeSpecialCharacters(&name);
590 std::cout << "<namespace>" << name << "</namespace>";
591 std::cout << "<strategy>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300592
Junxiao Shi78926c92015-02-28 22:56:06 -0700593 std::string strategy(strategyChoice.getStrategy().toUri());
594 escapeSpecialCharacters(&strategy);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300595
Junxiao Shi78926c92015-02-28 22:56:06 -0700596 std::cout << "<name>" << strategy << "</name>";
597 std::cout << "</strategy>";
598 std::cout << "</strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300599 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300600
Junxiao Shi78926c92015-02-28 22:56:06 -0700601 std::cout << "</strategyChoices>";
602 }
603 else {
604 std::cout << "Strategy choices:" << std::endl;
605
606 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800607 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700608 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300609 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800610 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700611 if (!isOk) {
612 std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
613 break;
614 }
615 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300616
Junxiao Shi78926c92015-02-28 22:56:06 -0700617 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300618
Junxiao Shi78926c92015-02-28 22:56:06 -0700619 std::cout << " " << strategyChoice.getName()
620 << " strategy=" << strategyChoice.getStrategy() << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300621 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700622 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300623
624 runNextStep();
625 }
626
627 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600628 fetchRibStatusInformation()
629 {
630 m_buffer = make_shared<OBufferStream>();
631
632 Interest interest("/localhost/nfd/rib/list");
633 interest.setChildSelector(1);
634 interest.setMustBeFresh(true);
635
Yukai Tu971d3c22015-06-21 12:32:03 +0800636 SegmentFetcher::fetch(m_face, interest,
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500637 m_validator,
Yukai Tu971d3c22015-06-21 12:32:03 +0800638 bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1),
639 bind(&NfdStatus::onErrorFetch, this, _1, _2));
Chengyu Fan30aa2072014-07-20 13:52:32 -0600640 }
641
642 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800643 afterFetchedRibStatusInformation(const ConstBufferPtr& dataset)
Chengyu Fan30aa2072014-07-20 13:52:32 -0600644 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700645 if (m_isOutputXml) {
646 std::cout << "<rib>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600647
Junxiao Shi78926c92015-02-28 22:56:06 -0700648 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800649 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700650 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600651 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800652 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700653 if (!isOk) {
654 std::cerr << "ERROR: cannot decode RibEntry TLV";
655 break;
656 }
657 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600658
Junxiao Shi78926c92015-02-28 22:56:06 -0700659 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600660
Junxiao Shi78926c92015-02-28 22:56:06 -0700661 std::cout << "<ribEntry>";
662 std::string prefix(ribEntry.getName().toUri());
663 escapeSpecialCharacters(&prefix);
664 std::cout << "<prefix>" << prefix << "</prefix>";
665 std::cout << "<routes>";
666 for (const nfd::Route& nextRoute : ribEntry) {
667 std::cout << "<route>" ;
668 std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>";
669 std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>";
670 std::cout << "<cost>" << nextRoute.getCost() << "</cost>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500671
Junxiao Shi78926c92015-02-28 22:56:06 -0700672 std::cout << "<flags>";
673 if (nextRoute.isChildInherit())
674 std::cout << "<childInherit/>";
675 if (nextRoute.isRibCapture())
676 std::cout << "<ribCapture/>";
677 std::cout << "</flags>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500678
Junxiao Shi78926c92015-02-28 22:56:06 -0700679 if (!nextRoute.hasInfiniteExpirationPeriod()) {
680 std::cout << "<expirationPeriod>PT"
681 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
682 .count() << "S"
683 << "</expirationPeriod>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600684 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700685 std::cout << "</route>";
686 }
687 std::cout << "</routes>";
688 std::cout << "</ribEntry>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600689 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600690
Junxiao Shi78926c92015-02-28 22:56:06 -0700691 std::cout << "</rib>";
692 }
693 else {
694 std::cout << "RIB:" << std::endl;
695
696 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800697 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700698 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600699 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800700 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700701 if (!isOk) {
702 std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
703 break;
704 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600705
Junxiao Shi78926c92015-02-28 22:56:06 -0700706 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600707
Junxiao Shi78926c92015-02-28 22:56:06 -0700708 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600709
Junxiao Shi78926c92015-02-28 22:56:06 -0700710 std::cout << " " << ribEntry.getName().toUri() << " route={";
711 bool isFirst = true;
712 for (const nfd::Route& nextRoute : ribEntry) {
713 if (isFirst)
714 isFirst = false;
715 else
716 std::cout << ", ";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500717
Junxiao Shi78926c92015-02-28 22:56:06 -0700718 std::cout << "faceid=" << nextRoute.getFaceId()
719 << " (origin=" << nextRoute.getOrigin()
720 << " cost=" << nextRoute.getCost();
721 if (!nextRoute.hasInfiniteExpirationPeriod()) {
722 std::cout << " expires="
723 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
724 .count() << "s";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600725 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700726
727 if (nextRoute.isChildInherit())
728 std::cout << " ChildInherit";
729 if (nextRoute.isRibCapture())
730 std::cout << " RibCapture";
731
732 std::cout << ")";
733 }
734 std::cout << "}" << std::endl;
735 }
736 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600737
738 runNextStep();
739 }
740
741
742 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700743 fetchInformation()
744 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300745 if (m_isOutputXml ||
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600746 (!m_needVersionRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300747 !m_needChannelStatusRetrieval &&
748 !m_needFaceStatusRetrieval &&
749 !m_needFibEnumerationRetrieval &&
Chengyu Fan30aa2072014-07-20 13:52:32 -0600750 !m_needRibStatusRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300751 !m_needStrategyChoiceRetrieval))
jeraldabrahamb6dde382014-03-19 18:58:09 -0700752 {
753 enableVersionRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300754 enableChannelStatusRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700755 enableFaceStatusRetrieval();
756 enableFibEnumerationRetrieval();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600757 enableRibStatusRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300758 enableStrategyChoiceRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700759 }
760
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300761 if (m_isOutputXml)
762 m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this));
763
jeraldabrahamb6dde382014-03-19 18:58:09 -0700764 if (m_needVersionRetrieval)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300765 m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700766
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300767 if (m_needChannelStatusRetrieval)
768 m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this));
769
770 if (m_needFaceStatusRetrieval)
771 m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this));
772
773 if (m_needFibEnumerationRetrieval)
774 m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this));
775
Chengyu Fan30aa2072014-07-20 13:52:32 -0600776 if (m_needRibStatusRetrieval)
777 m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this));
778
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300779 if (m_needStrategyChoiceRetrieval)
780 m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this));
781
782 if (m_isOutputXml)
783 m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this));
784
785 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700786 m_face.processEvents();
787 }
788
789private:
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300790 void
791 printXmlHeader()
792 {
793 std::cout << "<?xml version=\"1.0\"?>";
794 std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">";
795
796 runNextStep();
797 }
798
799 void
800 printXmlFooter()
801 {
802 std::cout << "</nfdStatus>";
803
804 runNextStep();
805 }
806
807 void
808 runNextStep()
809 {
810 if (m_fetchSteps.empty())
811 return;
812
813 function<void()> nextStep = m_fetchSteps.front();
814 m_fetchSteps.pop_front();
815 nextStep();
816 }
817
818private:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700819 std::string m_toolName;
820 bool m_needVersionRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300821 bool m_needChannelStatusRetrieval;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700822 bool m_needFaceStatusRetrieval;
823 bool m_needFibEnumerationRetrieval;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600824 bool m_needRibStatusRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300825 bool m_needStrategyChoiceRetrieval;
826 bool m_isOutputXml;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700827 Face m_face;
828
829 shared_ptr<OBufferStream> m_buffer;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300830
831 std::deque<function<void()> > m_fetchSteps;
Muktadir R Chowdhury6c4a67a2015-09-07 22:13:01 -0500832
833 ndn::ValidatorNull m_validator;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700834};
835
836}
837
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700838int main(int argc, char* argv[])
jeraldabrahamb6dde382014-03-19 18:58:09 -0700839{
840 int option;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700841 ndn::NfdStatus nfdStatus(argv[0]);
jeraldabrahamb6dde382014-03-19 18:58:09 -0700842
Chengyu Fan30aa2072014-07-20 13:52:32 -0600843 while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700844 switch (option) {
845 case 'h':
846 nfdStatus.usage();
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700847 return 0;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700848 case 'v':
849 nfdStatus.enableVersionRetrieval();
850 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300851 case 'c':
852 nfdStatus.enableChannelStatusRetrieval();
853 break;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700854 case 'f':
855 nfdStatus.enableFaceStatusRetrieval();
856 break;
857 case 'b':
858 nfdStatus.enableFibEnumerationRetrieval();
859 break;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600860 case 'r':
861 nfdStatus.enableRibStatusRetrieval();
862 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300863 case 's':
864 nfdStatus.enableStrategyChoiceRetrieval();
865 break;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600866 case 'x':
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300867 nfdStatus.enableXmlOutput();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600868 break;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700869 case 'V':
870 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
871 return 0;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700872 default:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700873 nfdStatus.usage();
874 return 1;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700875 }
876 }
877
878 try {
879 nfdStatus.fetchInformation();
880 }
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700881 catch (std::exception& e) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700882 std::cerr << "ERROR: " << e.what() << std::endl;
883 return 2;
884 }
885
886 return 0;
887}