src/wifi/helper/yans-wifi-helper.cc
author Nicola Baldo <nicola@baldo.biz>
Sun, 10 Apr 2011 18:37:49 +0200
changeset 7012 67ca195ea166
parent 6852 8f1a53d3f6ca
child 7141 072fb225b714
permissions -rw-r--r--
fixed Bug 1066 - Set Radiotap modulation type flags correctly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2008 INRIA
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    20
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6459
diff changeset
    21
#include "ns3/trace-helper.h"
4000
07bf8da834e0 bug 435: file names are not consistent
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3912
diff changeset
    22
#include "yans-wifi-helper.h"
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/error-rate-model.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "ns3/propagation-loss-model.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include "ns3/propagation-delay-model.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
#include "ns3/yans-wifi-channel.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "ns3/yans-wifi-phy.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include "ns3/wifi-net-device.h"
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
    29
#include "ns3/radiotap-header.h"
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6049
diff changeset
    30
#include "ns3/pcap-file-wrapper.h"
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
#include "ns3/simulator.h"
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
#include "ns3/config.h"
4147
5d8530130930 rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents: 4140
diff changeset
    33
#include "ns3/names.h"
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
    34
#include "ns3/abort.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
    35
#include "ns3/log.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
    36
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
    37
NS_LOG_COMPONENT_DEFINE ("YansWifiHelper");
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
namespace ns3 {
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    41
static void 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    42
AsciiPhyTransmitSinkWithContext (
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
    43
  Ptr<OutputStreamWrapper> stream, 
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    44
  std::string context, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    45
  Ptr<const Packet> p,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    46
  WifiMode mode, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    47
  WifiPreamble preamble,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    48
  uint8_t txLevel)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
{
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    50
  NS_LOG_FUNCTION (stream << context << p << mode << preamble << txLevel);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    51
  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    52
}
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    53
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    54
static void 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    55
AsciiPhyTransmitSinkWithoutContext (
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
    56
  Ptr<OutputStreamWrapper> stream, 
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    57
  Ptr<const Packet> p,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    58
  WifiMode mode, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    59
  WifiPreamble preamble,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    60
  uint8_t txLevel)
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    61
{
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    62
  NS_LOG_FUNCTION (stream << p << mode << preamble << txLevel);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    63
  *stream->GetStream () << "t " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    66
static void 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    67
AsciiPhyReceiveSinkWithContext (
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
    68
  Ptr<OutputStreamWrapper> stream,
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    69
  std::string context,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    70
  Ptr<const Packet> p, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    71
  double snr, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    72
  WifiMode mode,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    73
  enum WifiPreamble preamble)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
{
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    75
  NS_LOG_FUNCTION (stream << context << p << snr << mode << preamble);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    76
  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << context << " " << *p << std::endl;
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    79
static void 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    80
AsciiPhyReceiveSinkWithoutContext (
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
    81
  Ptr<OutputStreamWrapper> stream,
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    82
  Ptr<const Packet> p, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    83
  double snr, 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    84
  WifiMode mode,
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    85
  enum WifiPreamble preamble)
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    86
{
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    87
  NS_LOG_FUNCTION (stream << p << snr << mode << preamble);
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    88
  *stream->GetStream () << "r " << Simulator::Now ().GetSeconds () << " " << *p << std::endl;
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
    89
}
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
YansWifiChannelHelper::YansWifiChannelHelper ()
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
{}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
YansWifiChannelHelper 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
YansWifiChannelHelper::Default (void)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
  YansWifiChannelHelper helper;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
  helper.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
  helper.AddPropagationLoss ("ns3::LogDistancePropagationLossModel");
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
  return helper;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
void 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
YansWifiChannelHelper::AddPropagationLoss (std::string type,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
					   std::string n0, const AttributeValue &v0,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
					   std::string n1, const AttributeValue &v1,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
					   std::string n2, const AttributeValue &v2,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
					   std::string n3, const AttributeValue &v3,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
					   std::string n4, const AttributeValue &v4,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
					   std::string n5, const AttributeValue &v5,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
					   std::string n6, const AttributeValue &v6,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
					   std::string n7, const AttributeValue &v7)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
  ObjectFactory factory;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
  factory.SetTypeId (type);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
  factory.Set (n0, v0);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
  factory.Set (n1, v1);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
  factory.Set (n2, v2);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
  factory.Set (n3, v3);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
  factory.Set (n4, v4);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
  factory.Set (n5, v5);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
  factory.Set (n6, v6);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
  factory.Set (n7, v7);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
  m_propagationLoss.push_back (factory);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
void 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
YansWifiChannelHelper::SetPropagationDelay (std::string type,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
					    std::string n0, const AttributeValue &v0,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
					    std::string n1, const AttributeValue &v1,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
					    std::string n2, const AttributeValue &v2,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
					    std::string n3, const AttributeValue &v3,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
					    std::string n4, const AttributeValue &v4,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
					    std::string n5, const AttributeValue &v5,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
					    std::string n6, const AttributeValue &v6,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
					    std::string n7, const AttributeValue &v7)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
  ObjectFactory factory;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
  factory.SetTypeId (type);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
  factory.Set (n0, v0);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
  factory.Set (n1, v1);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
  factory.Set (n2, v2);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  factory.Set (n3, v3);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
  factory.Set (n4, v4);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
  factory.Set (n5, v5);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
  factory.Set (n6, v6);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
  factory.Set (n7, v7);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
  m_propagationDelay = factory;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
Ptr<YansWifiChannel> 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
YansWifiChannelHelper::Create (void) const
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
  Ptr<YansWifiChannel> channel = CreateObject<YansWifiChannel> ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
  Ptr<PropagationLossModel> prev = 0;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
  for (std::vector<ObjectFactory>::const_iterator i = m_propagationLoss.begin (); i != m_propagationLoss.end (); ++i)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
    {
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
      Ptr<PropagationLossModel> cur = (*i).Create<PropagationLossModel> ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
      if (prev != 0)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
	{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
	  prev->SetNext (cur);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
	}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
      if (m_propagationLoss.begin () == i)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
	{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
	  channel->SetPropagationLossModel (cur);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
	}
4058
5c7df2c1cfc5 update prev even if it is null
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4038
diff changeset
   167
      prev = cur;
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
    }
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
  Ptr<PropagationDelayModel> delay = m_propagationDelay.Create<PropagationDelayModel> ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
  channel->SetPropagationDelayModel (delay);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
  return channel;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
YansWifiPhyHelper::YansWifiPhyHelper ()
4492
3ebeb7bf3c15 added support for radiotap and prism headers
Nicola Baldo <nbaldo@cttc.es>
parents: 4264
diff changeset
   176
  : m_channel (0),
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   177
    m_pcapDlt(PcapHelper::DLT_IEEE802_11)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
  m_phy.SetTypeId ("ns3::YansWifiPhy");
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
YansWifiPhyHelper 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
YansWifiPhyHelper::Default (void)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
  YansWifiPhyHelper helper;
6459
d5cfe99001f0 Change default OFDM error rate model to NistErrorRateModel (issue 944)
Tom Henderson <tomh@tomh.org>
parents: 6313
diff changeset
   186
  helper.SetErrorRateModel ("ns3::NistErrorRateModel");
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
  return helper;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
void 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
YansWifiPhyHelper::SetChannel (Ptr<YansWifiChannel> channel)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
  m_channel = channel;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
void 
4140
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   196
YansWifiPhyHelper::SetChannel (std::string channelName)
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   197
{
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   198
  Ptr<YansWifiChannel> channel = Names::Find<YansWifiChannel> (channelName);
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   199
  m_channel = channel;
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   200
}
6bbf05bf4826 Brute force all of the helpers to use object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 4058
diff changeset
   201
void 
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
YansWifiPhyHelper::Set (std::string name, const AttributeValue &v)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
  m_phy.Set (name, v);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
void 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
YansWifiPhyHelper::SetErrorRateModel (std::string name,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
                                     std::string n0, const AttributeValue &v0,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
                                     std::string n1, const AttributeValue &v1,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
                                     std::string n2, const AttributeValue &v2,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
                                     std::string n3, const AttributeValue &v3,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
                                     std::string n4, const AttributeValue &v4,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
                                     std::string n5, const AttributeValue &v5,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
                                     std::string n6, const AttributeValue &v6,
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
                                     std::string n7, const AttributeValue &v7)
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
  m_errorRateModel = ObjectFactory ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
  m_errorRateModel.SetTypeId (name);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
  m_errorRateModel.Set (n0, v0);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
  m_errorRateModel.Set (n1, v1);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
  m_errorRateModel.Set (n2, v2);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
  m_errorRateModel.Set (n3, v3);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
  m_errorRateModel.Set (n4, v4);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
  m_errorRateModel.Set (n5, v5);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
  m_errorRateModel.Set (n6, v6);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
  m_errorRateModel.Set (n7, v7);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   229
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
Ptr<WifiPhy> 
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
YansWifiPhyHelper::Create (Ptr<Node> node, Ptr<WifiNetDevice> device) const
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
{
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
  Ptr<YansWifiPhy> phy = m_phy.Create<YansWifiPhy> ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
  Ptr<ErrorRateModel> error = m_errorRateModel.Create<ErrorRateModel> ();
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
  phy->SetErrorRateModel (error);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
  phy->SetChannel (m_channel);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
  phy->SetMobility (node);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
  phy->SetDevice (device);
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
  return phy;
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   241
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   242
static void 
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   243
PcapSniffTxEvent (
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6049
diff changeset
   244
  Ptr<PcapFileWrapper> file,
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   245
  Ptr<const Packet>   packet,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   246
  uint16_t            channelFreqMhz,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   247
  uint16_t            channelNumber,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   248
  uint32_t            rate,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   249
  bool                isShortPreamble)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   250
{
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   251
  uint32_t dlt = file->GetDataLinkType ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   252
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   253
  switch (dlt)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   254
    {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   255
    case PcapHelper::DLT_IEEE802_11:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   256
      file->Write (Simulator::Now (), packet);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   257
      return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   258
    case PcapHelper::DLT_PRISM_HEADER:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   259
      {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   260
        NS_FATAL_ERROR ("PcapSniffTxEvent(): DLT_PRISM_HEADER not implemented");
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   261
        return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   262
      }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   263
    case PcapHelper::DLT_IEEE802_11_RADIO:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   264
      {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   265
        Ptr<Packet> p = packet->Copy ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   266
        RadiotapHeader header;
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   267
        uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   268
        header.SetTsft (Simulator::Now ().GetMicroSeconds ());
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   269
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   270
        // Our capture includes the FCS, so we set the flag to say so.
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   271
        frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   272
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   273
        if (isShortPreamble)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   274
          {
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   275
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   276
          }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   277
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   278
        header.SetFrameFlags (frameFlags);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   279
        header.SetRate (rate);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   280
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   281
        uint16_t channelFlags = 0;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   282
        switch (rate) 
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   283
          {
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   284
          case 2:  // 1Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   285
          case 4:  // 2Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   286
          case 10: // 5Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   287
          case 22: // 11Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   288
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   289
            break;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   290
            
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   291
          default:
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   292
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   293
            break;              
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   294
          }
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   295
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   296
        if (channelFreqMhz < 2500)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   297
          {
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   298
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   299
          }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   300
        else
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   301
          {
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   302
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   303
          }
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   304
        
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   305
        header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   306
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   307
        p->AddHeader (header);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   308
        file->Write (Simulator::Now (), p);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   309
        return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   310
      }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   311
    default:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   312
      NS_ABORT_MSG ("PcapSniffTxEvent(): Unexpected data link type " << dlt);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   313
    }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   314
}
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   315
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   316
static void 
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   317
PcapSniffRxEvent (
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6049
diff changeset
   318
  Ptr<PcapFileWrapper> file,
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   319
  Ptr<const Packet> packet,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   320
  uint16_t channelFreqMhz,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   321
  uint16_t channelNumber,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   322
  uint32_t rate,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   323
  bool isShortPreamble,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   324
  double signalDbm,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   325
  double noiseDbm)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   326
{
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   327
  uint32_t dlt = file->GetDataLinkType ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   328
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   329
  switch (dlt)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   330
    {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   331
    case PcapHelper::DLT_IEEE802_11:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   332
      file->Write (Simulator::Now (), packet);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   333
      return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   334
    case PcapHelper::DLT_PRISM_HEADER:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   335
      {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   336
        NS_FATAL_ERROR ("PcapSniffRxEvent(): DLT_PRISM_HEADER not implemented");
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   337
        return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   338
      }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   339
    case PcapHelper::DLT_IEEE802_11_RADIO:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   340
      {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   341
        Ptr<Packet> p = packet->Copy ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   342
        RadiotapHeader header;
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   343
        uint8_t frameFlags = RadiotapHeader::FRAME_FLAG_NONE;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   344
        header.SetTsft (Simulator::Now ().GetMicroSeconds ());
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   345
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   346
        // Our capture includes the FCS, so we set the flag to say so.
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   347
        frameFlags |= RadiotapHeader::FRAME_FLAG_FCS_INCLUDED;
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   348
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   349
        if (isShortPreamble)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   350
          {
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   351
            frameFlags |= RadiotapHeader::FRAME_FLAG_SHORT_PREAMBLE;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   352
          }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   353
6299
56ac87d0f2f9 Set FCS included flag in Radiotap header
Dean Armstrong <deanarm@gmail.com>
parents: 6206
diff changeset
   354
        header.SetFrameFlags (frameFlags);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   355
        header.SetRate (rate);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   356
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   357
        uint16_t channelFlags = 0;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   358
        switch (rate) 
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   359
          {
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   360
          case 2:  // 1Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   361
          case 4:  // 2Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   362
          case 10: // 5Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   363
          case 22: // 11Mbps
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   364
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_CCK;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   365
            break;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   366
            
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   367
          default:
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   368
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_OFDM;
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   369
            break;              
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   370
          }
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   371
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   372
        if (channelFreqMhz < 2500)
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   373
          {
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   374
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_2GHZ;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   375
          }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   376
        else
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   377
          {
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   378
            channelFlags |= RadiotapHeader::CHANNEL_FLAG_SPECTRUM_5GHZ;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   379
          }
7012
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   380
        
67ca195ea166 fixed Bug 1066 - Set Radiotap modulation type flags correctly
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
   381
        header.SetChannelFrequencyAndFlags (channelFreqMhz, channelFlags);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   382
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   383
        header.SetAntennaSignalPower (signalDbm);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   384
        header.SetAntennaNoisePower (noiseDbm);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   385
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   386
        p->AddHeader (header);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   387
        file->Write (Simulator::Now (), p);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   388
        return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   389
      }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   390
    default:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   391
      NS_ABORT_MSG ("PcapSniffRxEvent(): Unexpected data link type " << dlt);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   392
    }
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   393
}
4492
3ebeb7bf3c15 added support for radiotap and prism headers
Nicola Baldo <nbaldo@cttc.es>
parents: 4264
diff changeset
   394
3ebeb7bf3c15 added support for radiotap and prism headers
Nicola Baldo <nbaldo@cttc.es>
parents: 4264
diff changeset
   395
void 
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6028
diff changeset
   396
YansWifiPhyHelper::SetPcapDataLinkType (enum SupportedPcapDataLinkTypes dlt)
4492
3ebeb7bf3c15 added support for radiotap and prism headers
Nicola Baldo <nbaldo@cttc.es>
parents: 4264
diff changeset
   397
{
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6028
diff changeset
   398
  switch (dlt)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   399
    {
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6028
diff changeset
   400
    case DLT_IEEE802_11:
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   401
      m_pcapDlt = PcapHelper::DLT_IEEE802_11;
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   402
      return;
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6028
diff changeset
   403
    case DLT_PRISM_HEADER:
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   404
      m_pcapDlt = PcapHelper::DLT_PRISM_HEADER;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   405
      return;
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6028
diff changeset
   406
    case DLT_IEEE802_11_RADIO:
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   407
      m_pcapDlt = PcapHelper::DLT_IEEE802_11_RADIO;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   408
      return;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   409
    default:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   410
      NS_ABORT_MSG ("YansWifiPhyHelper::SetPcapFormat(): Unexpected format");
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   411
    }
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   412
}
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   413
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   414
void 
6091
ab0d5e641fd7 fix thinko in fix for explicit pcap names
Craig Dowell <craigdo@ee.washington.edu>
parents: 6085
diff changeset
   415
YansWifiPhyHelper::EnablePcapInternal (std::string prefix, Ptr<NetDevice> nd, bool promiscuous, bool explicitFilename)
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4263
diff changeset
   416
{
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   417
  //
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   418
  // All of the Pcap enable functions vector through here including the ones
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   419
  // 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: 4715
diff changeset
   420
  // the system.  We can only deal with devices of type WifiNetDevice.
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   421
  //
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   422
  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   423
  if (device == 0)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
    {
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   425
      NS_LOG_INFO ("YansWifiHelper::EnablePcapInternal(): Device " << &device << " not of type ns3::WifiNetDevice");
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   426
      return;
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   427
    }
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   428
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   429
  Ptr<WifiPhy> phy = device->GetPhy ();
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   430
  NS_ABORT_MSG_IF (phy == 0, "YansWifiPhyHelper::EnablePcapInternal(): Phy layer in WifiNetDevice must be set");
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   432
  PcapHelper pcapHelper;
6096
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   433
6085
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   434
  std::string filename;
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   435
  if (explicitFilename)
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   436
    {
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   437
      filename = prefix;
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   438
    }
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   439
  else
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   440
    {
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   441
      filename = pcapHelper.GetFilenameFromDevice (prefix, device);
94b282f335d2 allow explicit filenames in pcap trace files
Craig Dowell <craigdo@ee.washington.edu>
parents: 6053
diff changeset
   442
    }
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   443
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6096
diff changeset
   444
  Ptr<PcapFileWrapper> file = pcapHelper.CreateFile (filename, std::ios::out, m_pcapDlt);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   445
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   446
  phy->TraceConnectWithoutContext ("PromiscSnifferTx", MakeBoundCallback (&PcapSniffTxEvent, file));
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 4715
diff changeset
   447
  phy->TraceConnectWithoutContext ("PromiscSnifferRx", MakeBoundCallback (&PcapSniffRxEvent, file));
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   448
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   449
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   450
void 
6096
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   451
YansWifiPhyHelper::EnableAsciiInternal (
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   452
  Ptr<OutputStreamWrapper> stream, 
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   453
  std::string prefix, 
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   454
  Ptr<NetDevice> nd,
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   455
  bool explicitFilename)
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   456
{
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   457
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   458
  // All of the ascii enable functions vector through here including the ones
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   459
  // that are wandering through all of devices on perhaps all of the nodes in
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   460
  // the system.  We can only deal with devices of type CsmaNetDevice.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   461
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   462
  Ptr<WifiNetDevice> device = nd->GetObject<WifiNetDevice> ();
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   463
  if (device == 0)
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   464
    {
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   465
      NS_LOG_INFO ("YansWifiHelper::EnableAsciiInternal(): Device " << device << " not of type ns3::WifiNetDevice");
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   466
      return;
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   467
    }
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   468
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   469
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   470
  // Our trace sinks are going to use packet printing, so we have to make sure
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   471
  // that is turned on.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   472
  //
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   473
  Packet::EnablePrinting ();
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   474
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   475
  uint32_t nodeid = nd->GetNode ()->GetId ();
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   476
  uint32_t deviceid = nd->GetIfIndex ();
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   477
  std::ostringstream oss;
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   478
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   479
  //
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
   480
  // If we are not provided an OutputStreamWrapper, we are expected to create 
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   481
  // one using the usual trace filename conventions and write our traces 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   482
  // without a context since there will be one file per context and therefore
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   483
  // the context would be redundant.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   484
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   485
  if (stream == 0)
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   486
    {
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   487
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   488
      // Set up an output stream object to deal with private ofstream copy 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   489
      // constructor and lifetime issues.  Let the helper decide the actual
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   490
      // name of the file given the prefix.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   491
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   492
      AsciiTraceHelper asciiTraceHelper;
6096
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   493
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   494
      std::string filename;
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   495
      if (explicitFilename)
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   496
        {
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   497
          filename = prefix;
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   498
        }
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   499
      else
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   500
        {
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   501
          filename = asciiTraceHelper.GetFilenameFromDevice (prefix, device);
96deefc231fa plumb explicitFilename everywhere and update manual and tutorial
Craig Dowell <craigdo@ee.washington.edu>
parents: 6091
diff changeset
   502
        }
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   503
6313
351d1431d58d fix bug 916
Craig Dowell <craigdo@ee.washington.edu>
parents: 6299
diff changeset
   504
      Ptr<OutputStreamWrapper> theStream = asciiTraceHelper.CreateFileStream (filename);
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   505
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   506
      // We could go poking through the phy and the state looking for the 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   507
      // correct trace source, but we can let Config deal with that with 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   508
      // some search cost.  Since this is presumably happening at topology
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   509
      // creation time, it doesn't seem much of a price to pay.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   510
      //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   511
      oss.str ("");
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   512
      oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
6313
351d1431d58d fix bug 916
Craig Dowell <craigdo@ee.washington.edu>
parents: 6299
diff changeset
   513
      Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&AsciiPhyReceiveSinkWithoutContext, theStream));
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   514
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   515
      oss.str ("");
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   516
      oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
6313
351d1431d58d fix bug 916
Craig Dowell <craigdo@ee.washington.edu>
parents: 6299
diff changeset
   517
      Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&AsciiPhyTransmitSinkWithoutContext, theStream));
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   518
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   519
      return;
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   520
    }
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   521
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   522
  //
6053
b17ea72acee9 OutputStreamKeeper to OutputStreamWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
   523
  // If we are provided an OutputStreamWrapper, we are expected to use it, and
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   524
  // to provide a context.  We are free to come up with our own context if we
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   525
  // want, and use the AsciiTraceHelper Hook*WithContext functions, but for 
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   526
  // compatibility and simplicity, we just use Config::Connect and let it deal
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   527
  // with coming up with a context.
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   528
  //
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   529
  oss.str ("");
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   530
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/RxOk";
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   531
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyReceiveSinkWithContext, stream));
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   532
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   533
  oss.str ("");
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   534
  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/State/Tx";
6013
fa3ab7f34eb2 checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   535
  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTransmitSinkWithContext, stream));
3912
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   536
}
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   537
4d1a61f80745 new wifi API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   538
} // namespace ns3