Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 1 | /* -*- 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 Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 26 | #include "legacy-status.hpp" |
Junxiao Shi | 9f5b01d | 2016-08-05 03:54:28 +0000 | [diff] [blame] | 27 | #include "core/version.hpp" |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 28 | |
Junxiao Shi | 8c39bf0 | 2016-08-28 23:54:13 +0000 | [diff] [blame] | 29 | #include <boost/program_options.hpp> |
| 30 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 31 | namespace nfd { |
| 32 | namespace tools { |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 33 | namespace nfdc { |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 34 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 35 | static void |
| 36 | showUsage(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 Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 43 | /** \brief parse legacy nfd-status command line, and show usage if necessary |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 44 | * \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 Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 47 | static std::tuple<int, StatusReportOptions> |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 48 | parseCommandLine(const std::vector<std::string>& args) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 49 | { |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 50 | StatusReportOptions options; |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 51 | |
| 52 | namespace po = boost::program_options; |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 53 | po::options_description cmdOptions("StatusReportOptions"); |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 54 | 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 Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 66 | po::store(po::command_line_parser(args).options(cmdOptions).run(), vm); |
| 67 | po::notify(vm); |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 68 | } |
| 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 Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 74 | |
| 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 Shi | 8c39bf0 | 2016-08-28 23:54:13 +0000 | [diff] [blame] | 85 | options.output = ReportFormat::XML; |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 86 | } |
Junxiao Shi | 8c39bf0 | 2016-08-28 23:54:13 +0000 | [diff] [blame] | 87 | if (options.output == ReportFormat::XML || |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 88 | (!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 Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 97 | /** \brief the 'legacy-nfd-status' command |
| 98 | */ |
| 99 | static int |
| 100 | legacyNfdStatus(ExecuteContext& ctx) |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 101 | { |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 102 | auto args = ctx.args.get<std::vector<std::string>>("args"); |
| 103 | |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 104 | int exitCode = -1; |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 105 | StatusReportOptions options; |
Junxiao Shi | 2f74132 | 2016-08-29 00:53:18 +0000 | [diff] [blame] | 106 | std::tie(exitCode, options) = parseCommandLine(args); |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 107 | if (exitCode >= 0) { |
| 108 | return exitCode; |
| 109 | } |
| 110 | |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 111 | return reportStatus(ctx, options); |
| 112 | } |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 113 | |
Junxiao Shi | ae88938 | 2016-11-23 04:52:51 +0000 | [diff] [blame^] | 114 | void |
| 115 | registerLegacyStatusCommand(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 Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Junxiao Shi | 331ade7 | 2016-08-19 14:07:19 +0000 | [diff] [blame] | 123 | } // namespace nfdc |
Junxiao Shi | 38f4ce9 | 2016-08-04 10:01:52 +0000 | [diff] [blame] | 124 | } // namespace tools |
| 125 | } // namespace nfd |