blob: 2d2b8fb09f3dcac354336c220e8c8ea2216af230 [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
30#include "ndn-face-container.hpp"
Spyridon Mastorakis588fd102014-11-20 19:50:02 -080031#include "ndn-fib-helper.hpp"
Spyridon Mastorakis592fcba2014-11-23 22:48:03 -080032#include "ndn-strategy-choice-helper.hpp"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070033
spirosmastorakis34eed982016-11-02 15:20:50 -070034namespace nfd {
35namespace cs {
36class Policy;
37} // namespace cs
38} // namespace nfd
39
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070040namespace ns3 {
41
42class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043
44namespace ndn {
45
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080046class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070047
48/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080049 * @ingroup ndn
50 * @defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070051 */
52/**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080053 * @ingroup ndn-helpers
54 * @brief Helper class to install NDN stack and configure its parameters
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070055 */
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080056class StackHelper : boost::noncopyable {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070057public:
58 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070059 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070060 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080062
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070064 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070065 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067
68 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070069 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070070 */
71 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
73 const std::string& attr2 = "", const std::string& value2 = "",
74 const std::string& attr3 = "", const std::string& value3 = "",
75 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080076
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080077 /**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080078 * @brief Set maximum size for NFD's Content Store (in number of packets)
79 */
80 void
81 setCsSize(size_t maxSize);
82
83 /**
spirosmastorakis34eed982016-11-02 15:20:50 -070084 * @brief Set the cache replacement policy for NFD's Content Store
85 */
86 void
87 setPolicy(const std::string& policy);
88
89 /**
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080090 * @brief Set ndnSIM 1.0 content store implementation and its attributes
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080091 * @param contentStoreClass string, representing class of the content store
Spyridon Mastorakis460f57c2014-12-17 00:44:14 -080092 * @note ndnSIM 1.0 content store implementation have limited support for Interest selectors
93 * Do not use these implementations if your scenario relies on proper selector processing.
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080094 */
95 void
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080096 SetOldContentStore(const std::string& contentStoreClass, const std::string& attr1 = "",
Spyridon Mastorakisde1f7732014-12-05 22:43:34 -080097 const std::string& value1 = "", const std::string& attr2 = "",
98 const std::string& value2 = "", const std::string& attr3 = "",
99 const std::string& value3 = "", const std::string& attr4 = "",
100 const std::string& value4 = "");
101
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700102 typedef Callback<shared_ptr<Face>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
103 FaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800104
105 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
107 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800108 *
109 * It is possible to set up several callbacks for different NetDevice types.
110 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800111 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
112 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800113 */
114 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700115 AddFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800116
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700117 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800118 * @brief Update callback to create and configure instance of the face, based on supplied
119 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700120 *
121 * It is possible to set up several callbacks for different NetDevice types.
122 *
123 * Using this method, it is possible to override Face creation for PointToPointNetDevices
124 */
125 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700126 UpdateFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700127
128 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129 * @brief Remove callback to create and configure instance of the face, based on supplied
130 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700131 */
132 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700133 RemoveFaceCreateCallback(TypeId netDeviceType, FaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700134
135 /**
Spyridon Mastorakis9760bd02014-11-12 13:32:55 -0800136 * \brief Install Ndn stack on the node
137 *
138 * This method will assert if called on a node that already has Ndn object
139 * installed on it
140 *
141 * \param nodeName The name of the node on which to install the stack.
142 *
143 * \returns list of installed faces in the form of a smart pointer
144 * to NdnFaceContainer object
145 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700146 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800147 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700148
149 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700150 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700151 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700152 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700153 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800154 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700155 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700156 *
157 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700158 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700159 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700160 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800161 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700162
163 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700164 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700165 *
166 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700167 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800168 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700169 * \param c NodeContainer that holds the set of nodes on which to install the
170 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700171 *
172 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700173 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700174 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700175 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800176 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700177
178 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700179 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700180 *
181 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700182 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700183 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700184 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800185 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700186
Spyridon Mastorakis588fd102014-11-20 19:50:02 -0800187 /**
188 * \brief Set flag indicating necessity to install default routes in FIB
189 */
190 void
191 SetDefaultRoutes(bool needSet);
192
Alexander Afanasyev34e13f32014-12-14 15:13:28 -0800193 static KeyChain&
194 getKeyChain();
195
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700196 /**
197 * \brief Update Ndn stack on a given node (Add faces for new devices)
198 *
199 * \param node The node on which to update the stack.
200 */
201 void
202 Update(Ptr<Node> node);
203
204 /**
205 *\brief Update Ndn stack on given nodes (Add faces for new devices)
206 *
207 * \param c The nodes on which to update the stack.
208 */
209 void
210 Update(const NodeContainer& c);
211
212 /**
213 *\brief Update Ndn stack on a given node name (Add faces for new devices)
214 *
215 * \param nodeName The name of the node on which to update the stack.
216 */
217 void
218 Update(const std::string& nodeName);
219
220 /**
221 *\brief Update Ndn stack on all the nodes (Add faces for new devices)
222 */
223 void
224 UpdateAll();
225
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800226 /**
227 *\brief Disable the RIB manager of NFD
228 */
229 void
230 disableRibManager();
231
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700232 // Cannot be disabled for now
233 // /**
234 // * \brief Disable Face Manager
235 // */
236 // void
237 // disableFaceManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800238
239 /**
240 * \brief Disable Strategy Choice Manager
241 */
242 void
243 disableStrategyChoiceManager();
244
245 /**
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700246 * \brief Disable Forwarder Status Manager
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800247 */
248 void
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700249 disableForwarderStatusManager();
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800250
Chavoosh Ghasemi58ef8612018-09-12 15:12:49 -0700251 /**
252 * @brief Set face metric of all faces connected through PointToPoint channel to channel latency
253 */
254 static void
255 SetLinkDelayAsFaceMetric();
256
Alexander Afanasyev11453142011-11-25 16:13:33 -0800257private:
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700258 shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800259 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800260
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700261 shared_ptr<Face>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800262 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
263 Ptr<NetDevice> netDevice) const;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700264 shared_ptr<Face>
Spyridon Mastorakis21226ae2015-03-31 18:03:11 -0700265 createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800266
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800267 bool m_isRibManagerDisabled;
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700268 // bool m_isFaceManagerDisabled;
269 bool m_isForwarderStatusManagerDisabled;
spirosmastorakis0df15ba2015-11-14 08:46:24 -0800270 bool m_isStrategyChoiceManagerDisabled;
271
Spyridon Mastorakis86edf6f2014-11-14 19:27:18 -0800272public:
273 void
274 setCustomNdnCxxClocks();
275
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800276private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700277 ObjectFactory m_ndnFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700278 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800279
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800280 bool m_needSetDefaultRoutes;
Alexander Afanasyevdde1e812015-01-06 14:26:09 -0800281 size_t m_maxCsSize;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800282
spirosmastorakis34eed982016-11-02 15:20:50 -0700283 typedef std::function<std::unique_ptr<nfd::cs::Policy>()> PolicyCreationCallback;
284 PolicyCreationCallback m_csPolicyCreationFunc;
285
286 std::map<std::string, PolicyCreationCallback> m_csPolicies;
287
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700288 typedef std::list<std::pair<TypeId, FaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700289 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700290};
291
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700292} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700293} // namespace ns3
294
Alexander Afanasyeva91aab42016-09-08 15:47:38 -0700295#endif // NDNSIM_HELPER_NDN_STACK_HELPER_HPP