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-convolutional-test.h" |
| 33 |
| 34 using namespace ns3; |
| 35 |
| 36 NS_LOG_COMPONENT_DEFINE ("PhySimWifiConvolutionalTest"); |
| 37 |
| 38 PhySimWifiConvolutionalTest::PhySimWifiConvolutionalTest () |
| 39 : TestCase ("PhySim WiFi convolutional test case") |
| 40 { |
| 41 m_convolutional = CreateObject<PhySimConvolutionalEncoder> (); |
| 42 } |
| 43 |
| 44 PhySimWifiConvolutionalTest::~PhySimWifiConvolutionalTest () |
| 45 { |
| 46 } |
| 47 |
| 48 bool |
| 49 PhySimWifiConvolutionalTest::DoRun (void) |
| 50 { |
| 51 SetErrorStatus (false); |
| 52 |
| 53 bool success; |
| 54 |
| 55 // Provide known seed for predictable results |
| 56 SeedManager::SetSeed (1); |
| 57 |
| 58 WifiCodeRate rate[] = { WIFI_CODE_RATE_1_2, WIFI_CODE_RATE_2_3, WIFI_CODE_RATE
_3_4}; |
| 59 std::string description[] = { "1/2 Coding Rate","2/3 Coding Rate", "3/4 Coding
Rate"}; |
| 60 |
| 61 for (int i = 0; i < 3; ++i) |
| 62 { |
| 63 success = RunSingle (rate[i]); |
| 64 if (!success) |
| 65 { |
| 66 NS_LOG_DEBUG ("FAIL: Convolutional test for" << description[i]); |
| 67 } |
| 68 else |
| 69 { |
| 70 NS_LOG_DEBUG ("PASS: Convolutional test for " << description[i]); |
| 71 } |
| 72 NS_TEST_ASSERT_MSG_EQ ( success, true, "Convolutional test failed for " <<
description[i] << " : Input bits before encoding and output bits after de-codin
g do not match"); |
| 73 } |
| 74 |
| 75 success = RunAnnexG (); |
| 76 if (!success) |
| 77 { |
| 78 NS_LOG_DEBUG ("FAIL: Convolutional test for input as in standard annex G")
; |
| 79 } |
| 80 else |
| 81 { |
| 82 NS_LOG_DEBUG ("PASS: Convolutional test for input as in standard annex G")
; |
| 83 } |
| 84 NS_TEST_ASSERT_MSG_EQ ( success, true, "Convolutional test failed as encoded b
its do not match standard annex G"); |
| 85 |
| 86 return false; |
| 87 } |
| 88 |
| 89 bool |
| 90 PhySimWifiConvolutionalTest::RunSingle (WifiCodeRate rate) |
| 91 { |
| 92 // create some random bits |
| 93 itpp::bvec bits = itpp::randb (144); |
| 94 m_convolutional->SetCodingRate (rate); |
| 95 itpp::bvec encodedBits = m_convolutional->Encode (bits); |
| 96 itpp::bvec decodedBits = m_convolutional->Decode (to_vec (encodedBits)); |
| 97 return (decodedBits == bits); |
| 98 } |
| 99 |
| 100 // Verify encoder against the example in the standard annex G |
| 101 bool |
| 102 PhySimWifiConvolutionalTest::RunAnnexG (void) |
| 103 { |
| 104 // Table G.16 -- First 144 Bits After scrambling |
| 105 const itpp::bvec |
| 106 first144BitsAfterScrambling = |
| 107 "0 1 1 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 1 1 1 0 1 1 0 1 0
0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 0 0 1 1
1 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0
1 1 0 0 1 1 1 0 1 0 1 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0"; |
| 108 // Table G.18 -- Coded bits of first DATA symbol |
| 109 const itpp::bvec |
| 110 encoded192Bits = |
| 111 "0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 0 0 1 1 1
0 1 1 0 1 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 1 0 0 1 0 1 0 1 1 1 1 1 0
1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 1 0
0 0 0 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 0
0 1 1 1 1 0 0 0 0 0 1 1 0 1 0 0 1 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 1 0"; |
| 112 m_convolutional->SetCodingRate (WIFI_CODE_RATE_3_4); |
| 113 itpp::bvec encodedBits = m_convolutional->Encode (first144BitsAfterScrambling)
; |
| 114 return (encodedBits == encoded192Bits); |
| 115 } |
OLD | NEW |