blob: 39f9b870d40402482371a1e2b73b902fb92ef335 [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
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070020#ifndef NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP
21#define NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080022
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 /**
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070064 * @brief Install a built-in strategy @p strategy on @p node for @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070065 */
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
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070071 * @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070072 */
73 static void
74 Install(const NodeContainer& c, const Name& namePrefix, const Name& strategy);
75
76 /**
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070077 * @brief Install a built-in strategy @p strategy on all nodes for @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070078 */
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 /**
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070083 * @brief Install a custom strategy on @p node for @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070084 * @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 /**
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070091 * @brief Install a custom strategy on nodes in @p c container for @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -070092 * @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 /**
Alexander Afanasyev5dee3612015-08-25 16:09:04 -070099 * @brief Install a custom strategy on all nodes for @p namePrefix namespace
Alexander Afanasyevc512dba2015-08-13 16:51:26 -0700100 * @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
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700119 if (!Strategy::canCreate(Strategy::getStrategyName())) {
120 Strategy::template registerType<Strategy>();
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -0800121 }
122
Spyridon Mastorakisf6d32852017-09-27 20:28:52 -0700123 Install(node, namePrefix, Strategy::getStrategyName());
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -0800124}
125
126template<class Strategy>
127inline void
128StrategyChoiceHelper::Install(const NodeContainer& c, const Name& namePrefix)
129{
130 for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
131 Install<Strategy>(*i, namePrefix);
132 }
133}
134
135template<class Strategy>
136inline void
137StrategyChoiceHelper::InstallAll(const Name& namePrefix)
138{
139 Install<Strategy>(NodeContainer::GetGlobal(), namePrefix);
140}
141
142} // namespace ndn
143} // namespace ns3
144
Alexander Afanasyev5dee3612015-08-25 16:09:04 -0700145#endif // NDNSIM_HELPER_NDN_STRATEGY_CHOICE_HELPER_HPP