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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include <ns3/log.h>
21#include <ns3/object.h>
22#include <ns3/packet.h>
23#include <ns3/ptr.h>
24#include <ns3/simulator.h>
25#include <ns3/spectrum-error-model.h>
26#include <ns3/spectrum-interference.h>
27#include <ns3/test.h>
28
29#include <iostream>
30
31using namespace ns3;
32
33NS_LOG_COMPONENT_DEFINE("SpectrumInterferenceTest");
34
35/**
36 * \ingroup spectrum-tests
37 *
38 * \brief Spectrum Interference Test
39 */
41{
42 public:
43 /**
44 * Constructor
45 * \param s Spectrum value
46 * \param txBytes number of bytes to transmit
47 * \param rxCorrect expected Rx bytes
48 * \param name test name
49 */
51 uint32_t txBytes,
52 bool rxCorrect,
53 std::string name);
55 void DoRun() override;
56 /**
57 * Retrieve the test results
58 * \param si SpectrumInterference instance
59 */
61
62 private:
63 Ptr<SpectrumValue> m_s; //!< Spectrum value
64 uint32_t m_txBytes; //!< number of bytes to transmit
65 bool m_rxCorrectKnownOutcome; //!< expected Rx bytes
66 Ptr<const SpectrumModel> m_mySpectrumModel; //!< Spectrum model pointer
67};
68
70 uint32_t txBytes,
71 bool rxCorrect,
72 std::string name)
73 : TestCase(name),
74 m_s(s),
75 m_txBytes(txBytes),
76 m_rxCorrectKnownOutcome(rxCorrect),
77 m_mySpectrumModel(s->GetSpectrumModel())
78{
79}
80
82{
83}
84
85void
87{
88 Ptr<SpectrumValue> n = Create<SpectrumValue>(m_mySpectrumModel);
89 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_mySpectrumModel);
90 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_mySpectrumModel);
91 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_mySpectrumModel);
92 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_mySpectrumModel);
93
94 (*n)[0] = 5.000000000000e-19;
95 (*n)[1] = 4.545454545455e-19;
96
97 (*i1)[0] = 5.000000000000e-18;
98 (*i2)[0] = 5.000000000000e-16;
99 (*i3)[0] = 1.581138830084e-16;
100 (*i4)[0] = 7.924465962306e-17;
101 (*i1)[1] = 1.437398936440e-18;
102 (*i2)[1] = 5.722388235428e-16;
103 (*i3)[1] = 7.204059965732e-17;
104 (*i4)[1] = 5.722388235428e-17;
105
107 si.SetErrorModel(CreateObject<ShannonSpectrumErrorModel>());
109
110 Time ts = Seconds(1);
111 Time ds = Seconds(1);
112 Time ti1 = Seconds(0);
113 Time di1 = Seconds(3);
114 Time ti2 = Seconds(0.7);
115 Time di2 = Seconds(1);
116 Time ti3 = Seconds(1.2);
117 Time di3 = Seconds(1);
118 Time ti4 = Seconds(1.5);
119 Time di4 = Seconds(0.1);
120
126
127 Ptr<Packet> p = Create<Packet>(m_txBytes);
130
132 // the above will return and after RetrieveTestResults have
133 // been called and after all signals have expired
135}
136
137void
139{
141}
142
143/**
144 * \ingroup spectrum-tests
145 *
146 * \brief Spectrum Interference TestSuite
147 */
149{
150 public:
152};
153
155 : TestSuite("spectrum-interference", Type::UNIT)
156{
157 NS_LOG_INFO("creating SpectrumInterferenceTestSuite");
158
160
161 Bands bands;
162 BandInfo bi;
163
164 bi.fl = 2.400e9;
165 bi.fc = 2.410e9;
166 bi.fh = 2.420e9;
167 bands.push_back(bi);
168
169 bi.fl = 2.420e9;
170 bi.fc = 2.431e9;
171 bi.fh = 2.442e9;
172 bands.push_back(bi);
173
174 m = Create<SpectrumModel>(bands);
175
176 double b; // max deliverable bytes
177
178 const double e = 1e-5; // max tolerated relative error for
179 // deliverable bytes
180
181 // Power Spectral Density of the signal of interest = [-46 -48] dBm;
182 Ptr<SpectrumValue> s1 = Create<SpectrumValue>(m);
183 (*s1)[0] = 1.255943215755e-15;
184 (*s1)[1] = 7.204059965732e-16;
185 b = 10067205.5632012;
186 AddTestCase(new SpectrumInterferenceTestCase(s1, 0, true, "sdBm = [-46 -48] tx bytes: 1"),
187 TestCase::Duration::QUICK);
189 static_cast<uint32_t>(b * 0.5 + 0.5),
190 true,
191 "sdBm = [-46 -48] tx bytes: b*0.5"),
192 TestCase::Duration::QUICK);
194 static_cast<uint32_t>(b * (1 - e) + 0.5),
195 true,
196 "sdBm = [-46 -48] tx bytes: b*(1-e)"),
197 TestCase::Duration::QUICK);
199 static_cast<uint32_t>(b * (1 + e) + 0.5),
200 false,
201 "sdBm = [-46 -48] tx bytes: b*(1+e)"),
202 TestCase::Duration::QUICK);
204 static_cast<uint32_t>(b * 1.5 + 0.5),
205 false,
206 "sdBm = [-46 -48] tx bytes: b*1.5"),
207 TestCase::Duration::QUICK);
209 0xffffffff,
210 false,
211 "sdBm = [-46 -48] tx bytes: 2^32-1"),
212 TestCase::Duration::QUICK);
213
214 // Power Spectral Density of the signal of interest = [-63 -61] dBm;
215 Ptr<SpectrumValue> s2 = Create<SpectrumValue>(m);
216 (*s2)[0] = 2.505936168136e-17;
217 (*s2)[1] = 3.610582885110e-17;
218 b = 882401.591840728;
219 AddTestCase(new SpectrumInterferenceTestCase(s2, 1, true, "sdBm = [-63 -61] tx bytes: 1"),
220 TestCase::Duration::QUICK);
222 static_cast<uint32_t>(b * 0.5 + 0.5),
223 true,
224 "sdBm = [-63 -61] tx bytes: b*0.5"),
225 TestCase::Duration::QUICK);
227 static_cast<uint32_t>(b * (1 - e) + 0.5),
228 true,
229 "sdBm = [-63 -61] tx bytes: b*(1-e)"),
230 TestCase::Duration::QUICK);
232 static_cast<uint32_t>(b * (1 + e) + 0.5),
233 false,
234 "sdBm = [-63 -61] tx bytes: b*(1+e)"),
235 TestCase::Duration::QUICK);
237 static_cast<uint32_t>(b * 1.5 + 0.5),
238 false,
239 "sdBm = [-63 -61] tx bytes: b*1.5"),
240 TestCase::Duration::QUICK);
242 0xffffffff,
243 false,
244 "sdBm = [-63 -61] tx bytes: 2^32-1"),
245 TestCase::Duration::QUICK);
246}
247
248/// 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.
bool m_rxCorrectKnownOutcome
expected Rx bytes
void DoRun() override
Implementation to actually run this TestCase.
Spectrum Interference TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:145
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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