blob: 1237a15f5fdcb4d691ddf7fb44dc1704ea7957d9 [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * 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.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * 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.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * 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 **/
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070019
Alexander Afanasyeva91aab42016-09-08 15:47:38 -070020#ifndef NDNSIM_HELPER_NDN_STACK_HELPER_HPP
21#define NDNSIM_HELPER_NDN_STACK_HELPER_HPP
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070022
Spyridon Mastorakis53e922f2014-10-17 17:29:26 -070023#include "ns3/ndnSIM/model/ndn-common.hpp"
24
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/ptr.h"
26#include "ns3/object-factory.h"
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -080027#include "ns3/node.h"
28#include "ns3/node-container.h"
29
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080030#include "ndn-fib-helper.hpp"
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080031#include "ndn-strategy-choice-helper.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070032
spirosmastorakis34eed982016-11-02 15:20:50 -070033namespace nfd {
34namespace cs {
35class Policy;
36} // namespace cs
37} // namespace nfd
38
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070039namespace ns3 {
40
41class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070042
43namespace ndn {
44
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080045class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070046
47/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080048 * @ingroup ndn
49 * @defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070050 */
51/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080052 * @ingroup ndn-helpers
53 * @brief Helper class to install NDN stack and configure its parameters
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070054 */
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080055class StackHelper : boost::noncopyable {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070056public:
57 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070058 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070059 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080061
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070062 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070063 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070064 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070066
67 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070068 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070069 */
70 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
72 const std::string& attr2 = "", const std::string& value2 = "",
73 const std::string& attr3 = "", const std::string& value3 = "",
74 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080075
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080076 /**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080077 * @brief Set maximum size for NFD's Content Store (in number of packets)
78 */
79 void
80 setCsSize(size_t maxSize);
81
82 /**
spirosmastorakis34eed982016-11-02 15:20:50 -070083 * @brief Set the cache replacement policy for NFD's Content Store
84 */
85 void
86 setPolicy(const std::string& policy);
87
88 /**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080089 * @brief Set ndnSIM 1.0 content store implementation and its attributes
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080090 * @param contentStoreClass string, representing class of the content store
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080091 * @note ndnSIM 1.0 content store implementation have limited support for Interest selectors
92 * Do not use these implementations if your scenario relies on proper selector processing.
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080093 */
94 void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080095 SetOldContentStore(const std::string& contentStoreClass, const std::string& attr1 = "",
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080096 const std::string& value1 = "", const std::string& attr2 = "",
97 const std::string& value2 = "", const std::string& attr3 = "",
98 const std::string& value3 = "", const std::string& attr4 = "",
99 const std::string& value4 = "");
100
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700101 typedef Callback<shared_ptr<Face>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
102 FaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800103
104 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
106 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800107 *
108 * It is possible to set up several callbacks for different NetDevice types.
109 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
111 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800112 */
113 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700114 AddFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800115
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700116 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800117 * @brief Update callback to create and configure instance of the face, based on supplied
118 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700119 *
120 * It is possible to set up several callbacks for different NetDevice types.
121 *
122 * Using this method, it is possible to override Face creation for PointToPointNetDevices
123 */
124 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700125 UpdateFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700126
127 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800128 * @brief Remove callback to create and configure instance of the face, based on supplied
129 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700130 */
131 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700132 RemoveFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700133
134 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800135 * \brief Install Ndn stack on the node
136 *
137 * This method will assert if called on a node that already has Ndn object
138 * installed on it
139 *
140 * \param nodeName The name of the node on which to install the stack.
141 *
142 * \returns list of installed faces in the form of a smart pointer
143 * to NdnFaceContainer object
144 */
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500145 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700147
148 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700149 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700150 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700151 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700152 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800153 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700154 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700155 *
156 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700157 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700158 */
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500159 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700161
162 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700163 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700164 *
165 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700166 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800167 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700168 * \param c NodeContainer that holds the set of nodes on which to install the
169 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700170 *
171 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700172 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700173 */
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500174 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700176
177 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700178 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700179 *
180 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700181 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700182 */
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500183 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800184 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700185
Spyridon Mastorakis588fd102014-11-20 19:50:02 -0800186 /**
187 * \brief Set flag indicating necessity to install default routes in FIB
188 */
189 void
190 SetDefaultRoutes(bool needSet);
191
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800192 static KeyChain&
193 getKeyChain();
194
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700195 /**
196 * \brief Update Ndn stack on a given node (Add faces for new devices)
197 *
198 * \param node The node on which to update the stack.
199 */
200 void
201 Update(Ptr<Node> node);
202
203 /**
204 *\brief Update Ndn stack on given nodes (Add faces for new devices)
205 *
206 * \param c The nodes on which to update the stack.
207 */
208 void
209 Update(const NodeContainer& c);
210
211 /**
212 *\brief Update Ndn stack on a given node name (Add faces for new devices)
213 *
214 * \param nodeName The name of the node on which to update the stack.
215 */
216 void
217 Update(const std::string& nodeName);
218
219 /**
220 *\brief Update Ndn stack on all the nodes (Add faces for new devices)
221 */
222 void
223 UpdateAll();
224
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800225 /**
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800226 * \brief Disable Strategy Choice Manager
227 */
228 void
229 disableStrategyChoiceManager();
230
231 /**
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700232 * \brief Disable Forwarder Status Manager
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800233 */
234 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700235 disableForwarderStatusManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800236
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -0700237 /**
238 * @brief Set face metric of all faces connected through PointToPoint channel to channel latency
239 */
240 static void
241 SetLinkDelayAsFaceMetric();
242
Alexander Afanasyev6995bb72019-02-23 15:53:26 -0500243 static void
244 ProcessWarmupEvents();
245
Alexander Afanasyev11453142011-11-25 16:13:33 -0800246private:
Alexander Afanasyevdc3c3a32019-02-17 20:17:32 -0500247 void
248 doInstall(Ptr<Node> node) const;
249
250private:
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700251 shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800252 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800253
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700254 shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800255 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
256 Ptr<NetDevice> netDevice) const;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700257 shared_ptr<Face>
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700258 createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800259
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700260 bool m_isForwarderStatusManagerDisabled;
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800261 bool m_isStrategyChoiceManagerDisabled;
262
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800263public:
264 void
265 setCustomNdnCxxClocks();
266
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800267private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700268 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700269 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800270
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800271 bool m_needSetDefaultRoutes;
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800272 size_t m_maxCsSize;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800273
spirosmastorakis34eed982016-11-02 15:20:50 -0700274 typedef std::function<std::unique_ptr<nfd::cs::Policy>()> PolicyCreationCallback;
275 PolicyCreationCallback m_csPolicyCreationFunc;
276
277 std::map<std::string, PolicyCreationCallback> m_csPolicies;
278
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700279 typedef std::list<std::pair<TypeId, FaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700280 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700281};
282
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700283} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700284} // namespace ns3
285
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700286#endif // NDNSIM_HELPER_NDN_STACK_HELPER_HPP