blob: 5eaa5819c7261903e4ccb5bb8e312cebde44f7c4 [file] [log] [blame]
Junxiao Shi38f4ce92016-08-04 10:01:52 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2016, 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
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 Shi2f741322016-08-29 00:53:18 +000048parseCommandLine(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) {
70 std::cerr << e.what() << "\n";
71 showUsage(std::cerr, cmdOptions);
72 return std::make_tuple(2, options);
73 }
Junxiao Shi38f4ce92016-08-04 10:01:52 +000074
75 if (vm.count("help") > 0) {
76 showUsage(std::cout, cmdOptions);
77 return std::make_tuple(0, options);
78 }
79 if (vm.count("version") > 0) {
80 std::cout << "nfd-status " << NFD_VERSION_BUILD_STRING << "\n";
81 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 */
99static int
100legacyNfdStatus(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 Shi2f741322016-08-29 00:53:18 +0000106 std::tie(exitCode, options) = parseCommandLine(args);
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000107 if (exitCode >= 0) {
108 return exitCode;
109 }
110
Junxiao Shiae889382016-11-23 04:52:51 +0000111 return reportStatus(ctx, options);
112}
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000113
Junxiao Shiae889382016-11-23 04:52:51 +0000114void
115registerLegacyStatusCommand(CommandParser& parser)
116{
117 CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
118 defLegacyNfdStatus
119 .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
120 parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP);
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000121}
122
Junxiao Shi331ade72016-08-19 14:07:19 +0000123} // namespace nfdc
Junxiao Shi38f4ce92016-08-04 10:01:52 +0000124} // namespace tools
125} // namespace nfd