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
40  Ptr<Ipv4> ipv4,
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 (Ipv4InterfaceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
61  {
62  std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
63  EnablePcapIpv4(prefix, pair.first, pair.second, false);
64  }
65 }
66 
67 void
69 {
70  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
71  {
72  Ptr<Node> node = *i;
73  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
74  if (ipv4)
75  {
76  for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
77  {
78  EnablePcapIpv4(prefix, ipv4, j, false);
79  }
80  }
81  }
82 }
83 
84 void
86 {
88 }
89 
90 void
92  uint32_t nodeid,
93  uint32_t interface,
94  bool explicitFilename)
95 {
97 
98  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
99  {
100  Ptr<Node> node = *i;
101  if (node->GetId() != nodeid)
102  {
103  continue;
104  }
105 
106  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
107  if (ipv4)
108  {
109  EnablePcapIpv4(prefix, ipv4, interface, explicitFilename);
110  }
111  return;
112  }
113 }
114 
115 //
116 // Public API
117 //
118 void
120  Ptr<Ipv4> ipv4,
121  uint32_t interface,
122  bool explicitFilename)
123 {
124  EnableAsciiIpv4Internal(Ptr<OutputStreamWrapper>(), prefix, ipv4, interface, explicitFilename);
125 }
126 
127 //
128 // Public API
129 //
130 void
132  Ptr<Ipv4> ipv4,
133  uint32_t interface)
134 {
135  EnableAsciiIpv4Internal(stream, std::string(), ipv4, interface, false);
136 }
137 
138 //
139 // Public API
140 //
141 void
143  std::string ipv4Name,
144  uint32_t interface,
145  bool explicitFilename)
146 {
147  EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, ipv4Name, interface, explicitFilename);
148 }
149 
150 //
151 // Public API
152 //
153 void
155  std::string ipv4Name,
156  uint32_t interface)
157 {
158  EnableAsciiIpv4Impl(stream, std::string(), ipv4Name, interface, false);
159 }
160 
161 //
162 // Private API
163 //
164 void
166  std::string prefix,
167  std::string ipv4Name,
168  uint32_t interface,
169  bool explicitFilename)
170 {
171  Ptr<Ipv4> ipv4 = Names::Find<Ipv4>(ipv4Name);
172  EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
173 }
174 
175 //
176 // Public API
177 //
178 void
180 {
182 }
183 
184 //
185 // Public API
186 //
187 void
189 {
190  EnableAsciiIpv4Impl(stream, std::string(), c);
191 }
192 
193 //
194 // Private API
195 //
196 void
198  std::string prefix,
200 {
201  for (Ipv4InterfaceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
202  {
203  std::pair<Ptr<Ipv4>, uint32_t> pair = *i;
204  EnableAsciiIpv4Internal(stream, prefix, pair.first, pair.second, false);
205  }
206 }
207 
208 //
209 // Public API
210 //
211 void
213 {
215 }
216 
217 //
218 // Public API
219 //
220 void
222 {
223  EnableAsciiIpv4Impl(stream, std::string(), n);
224 }
225 
226 //
227 // Private API
228 //
229 void
231  std::string prefix,
232  NodeContainer n)
233 {
234  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
235  {
236  Ptr<Node> node = *i;
237  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
238  if (ipv4)
239  {
240  for (uint32_t j = 0; j < ipv4->GetNInterfaces(); ++j)
241  {
242  EnableAsciiIpv4Internal(stream, prefix, ipv4, j, false);
243  }
244  }
245  }
246 }
247 
248 //
249 // Public API
250 //
251 void
253 {
255 }
256 
257 //
258 // Public API
259 //
260 void
262 {
263  EnableAsciiIpv4Impl(stream, std::string(), NodeContainer::GetGlobal());
264 }
265 
266 //
267 // Public API
268 //
269 void
271  uint32_t nodeid,
272  uint32_t interface,
273  bool explicitFilename)
274 {
275  EnableAsciiIpv4Impl(stream, std::string(), nodeid, interface, explicitFilename);
276 }
277 
278 //
279 // Public API
280 //
281 void
283  uint32_t nodeid,
284  uint32_t interface,
285  bool explicitFilename)
286 {
287  EnableAsciiIpv4Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
288 }
289 
290 //
291 // Private API
292 //
293 void
295  std::string prefix,
296  uint32_t nodeid,
297  uint32_t interface,
298  bool explicitFilename)
299 {
301 
302  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
303  {
304  Ptr<Node> node = *i;
305  if (node->GetId() != nodeid)
306  {
307  continue;
308  }
309 
310  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4>();
311  if (ipv4)
312  {
313  EnableAsciiIpv4Internal(stream, prefix, ipv4, interface, explicitFilename);
314  }
315 
316  return;
317  }
318 }
319 
320 void
322  Ptr<Ipv6> ipv6,
323  uint32_t interface,
324  bool explicitFilename)
325 {
326  EnablePcapIpv6Internal(prefix, ipv6, interface, explicitFilename);
327 }
328 
329 void
331  std::string ipv6Name,
332  uint32_t interface,
333  bool explicitFilename)
334 {
335  Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
336  EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
337 }
338 
339 void
341 {
342  for (Ipv6InterfaceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
343  {
344  std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
345  EnablePcapIpv6(prefix, pair.first, pair.second, false);
346  }
347 }
348 
349 void
351 {
352  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
353  {
354  Ptr<Node> node = *i;
355  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
356  if (ipv6)
357  {
358  for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
359  {
360  EnablePcapIpv6(prefix, ipv6, j, false);
361  }
362  }
363  }
364 }
365 
366 void
368 {
370 }
371 
372 void
374  uint32_t nodeid,
375  uint32_t interface,
376  bool explicitFilename)
377 {
379 
380  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
381  {
382  Ptr<Node> node = *i;
383  if (node->GetId() != nodeid)
384  {
385  continue;
386  }
387 
388  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
389  if (ipv6)
390  {
391  EnablePcapIpv6(prefix, ipv6, interface, explicitFilename);
392  }
393  return;
394  }
395 }
396 
397 //
398 // Public API
399 //
400 void
402  Ptr<Ipv6> ipv6,
403  uint32_t interface,
404  bool explicitFilename)
405 {
406  EnableAsciiIpv6Internal(Ptr<OutputStreamWrapper>(), prefix, ipv6, interface, explicitFilename);
407 }
408 
409 //
410 // Public API
411 //
412 void
414  Ptr<Ipv6> ipv6,
415  uint32_t interface)
416 {
417  EnableAsciiIpv6Internal(stream, std::string(), ipv6, interface, false);
418 }
419 
420 //
421 // Public API
422 //
423 void
425  std::string ipv6Name,
426  uint32_t interface,
427  bool explicitFilename)
428 {
429  EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, ipv6Name, interface, explicitFilename);
430 }
431 
432 //
433 // Public API
434 //
435 void
437  std::string ipv6Name,
438  uint32_t interface)
439 {
440  EnableAsciiIpv6Impl(stream, std::string(), ipv6Name, interface, false);
441 }
442 
443 //
444 // Private API
445 //
446 void
448  std::string prefix,
449  std::string ipv6Name,
450  uint32_t interface,
451  bool explicitFilename)
452 {
453  Ptr<Ipv6> ipv6 = Names::Find<Ipv6>(ipv6Name);
454  EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
455 }
456 
457 //
458 // Public API
459 //
460 void
462 {
464 }
465 
466 //
467 // Public API
468 //
469 void
471 {
472  EnableAsciiIpv6Impl(stream, std::string(), c);
473 }
474 
475 //
476 // Private API
477 //
478 void
480  std::string prefix,
482 {
483  for (Ipv6InterfaceContainer::Iterator i = c.Begin(); i != c.End(); ++i)
484  {
485  std::pair<Ptr<Ipv6>, uint32_t> pair = *i;
486  EnableAsciiIpv6Internal(stream, prefix, pair.first, pair.second, false);
487  }
488 }
489 
490 //
491 // Public API
492 //
493 void
495 {
497 }
498 
499 //
500 // Public API
501 //
502 void
504 {
505  EnableAsciiIpv6Impl(stream, std::string(), n);
506 }
507 
508 //
509 // Private API
510 //
511 void
513  std::string prefix,
514  NodeContainer n)
515 {
516  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
517  {
518  Ptr<Node> node = *i;
519  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
520  if (ipv6)
521  {
522  for (uint32_t j = 0; j < ipv6->GetNInterfaces(); ++j)
523  {
524  EnableAsciiIpv6Internal(stream, prefix, ipv6, j, false);
525  }
526  }
527  }
528 }
529 
530 //
531 // Public API
532 //
533 void
535 {
537 }
538 
539 //
540 // Public API
541 //
542 void
544 {
545  EnableAsciiIpv6Impl(stream, std::string(), NodeContainer::GetGlobal());
546 }
547 
548 //
549 // Public API
550 //
551 void
553  uint32_t nodeid,
554  uint32_t interface)
555 {
556  EnableAsciiIpv6Impl(stream, std::string(), nodeid, interface, false);
557 }
558 
559 //
560 // Public API
561 //
562 void
564  uint32_t nodeid,
565  uint32_t interface,
566  bool explicitFilename)
567 {
568  EnableAsciiIpv6Impl(Ptr<OutputStreamWrapper>(), prefix, nodeid, interface, explicitFilename);
569 }
570 
571 //
572 // Private API
573 //
574 void
576  std::string prefix,
577  uint32_t nodeid,
578  uint32_t interface,
579  bool explicitFilename)
580 {
582 
583  for (NodeContainer::Iterator i = n.Begin(); i != n.End(); ++i)
584  {
585  Ptr<Node> node = *i;
586  if (node->GetId() != nodeid)
587  {
588  continue;
589  }
590 
591  Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
592  if (ipv6)
593  {
594  EnableAsciiIpv6Internal(stream, prefix, ipv6, interface, explicitFilename);
595  }
596 
597  return;
598  }
599 }
600 
601 } // 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:79
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.
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
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.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
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 ...
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
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:78
#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.