Loading...
Searching...
No Matches
satellite-cno-estimator-test.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014 Magister Solutions Ltd
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Sami Rantanen <sami.rantanen@magister.fi>
19 */
20
26
27// Include a header file from your module to test.
30
31#include "ns3/boolean.h"
32#include "ns3/config.h"
33#include "ns3/log.h"
34#include "ns3/simulator.h"
35#include "ns3/singleton.h"
36#include "ns3/string.h"
37#include "ns3/test.h"
38#include "ns3/timer.h"
39
40#include <stdint.h>
41
42using namespace ns3;
43
44class SatEstimatorBaseTestCase : public TestCase
45{
46 public:
48 : TestCase("")
49 {
50 }
51
52 SatEstimatorBaseTestCase(std::string info)
53 : TestCase(info)
54 {
55 }
56
58 {
59 }
60
61 // add sample to estimator
62 void AddSample(double cno);
63
64 // get C/N0 estimation.
65 void GetCnoEstimation();
66
67 // create C/N0 estimator.
69
70 protected:
71 virtual void DoRun(void) = 0;
72 Ptr<SatCnoEstimator> m_estimator;
73 std::vector<double> m_cnoEstimations;
74};
75
76void
78{
79 m_estimator->AddSample(cno);
80}
81
82void
84{
85 m_cnoEstimations.push_back(m_estimator->GetCnoEstimation());
86}
87
88void
90{
91 m_estimator = Create<SatBasicCnoEstimator>(mode, window);
92}
93
113{
114 public:
116 : SatEstimatorBaseTestCase("Test satellite C per N0 basic estimator with mode LAST.")
117 {
118 }
119
121 {
122 }
123
124 protected:
125 virtual void DoRun(void);
126};
127
128void
130{
131 // Set simulation output details
132 SatEnvVariables::GetInstance()->DoInitialize();
133 SatEnvVariables::GetInstance()->SetOutputVariables("test-sat-cno-estimator-unit", "last", true);
134
135 // create estimator with window 100 ms
136 Simulator::Schedule(Seconds(0.05),
138 this,
140 Seconds(0.10));
141
142 // simulate sample additions with window 100 ms
143 Simulator::Schedule(Seconds(0.10), &SatBasicEstimatorLastTestCase::AddSample, this, -5.0);
144 Simulator::Schedule(Seconds(0.20), &SatBasicEstimatorLastTestCase::AddSample, this, 5.0);
145 Simulator::Schedule(Seconds(0.30), &SatBasicEstimatorLastTestCase::AddSample, this, -15.0);
146
147 // simulate C/N0 estimations with window 100 ms
148 Simulator::Schedule(Seconds(0.09),
150 this); // NAN expected
151 Simulator::Schedule(Seconds(0.19),
153 this); // -5.0 expected
154 Simulator::Schedule(Seconds(0.25),
156 this); // 5.0 expected
157 Simulator::Schedule(Seconds(0.31),
159 this); // -15.0 expected
160 Simulator::Schedule(Seconds(0.41),
162 this); // NAN expected
163
164 // create estimator with window 300 ms
165 Simulator::Schedule(Seconds(0.5),
167 this,
169 Seconds(0.30));
170
171 // simulate sample additions with window 300 ms
172 Simulator::Schedule(Seconds(0.60), &SatBasicEstimatorLastTestCase::AddSample, this, -6.0);
173 Simulator::Schedule(Seconds(0.70), &SatBasicEstimatorLastTestCase::AddSample, this, 1.0);
174 Simulator::Schedule(Seconds(1.10), &SatBasicEstimatorLastTestCase::AddSample, this, -5.0);
175
176 // simulate C/N0 estimations with window 300 ms
177 Simulator::Schedule(Seconds(0.59),
179 this); // NAN expected
180 Simulator::Schedule(Seconds(0.69),
182 this); // -6.0 expected
183 Simulator::Schedule(Seconds(0.75),
185 this); // 1.0 expected
186 Simulator::Schedule(Seconds(0.91),
188 this); // 1.0 expected
189 Simulator::Schedule(Seconds(1.39),
191 this); // -5.0 expected
192 Simulator::Schedule(Seconds(1.41),
194 this); // NAN expected
195
196 Simulator::Run();
197
198 // After simulation check that estimations are as expected
199
200 // estimations with window 100 ms
201 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[0]), true, "first estimation incorrect");
202 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[1], -5.0, "second estimation incorrect");
203 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[2], 5.0, "third estimation incorrect");
204 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[3], -15.0, "fourth estimation incorrect");
205 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[4]), true, "fifth estimation incorrect");
206
207 // estimations with window 300 ms
208 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[5]), true, "sixth estimation incorrect");
209 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[6], -6.0, "seventh estimation incorrect");
210 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[7], 1.0, "eight estimation incorrect");
211 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[8], 1.0, "ninth estimation incorrect");
212 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[9], -5.0, "tenth estimation incorrect");
213 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[10]), true, "eleventh estimation incorrect");
214
215 Simulator::Destroy();
216
217 SatEnvVariables::GetInstance()->DoDispose();
218}
219
238{
239 public:
241 : SatEstimatorBaseTestCase("Test satellite C per N0 basic estimator with mode MINIMUM.")
242 {
243 }
244
246 {
247 }
248
249 protected:
250 virtual void DoRun(void);
251};
252
253void
255{
256 // Set simulation output details
257 SatEnvVariables::GetInstance()->DoInitialize();
258 SatEnvVariables::GetInstance()->SetOutputVariables("test-sat-cno-estimator-unit", "min", true);
259
260 // create estimator with window 200 ms
261 Simulator::Schedule(Seconds(0.05),
263 this,
265 Seconds(0.20));
266
267 // simulate sample additions with window 100 ms
268 Simulator::Schedule(Seconds(0.17), &SatBasicEstimatorLastTestCase::AddSample, this, -4.2);
269 Simulator::Schedule(Seconds(0.22), &SatBasicEstimatorLastTestCase::AddSample, this, 8.1);
270 Simulator::Schedule(Seconds(0.46), &SatBasicEstimatorLastTestCase::AddSample, this, -15.7);
271 Simulator::Schedule(Seconds(0.48), &SatBasicEstimatorLastTestCase::AddSample, this, 2.4);
272
273 // simulate C/N0 estimations with window 200 ms
274 Simulator::Schedule(Seconds(0.09),
276 this); // NAN expected
277 Simulator::Schedule(Seconds(0.19),
279 this); // -4.2 expected
280 Simulator::Schedule(Seconds(0.35),
282 this); // -4.2 expected
283 Simulator::Schedule(Seconds(0.41),
285 this); // -8.1 expected
286 Simulator::Schedule(Seconds(0.49),
288 this); // -15.7 expected
289 Simulator::Schedule(Seconds(0.69),
291 this); // NAN expected
292
293 Simulator::Run();
294
295 // After simulation check that estimations are as expected
296
297 // estimations with window 200 ms
298 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[0]), true, "first estimation incorrect");
299 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[1], -4.2, "second estimation incorrect");
300 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[2], -4.2, "third estimation incorrect");
301 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[3], 8.1, "fourth estimation incorrect");
302 NS_TEST_ASSERT_MSG_EQ(m_cnoEstimations[4], -15.7, "fifth estimation incorrect");
303 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[5]), true, "sixth estimation incorrect");
304
305 Simulator::Destroy();
306
307 SatEnvVariables::GetInstance()->DoDispose();
308}
309
328{
329 public:
331 : SatEstimatorBaseTestCase("Test satellite C per N0 basic estimator with mode AVERAGE.")
332 {
333 }
334
338
339 protected:
340 virtual void DoRun(void);
341};
342
343void
345{
346 // Set simulation output details
347 SatEnvVariables::GetInstance()->DoInitialize();
348 SatEnvVariables::GetInstance()->SetOutputVariables("test-sat-cno-estimator-unit",
349 "average",
350 true);
351
352 // create estimator with window 200 ms
353 Simulator::Schedule(Seconds(0.05),
355 this,
357 Seconds(0.20));
358
359 // simulate sample additions with window 100 ms
360 Simulator::Schedule(Seconds(0.17), &SatBasicEstimatorLastTestCase::AddSample, this, -4.2);
361 Simulator::Schedule(Seconds(0.22), &SatBasicEstimatorLastTestCase::AddSample, this, 8.1);
362 Simulator::Schedule(Seconds(0.26), &SatBasicEstimatorLastTestCase::AddSample, this, -15.7);
363 Simulator::Schedule(Seconds(0.43), &SatBasicEstimatorLastTestCase::AddSample, this, 2.4);
364
365 // simulate C/N0 estimations with window 200 ms
366 Simulator::Schedule(Seconds(0.09),
368 this); // NAN expected
369 Simulator::Schedule(Seconds(0.19),
371 this); // -4.2 expected
372 Simulator::Schedule(Seconds(0.35),
374 this); // (-4.2 + 8.1 -15.7) / 3 expected
375 Simulator::Schedule(Seconds(0.41),
377 this); // (8.1 -15.7) / 2 expected
378 Simulator::Schedule(Seconds(0.49),
380 this); // 2.4 expected
381 Simulator::Schedule(Seconds(0.69),
383 this); // NAN expected
384
385 Simulator::Run();
386
387 // After simulation check that estimations are as expected
388
389 // estimations with window 200 ms
390 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[0]), true, "first estimation incorrect");
391 NS_TEST_ASSERT_MSG_EQ_TOL(m_cnoEstimations[1], -4.2, 0.0001, "second estimation incorrect");
392 NS_TEST_ASSERT_MSG_EQ_TOL(m_cnoEstimations[2],
393 (-4.2 + 8.1 - 15.7) / 3,
394 0.0001,
395 "third estimation incorrect");
396 NS_TEST_ASSERT_MSG_EQ_TOL(m_cnoEstimations[3],
397 (8.1 - 15.7) / 2,
398 0.0001,
399 "fourth estimation incorrect");
400 NS_TEST_ASSERT_MSG_EQ_TOL(m_cnoEstimations[4], 2.4, 0.0001, "fifth estimation incorrect");
401 NS_TEST_ASSERT_MSG_EQ(std::isnan(m_cnoEstimations[5]), true, "sixth estimation incorrect");
402
403 Simulator::Destroy();
404
405 SatEnvVariables::GetInstance()->DoDispose();
406}
407
412class SatBasicCnoEstimatorTestSuite : public TestSuite
413{
414 public:
416};
417
419 : TestSuite("sat-cno-estimator-unit-test", Type::UNIT)
420{
421 AddTestCase(new SatBasicEstimatorLastTestCase, TestCase::Duration::QUICK);
422 AddTestCase(new SatBasicEstimatorMinTestCase, TestCase::Duration::QUICK);
423 AddTestCase(new SatBasicEstimatorAverageTestCase, TestCase::Duration::QUICK);
424}
425
426// Do allocate an instance of this TestSuite
Test suite for Satellite C/N0 estimator unit test cases.
Test case to unit test satellite C/N0 estimator with mode AVERAGE.
Test case to unit test satellite C/N0 estimator with mode LAST.
Test case to unit test satellite C/N0 estimator with mode MINIMUM.
void CreateEstimator(SatCnoEstimator::EstimationMode_t mode, Time window)
virtual void DoRun(void)=0
EstimationMode_t
Definition of modes for estimator.
@ MINIMUM
Minimum value in the given window returned.
@ LAST
Last value in the given window returned.
@ AVERAGE
Average value in the given window returned.
static Ptr< SatEnvVariables > GetInstance()
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static SatBasicCnoEstimatorTestSuite satCnoEstimatorUnit