status.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "status.hpp"
28 #include "channel-module.hpp"
29 #include "face-module.hpp"
30 #include "fib-module.hpp"
31 #include "rib-module.hpp"
33 
34 #include <ndn-cxx/security/validator-null.hpp>
35 
36 namespace nfd {
37 namespace tools {
38 namespace nfdc {
39 
40 int
42 {
43  unique_ptr<Validator> validator = make_unique<ndn::ValidatorNull>();
44  CommandOptions ctrlOptions;
45 
46  StatusReport report;
47 
48  if (options.wantForwarderGeneral) {
49  auto nfdIdCollector = make_unique<NfdIdCollector>(std::move(validator));
50  auto forwarderGeneralModule = make_unique<ForwarderGeneralModule>();
51  forwarderGeneralModule->setNfdIdCollector(*nfdIdCollector);
52  report.sections.push_back(std::move(forwarderGeneralModule));
53  validator = std::move(nfdIdCollector);
54  }
55 
56  if (options.wantChannels) {
57  report.sections.push_back(make_unique<ChannelModule>());
58  }
59 
60  if (options.wantFaces) {
61  report.sections.push_back(make_unique<FaceModule>());
62  }
63 
64  if (options.wantFib) {
65  report.sections.push_back(make_unique<FibModule>());
66  }
67 
68  if (options.wantRib) {
69  report.sections.push_back(make_unique<RibModule>());
70  }
71 
72  if (options.wantStrategyChoice) {
73  report.sections.push_back(make_unique<StrategyChoiceModule>());
74  }
75 
76  uint32_t code = report.collect(ctx.face, ctx.keyChain, *validator, ctrlOptions);
77  if (code != 0) {
78  // Give a simple error code for end user.
79  // Technical support personnel:
80  // 1. get the exact command from end user
81  // 2. code div 1000000 is zero-based section index
82  // 3. code mod 1000000 is a Controller.fetch error code
83  std::cerr << "Error while collecting status report (" << code << ").\n";
84  return 1;
85  }
86 
87  switch (options.output) {
88  case ReportFormat::XML:
89  report.formatXml(std::cout);
90  break;
91  case ReportFormat::TEXT:
92  report.formatText(std::cout);
93  break;
94  }
95  return 0;
96 }
97 
100 static int
102 {
103  StatusReportOptions options;
104  options.*wantSection = true;
105  return reportStatus(ctx, options);
106 }
107 
110 static int
112 {
113  StatusReportOptions options;
114  options.output = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
115  options.wantForwarderGeneral = options.wantChannels = options.wantFaces =
116  options.wantFib = options.wantRib = options.wantStrategyChoice = true;
117  return reportStatus(ctx, options);
118 }
119 
120 void
122 {
123  CommandDefinition defStatusReport("status", "report");
124  defStatusReport
125  .setTitle("print NFD status report")
127  parser.addCommand(defStatusReport, &reportStatusComprehensive);
128 
129  CommandDefinition defStatusShow("status", "show");
130  defStatusShow
131  .setTitle("print general status");
133  parser.addAlias("status", "show", "list");
134 
135  CommandDefinition defFaceList("face", "list");
136  defFaceList
137  .setTitle("print face list");
138  parser.addCommand(defFaceList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFaces));
139 
140  CommandDefinition defChannelList("channel", "list");
141  defChannelList
142  .setTitle("print channel list");
143  parser.addCommand(defChannelList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantChannels));
144 
145  CommandDefinition defStrategyList("strategy", "list");
146  defStrategyList
147  .setTitle("print strategy choices");
149 
150  CommandDefinition defFibList("fib", "list");
151  defFibList
152  .setTitle("print FIB entries");
153  parser.addCommand(defFibList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantFib));
154 
155  CommandDefinition defRouteList("route", "list");
156  defRouteList
157  .setTitle("print RIB entries");
158  parser.addCommand(defRouteList, bind(&reportStatusSingleSection, _1, &StatusReportOptions::wantRib));
159 }
160 
161 } // namespace nfdc
162 } // namespace tools
163 } // namespace nfd
void registerStatusCommands(CommandParser &parser)
registers status commands
Definition: status.cpp:121
std::vector< unique_ptr< Module > > sections
modules through which status is collected
declares semantics of a command
context for command execution
static int reportStatusSingleSection(ExecuteContext &ctx, bool StatusReportOptions::*wantSection)
single-section status command
Definition: status.cpp:101
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
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...
collects and prints NFD status report
int reportStatus(ExecuteContext &ctx, const StatusReportOptions &options)
collect a status report and write to stdout
Definition: status.cpp:41
const CommandArguments & args
CommandDefinition & addArg(const std::string &name, ArgValueType valueType, Required isRequired=Required::NO, Positional allowPositional=Positional::NO, const std::string &metavar="")
declare an argument
argument is required
CommandParser & addCommand(const CommandDefinition &def, const ExecuteCommand &execute, std::underlying_type< AvailableIn >::type modes=AVAILABLE_IN_ALL)
add an available command
static int reportStatusComprehensive(ExecuteContext &ctx)
the 'status report' command
Definition: status.cpp:111
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 'xml' or 'text'