tools: nfdc strategy set/unset commands
nfdc set-strategy and nfdc unset-strategy are deprecated.
refs #3865
Change-Id: I934cbfcd567ac7ee33381ae4baf00b668977a0aa
diff --git a/tools/nfdc/available-commands.cpp b/tools/nfdc/available-commands.cpp
index a1d22cb..0d4847f 100644
--- a/tools/nfdc/available-commands.cpp
+++ b/tools/nfdc/available-commands.cpp
@@ -58,8 +58,8 @@
{"unregister", "unregister a prefix", "route remove"},
{"create", "create a face", "face create"},
{"destroy", "destroy a face", "face destroy"},
- {"set-strategy", "set strategy choice on namespace", ""},
- {"unset-strategy", "unset strategy choice on namespace", ""},
+ {"set-strategy", "set strategy choice on namespace", "strategy set"},
+ {"unset-strategy", "unset strategy choice on namespace", "strategy unset"},
{"add-nexthop", "add FIB nexthop", "route add"},
{"remove-nexthop", "remove FIB nexthop", "route remove"}
};
diff --git a/tools/nfdc/strategy-choice-module.cpp b/tools/nfdc/strategy-choice-module.cpp
index e5fe584..9e0031f 100644
--- a/tools/nfdc/strategy-choice-module.cpp
+++ b/tools/nfdc/strategy-choice-module.cpp
@@ -43,6 +43,19 @@
.setTitle("show strategy choice of an entry")
.addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES);
parser.addCommand(defStrategyShow, &StrategyChoiceModule::show);
+
+ CommandDefinition defStrategySet("strategy", "set");
+ defStrategySet
+ .setTitle("set strategy choice for a name prefix")
+ .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES)
+ .addArg("strategy", ArgValueType::NAME, Required::YES, Positional::YES);
+ parser.addCommand(defStrategySet, &StrategyChoiceModule::set);
+
+ CommandDefinition defStrategyUnset("strategy", "unset");
+ defStrategyUnset
+ .setTitle("clear strategy choice at a name prefix")
+ .addArg("prefix", ArgValueType::NAME, Required::YES, Positional::YES);
+ parser.addCommand(defStrategyUnset, &StrategyChoiceModule::unset);
}
void
@@ -84,6 +97,58 @@
}
void
+StrategyChoiceModule::set(ExecuteContext& ctx)
+{
+ auto prefix = ctx.args.get<Name>("prefix");
+ auto strategy = ctx.args.get<Name>("strategy");
+
+ ctx.controller.start<ndn::nfd::StrategyChoiceSetCommand>(
+ ControlParameters().setName(prefix).setStrategy(strategy),
+ [&] (const ControlParameters& resp) {
+ ctx.out << "strategy-set ";
+ text::ItemAttributes ia;
+ ctx.out << ia("prefix") << resp.getName()
+ << ia("strategy") << resp.getStrategy() << '\n';
+ },
+ [&] (const ControlResponse& resp) {
+ if (resp.getCode() == 404) {
+ ctx.exitCode = 7;
+ ctx.err << "Unknown strategy: " << strategy << '\n';
+ ///\todo #3887 list available strategies
+ return;
+ }
+ ctx.makeCommandFailureHandler("setting strategy")(resp); // invoke general error handler
+ },
+ ctx.makeCommandOptions());
+
+ ctx.face.processEvents();
+}
+
+void
+StrategyChoiceModule::unset(ExecuteContext& ctx)
+{
+ auto prefix = ctx.args.get<Name>("prefix");
+
+ if (prefix.empty()) {
+ ctx.exitCode = 2;
+ ctx.err << "Unsetting default strategy is prohibited\n";
+ return;
+ }
+
+ ctx.controller.start<ndn::nfd::StrategyChoiceUnsetCommand>(
+ ControlParameters().setName(prefix),
+ [&] (const ControlParameters& resp) {
+ ctx.out << "strategy-unset ";
+ text::ItemAttributes ia;
+ ctx.out << ia("prefix") << resp.getName() << '\n';
+ },
+ ctx.makeCommandFailureHandler("unsetting strategy"),
+ ctx.makeCommandOptions());
+
+ ctx.face.processEvents();
+}
+
+void
StrategyChoiceModule::fetchStatus(Controller& controller,
const function<void()>& onSuccess,
const Controller::DatasetFailCallback& onFailure,
diff --git a/tools/nfdc/strategy-choice-module.hpp b/tools/nfdc/strategy-choice-module.hpp
index aabc3db..71fa9a2 100644
--- a/tools/nfdc/strategy-choice-module.hpp
+++ b/tools/nfdc/strategy-choice-module.hpp
@@ -56,6 +56,16 @@
static void
show(ExecuteContext& ctx);
+ /** \brief the 'strategy set' command
+ */
+ static void
+ set(ExecuteContext& ctx);
+
+ /** \brief the 'strategy unset' command
+ */
+ static void
+ unset(ExecuteContext& ctx);
+
void
fetchStatus(Controller& controller,
const function<void()>& onSuccess,