blob: 604eaf2b2f6553db758965d2195316e85b263c94 [file] [log] [blame]
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -08001/* -*- 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"
Alexander Afanasyevc3c7f042015-08-21 11:38:00 -070031#include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp"
32#include "ns3/ndnSIM/NFD/daemon/table/strategy-choice.hpp"
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080033
34namespace ndn {
35namespace nfd {
36class ControlParameters;
37} // namespace nfd
38} // namespace ndn
39
40namespace nfd {
41namespace fw {
42class Strategy;
43} // namespace fw
44} // namespace nfd
45
46
47namespace ns3 {
48namespace ndn {
49
50using ::ndn::nfd::ControlParameters;
51
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080052/**
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 Afanasyevc512dba2015-08-13 16:51:26 -070060class StrategyChoiceHelper
61{
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080062public:
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070063 /**
64 * @brief Install a built-in strategy @p strategy on @p node for @namePrefix namespace
65 */
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080066 static void
67 Install(Ptr<Node> node, const Name& namePrefix, const Name& strategy);
68
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070069 /**
70 * @brief Install a built-in strategy @p strategy on nodes in @p c container for
71 * @namePrefix namespace
72 */
73 static void
74 Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy);
75
76 /**
77 * @brief Install a built-in strategy @p strategy on all nodes for @namePrefix namespace
78 */
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080079 static void
80 InstallAll(const Name& namePrefix, const Name& strategy);
81
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070082 /**
83 * @brief Install a custom strategy on @p node for @namePrefix namespace
84 * @tparam Strategy Class name of the custom strategy
85 */
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080086 template<class Strategy>
87 static void
88 Install(Ptr<Node> node, const Name& namePrefix);
89
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070090 /**
91 * @brief Install a custom strategy on nodes in @p c container for @namePrefix namespace
92 * @tparam Strategy Class name of the custom strategy
93 */
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080094 template<class Strategy>
95 static void
96 Install(const NodeContainer& c, const Name& namePrefix);
97
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070098 /**
99 * @brief Install a custom strategy on all nodes for @namePrefix namespace
100 * @tparam Strategy Class name of the custom strategy
101 */
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -0800102 template<class Strategy>
103 static void
104 InstallAll(const Name& namePrefix);
105
106private:
107 static void
108 sendCommand(const ControlParameters& parameters, Ptr<Node> node);
109};
110
111template<class Strategy>
112inline void
113StrategyChoiceHelper::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)) {
123 strategyChoice.install(make_shared<Strategy>(ref(forwarder)));
124 }
125
126 Install(node, namePrefix, Strategy::STRATEGY_NAME);
127}
128
129template<class Strategy>
130inline void
131StrategyChoiceHelper::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
138template<class Strategy>
139inline void
140StrategyChoiceHelper::InstallAll(const Name& namePrefix)
141{
142 Install<Strategy>(NodeContainer::GetGlobal(), namePrefix);
143}
144
145} // namespace ndn
146} // namespace ns3
147
148#endif // NDN_STRATEGY_CHOICE_HELPER_H