LTE用戶文檔
2. 使用概述
ns-3 LTE 模塊是一個軟件庫,允許仿真LTE網絡,一些情況下還可以仿真核心網 Evolved Packet Core (EPC)。仿真過程通常涉及以下幾個步驟:
- 定義仿真場景。
- 編寫程序,重建期望的仿真場景拓撲/架構,通過使用 ns3::LteHelper API(定義在 src/lte/helper/lte-helper.h 中)訪問 ns-3 LTE 模型庫。
-
指定 objects 的配置參數,通過使用 input files(通過 ns3::ConfigStore)或直接在仿真程序中編寫。
- 配置仿真器期望的輸出。
- 運行仿真。
3. 基本的仿真程序
下面是一個最簡單的仿真程序,只能允許 LTE-only 仿真(沒有EPC)。
1. 初始模板:
#include <ns3/core-module.h> #include <ns3/network-module.h> #include <ns3/mobility-module.h> #include <ns3/lte-module.h>
using namespace ns3; int main (int argc, char *argv[]) { // the rest of the simulation program follows
2. 創建一個 LteHelper 對象:
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
這會實例化一些常見對象(例如信道對象),並提供方法用於添加 eNBs 和UEs 然后配置它們。
3. 為 eNB(s) 和 UEs 創建 Node 對象:
NodeContainer enbNodes; enbNodes.Create (1); NodeContainer ueNodes; ueNodes.Create (2);
注意上述節點實例此時並沒有安裝 LTE 協議棧;它們還是空節點。
4. 為所有節點配置移動性模型:
MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes);
上述代碼會將所有節點放置在坐標 (0,0,0)。請參考 ns-3 移動性模型文檔學習如何設置自己想要的位置或者配置節點運動。
5. 在 eNB(s) 上安裝 LTE 協議棧:
NetDeviceContainer enbDevs; enbDevs = lteHelper->InstallEnbDevice (enbNodes);
6. 在 UEs 上安裝LTE協議棧:
NetDeviceContainer ueDevs; ueDevs = lteHelper->InstallUeDevice (ueNodes);
7. 連接 UEs 到 一個 eNB。這會根據 eNB 配置來配置每個 UE ,並在 eNB 和 UE 之間創建 RRC 連接。
lteHelper->Attach (ueDevs, enbDevs.Get (0));
8.在每個 UE 和它所連接的 eNB 之間激活數據無線承載:
enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
該方法也激活了該承載的兩種飽和業務生成器,分別用於上行和下行。
9.設置仿真停止時間:
Simulator::Stop (Seconds (0.005));
4 配置 LTE 模型參數
所有與LTE 模型相關的參數都可以通過 ns-3 屬性系統管理。關於實現它的所有可能方法(例如環境變量, C++ API, GtkConfigStore...)的詳細信息請參考[ns3tutorial] 和 [ns3manual] 。
接下來,我們開始簡短總結如何使用 input files 和 ns-3 ConfigStore 來實現它。首先,你需要把下列程序放入到代碼中,在 main () 開始的后面:
CommandLine cmd; cmd.Parse (argc, argv); ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line
cmd.Parse (argc, argv);
要想上述代碼工作,確保包含頭文件 #include "ns3/cinfug-store.h"。現在創建一個文本文件命名為(例如)input-defaults.txt 指定你想使用的一些屬性的新的默認值:
default ns3::LteHelper::Scheduler "ns3::PfFfMacScheduler"
default ns3::LteHelper::PathlossModel "ns3::FriisSpectrumPropagationLossModel"
default ns3::LteEnbNetDevice::UlBandwidth "25"
default ns3::LteEnbNetDevice::DlBandwidth "25"
default ns3::LteEnbNetDevice::DlEarfcn "100"
default ns3::LteEnbNetDevice::UlEarfcn "18100"
default ns3::LteUePhy::TxPower "10"
default ns3::LteUePhy::NoiseFigure "9"
default ns3::LteEnbPhy::TxPower "30"
default ns3::LteEnbPhy::NoiseFigure "5"
假定你的仿真程序稱為 src/lte/examples/lte-sim-with-input,可以通過以下方式傳遞屬性設置到仿真程序中:
./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lte-sim-with-input
而且,你可以使用下列命令生成模板輸入文件:
./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lte-sim-with-input
注意上述代碼會將所有的默認值(注冊在你特定建立的仿真器中)放入到輸入文件 input-defaults.txt 中,還包括一些非 LTE 屬性。
我的仿真過程:
首先創建一個輸入文件 input-defaults.txt ,如下:


