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