NS3 LTE网络仿真程序,只含LTE无线接入网(无EPC)

NS3 LTE网络仿真程序


一 只含LTE无线接入网(无EPC)

首先看最简单情形,编写思路:

创建节点-->安装最简单的移动模型-->安装LTE设置-->关联UE与eNB-->最后激活UE-eNB之间无线承载-->设置仿真参数-->无仿真输出-->结束

#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[]){
//create a ltehelper object
Ptr<LteHelper> lte=CreateObject<LteHelper>();
//为UE eNB创建节点
NodeContainer enbNodes;
enbNodes.Create(1);
NodeContainer ueNodes;
ueNodes.Create(2);
//为节点配置移动模型
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(enbNodes);
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(ueNodes);
//上述节点都在(0,0,0)处
//装载LTE设备及信道
NetDeviceContainer enbdevice;
enbdevice=lte->InstallEnbDevice(enbNodes);
NetDeviceContainer uedevice;
uedevice=lte->InstallUeDevice(ueNodes);
//关联UE 和基站eNB,根据eNB配置来配置每一个UE并创建UE-ENB之间的RRC连接
lte->Attach(uedevice,enbdevice.Get(0));
//激活EPS承载包括UE-ENB之间的无线承载
enum EpsBearer::Qci q=EpsBearer::GBR_CONV_VOICE;
EpsBearer bearer(q);
lte->ActivateDataRadioBearer(uedevice,bearer);
//设置仿真参数
Simulator::Stop(Seconds(0.005));
Simulator::Run();
Simulator::Destroy();
return 0;

}
再看改进版,增加了日志功能,加入了ns3::ConfigStore改变默认参数机制,改进了移动模型,增加了仿真输出。

#include"ns3/core-module.h"
#include"ns3/network-module.h"
#include"ns3/mobility-module.h"
#include"ns3/lte-module.h"
#include"ns3/buildings-helper.h"
#include"ns3/config-store.h"
/*
 * create an LTE-only simulation without EPC
 */

using namespace ns3;
NS_LOG_COMPONENT_DEFINE("LteFirstExample");
int main(int argc,char*argv[]){

    //加入命令行以方便修改参数
CommandLine cmd;
cmd.Parse(argc,argv);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();//注意先Load再save
cmd.Parse(argc,argv);
NS_LOG_INFO("Create LTE NET");
LogComponentEnable("LteFirstExample",LOG_LEVEL_INFO);
//create a ltehelper object  epc object
Ptr<LteHelper> lte=CreateObject<LteHelper>();
/*lte->SetFadingModel("ns3::TraceFadingLossModel");
lte->SetFadingModelAttribute("TraceFilename",StringValue("src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
lte->SetFadingModelAttribute("TraceLength",TimeValue(Seconds(10.0)));
lte->SetFadingModelAttribute("SamplesNum",UintegerValue(10000));
lte->SetFadingModelAttribute("WindowSize",TimeValue(Seconds(0.5)));
lte->SetFadingModelAttribute("RbNum",UintegerValue(100));*/
//为UE eNB创建节点
NodeContainer enbNodes;
enbNodes.Create(1);
NodeContainer ueNodes;
ueNodes.Create(2);
//为节点配置移动模型
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(enbNodes);//初始位置(0,0,0)
//mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
//mobility.Install(ueNodes);
mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator", 
"X", StringValue ("100.0"), 
"Y", StringValue ("100.0"), 
"Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]")); 
mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel", 
"Mode", StringValue ("Time"), 
"Time", StringValue ("2s"), 
"Speed", StringValue ("ns3::ConstantRandomVariable[Constant=1.0]"), 
"Bounds", StringValue ("0|200|0|200")); 
mobility.Install(ueNodes); 
BuildingsHelper::Install (ueNodes); 
// Default scheduler is PF, uncomment to use RR 
//lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler"); 
//装载LTE协议栈
NetDeviceContainer enbdevice;
enbdevice=lte->InstallEnbDevice(enbNodes);
NetDeviceContainer uedevice;
uedevice=lte->InstallUeDevice(ueNodes);
//关联UE 和基站eNB,根据eNB配置来配置每一个UE并创建UE-ENB之间的RRC连接
lte->Attach(uedevice,enbdevice.Get(0));

//激活EPS承载包括UE-ENB之间的无线承载
enum EpsBearer::Qci q=EpsBearer::GBR_CONV_VOICE;
EpsBearer bearer(q);
lte->ActivateDataRadioBearer(uedevice,bearer);
// configure all the simulation scenario here...
//输出PHY MAC RLC PDCP层KPI信息
lte->EnablePhyTraces ();
lte->EnableMacTraces ();
lte->EnableRlcTraces ();
lte->EnablePdcpTraces ();
//设置仿真参数
Simulator::Stop(Seconds(0.005));
Simulator::Run();
Simulator::Destroy();
return 0;

}

在ns运行路径内建立一个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"
来指定想使用的一些属性的新默认值。

然后先Load:

./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
再用Save命令生成模板输入文件:


./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.txtx中。



  • 3
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值