blob: a61defdcd54b83ef3a24857e094022cc21cc5736 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi88a062d2017-01-26 03:10:05 +00003 * Copyright (c) 2014-2017, Regents of the University of California,
Junxiao Shi38f4ce92016-08-04 10:01:52 +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
Junxiao Shiae889382016-11-23 04:52:51 +000026#include "legacy-status.hpp"
Junxiao Shi9f5b01d2016-08-05 03:54:28 +000027#include "core/version.hpp"
Junxiao Shi38f4ce92016-08-04 10:01:52 +000028
Junxiao Shi8c39bf02016-08-28 23:54:13 +000029#include <boost/program_options.hpp>
30
Junxiao Shi38f4ce92016-08-04 10:01:52 +000031namespace nfd {
32namespace tools {
Junxiao Shi331ade72016-08-19 14:07:19 +000033namespace nfdc {
Junxiao Shi38f4ce92016-08-04 10:01:52 +000034
Junxiao Shi38f4ce92016-08-04 10:01:52 +000035static void
36showUsage(std::ostream& os, const boost::program_options::options_description& cmdOptions)
37{
38 os << "Usage: nfd-status [options]\n\n"
39 << "Show NFD version and status information.\n\n"
40 << cmdOptions;
41}
42
Junxiao Shiae889382016-11-23 04:52:51 +000043/** \brief parse legacy nfd-status command line, and show usage if necessary
Junxiao Shi38f4ce92016-08-04 10:01:52 +000044 * \return if first item is -1, caller should retrieve and display StatusReport;
45 * otherwise, caller should immediately exit with the specified exit code
46 */
Junxiao Shiae889382016-11-23 04:52:51 +000047static std::tuple<int, StatusReportOptions>
Junxiao Shi88a062d2017-01-26 03:10:05 +000048parseCommandLine(ExecuteContext& ctx, const std::vector<std::string>& args)
Junxiao Shi38f4ce92016-08-04 10:01:52 +000049{
Junxiao Shiae889382016-11-23 04:52:51 +000050 StatusReportOptions options;
Junxiao Shi38f4ce92016-08-04 10:01:52 +000051
52 namespace po = boost::program_options;
Junxiao Shiae889382016-11-23 04:52:51 +000053 po::options_description cmdOptions("StatusReportOptions");
Junxiao Shi38f4ce92016-08-04 10:01:52 +000054 cmdOptions.add_options()
55 ("help,h", "print this help message")
56 ("version,V", "show program version")
57 ("general,v", po::bool_switch(&options.wantForwarderGeneral), "show general status")
58 ("channels,c", po::bool_switch(&options.wantChannels), "show channels")
59 ("faces,f", po::bool_switch(&options.wantFaces), "show faces")
60 ("fib,b", po::bool_switch(&options.wantFib), "show FIB entries")
61 ("rib,r", po::bool_switch(&options.wantRib), "show RIB routes")
62 ("sc,s", po::bool_switch(&options.wantStrategyChoice), "show strategy choice entries")
63 ("xml,x", "output as XML instead of text (implies -vcfbrs)");
64 po::variables_map vm;
65 try {
Junxiao Shi2f741322016-08-29 00:53:18 +000066 po::store(po::command_line_parser(args).options(cmdOptions).run(), vm);
67 po::notify(vm);
Junxiao Shi38f4ce92016-08-04 10:01:52 +000068 }
69 catch (const po::error& e) {
Junxiao Shi88a062d2017-01-26 03:10:05 +000070 ctx.err << e.what() << "\n";
71 showUsage(ctx.err, cmdOptions);
Junxiao Shi38f4ce92016-08-04 10:01:52 +000072 return std::make_tuple(2, options);
73 }
Junxiao Shi38f4ce92016-08-04 10:01:52 +000074
75 if (vm.count("help") > 0) {
Junxiao Shi88a062d2017-01-26 03:10:05 +000076 showUsage(ctx.out, cmdOptions);
Junxiao Shi38f4ce92016-08-04 10:01:52 +000077 return std::make_tuple(0, options);
78 }
79 if (vm.count("version") > 0) {
Junxiao Shi88a062d2017-01-26 03:10:05 +000080 ctx.out << "nfd-status " << NFD_VERSION_BUILD_STRING << "\n";
Junxiao Shi38f4ce92016-08-04 10:01:52 +000081 return std::make_tuple(0, options);
82 }
83
84 if (vm.count("xml") > 0) {
Junxiao Shi8c39bf02016-08-28 23:54:13 +000085 options.output = ReportFormat::XML;
Junxiao Shi38f4ce92016-08-04 10:01:52 +000086 }
Junxiao Shi8c39bf02016-08-28 23:54:13 +000087 if (options.output == ReportFormat::XML ||
Junxiao Shi38f4ce92016-08-04 10:01:52 +000088 (!options.wantForwarderGeneral && !options.wantChannels && !options.wantFaces &&
89 !options.wantFib && !options.wantRib && !options.wantStrategyChoice)) {
90 options.wantForwarderGeneral = options.wantChannels = options.wantFaces =
91 options.wantFib = options.wantRib = options.wantStrategyChoice = true;
92 }
93
94 return std::make_tuple(-1, options);
95}
96
Junxiao Shiae889382016-11-23 04:52:51 +000097/** \brief the 'legacy-nfd-status' command
98 */
Junxiao Shi88a062d2017-01-26 03:10:05 +000099static void
Junxiao Shiae889382016-11-23 04:52:51 +0000100legacyNfdStatus(ExecuteContext& ctx)
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000101{
Junxiao Shiae889382016-11-23 04:52:51 +0000102 auto args = ctx.args.get<std::vector<std::string>>("args");
103
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000104 int exitCode = -1;
Junxiao Shiae889382016-11-23 04:52:51 +0000105 StatusReportOptions options;
Junxiao Shi88a062d2017-01-26 03:10:05 +0000106 std::tie(exitCode, options) = parseCommandLine(ctx, args);
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000107 if (exitCode >= 0) {
Junxiao Shi88a062d2017-01-26 03:10:05 +0000108 ctx.exitCode = exitCode;
109 return;
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000110 }
111
Junxiao Shi88a062d2017-01-26 03:10:05 +0000112 reportStatus(ctx, options);
Junxiao Shiae889382016-11-23 04:52:51 +0000113}
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000114
Junxiao Shiae889382016-11-23 04:52:51 +0000115void
116registerLegacyStatusCommand(CommandParser& parser)
117{
118 CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
119 defLegacyNfdStatus
120 .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
121 parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP);
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000122}
123
Junxiao Shi331ade72016-08-19 14:07:19 +0000124} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000125} // namespace tools
126} // namespace nfd