blob: 78cc12191fe4456b3a1d1b9e05ef62951ef67611 [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 Afanasyev45b92d42011-08-14 23:11:38 -070028
29#include "ccnx-trace-helper.h"
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070030#include "ns3/ccnx-forwarding-helper.h"
31#include "ns3/ccnx.h"
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070032
33namespace ns3 {
34
35class Node;
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070036class CcnxFaceContainer;
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070037
38/**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070039 * \ingroup ccnx
40 * \defgroup ccnx-helpers Helpers
41 */
42/**
43 * \ingroup ccnx-helpers
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070044 * \brief Adding CCNx functionality to existing Nodes.
45 *
46 * This helper enables pcap and ascii tracing of events in the ccnx stack
47 * associated with a node. This is substantially similar to the tracing that
48 * happens in device helpers, but the important difference is that, well, there
49 * is no device. This means that the creation of output file names will change,
50 * and also the user-visible methods will not reference devices and therefore
51 * the number of trace enable methods is reduced.
52 *
53 * Normally we eschew multiple inheritance, however, the classes
54 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
55 * "mixins". A mixin is a self-contained class that encapsulates a general
56 * attribute or a set of functionality that may be of interest to many other
57 * classes.
58 */
59class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx
60{
61public:
62 /**
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070063 * \brief Create a new CcnxStackHelper with a default NDN_FLOODING forwarding stategy
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070064 */
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070065 CcnxStackHelper();
66
67 /**
68 * \brief Create a new CcnxStackHelper with a specified forwarding strategy
69 */
70 CcnxStackHelper (Ccnx::ForwardingStrategy);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070071
72 /**
Alexander Afanasyev0ab833e2011-08-18 15:49:13 -070073 * \brief Destroy the CcnxStackHelper
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070074 */
75 virtual ~CcnxStackHelper ();
76 CcnxStackHelper (const CcnxStackHelper &);
77 CcnxStackHelper &operator = (const CcnxStackHelper &o);
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
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -070090 SetForwardingStrategy (Ccnx::ForwardingStrategy strategy);
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 /**
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 Afanasyev45b92d42011-08-14 23:11:38 -0700154
155private:
Ilya Moiseenko25f7d4d2011-09-29 18:41:06 -0700156 CcnxForwardingHelper m_forwardingHelper;
157
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700158 /**
159 * @brief Enable pcap output the indicated Ccnx and interface pair.
160 * @internal
161 *
162 * @param prefix Filename prefix to use for pcap files.
163 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
164 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
165 */
166 virtual void EnablePcapCcnxInternal (std::string prefix,
167 Ptr<Ccnx> ccnx,
168 uint32_t interface,
169 bool explicitFilename);
170
171 /**
172 * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
173 * @internal
174 *
175 * @param stream An OutputStreamWrapper representing an existing file to use
176 * when writing trace data.
177 * @param prefix Filename prefix to use for ascii trace files.
178 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
179 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
180 */
181 virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
182 std::string prefix,
183 Ptr<Ccnx> ccnx,
184 uint32_t interface,
185 bool explicitFilename);
186
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700187 // /**
188 // * \internal
189 // */
190 // static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700191
192 /**
193 * \internal
194 */
195 static void Cleanup (void);
196
197 /**
198 * \internal
199 */
200 bool PcapHooked (Ptr<Ccnx> ccnx);
201
202 /**
203 * \internal
204 */
205 bool AsciiHooked (Ptr<Ccnx> ccnx);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700206};
207
208} // namespace ns3
209
210#endif /* CCNX_STACK_HELPER_H */