blob: 01222c8be9149503540cc774948e11eb25f8e9c4 [file] [log] [blame]
Junxiao Shiae889382016-11-23 04:52:51 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Junxiao Shib347b7f2017-07-23 14:01:58 +00002/*
Junxiao Shi88a062d2017-01-26 03:10:05 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shiae889382016-11-23 04:52:51 +00004 * 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.
10 *
11 * 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
26#include "status.hpp"
27#include "forwarder-general-module.hpp"
28#include "channel-module.hpp"
29#include "face-module.hpp"
30#include "fib-module.hpp"
31#include "rib-module.hpp"
32#include "strategy-choice-module.hpp"
33
34#include <ndn-cxx/security/validator-null.hpp>
35
36namespace nfd {
37namespace tools {
38namespace nfdc {
39
Junxiao Shi88a062d2017-01-26 03:10:05 +000040void
Junxiao Shiae889382016-11-23 04:52:51 +000041reportStatus(ExecuteContext& ctx, const StatusReportOptions& options)
42{
Junxiao Shiae889382016-11-23 04:52:51 +000043 StatusReport report;
44
45 if (options.wantForwarderGeneral) {
Alexander Afanasyev01bbd092017-08-14 23:56:19 +000046 report.sections.push_back(make_unique<ForwarderGeneralModule>());
Junxiao Shiae889382016-11-23 04:52:51 +000047 }
48
49 if (options.wantChannels) {
50 report.sections.push_back(make_unique<ChannelModule>());
51 }
52
53 if (options.wantFaces) {
54 report.sections.push_back(make_unique<FaceModule>());
55 }
56
57 if (options.wantFib) {
58 report.sections.push_back(make_unique<FibModule>());
59 }
60
61 if (options.wantRib) {
62 report.sections.push_back(make_unique<RibModule>());
63 }
64
65 if (options.wantStrategyChoice) {
66 report.sections.push_back(make_unique<StrategyChoiceModule>());
67 }
68
Alexander Afanasyev01bbd092017-08-14 23:56:19 +000069 uint32_t code = report.collect(ctx.face, ctx.keyChain,
70 ndn::security::v2::getAcceptAllValidator(),
71 CommandOptions());
Junxiao Shiae889382016-11-23 04:52:51 +000072 if (code != 0) {
Junxiao Shi88a062d2017-01-26 03:10:05 +000073 ctx.exitCode = 1;
Junxiao Shiae889382016-11-23 04:52:51 +000074 // Give a simple error code for end user.
75 // Technical support personnel:
76 // 1. get the exact command from end user
77 // 2. code div 1000000 is zero-based section index
78 // 3. code mod 1000000 is a Controller.fetch error code
Junxiao Shi88a062d2017-01-26 03:10:05 +000079 ctx.err << "Error while collecting status report (" << code << ").\n";
Junxiao Shiae889382016-11-23 04:52:51 +000080 }
81
82 switch (options.output) {
83 case ReportFormat::XML:
Junxiao Shi88a062d2017-01-26 03:10:05 +000084 report.formatXml(ctx.out);
Junxiao Shiae889382016-11-23 04:52:51 +000085 break;
86 case ReportFormat::TEXT:
Junxiao Shi88a062d2017-01-26 03:10:05 +000087 report.formatText(ctx.out);
Junxiao Shiae889382016-11-23 04:52:51 +000088 break;
89 }
Junxiao Shiae889382016-11-23 04:52:51 +000090}
91
92/** \brief single-section status command
93 */
Junxiao Shi88a062d2017-01-26 03:10:05 +000094static void
Junxiao Shiae889382016-11-23 04:52:51 +000095reportStatusSingleSection(ExecuteContext& ctx, bool StatusReportOptions::*wantSection)
96{
97 StatusReportOptions options;
98 options.*wantSection = true;
Junxiao Shi88a062d2017-01-26 03:10:05 +000099 reportStatus(ctx, options);
Junxiao Shiae889382016-11-23 04:52:51 +0000100}
101
102/** \brief the 'status report' command
103 */
Junxiao Shi88a062d2017-01-26 03:10:05 +0000104static void
Junxiao Shiae889382016-11-23 04:52:51 +0000105reportStatusComprehensive(ExecuteContext& ctx)
106{
107 StatusReportOptions options;
108 options.output = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
109 options.wantForwarderGeneral = options.wantChannels = options.wantFaces =
110 options.wantFib = options.wantRib = options.wantStrategyChoice = true;
Junxiao Shi88a062d2017-01-26 03:10:05 +0000111 reportStatus(ctx, options);
Junxiao Shiae889382016-11-23 04:52:51 +0000112}
113
114void
115registerStatusCommands(CommandParser& parser)
116{
117 CommandDefinition defStatusReport("status", "report");
118 defStatusReport
119 .setTitle("print NFD status report")
120 .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
121 parser.addCommand(defStatusReport, &reportStatusComprehensive);
122
123 CommandDefinition defStatusShow("status", "show");
124 defStatusShow
125 .setTitle("print general status");
126 parser.addCommand(defStatusShow, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantForwarderGeneral));
127 parser.addAlias("status", "show", "list");
128
Junxiao Shiae889382016-11-23 04:52:51 +0000129 CommandDefinition defChannelList("channel", "list");
130 defChannelList
131 .setTitle("print channel list");
132 parser.addCommand(defChannelList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels));
133
Junxiao Shiae889382016-11-23 04:52:51 +0000134 CommandDefinition defFibList("fib", "list");
135 defFibList
136 .setTitle("print FIB entries");
137 parser.addCommand(defFibList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib));
Junxiao Shiae889382016-11-23 04:52:51 +0000138}
139
140} // namespace nfdc
141} // namespace tools
142} // namespace nfd