blob: 155c22df232c1fd7cc9e776406b1e560ceae1f53 [file] [log] [blame]
Alexander Afanasyevc74a6022011-08-15 20:01:35 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07002/*
3 * Copyright (c) 2011 UCLA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Alexander Afanasyev122f3782013-02-02 00:04:40 -080019 * Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070020 */
21
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070022#ifndef NDN_STACK_HELPER_H
23#define NDN_STACK_HELPER_H
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070025#include "ns3/packet.h"
26#include "ns3/ptr.h"
27#include "ns3/object-factory.h"
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080028#include "ns3/nstime.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070029
30namespace ns3 {
31
32class Node;
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070033
34namespace ndn {
35
36class FaceContainer;
37class Face;
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -080038class NetDeviceFace;
39class L3Protocol;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070040
41/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042 * \ingroup ndn
43 * \defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070044 */
45/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070046 * \ingroup ndn-helpers
47 * \brief Adding Ndn functionality to existing Nodes.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070048 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070049 * This helper enables pcap and ascii tracing of events in the ndn stack
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070050 * associated with a node. This is substantially similar to the tracing that
51 * happens in device helpers, but the important difference is that, well, there
52 * is no device. This means that the creation of output file names will change,
53 * and also the user-visible methods will not reference devices and therefore
54 * the number of trace enable methods is reduced.
55 *
56 * Normally we eschew multiple inheritance, however, the classes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070058 * "mixins". A mixin is a self-contained class that encapsulates a general
59 * attribute or a set of functionality that may be of interest to many other
60 * classes.
61 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062class StackHelper {
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070063public:
64 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070066 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080068
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070069 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070070 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070071 */
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 virtual ~StackHelper();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073
74 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070075 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070076 */
77 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080078 SetStackAttributes(const std::string& attr1 = "", const std::string& value1 = "",
79 const std::string& attr2 = "", const std::string& value2 = "",
80 const std::string& attr3 = "", const std::string& value3 = "",
81 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080082
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070083 /**
84 * @brief Set forwarding strategy class and its attributes
85 * @param forwardingStrategyClass string containing name of the forwarding strategy class
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070086 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070087 * Valid options are "ns3::NdnFloodingStrategy" (default) and "ns3::NdnBestRouteStrategy"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070088 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070089 * Other strategies can be implemented, inheriting ns3::NdnForwardingStrategy class
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070090 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070091 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 SetForwardingStrategy(const std::string& forwardingStrategyClass, const std::string& attr1 = "",
93 const std::string& value1 = "", const std::string& attr2 = "",
94 const std::string& value2 = "", const std::string& attr3 = "",
95 const std::string& value3 = "", const std::string& attr4 = "",
96 const std::string& value4 = "");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070097
98 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070099 * @brief Set content store class and its attributes
100 * @param contentStoreClass string, representing class of the content store
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700101 */
102 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 SetContentStore(const std::string& contentStoreClass, const std::string& attr1 = "",
104 const std::string& value1 = "", const std::string& attr2 = "",
105 const std::string& value2 = "", const std::string& attr3 = "",
106 const std::string& value3 = "", const std::string& attr4 = "",
107 const std::string& value4 = "");
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700108
109 /**
110 * @brief Set PIT class and its attributes
111 * @param pitClass string, representing class of PIT
112 */
113 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800114 SetPit(const std::string& pitClass, const std::string& attr1 = "", const std::string& value1 = "",
115 const std::string& attr2 = "", const std::string& value2 = "",
116 const std::string& attr3 = "", const std::string& value3 = "",
117 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800118
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700119 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700120 * @brief Set FIB class and its attributes
121 * @param pitClass string, representing class of FIB
122 */
123 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800124 SetFib(const std::string& fibClass, const std::string& attr1 = "", const std::string& value1 = "",
125 const std::string& attr2 = "", const std::string& value2 = "",
126 const std::string& attr3 = "", const std::string& value3 = "",
127 const std::string& attr4 = "", const std::string& value4 = "");
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700128
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800129 typedef Callback<Ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice>>
130 NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800131
132 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800133 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node>
134 *and Ptr<NetDevice>
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800135 *
136 * It is possible to set up several callbacks for different NetDevice types.
137 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800138 * Currently, there is only one specialized callback for PointToPointNetDevice, which creates face
139 *and sets limits (if enabled)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800140 * based on PointToPoint link parameters
141 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800142 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used
143 *(DefaultNetDeviceCallback)
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800144 */
145 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800146 AddNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800147
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700148 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800149 * @brief Update callback to create and configure instance of the face, based on supplied
150 *Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700151 *
152 * It is possible to set up several callbacks for different NetDevice types.
153 *
154 * Using this method, it is possible to override Face creation for PointToPointNetDevices
155 */
156 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800157 UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700158
159 /**
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800160 * @brief Remove callback to create and configure instance of the face, based on supplied
161 * Ptr<Node> and Ptr<NetDevice>
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700162 */
163 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800164 RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700165
166 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -0800167 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800168 *
169 * @param enable Enable or disable limits
170 * @param avgRtt Average RTT
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700171 * @param avgData Average size of contentObject packets (including all headers)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800172 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -0800173 */
174 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800175 EnableLimits(bool enable = true, Time avgRtt = Seconds(0.1), uint32_t avgData = 1100,
176 uint32_t avgInterest = 40);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800177
Alexander Afanasyev11453142011-11-25 16:13:33 -0800178 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700179 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700180 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700181 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700182 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800183 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700184 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700185 *
186 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700187 * to NdnFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700188 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700189 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800190 Install(const std::string& nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700191
192 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700193 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700194 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700195 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700196 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800197 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700198 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700199 *
200 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700201 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700202 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700203 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800204 Install(Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700205
206 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700207 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700208 *
209 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700210 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800211 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700212 * \param c NodeContainer that holds the set of nodes on which to install the
213 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700214 *
215 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700216 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700217 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700218 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800219 Install(const NodeContainer& c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700220
221 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700222 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700223 *
224 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700225 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700226 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700227 Ptr<FaceContainer>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800228 InstallAll() const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700229
230 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800231 * \brief Add forwarding entry to FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700232 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700233 * \param nodeName Node name
234 * \param prefix Routing prefix
235 * \param faceId Face index
236 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700237 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800238 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800239 AddRoute(const std::string& nodeName, const std::string& prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800240
241 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800242 * \brief Add forwarding entry to FIB
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800243 *
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700244 * \param nodeName Node
245 * \param prefix Routing prefix
246 * \param faceId Face index
247 * \param metric Routing metric
248 */
249 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800250 AddRoute(Ptr<Node> node, const std::string& prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700251
252 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800253 * \brief Add forwarding entry to FIB
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700254 *
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800255 * \param node Node
256 * \param prefix Routing prefix
257 * \param face Face
258 * \param metric Routing metric
259 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800260 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800261 AddRoute(Ptr<Node> node, const std::string& prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800262
263 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800264 * @brief Add forwarding entry to FIB (work only with point-to-point links)
265 *
266 * \param node Node
267 * \param prefix Routing prefix
268 * \param otherNode The other node, to which interests (will be used to infer face id
269 * \param metric Routing metric
270 */
271 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800272 AddRoute(Ptr<Node> node, const std::string& prefix, Ptr<Node> otherNode, int32_t metric);
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800273
274 /**
275 * @brief Add forwarding entry to FIB (work only with point-to-point links)
276 *
277 * \param nodeName Node name (refer to ns3::Names)
278 * \param prefix Routing prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800279 * \param otherNode The other node name, to which interests (will be used to infer face id (refer
280 *to ns3::Names)
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800281 * \param metric Routing metric
282 */
283 static void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800284 AddRoute(const std::string& nodeName, const std::string& prefix, const std::string& otherNodeName,
285 int32_t metric);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800286
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800287 /**
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800288 * \brief Set flag indicating necessity to install default routes in FIB
289 */
290 void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800291 SetDefaultRoutes(bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800292
Alexander Afanasyev11453142011-11-25 16:13:33 -0800293private:
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800294 Ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800295 DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800296
297 Ptr<NetDeviceFace>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800298 PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn,
299 Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800300
301private:
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800302 StackHelper(const StackHelper&);
303 StackHelper&
304 operator=(const StackHelper& o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800305
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700306private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700307 ObjectFactory m_ndnFactory;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800308 ObjectFactory m_strategyFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700309 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700310 ObjectFactory m_pitFactory;
311 ObjectFactory m_fibFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800312
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800313 bool m_limitsEnabled;
314 Time m_avgRtt;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700315 uint32_t m_avgDataSize;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800316 uint32_t m_avgInterestSize;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800317 bool m_needSetDefaultRoutes;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800318
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800319 typedef std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>> NetDeviceCallbackList;
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700320 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700321};
322
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700323} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700324} // namespace ns3
325
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700326#endif /* NDN_STACK_HELPER_H */