blob: a4b7170fd9b6c96403fe8101f40393280c334f8d [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
Alexander Afanasyeveface602011-08-17 17:50:12 -070051 /// \todo This call is broken
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070052void
53PcapHelperForCcnx::EnablePcapCcnx (std::string prefix, CcnxFaceContainer c)
54{
55 for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
56 {
Alexander Afanasyeveface602011-08-17 17:50:12 -070057 // EnablePcapCcnx (prefix, (*i)->GetCcnx (), 0,false);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -070058 }
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
Alexander Afanasyeveface602011-08-17 17:50:12 -0700181// \todo This method is broken
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700182void
183AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, CcnxFaceContainer c)
184{
185 for (CcnxFaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
186 {
Alexander Afanasyeveface602011-08-17 17:50:12 -0700187 // EnableAsciiCcnxInternal (stream, prefix, pair.first, pair.second, false);
Alexander Afanasyev45b92d42011-08-14 23:11:38 -0700188 }
189}
190
191//
192// Public API
193//
194void
195AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, NodeContainer n)
196{
197 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, n);
198}
199
200//
201// Public API
202//
203void
204AsciiTraceHelperForCcnx::EnableAsciiCcnx (Ptr<OutputStreamWrapper> stream, NodeContainer n)
205{
206 EnableAsciiCcnxImpl (stream, std::string (), n);
207}
208
209//
210// Private API
211//
212void
213AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> stream, std::string prefix, NodeContainer n)
214{
215 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
216 {
217 Ptr<Node> node = *i;
218 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
219 if (ccnx)
220 {
221 for (uint32_t j = 0; j < ccnx->GetNFaces (); ++j)
222 {
223 EnableAsciiCcnxInternal (stream, prefix, ccnx, j, false);
224 }
225 }
226 }
227}
228
229//
230// Public API
231//
232void
233AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (std::string prefix)
234{
235 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, NodeContainer::GetGlobal ());
236}
237
238//
239// Public API
240//
241void
242AsciiTraceHelperForCcnx::EnableAsciiCcnxAll (Ptr<OutputStreamWrapper> stream)
243{
244 EnableAsciiCcnxImpl (stream, std::string (), NodeContainer::GetGlobal ());
245}
246
247//
248// Public API
249//
250void
251AsciiTraceHelperForCcnx::EnableAsciiCcnx (
252 Ptr<OutputStreamWrapper> stream,
253 uint32_t nodeid,
254 uint32_t interface,
255 bool explicitFilename)
256{
257 EnableAsciiCcnxImpl (stream, std::string (), nodeid, interface, explicitFilename);
258}
259
260//
261// Public API
262//
263void
264AsciiTraceHelperForCcnx::EnableAsciiCcnx (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
265{
266 EnableAsciiCcnxImpl (Ptr<OutputStreamWrapper> (), prefix, nodeid, interface, explicitFilename);
267}
268
269//
270// Private API
271//
272void
273AsciiTraceHelperForCcnx::EnableAsciiCcnxImpl (
274 Ptr<OutputStreamWrapper> stream,
275 std::string prefix,
276 uint32_t nodeid,
277 uint32_t interface,
278 bool explicitFilename)
279{
280 NodeContainer n = NodeContainer::GetGlobal ();
281
282 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
283 {
284 Ptr<Node> node = *i;
285 if (node->GetId () != nodeid)
286 {
287 continue;
288 }
289
290 Ptr<Ccnx> ccnx = node->GetObject<Ccnx> ();
291 if (ccnx)
292 {
293 EnableAsciiCcnxInternal (stream, prefix, ccnx, interface, explicitFilename);
294 }
295
296 return;
297 }
298}
299
300
301} // namespace ns3
302