#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
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
NodeContainer enbNodes; enbNodes.Create (1); NodeContainer ueNodes; ueNodes.Create (2);
注意上述节点实例此时并没有安装 LTE 协议栈;它们还是空节点。
MobilityHelper mobility; mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (enbNodes); mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); mobility.Install (ueNodes);
上述代码会将所有节点放置在坐标 (0,0,0)。请参考 ns-3 移动性模型文档学习如何设置自己想要的位置或者配置节点运动。
NetDeviceContainer enbDevs; enbDevs = lteHelper->InstallEnbDevice (enbNodes);
NetDeviceContainer ueDevs; ueDevs = lteHelper->InstallUeDevice (ueNodes);
lteHelper->Attach (ueDevs, enbDevs.Get (0));
enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; EpsBearer bearer (q); lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
Simulator::Stop (Seconds (0.005));
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);
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"
./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
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 }
参考文献
https://www.nsnam.org/docs/models/html/lte-user.html