src/devices/wifi/propagation-loss-model-test-suite.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 06 Jan 2010 16:26:07 +0100
changeset 6065 0f012e7d9128
parent 5364 9c79df567f12
permissions -rw-r--r--
bug 602
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5364
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2009 The Boeing Company
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 */
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
#include "ns3/log.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
#include "ns3/abort.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#include "ns3/test.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/pcap-file.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/config.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/string.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/uinteger.h"
6065
0f012e7d9128 bug 602
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 5364
diff changeset
    26
#include "ns3/double.h"
5364
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "ns3/data-rate.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/inet-socket-address.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ns3/internet-stack-helper.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "ns3/ipv4-address-helper.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "ns3/tcp-socket-factory.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "ns3/yans-wifi-helper.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "ns3/propagation-loss-model.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "ns3/propagation-delay-model.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
#include "ns3/yans-wifi-channel.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
#include "ns3/yans-wifi-phy.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
#include "ns3/wifi-net-device.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
#include "ns3/mobility-helper.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
#include "ns3/constant-position-mobility-model.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
#include "ns3/nqos-wifi-mac-helper.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
#include "ns3/simulator.h"
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
using namespace ns3;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
NS_LOG_COMPONENT_DEFINE ("PropagationLossModelsTest");
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
// ===========================================================================
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
// This is a simple test to validate propagation loss models of ns-3 wifi.
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
// See the chapter in the ns-3 testing and validation guide for more detail
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
// ===========================================================================
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
//
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
class FriisPropagationLossModelTestCase : public TestCase
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
public:
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
  FriisPropagationLossModelTestCase ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
  virtual ~FriisPropagationLossModelTestCase ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
private:
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  virtual bool DoRun (void);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
  typedef struct {
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
    Vector m_position;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
    double m_pt;  // dBm
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
    double m_pr;  // W
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
    double m_tolerance;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
  } TestVector;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
  TestVectors<TestVector> m_testVectors;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
};
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
FriisPropagationLossModelTestCase::FriisPropagationLossModelTestCase ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
  : TestCase ("Check to see that the ns-3 Friis propagation loss model provides correct received power"), m_testVectors ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
