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 | |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 20 | #ifndef NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP |
| 21 | #define NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 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" |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 31 | #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" |
| 32 | #include "ns3/ndnSIM/NFD/daemon/table/strategy-choice.hpp" |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 33 | |
| 34 | namespace ndn { |
| 35 | namespace nfd { |
| 36 | class ControlParameters; |
| 37 | } // namespace nfd |
| 38 | } // namespace ndn |
| 39 | |
| 40 | namespace nfd { |
| 41 | namespace fw { |
| 42 | class Strategy; |
| 43 | } // namespace fw |
| 44 | } // namespace nfd |
| 45 | |
| 46 | |
| 47 | namespace ns3 { |
| 48 | namespace ndn { |
| 49 | |
| 50 | using ::ndn::nfd::ControlParameters; |
| 51 | |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 52 | /** |
| 53 | * @ingroup ndn-helpers |
| 54 | * @brief NFD Strategy Choice Helper (FIB) helper |
| 55 | * |
| 56 | * The Strategy Choice helper interacts with the Strategy Choice manager of NFD by sending |
| 57 | * special Interest commands to the manager in order to specify the desired per-name |
| 58 | * prefix forwarding strategy for one, more or all the nodes of a topology. |
| 59 | */ |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 60 | class StrategyChoiceHelper |
| 61 | { |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 62 | public: |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 63 | /** |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 64 | * @brief Install a built-in strategy @p strategy on @p node for @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 65 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 66 | static void |
| 67 | Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy); |
| 68 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 69 | /** |
| 70 | * @brief Install a built-in strategy @p strategy on nodes in @p c container for |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 71 | * @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 72 | */ |
| 73 | static void |
| 74 | Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy); |
| 75 | |
| 76 | /** |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 77 | * @brief Install a built-in strategy @p strategy on all nodes for @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 78 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 79 | static void |
| 80 | InstallAll(const Name& namePrefix, const Name& strategy); |
| 81 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 82 | /** |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 83 | * @brief Install a custom strategy on @p node for @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 84 | * @tparam Strategy Class name of the custom strategy |
| 85 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 86 | template<class Strategy> |
| 87 | static void |
| 88 | Install(Ptr<Node> node, const Name& namePrefix); |
| 89 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 90 | /** |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 91 | * @brief Install a custom strategy on nodes in @p c container for @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 92 | * @tparam Strategy Class name of the custom strategy |
| 93 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 94 | template<class Strategy> |
| 95 | static void |
| 96 | Install(const NodeContainer& c, const Name& namePrefix); |
| 97 | |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 98 | /** |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 99 | * @brief Install a custom strategy on all nodes for @p namePrefix namespace |
Alexander Afanasyev | c512dba | 2015-08-13 16:51:26 -0700 | [diff] [blame] | 100 | * @tparam Strategy Class name of the custom strategy |
| 101 | */ |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 102 | template<class Strategy> |
| 103 | static void |
| 104 | InstallAll(const Name& namePrefix); |
| 105 | |
| 106 | private: |
| 107 | static void |
| 108 | sendCommand(const ControlParameters& parameters, Ptr<Node> node); |
| 109 | }; |
| 110 | |
| 111 | template<class Strategy> |
| 112 | inline void |
| 113 | StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix) |
| 114 | { |
| 115 | Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>(); |
| 116 | NS_ASSERT(l3Protocol != nullptr); |
| 117 | NS_ASSERT(l3Protocol->getForwarder() != nullptr); |
| 118 | |
| 119 | nfd::Forwarder& forwarder = *l3Protocol->getForwarder(); |
| 120 | nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 121 | |
| 122 | if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) { |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame^] | 123 | strategyChoice.install(make_unique<Strategy>(ref(forwarder))); |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | Install(node, namePrefix, Strategy::STRATEGY_NAME); |
| 127 | } |
| 128 | |
| 129 | template<class Strategy> |
| 130 | inline void |
| 131 | StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix) |
| 132 | { |
| 133 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 134 | Install<Strategy>(*i, namePrefix); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | template<class Strategy> |
| 139 | inline void |
| 140 | StrategyChoiceHelper::InstallAll(const Name& namePrefix) |
| 141 | { |
| 142 | Install<Strategy>(NodeContainer::GetGlobal(), namePrefix); |
| 143 | } |
| 144 | |
| 145 | } // namespace ndn |
| 146 | } // namespace ns3 |
| 147 | |
Alexander Afanasyev | 5dee361 | 2015-08-25 16:09:04 -0700 | [diff] [blame] | 148 | #endif // NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP |