Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 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 | #include "ndn-strategy-choice-helper.hpp" |
| 21 | |
| 22 | #include "ns3/log.h" |
| 23 | |
| 24 | #include "ndn-stack-helper.hpp" |
| 25 | |
| 26 | namespace ns3 { |
| 27 | namespace ndn { |
| 28 | |
| 29 | NS_LOG_COMPONENT_DEFINE("ndn.StrategyChoiceHelper"); |
| 30 | |
| 31 | void |
| 32 | StrategyChoiceHelper::sendCommand(const ControlParameters& parameters, Ptr<Node> node) |
| 33 | { |
| 34 | NS_LOG_DEBUG("Strategy choice command was initialized"); |
| 35 | Block encodedParameters(parameters.wireEncode()); |
| 36 | |
| 37 | Name commandName("/localhost/nfd/strategy-choice"); |
| 38 | commandName.append("set"); |
| 39 | commandName.append(encodedParameters); |
| 40 | |
| 41 | shared_ptr<Interest> command(make_shared<Interest>(commandName)); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 42 | command->setCanBePrefix(false); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 43 | StackHelper::getKeyChain().sign(*command); |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 44 | |
| 45 | Ptr<L3Protocol> l3protocol = node->GetObject<L3Protocol>(); |
| 46 | l3protocol->injectInterest(*command); |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void |
| 50 | StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy) |
| 51 | { |
| 52 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 53 | Install(*i, namePrefix, strategy); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | StrategyChoiceHelper::Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy) |
| 59 | { |
| 60 | ControlParameters parameters; |
| 61 | parameters.setName(namePrefix); |
| 62 | NS_LOG_DEBUG("Node ID: " << node->GetId() << " with forwarding strategy " << strategy); |
| 63 | parameters.setStrategy(strategy); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 64 | |
| 65 | Simulator::ScheduleWithContext(node->GetId(), Seconds(0), |
| 66 | &StrategyChoiceHelper::sendCommand, parameters, node); |
Alexander Afanasyev | 6995bb7 | 2019-02-23 15:53:26 -0500 | [diff] [blame^] | 67 | StackHelper::ProcessWarmupEvents(); |
Spyridon Mastorakis | 592fcba | 2014-11-23 22:48:03 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void |
| 71 | StrategyChoiceHelper::InstallAll(const Name& namePrefix, const Name& strategy) |
| 72 | { |
| 73 | Install(NodeContainer::GetGlobal(), namePrefix, strategy); |
| 74 | } |
| 75 | |
| 76 | } // namespace ndn |
| 77 | |
| 78 | } // namespace ns |