src/lte/examples/lte-channel-model.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 /*
       
    22  * Test for the LTE DL Channel Model
       
    23  */
       
    24 
       
    25 #include <iostream>
       
    26 #include <vector>
       
    27 #include <ns3/core-module.h>
       
    28 #include <ns3/network-module.h>
       
    29 #include <ns3/log.h>
       
    30 #include <string>
       
    31 #include <ns3/mobility-module.h>
       
    32 #include <ns3/spectrum-helper.h>
       
    33 #include <ns3/lte-helper.h>
       
    34 #include <ns3/enb-phy.h>
       
    35 #include <ns3/ue-phy.h>
       
    36 #include <ns3/packet-burst.h>
       
    37 #include <ns3/constant-position-mobility-model.h>
       
    38 #include <ns3/constant-velocity-mobility-model.h>
       
    39 #include "ns3/single-model-spectrum-channel.h"
       
    40 #include "ns3/lte-spectrum-phy.h"
       
    41 #include "ns3/enb-lte-spectrum-phy.h"
       
    42 #include "ns3/ue-lte-spectrum-phy.h"
       
    43 #include "ns3/ue-net-device.h"
       
    44 #include "ns3/enb-net-device.h"
       
    45 #include "ns3/ue-manager.h"
       
    46 #include "ns3/spectrum-propagation-loss-model.h"
       
    47 #include "ns3/lte-propagation-loss-model.h"
       
    48 
       
    49 
       
    50 
       
    51 NS_LOG_COMPONENT_DEFINE ("TestChannelModel");
       
    52 
       
    53 using namespace ns3;
       
    54 
       
    55 
       
    56 int main (int argc, char** argv)
       
    57 {
       
    58 
       
    59   LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
       
    60 
       
    61 
       
    62   // CREATE PHY LAYER FOR BOTH UE AND ENB
       
    63   Ptr<EnbLtePhy> phyEnb = CreateObject<EnbLtePhy> ();
       
    64   Ptr<EnbLteSpectrumPhy> dlEnb = CreateObject<EnbLteSpectrumPhy> ();
       
    65   Ptr<EnbLteSpectrumPhy> ulEnb = CreateObject<EnbLteSpectrumPhy> ();
       
    66   phyEnb->SetDownlinkSpectrumPhy (dlEnb);
       
    67   phyEnb->SetUplinkSpectrumPhy (ulEnb);
       
    68   phyEnb->SetTxPower (43);
       
    69 
       
    70   Ptr<UeLtePhy> phyUe = CreateObject<UeLtePhy> ();
       
    71   Ptr<UeLteSpectrumPhy> dlUe = CreateObject<UeLteSpectrumPhy> ();
       
    72   Ptr<UeLteSpectrumPhy> ulUe = CreateObject<UeLteSpectrumPhy> ();
       
    73   phyUe->SetDownlinkSpectrumPhy (dlUe);
       
    74   phyUe->SetUplinkSpectrumPhy (ulUe);
       
    75 
       
    76 
       
    77   // CONFIGURE MOBILITY
       
    78   Ptr<ConstantPositionMobilityModel> enbMobility = CreateObject<ConstantPositionMobilityModel> ();
       
    79   enbMobility->SetPosition (Vector (0.0, 0.0, 0.0));
       
    80   phyEnb->GetDownlinkSpectrumPhy ()->SetMobility (enbMobility);
       
    81   phyEnb->GetUplinkSpectrumPhy ()->SetMobility (enbMobility);
       
    82 
       
    83   Ptr<ConstantVelocityMobilityModel> ueMobility = CreateObject<ConstantVelocityMobilityModel> ();
       
    84   ueMobility->SetPosition (Vector (30.0, 0.0, 0.0));
       
    85   ueMobility->SetVelocity (Vector (30.0, 0.0, 0.0));
       
    86   phyUe->GetDownlinkSpectrumPhy ()->SetMobility (ueMobility);
       
    87   phyUe->GetUplinkSpectrumPhy ()->SetMobility (ueMobility);
       
    88 
       
    89 
       
    90   // CONFIGURE DL and UL SUB CHANNELS
       
    91   // Define a list of sub channels for the downlink
       
    92   std::vector<int> dlSubChannels;
       
    93   for (int i = 0; i < 25; i++)
       
    94     {
       
    95       dlSubChannels.push_back (i);
       
    96     }
       
    97   // Define a list of sub channels for the uplink
       
    98   std::vector<int> ulSubChannels;
       
    99   for (int i = 50; i < 100; i++)
       
   100     {
       
   101       ulSubChannels.push_back (i);
       
   102     }
       
   103 
       
   104   phyEnb->SetDownlinkSubChannels (dlSubChannels);
       
   105   phyEnb->SetUplinkSubChannels (ulSubChannels);
       
   106 
       
   107   phyUe->SetDownlinkSubChannels (dlSubChannels);
       
   108   phyUe->SetUplinkSubChannels (ulSubChannels);
       
   109 
       
   110 
       
   111 
       
   112   // CREATE CHANNEL AND ATTACH DEVICE BY ITS, create also PROPAGATION LOSS MODEL
       
   113   Ptr<SingleModelSpectrumChannel> downlinkChannel = CreateObject<SingleModelSpectrumChannel> ();
       
   114   Ptr<SingleModelSpectrumChannel> uplinkChannel = CreateObject<SingleModelSpectrumChannel> ();
       
   115 
       
   116   dlUe->SetChannel (downlinkChannel);
       
   117   ulUe->SetChannel (uplinkChannel);
       
   118   downlinkChannel->AddRx (dlUe);
       
   119 
       
   120   dlEnb->SetChannel (downlinkChannel);
       
   121   ulEnb->SetChannel (uplinkChannel);
       
   122   downlinkChannel->AddRx (dlEnb);
       
   123   uplinkChannel->AddRx (ulEnb);
       
   124 
       
   125   Ptr<LtePropagationLossModel> mobility = CreateObject<LtePropagationLossModel> ();
       
   126   downlinkChannel->AddSpectrumPropagationLossModel (mobility->GetObject<SpectrumPropagationLossModel> ());
       
   127 
       
   128   mobility->CreateChannelRealization (enbMobility, ueMobility);
       
   129   // initialize multipath model
       
   130   Ptr<JakesFadingLossModel> m = mobility->GetChannelRealization (enbMobility, ueMobility)->GetJakesFadingLossModel ();
       
   131   m->SetPhy (phyUe);
       
   132 
       
   133 
       
   134 
       
   135   /*
       
   136    * ******************
       
   137    * analyze the propagation loss model
       
   138    * ******************
       
   139    */
       
   140 
       
   141 
       
   142   Ptr<SpectrumValue> txPsd = phyEnb->CreateTxPowerSpectralDensity ();
       
   143 
       
   144   Ptr<SpectrumValue> rxPsd = mobility->CalcRxPowerSpectralDensity (txPsd,enbMobility, ueMobility);
       
   145 
       
   146 
       
   147   Simulator::Destroy ();
       
   148 
       
   149   return 0;
       
   150 }