blob: 4ee4e2ff270670cf45748c466ce2d098bcdb2346 [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) 2010 University of Washington
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
19#include <stdint.h>
20#include <string>
21#include <fstream>
22
23#include "ns3/abort.h"
24#include "ns3/assert.h"
25#include "ns3/log.h"
26#include "ns3/ptr.h"
27#include "ns3/node.h"
28#include "ns3/names.h"
29#include "ns3/net-device.h"
30#include "ns3/pcap-file-wrapper.h"
31
32#include "ccnx-trace-helper.h"
33
34NS_LOG_COMPONENT_DEFINE ("CcnxTraceHelper");
35
36namespace ns3 {
37
38void
39PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, Ptr<Ccnx> ccnx, uint32_t interface, bool explicitFilename)
40{
41 EnablePcapCcnxInternal (prefix, ccnx, interface, explicitFilename);
42}
43
44void
45PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, std::string ccnxName, uint32_t interface, bool explicitFilename)
46{
47 Ptr<Ccnx> ccnx = Names::Find<Ccnx> (ccnxName);
48 EnablePcapCcnx (prefix, ccnx, interface, explicitFilename);
49}
50
51void
52PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, CcnxFaceContainer c)
53{
54 for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
55 {
56 std::pair<Ptr<Ccnx>, uint32_t> pair = *i;
57 EnablePcapCcnx (prefix, pair.first, pair.second, false);
58 }
59}
60
61void
62PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, NodeContainer n)
63{
64 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
65 {
66 Ptr<Node> node = *i;
67 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
68 if (ccnx)
69 {
70 for (uint32_t j = 0; j < ccnx->GetNFaces (); ++j)
71 {
72 EnablePcapCcnx (prefix, ccnx, j, false);
73 }
74 }
75 }
76}
77
78void
79PcapHelperForCcnx::EnablePcapCcnxAll (std::string prefix)
80{
81 EnablePcapCcnx (prefix, NodeContainer::GetGlobal ());
82}
83
84void
85PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
86{
87 NodeContainer n = NodeContainer::GetGlobal ();
88
89 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
90 {
91 Ptr<Node> node = *i;
92 if (node->GetId () != nodeid)
93 {
94 continue;
95 }
96
97 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
98 if (ccnx)
99 {
100 EnablePcapCcnx (prefix, ccnx, interface, explicitFilename);
101 }
102 return;
103 }
104}
105
106//
107// Public API
108//
109void
110AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, Ptr<Ccnx> ccnx, uint32_t interface, bool explicitFilename)
111{
112 EnableAsciiCcnxInternal (Ptr<OutputStreamWrapper> (), prefix, ccnx, interface, explicitFilename);
113}
114
115//
116// Public API
117//
118void
119AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, Ptr<Ccnx> ccnx, uint32_t interface)
120{
121 EnableAsciiCcnxInternal (stream, std::string (), ccnx, interface, false);
122}
123
124//
125// Public API
126//
127void
128AsciiTraceHelperForCcnx::EnableAsciiCcnx (
129 std::string prefix,
130 std::string ccnxName,
131 uint32_t interface,
132 bool explicitFilename)
133{
134 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, ccnxName, interface, explicitFilename);
135}
136
137//
138// Public API
139//
140void
141AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, std::string ccnxName, uint32_t interface)
142{
143 EnableAsciiCcnxImpl (stream, std::string (), ccnxName, interface, false);
144}
145
146//
147// Private API
148//
149void
150AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (
151 Ptr<OutputStreamWrapper> stream,
152 std::string prefix,
153 std::string ccnxName,
154 uint32_t interface,
155 bool explicitFilename)
156{
157 Ptr<Ccnx> ccnx = Names::Find<Ccnx> (ccnxName);
158 EnableAsciiCcnxInternal (stream, prefix, ccnx, interface, explicitFilename);
159}
160
161//
162// Public API
163//
164void
165AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, CcnxFaceContainer c)
166{
167 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, c);
168}
169
170//
171// Public API
172//
173void
174AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, CcnxFaceContainer c)
175{
176 EnableAsciiCcnxImpl (stream, std::string (), c);
177}
178
179//
180// Private API
181//
182void
183AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, CcnxFaceContainer c)
184{
185 for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
186 {
187 std::pair<Ptr<Ccnx>, uint32_t> pair = *i;
188 EnableAsciiCcnxInternal (stream, prefix, pair.first, pair.second, false);
189 }
190}
191
192//
193// Public API
194//
195void
196AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, NodeContainer n)
197{
198 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, n);
199}
200
201//
202// Public API
203//
204void
205AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, NodeContainer n)
206{
207 EnableAsciiCcnxImpl (stream, std::string (), n);
208}
209
210//
211// Private API
212//
213void
214AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n)
215{
216 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
217 {
218 Ptr<Node> node = *i;
219 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
220 if (ccnx)
221 {
222 for (uint32_t j = 0; j < ccnx->GetNFaces (); ++j)
223 {
224 EnableAsciiCcnxInternal (stream, prefix, ccnx, j, false);
225 }
226 }
227 }
228}
229
230//
231// Public API
232//
233void
234AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (std::string prefix)
235{
236 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, NodeContainer::GetGlobal ());
237}
238
239//
240// Public API
241//
242void
243AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (Ptr<OutputStreamWrapper> stream)
244{
245 EnableAsciiCcnxImpl (stream, std::string (), NodeContainer::GetGlobal ());
246}
247
248//
249// Public API
250//
251void
252AsciiTraceHelperForCcnx::EnableAsciiCcnx (
253 Ptr<OutputStreamWrapper> stream,
254 uint32_t nodeid,
255 uint32_t interface,
256 bool explicitFilename)
257{
258 EnableAsciiCcnxImpl (stream, std::string (), nodeid, interface, explicitFilename);
259}
260
261//
262// Public API
263//
264void
265AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
266{
267 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, nodeid, interface, explicitFilename);
268}
269
270//
271// Private API
272//
273void
274AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (
275 Ptr<OutputStreamWrapper> stream,
276 std::string prefix,
277 uint32_t nodeid,
278 uint32_t interface,
279 bool explicitFilename)
280{
281 NodeContainer n = NodeContainer::GetGlobal ();
282
283 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
284 {
285 Ptr<Node> node = *i;
286 if (node->GetId () != nodeid)
287 {
288 continue;
289 }
290
291 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
292 if (ccnx)
293 {
294 EnableAsciiCcnxInternal (stream, prefix, ccnx, interface, explicitFilename);
295 }
296
297 return;
298 }
299}
300
301
302} // namespace ns3
303