blob: a4b6e1a1c382d97ca251402af8a5ce117d7429eb [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>
jeraldabrahamb6dde382014-03-19 18:58:09 -070042
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070043#include <boost/algorithm/string/replace.hpp>
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030044#include <list>
Alexander Afanasyevb3893c92014-05-15 01:49:54 -070045
jeraldabrahamb6dde382014-03-19 18:58:09 -070046namespace ndn {
47
Yukai Tu971d3c22015-06-21 12:32:03 +080048using util::SegmentFetcher;
49
jeraldabrahamb6dde382014-03-19 18:58:09 -070050class NfdStatus
51{
52public:
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -070053 explicit
jeraldabrahamb6dde382014-03-19 18:58:09 -070054 NfdStatus(char* toolName)
55 : m_toolName(toolName)
56 , m_needVersionRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030057 , m_needChannelStatusRetrieval(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070058 , m_needFaceStatusRetrieval(false)
59 , m_needFibEnumerationRetrieval(false)
Chengyu Fan30aa2072014-07-20 13:52:32 -060060 , m_needRibStatusRetrieval(false)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030061 , m_needStrategyChoiceRetrieval(false)
62 , m_isOutputXml(false)
jeraldabrahamb6dde382014-03-19 18:58:09 -070063 {
64 }
65
66 void
67 usage()
68 {
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -070069 std::cout << "Usage: \n " << m_toolName << " [options]\n\n"
70 "Show NFD version and status information\n\n"
71 "Options:\n"
72 " [-h] - print this help message\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -070073 " [-v] - retrieve version information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030074 " [-c] - retrieve channel status information\n"
jeraldabrahamb6dde382014-03-19 18:58:09 -070075 " [-f] - retrieve face status information\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070076 " [-b] - retrieve FIB information\n"
Chengyu Fan30aa2072014-07-20 13:52:32 -060077 " [-r] - retrieve RIB information\n"
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030078 " [-s] - retrieve configured strategy choice for NDN namespaces\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -060079 " [-x] - output NFD status information in XML format\n"
Alexander Afanasyevb47d5382014-05-05 14:35:03 -070080 "\n"
81 " [-V] - show version information of nfd-status and exit\n"
82 "\n"
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -070083 "If no options are provided, all information is retrieved.\n"
Chengyu Fanee92fc72014-06-21 14:58:19 -060084 "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 -070085 ;
jeraldabrahamb6dde382014-03-19 18:58:09 -070086 }
87
88 void
89 enableVersionRetrieval()
90 {
91 m_needVersionRetrieval = true;
92 }
93
94 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +030095 enableChannelStatusRetrieval()
96 {
97 m_needChannelStatusRetrieval = true;
98 }
99
100 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700101 enableFaceStatusRetrieval()
102 {
103 m_needFaceStatusRetrieval = true;
104 }
105
106 void
107 enableFibEnumerationRetrieval()
108 {
109 m_needFibEnumerationRetrieval = true;
110 }
111
112 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300113 enableStrategyChoiceRetrieval()
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600114 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300115 m_needStrategyChoiceRetrieval = true;
116 }
117
118 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600119 enableRibStatusRetrieval()
120 {
121 m_needRibStatusRetrieval = true;
122 }
123
124 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300125 enableXmlOutput()
126 {
127 m_isOutputXml = true;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600128 }
129
130 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700131 onTimeout()
132 {
133 std::cerr << "Request timed out" << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300134
135 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700136 }
137
Yukai Tu971d3c22015-06-21 12:32:03 +0800138
jeraldabrahamb6dde382014-03-19 18:58:09 -0700139 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800140 onErrorFetch(uint32_t errorCode, const std::string& errorMsg)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700141 {
Yukai Tu971d3c22015-06-21 12:32:03 +0800142 std::cerr << "Error code:" << errorCode << ", message:" << errorMsg << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700143
Yukai Tu971d3c22015-06-21 12:32:03 +0800144 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700145 }
146
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300147 void
148 escapeSpecialCharacters(std::string *data)
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600149 {
150 using boost::algorithm::replace_all;
151 replace_all(*data, "&", "&amp;");
152 replace_all(*data, "\"", "&quot;");
153 replace_all(*data, "\'", "&apos;");
154 replace_all(*data, "<", "&lt;");
155 replace_all(*data, ">", "&gt;");
156 }
157
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300158 //////////////////////////////////////////////////////////////////////////////////
159 //////////////////////////////////////////////////////////////////////////////////
160
161 void
162 fetchVersionInformation()
163 {
164 Interest interest("/localhost/nfd/status");
165 interest.setChildSelector(1);
166 interest.setMustBeFresh(true);
167 m_face.expressInterest(
168 interest,
169 bind(&NfdStatus::afterFetchedVersionInformation, this, _2),
170 bind(&NfdStatus::onTimeout, this));
171 }
172
jeraldabrahamb6dde382014-03-19 18:58:09 -0700173 void
174 afterFetchedVersionInformation(const Data& data)
175 {
Junxiao Shi88d69372014-03-28 11:52:39 -0700176 nfd::ForwarderStatus status(data.getContent());
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600177 std::string nfdId;
178 if (data.getSignature().hasKeyLocator())
179 {
180 const ndn::KeyLocator& locator = data.getSignature().getKeyLocator();
181 if (locator.getType() == KeyLocator::KeyLocator_Name)
182 nfdId = locator.getName().toUri();
183 //todo: KeyDigest supporting
184 }
185
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300186 if (m_isOutputXml)
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600187 {
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600188 std::cout << "<generalStatus>";
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600189 std::cout << "<nfdId>"
190 << nfdId << "</nfdId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600191 std::cout << "<version>"
192 << status.getNfdVersion() << "</version>";
193 std::cout << "<startTime>"
194 << time::toString(status.getStartTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
195 << "</startTime>";
196 std::cout << "<currentTime>"
197 << time::toString(status.getCurrentTimestamp(), "%Y-%m-%dT%H:%M:%S%F")
198 << "</currentTime>";
199 std::cout << "<uptime>PT"
200 << time::duration_cast<time::seconds>(status.getCurrentTimestamp()
201 - status.getStartTimestamp()).count()
202 << "S</uptime>";
203 std::cout << "<nNameTreeEntries>" << status.getNNameTreeEntries()
204 << "</nNameTreeEntries>";
205 std::cout << "<nFibEntries>" << status.getNFibEntries()
206 << "</nFibEntries>";
207 std::cout << "<nPitEntries>" << status.getNPitEntries()
208 << "</nPitEntries>";
209 std::cout << "<nMeasurementsEntries>" << status.getNMeasurementsEntries()
210 << "</nMeasurementsEntries>";
211 std::cout << "<nCsEntries>" << status.getNCsEntries()
212 << "</nCsEntries>";
213 std::cout << "<packetCounters>";
214 std::cout << "<incomingPackets>";
215 std::cout << "<nInterests>" << status.getNInInterests()
216 << "</nInterests>";
217 std::cout << "<nDatas>" << status.getNInDatas()
218 << "</nDatas>";
219 std::cout << "</incomingPackets>";
220 std::cout << "<outgoingPackets>";
221 std::cout << "<nInterests>" << status.getNOutInterests()
222 << "</nInterests>";
223 std::cout << "<nDatas>" << status.getNOutDatas()
224 << "</nDatas>";
225 std::cout << "</outgoingPackets>";
226 std::cout << "</packetCounters>";
227 std::cout << "</generalStatus>";
228 }
229 else
230 {
231 std::cout << "General NFD status:" << std::endl;
Chengyu Fan8a53caf2014-08-01 14:08:37 -0600232 std::cout << " nfdId="
233 << nfdId << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600234 std::cout << " version="
235 << status.getNfdVersion() << std::endl;
236 std::cout << " startTime="
237 << time::toIsoString(status.getStartTimestamp()) << std::endl;
238 std::cout << " currentTime="
239 << time::toIsoString(status.getCurrentTimestamp()) << std::endl;
240 std::cout << " uptime="
241 << time::duration_cast<time::seconds>(status.getCurrentTimestamp()
242 - status.getStartTimestamp()) << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700243
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600244 std::cout << " nNameTreeEntries=" << status.getNNameTreeEntries() << std::endl;
245 std::cout << " nFibEntries=" << status.getNFibEntries() << std::endl;
246 std::cout << " nPitEntries=" << status.getNPitEntries() << std::endl;
247 std::cout << " nMeasurementsEntries=" << status.getNMeasurementsEntries() << std::endl;
248 std::cout << " nCsEntries=" << status.getNCsEntries() << std::endl;
249 std::cout << " nInInterests=" << status.getNInInterests() << std::endl;
250 std::cout << " nOutInterests=" << status.getNOutInterests() << std::endl;
251 std::cout << " nInDatas=" << status.getNInDatas() << std::endl;
252 std::cout << " nOutDatas=" << status.getNOutDatas() << std::endl;
253 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300254
255 runNextStep();
256 }
257
258 //////////////////////////////////////////////////////////////////////////////////
259 //////////////////////////////////////////////////////////////////////////////////
260
261 void
262 fetchChannelStatusInformation()
263 {
264 m_buffer = make_shared<OBufferStream>();
265
266 Interest interest("/localhost/nfd/faces/channels");
267 interest.setChildSelector(1);
268 interest.setMustBeFresh(true);
269
Yukai Tu971d3c22015-06-21 12:32:03 +0800270 SegmentFetcher::fetch(m_face, interest,
271 util::DontVerifySegment(),
272 bind(&NfdStatus::afterFetchedChannelStatusInformation, this, _1),
273 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700274 }
275
276 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800277 afterFetchedChannelStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700278 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700279 if (m_isOutputXml) {
280 std::cout << "<channels>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300281
Junxiao Shi78926c92015-02-28 22:56:06 -0700282 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800283 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700284 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300285 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800286 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700287 if (!isOk) {
288 std::cerr << "ERROR: cannot decode ChannelStatus TLV" << std::endl;
289 break;
290 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300291
Junxiao Shi78926c92015-02-28 22:56:06 -0700292 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300293
Junxiao Shi78926c92015-02-28 22:56:06 -0700294 nfd::ChannelStatus channelStatus(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300295
Junxiao Shi78926c92015-02-28 22:56:06 -0700296 std::cout << "<channel>";
297 std::string localUri(channelStatus.getLocalUri());
298 escapeSpecialCharacters(&localUri);
299 std::cout << "<localUri>" << localUri << "</localUri>";
300 std::cout << "</channel>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300301 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300302
Junxiao Shi78926c92015-02-28 22:56:06 -0700303 std::cout << "</channels>";
304 }
305 else {
306 std::cout << "Channels:" << std::endl;
307
308 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);
321 std::cout << " " << channelStatus.getLocalUri() << std::endl;
322 }
323 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300324
325 runNextStep();
326 }
327
328 //////////////////////////////////////////////////////////////////////////////////
329 //////////////////////////////////////////////////////////////////////////////////
330
331 void
332 fetchFaceStatusInformation()
333 {
334 m_buffer = make_shared<OBufferStream>();
335
336 Interest interest("/localhost/nfd/faces/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700337 interest.setChildSelector(1);
338 interest.setMustBeFresh(true);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300339
Yukai Tu971d3c22015-06-21 12:32:03 +0800340 SegmentFetcher::fetch(m_face, interest,
341 util::DontVerifySegment(),
342 bind(&NfdStatus::afterFetchedFaceStatusInformation, this, _1),
343 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700344 }
345
346 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800347 afterFetchedFaceStatusInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700348 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700349 if (m_isOutputXml) {
350 std::cout << "<faces>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600351
Junxiao Shi78926c92015-02-28 22:56:06 -0700352 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800353 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700354 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600355 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800356 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700357 if (!isOk) {
358 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
359 break;
360 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600361
Junxiao Shi78926c92015-02-28 22:56:06 -0700362 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600363
Junxiao Shi78926c92015-02-28 22:56:06 -0700364 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600365
Junxiao Shi78926c92015-02-28 22:56:06 -0700366 std::cout << "<face>";
367 std::cout << "<faceId>" << faceStatus.getFaceId() << "</faceId>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600368
Junxiao Shi78926c92015-02-28 22:56:06 -0700369 std::string remoteUri(faceStatus.getRemoteUri());
370 escapeSpecialCharacters(&remoteUri);
371 std::cout << "<remoteUri>" << remoteUri << "</remoteUri>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600372
Junxiao Shi78926c92015-02-28 22:56:06 -0700373 std::string localUri(faceStatus.getLocalUri());
374 escapeSpecialCharacters(&localUri);
375 std::cout << "<localUri>" << localUri << "</localUri>";
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700376
Junxiao Shi78926c92015-02-28 22:56:06 -0700377 if (faceStatus.hasExpirationPeriod()) {
378 std::cout << "<expirationPeriod>PT"
379 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
380 .count() << "S"
381 << "</expirationPeriod>";
382 }
Alexander Afanasyev40c61f72014-06-30 17:21:01 -0700383
Junxiao Shi78926c92015-02-28 22:56:06 -0700384 std::cout << "<faceScope>" << faceStatus.getFaceScope()
385 << "</faceScope>";
386 std::cout << "<facePersistency>" << faceStatus.getFacePersistency()
387 << "</facePersistency>";
388 std::cout << "<linkType>" << faceStatus.getLinkType()
389 << "</linkType>";
Chengyu Fan27d570a2014-10-09 11:52:17 -0600390
Junxiao Shi78926c92015-02-28 22:56:06 -0700391 std::cout << "<packetCounters>";
392 std::cout << "<incomingPackets>";
393 std::cout << "<nInterests>" << faceStatus.getNInInterests()
394 << "</nInterests>";
395 std::cout << "<nDatas>" << faceStatus.getNInDatas()
396 << "</nDatas>";
397 std::cout << "</incomingPackets>";
398 std::cout << "<outgoingPackets>";
399 std::cout << "<nInterests>" << faceStatus.getNOutInterests()
400 << "</nInterests>";
401 std::cout << "<nDatas>" << faceStatus.getNOutDatas()
402 << "</nDatas>";
403 std::cout << "</outgoingPackets>";
404 std::cout << "</packetCounters>";
Alexander Afanasyevd3967a22014-06-30 12:22:10 -0700405
Junxiao Shi78926c92015-02-28 22:56:06 -0700406 std::cout << "<byteCounters>";
407 std::cout << "<incomingBytes>" << faceStatus.getNInBytes()
408 << "</incomingBytes>";
409 std::cout << "<outgoingBytes>" << faceStatus.getNOutBytes()
410 << "</outgoingBytes>";
411 std::cout << "</byteCounters>";
Chengyu Fan3331cfa2014-07-25 17:36:31 -0600412
Junxiao Shi78926c92015-02-28 22:56:06 -0700413 std::cout << "</face>";
jeraldabrahamb6dde382014-03-19 18:58:09 -0700414 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700415 std::cout << "</faces>";
416 }
417 else {
418 std::cout << "Faces:" << std::endl;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600419
Junxiao Shi78926c92015-02-28 22:56:06 -0700420 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800421 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700422 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600423 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800424 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700425 if (!isOk) {
426 std::cerr << "ERROR: cannot decode FaceStatus TLV" << std::endl;
427 break;
428 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600429
Junxiao Shi78926c92015-02-28 22:56:06 -0700430 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600431
Junxiao Shi78926c92015-02-28 22:56:06 -0700432 nfd::FaceStatus faceStatus(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600433
Junxiao Shi78926c92015-02-28 22:56:06 -0700434 std::cout << " faceid=" << faceStatus.getFaceId()
435 << " remote=" << faceStatus.getRemoteUri()
436 << " local=" << faceStatus.getLocalUri();
437 if (faceStatus.hasExpirationPeriod()) {
438 std::cout << " expires="
439 << time::duration_cast<time::seconds>(faceStatus.getExpirationPeriod())
440 .count() << "s";
441 }
442 std::cout << " counters={"
443 << "in={" << faceStatus.getNInInterests() << "i "
444 << faceStatus.getNInDatas() << "d "
445 << faceStatus.getNInBytes() << "B}"
446 << " out={" << faceStatus.getNOutInterests() << "i "
447 << faceStatus.getNOutDatas() << "d "
448 << faceStatus.getNOutBytes() << "B}"
449 << "}";
450 std::cout << " " << faceStatus.getFaceScope()
451 << " " << faceStatus.getFacePersistency()
452 << " " << faceStatus.getLinkType();
453 std::cout << std::endl;
454 }
455 }
jeraldabrahamb6dde382014-03-19 18:58:09 -0700456
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300457 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700458 }
459
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300460 //////////////////////////////////////////////////////////////////////////////////
461 //////////////////////////////////////////////////////////////////////////////////
462
jeraldabrahamb6dde382014-03-19 18:58:09 -0700463 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300464 fetchFibEnumerationInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700465 {
466 m_buffer = make_shared<OBufferStream>();
467
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300468 Interest interest("/localhost/nfd/fib/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700469 interest.setChildSelector(1);
470 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800471
472 SegmentFetcher::fetch(m_face, interest,
473 util::DontVerifySegment(),
474 bind(&NfdStatus::afterFetchedFibEnumerationInformation, this, _1),
475 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700476 }
477
478 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800479 afterFetchedFibEnumerationInformation(const ConstBufferPtr& dataset)
jeraldabrahamb6dde382014-03-19 18:58:09 -0700480 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700481 if (m_isOutputXml) {
482 std::cout << "<fib>";
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700483
Junxiao Shi78926c92015-02-28 22:56:06 -0700484 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800485 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700486 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600487 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800488 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700489 if (!isOk) {
490 std::cerr << "ERROR: cannot decode FibEntry TLV";
491 break;
492 }
493 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600494
Junxiao Shi78926c92015-02-28 22:56:06 -0700495 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600496
Junxiao Shi78926c92015-02-28 22:56:06 -0700497 std::cout << "<fibEntry>";
498 std::string prefix(fibEntry.getPrefix().toUri());
499 escapeSpecialCharacters(&prefix);
500 std::cout << "<prefix>" << prefix << "</prefix>";
501 std::cout << "<nextHops>";
502 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
503 std::cout << "<nextHop>" ;
504 std::cout << "<faceId>" << nextHop.getFaceId() << "</faceId>";
505 std::cout << "<cost>" << nextHop.getCost() << "</cost>";
506 std::cout << "</nextHop>";
507 }
508 std::cout << "</nextHops>";
509 std::cout << "</fibEntry>";
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600510 }
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600511
Junxiao Shi78926c92015-02-28 22:56:06 -0700512 std::cout << "</fib>";
513 }
514 else {
515 std::cout << "FIB:" << std::endl;
516
517 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800518 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700519 bool isOk = false;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600520 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800521 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700522 if (!isOk) {
523 std::cerr << "ERROR: cannot decode FibEntry TLV" << std::endl;
524 break;
525 }
526 offset += block.size();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600527
Junxiao Shi78926c92015-02-28 22:56:06 -0700528 nfd::FibEntry fibEntry(block);
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600529
Junxiao Shi78926c92015-02-28 22:56:06 -0700530 std::cout << " " << fibEntry.getPrefix() << " nexthops={";
531 bool isFirst = true;
532 for (const nfd::NextHopRecord& nextHop : fibEntry.getNextHopRecords()) {
533 if (isFirst)
534 isFirst = false;
535 else
536 std::cout << ", ";
537
538 std::cout << "faceid=" << nextHop.getFaceId()
539 << " (cost=" << nextHop.getCost() << ")";
540 }
541 std::cout << "}" << std::endl;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700542 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700543 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300544
545 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700546 }
547
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300548 //////////////////////////////////////////////////////////////////////////////////
549 //////////////////////////////////////////////////////////////////////////////////
550
jeraldabrahamb6dde382014-03-19 18:58:09 -0700551 void
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300552 fetchStrategyChoiceInformation()
jeraldabrahamb6dde382014-03-19 18:58:09 -0700553 {
554 m_buffer = make_shared<OBufferStream>();
555
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300556 Interest interest("/localhost/nfd/strategy-choice/list");
jeraldabrahamb6dde382014-03-19 18:58:09 -0700557 interest.setChildSelector(1);
558 interest.setMustBeFresh(true);
Yukai Tu971d3c22015-06-21 12:32:03 +0800559
560 SegmentFetcher::fetch(m_face, interest,
561 util::DontVerifySegment(),
562 bind(&NfdStatus::afterFetchedStrategyChoiceInformationInformation, this, _1),
563 bind(&NfdStatus::onErrorFetch, this, _1, _2));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700564 }
565
566 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800567 afterFetchedStrategyChoiceInformationInformation(const ConstBufferPtr& dataset)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300568 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700569 if (m_isOutputXml) {
570 std::cout << "<strategyChoices>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300571
Junxiao Shi78926c92015-02-28 22:56:06 -0700572 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800573 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700574 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300575 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800576 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700577 if (!isOk) {
578 std::cerr << "ERROR: cannot decode StrategyChoice TLV";
579 break;
580 }
581 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300582
Junxiao Shi78926c92015-02-28 22:56:06 -0700583 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300584
Junxiao Shi78926c92015-02-28 22:56:06 -0700585 std::cout << "<strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300586
Junxiao Shi78926c92015-02-28 22:56:06 -0700587 std::string name(strategyChoice.getName().toUri());
588 escapeSpecialCharacters(&name);
589 std::cout << "<namespace>" << name << "</namespace>";
590 std::cout << "<strategy>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300591
Junxiao Shi78926c92015-02-28 22:56:06 -0700592 std::string strategy(strategyChoice.getStrategy().toUri());
593 escapeSpecialCharacters(&strategy);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300594
Junxiao Shi78926c92015-02-28 22:56:06 -0700595 std::cout << "<name>" << strategy << "</name>";
596 std::cout << "</strategy>";
597 std::cout << "</strategyChoice>";
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300598 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300599
Junxiao Shi78926c92015-02-28 22:56:06 -0700600 std::cout << "</strategyChoices>";
601 }
602 else {
603 std::cout << "Strategy choices:" << std::endl;
604
605 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800606 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700607 bool isOk = false;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300608 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800609 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700610 if (!isOk) {
611 std::cerr << "ERROR: cannot decode StrategyChoice TLV" << std::endl;
612 break;
613 }
614 offset += block.size();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300615
Junxiao Shi78926c92015-02-28 22:56:06 -0700616 nfd::StrategyChoice strategyChoice(block);
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300617
Junxiao Shi78926c92015-02-28 22:56:06 -0700618 std::cout << " " << strategyChoice.getName()
619 << " strategy=" << strategyChoice.getStrategy() << std::endl;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300620 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700621 }
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300622
623 runNextStep();
624 }
625
626 void
Chengyu Fan30aa2072014-07-20 13:52:32 -0600627 fetchRibStatusInformation()
628 {
629 m_buffer = make_shared<OBufferStream>();
630
631 Interest interest("/localhost/nfd/rib/list");
632 interest.setChildSelector(1);
633 interest.setMustBeFresh(true);
634
Yukai Tu971d3c22015-06-21 12:32:03 +0800635 SegmentFetcher::fetch(m_face, interest,
636 util::DontVerifySegment(),
637 bind(&NfdStatus::afterFetchedRibStatusInformation, this, _1),
638 bind(&NfdStatus::onErrorFetch, this, _1, _2));
Chengyu Fan30aa2072014-07-20 13:52:32 -0600639 }
640
641 void
Yukai Tu971d3c22015-06-21 12:32:03 +0800642 afterFetchedRibStatusInformation(const ConstBufferPtr& dataset)
Chengyu Fan30aa2072014-07-20 13:52:32 -0600643 {
Junxiao Shi78926c92015-02-28 22:56:06 -0700644 if (m_isOutputXml) {
645 std::cout << "<rib>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600646
Junxiao Shi78926c92015-02-28 22:56:06 -0700647 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800648 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700649 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600650 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800651 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700652 if (!isOk) {
653 std::cerr << "ERROR: cannot decode RibEntry TLV";
654 break;
655 }
656 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600657
Junxiao Shi78926c92015-02-28 22:56:06 -0700658 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600659
Junxiao Shi78926c92015-02-28 22:56:06 -0700660 std::cout << "<ribEntry>";
661 std::string prefix(ribEntry.getName().toUri());
662 escapeSpecialCharacters(&prefix);
663 std::cout << "<prefix>" << prefix << "</prefix>";
664 std::cout << "<routes>";
665 for (const nfd::Route& nextRoute : ribEntry) {
666 std::cout << "<route>" ;
667 std::cout << "<faceId>" << nextRoute.getFaceId() << "</faceId>";
668 std::cout << "<origin>" << nextRoute.getOrigin() << "</origin>";
669 std::cout << "<cost>" << nextRoute.getCost() << "</cost>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500670
Junxiao Shi78926c92015-02-28 22:56:06 -0700671 std::cout << "<flags>";
672 if (nextRoute.isChildInherit())
673 std::cout << "<childInherit/>";
674 if (nextRoute.isRibCapture())
675 std::cout << "<ribCapture/>";
676 std::cout << "</flags>";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500677
Junxiao Shi78926c92015-02-28 22:56:06 -0700678 if (!nextRoute.hasInfiniteExpirationPeriod()) {
679 std::cout << "<expirationPeriod>PT"
680 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
681 .count() << "S"
682 << "</expirationPeriod>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600683 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700684 std::cout << "</route>";
685 }
686 std::cout << "</routes>";
687 std::cout << "</ribEntry>";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600688 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600689
Junxiao Shi78926c92015-02-28 22:56:06 -0700690 std::cout << "</rib>";
691 }
692 else {
693 std::cout << "RIB:" << std::endl;
694
695 size_t offset = 0;
Yukai Tu971d3c22015-06-21 12:32:03 +0800696 while (offset < dataset->size()) {
Junxiao Shi78926c92015-02-28 22:56:06 -0700697 bool isOk = false;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600698 Block block;
Yukai Tu971d3c22015-06-21 12:32:03 +0800699 std::tie(isOk, block) = Block::fromBuffer(dataset, offset);
Junxiao Shi78926c92015-02-28 22:56:06 -0700700 if (!isOk) {
701 std::cerr << "ERROR: cannot decode RibEntry TLV" << std::endl;
702 break;
703 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600704
Junxiao Shi78926c92015-02-28 22:56:06 -0700705 offset += block.size();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600706
Junxiao Shi78926c92015-02-28 22:56:06 -0700707 nfd::RibEntry ribEntry(block);
Chengyu Fan30aa2072014-07-20 13:52:32 -0600708
Junxiao Shi78926c92015-02-28 22:56:06 -0700709 std::cout << " " << ribEntry.getName().toUri() << " route={";
710 bool isFirst = true;
711 for (const nfd::Route& nextRoute : ribEntry) {
712 if (isFirst)
713 isFirst = false;
714 else
715 std::cout << ", ";
Chengyu Fan1c630ba2014-08-20 13:27:58 -0500716
Junxiao Shi78926c92015-02-28 22:56:06 -0700717 std::cout << "faceid=" << nextRoute.getFaceId()
718 << " (origin=" << nextRoute.getOrigin()
719 << " cost=" << nextRoute.getCost();
720 if (!nextRoute.hasInfiniteExpirationPeriod()) {
721 std::cout << " expires="
722 << time::duration_cast<time::seconds>(nextRoute.getExpirationPeriod())
723 .count() << "s";
Chengyu Fan30aa2072014-07-20 13:52:32 -0600724 }
Junxiao Shi78926c92015-02-28 22:56:06 -0700725
726 if (nextRoute.isChildInherit())
727 std::cout << " ChildInherit";
728 if (nextRoute.isRibCapture())
729 std::cout << " RibCapture";
730
731 std::cout << ")";
732 }
733 std::cout << "}" << std::endl;
734 }
735 }
Chengyu Fan30aa2072014-07-20 13:52:32 -0600736
737 runNextStep();
738 }
739
740
741 void
jeraldabrahamb6dde382014-03-19 18:58:09 -0700742 fetchInformation()
743 {
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300744 if (m_isOutputXml ||
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600745 (!m_needVersionRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300746 !m_needChannelStatusRetrieval &&
747 !m_needFaceStatusRetrieval &&
748 !m_needFibEnumerationRetrieval &&
Chengyu Fan30aa2072014-07-20 13:52:32 -0600749 !m_needRibStatusRetrieval &&
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300750 !m_needStrategyChoiceRetrieval))
jeraldabrahamb6dde382014-03-19 18:58:09 -0700751 {
752 enableVersionRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300753 enableChannelStatusRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700754 enableFaceStatusRetrieval();
755 enableFibEnumerationRetrieval();
Chengyu Fan30aa2072014-07-20 13:52:32 -0600756 enableRibStatusRetrieval();
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300757 enableStrategyChoiceRetrieval();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700758 }
759
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300760 if (m_isOutputXml)
761 m_fetchSteps.push_back(bind(&NfdStatus::printXmlHeader, this));
762
jeraldabrahamb6dde382014-03-19 18:58:09 -0700763 if (m_needVersionRetrieval)
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300764 m_fetchSteps.push_back(bind(&NfdStatus::fetchVersionInformation, this));
jeraldabrahamb6dde382014-03-19 18:58:09 -0700765
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300766 if (m_needChannelStatusRetrieval)
767 m_fetchSteps.push_back(bind(&NfdStatus::fetchChannelStatusInformation, this));
768
769 if (m_needFaceStatusRetrieval)
770 m_fetchSteps.push_back(bind(&NfdStatus::fetchFaceStatusInformation, this));
771
772 if (m_needFibEnumerationRetrieval)
773 m_fetchSteps.push_back(bind(&NfdStatus::fetchFibEnumerationInformation, this));
774
Chengyu Fan30aa2072014-07-20 13:52:32 -0600775 if (m_needRibStatusRetrieval)
776 m_fetchSteps.push_back(bind(&NfdStatus::fetchRibStatusInformation, this));
777
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300778 if (m_needStrategyChoiceRetrieval)
779 m_fetchSteps.push_back(bind(&NfdStatus::fetchStrategyChoiceInformation, this));
780
781 if (m_isOutputXml)
782 m_fetchSteps.push_back(bind(&NfdStatus::printXmlFooter, this));
783
784 runNextStep();
jeraldabrahamb6dde382014-03-19 18:58:09 -0700785 m_face.processEvents();
786 }
787
788private:
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300789 void
790 printXmlHeader()
791 {
792 std::cout << "<?xml version=\"1.0\"?>";
793 std::cout << "<nfdStatus xmlns=\"ndn:/localhost/nfd/status/1\">";
794
795 runNextStep();
796 }
797
798 void
799 printXmlFooter()
800 {
801 std::cout << "</nfdStatus>";
802
803 runNextStep();
804 }
805
806 void
807 runNextStep()
808 {
809 if (m_fetchSteps.empty())
810 return;
811
812 function<void()> nextStep = m_fetchSteps.front();
813 m_fetchSteps.pop_front();
814 nextStep();
815 }
816
817private:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700818 std::string m_toolName;
819 bool m_needVersionRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300820 bool m_needChannelStatusRetrieval;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700821 bool m_needFaceStatusRetrieval;
822 bool m_needFibEnumerationRetrieval;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600823 bool m_needRibStatusRetrieval;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300824 bool m_needStrategyChoiceRetrieval;
825 bool m_isOutputXml;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700826 Face m_face;
827
828 shared_ptr<OBufferStream> m_buffer;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300829
830 std::deque<function<void()> > m_fetchSteps;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700831};
832
833}
834
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700835int main(int argc, char* argv[])
jeraldabrahamb6dde382014-03-19 18:58:09 -0700836{
837 int option;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700838 ndn::NfdStatus nfdStatus(argv[0]);
jeraldabrahamb6dde382014-03-19 18:58:09 -0700839
Chengyu Fan30aa2072014-07-20 13:52:32 -0600840 while ((option = getopt(argc, argv, "hvcfbrsxV")) != -1) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700841 switch (option) {
842 case 'h':
843 nfdStatus.usage();
Alexander Afanasyev60a7ba52014-03-23 11:23:06 -0700844 return 0;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700845 case 'v':
846 nfdStatus.enableVersionRetrieval();
847 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300848 case 'c':
849 nfdStatus.enableChannelStatusRetrieval();
850 break;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700851 case 'f':
852 nfdStatus.enableFaceStatusRetrieval();
853 break;
854 case 'b':
855 nfdStatus.enableFibEnumerationRetrieval();
856 break;
Chengyu Fan30aa2072014-07-20 13:52:32 -0600857 case 'r':
858 nfdStatus.enableRibStatusRetrieval();
859 break;
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300860 case 's':
861 nfdStatus.enableStrategyChoiceRetrieval();
862 break;
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600863 case 'x':
Alexander Afanasyev0417d2a2014-06-08 10:56:43 +0300864 nfdStatus.enableXmlOutput();
Chengyu Fan514ed5e2014-04-17 13:07:30 -0600865 break;
Alexander Afanasyevb47d5382014-05-05 14:35:03 -0700866 case 'V':
867 std::cout << NFD_VERSION_BUILD_STRING << std::endl;
868 return 0;
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700869 default:
jeraldabrahamb6dde382014-03-19 18:58:09 -0700870 nfdStatus.usage();
871 return 1;
jeraldabrahamb6dde382014-03-19 18:58:09 -0700872 }
873 }
874
875 try {
876 nfdStatus.fetchInformation();
877 }
Alexander Afanasyev7b7dfdd2014-03-21 13:57:54 -0700878 catch (std::exception& e) {
jeraldabrahamb6dde382014-03-19 18:58:09 -0700879 std::cerr << "ERROR: " << e.what() << std::endl;
880 return 2;
881 }
882
883 return 0;
884}