Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Junxiao Shi | b347b7f | 2017-07-23 14:01:58 +0000 | [diff] [blame] | 2 | /* |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California, |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 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. |
| 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 Shi | 3160a3f | 2018-01-09 21:25:15 +0000 | [diff] [blame] | 32 | #include "cs-module.hpp" |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 33 | #include "strategy-choice-module.hpp" |
| 34 | |
| 35 | #include <ndn-cxx/security/validator-null.hpp> |
| 36 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 37 | namespace nfd::tools::nfdc { |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 38 | |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 39 | void |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 40 | reportStatus(ExecuteContext& ctx, const StatusReportOptions& options) |
| 41 | { |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 42 | StatusReport report; |
| 43 | |
| 44 | if (options.wantForwarderGeneral) { |
Alexander Afanasyev | 01bbd09 | 2017-08-14 23:56:19 +0000 | [diff] [blame] | 45 | report.sections.push_back(make_unique<ForwarderGeneralModule>()); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | if (options.wantChannels) { |
| 49 | report.sections.push_back(make_unique<ChannelModule>()); |
| 50 | } |
| 51 | |
| 52 | if (options.wantFaces) { |
| 53 | report.sections.push_back(make_unique<FaceModule>()); |
| 54 | } |
| 55 | |
| 56 | if (options.wantFib) { |
| 57 | report.sections.push_back(make_unique<FibModule>()); |
| 58 | } |
| 59 | |
| 60 | if (options.wantRib) { |
| 61 | report.sections.push_back(make_unique<RibModule>()); |
| 62 | } |
| 63 | |
Junxiao Shi | 3160a3f | 2018-01-09 21:25:15 +0000 | [diff] [blame] | 64 | if (options.wantCs) { |
| 65 | report.sections.push_back(make_unique<CsModule>()); |
| 66 | } |
| 67 | |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 68 | if (options.wantStrategyChoice) { |
| 69 | report.sections.push_back(make_unique<StrategyChoiceModule>()); |
| 70 | } |
| 71 | |
Alexander Afanasyev | 01bbd09 | 2017-08-14 23:56:19 +0000 | [diff] [blame] | 72 | uint32_t code = report.collect(ctx.face, ctx.keyChain, |
Alexander Afanasyev | a158370 | 2020-06-03 13:55:45 -0400 | [diff] [blame] | 73 | ndn::security::getAcceptAllValidator(), |
Alexander Afanasyev | 01bbd09 | 2017-08-14 23:56:19 +0000 | [diff] [blame] | 74 | CommandOptions()); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 75 | if (code != 0) { |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 76 | ctx.exitCode = 1; |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 77 | // Give a simple error code for end user. |
| 78 | // Technical support personnel: |
| 79 | // 1. get the exact command from end user |
| 80 | // 2. code div 1000000 is zero-based section index |
| 81 | // 3. code mod 1000000 is a Controller.fetch error code |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 82 | ctx.err << "Error while collecting status report (" << code << ").\n"; |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | switch (options.output) { |
| 86 | case ReportFormat::XML: |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 87 | report.formatXml(ctx.out); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 88 | break; |
| 89 | case ReportFormat::TEXT: |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 90 | report.formatText(ctx.out); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 91 | break; |
| 92 | } |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 95 | /** \brief Single-section status command. |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 96 | */ |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 97 | static void |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 98 | reportStatusSingleSection(ExecuteContext& ctx, bool StatusReportOptions::*wantSection) |
| 99 | { |
| 100 | StatusReportOptions options; |
| 101 | options.*wantSection = true; |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 102 | reportStatus(ctx, options); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Davide Pesavento | aa9e3b2 | 2022-10-21 17:00:07 -0400 | [diff] [blame] | 105 | /** \brief The 'status report' command. |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 106 | */ |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 107 | static void |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 108 | reportStatusComprehensive(ExecuteContext& ctx) |
| 109 | { |
| 110 | StatusReportOptions options; |
| 111 | options.output = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT); |
Junxiao Shi | 3160a3f | 2018-01-09 21:25:15 +0000 | [diff] [blame] | 112 | options.wantForwarderGeneral = options.wantChannels = options.wantFaces = options.wantFib = |
| 113 | options.wantRib = options.wantCs = options.wantStrategyChoice = true; |
Junxiao Shi | 88a062d | 2017-01-26 03:10:05 +0000 | [diff] [blame] | 114 | reportStatus(ctx, options); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void |
| 118 | registerStatusCommands(CommandParser& parser) |
| 119 | { |
| 120 | CommandDefinition defStatusReport("status", "report"); |
| 121 | defStatusReport |
Davide Pesavento | 2a58815 | 2018-02-19 18:10:03 -0500 | [diff] [blame] | 122 | .setTitle("print full status report") |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 123 | .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES); |
| 124 | parser.addCommand(defStatusReport, &reportStatusComprehensive); |
| 125 | |
| 126 | CommandDefinition defStatusShow("status", "show"); |
| 127 | defStatusShow |
| 128 | .setTitle("print general status"); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 129 | parser.addCommand(defStatusShow, |
| 130 | std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantForwarderGeneral)); |
Davide Pesavento | d214744 | 2018-02-19 23:58:17 -0500 | [diff] [blame] | 131 | parser.addAlias("status", "show", ""); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 132 | |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 133 | CommandDefinition defChannelList("channel", "list"); |
| 134 | defChannelList |
| 135 | .setTitle("print channel list"); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 136 | parser.addCommand(defChannelList, |
| 137 | std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels)); |
Davide Pesavento | d214744 | 2018-02-19 23:58:17 -0500 | [diff] [blame] | 138 | parser.addAlias("channel", "list", ""); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 139 | |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 140 | CommandDefinition defFibList("fib", "list"); |
| 141 | defFibList |
| 142 | .setTitle("print FIB entries"); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 143 | parser.addCommand(defFibList, |
| 144 | std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib)); |
Davide Pesavento | d214744 | 2018-02-19 23:58:17 -0500 | [diff] [blame] | 145 | parser.addAlias("fib", "list", ""); |
Junxiao Shi | 3160a3f | 2018-01-09 21:25:15 +0000 | [diff] [blame] | 146 | |
| 147 | CommandDefinition defCsInfo("cs", "info"); |
| 148 | defCsInfo |
| 149 | .setTitle("print CS information"); |
Davide Pesavento | 412c982 | 2021-07-02 00:21:05 -0400 | [diff] [blame] | 150 | parser.addCommand(defCsInfo, |
| 151 | std::bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantCs)); |
Davide Pesavento | d214744 | 2018-02-19 23:58:17 -0500 | [diff] [blame] | 152 | parser.addAlias("cs", "info", ""); |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Davide Pesavento | e422f9e | 2022-06-03 01:30:23 -0400 | [diff] [blame] | 155 | } // namespace nfd::tools::nfdc |