其次,按照前面的步驟編寫一個最簡單的 LTE 程序 “lte-sim-with-input.cc”。代碼如下:
1 #include "ns3/core-module.h"
2 #include "ns3/network-module.h"
3 #include "ns3/mobility-module.h"
4 #include "ns3/lte-module.h"
5 #include "ns3/config-store.h"
6 #include <ns3/buildings-helper.h>
7 //#include "ns3/gtk-config-store.h"
8
9 using namespace ns3; 10
11 int main (int argc, char *argv[]) 12 { 13 CommandLine cmd; 14 cmd.Parse (argc, argv); 15
16 //注意,先load 再 save! 17 // to save a template default attribute file run it like this: 18 // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Save --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lte-sim-with-input 19 //
20 // to load a previously created default attribute file 21 // ./waf --command-template="%s --ns3::ConfigStore::Filename=input-defaults.txt --ns3::ConfigStore::Mode=Load --ns3::ConfigStore::FileFormat=RawText" --run src/lte/examples/lte-sim-with-input
22
23 ConfigStore inputConfig; 24 inputConfig.ConfigureDefaults (); 25
26 // Parse again so you can override default values from the command line
27 cmd.Parse (argc, argv); 28
29 Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); 30
31 // Uncomment to enable logging 32 // lteHelper->EnableLogComponents (); 33
34 // Create Nodes: eNodeB and UE
35 NodeContainer enbNodes; 36 NodeContainer ueNodes; 37 enbNodes.Create (1); 38 ueNodes.Create (1); 39
40 // Install Mobility Model
41 MobilityHelper mobility; 42 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); 43 mobility.Install (enbNodes); 44 BuildingsHelper::Install (enbNodes); 45 // mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); 46 // mobility.Install (ueNodes); 47 // BuildingsHelper::Install (ueNodes);
48
49 mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", 50 "X", StringValue ("100.0"), 51 "Y", StringValue ("100.0"), 52 "Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]")); 53 mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", 54 "Mode", StringValue ("Time"), 55 "Time", StringValue ("2s"), 56 "Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), 57 "Bounds", StringValue ("0|200|0|200")); 58 mobility.Install(ueNodes); 59 BuildingsHelper::Install (ueNodes); 60
61 // Create Devices and install them in the Nodes (eNB and UE)
62 NetDeviceContainer enbDevs; 63 NetDeviceContainer ueDevs; 64 // Default scheduler is PF, uncomment to use RR 65 //lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
66
67 enbDevs = lteHelper->InstallEnbDevice (enbNodes); 68 ueDevs = lteHelper->InstallUeDevice (ueNodes); 69
70 // Attach a UE to a eNB
71 lteHelper->Attach (ueDevs, enbDevs.Get (0)); 72
73 // Activate a data radio bearer
74 enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; 75 EpsBearer bearer (q); 76 lteHelper->ActivateDataRadioBearer (ueDevs, bearer); 77 //lteHelper->EnableTraces ();
78
79 Simulator::Stop (Seconds (1.05)); 80
81 // configure all the simulation scenario here...
82 lteHelper->EnablePhyTraces (); 83 lteHelper->EnableMacTraces (); 84 lteHelper->EnableRlcTraces (); 85 lteHelper->EnablePdcpTraces (); 86
87 Simulator::Run (); 88
89 // GtkConfigStore config; 90 // config.ConfigureAttributes ();
91
92 Simulator::Destroy (); 93 return 0; 94 }
然后在終端執行"load"命令,傳遞屬性設置到仿真程序中 :

執行完成后, 會增加以下關鍵性能指標(KPI)文件:



注意:由於程序“lte-sim-with-input.cc”是 LTE only 程序,沒有 EPC,所以 DlPdcpStats.txt 和 UlPdcpStats.txt 內容為空。
接着在終端執行 "save" 命令,生成模板輸入文件 :


執行完成后,input-defaults.txt 增加了很多屬性,部分內容截圖如下:


參考文獻
https://www.nsnam.org/docs/models/html/lte-user.html