A Discrete-Event Network Simulator
API
internet-trace-helper.cc
Go to the documentation of this file.
1/* -*- 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
33
34namespace ns3 {
35
36NS_LOG_COMPONENT_DEFINE ("InternetTraceHelper");
37
38void
39PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
40{
41 EnablePcapIpv4Internal (prefix, ipv4, interface, explicitFilename);
42}
43
44void
45PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, std::string ipv4Name, uint32_t interface, bool explicitFilename)
46{
47 Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name);
48 EnablePcapIpv4 (prefix, ipv4, interface, explicitFilename);
49}
50
51void
53{
54 for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
55 {
56 std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
57 EnablePcapIpv4 (prefix, pair.first, pair.second, false);
58 }
59}
60
61void
63{
64 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
65 {
66 Ptr<Node> node = *i;
67 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
68 if (ipv4)
69 {
70 for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j)
71 {
72 EnablePcapIpv4 (prefix, ipv4, j, false);
73 }
74 }
75 }
76}
77
78void
80{
82}
83
84void
85PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
86{
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<Ipv4> ipv4 = node->GetObject<Ipv4> ();
98 if (ipv4)
99 {
100 EnablePcapIpv4 (prefix, ipv4, interface, explicitFilename);
101 }
102 return;
103 }
104}
105
106//
107// Public API
108//
109void
110AsciiTraceHelperForIpv4::EnableAsciiIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
111{
112 EnableAsciiIpv4Internal (Ptr<OutputStreamWrapper> (), prefix, ipv4, interface, explicitFilename);
113}
114
115//
116// Public API
117//
118void
120{
121 EnableAsciiIpv4Internal (stream, std::string (), ipv4, interface, false);
122}
123
124//
125// Public API
126//
127void
129 std::string prefix,
130 std::string ipv4Name,
131 uint32_t interface,
132 bool explicitFilename)
133{
134 EnableAsciiIpv4Impl (Ptr<OutputStreamWrapper> (), prefix, ipv4Name, interface, explicitFilename);
135}
136
137//
138// Public API
139//
140void
142{
143 EnableAsciiIpv4Impl (stream, std::string (), ipv4Name, interface, false);
144}
145
146//
147// Private API
148//
149void
152 std::string prefix,
153 std::string ipv4Name,
154 uint32_t interface,
155 bool explicitFilename)
156{
157 Ptr<Ipv4> ipv4 = Names::Find<Ipv4> (ipv4Name);
158 EnableAsciiIpv4Internal (stream, prefix, ipv4, interface, explicitFilename);
159}
160
161//
162// Public API
163//
164void
166{
168}
169
170//
171// Public API
172//
173void
175{
176 EnableAsciiIpv4Impl (stream, std::string (), c);
177}
178
179//
180// Private API
181//
182void
184{
185 for (Ipv4InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
186 {
187 std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
188 EnableAsciiIpv4Internal (stream, prefix, pair.first, pair.second, false);
189 }
190}
191
192//
193// Public API
194//
195void
197{
199}
200
201//
202// Public API
203//
204void
206{
207 EnableAsciiIpv4Impl (stream, std::string (), n);
208}
209
210//
211// Private API
212//
213void
215{
216 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
217 {
218 Ptr<Node> node = *i;
219 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
220 if (ipv4)
221 {
222 for (uint32_t j = 0; j < ipv4->GetNInterfaces (); ++j)
223 {
224 EnableAsciiIpv4Internal (stream, prefix, ipv4, j, false);
225 }
226 }
227 }
228}
229
230//
231// Public API
232//
233void
235{
237}
238
239//
240// Public API
241//
242void
244{
245 EnableAsciiIpv4Impl (stream, std::string (), NodeContainer::GetGlobal ());
246}
247
248//
249// Public API
250//
251void
254 uint32_t nodeid,
255 uint32_t interface,
256 bool explicitFilename)
257{
258 EnableAsciiIpv4Impl (stream, std::string (), nodeid, interface, explicitFilename);
259}
260
261//
262// Public API
263//
264void
265AsciiTraceHelperForIpv4::EnableAsciiIpv4 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
266{
267 EnableAsciiIpv4Impl (Ptr<OutputStreamWrapper> (), prefix, nodeid, interface, explicitFilename);
268}
269
270//
271// Private API
272//
273void
276 std::string prefix,
277 uint32_t nodeid,
278 uint32_t interface,
279 bool explicitFilename)
280{
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<Ipv4> ipv4 = node->GetObject<Ipv4> ();
292 if (ipv4)
293 {
294 EnableAsciiIpv4Internal (stream, prefix, ipv4, interface, explicitFilename);
295 }
296
297 return;
298 }
299}
300
301void
302PcapHelperForIpv6::EnablePcapIpv6 (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
303{
304 EnablePcapIpv6Internal (prefix, ipv6, interface, explicitFilename);
305}
306
307void
308PcapHelperForIpv6::EnablePcapIpv6 (std::string prefix, std::string ipv6Name, uint32_t interface, bool explicitFilename)
309{
310 Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name);
311 EnablePcapIpv6 (prefix, ipv6, interface, explicitFilename);
312}
313
314void
316{
317 for (Ipv6InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
318 {
319 std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
320 EnablePcapIpv6 (prefix, pair.first, pair.second, false);
321 }
322}
323
324void
326{
327 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
328 {
329 Ptr<Node> node = *i;
330 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
331 if (ipv6)
332 {
333 for (uint32_t j = 0; j < ipv6->GetNInterfaces (); ++j)
334 {
335 EnablePcapIpv6 (prefix, ipv6, j, false);
336 }
337 }
338 }
339}
340
341void
343{
345}
346
347void
348PcapHelperForIpv6::EnablePcapIpv6 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
349{
351
352 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
353 {
354 Ptr<Node> node = *i;
355 if (node->GetId () != nodeid)
356 {
357 continue;
358 }
359
360 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
361 if (ipv6)
362 {
363 EnablePcapIpv6 (prefix, ipv6, interface, explicitFilename);
364 }
365 return;
366 }
367}
368
369//
370// Public API
371//
372void
373AsciiTraceHelperForIpv6::EnableAsciiIpv6 (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
374{
375 EnableAsciiIpv6Internal (Ptr<OutputStreamWrapper> (), prefix, ipv6, interface, explicitFilename);
376}
377
378//
379// Public API
380//
381void
383{
384 EnableAsciiIpv6Internal (stream, std::string (), ipv6, interface, false);
385}
386
387//
388// Public API
389//
390void
391AsciiTraceHelperForIpv6::EnableAsciiIpv6 (std::string prefix, std::string ipv6Name, uint32_t interface, bool explicitFilename)
392{
393 EnableAsciiIpv6Impl (Ptr<OutputStreamWrapper> (), prefix, ipv6Name, interface, explicitFilename);
394}
395
396//
397// Public API
398//
399void
401{
402 EnableAsciiIpv6Impl (stream, std::string (), ipv6Name, interface, false);
403}
404
405//
406// Private API
407//
408void
411 std::string prefix,
412 std::string ipv6Name,
413 uint32_t interface,
414 bool explicitFilename)
415{
416 Ptr<Ipv6> ipv6 = Names::Find<Ipv6> (ipv6Name);
417 EnableAsciiIpv6Internal (stream, prefix, ipv6, interface, explicitFilename);
418}
419
420//
421// Public API
422//
423void
425{
427}
428
429//
430// Public API
431//
432void
434{
435 EnableAsciiIpv6Impl (stream, std::string (), c);
436}
437
438//
439// Private API
440//
441void
443{
444 for (Ipv6InterfaceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
445 {
446 std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
447 EnableAsciiIpv6Internal (stream, prefix, pair.first, pair.second, false);
448 }
449}
450
451//
452// Public API
453//
454void
456{
458}
459
460//
461// Public API
462//
463void
465{
466 EnableAsciiIpv6Impl (stream, std::string (), n);
467}
468
469//
470// Private API
471//
472void
474{
475 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
476 {
477 Ptr<Node> node = *i;
478 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
479 if (ipv6)
480 {
481 for (uint32_t j = 0; j < ipv6->GetNInterfaces (); ++j)
482 {
483 EnableAsciiIpv6Internal (stream, prefix, ipv6, j, false);
484 }
485 }
486 }
487}
488
489//
490// Public API
491//
492void
494{
496}
497
498//
499// Public API
500//
501void
503{
504 EnableAsciiIpv6Impl (stream, std::string (), NodeContainer::GetGlobal ());
505}
506
507//
508// Public API
509//
510void
512{
513 EnableAsciiIpv6Impl (stream, std::string (), nodeid, interface, false);
514}
515
516//
517// Public API
518//
519void
520AsciiTraceHelperForIpv6::EnableAsciiIpv6 (std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
521{
522 EnableAsciiIpv6Impl (Ptr<OutputStreamWrapper> (), prefix, nodeid, interface, explicitFilename);
523}
524
525//
526// Private API
527//
528void
531 std::string prefix,
532 uint32_t nodeid,
533 uint32_t interface,
534 bool explicitFilename)
535{
537
538 for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
539 {
540 Ptr<Node> node = *i;
541 if (node->GetId () != nodeid)
542 {
543 continue;
544 }
545
546 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6> ();
547 if (ipv6)
548 {
549 EnableAsciiIpv6Internal (stream, prefix, ipv6, interface, explicitFilename);
550 }
551
552 return;
553 }
554}
555
556} // namespace ns3
557
void EnableAsciiIpv4Impl(Ptr< OutputStreamWrapper > stream, std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
Enable ascii trace output on the Ipv4 and interface pair specified by a global node-id (of a previous...
void EnableAsciiIpv4All(std::string prefix)
Enable ascii trace output on all Ipv4 and interface pairs existing in the set of all nodes created in...
void EnableAsciiIpv4(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename=false)
Enable ascii trace output on the indicated Ipv4 and interface pair.
virtual void EnableAsciiIpv4Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename)=0
Enable ascii trace output on the indicated Ipv4 and interface pair.
void EnableAsciiIpv6All(std::string prefix)
Enable ascii trace output on all Ipv6 and interface pairs existing in the set of all nodes created in...
void EnableAsciiIpv6(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename=false)
Enable ascii trace output on the indicated Ipv6 and interface pair.
virtual void EnableAsciiIpv6Internal(Ptr< OutputStreamWrapper > stream, std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)=0
Enable ascii trace output on the indicated Ipv6 and interface pair.
void EnableAsciiIpv6Impl(Ptr< OutputStreamWrapper > stream, std::string prefix, uint32_t nodeid, uint32_t interface, bool explicitFilename)
Enable ascii trace output on the Ipv6 and interface pair specified by a global node-id (of a previous...
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:82
Keep track of a set of IPv6 interfaces.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
uint32_t GetId(void) const
Definition: node.cc:109
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
virtual void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename)=0
Enable pcap output the indicated Ipv4 and interface pair.
void EnablePcapIpv4(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename=false)
Enable pcap output the indicated Ipv4 and interface pair.
void EnablePcapIpv4All(std::string prefix)
Enable pcap output on all Ipv4 and interface pairs existing in the set of all nodes created in the si...
void EnablePcapIpv6All(std::string prefix)
Enable pcap output on all Ipv6 and interface pairs existing in the set of all nodes created in the si...
void EnablePcapIpv6(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename=false)
Enable pcap output the indicated Ipv6 and interface pair.
virtual void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)=0
Enable pcap output the indicated Ipv6 and interface pair.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Every class exported by the ns3 library is enclosed in the ns3 namespace.