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 
32 #include "internet-trace-helper.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("InternetTraceHelper");
37 
38 void
39 PcapHelperForIpv4::EnablePcapIpv4 (std::string prefix, Ptr<Ipv4> ipv4, uint32_t interface, bool explicitFilename)
40 {
41  EnablePcapIpv4Internal (prefix, ipv4, interface, explicitFilename);
42 }
43 
44 void
45 PcapHelperForIpv4::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 
51 void
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 
61 void
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 
78 void
80 {
82 }
83 
84 void
85 PcapHelperForIpv4::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 //
109 void
110 AsciiTraceHelperForIpv4::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 //
118 void
120 {
121  EnableAsciiIpv4Internal (stream, std::string (), ipv4, interface, false);
122 }
123 
124 //
125 // Public API
126 //
127 void
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 //
140 void
141 AsciiTraceHelperForIpv4::EnableAsciiIpv4 (Ptr<OutputStreamWrapper> stream, std::string ipv4Name, uint32_t interface)
142 {
143  EnableAsciiIpv4Impl (stream, std::string (), ipv4Name, interface, false);
144 }
145 
146 //
147 // Private API
148 //
149 void
151  Ptr<OutputStreamWrapper> stream,
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 //
164 void
166 {
168 }
169 
170 //
171 // Public API
172 //
173 void
175 {
176  EnableAsciiIpv4Impl (stream, std::string (), c);
177 }
178 
179 //
180 // Private API
181 //
182 void
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 //
195 void
197 {
199 }
200 
201 //
202 // Public API
203 //
204 void
206 {
207  EnableAsciiIpv4Impl (stream, std::string (), n);
208 }
209 
210 //
211 // Private API
212 //
213 void
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 //
233 void
235 {
237 }
238 
239 //
240 // Public API
241 //
242 void
244 {
245  EnableAsciiIpv4Impl (stream, std::string (), NodeContainer::GetGlobal ());
246 }
247 
248 //
249 // Public API
250 //
251 void
253  Ptr<OutputStreamWrapper> stream,
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 //
264 void
265 AsciiTraceHelperForIpv4::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 //
273 void
275  Ptr<OutputStreamWrapper> stream,
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 
301 void
302 PcapHelperForIpv6::EnablePcapIpv6 (std::string prefix, Ptr<Ipv6> ipv6, uint32_t interface, bool explicitFilename)
303 {
304  EnablePcapIpv6Internal (prefix, ipv6, interface, explicitFilename);
305 }
306 
307 void
308 PcapHelperForIpv6::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 
314 void
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 
324 void
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 
341 void
343 {
345 }
346 
347 void
348 PcapHelperForIpv6::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 //
372 void
373 AsciiTraceHelperForIpv6::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 //
381 void
383 {
384  EnableAsciiIpv6Internal (stream, std::string (), ipv6, interface, false);
385 }
386 
387 //
388 // Public API
389 //
390 void
391 AsciiTraceHelperForIpv6::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 //
399 void
400 AsciiTraceHelperForIpv6::EnableAsciiIpv6 (Ptr<OutputStreamWrapper> stream, std::string ipv6Name, uint32_t interface)
401 {
402  EnableAsciiIpv6Impl (stream, std::string (), ipv6Name, interface, false);
403 }
404 
405 //
406 // Private API
407 //
408 void
410  Ptr<OutputStreamWrapper> stream,
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 //
423 void
425 {
427 }
428 
429 //
430 // Public API
431 //
432 void
434 {
435  EnableAsciiIpv6Impl (stream, std::string (), c);
436 }
437 
438 //
439 // Private API
440 //
441 void
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 //
454 void
456 {
458 }
459 
460 //
461 // Public API
462 //
463 void
465 {
466  EnableAsciiIpv6Impl (stream, std::string (), n);
467 }
468 
469 //
470 // Private API
471 //
472 void
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 //
492 void
494 {
496 }
497 
498 //
499 // Public API
500 //
501 void
503 {
504  EnableAsciiIpv6Impl (stream, std::string (), NodeContainer::GetGlobal ());
505 }
506 
507 //
508 // Public API
509 //
510 void
511 AsciiTraceHelperForIpv6::EnableAsciiIpv6 (Ptr<OutputStreamWrapper> stream, uint32_t nodeid, uint32_t interface)
512 {
513  EnableAsciiIpv6Impl (stream, std::string (), nodeid, interface, false);
514 }
515 
516 //
517 // Public API
518 //
519 void
520 AsciiTraceHelperForIpv6::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 //
528 void
530  Ptr<OutputStreamWrapper> stream,
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 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
uint32_t GetId(void) const
Definition: node.cc:107
Keep track of a set of IPv6 interfaces.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition: ipv6.h:81
void EnablePcapIpv4(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename=false)
Enable pcap output the indicated Ipv4 and interface pair.
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...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.
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 EnableAsciiIpv4(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename=false)
Enable ascii trace output on the indicated Ipv4 and interface pair.
std::vector< std::pair< Ptr< Ipv6 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv6 smart pointer / Interface Index.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
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 EnableAsciiIpv4All(std::string prefix)
Enable ascii trace output on all Ipv4 and interface pairs existing in the set of all nodes created in...
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void EnablePcapIpv6(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename=false)
Enable pcap output the indicated Ipv6 and interface pair.
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...
std::vector< std::pair< Ptr< Ipv4 >, uint32_t > >::const_iterator Iterator
Container Const Iterator for pairs of Ipv4 smart pointer / Interface Index.
void EnableAsciiIpv6All(std::string prefix)
Enable ascii trace output on all Ipv6 and interface pairs existing in the set of all nodes created in...
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
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...
virtual void EnablePcapIpv4Internal(std::string prefix, Ptr< Ipv4 > ipv4, uint32_t interface, bool explicitFilename)=0
Enable pcap output the indicated Ipv4 and interface pair.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
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...
virtual void EnablePcapIpv6Internal(std::string prefix, Ptr< Ipv6 > ipv6, uint32_t interface, bool explicitFilename)=0
Enable pcap output the indicated Ipv6 and interface pair.
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.
Iterator Begin(void) const
Get an iterator which refers to the first pair in the container.