blob: b0a118a7f09b9c1faa887bcf511095e131724c2d [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"
27#include "status-report.hpp"
28#include "status-main.hpp"
29#include "legacy-nfdc.hpp"
30
31namespace nfd {
32namespace tools {
33namespace nfdc {
34
Junxiao Shi737c43c2016-09-14 02:51:44 +000035static int
36statusReport(ExecuteContext& ctx)
Junxiao Shi64567bb2016-09-04 16:00:27 +000037{
Junxiao Shi737c43c2016-09-14 02:51:44 +000038 ReportFormat fmt = ctx.args.get<ReportFormat>("format", ReportFormat::TEXT);
Junxiao Shi64567bb2016-09-04 16:00:27 +000039 switch (fmt) {
40 case ReportFormat::XML:
Junxiao Shi737c43c2016-09-14 02:51:44 +000041 return statusMain(std::vector<std::string>{"-x"}, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000042 case ReportFormat::TEXT:
Junxiao Shi737c43c2016-09-14 02:51:44 +000043 return statusMain(std::vector<std::string>{}, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000044 }
Junxiao Shi737c43c2016-09-14 02:51:44 +000045 BOOST_ASSERT(false);
46 return 1;
Junxiao Shi64567bb2016-09-04 16:00:27 +000047}
48
Junxiao Shi737c43c2016-09-14 02:51:44 +000049static int
Junxiao Shi3d1eb092016-09-14 19:20:20 +000050statusList(ExecuteContext& ctx, const std::string& option)
51{
52 return statusMain(std::vector<std::string>{option}, ctx.face, ctx.keyChain);
53}
54
55static int
Junxiao Shi737c43c2016-09-14 02:51:44 +000056legacyNfdStatus(ExecuteContext& ctx)
Junxiao Shi64567bb2016-09-04 16:00:27 +000057{
Junxiao Shi737c43c2016-09-14 02:51:44 +000058 auto args = ctx.args.get<std::vector<std::string>>("args");
59 return statusMain(args, ctx.face, ctx.keyChain);
Junxiao Shi64567bb2016-09-04 16:00:27 +000060}
61
62void
63registerCommands(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 Shi3d1eb092016-09-14 19:20:20 +000070 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 Shi64567bb2016-09-04 16:00:27 +000090 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 Shi737c43c2016-09-14 02:51:44 +0000108 parser.addCommand(def, &legacyNfdcMain);
Junxiao Shi64567bb2016-09-04 16:00:27 +0000109 }
110}
111
112} // namespace nfdc
113} // namespace tools
114} // namespace nfd