blob: a338b1dadb3fc86e1012cfd05ad3fb12a84226b1 [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/*
Davide Pesavento412c9822021-07-02 00:21:05 -04003 * Copyright (c) 2014-2021, 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"
Junxiao Shi3160a3f2018-01-09 21:25:15 +000032#include "cs-module.hpp"
Junxiao Shiae889382016-11-23 04:52:51 +000033#include "strategy-choice-module.hpp"
34
35#include <ndn-cxx/security/validator-null.hpp>
36
37namespace nfd {
38namespace tools {
39namespace nfdc {
40
Junxiao Shi88a062d2017-01-26 03:10:05 +000041void
Junxiao Shiae889382016-11-23 04:52:51 +000042reportStatus(ExecuteContext& ctx, const StatusReportOptions& options)
43{
Junxiao Shiae889382016-11-23 04:52:51 +000044 StatusReport report;
45
46 if (options.wantForwarderGeneral) {
Alexander Afanasyev01bbd092017-08-14 23:56:19 +000047 report.sections.push_back(make_unique<ForwarderGeneralModule>());
Junxiao Shiae889382016-11-23 04:52:51 +000048 }
49
50 if (options.wantChannels) {
51 report.sections.push_back(make_unique<ChannelModule>());
52 }
53
54 if (options.wantFaces) {
55 report.sections.push_back(make_unique<FaceModule>());
56 }
57
58 if (options.wantFib) {
59 report.sections.push_back(make_unique<FibModule>());
60 }
61
62 if (options.wantRib) {
63 report.sections.push_back(make_unique<RibModule>());
64 }
65
Junxiao Shi3160a3f2018-01-09 21:25:15 +000066 if (options.wantCs) {
67 report.sections.push_back(make_unique<CsModule>());
68 }
69
Junxiao Shiae889382016-11-23 04:52:51 +000070 if (options.wantStrategyChoice) {
71 report.sections.push_back(make_unique<StrategyChoiceModule>());
72 }
73
Alexander Afanasyev01bbd092017-08-14 23:56:19 +000074 uint32_t code = report.collect(ctx.face, ctx.keyChain,
Alexander Afanasyeva1583702020-06-03 13:55:45 -040075 ndn::security::getAcceptAllValidator(),
Alexander Afanasyev01bbd092017-08-14 23:56:19 +000076 CommandOptions());
Junxiao Shiae889382016-11-23 04:52:51 +000077 if (code != 0) {
Junxiao Shi88a062d2017-01-26 03:10:05 +000078 ctx.exitCode = 1;
Junxiao Shiae889382016-11-23 04:52:51 +000079 // Give a simple error code for end user.
80 // Technical support personnel:
81 // 1. get the exact command from end user
82 // 2. code div 1000000 is zero-based section index
83 // 3. code mod 1000000 is a Controller.fetch error code
Junxiao Shi88a062d2017-01-26 03:10:05 +000084 ctx.err << "Error while collecting status report (" << code << ").\n";
Junxiao Shiae889382016-11-23 04:52:51 +000085 }
86
87 switch (options.output) {
88 case ReportFormat::XML:
Junxiao Shi88a062d2017-01-26 03:10:05 +000089 report.formatXml(ctx.out);
Junxiao Shiae889382016-11-23 04:52:51 +000090 break;
91 case ReportFormat::TEXT:
Junxiao Shi88a062d2017-01-26 03:10:05 +000092 report.formatText(ctx.out);
Junxiao Shiae889382016-11-23 04:52:51 +000093 break;
94 }
Junxiao Shiae889382016-11-23 04:52:51 +000095}
96
97/** \brief single-section status command
98 */
Junxiao Shi88a062d2017-01-26 03:10:05 +000099static void
Junxiao Shiae889382016-11-23 04:52:51 +0000100reportStatusSingleSection(ExecuteContext& ctx, bool StatusReportOptions::*wantSection)
101{
102 StatusReportOptions options;
103 options.*wantSection = true;
Junxiao Shi88a062d2017-01-26 03:10:05 +0000104 reportStatus(ctx, options);
Junxiao Shiae889382016-11-23 04:52:51 +0000105}
106
107/** \brief the 'status report' command
108 */
Junxiao Shi88a062d2017-01-26 03:10:05 +0000109static void
Junxiao Shiae889382016-11-23 04:52:51 +0000110reportStatusComprehensive(ExecuteContext& ctx)
111{
112 StatusReportOptions options;
113 options.output = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
Junxiao Shi3160a3f2018-01-09 21:25:15 +0000114 options.wantForwarderGeneral = options.wantChannels = options.wantFaces = options.wantFib =
115 options.wantRib = options.wantCs = options.wantStrategyChoice = true;
Junxiao Shi88a062d2017-01-26 03:10:05 +0000116 reportStatus(ctx, options);
Junxiao Shiae889382016-11-23 04:52:51 +0000117}
118
119void
120registerStatusCommands(CommandParser& parser)
121{
122 CommandDefinition defStatusReport("status", "report");
123 defStatusReport
Davide Pesavento2a588152018-02-19 18:10:03 -0500124 .setTitle("print full status report")
Junxiao Shiae889382016-11-23 04:52:51 +0000125 .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
126 parser.addCommand(defStatusReport, &reportStatusComprehensive);
127
128 CommandDefinition defStatusShow("status", "show");
129 defStatusShow
130 .setTitle("print general status");
Davide Pesavento412c9822021-07-02 00:21:05 -0400131 parser.addCommand(defStatusShow,
132 std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantForwarderGeneral));
Davide Pesaventod2147442018-02-19 23:58:17 -0500133 parser.addAlias("status", "show", "");
Junxiao Shiae889382016-11-23 04:52:51 +0000134
Junxiao Shiae889382016-11-23 04:52:51 +0000135 CommandDefinition defChannelList("channel", "list");
136 defChannelList
137 .setTitle("print channel list");
Davide Pesavento412c9822021-07-02 00:21:05 -0400138 parser.addCommand(defChannelList,
139 std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels));
Davide Pesaventod2147442018-02-19 23:58:17 -0500140 parser.addAlias("channel", "list", "");
Junxiao Shiae889382016-11-23 04:52:51 +0000141
Junxiao Shiae889382016-11-23 04:52:51 +0000142 CommandDefinition defFibList("fib", "list");
143 defFibList
144 .setTitle("print FIB entries");
Davide Pesavento412c9822021-07-02 00:21:05 -0400145 parser.addCommand(defFibList,
146 std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib));
Davide Pesaventod2147442018-02-19 23:58:17 -0500147 parser.addAlias("fib", "list", "");
Junxiao Shi3160a3f2018-01-09 21:25:15 +0000148
149 CommandDefinition defCsInfo("cs", "info");
150 defCsInfo
151 .setTitle("print CS information");
Davide Pesavento412c9822021-07-02 00:21:05 -0400152 parser.addCommand(defCsInfo,
153 std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantCs));
Davide Pesaventod2147442018-02-19 23:58:17 -0500154 parser.addAlias("cs", "info", "");
Junxiao Shiae889382016-11-23 04:52:51 +0000155}
156
157} // namespace nfdc
158} // namespace tools
159} // namespace nfd