blob: 0c036d497fe3ed518b789750c8311e81cc0618b9 [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>
19 * 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 Afanasyev45b92d42011-08-14 23:11:38 -070038
39/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070040 * \ingroup ndn
41 * \defgroup ndn-helpers Helpers
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070042 */
43/**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070044 * \ingroup ndn-helpers
45 * \brief Adding Ndn functionality to existing Nodes.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070046 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047 * This helper enables pcap and ascii tracing of events in the ndn stack
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070048 * associated with a node. This is substantially similar to the tracing that
49 * happens in device helpers, but the important difference is that, well, there
50 * is no device. This means that the creation of output file names will change,
51 * and also the user-visible methods will not reference devices and therefore
52 * the number of trace enable methods is reduced.
53 *
54 * Normally we eschew multiple inheritance, however, the classes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070055 * PcapUserHelperForNdn and AsciiTraceUserHelperForNdn are treated as
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070056 * "mixins". A mixin is a self-contained class that encapsulates a general
57 * attribute or a set of functionality that may be of interest to many other
58 * classes.
59 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070060class StackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070061{
62public:
63 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070064 * \brief Create a new NdnStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070065 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070066 StackHelper();
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070067
68 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070069 * \brief Destroy the NdnStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070070 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070071 virtual ~StackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070072
73 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070074 * @brief Set parameters of NdnL3Protocol
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070075 */
76 void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070077 SetStackAttributes (const std::string &attr1 = "", const std::string &value1 = "",
78 const std::string &attr2 = "", const std::string &value2 = "",
79 const std::string &attr3 = "", const std::string &value3 = "",
80 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -070081
82
83 /**
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 Afanasyev3a4a0b32012-06-28 14:14:22 -070092 SetForwardingStrategy (const std::string &forwardingStrategyClass,
93 const std::string &attr1 = "", const std::string &value1 = "",
94 const std::string &attr2 = "", const std::string &value2 = "",
95 const std::string &attr3 = "", const std::string &value3 = "",
96 const std::string &attr4 = "", 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 Afanasyev3a4a0b32012-06-28 14:14:22 -0700103 SetContentStore (const std::string &contentStoreClass,
104 const std::string &attr1 = "", const std::string &value1 = "",
105 const std::string &attr2 = "", const std::string &value2 = "",
106 const std::string &attr3 = "", const std::string &value3 = "",
107 const std::string &attr4 = "", const std::string &value4 = "");
108
109 /**
110 * @brief Set PIT class and its attributes
111 * @param pitClass string, representing class of PIT
112 */
113 void
114 SetPit (const std::string &pitClass,
115 const std::string &attr1 = "", const std::string &value1 = "",
116 const std::string &attr2 = "", const std::string &value2 = "",
117 const std::string &attr3 = "", const std::string &value3 = "",
118 const std::string &attr4 = "", const std::string &value4 = "");
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700119
120 /**
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700121 * @brief Set FIB class and its attributes
122 * @param pitClass string, representing class of FIB
123 */
124 void
125 SetFib (const std::string &fibClass,
126 const std::string &attr1 = "", const std::string &value1 = "",
127 const std::string &attr2 = "", const std::string &value2 = "",
128 const std::string &attr3 = "", const std::string &value3 = "",
129 const std::string &attr4 = "", const std::string &value4 = "");
130
131 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -0800132 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800133 *
134 * @param enable Enable or disable limits
135 * @param avgRtt Average RTT
136 * @param avgContentObject Average size of contentObject packets (including all headers)
137 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -0800138 */
139 void
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800140 EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgContentObject=1100, uint32_t avgInterest=40);
Alexander Afanasyev11453142011-11-25 16:13:33 -0800141
142 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700143 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700144 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700145 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700146 * installed on it
147 *
148 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700149 *
150 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700151 * to NdnFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700152 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700153 Ptr<FaceContainer>
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800154 Install (const std::string &nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700155
156 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700157 * \brief Install Ndn stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700158 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700159 * This method will assert if called on a node that already has Ndn object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700160 * installed on it
161 *
162 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700163 *
164 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700165 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700166 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700167 Ptr<FaceContainer>
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700168 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700169
170 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700171 * \brief Install Ndn stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700172 *
173 * The program will assert if this method is called on a container with a node
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700174 * that already has an ndn object aggregated to it.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700175 *
176 * \param c NodeContainer that holds the set of nodes on which to install the
177 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700178 *
179 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700180 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700181 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700182 Ptr<FaceContainer>
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800183 Install (const NodeContainer &c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700184
185 /**
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700186 * \brief Install Ndn stack on all nodes in the simulation
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700187 *
188 * \returns list of installed faces in the form of a smart pointer
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700189 * to FaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700190 */
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700191 Ptr<FaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700192 InstallAll () const;
193
194 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800195 * \brief Add forwarding entry to FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700196 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700197 * \param nodeName Node name
198 * \param prefix Routing prefix
199 * \param faceId Face index
200 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700201 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800202 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800203 AddRoute (const std::string &nodeName, const std::string &prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800204
205 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800206 * \brief Add forwarding entry to FIB
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800207 *
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700208 * \param nodeName Node
209 * \param prefix Routing prefix
210 * \param faceId Face index
211 * \param metric Routing metric
212 */
213 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800214 AddRoute (Ptr<Node> node, const std::string &prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700215
216 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800217 * \brief Add forwarding entry to FIB
Alexander Afanasyev8bedcaf2012-07-20 15:30:44 -0700218 *
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800219 * \param node Node
220 * \param prefix Routing prefix
221 * \param face Face
222 * \param metric Routing metric
223 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800224 static void
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800225 AddRoute (Ptr<Node> node, const std::string &prefix, Ptr<Face> face, int32_t metric);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800226
227 /**
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800228 * @brief Add forwarding entry to FIB (work only with point-to-point links)
229 *
230 * \param node Node
231 * \param prefix Routing prefix
232 * \param otherNode The other node, to which interests (will be used to infer face id
233 * \param metric Routing metric
234 */
235 static void
236 AddRoute (Ptr<Node> node, const std::string &prefix, Ptr<Node> otherNode, int32_t metric);
237
238 /**
239 * @brief Add forwarding entry to FIB (work only with point-to-point links)
240 *
241 * \param nodeName Node name (refer to ns3::Names)
242 * \param prefix Routing prefix
243 * \param otherNode The other node name, to which interests (will be used to infer face id (refer to ns3::Names)
244 * \param metric Routing metric
245 */
246 static void
247 AddRoute (const std::string &nodeName, const std::string &prefix, const std::string &otherNodeName, int32_t metric);
248
249 /**
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800250 * \brief Set flag indicating necessity to install default routes in FIB
251 */
252 void
253 SetDefaultRoutes (bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800254
Alexander Afanasyev11453142011-11-25 16:13:33 -0800255private:
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700256 StackHelper (const StackHelper &);
257 StackHelper &operator = (const StackHelper &o);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800258
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700259private:
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700260 ObjectFactory m_ndnFactory;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800261 ObjectFactory m_strategyFactory;
Alexander Afanasyevd9fecdd2012-06-08 16:22:24 -0700262 ObjectFactory m_contentStoreFactory;
Alexander Afanasyev3a4a0b32012-06-28 14:14:22 -0700263 ObjectFactory m_pitFactory;
264 ObjectFactory m_fibFactory;
265
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800266 bool m_limitsEnabled;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800267 Time m_avgRtt;
268 uint32_t m_avgContentObjectSize;
269 uint32_t m_avgInterestSize;
Alexander Afanasyevfd258262012-11-23 14:59:19 -0800270 bool m_needSetDefaultRoutes;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700271};
272
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700273} // namespace ndn
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700274} // namespace ns3
275
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700276#endif /* NDN_STACK_HELPER_H */