helper: StrategyChoiceHelper
diff --git a/helper/ndn-stack-helper.hpp b/helper/ndn-stack-helper.hpp
index bc9ff3e..77d3b5c 100644
--- a/helper/ndn-stack-helper.hpp
+++ b/helper/ndn-stack-helper.hpp
@@ -31,6 +31,7 @@
#include "ndn-face-container.hpp"
#include "ndn-fib-helper.hpp"
+#include "ndn-strategy-choice-helper.hpp"
namespace ns3 {
diff --git a/helper/ndn-strategy-choice-helper.cpp b/helper/ndn-strategy-choice-helper.cpp
new file mode 100644
index 0000000..e6b6ea6
--- /dev/null
+++ b/helper/ndn-strategy-choice-helper.cpp
@@ -0,0 +1,75 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2014 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#include "ndn-strategy-choice-helper.hpp"
+
+#include "ns3/log.h"
+
+#include "ndn-stack-helper.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+NS_LOG_COMPONENT_DEFINE("ndn.StrategyChoiceHelper");
+
+void
+StrategyChoiceHelper::sendCommand(const ControlParameters& parameters, Ptr<Node> node)
+{
+ NS_LOG_DEBUG("Strategy choice command was initialized");
+ Block encodedParameters(parameters.wireEncode());
+
+ Name commandName("/localhost/nfd/strategy-choice");
+ commandName.append("set");
+ commandName.append(encodedParameters);
+
+ shared_ptr<Interest> command(make_shared<Interest>(commandName));
+ StackHelper::getKeyChain().signWithSha256(*command);
+ Ptr<L3Protocol> L3protocol = node->GetObject<L3Protocol>();
+ auto strategyChoiceManager = L3protocol->getStrategyChoiceManager();
+ strategyChoiceManager->onStrategyChoiceRequest(*command);
+ NS_LOG_DEBUG("Forwarding strategy installed in node " << node->GetId());
+}
+
+void
+StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy)
+{
+ for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
+ Install(*i, namePrefix, strategy);
+ }
+}
+
+void
+StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy)
+{
+ ControlParameters parameters;
+ parameters.setName(namePrefix);
+ NS_LOG_DEBUG("Node ID: " << node->GetId() << " with forwarding strategy " << strategy);
+ parameters.setStrategy(strategy);
+ sendCommand(parameters, node);
+}
+
+void
+StrategyChoiceHelper::InstallAll(const Name& namePrefix, const Name& strategy)
+{
+ Install(NodeContainer::GetGlobal(), namePrefix, strategy);
+}
+
+} // namespace ndn
+
+} // namespace ns
diff --git a/helper/ndn-strategy-choice-helper.hpp b/helper/ndn-strategy-choice-helper.hpp
new file mode 100644
index 0000000..8e7e32f
--- /dev/null
+++ b/helper/ndn-strategy-choice-helper.hpp
@@ -0,0 +1,116 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NDN_STRATEGY_CHOICE_HELPER_H
+#define NDN_STRATEGY_CHOICE_HELPER_H
+
+#include "ns3/ndnSIM/model/ndn-common.hpp"
+
+#include "ns3/node.h"
+#include "ns3/ptr.h"
+#include "ns3/node-container.h"
+
+#include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
+#include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp"
+#include "ns3/ndnSIM/NFD/daemon/fw/available-strategies.hpp"
+
+namespace ndn {
+namespace nfd {
+class ControlParameters;
+} // namespace nfd
+} // namespace ndn
+
+namespace nfd {
+namespace fw {
+class Strategy;
+} // namespace fw
+} // namespace nfd
+
+
+namespace ns3 {
+namespace ndn {
+
+using ::ndn::nfd::ControlParameters;
+
+class StrategyChoiceHelper {
+public:
+ static void
+ Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy);
+
+ static void
+ Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
+
+ static void
+ InstallAll(const Name& namePrefix, const Name& strategy);
+
+ template<class Strategy>
+ static void
+ Install(Ptr<Node> node, const Name& namePrefix);
+
+ template<class Strategy>
+ static void
+ Install(const NodeContainer& c, const Name& namePrefix);
+
+ template<class Strategy>
+ static void
+ InstallAll(const Name& namePrefix);
+
+private:
+ static void
+ sendCommand(const ControlParameters& parameters, Ptr<Node> node);
+};
+
+template<class Strategy>
+inline void
+StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix)
+{
+ Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>();
+ NS_ASSERT(l3Protocol != nullptr);
+ NS_ASSERT(l3Protocol->getForwarder() != nullptr);
+
+ nfd::Forwarder& forwarder = *l3Protocol->getForwarder();
+ nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice();
+
+ if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) {
+ strategyChoice.install(make_shared<Strategy>(ref(forwarder)));
+ }
+
+ Install(node, namePrefix, Strategy::STRATEGY_NAME);
+}
+
+template<class Strategy>
+inline void
+StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix)
+{
+ for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
+ Install<Strategy>(*i, namePrefix);
+ }
+}
+
+template<class Strategy>
+inline void
+StrategyChoiceHelper::InstallAll(const Name& namePrefix)
+{
+ Install<Strategy>(NodeContainer::GetGlobal(), namePrefix);
+}
+
+} // namespace ndn
+} // namespace ns3
+
+#endif // NDN_STRATEGY_CHOICE_HELPER_H
diff --git a/wscript b/wscript
index c46c59d..e7012d6 100644
--- a/wscript
+++ b/wscript
@@ -90,7 +90,8 @@
'utils/*/*'])
module.source += bld.path.ant_glob(['helper/ndn-face-container.cpp',
'helper/ndn-stack-helper.cpp',
- 'helper/ndn-fib-helper.cpp'])
+ 'helper/ndn-fib-helper.cpp',
+ 'helper/ndn-strategy-choice-helper.cpp'])
module.full_headers = [p.path_from(bld.path) for p in bld.path.ant_glob(
['%s/**/*.hpp' % dir for dir in module_dirs])]