A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
spectrum-interference-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 CTTC
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include <ns3/log.h>
10#include <ns3/object.h>
11#include <ns3/packet.h>
12#include <ns3/ptr.h>
13#include <ns3/simulator.h>
14#include <ns3/spectrum-error-model.h>
15#include <ns3/spectrum-interference.h>
16#include <ns3/test.h>
17
18#include <iostream>
19
20using namespace ns3;
21
22NS_LOG_COMPONENT_DEFINE("SpectrumInterferenceTest");
23
24/**
25 * \ingroup spectrum-tests
26 *
27 * \brief Spectrum Interference Test
28 */
30{
31 public:
32 /**
33 * Constructor
34 * \param s Spectrum value
35 * \param txBytes number of bytes to transmit
36 * \param rxCorrect expected Rx bytes
37 * \param name test name
38 */
40 uint32_t txBytes,
41 bool rxCorrect,
42 std::string name);
44 void DoRun() override;
45 /**
46 * Retrieve the test results
47 * \param si SpectrumInterference instance
48 */
50
51 private:
52 Ptr<SpectrumValue> m_s; //!< Spectrum value
53 uint32_t m_txBytes; //!< number of bytes to transmit
54 bool m_rxCorrectKnownOutcome; //!< expected Rx bytes
55 Ptr<const SpectrumModel> m_mySpectrumModel; //!< Spectrum model pointer
56};
57
59 uint32_t txBytes,
60 bool rxCorrect,
61 std::string name)
62 : TestCase(name),
63 m_s(s),
64 m_txBytes(txBytes),
65 m_rxCorrectKnownOutcome(rxCorrect),
66 m_mySpectrumModel(s->GetSpectrumModel())
67{
68}
69
73
74void
76{
82
83 (*n)[0] = 5.000000000000e-19;
84 (*n)[1] = 4.545454545455e-19;
85
86 (*i1)[0] = 5.000000000000e-18;
87 (*i2)[0] = 5.000000000000e-16;
88 (*i3)[0] = 1.581138830084e-16;
89 (*i4)[0] = 7.924465962306e-17;
90 (*i1)[1] = 1.437398936440e-18;
91 (*i2)[1] = 5.722388235428e-16;
92 (*i3)[1] = 7.204059965732e-17;
93 (*i4)[1] = 5.722388235428e-17;
94
98
99 Time ts = Seconds(1);
100 Time ds = Seconds(1);
101 Time ti1 = Seconds(0);
102 Time di1 = Seconds(3);
103 Time ti2 = Seconds(0.7);
104 Time di2 = Seconds(1);
105 Time ti3 = Seconds(1.2);
106 Time di3 = Seconds(1);
107 Time ti4 = Seconds(1.5);
108 Time di4 = Seconds(0.1);
109
115
119
121 // the above will return and after RetrieveTestResults have
122 // been called and after all signals have expired
124}
125
126void
131
132/**
133 * \ingroup spectrum-tests
134 *
135 * \brief Spectrum Interference TestSuite
136 */
138{
139 public:
141};
142
144 : TestSuite("spectrum-interference", Type::UNIT)
145{
146 NS_LOG_INFO("creating SpectrumInterferenceTestSuite");
147
149
150 Bands bands;
151 BandInfo bi;
152
153 bi.fl = 2.400e9;
154 bi.fc = 2.410e9;
155 bi.fh = 2.420e9;
156 bands.push_back(bi);
157
158 bi.fl = 2.420e9;
159 bi.fc = 2.431e9;
160 bi.fh = 2.442e9;
161 bands.push_back(bi);
162
163 m = Create<SpectrumModel>(bands);
164
165 double b; // max deliverable bytes
166
167 const double e = 1e-5; // max tolerated relative error for
168 // deliverable bytes
169
170 // Power Spectral Density of the signal of interest = [-46 -48] dBm;
172 (*s1)[0] = 1.255943215755e-15;
173 (*s1)[1] = 7.204059965732e-16;
174 b = 10067205.5632012;
175 AddTestCase(new SpectrumInterferenceTestCase(s1, 0, true, "sdBm = [-46 -48] tx bytes: 1"),
176 TestCase::Duration::QUICK);
178 static_cast<uint32_t>(b * 0.5 + 0.5),
179 true,
180 "sdBm = [-46 -48] tx bytes: b*0.5"),
181 TestCase::Duration::QUICK);
183 static_cast<uint32_t>(b * (1 - e) + 0.5),
184 true,
185 "sdBm = [-46 -48] tx bytes: b*(1-e)"),
186 TestCase::Duration::QUICK);
188 static_cast<uint32_t>(b * (1 + e) + 0.5),
189 false,
190 "sdBm = [-46 -48] tx bytes: b*(1+e)"),
191 TestCase::Duration::QUICK);
193 static_cast<uint32_t>(b * 1.5 + 0.5),
194 false,
195 "sdBm = [-46 -48] tx bytes: b*1.5"),
196 TestCase::Duration::QUICK);
198 0xffffffff,
199 false,
200 "sdBm = [-46 -48] tx bytes: 2^32-1"),
201 TestCase::Duration::QUICK);
202
203 // Power Spectral Density of the signal of interest = [-63 -61] dBm;
205 (*s2)[0] = 2.505936168136e-17;
206 (*s2)[1] = 3.610582885110e-17;
207 b = 882401.591840728;
208 AddTestCase(new SpectrumInterferenceTestCase(s2, 1, true, "sdBm = [-63 -61] tx bytes: 1"),
209 TestCase::Duration::QUICK);
211 static_cast<uint32_t>(b * 0.5 + 0.5),
212 true,
213 "sdBm = [-63 -61] tx bytes: b*0.5"),
214 TestCase::Duration::QUICK);
216 static_cast<uint32_t>(b * (1 - e) + 0.5),
217 true,
218 "sdBm = [-63 -61] tx bytes: b*(1-e)"),
219 TestCase::Duration::QUICK);
221 static_cast<uint32_t>(b * (1 + e) + 0.5),
222 false,
223 "sdBm = [-63 -61] tx bytes: b*(1+e)"),
224 TestCase::Duration::QUICK);
226 static_cast<uint32_t>(b * 1.5 + 0.5),
227 false,
228 "sdBm = [-63 -61] tx bytes: b*1.5"),
229 TestCase::Duration::QUICK);
231 0xffffffff,
232 false,
233 "sdBm = [-63 -61] tx bytes: 2^32-1"),
234 TestCase::Duration::QUICK);
235}
236
237/// Static variable for test initialization
Ptr< SpectrumValue > m_s
Spectrum value.
SpectrumInterferenceTestCase(Ptr< SpectrumValue > s, uint32_t txBytes, bool rxCorrect, std::string name)
Constructor.
uint32_t m_txBytes
number of bytes to transmit
void RetrieveTestResult(SpectrumInterference *si)
Retrieve the test results.
Ptr< const SpectrumModel > m_mySpectrumModel
Spectrum model pointer.
void DoRun() override
Implementation to actually run this TestCase.
Spectrum Interference TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
This class implements a gaussian interference model, i.e., all incoming signals are added to the tota...
void SetNoisePowerSpectralDensity(Ptr< const SpectrumValue > noisePsd)
Set the Noise Power Spectral Density.
bool EndRx()
Notify that the RX attempt has ended.
void SetErrorModel(Ptr< SpectrumErrorModel > e)
Set the SpectrumErrorModel to be used.
void StartRx(Ptr< const Packet > p, Ptr< const SpectrumValue > rxPsd)
Notify that the PHY is starting a RX attempt.
void AddSignal(Ptr< const SpectrumValue > spd, const Time duration)
Notify that a new signal is being perceived in the medium.
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition test.h:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< BandInfo > Bands
Container of BandInfo.
static SpectrumInterferenceTestSuite spectrumInterferenceTestSuite
Static variable for test initialization.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband