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 | |
| 51 | class StrategyChoiceHelper { |
| 52 | public: |
| 53 | static void |
| 54 | Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy); |
| 55 | |
| 56 | static void |
| 57 | Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy); |
| 58 | |
| 59 | static void |
| 60 | InstallAll(const Name& namePrefix, const Name& strategy); |
| 61 | |
| 62 | template<class Strategy> |
| 63 | static void |
| 64 | Install(Ptr<Node> node, const Name& namePrefix); |
| 65 | |
| 66 | template<class Strategy> |
| 67 | static void |
| 68 | Install(const NodeContainer& c, const Name& namePrefix); |
| 69 | |
| 70 | template<class Strategy> |
| 71 | static void |
| 72 | InstallAll(const Name& namePrefix); |
| 73 | |
| 74 | private: |
| 75 | static void |
| 76 | sendCommand(const ControlParameters& parameters, Ptr<Node> node); |
| 77 | }; |
| 78 | |
| 79 | template<class Strategy> |
| 80 | inline void |
| 81 | StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix) |
| 82 | { |
| 83 | Ptr<L3Protocol> l3Protocol = node->GetObject<L3Protocol>(); |
| 84 | NS_ASSERT(l3Protocol != nullptr); |
| 85 | NS_ASSERT(l3Protocol->getForwarder() != nullptr); |
| 86 | |
| 87 | nfd::Forwarder& forwarder = *l3Protocol->getForwarder(); |
| 88 | nfd::StrategyChoice& strategyChoice = forwarder.getStrategyChoice(); |
| 89 | |
| 90 | if (!strategyChoice.hasStrategy(Strategy::STRATEGY_NAME)) { |
| 91 | strategyChoice.install(make_shared<Strategy>(ref(forwarder))); |
| 92 | } |
| 93 | |
| 94 | Install(node, namePrefix, Strategy::STRATEGY_NAME); |
| 95 | } |
| 96 | |
| 97 | template<class Strategy> |
| 98 | inline void |
| 99 | StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix) |
| 100 | { |
| 101 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 102 | Install<Strategy>(*i, namePrefix); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | template<class Strategy> |
| 107 | inline void |
| 108 | StrategyChoiceHelper::InstallAll(const Name& namePrefix) |
| 109 | { |
| 110 | Install<Strategy>(NodeContainer::GetGlobal(), namePrefix); |
| 111 | } |
| 112 | |
| 113 | } // namespace ndn |
| 114 | } // namespace ns3 |
| 115 | |
| 116 | #endif // NDN_STRATEGY_CHOICE_HELPER_H |