src/csma/helper/csma-helper.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 26 Sep 2014 15:51:00 -0700
changeset 10968 2d29fee2b7b8
parent 8974 bfe1b44645d8
permissions -rw-r--r--
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2833
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     2
/*
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     3
 * Copyright (c) 2008 INRIA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     4
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     7
 * published by the Free Software Foundation;
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     8
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    12
 * GNU General Public License for more details.
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    13
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    15
 * along with this program; if not, write to the Free Software
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    17
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2799
diff changeset
    19
 */
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    20
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    21
#include "ns3/abort.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    22
#include "ns3/log.h"
2799
17660e306cab Prepend ascii trace lines with action and time
Tom Henderson <tomh@tomh.org>
parents: 2789
diff changeset
    23
#include "ns3/simulator.h"
2603
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    24
#include "ns3/object-factory.h"
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    25
#include "ns3/queue.h"
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    26
#include "ns3/csma-net-device.h"
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    27
#include "ns3/csma-channel.h"
2780
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
    28
#include "ns3/config.h"
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
    29
#include "ns3/packet.h"
4147
5d8530130930 rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents: 4140
diff changeset
    30
#include "ns3/names.h"
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    31
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6206
diff changeset
    32
#include "ns3/trace-helper.h"
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    33
#include "csma-helper.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    34
2603
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    35
#include <string>
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 8974
diff changeset
    37
