A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
internet-trace-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "ns3/abort.h"
10#include "ns3/assert.h"
11#include "ns3/log.h"
12#include "ns3/names.h"
13#include "ns3/net-device.h"
14#include "ns3/node.h"
15#include "ns3/pcap-file-wrapper.h"
16#include "ns3/ptr.h"
17
18#include <fstream>
19#include <stdint.h>
20#include <string>
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("InternetTraceHelper");
26
27void
29 Ptr<Ipv4> ipv4,
30 uint32_t interface,
31 bool explicitFilename)
32{
33 EnablePcapIpv4Internal(prefix, ipv4, interface, explicitFilename);
34}
35
36void
38 std::string ipv4Name,
39 uint32_t interface,
40 bool explicitFilename)
41{
42 Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
43 EnablePcapIpv4(prefix, ipv4, interface, explicitFilename);
44}
45
46void
48{
49 for (auto i = c.Begin(); i != c.End(); ++i)
50 {
51 EnablePcapIpv4(prefix, (*i).first, (*i).second, false);
52 }
53}
54
55void
57{
58 for (auto i = n.Begin(); i != n.End(); ++i)
59 {
60 Ptr<Node> node = *i;
61 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
62 if (ipv4)
63 {
64 for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
65 {
66 EnablePcapIpv4(prefix, ipv4, j, false);
67 }
68 }
69 }
70}
71
72void
77
78void
80 uint32_t nodeid,
81 uint32_t interface,
82 bool explicitFilename)
83{
85
86 for (auto i = n.Begin(); i != n.End(); ++i)
87 {
88 Ptr<Node> node = *i;
89 if (node->GetId() != nodeid)
90 {
91 continue;
92 }
93
94 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
95 if (ipv4)
96 {
97 EnablePcapIpv4(prefix, ipv4, interface, explicitFilename);
98 }
99 return;
100 }
101}
102
103//
104// Public API
105//
106void
108 Ptr<Ipv4> ipv4,
109 uint32_t interface,
110 bool explicitFilename)
111{
112 EnableAsciiIpv4Internal(Ptr<OutputStreamWrapper>(), prefix, ipv4, interface, explicitFilename);
113}
114
115//
116// Public API
117//
118void
120 Ptr<Ipv4> ipv4,
121 uint32_t interface)
122{
123 EnableAsciiIpv4Internal(stream, std::string(), ipv4, interface, false);
124}
125
126//
127// Public API
128//
129void
131 std::string ipv4Name,
132 uint32_t interface,
133 bool explicitFilename)
134{
135 EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, ipv4Name, interface, explicitFilename);
136}
137
138//
139// Public API
140//
141void
143 std::string ipv4Name,
144 uint32_t interface)
145{
146 EnableAsciiIpv4Impl(stream, std::string(), ipv4Name, interface, false);
147}
148
149//
150// Private API
151//
152void
154 std::string prefix,
155 std::string ipv4Name,
156 uint32_t interface,
157 bool explicitFilename)
158{
159 Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
160 EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
161}
162
163//
164// Public API
165//
166void
171
172//
173// Public API
174//
175void
180
181//
182// Private API
183//
184void
186 std::string prefix,
188{
189 for (auto i = c.Begin(); i != c.End(); ++i)
190 {
191 EnableAsciiIpv4Internal(stream, prefix, (*i).first, (*i).second, false);
192 }
193}
194
195//
196// Public API
197//
198void
203
204//
205// Public API
206//
207void
212
213//
214// Private API
215//
216void
218 std::string prefix,
220{
221 for (auto i = n.Begin(); i != n.End(); ++i)
222 {
223 Ptr<Node> node = *i;
224 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
225 if (ipv4)
226 {
227 for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
228 {
229 EnableAsciiIpv4Internal(stream, prefix, ipv4, j, false);
230 }
231 }
232 }
233}
234
235//
236// Public API
237//
238void
243
244//
245// Public API
246//
247void
252
253//
254// Public API
255//
256void
258 uint32_t nodeid,
259 uint32_t interface,
260 bool explicitFilename)
261{
262 EnableAsciiIpv4Impl(stream, std::string(), nodeid, interface, explicitFilename);
263}
264
265//
266// Public API
267//
268void
270 uint32_t nodeid,
271 uint32_t interface,
272 bool explicitFilename)
273{
274 EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
275}
276
277//
278// Private API
279//
280void
282 std::string prefix,
283 uint32_t nodeid,
284 uint32_t interface,
285 bool explicitFilename)
286{
288
289 for (auto i = n.Begin(); i != n.End(); ++i)
290 {
291 Ptr<Node> node = *i;
292 if (node->GetId() != nodeid)
293 {
294 continue;
295 }
296
297 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
298 if (ipv4)
299 {
300 EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
301 }
302
303 return;
304 }
305}
306
307void
309 Ptr<Ipv6> ipv6,
310 uint32_t interface,
311 bool explicitFilename)
312{
313 EnablePcapIpv6Internal(prefix, ipv6, interface, explicitFilename);
314}
315
316void
318 std::string ipv6Name,
319 uint32_t interface,
320 bool explicitFilename)
321{
322 Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
323 EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
324}
325
326void
328{
329 for (auto i = c.Begin(); i != c.End(); ++i)
330 {
331 EnablePcapIpv6(prefix, (*i).first, (*i).second, false);
332 }
333}
334
335void
337{
338 for (auto i = n.Begin(); i != n.End(); ++i)
339 {
340 Ptr<Node> node = *i;
341 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
342 if (ipv6)
343 {
344 for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
345 {
346 EnablePcapIpv6(prefix, ipv6, j, false);
347 }
348 }
349 }
350}
351
352void
357
358void
360 uint32_t nodeid,
361 uint32_t interface,
362 bool explicitFilename)
363{
365
366 for (auto i = n.Begin(); i != n.End(); ++i)
367 {
368 Ptr<Node> node = *i;
369 if (node->GetId() != nodeid)
370 {
371 continue;
372 }
373
374 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
375 if (ipv6)
376 {
377 EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
378 }
379 return;
380 }
381}
382
383//
384// Public API
385//
386void
388 Ptr<Ipv6> ipv6,
389 uint32_t interface,
390 bool explicitFilename)
391{
392 EnableAsciiIpv6Internal(Ptr<OutputStreamWrapper>(), prefix, ipv6, interface, explicitFilename);
393}
394
395//
396// Public API
397//
398void
400 Ptr<Ipv6> ipv6,
401 uint32_t interface)
402{
403 EnableAsciiIpv6Internal(stream, std::string(), ipv6, interface, false);
404}
405
406//
407// Public API
408//
409void
411 std::string ipv6Name,
412 uint32_t interface,
413 bool explicitFilename)
414{
415 EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, ipv6Name, interface, explicitFilename);
416}
417
418//
419// Public API
420//
421void
423 std::string ipv6Name,
424 uint32_t interface)
425{
426 EnableAsciiIpv6Impl(stream, std::string(), ipv6Name, interface, false);
427}
428
429//
430// Private API
431//
432void
434 std::string prefix,
435 std::string ipv6Name,
436 uint32_t interface,
437 bool explicitFilename)
438{
439 Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
440 EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
441}
442
443//
444// Public API
445//
446void
451
452//
453// Public API
454//
455void
460
461//
462// Private API
463//
464void
466 std::string prefix,
468{
469 for (auto i = c.Begin(); i != c.End(); ++i)
470 {
471 EnableAsciiIpv6Internal(stream, prefix, (*i).first, (*i).second, false);
472 }
473}
474
475//
476// Public API
477//
478void
483
484//
485// Public API
486//
487void
492
493//
494// Private API
495//
496void
498 std::string prefix,
500{
501 for (auto i = n.Begin(); i != n.End(); ++i)
502 {
503 Ptr<Node> node = *i;
504 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
505 if (ipv6)
506 {
507 for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
508 {
509 EnableAsciiIpv6Internal(stream, prefix, ipv6, j, false);
510 }
511 }
512 }
513}
514
515//
516// Public API
517//
518void
523
524//
525// Public API
526//
527void
532
533//
534// Public API
535//
536void
538 uint32_t nodeid,
539 uint32_t interface)
540{
541 EnableAsciiIpv6Impl(stream, std::string(), nodeid, interface, false);
542}
543
544//
545// Public API
546//
547void
549 uint32_t nodeid,
550 uint32_t interface,
551 bool explicitFilename)
552{
553 EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
554}
555
556//
557// Private API
558//
559void
561 std::string prefix,
562 uint32_t nodeid,
563 uint32_t interface,
564 bool explicitFilename)
565{
567
568 for (auto i = n.Begin(); i != n.End(); ++i)
569 {
570 Ptr<Node> node = *i;
571 if (node->GetId() != nodeid)
572 {
573 continue;
574 }
575
576 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
577 if (ipv6)
578 {
579 EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
580 }
581
582 return;
583 }
584}
585
586} // namespace ns3
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:69
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
Keep track of a set of IPv6 interfaces.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first pair in the container.
static Ptr< T > Find(std::string path)
Given a name path string, look to see if there's an object in the system with that associated to it.
Definition names.h:443
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
static NodeContainer GetGlobal()
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Every class exported by the ns3 library is enclosed in the ns3 namespace.