1
/*******************************************************************************
2
* This file is part of openWNS (open Wireless Network Simulator)
3
* _____________________________________________________________________________
5
* Copyright (C) 2004-2007
6
* Chair of Communication Networks (ComNets)
7
* Kopernikusstr. 5, D-52074 Aachen, Germany
8
* phone: ++49-241-80-27910,
9
* fax: ++49-241-80-22242
10
* email: info@openwns.org
11
* www: http://www.openwns.org
12
* _____________________________________________________________________________
14
* openWNS is free software; you can redistribute it and/or modify it under the
15
* terms of the GNU Lesser General Public License version 2 as published by the
16
* Free Software Foundation;
18
* openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
19
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
23
* You should have received a copy of the GNU Lesser General Public License
24
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
******************************************************************************/
28
#include <WNS/pyconfig/helper/Functions.hpp>
29
#include <WNS/CppUnit.hpp>
30
#include <cppunit/extensions/HelperMacros.h>
33
#include <RISE/plmapping/PhyMode.hpp>
34
#include <RISE/plmapping/CodeRates.hpp>
35
#include <RISE/plmapping/MI2PER.hpp>
37
namespace rise { namespace plmapping { namespace tests {
40
public wns::TestFixture
42
CPPUNIT_TEST_SUITE( MI2PERTest );
43
CPPUNIT_TEST( TestTableEntries );
44
CPPUNIT_TEST( Fixed );
45
CPPUNIT_TEST( TestMI2PER );
46
CPPUNIT_TEST( TestPER2MIB );
47
CPPUNIT_TEST_SUITE_END();
50
virtual ~MI2PERTest();
53
void TestTableEntries();
58
rise::plmapping::CoderMapping* coderMapper; // Singleton
59
rise::plmapping::CoderFullMapping* mi2perMapper; // Singleton
61
wns::service::phy::phymode::MI2PERMappingInterface* testee1;
62
wns::service::phy::phymode::MI2PERMappingInterface* testee2;
68
CPPUNIT_TEST_SUITE_REGISTRATION( MI2PERTest );
70
MI2PERTest::MI2PERTest()
78
MI2PERTest::~MI2PERTest()
81
void MI2PERTest::prepare()
83
wns::pyconfig::Parser pyconfig;
85
"import rise.CoderSpecification\n"
86
"coderMapping = rise.CoderSpecification.default\n"
89
wns::pyconfig::View coderMappingConfig = pyconfig.getView("coderMapping");
90
coderMapper = dynamic_cast<CoderMapping*>(wns::service::phy::phymode::CoderMappingInterface::getCoderMapping(coderMappingConfig));
91
mi2perMapper = dynamic_cast<CoderFullMapping*>(wns::service::phy::phymode::CoderFullMappingInterface::getCoderFullMapping(coderMappingConfig));
92
CPPUNIT_ASSERT(coderMapper != NULL);
93
CPPUNIT_ASSERT(mi2perMapper != NULL);
95
wns::pyconfig::Parser M2Ppyconfig;
96
M2Ppyconfig.loadString(
97
"import rise.CoderSpecification\n"
98
"mi2per = rise.CoderSpecification.default\n"
101
testee1 = new WINNERM2P(M2Ppyconfig);
102
testee2 = new FixedM2P(M2Ppyconfig);
105
void MI2PERTest::cleanup()
114
void MI2PERTest::TestTableEntries()
116
//We have to take into account that here we are introducing the payload,
117
//so the CWL used will be the payload multiplied by the rate of the CoderSpecification
118
WNS_ASSERT_MAX_REL_ERROR( 0.9746288,
119
testee1->mapMI2PER(0.921, 400,coderMapper->fromString("No")),
121
// 300 * 3 = CWL 840 -> the CWL 600 will be used.
122
WNS_ASSERT_MAX_REL_ERROR( 0.9932241,
123
testee1->mapMI2PER(0.35, 280,coderMapper->fromString("Turbo_UMTS-1/3")),
126
WNS_ASSERT_MAX_REL_ERROR( 0.6567467,
127
testee1->mapMI2PER(0.340, 100,coderMapper->fromString("RCPC_BENQ-1/3")),
129
// (450 * 3) / 2 = 675 -> the CWL 576 will be used
130
WNS_ASSERT_MAX_REL_ERROR( 0.00502388,
131
testee1->mapMI2PER(0.799, 450,coderMapper->fromString("LDPC_SEUK-2/3")),
136
void MI2PERTest::Fixed()
138
WNS_ASSERT_MAX_REL_ERROR( 0.05,
139
testee2->mapMI2PER(1.0, // Mutual Information
140
42, // any block length
141
1234), // the coding ID has
144
// another combination should have the same effect
145
WNS_ASSERT_MAX_REL_ERROR( 0.05,
146
testee2->mapMI2PER(0.5, // Mutual Information
147
43, // any block length
148
123), // the coding ID has
153
void MI2PERTest::TestMI2PER()
155
const Coding &coding = coderMapper->fromString("RCPC_BENQ-1/3");
156
const TableCoder* coderFullSpec =
157
dynamic_cast<const TableCoder*>(&(mi2perMapper->getCoderFullSpecification(coding)));
158
CPPUNIT_ASSERT( coderFullSpec != NULL );
159
const CodeWordLengths& codeWordLengths = coderFullSpec->getCWLvector();
160
unsigned int bl = (int) (coderFullSpec->getRate() * (double) codeWordLengths[0] + 0.5); // smallest CWL
161
//std::cout << "TestMI2PER(): "<<coderFullSpec.getName()<<": bl="<<bl<<std::endl;
162
for (double mib=0.0; mib<=1.0; mib+=0.1) {
163
// these two ways should be equivalent:
164
double per1 = testee1->mapMI2PER(mib, bl, coding);
165
double per2 = coderFullSpec->mapMI2PER(mib, bl); // faster access method
166
WNS_ASSERT_MAX_REL_ERROR( per1, per2, 1e-6 );
170
void MI2PERTest::TestPER2MIB()
172
const Coding &coding = coderMapper->fromString("RCPC_BENQ-1/3");
173
const TableCoder* coderFullSpec =
174
dynamic_cast<const TableCoder*>(&(mi2perMapper->getCoderFullSpecification(coding)));
175
CPPUNIT_ASSERT( coderFullSpec != NULL );
176
const CodeWordLengths& codeWordLengths = coderFullSpec->getCWLvector();
177
unsigned int bl = (int) (coderFullSpec->getRate() * (double) codeWordLengths[0] + 0.5); // smallest CWL
178
//std::cout << "TestPER2MIB(): "<<coderFullSpec.getName()<<": bl="<<bl<<std::endl;
179
for (double mib=0.0; mib<=1.0; mib+=0.05) {
180
// these two ways should be equivalent:
181
double per1 = testee1->mapMI2PER(mib, bl, coding);
182
double per2 = coderFullSpec->mapMI2PER(mib, bl); // faster access method
183
//std::cout << "MIB="<<mib<<" => PER="<<per1<<std::endl;
184
WNS_ASSERT_MAX_REL_ERROR( per1, per2, 1e-6 );
186
double mib2 = coderFullSpec->PER2MIB(per1, bl);
187
//std::cout << " PER="<<per1<<" => MIB="<<mib2<<std::endl;
188
WNS_ASSERT_MAX_REL_ERROR( mib, mib2, 0.02 );