namespace ns3 {
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    38
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 8974
diff changeset
    39
NS_LOG_COMPONENT_DEFINE ("CsmaHelper");
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
CsmaHelper::CsmaHelper ()
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
{
2603
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    43
  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    44
  m_deviceFactory.SetTypeId ("ns3::CsmaNetDevice");
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    45
  m_channelFactory.SetTypeId ("ns3::CsmaChannel");
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
void 
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
CsmaHelper::SetQueue (std::string type,
3786
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3553
diff changeset
    50
                      std::string n1, const AttributeValue &v1,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3553
diff changeset
    51
                      std::string n2, const AttributeValue &v2,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3553
diff changeset
    52
                      std::string n3, const AttributeValue &v3,
9f384deadb46 replace \t with 8 spaces.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3553
diff changeset
    53
                      std::string n4, const AttributeValue &v4)
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
{
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
  m_queueFactory.SetTypeId (type);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
  m_queueFactory.Set (n1, v1);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
  m_queueFactory.Set (n2, v2);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
  m_queueFactory.Set (n3, v3);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
  m_queueFactory.Set (n4, v4);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
void 
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    63
CsmaHelper::SetDeviceAttribute (std::string n1, const AttributeValue &v1)
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
{
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
  m_deviceFactory.Set (n1, v1);
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
void 
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3011
diff changeset
    69
CsmaHelper::SetChannelAttribute (std::string n1, const AttributeValue &v1)
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
2603
1308da4cb3bf move helpers to their own dir.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    71
  m_channelFactory.Set (n1, v1);
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
2780
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
    74
void 
6091
ab0d5e641fd7 fix thinko in fix for explicit pcap names
Craig Dowell <craigdo@ee.washington.edu>
parents: 6085
diff changeset
    75
CsmaHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
    76
{
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    77
  //
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    78
  // All of the Pcap enable functions vector through here including the ones
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    79
  // that are wandering through all of devices on perhaps all of the nodes in
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    80
  // the system.  We can only deal with devices of type CsmaNetDevice.
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    81
  //
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    82
  Ptr<CsmaNetDevice> device = nd->GetObject<CsmaNetDevice> ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    83
  if (device == 0)
3789
616c83eeb4b9 bug 280: trace helpers too inclusive
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3786
diff changeset
    84
    {
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    85
      NS_LOG_INFO ("CsmaHelper::EnablePcapInternal(): Device " << device << " not of type ns3::CsmaNetDevice");
3789
616c83eeb4b9 bug 280: trace helpers too inclusive
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3786
diff changeset
    86
      return;
616c83eeb4b9 bug 280: trace helpers too inclusive
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3786
diff changeset
    87
    }
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    88
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
    89
  PcapHelper pcapHelper;
6085
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    90
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    91
  std::string filename;
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    92
  if (explicitFilename)
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    93
    {
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    94
      filename = prefix;
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    95
    }
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    96
  else
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    97
    {
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    98
      filename = pcapHelper.GetFilenameFromDevice (prefix, device);
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
    99
    }
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   100
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6096
diff changeset
   101
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, 
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6096
diff changeset
   102
                                                     PcapHelper::DLT_EN10MB);
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   103
  if (promiscuous)
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   104
    {
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
   105
      pcapHelper.HookDefaultSink<CsmaNetDevice> (device, "PromiscSniffer", file);
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   106
    }
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   107
  else
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   108
    {
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5776
diff changeset
   109
      pcapHelper.HookDefaultSink<CsmaNetDevice> (device, "Sniffer", file);
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   110
    }
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   111
}
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   112
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   113
void 
6096
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   114
CsmaHelper::EnableAsciiInternal (
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   115
  Ptr<OutputStreamWrapper> stream, 
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   116
  std::string prefix, 
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   117
  Ptr<NetDevice> nd,
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   118
  bool explicitFilename)
6011
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   119
{
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   120
  //
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   121
  // All of the ascii enable functions vector through here including the ones
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   122
  // that are wandering through all of devices on perhaps all of the nodes in
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   123
  // the system.  We can only deal with devices of type CsmaNetDevice.
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   124
  //
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   125
  Ptr<CsmaNetDevice> device = nd->GetObject<CsmaNetDevice> ();
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   126
  if (device == 0)
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   127
    {
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   128
      NS_LOG_INFO ("CsmaHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::CsmaNetDevice");
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   129
      return;
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   130
    }
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   131
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   132
  //
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   133
  // Our default trace sinks are going to use packet printing, so we have to 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   134
  // make sure that is turned on.
6011
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   135
  //
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   136
  Packet::EnablePrinting ();
6011
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   137
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   138
  //
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
   139
  // If we are not provided an OutputStreamWrapper, we are expected to create 
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   140
  // one using the usual trace filename conventions and do a Hook*WithoutContext
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   141
  // since there will be one file per context and therefore the context would
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   142
  // be redundant.
6011
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   143
  //
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   144
  if (stream == 0)
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   145
    {
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   146
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   147
      // Set up an output stream object to deal with private ofstream copy 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   148
      // constructor and lifetime issues.  Let the helper decide the actual
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   149
      // name of the file given the prefix.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   150
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   151
      AsciiTraceHelper asciiTraceHelper;
6096
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   152
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   153
      std::string filename;
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   154
      if (explicitFilename)
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   155
        {
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   156
          filename = prefix;
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   157
        }
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   158
      else
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   159
        {
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   160
          filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   161
        }
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   162
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6096
diff changeset
   163
      Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   164
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   165
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   166
      // The MacRx trace source provides our "r" event.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   167
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   168
      asciiTraceHelper.HookDefaultReceiveSinkWithoutContext<CsmaNetDevice> (device, "MacRx", theStream);
6011
3fd7841b9c20 ascii trace additions
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   169
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   170
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   171
      // The "+", '-', and 'd' events are driven by trace sources actually in the
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   172
      // transmit queue.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   173
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   174
      Ptr<Queue> queue = device->GetQueue ();
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   175
      asciiTraceHelper.HookDefaultEnqueueSinkWithoutContext<Queue> (queue, "Enqueue", theStream);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   176
      asciiTraceHelper.HookDefaultDropSinkWithoutContext<Queue> (queue, "Drop", theStream);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   177
      asciiTraceHelper.HookDefaultDequeueSinkWithoutContext<Queue> (queue, "Dequeue", theStream);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   178
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   179
      return;
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   180
    }
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   181
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   182
  //
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
   183
  // If we are provided an OutputStreamWrapper, we are expected to use it, and
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   184
  // to providd a context.  We are free to come up with our own context if we
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   185
  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   186
  // compatibility and simplicity, we just use Config::Connect and let it deal
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   187
  // with the context.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   188
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   189
  // Note that we are going to use the default trace sinks provided by the 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   190
  // ascii trace helper.  There is actually no AsciiTraceHelper in sight here,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   191
  // but the default trace sinks are actually publicly available static 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   192
  // functions that are always there waiting for just such a case.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   193
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   194
  uint32_t nodeid = nd->GetNode ()->GetId ();
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   195
  uint32_t deviceid = nd->GetIfIndex ();
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   196
  std::ostringstream oss;
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   197
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   198
  oss << "/NodeList/" << nd->GetNode ()->GetId () << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/MacRx";
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   199
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultReceiveSinkWithContext, stream));
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   200
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   201
  oss.str ("");
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   202
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   203
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultEnqueueSinkWithContext, stream));
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   204
2789
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   205
  oss.str ("");
