A Discrete-Event Network Simulator
API
internet-trace-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #include "internet-trace-helper.h"
19 
20 #include "ns3/abort.h"
21 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/names.h"
24 #include "ns3/net-device.h"
25 #include "ns3/node.h"
26 #include "ns3/pcap-file-wrapper.h"
27 #include "ns3/ptr.h"
28 
29 #include <fstream>
30 #include <stdint.h>
31 #include <string>
32 
33 namespace ns3
34 {
35 
36 NS_LOG_COMPONENT_DEFINE("InternetTraceHelper");
37 
38 void
41  uint32_t interface,
42  bool explicitFilename)
43 {
44  EnablePcapIpv4Internal(prefix, ipv4, interface, explicitFilename);
45 }
46 
47 void
49  std::string ipv4Name,
50  uint32_t interface,
51  bool explicitFilename)
52 {
53  Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
54  EnablePcapIpv4(prefix, ipv4, interface, explicitFilename);
55 }
56 
57 void
59 {
60  for (auto i = c.Begin(); i != c.End(); ++i)
61  {
62  EnablePcapIpv4(prefix, (*i).first, (*i).second, false);
63  }
64 }
65 
66 void
68 {
69  for (auto i = n.Begin(); i != n.End(); ++i)
70  {
71  Ptr<Node> node = *i;
72  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
73  if (ipv4)
74  {
75  for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
76  {
77  EnablePcapIpv4(prefix, ipv4, j, false);
78  }
79  }
80  }
81 }
82 
83 void
85 {
87 }
88 
89 void
91  uint32_t nodeid,
92  uint32_t interface,
93  bool explicitFilename)
94 {
96 
97  for (auto i = n.Begin(); i != n.End(); ++i)
98  {
99  Ptr<Node> node = *i;
100  if (node->GetId() != nodeid)
101  {
102  continue;
103  }
104 
105  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
106  if (ipv4)
107  {
108  EnablePcapIpv4(prefix, ipv4, interface, explicitFilename);
109  }
110  return;
111  }
112 }
113 
114 //
115 // Public API
116 //
117 void
119  Ptr<Ipv4> ipv4,
120  uint32_t interface,
121  bool explicitFilename)
122 {
123  EnableAsciiIpv4Internal(Ptr<OutputStreamWrapper>(), prefix, ipv4, interface, explicitFilename);
124 }
125 
126 //
127 // Public API
128 //
129 void
131  Ptr<Ipv4> ipv4,
132  uint32_t interface)
133 {
134  EnableAsciiIpv4Internal(stream, std::string(), ipv4, interface, false);
135 }
136 
137 //
138 // Public API
139 //
140 void
142  std::string ipv4Name,
143  uint32_t interface,
144  bool explicitFilename)
145 {
146  EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, ipv4Name, interface, explicitFilename);
147 }
148 
149 //
150 // Public API
151 //
152 void
154  std::string ipv4Name,
155  uint32_t interface)
156 {
157  EnableAsciiIpv4Impl(stream, std::string(), ipv4Name, interface, false);
158 }
159 
160 //
161 // Private API
162 //
163 void
165  std::string prefix,
166  std::string ipv4Name,
167  uint32_t interface,
168  bool explicitFilename)
169 {
170  Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
171  EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
172 }
173 
174 //
175 // Public API
176 //
177 void
179 {
181 }
182 
183 //
184 // Public API
185 //
186 void
188 {
189  EnableAsciiIpv4Impl(stream, std::string(), c);
190 }
191 
192 //
193 // Private API
194 //
195 void
197  std::string prefix,
199 {
200  for (auto i = c.Begin(); i != c.End(); ++i)
201  {
202  EnableAsciiIpv4Internal(stream, prefix, (*i).first, (*i).second, false);
203  }
204 }
205 
206 //
207 // Public API
208 //
209 void
211 {
213 }
214 
215 //
216 // Public API
217 //
218 void
220 {
221  EnableAsciiIpv4Impl(stream, std::string(), n);
222 }
223 
224 //
225 // Private API
226 //
227 void
229  std::string prefix,
230  NodeContainer n)
231 {
232  for (auto i = n.Begin(); i != n.End(); ++i)
233  {
234  Ptr<Node> node = *i;
235  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
236  if (ipv4)
237  {
238  for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
239  {
240  EnableAsciiIpv4Internal(stream, prefix, ipv4, j, false);
241  }
242  }
243  }
244 }
245 
246 //
247 // Public API
248 //
249 void
251 {
253 }
254 
255 //
256 // Public API
257 //
258 void
260 {
261  EnableAsciiIpv4Impl(stream, std::string(), NodeContainer::GetGlobal());
262 }
263 
264 //
265 // Public API
266 //
267 void
269  uint32_t nodeid,
270  uint32_t interface,
271  bool explicitFilename)
272 {
273  EnableAsciiIpv4Impl(stream, std::string(), nodeid, interface, explicitFilename);
274 }
275 
276 //
277 // Public API
278 //
279 void
281  uint32_t nodeid,
282  uint32_t interface,
283  bool explicitFilename)
284 {
285  EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
286 }
287 
288 //
289 // Private API
290 //
291 void
293  std::string prefix,
294  uint32_t nodeid,
295  uint32_t interface,
296  bool explicitFilename)
297 {
299 
300  for (auto i = n.Begin(); i != n.End(); ++i)
301  {
302  Ptr<Node> node = *i;
303  if (node->GetId() != nodeid)
304  {
305  continue;
306  }
307 
308  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
309  if (ipv4)
310  {
311  EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
312  }
313 
314  return;
315  }
316 }
317 
318 void
320  Ptr<Ipv6> ipv6,
321  uint32_t interface,
322  bool explicitFilename)
323 {
324  EnablePcapIpv6Internal(prefix, ipv6, interface, explicitFilename);
325 }
326 
327 void
329  std::string ipv6Name,
330  uint32_t interface,
331  bool explicitFilename)
332 {
333  Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
334  EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
335 }
336 
337 void
339 {
340  for (auto i = c.Begin(); i != c.End(); ++i)
341  {
342  EnablePcapIpv6(prefix, (*i).first, (*i).second, false);
343  }
344 }
345 
346 void
348 {
349  for (auto i = n.Begin(); i != n.End(); ++i)
350  {
351  Ptr<Node> node = *i;
352  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
353  if (ipv6)
354  {
355  for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
356  {
357  EnablePcapIpv6(prefix, ipv6, j, false);
358  }
359  }
360  }
361 }
362 
363 void
365 {
367 }
368 
369 void
371  uint32_t nodeid,
372  uint32_t interface,
373  bool explicitFilename)
374 {
376 
377  for (auto i = n.Begin(); i != n.End(); ++i)
378  {
379  Ptr<Node> node = *i;
380  if (node->GetId() != nodeid)
381  {
382  continue;
383  }
384 
385  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
386  if (ipv6)
387  {
388  EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
389  }
390  return;
391  }
392 }
393 
394 //
395 // Public API
396 //
397 void
399  Ptr<Ipv6> ipv6,
400  uint32_t interface,
401  bool explicitFilename)
402 {
403  EnableAsciiIpv6Internal(Ptr<OutputStreamWrapper>(), prefix, ipv6, interface, explicitFilename);
404 }
405 
406 //
407 // Public API
408 //
409 void
411  Ptr<Ipv6> ipv6,
412  uint32_t interface)
413 {
414  EnableAsciiIpv6Internal(stream, std::string(), ipv6, interface, false);
415 }
416 
417 //
418 // Public API
419 //
420 void
422  std::string ipv6Name,
423  uint32_t interface,
424  bool explicitFilename)
425 {
426  EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, ipv6Name, interface, explicitFilename);
427 }
428 
429 //
430 // Public API
431 //
432 void
434  std::string ipv6Name,
435  uint32_t interface)
436 {
437  EnableAsciiIpv6Impl(stream, std::string(), ipv6Name, interface, false);
438 }
439 
440 //
441 // Private API
442 //
443 void
445  std::string prefix,
446  std::string ipv6Name,
447  uint32_t interface,
448  bool explicitFilename)
449 {
450  Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
451  EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
452 }
453 
454 //
455 // Public API
456 //
457 void
459 {
461 }
462 
463 //
464 // Public API
465 //
466 void
468 {
469  EnableAsciiIpv6Impl(stream, std::string(), c);
470 }
471 
472 //
473 // Private API
474 //
475 void
477  std::string prefix,
479 {
480  for (auto i = c.Begin(); i != c.End(); ++i)
481  {
482  EnableAsciiIpv6Internal(stream, prefix, (*i).first, (*i).second, false);
483  }
484 }
485 
486 //
487 // Public API
488 //
489 void
491 {
493 }
494 
495 //
496 // Public API
497 //
498 void
500 {
501  EnableAsciiIpv6Impl(stream, std::string(), n);
502 }
503 
504 //
505 // Private API
506 //
507 void
509  std::string prefix,
510  NodeContainer n)
511 {
512  for (auto i = n.Begin(); i != n.End(); ++i)
513  {
514  Ptr<Node> node = *i;
515  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
516  if (ipv6)
517  {
518  for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
519  {
520  EnableAsciiIpv6Internal(stream, prefix, ipv6, j, false);
521  }
522  }
523  }
524 }
525 
526 //
527 // Public API
528 //
529 void
531 {
533 }
534 
535 //
536 // Public API
537 //
538 void
540 {
541  EnableAsciiIpv6Impl(stream, std::string(), NodeContainer::GetGlobal());
542 }
543 
544 //
545 // Public API
546 //
547 void
549  uint32_t nodeid,
550  uint32_t interface)
551 {
552  EnableAsciiIpv6Impl(stream, std::string(), nodeid, interface, false);
553 }
554 
555 //
556 // Public API
557 //
558 void
560  uint32_t nodeid,
561  uint32_t interface,
562  bool explicitFilename)
563 {
564  EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
565 }
566 
567 //
568 // Private API
569 //
570 void
572  std::string prefix,
573  uint32_t nodeid,
574  uint32_t interface,
575  bool explicitFilename)
576 {
578 
579  for (auto i = n.Begin(); i != n.End(); ++i)
580  {
581  Ptr<Node> node = *i;
582  if (node->GetId() != nodeid)
583  {
584  continue;
585  }
586 
587  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
588  if (ipv6)
589  {
590  EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
591  }
592 
593  return;
594  }
595 }
596 
597 } // 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:80
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:82
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.
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.
uint32_t GetId() const
Definition: node.cc:117
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Every class exported by the ns3 library is enclosed in the ns3 namespace.