blob: bcfab3f378ddd624de581cdfaee04693d1fba072 [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 Afanasyevc39f0b42011-11-28 12:51:12 -080033#include "ns3/nstime.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070034
35namespace ns3 {
36
37class Node;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070038class CcnxFaceContainer;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070039
40/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070041 * \ingroup ccnx
42 * \defgroup ccnx-helpers Helpers
43 */
44/**
45 * \ingroup ccnx-helpers
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070046 * \brief Adding CCNx functionality to existing Nodes.
47 *
48 * This helper enables pcap and ascii tracing of events in the ccnx stack
49 * associated with a node. This is substantially similar to the tracing that
50 * happens in device helpers, but the important difference is that, well, there
51 * is no device. This means that the creation of output file names will change,
52 * and also the user-visible methods will not reference devices and therefore
53 * the number of trace enable methods is reduced.
54 *
55 * Normally we eschew multiple inheritance, however, the classes
56 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
57 * "mixins". A mixin is a self-contained class that encapsulates a general
58 * attribute or a set of functionality that may be of interest to many other
59 * classes.
60 */
Alexander Afanasyev11453142011-11-25 16:13:33 -080061class CcnxStackHelper //: public PcapHelperForCcnx, public AsciiTraceHelperForCcnx
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070062{
63public:
64 /**
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070065 * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070066 */
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070067 CcnxStackHelper();
68
69 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070070 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070071 */
72 virtual ~CcnxStackHelper ();
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070073
74 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080075 * @brief Set forwarding strategy helper
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070076 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070077 * \param forwarding a new forwarding helper
78 *
79 * Set the forwarding helper to use during Install. The forwarding helper is
80 * really an object factory which is used to create an object of type
81 * ns3::CcnxFrProtocol per node. This forwarding object is then associated to
82 * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
83 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070084 void
Alexander Afanasyev11453142011-11-25 16:13:33 -080085 SetForwardingStrategy (std::string forwardingStrategy);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070086
87 /**
Alexander Afanasyev11453142011-11-25 16:13:33 -080088 * @brief Enable Interest limits (disabled by default)
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080089 *
90 * @param enable Enable or disable limits
91 * @param avgRtt Average RTT
92 * @param avgContentObject Average size of contentObject packets (including all headers)
93 * @param avgInterest Average size of interest packets (including all headers)
Alexander Afanasyev11453142011-11-25 16:13:33 -080094 */
95 void
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080096 EnableLimits (bool enable = true, Time avgRtt=Seconds(0.1), uint32_t avgContentObject=1100, uint32_t avgInterest=40);
Alexander Afanasyev11453142011-11-25 16:13:33 -080097
98 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070099 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700100 *
101 * This method will assert if called on a node that already has Ccnx object
102 * installed on it
103 *
104 * \param nodeName The name of the node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700105 *
106 * \returns list of installed faces in the form of a smart pointer
107 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700108 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700109 Ptr<CcnxFaceContainer>
110 Install (std::string nodeName) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700111
112 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700113 * \brief Install CCNx stack on the node
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700114 *
115 * This method will assert if called on a node that already has Ccnx object
116 * installed on it
117 *
118 * \param node The node on which to install the stack.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700119 *
120 * \returns list of installed faces in the form of a smart pointer
121 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700122 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700123 Ptr<CcnxFaceContainer>
124 Install (Ptr<Node> node) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700125
126 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700127 * \brief Install CCNx stack on each node in the input container
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700128 *
129 * The program will assert if this method is called on a container with a node
130 * that already has an ccnx object aggregated to it.
131 *
132 * \param c NodeContainer that holds the set of nodes on which to install the
133 * new stacks.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700134 *
135 * \returns list of installed faces in the form of a smart pointer
136 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700137 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700138 Ptr<CcnxFaceContainer>
139 Install (NodeContainer c) const;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700140
141 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700142 * \brief Install CCNx stack on all nodes in the simulation
143 *
144 * \returns list of installed faces in the form of a smart pointer
145 * to CcnxFaceContainer object
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700146 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700147 Ptr<CcnxFaceContainer>
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700148 InstallAll () const;
149
150 /**
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700151 * \brief Add forwarding entry in FIB
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700152 *
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700153 * \param nodeName Node name
154 * \param prefix Routing prefix
155 * \param faceId Face index
156 * \param metric Routing metric
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700157 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700158 void
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800159 AddRoute (std::string nodeName, std::string prefix, uint32_t faceId, int32_t metric) const;
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800160
161 /**
162 * \brief Add forwarding entry in FIB
163 *
164 * \param node Node
165 * \param prefix Routing prefix
166 * \param face Face
167 * \param metric Routing metric
168 */
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700169 void
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800170 AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric) const;
171
172 /**
173 * \brief Set flag indicating necessity to install default routes in FIB
174 */
175 void
176 SetDefaultRoutes (bool needSet);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800177
178 /**
179 * \brief Install fake IPv4 routes that could be used to find nexthops for CCNx routes
180 *
181 * This method adds fake routes to all nodes, where each route is /32 and IPv4 address equal to node number.
182 * For example, node 5 will have direct route to 0.0.0.5.
183 */
184 void
185 InstallFakeGlobalRoutes ();
186
187 /**
188 * \brief Installs CCNx route to `node` based on fake IPv4 routes
189 *
190 * Actual route is "/<nodeId>"
191 *
192 * \param node Pointer to a node, which should be reached from all other nodes
193 */
194 void
195 InstallRouteTo (Ptr<Node> node);
196
197 /**
198 * \brief Installs CCNx route to all nodes based on fake IPv4 routes
199 *
200 * \see InstallRouteTo
201 */
202 void
203 InstallRoutesToAll ();
Alexander Afanasyev11453142011-11-25 16:13:33 -0800204
205private:
206 CcnxStackHelper (const CcnxStackHelper &);
207 CcnxStackHelper &operator = (const CcnxStackHelper &o);
Alexander Afanasyev52e9aa92011-11-15 20:23:20 -0800208
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700209private:
Alexander Afanasyev11453142011-11-25 16:13:33 -0800210 ObjectFactory m_strategyFactory;
211 bool m_limitsEnabled;
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800212 Time m_avgRtt;
213 uint32_t m_avgContentObjectSize;
214 uint32_t m_avgInterestSize;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800215 bool m_needSetDefaultRoutes;
Alexander Afanasyev11453142011-11-25 16:13:33 -0800216
217 // /**
218 // * @brief Enable pcap output the indicated Ccnx and interface pair.
219 // * @internal
220 // *
221 // * @param prefix Filename prefix to use for pcap 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 EnablePcapCcnxInternal (std::string prefix,
226 // Ptr<Ccnx> ccnx,
227 // uint32_t interface,
228 // bool explicitFilename);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700229
Alexander Afanasyev11453142011-11-25 16:13:33 -0800230 // /**
231 // * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
232 // * @internal
233 // *
234 // * @param stream An OutputStreamWrapper representing an existing file to use
235 // * when writing trace data.
236 // * @param prefix Filename prefix to use for ascii trace files.
237 // * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
238 // * @param interface Interface ID on the Ccnx on which you want to enable tracing.
239 // */
240 // virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
241 // std::string prefix,
242 // Ptr<Ccnx> ccnx,
243 // uint32_t interface,
244 // bool explicitFilename);
245
246 // // /**
247 // // * \internal
248 // // */
249 // // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700250
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700251 // /**
252 // * \internal
253 // */
Alexander Afanasyev11453142011-11-25 16:13:33 -0800254 // static void Cleanup (void);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700255
Alexander Afanasyev11453142011-11-25 16:13:33 -0800256 // /**
257 // * \internal
258 // */
259 // bool PcapHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700260
Alexander Afanasyev11453142011-11-25 16:13:33 -0800261 // /**
262 // * \internal
263 // */
264 // bool AsciiHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700265};
266
267} // namespace ns3
268
269#endif /* CCNX_STACK_HELPER_H */