blob: 3b6a39382716fa3802e674f96b4a5131d6519304 [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
35static void
36statusReport(const CommandArguments& ca)
37{
38 int res = 1;
39 ReportFormat fmt = ca.get<ReportFormat>("format", ReportFormat::TEXT);
40 switch (fmt) {
41 case ReportFormat::XML:
42 res = statusMain(std::vector<std::string>{"-x"});
43 break;
44 case ReportFormat::TEXT:
45 res = statusMain(std::vector<std::string>{});
46 break;
47 }
48 exit(res);
49}
50
51static void
52legacyNfdStatus(const CommandArguments& ca)
53{
54 std::vector<std::string> args = ca.get<std::vector<std::string>>("args");
55 int res = statusMain(args);
56 exit(res);
57}
58
59static void
60legacyNfdc(const std::string& subcommand, const CommandArguments& ca)
61{
62 std::vector<std::string> args = ca.get<std::vector<std::string>>("args");
63 int res = legacyNfdcMain(subcommand, args);
64 exit(res);
65}
66
67void
68registerCommands(CommandParser& parser)
69{
70 CommandDefinition defStatusReport("status", "report");
71 defStatusReport
72 .addArg("format", ArgValueType::REPORT_FORMAT, Required::NO, Positional::YES);
73 parser.addCommand(defStatusReport, &statusReport);
74
75 CommandDefinition defLegacyNfdStatus("legacy-nfd-status", "");
76 defLegacyNfdStatus
77 .addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
78 parser.addCommand(defLegacyNfdStatus, &legacyNfdStatus);
79
80 const std::vector<std::string> legacyNfdcSubcommands{
81 "register",
82 "unregister",
83 "create",
84 "destroy",
85 "set-strategy",
86 "unset-strategy",
87 "add-nexthop",
88 "remove-nexthop"
89 };
90 for (const std::string& subcommand : legacyNfdcSubcommands) {
91 CommandDefinition def(subcommand, "");
92 def.addArg("args", ArgValueType::ANY, Required::NO, Positional::YES);
93 parser.addCommand(def, bind(&legacyNfdc, subcommand, _1));
94 }
95}
96
97} // namespace nfdc
98} // namespace tools
99} // namespace nfd