blob: 6cd37459f753e740de2e44549a8d1a576ade10b5 [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
22#ifndef CCNX_STACK_HELPER_H
23#define CCNX_STACK_HELPER_H
24
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 Afanasyev0ab833e2011-08-18 15:49:13 -070033class CcnxFaceContainer;
Alexander Afanasyev07827182011-12-13 01:07:32 -080034class CcnxFace;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070035
36/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070037 * \ingroup ccnx
38 * \defgroup ccnx-helpers Helpers
39 */
40/**
41 * \ingroup ccnx-helpers
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070042 * \brief Adding CCNx functionality to existing Nodes.
43 *
44 * This helper enables pcap and ascii tracing of events in the ccnx stack
45 * associated with a node. This is substantially similar to the tracing that
46 * happens in device helpers, but the important difference is that, well, there
47 * is no device. This means that the creation of output file names will change,
48 * and also the user-visible methods will not reference devices and therefore
49 * the number of trace enable methods is reduced.
50 *
51 * Normally we eschew multiple inheritance, however, the classes
52 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
53 * "mixins". A mixin is a self-contained class that encapsulates a general
54 * attribute or a set of functionality that may be of interest to many other
55 * classes.
56 */
Alexander Afanasyev07827182011-12-13 01:07:32 -080057class CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070058{
59public:
60 /**
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070061 * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070062 */
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063 CcnxStackHelper();
64
65 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070066 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070067 */
68 virtual ~CcnxStackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069
70 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080071 * @brief Set forwarding strategy helper
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070072 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073 * \param forwarding a new forwarding helper
74 *
75 * Set the forwarding helper to use during Install. The forwarding helper is
76 * really an object factory which is used to create an object of type
Ilya Moiseenko956d0542012-01-02 15:26:40 -080077 * ns3::CcnxL3Protocol per node. This forwarding object is then associated to
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070078 * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
79 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070080 void
Alexander Afanasyev11453142011-11-25 16:13:33 -080081 SetForwardingStrategy (std::string forwardingStrategy);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070082
83 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080084 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080085 *
86 * @param enable Enable or disable limits
87 * @param avgRtt Average RTT
88 * @param avgContentObject Average size of contentObject packets (including all headers)
89 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -080090 */
91 void
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080092 EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgContentObject=1100, uint32_t avgInterest=40);
Alexander Afanasyev11453142011-11-25 16:13:33 -080093
94 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070095 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070096 *
97 * This method will assert if called on a node that already has Ccnx object
98 * installed on it
99 *
100 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700101 *
102 * \returns list of installed faces in the form of a smart pointer
103 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700104 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700105 Ptr<CcnxFaceContainer>
106 Install (std::string nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700107
108 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700109 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700110 *
111 * This method will assert if called on a node that already has Ccnx object
112 * installed on it
113 *
114 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700115 *
116 * \returns list of installed faces in the form of a smart pointer
117 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700118 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700119 Ptr<CcnxFaceContainer>
120 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700121
122 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700123 * \brief Install CCNx stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700124 *
125 * The program will assert if this method is called on a container with a node
126 * that already has an ccnx object aggregated to it.
127 *
128 * \param c NodeContainer that holds the set of nodes on which to install the
129 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700130 *
131 * \returns list of installed faces in the form of a smart pointer
132 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700133 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700134 Ptr<CcnxFaceContainer>
135 Install (NodeContainer c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700136
137 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700138 * \brief Install CCNx stack on all nodes in the simulation
139 *
140 * \returns list of installed faces in the form of a smart pointer
141 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700142 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700143 Ptr<CcnxFaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700144 InstallAll () const;
145
146 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700147 * \brief Add forwarding entry in FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700148 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700149 * \param nodeName Node name
150 * \param prefix Routing prefix
151 * \param faceId Face index
152 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700153 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800154 static void
155 AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800156
157 /**
158 * \brief Add forwarding entry in FIB
159 *
160 * \param node Node
161 * \param prefix Routing prefix
162 * \param face Face
163 * \param metric Routing metric
164 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800165 static void
166 AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800167
168 /**
169 * \brief Set flag indicating necessity to install default routes in FIB
170 */
171 void
172 SetDefaultRoutes (bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800173
174 /**
175 * \brief Install fake IPv4 routes that could be used to find nexthops for CCNx routes
176 *
177 * This method adds fake routes to all nodes, where each route is /32 and IPv4 address equal to node number.
178 * For example, node 5 will have direct route to 0.0.0.5.
179 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800180 static void
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800181 InstallFakeGlobalRoutes ();
182
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800183 static void
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800184 InstallFakeGlobalRoutesImpl ();
185
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800186 /**
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800187 * \brief Install CCNx route to `node` based on fake IPv4 routes
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800188 *
189 * Actual route is "/<nodeId>"
190 *
191 * \param node Pointer to a node, which should be reached from all other nodes
192 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800193 static void
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800194 InstallRouteTo (Ptr<Node> node);
195
196 /**
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800197 * \brief Install CCNx route to /prefix which is installed on `node'
198 *
199 * Normally, prefix is /<node->GetId()>. Other values may be used in black-holing scenarios
200 */
201 static void
202 InstallRouteTo (const std::string &prefix, Ptr<Node> node);
203
204 /**
205 * \brief Install CCNx route to all nodes based on fake IPv4 routes
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800206 *
207 * \see InstallRouteTo
208 */
Alexander Afanasyevb7626842012-01-12 13:43:33 -0800209 static void
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800210 InstallRoutesToAll ();
Alexander Afanasyev11453142011-11-25 16:13:33 -0800211
212private:
213 CcnxStackHelper (const CcnxStackHelper &);
214 CcnxStackHelper &operator = (const CcnxStackHelper &o);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800215
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700216private:
Alexander Afanasyev11453142011-11-25 16:13:33 -0800217 ObjectFactory m_strategyFactory;
218 bool m_limitsEnabled;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800219 Time m_avgRtt;
220 uint32_t m_avgContentObjectSize;
221 uint32_t m_avgInterestSize;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800222 bool m_needSetDefaultRoutes;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800223
224 // /**
225 // * @brief Enable pcap output the indicated Ccnx and interface pair.
226 // * @internal
227 // *
228 // * @param prefix Filename prefix to use for pcap files.
229 // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
230 // * @param interface Interface ID on the Ccnx on which you want to enable tracing.
231 // */
232 // virtual void EnablePcapCcnxInternal (std::string prefix,
233 // Ptr<Ccnx> ccnx,
234 // uint32_t interface,
235 // bool explicitFilename);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700236
Alexander Afanasyev11453142011-11-25 16:13:33 -0800237 // /**
238 // * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
239 // * @internal
240 // *
241 // * @param stream An OutputStreamWrapper representing an existing file to use
242 // * when writing trace data.
243 // * @param prefix Filename prefix to use for ascii trace files.
244 // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
245 // * @param interface Interface ID on the Ccnx on which you want to enable tracing.
246 // */
247 // virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
248 // std::string prefix,
249 // Ptr<Ccnx> ccnx,
250 // uint32_t interface,
251 // bool explicitFilename);
252
253 // // /**
254 // // * \internal
255 // // */
256 // // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700257
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700258 // /**
259 // * \internal
260 // */
Alexander Afanasyev11453142011-11-25 16:13:33 -0800261 // static void Cleanup (void);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700262
Alexander Afanasyev11453142011-11-25 16:13:33 -0800263 // /**
264 // * \internal
265 // */
266 // bool PcapHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700267
Alexander Afanasyev11453142011-11-25 16:13:33 -0800268 // /**
269 // * \internal
270 // */
271 // bool AsciiHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700272};
273
274} // namespace ns3
275
276#endif /* CCNX_STACK_HELPER_H */