src/lr-wpan/test/lr-wpan-error-model-test.cc
author Peter D. Barnes, Jr. <barnes26@llnl.gov>
Fri, 26 Sep 2014 15:51:00 -0700
changeset 10968 2d29fee2b7b8
parent 10762 c2b219af3310
permissions -rw-r--r--
[Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2011 The Boeing Company
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Tom Henderson <thomas.r.henderson@boeing.com>
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
#include <ns3/test.h>
10720
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    21
#include <ns3/log.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    22
#include <ns3/callback.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    23
#include <ns3/packet.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    24
#include <ns3/simulator.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    25
#include <ns3/lr-wpan-error-model.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    26
#include <ns3/propagation-loss-model.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    27
#include <ns3/lr-wpan-net-device.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    28
#include <ns3/lr-wpan-mac.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    29
#include <ns3/node.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    30
#include <ns3/net-device.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    31
#include <ns3/single-model-spectrum-channel.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    32
#include <ns3/mac16-address.h>
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
    33
#include <ns3/constant-position-mobility-model.h>
10755
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    34
#include "ns3/rng-seed-manager.h"
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10762
diff changeset
    36
using namespace ns3;
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10762
diff changeset
    38
NS_LOG_COMPONENT_DEFINE ("lr-wpan-error-model-test");
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
class LrWpanErrorDistanceTestCase : public TestCase
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
public:
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
  LrWpanErrorDistanceTestCase ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
  virtual ~LrWpanErrorDistanceTestCase ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
  uint32_t GetReceived (void) const
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
  {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
    return m_received;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
  }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    50
private:
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
  virtual void DoRun (void);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
  void Callback (McpsDataIndicationParams params, Ptr<Packet> p);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
  uint32_t m_received;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
};
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
class LrWpanErrorModelTestCase : public TestCase
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
public:
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  LrWpanErrorModelTestCase ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
  virtual ~LrWpanErrorModelTestCase ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
private:
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
  virtual void DoRun (void);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
};
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
LrWpanErrorDistanceTestCase::LrWpanErrorDistanceTestCase ()
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
  : TestCase ("Test the 802.15.4 error model vs distance"),
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
    m_received (0)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
