NS3 LTE网络仿真程序, 含LTE无线接入网与EPC

NS3 LTE网络仿真程序, 含LTE无线接入网与EPC

#include"ns3/core-module.h"
#include"ns3/network-module.h"
#include"ns3/mobility-module.h"
#include"ns3/lte-module.h"
#include"ns3/lte-helper.h"
#include"ns3/epc-helper.h"
#include"ns3/ipv4-global-routing-helper.h"
#include"ns3/config-store.h"
#include"ns3/internet-module.h"
#include"ns3/point-to-point-module.h"
#include"ns3/applications-module.h"
/*
 * create an LTE simulation with EPC
 */
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("EpcFirstExample");
int main(int argc,char*argv[]){
uint16_t numOfNode=2;
double simTime=1.1;
double distance=60.0;
double interPacketInterval=100;
    //加入命令行以方便修改参数
CommandLine cmd;
cmd.AddValue("numOfNode","Number of eNodes +UE pairs",numOfNode);
cmd.AddValue("simTime","Total duration of the simulation [s]",simTime);
cmd.AddValue("distance","Distance between eNBs [m]",distance);
cmd.AddValue("interPacketInterval","Inter packet interval [ms]",interPacketInterval);
cmd.Parse(argc,argv);
ConfigStore inputConfig;
inputConfig.ConfigureDefaults();
cmd.Parse(argc,argv);
//create a ltehelper object  epc object
Ptr<LteHelper> lte=CreateObject<LteHelper>();
Ptr<PointToPointEpcHelper> epc=CreateObject<PointToPointEpcHelper>();
//告诉ltehelper epc将会使用
lte->SetEpcHelper(epc);
//epchelper 自动创建和配置Pgw节点,下一步需要将pgw与其他IPV4网络如Internet连接
Ptr<Node> pgw=epc->GetPgwNode();
//创建一个romotehost节点并安装协议栈
NodeContainer remoteHostContainer;
remoteHostContainer.Create(1);
Ptr<Node> remoteHost=remoteHostContainer.Get(0);
InternetStackHelper internet;
internet.Install(remoteHostContainer);//创建一个remoteHost,遵循internet协议
//pgw remoteHost 安装P2P2设备
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute("DataRate",DataRateValue(DataRate("100Gb/s")));
p2ph.SetDeviceAttribute("Mtu",UintegerValue(1500));//最大传输单元
p2ph.SetChannelAttribute("Delay",TimeValue(Seconds(0.010)));
NetDeviceContainer internetDevice=p2ph.Install(pgw,remoteHost);
//pgw remoteHost分配IP地址
Ipv4AddressHelper ipv4h;
ipv4h.SetBase("1.0.0.0","255.0.0.0");
Ipv4InterfaceContainer internetIpIface=ipv4h.Assign(internetDevice);//创建网络
Ipv4Address remoteHostAddr=internetIpIface.GetAddress(1);//接口0 是localhost 接口1是 p2p device
//remoteHost 怎么才能路由到Ue,利用UE默认在公共网络7.0.0.0
Ipv4StaticRoutingHelper ipv4RoutingHelper;
Ptr<Ipv4StaticRouting> remoteHostStaticRouting=ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"),Ipv4Mask("255.0.0.0"),1);

//为UE eNB创建节点
NodeContainer enbNodes;
enbNodes.Create(numOfNode);
NodeContainer ueNodes;
ueNodes.Create(numOfNode);
//为节点配置移动模型
Ptr<ListPositionAllocator> positionAlloc=CreateObject<ListPositionAllocator>();
for (uint16_t i=0;i<numOfNode;i++)
    positionAlloc->Add(Vector(distance*i,0,0));//初始位置(distance*i,0,0)
MobilityHelper mobility;
mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.SetPositionAllocator(positionAlloc);
mobility.Install(enbNodes);
//mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
mobility.Install(ueNodes);
//装载LTE设备及信道
NetDeviceContainer enbdevice;
enbdevice=lte->InstallEnbDevice(enbNodes);
NetDeviceContainer uedevice;
uedevice=lte->InstallUeDevice(ueNodes);

//这里不再是LTE-ONLY,需要将LTE连接IP 分配IP地址给UE
internet.Install(ueNodes);//安装IP协议栈在UE节点
Ipv4InterfaceContainer ueIpIface;
ueIpIface=epc->AssignUeIpv4Address(NetDeviceContainer(uedevice));
//
for(uint32_t u=0;u<ueNodes.GetN();++u)
  {Ptr<Node> ue=ueNodes.Get(u);
   Ptr<Ipv4StaticRouting> ueStaticRouting=ipv4RoutingHelper.GetStaticRouting(ue->GetObject<Ipv4>());//为UE设置默认网关
   ueStaticRouting->SetDefaultRoute(epc->GetUeDefaultGatewayAddress(),1);
  }
//关联UE 和基站eNB,根据eNB配置来配置每一个UE并创建UE-ENB之间的RRC连接
for(uint16_t i=0;i<numOfNode;i++)
  {
    lte->Attach(uedevice.Get(i),enbdevice.Get(i));//默认EPS承载将激活
  }
//含有EPC时ActivateDataRadioBearer不用了
/*//激活EPS承载包括UE-ENB之间的无线承载
enum EpsBearer::Qci q=EpsBearer::GBR_CONV_VOICE;
EpsBearer bearer(q);
lte->ActivateDataRadioBearer(uedevice,bearer);*/
//改用默认EPS承载(由LteHelper::Attcah()自动激活)或者专用EPS承载(LteHelper::ActivateDedicatedEpsBearer())
Ptr<EpcTft> tft=Create<EpcTft>();
EpcTft::PacketFilter pf;
pf.localPortStart=1234;
pf.localPortEnd=1234;
tft->Add(pf);
lte->ActivateDedicatedEpsBearer(uedevice,EpsBearer(EpsBearer::NGBR_VIDEO_TCP_DEFAULT),tft);
//最后是在UE节点安装应用(与远程应用程序通信)
//下面是一个UdpClient APP 建立在远程客户端 下行
uint16_t dl_port=1234;
uint16_t ul_port=2000;
uint16_t other_port=3000;
ApplicationContainer clientApps;
ApplicationContainer serverApps;
for(uint32_t u=0;u<ueNodes.GetN();++u){
++ul_port;++other_port;
PacketSinkHelper dlPacketSinkHelper("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),dl_port));
PacketSinkHelper ulPacketSinkHelper("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),ul_port));
PacketSinkHelper packetSinkHelper("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),other_port));
serverApps.Add(dlPacketSinkHelper.Install(ueNodes.Get(u)));
serverApps.Add(ulPacketSinkHelper.Install(remoteHost));
serverApps.Add(packetSinkHelper.Install(ueNodes.Get(u)));

UdpClientHelper dlClient (ueIpIface.GetAddress(u),dl_port);
dlClient.SetAttribute("Interval",TimeValue(MilliSeconds(interPacketInterval)));
dlClient.SetAttribute("MaxPackets",UintegerValue(1000000));

UdpClientHelper ulClient (remoteHostAddr,ul_port);
ulClient.SetAttribute("Interval",TimeValue(MilliSeconds(interPacketInterval)));
ulClient.SetAttribute("MaxPackets",UintegerValue(1000000));

UdpClientHelper Client (ueIpIface.GetAddress(u),other_port);
Client.SetAttribute("Interval",TimeValue(MilliSeconds(interPacketInterval)));
Client.SetAttribute("MaxPackets",UintegerValue(1000000));

clientApps.Add(dlClient.Install(remoteHost));
clientApps.Add(ulClient.Install(ueNodes.Get(u)));

if(u+1<ueNodes.GetN()){
    clientApps.Add(Client.Install(ueNodes.Get(u+1)));
                       }
else 
   clientApps.Add(Client.Install(ueNodes.Get(0)));//第一个节点运行
                                         }

//设置仿真参数
serverApps.Start(Seconds(0.01));
clientApps.Start(Seconds(0.01));
lte->EnableTraces();
//p2ph.EnablePcapAll("lte-epc-first");
Simulator::Stop(Seconds(simTime));
Simulator::Run();
Simulator::Destroy();
return 0;

}
lte->EnableTraces();通过*.txt文件形式存储Phy/Mac/Rlc/Pdcp子层相关KPI信息,当然也可以指定只输出某一层信息:

对于lte->EnablePhyTraces();将输出以下几类文件:

DlRsrpSinrStats.txt                                                                           UlInterferenceStats.txt

DlRxPhyStats.txt                                                                              UlSinrStats.txt           UlRxPhyStats.txt

DlTxPhyStats.txt                                                                              UlTxPhyStats.txt

在RSRP/SINR文件中将包含以下内容:

  1. Simulation time in seconds at which the allocation is indicated by the scheduler
  2. Cell ID
  3. unique UE ID (IMSI)
  4. RSRP
  5. Linear average over all RBs of the downlink SINR in linear units
例如打开DlRsrpSinrStats.txt

SINR文件包含:

  1. Simulation time in seconds at which the allocation is indicated by the scheduler
  2. Cell ID
  3. unique UE ID (IMSI)
  4. uplink SINR in linear units for the UE
Interference文件包括:

  1. Simulation time in seconds at which the allocation is indicated by the scheduler
  2. Cell ID
  3. List of interference values per RB
上下行发射端参数:

  1. Simulation time in milliseconds
  2. Cell ID
  3. unique UE ID (IMSI)
  4. RNTI
  5. Layer of transmission
  6. MCS
  7. size of the TB
  8. Redundancy version
  9. New Data Indicator flag
类似还可以lte->EnableMacTraces();输出

DlMacStats.txt                                                                                  UlMacStats.txt

lte->EnableRlcTraces();输出

DlRlcStats.txt                                                                                   UlRlcStats.txt

lte->EnablePdcpTraces();输出

DlPdcpStats.txt                                                                                 UlPdcpStats.txt

具体每一层KPI参考:

https://www.baidu.com/s?wd=NS3 trace&rsv_spt=1&rsv_iqid=0xbe639d140001ae18&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=0&inputT=830475&rsv_t=ab0crCOOZRZc5AQwQzVeq94V4%2BbmyLVL78KRhsg7%2B%2B%2FsM4hsDiKp4vx5lTPF0%2FlfoVCg&oq=PacketSinkApplication udpechoserver&rsv_pq=f5e6698e0002f1dd&rsv_sug3=68&rsv_sug1=27&rsv_sug7=100&rsv_sug2=0&rsv_sug4=830484

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值