Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +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 | |
| 26 | #include "available-commands.hpp" |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 27 | #include "help.hpp" |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 28 | #include "status-report.hpp" |
| 29 | #include "status-main.hpp" |
| 30 | #include "legacy-nfdc.hpp" |
| 31 | |
| 32 | namespace nfd { |
| 33 | namespace tools { |
| 34 | namespace nfdc { |
| 35 | |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 36 | static int |
| 37 | statusReport(ExecuteContext& ctx) |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 38 | { |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 39 | ReportFormat fmt = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 40 | switch (fmt) { |
| 41 | case ReportFormat::XML: |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 42 | return statusMain(std::vector<std::string>{"-x"}, ctx.face, ctx.keyChain); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 43 | case ReportFormat::TEXT: |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 44 | return statusMain(std::vector<std::string>{}, ctx.face, ctx.keyChain); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 45 | } |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 46 | BOOST_ASSERT(false); |
| 47 | return 1; |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 50 | static int |
Junxiao Shi | 3d1eb09 | 2016-09-14 19:20:20 +0000 | [diff] [blame] | 51 | statusList(ExecuteContext& ctx, const std::string& option) |
| 52 | { |
| 53 | return statusMain(std::vector<std::string>{option}, ctx.face, ctx.keyChain); |
| 54 | } |
| 55 | |
| 56 | static int |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 57 | legacyNfdStatus(ExecuteContext& ctx) |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 58 | { |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 59 | auto args = ctx.args.get<std::vector<std::string>>("args"); |
| 60 | return statusMain(args, ctx.face, ctx.keyChain); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void |
| 64 | registerCommands(CommandParser& parser) |
| 65 | { |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 66 | registerHelpCommand(parser); |
| 67 | |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 68 | CommandDefinition defStatusReport("status", "report"); |
| 69 | defStatusReport |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 70 | .setTitle("print NFD status report") |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 71 | .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES); |
| 72 | parser.addCommand(defStatusReport, &statusReport); |
| 73 | |
Junxiao Shi | 3d1eb09 | 2016-09-14 19:20:20 +0000 | [diff] [blame] | 74 | struct StatusCommandDefinition |
| 75 | { |
| 76 | std::string noun; |
| 77 | std::string verb; |
| 78 | std::string legacyOption; |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 79 | std::string title; |
Junxiao Shi | 3d1eb09 | 2016-09-14 19:20:20 +0000 | [diff] [blame] | 80 | }; |
| 81 | const std::vector<StatusCommandDefinition> statusCommands{ |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 82 | {"status", "show", "-v", "print general status"}, |
| 83 | {"face", "list", "-f", "print face list"}, |
| 84 | {"channel", "list", "-c", "print channel list"}, |
| 85 | {"strategy", "list", "-s", "print strategy choices"}, |
| 86 | {"fib", "list", "-b", "print FIB entries"}, |
| 87 | {"route", "list", "-r", "print RIB routes"} |
Junxiao Shi | 3d1eb09 | 2016-09-14 19:20:20 +0000 | [diff] [blame] | 88 | }; |
| 89 | for (const StatusCommandDefinition& scd : statusCommands) { |
| 90 | CommandDefinition def(scd.noun, scd.verb); |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 91 | def.setTitle(scd.title); |
Junxiao Shi | 3d1eb09 | 2016-09-14 19:20:20 +0000 | [diff] [blame] | 92 | parser.addCommand(def, bind(&statusList, _1, scd.legacyOption)); |
| 93 | } |
| 94 | parser.addAlias("status", "show", "list"); |
| 95 | |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 96 | CommandDefinition defLegacyNfdStatus("legacy-nfd-status", ""); |
| 97 | defLegacyNfdStatus |
| 98 | .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES); |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 99 | parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 100 | |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 101 | struct LegacyNfdcCommandDefinition |
| 102 | { |
| 103 | std::string subcommand; |
| 104 | std::string title; |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 105 | }; |
Junxiao Shi | 6c13562 | 2016-11-21 14:30:33 +0000 | [diff] [blame] | 106 | const std::vector<LegacyNfdcCommandDefinition> legacyNfdcSubcommands{ |
| 107 | {"register", "register a prefix"}, |
| 108 | {"unregister", "unregister a prefix"}, |
| 109 | {"create", "create a face"}, |
| 110 | {"destroy", "destroy a face"}, |
| 111 | {"set-strategy", "set strategy choice on namespace"}, |
| 112 | {"unset-strategy", "unset strategy choice on namespace"}, |
| 113 | {"add-nexthop", "add FIB nexthop"}, |
| 114 | {"remove-nexthop", "remove FIB nexthop"} |
| 115 | }; |
| 116 | for (const LegacyNfdcCommandDefinition& lncd : legacyNfdcSubcommands) { |
| 117 | CommandDefinition def(lncd.subcommand, ""); |
| 118 | def.setTitle(lncd.title); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 119 | def.addArg("args", ArgValueType::ANY, Required::NO, Positional::YES); |
Junxiao Shi | 737c43c | 2016-09-14 02:51:44 +0000 | [diff] [blame] | 120 | parser.addCommand(def, &legacyNfdcMain); |
Junxiao Shi | 64567bb | 2016-09-04 16:00:27 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
| 124 | } // namespace nfdc |
| 125 | } // namespace tools |
| 126 | } // namespace nfd |