OLD | NEW |
(Empty) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Jens Mittag, Stylianos Papanastasiou |
| 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 * Authors: |
| 19 * Jens Mittag <jens.mittag@kit.edu> |
| 20 * Stylianos Papanastasiou <stylianos@gmail.com> |
| 21 */ |
| 22 |
| 23 #include <itpp/itcomm.h> |
| 24 #include "ns3/config.h" |
| 25 #include "ns3/log.h" |
| 26 #include "ns3/boolean.h" |
| 27 #include "ns3/double.h" |
| 28 #include "ns3/uinteger.h" |
| 29 #include "ns3/object-factory.h" |
| 30 #include "ns3/physim-helper.h" |
| 31 #include "ns3/random-variable.h" |
| 32 #include "physim-wifi-modulator-test.h" |
| 33 |
| 34 using namespace ns3; |
| 35 |
| 36 NS_LOG_COMPONENT_DEFINE ("PhySimWifiModulatorTest"); |
| 37 |
| 38 PhySimWifiModulatorTest::PhySimWifiModulatorTest () |
| 39 : TestCase ("PhySim WiFi modulator test case") |
| 40 { |
| 41 CreateObject<PhySimChannelEstimator> (); |
| 42 m_symbolcreator = CreateObject<PhySimOFDMSymbolCreator> (); |
| 43 m_symbolcreator->SetChannelEstimator ("ns3::PhySimChannelEstimator"); |
| 44 } |
| 45 |
| 46 PhySimWifiModulatorTest::~PhySimWifiModulatorTest () |
| 47 { |
| 48 } |
| 49 |
| 50 bool |
| 51 PhySimWifiModulatorTest::DoRun (void) |
| 52 { |
| 53 SetErrorStatus (false); |
| 54 |
| 55 // Provide known seed for predictable results |
| 56 SeedManager::SetSeed (1); |
| 57 |
| 58 PhySimHelper::ModulationType modulation = PhySimHelper::BPSK; |
| 59 uint8_t constellation = 2; |
| 60 uint16_t blockSize = 48; |
| 61 std::string description = "BPSK"; |
| 62 RunSingle (modulation, constellation, blockSize, description); |
| 63 |
| 64 modulation = PhySimHelper::QPSK; |
| 65 constellation = 4; |
| 66 blockSize = 96; |
| 67 description = "QPSK"; |
| 68 RunSingle (modulation, constellation, blockSize, description); |
| 69 |
| 70 modulation = PhySimHelper::QAM16; |
| 71 constellation = 16; |
| 72 blockSize = 192; |
| 73 description = "QAM-16"; |
| 74 RunSingle (modulation, constellation, blockSize, description); |
| 75 |
| 76 modulation = PhySimHelper::QAM64; |
| 77 constellation = 64; |
| 78 blockSize = 288; |
| 79 description = "QAM-64"; |
| 80 RunSingle (modulation, constellation, blockSize, description); |
| 81 |
| 82 return false; |
| 83 } |
| 84 |
| 85 bool |
| 86 PhySimWifiModulatorTest::RunSingle (PhySimHelper::ModulationType modulation,uint
8_t constellation, uint16_t blockSize, std::string description) |
| 87 { |
| 88 // create some random bits |
| 89 itpp::bvec bits = itpp::randb (blockSize); |
| 90 m_symbolcreator->SetModulationType (modulation,constellation); |
| 91 itpp::cvec modulatedBits = m_symbolcreator->Modulate (bits,0); |
| 92 itpp::bvec demodulatedBits = to_bvec (m_symbolcreator->DeModulate (modulatedBi
ts,0)); |
| 93 bool success = (demodulatedBits == bits); |
| 94 if (!success) |
| 95 { |
| 96 NS_LOG_DEBUG ("FAIL: Modulation test for" << description); |
| 97 } |
| 98 else |
| 99 { |
| 100 NS_LOG_DEBUG ("PASS: Modulation test for " << description); |
| 101 } |
| 102 NS_TEST_ASSERT_MSG_EQ (success, true, "Modulation test failed for " << descrip
tion); |
| 103 return success; |
| 104 } |
OLD | NEW |