blob: af45c2bda7f9a9fba4fe7d5d181582d7d4ba9181 [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"
Ilya Moiseenkofbd0a8b2011-10-28 13:07:16 -070028#include "ns3/point-to-point-net-device.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070029#include "ccnx-trace-helper.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070030#include "ns3/ccnx-forwarding-helper.h"
31#include "ns3/ccnx.h"
Ilya Moiseenkofbd0a8b2011-10-28 13:07:16 -070032#include "ns3/ccnx-interest-header.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070033
34namespace ns3 {
35
36class Node;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070037class CcnxFaceContainer;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070038
39/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070040 * \ingroup ccnx
41 * \defgroup ccnx-helpers Helpers
42 */
43/**
44 * \ingroup ccnx-helpers
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070045 * \brief Adding CCNx functionality to existing Nodes.
46 *
47 * This helper enables pcap and ascii tracing of events in the ccnx stack
48 * 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
55 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
56 * "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 Afanasyev11453142011-11-25 16:13:33 -080060class CcnxStackHelper //: public PcapHelperForCcnx, public AsciiTraceHelperForCcnx
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070061{
62public:
63 /**
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070064 * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070065 */
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070066 CcnxStackHelper();
67
68 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070069 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070070 */
71 virtual ~CcnxStackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070072
73 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080074 * @brief Set forwarding strategy helper
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070075 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070076 * \param forwarding a new forwarding helper
77 *
78 * Set the forwarding helper to use during Install. The forwarding helper is
79 * really an object factory which is used to create an object of type
80 * ns3::CcnxFrProtocol per node. This forwarding object is then associated to
81 * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
82 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070083 void
Alexander Afanasyev11453142011-11-25 16:13:33 -080084 SetForwardingStrategy (std::string forwardingStrategy);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070085
86 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080087 * @brief Enable Interest limits (disabled by default)
88 */
89 void
90 EnableLimits (bool enable = true);
91
92 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070093 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070094 *
95 * This method will assert if called on a node that already has Ccnx object
96 * installed on it
97 *
98 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070099 *
100 * \returns list of installed faces in the form of a smart pointer
101 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700102 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700103 Ptr<CcnxFaceContainer>
104 Install (std::string nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700105
106 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700107 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700108 *
109 * This method will assert if called on a node that already has Ccnx object
110 * installed on it
111 *
112 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700113 *
114 * \returns list of installed faces in the form of a smart pointer
115 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700116 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700117 Ptr<CcnxFaceContainer>
118 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700119
120 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700121 * \brief Install CCNx stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700122 *
123 * The program will assert if this method is called on a container with a node
124 * that already has an ccnx object aggregated to it.
125 *
126 * \param c NodeContainer that holds the set of nodes on which to install the
127 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700128 *
129 * \returns list of installed faces in the form of a smart pointer
130 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700131 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700132 Ptr<CcnxFaceContainer>
133 Install (NodeContainer c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700134
135 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700136 * \brief Install CCNx stack on all nodes in the simulation
137 *
138 * \returns list of installed faces in the form of a smart pointer
139 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700140 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700141 Ptr<CcnxFaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700142 InstallAll () const;
143
144 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700145 * \brief Add forwarding entry in FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700146 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700147 * \param nodeName Node name
148 * \param prefix Routing prefix
149 * \param faceId Face index
150 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700151 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700152 void
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700153 AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800154
155 /**
156 * \brief Add forwarding entry in FIB
157 *
158 * \param node Node
159 * \param prefix Routing prefix
160 * \param face Face
161 * \param metric Routing metric
162 */
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700163 void
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800164 AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric);
165
166
167 /**
168 * \brief Install fake IPv4 routes that could be used to find nexthops for CCNx routes
169 *
170 * This method adds fake routes to all nodes, where each route is /32 and IPv4 address equal to node number.
171 * For example, node 5 will have direct route to 0.0.0.5.
172 */
173 void
174 InstallFakeGlobalRoutes ();
175
176 /**
177 * \brief Installs CCNx route to `node` based on fake IPv4 routes
178 *
179 * Actual route is "/<nodeId>"
180 *
181 * \param node Pointer to a node, which should be reached from all other nodes
182 */
183 void
184 InstallRouteTo (Ptr<Node> node);
185
186 /**
187 * \brief Installs CCNx route to all nodes based on fake IPv4 routes
188 *
189 * \see InstallRouteTo
190 */
191 void
192 InstallRoutesToAll ();
Alexander Afanasyev11453142011-11-25 16:13:33 -0800193
194private:
195 CcnxStackHelper (const CcnxStackHelper &);
196 CcnxStackHelper &operator = (const CcnxStackHelper &o);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800197
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700198private:
Alexander Afanasyev11453142011-11-25 16:13:33 -0800199 ObjectFactory m_strategyFactory;
200 bool m_limitsEnabled;
201
202 // /**
203 // * @brief Enable pcap output the indicated Ccnx and interface pair.
204 // * @internal
205 // *
206 // * @param prefix Filename prefix to use for pcap files.
207 // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
208 // * @param interface Interface ID on the Ccnx on which you want to enable tracing.
209 // */
210 // virtual void EnablePcapCcnxInternal (std::string prefix,
211 // Ptr<Ccnx> ccnx,
212 // uint32_t interface,
213 // bool explicitFilename);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700214
Alexander Afanasyev11453142011-11-25 16:13:33 -0800215 // /**
216 // * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
217 // * @internal
218 // *
219 // * @param stream An OutputStreamWrapper representing an existing file to use
220 // * when writing trace data.
221 // * @param prefix Filename prefix to use for ascii trace files.
222 // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
223 // * @param interface Interface ID on the Ccnx on which you want to enable tracing.
224 // */
225 // virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
226 // std::string prefix,
227 // Ptr<Ccnx> ccnx,
228 // uint32_t interface,
229 // bool explicitFilename);
230
231 // // /**
232 // // * \internal
233 // // */
234 // // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700235
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700236 // /**
237 // * \internal
238 // */
Alexander Afanasyev11453142011-11-25 16:13:33 -0800239 // static void Cleanup (void);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700240
Alexander Afanasyev11453142011-11-25 16:13:33 -0800241 // /**
242 // * \internal
243 // */
244 // bool PcapHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700245
Alexander Afanasyev11453142011-11-25 16:13:33 -0800246 // /**
247 // * \internal
248 // */
249 // bool AsciiHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700250};
251
252} // namespace ns3
253
254#endif /* CCNX_STACK_HELPER_H */