A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lr-wpan-spectrum-value-helper-test.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 The Boeing Company
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Tom Henderson <thomas.r.henderson@boeing.com>
7
*/
8
#include <ns3/log.h>
9
#include <ns3/lr-wpan-spectrum-value-helper.h>
10
#include <ns3/spectrum-value.h>
11
#include <ns3/test.h>
12
13
#include <cmath>
14
15
using namespace
ns3
;
16
using namespace
ns3::lrwpan
;
17
18
/**
19
* @ingroup lr-wpan-test
20
* @ingroup tests
21
*
22
* @brief LrWpan SpectrumValue Helper TestSuite
23
*/
24
class
LrWpanSpectrumValueHelperTestCase
:
public
TestCase
25
{
26
public
:
27
LrWpanSpectrumValueHelperTestCase
();
28
~LrWpanSpectrumValueHelperTestCase
()
override
;
29
30
private
:
31
void
DoRun
()
override
;
32
};
33
34
LrWpanSpectrumValueHelperTestCase::LrWpanSpectrumValueHelperTestCase
()
35
:
TestCase
(
"Test the 802.15.4 SpectrumValue helper class"
)
36
{
37
}
38
39
LrWpanSpectrumValueHelperTestCase::~LrWpanSpectrumValueHelperTestCase
()
40
{
41
}
42
43
void
44
LrWpanSpectrumValueHelperTestCase::DoRun
()
45
{
46
LrWpanSpectrumValueHelper
helper;
47
Ptr<SpectrumValue>
value;
48
double
pwrWatts;
49
for
(
uint32_t
chan = 11; chan <= 26; chan++)
50
{
51
// 50dBm = 100 W, -50dBm = 0.01 mW
52
for
(
double
pwrdBm = -50; pwrdBm < 50; pwrdBm += 10)
53
{
54
value = helper.
CreateTxPowerSpectralDensity
(pwrdBm, chan);
55
pwrWatts = pow(10.0, pwrdBm / 10.0) / 1000;
56
// Test that average power calculation is within +/- 25% of expected
57
NS_TEST_ASSERT_MSG_EQ_TOL
(helper.
TotalAvgPower
(value, chan),
58
pwrWatts,
59
pwrWatts / 4.0,
60
"Not equal for channel "
<< chan <<
" pwrdBm "
<< pwrdBm);
61
}
62
}
63
}
64
65
/**
66
* @ingroup lr-wpan-test
67
* @ingroup tests
68
*
69
* @brief LrWpan SpectrumValue Helper TestSuite
70
*/
71
class
LrWpanSpectrumValueHelperTestSuite
:
public
TestSuite
72
{
73
public
:
74
LrWpanSpectrumValueHelperTestSuite
();
75
};
76
77
LrWpanSpectrumValueHelperTestSuite::LrWpanSpectrumValueHelperTestSuite
()
78
:
TestSuite
(
"lr-wpan-spectrum-value-helper"
,
Type
::UNIT)
79
{
80
AddTestCase
(
new
LrWpanSpectrumValueHelperTestCase
, TestCase::Duration::QUICK);
81
}
82
83
static
LrWpanSpectrumValueHelperTestSuite
84
g_lrWpanSpectrumValueHelperTestSuite
;
//!< Static variable for test initialization
LrWpanSpectrumValueHelperTestCase
LrWpan SpectrumValue Helper TestSuite.
Definition
lr-wpan-spectrum-value-helper-test.cc:25
LrWpanSpectrumValueHelperTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
lr-wpan-spectrum-value-helper-test.cc:44
LrWpanSpectrumValueHelperTestCase::LrWpanSpectrumValueHelperTestCase
LrWpanSpectrumValueHelperTestCase()
Definition
lr-wpan-spectrum-value-helper-test.cc:34
LrWpanSpectrumValueHelperTestCase::~LrWpanSpectrumValueHelperTestCase
~LrWpanSpectrumValueHelperTestCase() override
Definition
lr-wpan-spectrum-value-helper-test.cc:39
LrWpanSpectrumValueHelperTestSuite
LrWpan SpectrumValue Helper TestSuite.
Definition
lr-wpan-spectrum-value-helper-test.cc:72
LrWpanSpectrumValueHelperTestSuite::LrWpanSpectrumValueHelperTestSuite
LrWpanSpectrumValueHelperTestSuite()
Definition
lr-wpan-spectrum-value-helper-test.cc:77
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::lrwpan::LrWpanSpectrumValueHelper
This class defines all functions to create spectrum model for LrWpan.
Definition
lr-wpan-spectrum-value-helper.h:27
ns3::lrwpan::LrWpanSpectrumValueHelper::TotalAvgPower
static double TotalAvgPower(Ptr< const SpectrumValue > psd, uint32_t channel)
total average power of the signal is the integral of the PSD using the limits of the given channel
Definition
lr-wpan-spectrum-value-helper.cc:127
ns3::lrwpan::LrWpanSpectrumValueHelper::CreateTxPowerSpectralDensity
Ptr< SpectrumValue > CreateTxPowerSpectralDensity(double txPower, uint32_t channel)
create spectrum value
Definition
lr-wpan-spectrum-value-helper.cc:65
uint32_t
NS_TEST_ASSERT_MSG_EQ_TOL
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition
test.h:327
g_lrWpanSpectrumValueHelperTestSuite
static LrWpanSpectrumValueHelperTestSuite g_lrWpanSpectrumValueHelperTestSuite
Static variable for test initialization.
Definition
lr-wpan-spectrum-value-helper-test.cc:84
ns3::lrwpan
Definition
lr-wpan-constants.h:23
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lr-wpan
test
lr-wpan-spectrum-value-helper-test.cc
Generated on Fri Dec 13 2024 09:20:42 for ns-3 by
1.11.0