FriisPropagationLossModelTestCase::~FriisPropagationLossModelTestCase ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
bool
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
FriisPropagationLossModelTestCase::DoRun (void)
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
  // The ns-3 testing manual gives more background on the values selected
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
  // for this test.  First, set a few defaults. 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
  // wavelength at 2.4 GHz is 0.125m
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  Config::SetDefault ("ns3::FriisPropagationLossModel::Lambda", DoubleValue (0.125));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  Config::SetDefault ("ns3::FriisPropagationLossModel::SystemLoss", DoubleValue (1.0));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
  // Select a reference transmit power
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
  // Pt = 10^(17.0206/10)/10^3 = .05035702 W
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
  double txPowerW = 0.05035702;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
  double txPowerdBm = 10 * log10 (txPowerW) + 30;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
  //
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
  // We want to test the propagation loss model calculations at a few chosen 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
  // distances and compare the results to those we have manually calculated
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
  // according to the model documentation.  The model reference specifies, 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
  // for instance, that the received power at 100m according to the provided
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  // input power will be 4.98265e-10 W.  Since this value specifies the power
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  // to 1e-15 significance, we test the ns-3 calculated value for agreement 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
  // within 5e-16.
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  //
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
  TestVector testVector;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  testVector.m_position = Vector (100, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
  testVector.m_pr = 4.98265e-10;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
  testVector.m_tolerance = 5e-16;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
  testVector.m_position = Vector (500, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
  testVector.m_pr = 1.99306e-11;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  testVector.m_tolerance = 5e-17;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
  testVector.m_position = Vector (1000, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  testVector.m_pr = 4.98265e-12;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
  testVector.m_tolerance = 5e-18;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
  testVector.m_position = Vector (2000, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  testVector.m_pr = 1.24566e-12;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  testVector.m_tolerance = 5e-18;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
  // Now, check that the received power values are expected
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
  a->SetPosition (Vector (0,0,0));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
  Ptr<FriisPropagationLossModel> lossModel = CreateObject<FriisPropagationLossModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
    {
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
      testVector = m_testVectors.Get (i);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
      b->SetPosition (testVector.m_position);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
      double resultW =   pow (10.0, resultdBm/10.0)/1000;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
    }
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
	
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  return GetErrorStatus ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
class LogDistancePropagationLossModelTestCase : public TestCase
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
public:
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
  LogDistancePropagationLossModelTestCase ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
  virtual ~LogDistancePropagationLossModelTestCase ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
private:
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  virtual bool DoRun (void);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  typedef struct {
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
    Vector m_position;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
    double m_pt;  // dBm
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
    double m_pr;  // W
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
    double m_tolerance;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
  } TestVector;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  TestVectors<TestVector> m_testVectors;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
};
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
LogDistancePropagationLossModelTestCase::LogDistancePropagationLossModelTestCase ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  : TestCase ("Check to see that the ns-3 Log Distance propagation loss model provides correct received power"), m_testVectors ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
LogDistancePropagationLossModelTestCase::~LogDistancePropagationLossModelTestCase ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
bool
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
LogDistancePropagationLossModelTestCase::DoRun (void)
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
  // reference loss at 2.4 GHz is 40.045997
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
  Config::SetDefault ("ns3::LogDistancePropagationLossModel::ReferenceLoss", DoubleValue (40.045997));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
  Config::SetDefault ("ns3::LogDistancePropagationLossModel::Exponent", DoubleValue (3));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
  // Select a reference transmit power
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
  // Pt = 10^(17.0206/10)/10^3 = .05035702 W
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
  double txPowerW = 0.05035702;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
  double txPowerdBm = 10 * log10 (txPowerW) + 30;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  //
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
  // We want to test the propagation loss model calculations at a few chosen 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
  // distances and compare the results to those we have manually calculated
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
  // according to the model documentation.  The following "TestVector" objects
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
  // will drive the test.
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
  //
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  TestVector testVector;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  testVector.m_position = Vector (10, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
  testVector.m_pr = 4.98265e-9;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  testVector.m_tolerance = 5e-15; 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  testVector.m_position = Vector (20, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
  testVector.m_pr = 6.22831e-10;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
  testVector.m_tolerance = 5e-16;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
  testVector.m_position = Vector (40, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
  testVector.m_pr = 7.78539e-11;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
  testVector.m_tolerance = 5e-17;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
  testVector.m_position = Vector (80, 0, 0);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
  testVector.m_pt = txPowerdBm;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
  testVector.m_pr = 9.73173e-12;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
  testVector.m_tolerance = 5e-17;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
  m_testVectors.Add (testVector);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
  a->SetPosition (Vector (0,0,0));
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
  Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> (); 
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
    {
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
      testVector = m_testVectors.Get (i);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
      b->SetPosition (testVector.m_position);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
      double resultdBm = lossModel->CalcRxPower (testVector.m_pt, a, b);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
      double resultW =   pow (10.0, resultdBm/10.0)/1000;
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   232
      NS_TEST_EXPECT_MSG_EQ_TOL (resultW, testVector.m_pr, testVector.m_tolerance, "Got unexpected rcv power");
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
    }
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
	
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  return GetErrorStatus ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
class PropagationLossModelsTestSuite : public TestSuite
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   240
public:
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
  PropagationLossModelsTestSuite ();
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   242
};
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   243
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
PropagationLossModelsTestSuite::PropagationLossModelsTestSuite ()
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  : TestSuite ("propagation-loss-model", UNIT)
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
{
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
  AddTestCase (new FriisPropagationLossModelTestCase);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
  AddTestCase (new LogDistancePropagationLossModelTestCase);
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
}
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
9c79df567f12 Fix propagation-loss-model test suite; make it a unit test
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
PropagationLossModelsTestSuite WifiPropagationLossModelsTestSuite;