LrWpanErrorDistanceTestCase::~LrWpanErrorDistanceTestCase ()
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
void
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
LrWpanErrorDistanceTestCase::Callback (McpsDataIndicationParams params, Ptr<Packet> p)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  m_received++;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
void
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
LrWpanErrorDistanceTestCase::DoRun (void)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
{
10755
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    85
  // Set the random seed and run number for this test
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    86
  RngSeedManager::SetSeed (1);
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    87
  RngSeedManager::SetRun (6);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
  Ptr<Node> n0 = CreateObject <Node> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
  Ptr<Node> n1 = CreateObject <Node> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
  Ptr<LrWpanNetDevice> dev0 = CreateObject<LrWpanNetDevice> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
  Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice> ();
10755
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    93
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    94
  // Make random variable stream assignment deterministic
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    95
  dev0->AssignStreams (0);
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    96
  dev1->AssignStreams (10);
0307ac773941 assign fixed random variable streams to lr-wpan tests
Tom Henderson <tomh@tomh.org>
parents: 10753
diff changeset
    97
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
  dev0->SetAddress (Mac16Address ("00:01"));
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
  dev1->SetAddress (Mac16Address ("00:02"));
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
  channel->AddPropagationLossModel (model);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  dev0->SetChannel (channel);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
  dev1->SetChannel (channel);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  n0->AddDevice (dev0);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  n1->AddDevice (dev1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
  Ptr<ConstantPositionMobilityModel> mob0 = CreateObject<ConstantPositionMobilityModel> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
  dev0->GetPhy ()->SetMobility (mob0);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
  Ptr<ConstantPositionMobilityModel> mob1 = CreateObject<ConstantPositionMobilityModel> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
  dev1->GetPhy ()->SetMobility (mob1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
  McpsDataIndicationCallback cb0;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
  cb0 = MakeCallback (&LrWpanErrorDistanceTestCase::Callback, this);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
  dev1->GetMac ()->SetMcpsDataIndicationCallback (cb0);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
  McpsDataRequestParams params;
10720
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
   117
  params.m_srcAddrMode = SHORT_ADDR;
4e4a0de88982 ACK (Sascha Jopen), NetDevice (Tommaso Pecorella and Margherita Filippetti), FCS changes (Erwan Livolant), and clang compliance
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10712
diff changeset
   118
  params.m_dstAddrMode = SHORT_ADDR;
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  params.m_dstPanId = 0;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  params.m_dstAddr = Mac16Address ("00:02");
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
  params.m_msduHandle = 0;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
  params.m_txOptions = 0;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
  Ptr<Packet> p;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  mob0->SetPosition (Vector (0,0,0));
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  mob1->SetPosition (Vector (100,0,0));
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  for (int i = 0; i < 1000; i++)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
    {
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
      p = Create<Packet> (20);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
      Simulator::Schedule (Seconds (i),
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
                           &LrWpanMac::McpsDataRequest,
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
                           dev0->GetMac (), params, p);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
    }
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  Simulator::Run ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
10762
c2b219af3310 Reverted lr-wpan-error-model "fix", the differences were due to randomness problems.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10758
diff changeset
   137
  // Test that we received 977 packets out of 1000, at distance of 100 m
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
  // with default power of 0
10762
c2b219af3310 Reverted lr-wpan-error-model "fix", the differences were due to randomness problems.
Sascha Jopen <jopen@cs.uni-bonn.de>
parents: 10758
diff changeset
   139
  NS_TEST_ASSERT_MSG_EQ (GetReceived (), 977, "Model fails");
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
  Simulator::Destroy ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
// ==============================================================================
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
LrWpanErrorModelTestCase::LrWpanErrorModelTestCase ()
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
  : TestCase ("Test the 802.15.4 error model")
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
LrWpanErrorModelTestCase::~LrWpanErrorModelTestCase ()
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
void
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
LrWpanErrorModelTestCase::DoRun (void)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  Ptr<LrWpanErrorModel> model = CreateObject<LrWpanErrorModel> ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
  // Test a few values
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
  double snr = 5;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
  double ber = 1.0 - model->GetChunkSuccessRate (pow (10.0, snr / 10.0), 1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
  NS_TEST_ASSERT_MSG_EQ_TOL (ber, 7.38e-14, 0.01e-14, "Model fails for SNR = " << snr);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
  snr = 2;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  ber = 1.0 - model->GetChunkSuccessRate (pow (10.0, snr / 10.0), 1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  NS_TEST_ASSERT_MSG_EQ_TOL (ber, 5.13e-7, 0.01e-7, "Model fails for SNR = " << snr);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  snr = -1;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
  ber = 1.0 - model->GetChunkSuccessRate (pow (10.0, snr / 10.0), 1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  NS_TEST_ASSERT_MSG_EQ_TOL (ber, 0.00114, 0.00001, "Model fails for SNR = " << snr);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
  snr = -4;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
  ber = 1.0 - model->GetChunkSuccessRate (pow (10.0, snr / 10.0), 1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
  NS_TEST_ASSERT_MSG_EQ_TOL (ber, 0.0391, 0.0001, "Model fails for SNR = " << snr);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
  snr = -7;
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
  ber = 1.0 - model->GetChunkSuccessRate (pow (10.0, snr / 10.0), 1);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  NS_TEST_ASSERT_MSG_EQ_TOL (ber, 0.175, 0.001, "Model fails for SNR = " << snr);
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
// ==============================================================================
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
class LrWpanErrorModelTestSuite : public TestSuite
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
{
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
public:
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
  LrWpanErrorModelTestSuite ();
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
};
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
LrWpanErrorModelTestSuite::LrWpanErrorModelTestSuite ()
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
  : TestSuite ("lr-wpan-error-model", UNIT)
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
{
10753
c12397c14d1a add TestCase type specifier
Tom Henderson <tomh@tomh.org>
parents: 10730
diff changeset
   188
  AddTestCase (new LrWpanErrorModelTestCase, TestCase::QUICK);
c12397c14d1a add TestCase type specifier
Tom Henderson <tomh@tomh.org>
parents: 10730
diff changeset
   189
  AddTestCase (new LrWpanErrorDistanceTestCase, TestCase::QUICK);
10712
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
}
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
b953606d11fa roll-up of many updates to models, tests, examples
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
static LrWpanErrorModelTestSuite lrWpanErrorModelTestSuite;