blob: 3cd540aeb1ee922f9de89e474d895fad8e3b6d02 [file] [log] [blame]
Junxiao Shi64567bb2016-09-04 16:00:27 +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
26#include "available-commands.hpp"
Junxiao Shi6c135622016-11-21 14:30:33 +000027#include "help.hpp"
Junxiao Shi64567bb2016-09-04 16:00:27 +000028#include "status-report.hpp"
29#include "status-main.hpp"
30#include "legacy-nfdc.hpp"
31
32namespace nfd {
33namespace tools {
34namespace nfdc {
35
Junxiao Shi737c43c2016-09-14 02:51:44 +000036static int
37statusReport(ExecuteContext& ctx)
Junxiao Shi64567bb2016-09-04 16:00:27 +000038{
Junxiao Shi737c43c2016-09-14 02:51:44 +000039 ReportFormat fmt = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
Junxiao Shi64567bb2016-09-04 16:00:27 +000040 switch (fmt) {
41 case ReportFormat::XML:
Junxiao Shi737c43c2016-09-14 02:51:44 +000042 return statusMain(std::vector<std::string>{"-x"}, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000043 case ReportFormat::TEXT:
Junxiao Shi737c43c2016-09-14 02:51:44 +000044 return statusMain(std::vector<std::string>{}, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000045 }
Junxiao Shi737c43c2016-09-14 02:51:44 +000046 BOOST_ASSERT(false);
47 return 1;
Junxiao Shi64567bb2016-09-04 16:00:27 +000048}
49
Junxiao Shi737c43c2016-09-14 02:51:44 +000050static int
Junxiao Shi3d1eb092016-09-14 19:20:20 +000051statusList(ExecuteContext& ctx, const std::string& option)
52{
53 return statusMain(std::vector<std::string>{option}, ctx.face, ctx.keyChain);
54}
55
56static int
Junxiao Shi737c43c2016-09-14 02:51:44 +000057legacyNfdStatus(ExecuteContext& ctx)
Junxiao Shi64567bb2016-09-04 16:00:27 +000058{
Junxiao Shi737c43c2016-09-14 02:51:44 +000059 auto args = ctx.args.get<std::vector<std::string>>("args");
60 return statusMain(args, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000061}
62
63void
64registerCommands(CommandParser& parser)
65{
Junxiao Shi6c135622016-11-21 14:30:33 +000066 registerHelpCommand(parser);
67
Junxiao Shi64567bb2016-09-04 16:00:27 +000068 CommandDefinition defStatusReport("status", "report");
69 defStatusReport
Junxiao Shi6c135622016-11-21 14:30:33 +000070 .setTitle("print NFD status report")
Junxiao Shi64567bb2016-09-04 16:00:27 +000071 .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
72 parser.addCommand(defStatusReport, &statusReport);
73
Junxiao Shi3d1eb092016-09-14 19:20:20 +000074 struct StatusCommandDefinition
75 {
76 std::string noun;
77 std::string verb;
78 std::string legacyOption;
Junxiao Shi6c135622016-11-21 14:30:33 +000079 std::string title;
Junxiao Shi3d1eb092016-09-14 19:20:20 +000080 };
81 const std::vector<StatusCommandDefinition> statusCommands{
Junxiao Shi6c135622016-11-21 14:30:33 +000082 {"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 Shi3d1eb092016-09-14 19:20:20 +000088 };
89 for (const StatusCommandDefinition& scd : statusCommands) {
90 CommandDefinition def(scd.noun, scd.verb);
Junxiao Shi6c135622016-11-21 14:30:33 +000091 def.setTitle(scd.title);
Junxiao Shi3d1eb092016-09-14 19:20:20 +000092 parser.addCommand(def, bind(&statusList, _1, scd.legacyOption));
93 }
94 parser.addAlias("status", "show", "list");
95
Junxiao Shi64567bb2016-09-04 16:00:27 +000096 CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
97 defLegacyNfdStatus
98 .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
Junxiao Shi6c135622016-11-21 14:30:33 +000099 parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus, AVAILABLE_IN_ALL & ~AVAILABLE_IN_HELP);
Junxiao Shi64567bb2016-09-04 16:00:27 +0000100
Junxiao Shi6c135622016-11-21 14:30:33 +0000101 struct LegacyNfdcCommandDefinition
102 {
103 std::string subcommand;
104 std::string title;
Junxiao Shi64567bb2016-09-04 16:00:27 +0000105 };
Junxiao Shi6c135622016-11-21 14:30:33 +0000106 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 Shi64567bb2016-09-04 16:00:27 +0000119 def.addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
Junxiao Shi737c43c2016-09-14 02:51:44 +0000120 parser.addCommand(def, &legacyNfdcMain);
Junxiao Shi64567bb2016-09-04 16:00:27 +0000121 }
122}
123
124} // namespace nfdc
125} // namespace tools
126} // namespace nfd