Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
| 7 | * |
| 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
| 19 | |
| 20 | #ifndef NDN_STRATEGY_CHOICE_HELPER_H |
| 21 | #define NDN_STRATEGY_CHOICE_HELPER_H |
| 22 | |
| 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 24 | |
| 25 | #include "ns3/node.h" |
| 26 | #include "ns3/ptr.h" |
| 27 | #include "ns3/node-container.h" |
| 28 | |
| 29 | #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp" |
| 30 | #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp" |
| 31 | #include "ns3/ndnSIM/NFD/daemon/fw/available-strategies.hpp" |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace nfd { |
| 35 | class ControlParameters; |
| 36 | } // namespace nfd |
| 37 | } // namespace ndn |
| 38 | |
| 39 | namespace nfd { |
| 40 | namespace fw { |
| 41 | class Strategy; |
| 42 | } // namespace fw |
| 43 | } // namespace nfd |
| 44 | |
| 45 | |
| 46 | namespace ns3 { |
| 47 | namespace ndn { |
| 48 | |
| 49 | using ::ndn::nfd::ControlParameters; |
| 50 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 51 | /** |
| 52 | * @ingroup ndn-helpers |
| 53 | * @brief NFD Strategy Choice Helper (FIB) helper |
| 54 | * |
| 55 | * The Strategy Choice helper interacts with the Strategy Choice manager of NFD by sending |
| 56 | * special Interest commands to the manager in order to specify the desired per-name |
| 57 | * prefix forwarding strategy for one, more or all the nodes of a topology. |
| 58 | */ |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 59 | class StrategyChoiceHelper |
| 60 | { |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 61 | public: |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 62 | /** |
| 63 | * @brief Install a built-in strategy @p strategy on @p node for @namePrefix namespace |
| 64 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 65 | static void |
| 66 | Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy); |
| 67 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 68 | /** |
| 69 | * @brief Install a built-in strategy @p strategy on nodes in @p c container for |
| 70 | * @namePrefix namespace |
| 71 | */ |
| 72 | static void |
| 73 | Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy); |
| 74 | |
| 75 | /** |
| 76 | * @brief Install a built-in strategy @p strategy on all nodes for @namePrefix namespace |
| 77 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 78 | static void |
| 79 | InstallAll(const Name& namePrefix, const Name& strategy); |
| 80 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 81 | /** |
| 82 | * @brief Install a custom strategy on @p node for @namePrefix namespace |
| 83 | * @tparam Strategy Class name of the custom strategy |
| 84 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 85 | template<class Strategy> |
| 86 | static void |
| 87 | Install(Ptr<Node> node, const Name& namePrefix); |
| 88 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 89 | /** |
| 90 | * @brief Install a custom strategy on nodes in @p c container for @namePrefix namespace |
| 91 | * @tparam Strategy Class name of the custom strategy |
| 92 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 93 | template<class Strategy> |
| 94 | static void |
| 95 | Install(const NodeContainer& c, const Name& namePrefix); |
| 96 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 97 | /** |
| 98 | * @brief Install a custom strategy on all nodes for @namePrefix namespace |
| 99 | * @tparam Strategy Class name of the custom strategy |
| 100 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 101 | template<class Strategy> |
| 102 | static void |
| 103 | InstallAll(const Name& namePrefix); |
| 104 | |
| 105 | private: |
| 106 | static void |
| 107 | sendCommand(const ControlParameters& parameters, Ptr<Node> node); |
| 108 | }; |
| 109 | |
| 110 | template<class Strategy> |
| 111 | inline void |
| 112 | StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix) |
| 113 | { |
| 114 | Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>(); |
| 115 | NS_ASSERT(l3Protocol != nullptr); |
| 116 | NS_ASSERT(l3Protocol->getForwarder() != nullptr); |
| 117 | |
| 118 | nfd::Forwarder& forwarder = *l3Protocol->getForwarder(); |
| 119 | nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 120 | |
| 121 | if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) { |
| 122 | strategyChoice.install(make_shared<Strategy>(ref(forwarder))); |
| 123 | } |
| 124 | |
| 125 | Install(node, namePrefix, Strategy::STRATEGY_NAME); |
| 126 | } |
| 127 | |
| 128 | template<class Strategy> |
| 129 | inline void |
| 130 | StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix) |
| 131 | { |
| 132 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 133 | Install<Strategy>(*i, namePrefix); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | template<class Strategy> |
| 138 | inline void |
| 139 | StrategyChoiceHelper::InstallAll(const Name& namePrefix) |
| 140 | { |
| 141 | Install<Strategy>(NodeContainer::GetGlobal(), namePrefix); |
| 142 | } |
| 143 | |
| 144 | } // namespace ndn |
| 145 | } // namespace ns3 |
| 146 | |
| 147 | #endif // NDN_STRATEGY_CHOICE_HELPER_H |