blob: d692b051392ba5e4d66178f646ffc0b337a06127 [file] [log] [blame]
Alexander Afanasyev45b92d42011-08-14 23:11:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
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
24#include "ns3/node-container.h"
25#include "ns3/net-device-container.h"
26#include "ns3/packet.h"
27#include "ns3/ptr.h"
28#include "ns3/object-factory.h"
29#include "ns3/ccnx-l3-protocol.h"
30
31#include "ccnx-trace-helper.h"
32
33namespace ns3 {
34
35class Node;
36class CcnxForwardingHelper;
37
38/**
39 * \brief Adding CCNx functionality to existing Nodes.
40 *
41 * This helper enables pcap and ascii tracing of events in the ccnx stack
42 * associated with a node. This is substantially similar to the tracing that
43 * happens in device helpers, but the important difference is that, well, there
44 * is no device. This means that the creation of output file names will change,
45 * and also the user-visible methods will not reference devices and therefore
46 * the number of trace enable methods is reduced.
47 *
48 * Normally we eschew multiple inheritance, however, the classes
49 * PcapUserHelperForCcnx and AsciiTraceUserHelperForCcnx are treated as
50 * "mixins". A mixin is a self-contained class that encapsulates a general
51 * attribute or a set of functionality that may be of interest to many other
52 * classes.
53 */
54class CcnxStackHelper : public PcapHelperForCcnx, public AsciiTraceHelperForCcnx
55{
56public:
57 /**
58 * Create a new CcnxStackHelper which <empty> forwarding by default.
59 *
60 * \todo set non-empty default forwarding
61 */
62 CcnxStackHelper ();
63
64 /**
65 * Destroy the CcnxStackHelper
66 */
67 virtual ~CcnxStackHelper ();
68 CcnxStackHelper (const CcnxStackHelper &);
69 CcnxStackHelper &operator = (const CcnxStackHelper &o);
70
71 /**
72 * Return helper internal state to that of a newly constructed one
73 */
74 void Reset ();
75
76 /**
77 * \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 */
84 void SetForwardingHelper (const CcnxForwardingHelper &forwarding);
85
86 /**
87 * Install CCNx stack on the node
88 *
89 * This method will assert if called on a node that already has Ccnx object
90 * installed on it
91 *
92 * \param nodeName The name of the node on which to install the stack.
93 */
94 void Install (std::string nodeName) const;
95
96 /**
97 * Install CCNx stack on the node
98 *
99 * This method will assert if called on a node that already has Ccnx object
100 * installed on it
101 *
102 * \param node The node on which to install the stack.
103 */
104 void Install (Ptr<Node> node) const;
105
106 /**
107 * Install CCNx stack on each node in the input container
108 *
109 * The program will assert if this method is called on a container with a node
110 * that already has an ccnx object aggregated to it.
111 *
112 * \param c NodeContainer that holds the set of nodes on which to install the
113 * new stacks.
114 */
115 void Install (NodeContainer c) const;
116
117 /**
118 * Install CCNx stack on all nodes in the simulation
119 */
120 void
121 InstallAll () const;
122
123 /**
124 * \brief Enable/disable ccnx stack install.
125 * \param enable enable state
126 */
127 void SetCcnxStackInstall (bool enable);
128
129private:
130 /**
131 * @brief Enable pcap output the indicated Ccnx and interface pair.
132 * @internal
133 *
134 * @param prefix Filename prefix to use for pcap files.
135 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
136 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
137 */
138 virtual void EnablePcapCcnxInternal (std::string prefix,
139 Ptr<Ccnx> ccnx,
140 uint32_t interface,
141 bool explicitFilename);
142
143 /**
144 * @brief Enable ascii trace output on the indicated Ccnx and interface pair.
145 * @internal
146 *
147 * @param stream An OutputStreamWrapper representing an existing file to use
148 * when writing trace data.
149 * @param prefix Filename prefix to use for ascii trace files.
150 * @param ccnx Ptr to the Ccnx interface on which you want to enable tracing.
151 * @param interface Interface ID on the Ccnx on which you want to enable tracing.
152 */
153 virtual void EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> stream,
154 std::string prefix,
155 Ptr<Ccnx> ccnx,
156 uint32_t interface,
157 bool explicitFilename);
158
159 void Initialize (void);
160 ObjectFactory m_tcpFactory;
161 const CcnxForwardingHelper *m_forwarding;
162
163 /**
164 * \internal
165 */
166 static void CreateAndAggregateObjectFromTypeId (Ptr<Node> node, const std::string typeId);
167
168 /**
169 * \internal
170 */
171 static void Cleanup (void);
172
173 /**
174 * \internal
175 */
176 bool PcapHooked (Ptr<Ccnx> ccnx);
177
178 /**
179 * \internal
180 */
181 bool AsciiHooked (Ptr<Ccnx> ccnx);
182
183 /**
184 * \brief Ccnx install state (enabled/disabled) ?
185 */
186 bool m_ccnxEnabled;
187};
188
189} // namespace ns3
190
191#endif /* CCNX_STACK_HELPER_H */