status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2018, 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.
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"
28 #include "channel-module.hpp"
29 #include "face-module.hpp"
30 #include "fib-module.hpp"
31 #include "rib-module.hpp"
32 #include "cs-module.hpp"
34 
35 #include <ndn-cxx/security/validator-null.hpp>
36 
37 namespace nfd {
38 namespace tools {
39 namespace nfdc {
40 
41 void
43 {
44  StatusReport report;
45 
46  if (options.wantForwarderGeneral) {
47  report.sections.push_back(make_unique<ForwarderGeneralModule>());
48  }
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 
66  if (options.wantCs) {
67  report.sections.push_back(make_unique<CsModule>());
68  }
69 
70  if (options.wantStrategyChoice) {
71  report.sections.push_back(make_unique<StrategyChoiceModule>());
72  }
73 
74  uint32_t code = report.collect(ctx.face, ctx.keyChain,
75  ndn::security::v2::getAcceptAllValidator(),
76  CommandOptions());
77  if (code != 0) {
78  ctx.exitCode = 1;
79  // 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
84  ctx.err << "Error while collecting status report (" << code << ").\n";
85  }
86 
87  switch (options.output) {
88  case ReportFormat::XML:
89  report.formatXml(ctx.out);
90  break;
91  case ReportFormat::TEXT:
92  report.formatText(ctx.out);
93  break;
94  }
95 }
96 
99 static void
101 {
102  StatusReportOptions options;
103  options.*wantSection = true;
104  reportStatus(ctx, options);
105 }
106 
109 static void
111 {
112  StatusReportOptions options;
113  options.output = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
114  options.wantForwarderGeneral = options.wantChannels = options.wantFaces = options.wantFib =
115  options.wantRib = options.wantCs = options.wantStrategyChoice = true;
116  reportStatus(ctx, options);
117 }
118 
119 void
121 {
122  CommandDefinition defStatusReport("status", "report");
123  defStatusReport
124  .setTitle("print full status report")
126  parser.addCommand(defStatusReport, &reportStatusComprehensive);
127 
128  CommandDefinition defStatusShow("status", "show");
129  defStatusShow
130  .setTitle("print general status");
132  parser.addAlias("status", "show", "");
133 
134  CommandDefinition defChannelList("channel", "list");
135  defChannelList
136  .setTitle("print channel list");
137  parser.addCommand(defChannelList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels));
138  parser.addAlias("channel", "list", "");
139 
140  CommandDefinition defFibList("fib", "list");
141  defFibList
142  .setTitle("print FIB entries");
143  parser.addCommand(defFibList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib));
144  parser.addAlias("fib", "list", "");
145 
146  CommandDefinition defCsInfo("cs", "info");
147  defCsInfo
148  .setTitle("print CS information");
149  parser.addCommand(defCsInfo, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantCs));
150  parser.addAlias("cs", "info", "");
151 }
152 
153 } // namespace nfdc
154 } // namespace tools
155 } // namespace nfd
const CommandArguments & args
void registerStatusCommands(CommandParser &parser)
registers status commands
Definition: status.cpp:120
std::vector< unique_ptr< Module > > sections
modules through which status is collected
declares semantics of a command
std::ostream & out
output stream
context for command execution
void formatXml(std::ostream &os) const
print an XML report
uint32_t collect(Face &face, KeyChain &keyChain, Validator &validator, const CommandOptions &options)
collect status via chosen sections
void reportStatus(ExecuteContext &ctx, const StatusReportOptions &options)
collect a status report and write to stdout
Definition: status.cpp:42
T get(const std::string &key, const T &defaultValue=T()) const
CommandDefinition & setTitle(const std::string &title)
set one-line description
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
collects and prints NFD status report
CommandDefinition & addArg(const std::string &name, ArgValueType valueType, Required isRequired=Required::NO, Positional allowPositional=Positional::NO, const std::string &metavar="")
declare an argument
static void reportStatusComprehensive(ExecuteContext &ctx)
the &#39;status report&#39; command
Definition: status.cpp:110
static void reportStatusSingleSection(ExecuteContext &ctx, bool StatusReportOptions::*wantSection)
single-section status command
Definition: status.cpp:100
argument is required
std::ostream & err
error stream
CommandParser & addCommand(const CommandDefinition &def, const ExecuteCommand &execute, std::underlying_type< AvailableIn >::type modes=AVAILABLE_IN_ALL)
add an available command
argument is optional
CommandParser & addAlias(const std::string &noun, const std::string &verb, const std::string &verb2)
add an alias "noun verb2" to existing command "noun verb"
void formatText(std::ostream &os) const
print a text report
report format &#39;xml&#39; or &#39;text&#39;