blob: 7308241dc6bf065d8a63a3617866ed90d0b64e99 [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 *
18 * Author:
19 */
20
21#ifndef CCNX_STACK_HELPER_H
22#define CCNX_STACK_HELPER_H
23
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070024#include "ns3/packet.h"
25#include "ns3/ptr.h"
26#include "ns3/object-factory.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070027
28#include "ccnx-trace-helper.h"
29
30namespace ns3 {
31
32class Node;
33class CcnxForwardingHelper;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070034class CcnxFaceContainer;
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 */
57class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx
58{
59public:
60 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070061 * \brief Create a new CcnxStackHelper which <empty> forwarding by default.
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070062 *
63 * \todo set non-empty default forwarding
64 */
65 CcnxStackHelper ();
66
67 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070068 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070069 */
70 virtual ~CcnxStackHelper ();
71 CcnxStackHelper (const CcnxStackHelper &);
72 CcnxStackHelper &operator = (const CcnxStackHelper &o);
73
74 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070075 * \brief Return helper internal state to that of a newly constructed one
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070076 */
77 void Reset ();
78
79 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070080 * Set forwarding strategy helper
81 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070082 * \param forwarding a new forwarding helper
83 *
84 * Set the forwarding helper to use during Install. The forwarding helper is
85 * really an object factory which is used to create an object of type
86 * ns3::CcnxFrProtocol per node. This forwarding object is then associated to
87 * a single ns3::Ccnx object through its ns3::Ccnx::SetforwardingProtocol.
88 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070089 void
90 SetForwardingHelper (const CcnxForwardingHelper &forwarding);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070091
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 /**
145 * \brief Enable/disable ccnx stack install.
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700146 *
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700147 * \param enable enable state
148 */
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -0700149 void
150 SetCcnxStackInstall (bool enable);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700151
152private:
153 /**
154 * @brief Enable pcap output the indicated Ccnx and interface pair.
155 * @internal
156 *
157 * @param prefix Filename prefix to use for pcap files.
158 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
159 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
160 */
161 virtual void EnablePcapCcnxInternal (std::string prefix,
162 Ptr<Ccnx> ccnx,
163 uint32_t interface,
164 bool explicitFilename);
165
166 /**
167 * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
168 * @internal
169 *
170 * @param stream An OutputStreamWrapper representing an existing file to use
171 * when writing trace data.
172 * @param prefix Filename prefix to use for ascii trace files.
173 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
174 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
175 */
176 virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
177 std::string prefix,
178 Ptr<Ccnx> ccnx,
179 uint32_t interface,
180 bool explicitFilename);
181
182 void Initialize (void);
183 ObjectFactory m_tcpFactory;
184 const CcnxForwardingHelper *m_forwarding;
185
186 /**
187 * \internal
188 */
189 static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
190
191 /**
192 * \internal
193 */
194 static void Cleanup (void);
195
196 /**
197 * \internal
198 */
199 bool PcapHooked (Ptr<Ccnx> ccnx);
200
201 /**
202 * \internal
203 */
204 bool AsciiHooked (Ptr<Ccnx> ccnx);
205
206 /**
207 * \brief Ccnx install state (enabled/disabled) ?
208 */
209 bool m_ccnxEnabled;
210};
211
212} // namespace ns3
213
214#endif /* CCNX_STACK_HELPER_H */