47e92324cf4b configure tracing post-topology construction, not before.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2780
diff changeset
   206
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue";
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   207
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDequeueSinkWithContext, stream));
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   208
2799
17660e306cab Prepend ascii trace lines with action and time
Tom Henderson <tomh@tomh.org>
parents: 2789
diff changeset
   209
  oss.str ("");
17660e306cab Prepend ascii trace lines with action and time
Tom Henderson <tomh@tomh.org>
parents: 2789
diff changeset
   210
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop";
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6011
diff changeset
   211
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiTraceHelper::DefaultDropSinkWithContext, stream));
2780
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
   212
}
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
   213
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   214
NetDeviceContainer
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   215
CsmaHelper::Install (Ptr<Node> node) const
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   216
{
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   217
  Ptr<CsmaChannel> channel = m_channelFactory.Create ()->GetObject<CsmaChannel> ();
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   218
  return Install (node, channel);
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   219
}
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   220
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   221
NetDeviceContainer
4140
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   222
CsmaHelper::Install (std::string nodeName) const
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   223
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   224
  Ptr<Node> node = Names::Find<Node> (nodeName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   225
  return Install (node);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   226
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   227
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   228
NetDeviceContainer
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   229
CsmaHelper::Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   230
{
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   231
  return NetDeviceContainer (InstallPriv (node, channel));
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   232
}
2780
306f665014b6 add ascii and pcap tracing support to csma helper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2656
diff changeset
   233
4140
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   234
NetDeviceContainer
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   235
CsmaHelper::Install (Ptr<Node> node, std::string channelName) const
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   236
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   237
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   238
  return NetDeviceContainer (InstallPriv (node, channel));
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   239
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   240
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   241
NetDeviceContainer
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   242
CsmaHelper::Install (std::string nodeName, Ptr<CsmaChannel> channel) const
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   243
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   244
  Ptr<Node> node = Names::Find<Node> (nodeName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   245
  return NetDeviceContainer (InstallPriv (node, channel));
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   246
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   247
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   248
NetDeviceContainer
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   249
CsmaHelper::Install (std::string nodeName, std::string channelName) const
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   250
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   251
  Ptr<Node> node = Names::Find<Node> (nodeName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   252
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   253
  return NetDeviceContainer (InstallPriv (node, channel));
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   254
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   255
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
NetDeviceContainer 
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   257
CsmaHelper::Install (const NodeContainer &c) const
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
{
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
  Ptr<CsmaChannel> channel = m_channelFactory.Create ()->GetObject<CsmaChannel> ();
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   260
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2839
diff changeset
   261
  return Install (c, channel);
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
NetDeviceContainer 
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   265
CsmaHelper::Install (const NodeContainer &c, Ptr<CsmaChannel> channel) const
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
{
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   267
  NetDeviceContainer devs;
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   268
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
    {
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   271
      devs.Add (InstallPriv (*i, channel));
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
    }
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   273
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   274
  return devs;
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   275
}
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   276
4140
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   277
NetDeviceContainer 
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   278
CsmaHelper::Install (const NodeContainer &c, std::string channelName) const
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   279
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   280
  Ptr<CsmaChannel> channel = Names::Find<CsmaChannel> (channelName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   281
  return Install (c, channel);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   282
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3848
diff changeset
   283
8974
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   284
int64_t
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   285
CsmaHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   286
{
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   287
  int64_t currentStream = stream;
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   288
  Ptr<NetDevice> netDevice;
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   289
  for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   290
    {
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   291
      netDevice = (*i);
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   292
      Ptr<CsmaNetDevice> csma = DynamicCast<CsmaNetDevice> (netDevice);
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   293
      if (csma)
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   294
        {
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   295
          currentStream += csma->AssignStreams (currentStream);
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   296
        }
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   297
    }
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   298
  return (currentStream - stream);
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   299
}
bfe1b44645d8 Replace src/csma usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 6852
diff changeset
   300
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   301
Ptr<NetDevice>
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   302
CsmaHelper::InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   303
{
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   304
  Ptr<CsmaNetDevice> device = m_deviceFactory.Create<CsmaNetDevice> ();
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   305
  device->SetAddress (Mac48Address::Allocate ());
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   306
  node->AddDevice (device);
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   307
  Ptr<Queue> queue = m_queueFactory.Create<Queue> ();
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   308
  device->SetQueue (queue);
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   309
  device->Attach (channel);
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   310
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3795
diff changeset
   311
  return device;
2418
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
}
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   313
4ff45fa08781 an initial draft of helper classes. don't work yet.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
} // namespace ns3