src/lte/test/lte-propagation-loss-model-test.cc
changeset 8749 4462ac63d4cf
parent 8748 87a141a38088
parent 8747 2aec19a85c73
child 8750 b3db7d51f260
child 8765 b89660102b63
equal deleted inserted replaced
8748:87a141a38088 8749:4462ac63d4cf
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
       
     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: Giuseppe Piro  <g.piro@poliba.it>
       
    19  */
       
    20 
       
    21 #include <iostream>
       
    22 #include <ns3/log.h>
       
    23 #include <string>
       
    24 #include <vector>
       
    25 #include "ns3/log.h"
       
    26 #include "ns3/abort.h"
       
    27 #include "ns3/test.h"
       
    28 #include "ns3/uinteger.h"
       
    29 #include <ns3/simulator.h>
       
    30 #include <ns3/lte-helper.h>
       
    31 #include <ns3/enb-phy.h>
       
    32 #include <ns3/ue-phy.h>
       
    33 #include <ns3/packet-burst.h>
       
    34 #include <ns3/constant-position-mobility-model.h>
       
    35 #include <ns3/constant-velocity-mobility-model.h>
       
    36 #include "ns3/single-model-spectrum-channel.h"
       
    37 #include "ns3/lte-spectrum-phy.h"
       
    38 #include "ns3/enb-lte-spectrum-phy.h"
       
    39 #include "ns3/ue-lte-spectrum-phy.h"
       
    40 #include "ns3/ue-net-device.h"
       
    41 #include "ns3/enb-net-device.h"
       
    42 #include "ns3/ue-manager.h"
       
    43 #include "ns3/spectrum-propagation-loss-model.h"
       
    44 #include "ns3/lte-propagation-loss-model.h"
       
    45 
       
    46 using namespace ns3;
       
    47 
       
    48 /*
       
    49  * Test the LTE physical layer.
       
    50  */
       
    51 class Ns3LtePropagationLossModelTestCase : public TestCase
       
    52 {
       
    53 public:
       
    54   Ns3LtePropagationLossModelTestCase ();
       
    55   virtual ~Ns3LtePropagationLossModelTestCase ();
       
    56 
       
    57 private:
       
    58   virtual void DoRun (void);
       
    59 
       
    60 };
       
    61 
       
    62 Ns3LtePropagationLossModelTestCase::Ns3LtePropagationLossModelTestCase ()
       
    63   : TestCase ("Test the LTE propagation loss model")
       
    64 {
       
    65 }
       
    66 
       
    67 Ns3LtePropagationLossModelTestCase::~Ns3LtePropagationLossModelTestCase ()
       
    68 {
       
    69 }
       
    70 
       
    71 void
       
    72 Ns3LtePropagationLossModelTestCase::DoRun (void)
       
    73 {
       
    74   // CREATE PHY LAYER FOR BOTH UE AND ENB
       
    75   Ptr<EnbLtePhy> phyEnb = CreateObject<EnbLtePhy> ();
       
    76   Ptr<EnbLteSpectrumPhy> dlEnb = CreateObject<EnbLteSpectrumPhy> ();
       
    77   Ptr<EnbLteSpectrumPhy> ulEnb = CreateObject<EnbLteSpectrumPhy> ();
       
    78   phyEnb->SetDownlinkSpectrumPhy (dlEnb);
       
    79   phyEnb->SetUplinkSpectrumPhy (ulEnb);
       
    80   phyEnb->SetTxPower (43);
       
    81 
       
    82   Ptr<UeLtePhy> phyUe = CreateObject<UeLtePhy> ();
       
    83   Ptr<UeLteSpectrumPhy> dlUe = CreateObject<UeLteSpectrumPhy> ();
       
    84   Ptr<UeLteSpectrumPhy> ulUe = CreateObject<UeLteSpectrumPhy> ();
       
    85   phyUe->SetDownlinkSpectrumPhy (dlUe);
       
    86   phyUe->SetUplinkSpectrumPhy (ulUe);
       
    87 
       
    88 
       
    89   // CONFIGURE DL and UL SUB CHANNELS
       
    90   // Define a list of sub channels for the downlink
       
    91   std::vector<int> dlSubChannels;
       
    92   for (int i = 0; i < 25; i++)
       
    93     {
       
    94       dlSubChannels.push_back (i);
       
    95     }
       
    96   // Define a list of sub channels for the uplink
       
    97   std::vector<int> ulSubChannels;
       
    98   for (int i = 50; i < 100; i++)
       
    99     {
       
   100       ulSubChannels.push_back (i);
       
   101     }
       
   102 
       
   103   phyEnb->SetDownlinkSubChannels (dlSubChannels);
       
   104   phyEnb->SetUplinkSubChannels (ulSubChannels);
       
   105 
       
   106   phyUe->SetDownlinkSubChannels (dlSubChannels);
       
   107   phyUe->SetUplinkSubChannels (ulSubChannels);
       
   108 
       
   109 
       
   110   // CONFIGURE MOBILITY
       
   111   Ptr<ConstantPositionMobilityModel> enbMobility = CreateObject<ConstantPositionMobilityModel> ();
       
   112   enbMobility->SetPosition (Vector (0.0, 0.0, 0.0));
       
   113   phyEnb->GetDownlinkSpectrumPhy ()->SetMobility (enbMobility);
       
   114   phyEnb->GetUplinkSpectrumPhy ()->SetMobility (enbMobility);
       
   115 
       
   116   Ptr<ConstantVelocityMobilityModel> ueMobility = CreateObject<ConstantVelocityMobilityModel> ();
       
   117   ueMobility->SetPosition (Vector (50.0, 50.0, 0.0));
       
   118   ueMobility->SetVelocity (Vector (50.0, 50.0, 0.0));
       
   119   phyUe->GetDownlinkSpectrumPhy ()->SetMobility (ueMobility);
       
   120   phyUe->GetUplinkSpectrumPhy ()->SetMobility (ueMobility);
       
   121 
       
   122 
       
   123 
       
   124 
       
   125   // CREATE CHANNEL AND ATTACH DEVICE BY ITS, create also PROPAGATION LOSS MODEL
       
   126   Ptr<SingleModelSpectrumChannel> downlinkChannel = CreateObject<SingleModelSpectrumChannel> ();
       
   127   Ptr<SingleModelSpectrumChannel> uplinkChannel =  CreateObject<SingleModelSpectrumChannel> ();
       
   128 
       
   129   dlUe->SetChannel (downlinkChannel);
       
   130   ulUe->SetChannel (uplinkChannel);
       
   131   downlinkChannel->AddRx (dlUe);
       
   132 
       
   133   dlEnb->SetChannel (downlinkChannel);
       
   134   ulEnb->SetChannel (uplinkChannel);
       
   135   downlinkChannel->AddRx (dlEnb);
       
   136   uplinkChannel->AddRx (ulEnb);
       
   137 
       
   138   Ptr<LtePropagationLossModel> mobility = CreateObject<LtePropagationLossModel> ();
       
   139   downlinkChannel->AddSpectrumPropagationLossModel (mobility->GetObject<SpectrumPropagationLossModel> ());
       
   140 
       
   141   mobility->CreateChannelRealization (enbMobility, ueMobility);
       
   142   // initialize multipath model
       
   143   Ptr<JakesFadingLossModel> m = mobility->GetChannelRealization (enbMobility, ueMobility)->GetJakesFadingLossModel ();
       
   144   m->SetPhy (phyUe);
       
   145 
       
   146 
       
   147 
       
   148 
       
   149   //analyze the propagation loss model
       
   150   Ptr<SpectrumValue> txPsd = phyEnb->CreateTxPowerSpectralDensity ();
       
   151   Ptr<SpectrumValue> rxPsd = mobility->CalcRxPowerSpectralDensity (txPsd,enbMobility, ueMobility);
       
   152   std::vector<double> tx, rx;
       
   153   for (Values::const_iterator it = txPsd->ConstValuesBegin ();
       
   154        it != txPsd->ConstValuesEnd (); it++ )
       
   155     {
       
   156       double tx_ = (*it);
       
   157       tx.push_back (tx_);
       
   158     }
       
   159 
       
   160   for (Values::const_iterator it = rxPsd->ConstValuesBegin ();
       
   161        it != rxPsd->ConstValuesEnd (); it++ )
       
   162     {
       
   163       double rx_ = (*it);
       
   164       rx.push_back (rx_);
       
   165     }
       
   166 
       
   167 
       
   168   NS_TEST_ASSERT_MSG_EQ (tx.size (), rx.size (), "Sizes of tx and rx don't agree.");
       
   169 
       
   170   int nbOfValues = tx.size ();
       
   171   for (int i = 0; i < nbOfValues; i++)
       
   172     {
       
   173       NS_TEST_ASSERT_MSG_EQ ((tx.at (i) == 0 && rx.at (i) != 0), false, "Problem with elements of tx and rx.");
       
   174       NS_TEST_ASSERT_MSG_EQ ((tx.at (i) != 0 && (tx.at (i) <= rx.at (i))), false, "Problem with elements of tx and rx.");
       
   175     }
       
   176 
       
   177 
       
   178   Simulator::Destroy ();
       
   179 }
       
   180 // ==============================================================================
       
   181 
       
   182 class Ns3LtePropagationLossModelTestTestSuite : public TestSuite
       
   183 {
       
   184 public:
       
   185   Ns3LtePropagationLossModelTestTestSuite ();
       
   186 };
       
   187 
       
   188 Ns3LtePropagationLossModelTestTestSuite::Ns3LtePropagationLossModelTestTestSuite ()
       
   189   : TestSuite ("lte-propagation-loss-model", UNIT)
       
   190 {
       
   191   AddTestCase (new Ns3LtePropagationLossModelTestCase);
       
   192 }
       
   193 
       
   194 static Ns3LtePropagationLossModelTestTestSuite ns3LtePropagationLossModelTestTestSuite;