blob: dc11bcfdc984589a644f898e3c32decaa3334bff [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 Afanasyev122f3782013-02-02 00:04:40 -080062class StackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070063{
64public:
65 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070066 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070068 StackHelper();
Alexander Afanasyev122f3782013-02-02 00:04:40 -080069
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070070 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070072 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 virtual ~StackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070074
75 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070076 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070077 */
78 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070079 SetStackAttributes (const std::string &attr1 = "", const std::string &value1 = "",
80 const std::string &attr2 = "", const std::string &value2 = "",
81 const std::string &attr3 = "", const std::string &value3 = "",
82 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -080083
84
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070085 /**
86 * @brief Set forwarding strategy class and its attributes
87 * @param forwardingStrategyClass string containing name of the forwarding strategy class
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070088 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070089 * Valid options are "ns3::NdnFloodingStrategy" (default) and "ns3::NdnBestRouteStrategy"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070090 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070091 * Other strategies can be implemented, inheriting ns3::NdnForwardingStrategy class
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070092 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070093 void
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070094 SetForwardingStrategy (const std::string &forwardingStrategyClass,
95 const std::string &attr1 = "", const std::string &value1 = "",
96 const std::string &attr2 = "", const std::string &value2 = "",
97 const std::string &attr3 = "", const std::string &value3 = "",
98 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070099
100 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700101 * @brief Set content store class and its attributes
102 * @param contentStoreClass string, representing class of the content store
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700103 */
104 void
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700105 SetContentStore (const std::string &contentStoreClass,
106 const std::string &attr1 = "", const std::string &value1 = "",
107 const std::string &attr2 = "", const std::string &value2 = "",
108 const std::string &attr3 = "", const std::string &value3 = "",
109 const std::string &attr4 = "", const std::string &value4 = "");
110
111 /**
112 * @brief Set PIT class and its attributes
113 * @param pitClass string, representing class of PIT
114 */
115 void
116 SetPit (const std::string &pitClass,
117 const std::string &attr1 = "", const std::string &value1 = "",
118 const std::string &attr2 = "", const std::string &value2 = "",
119 const std::string &attr3 = "", const std::string &value3 = "",
120 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800121
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700122 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700123 * @brief Set FIB class and its attributes
124 * @param pitClass string, representing class of FIB
125 */
126 void
127 SetFib (const std::string &fibClass,
128 const std::string &attr1 = "", const std::string &value1 = "",
129 const std::string &attr2 = "", const std::string &value2 = "",
130 const std::string &attr3 = "", const std::string &value3 = "",
131 const std::string &attr4 = "", const std::string &value4 = "");
132
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800133 typedef Callback< Ptr<NetDeviceFace>, Ptr<Node>, Ptr<L3Protocol>, Ptr<NetDevice> > NetDeviceFaceCreateCallback;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800134
135 /**
136 * @brief Add callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<NetDevice>
137 *
138 * It is possible to set up several callbacks for different NetDevice types.
139 *
140 * Currently, there is only one specialized callback for PointToPointNetDevice, which creates face and sets limits (if enabled)
141 * based on PointToPoint link parameters
142 *
143 * If none of the callbacks fit the TypeId of NetDevice, a default callback is used (DefaultNetDeviceCallback)
144 */
145 void
146 AddNetDeviceFaceCreateCallback (TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
147
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700148 /**
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700149 * @brief Update callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<NetDevice>
150 *
151 * It is possible to set up several callbacks for different NetDevice types.
152 *
153 * Using this method, it is possible to override Face creation for PointToPointNetDevices
154 */
155 void
156 UpdateNetDeviceFaceCreateCallback (TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
157
158 /**
159 * @brief Remove callback to create and configure instance of the face, based on supplied Ptr<Node> and Ptr<NetDevice>
160 */
161 void
162 RemoveNetDeviceFaceCreateCallback (TypeId netDeviceType, NetDeviceFaceCreateCallback callback);
163
164 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -0800165 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800166 *
167 * @param enable Enable or disable limits
168 * @param avgRtt Average RTT
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700169 * @param avgData Average size of contentObject packets (including all headers)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800170 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -0800171 */
172 void
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700173 EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgData=1100, uint32_t avgInterest=40);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800174
Alexander Afanasyev11453142011-11-25 16:13:33 -0800175 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700176 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700177 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700178 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700179 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800180 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700181 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700182 *
183 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700184 * to NdnFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700185 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700186 Ptr<FaceContainer>
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800187 Install (const std::string &nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700188
189 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700190 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700191 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700192 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700193 * installed on it
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800194 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700195 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700196 *
197 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700198 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700199 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700200 Ptr<FaceContainer>
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700201 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700202
203 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700204 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700205 *
206 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700207 * that already has an ndn object aggregated to it.
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800208 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700209 * \param c NodeContainer that holds the set of nodes on which to install the
210 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700211 *
212 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700213 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700214 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700215 Ptr<FaceContainer>
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800216 Install (const NodeContainer &c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700217
218 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700219 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700220 *
221 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700222 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700223 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700224 Ptr<FaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700225 InstallAll () const;
226
227 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800228 * \brief Add forwarding entry to FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700229 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700230 * \param nodeName Node name
231 * \param prefix Routing prefix
232 * \param faceId Face index
233 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700234 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800235 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800236 AddRoute (const std::string &nodeName, const std::string &prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800237
238 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800239 * \brief Add forwarding entry to FIB
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800240 *
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700241 * \param nodeName Node
242 * \param prefix Routing prefix
243 * \param faceId Face index
244 * \param metric Routing metric
245 */
246 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800247 AddRoute (Ptr<Node> node, const std::string &prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700248
249 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800250 * \brief Add forwarding entry to FIB
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700251 *
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800252 * \param node Node
253 * \param prefix Routing prefix
254 * \param face Face
255 * \param metric Routing metric
256 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800257 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800258 AddRoute (Ptr<Node> node, const std::string &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800259
260 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800261 * @brief Add forwarding entry to FIB (work only with point-to-point links)
262 *
263 * \param node Node
264 * \param prefix Routing prefix
265 * \param otherNode The other node, to which interests (will be used to infer face id
266 * \param metric Routing metric
267 */
268 static void
269 AddRoute (Ptr<Node> node, const std::string &prefix, Ptr<Node> otherNode, int32_t metric);
270
271 /**
272 * @brief Add forwarding entry to FIB (work only with point-to-point links)
273 *
274 * \param nodeName Node name (refer to ns3::Names)
275 * \param prefix Routing prefix
276 * \param otherNode The other node name, to which interests (will be used to infer face id (refer to ns3::Names)
277 * \param metric Routing metric
278 */
279 static void
280 AddRoute (const std::string &nodeName, const std::string &prefix, const std::string &otherNodeName, int32_t metric);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800281
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800282 /**
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800283 * \brief Set flag indicating necessity to install default routes in FIB
284 */
285 void
286 SetDefaultRoutes (bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800287
Alexander Afanasyev11453142011-11-25 16:13:33 -0800288private:
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800289 Ptr<NetDeviceFace>
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800290 DefaultNetDeviceCallback (Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800291
292 Ptr<NetDeviceFace>
Alexander Afanasyevc17e4bd2013-02-17 14:31:56 -0800293 PointToPointNetDeviceCallback (Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> netDevice) const;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800294
295private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700296 StackHelper (const StackHelper &);
297 StackHelper &operator = (const StackHelper &o);
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800298
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700299private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700300 ObjectFactory m_ndnFactory;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800301 ObjectFactory m_strategyFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700302 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700303 ObjectFactory m_pitFactory;
304 ObjectFactory m_fibFactory;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800305
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800306 bool m_limitsEnabled;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800307 Time m_avgRtt;
Alexander Afanasyev772f51b2013-08-01 18:53:25 -0700308 uint32_t m_avgDataSize;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800309 uint32_t m_avgInterestSize;
Alexander Afanasyev122f3782013-02-02 00:04:40 -0800310 bool m_needSetDefaultRoutes;
311
Alexander Afanasyev2a269f72013-06-06 22:59:33 -0700312 typedef std::list< std::pair<TypeId, NetDeviceFaceCreateCallback> > NetDeviceCallbackList;
313 NetDeviceCallbackList m_netDeviceCallbacks;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700314};
315
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700316} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700317} // namespace ns3
318
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700319#endif /* NDN_STACK_HELPER_H */