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 lte=CreateObject();
Ptr epc=CreateObject();
//告诉ltehelper epc将会使用
lte->SetEpcHelper(epc);
//epchelper 自动创建和配置Pgw节点,下一步需要将pgw与其他IPV4网络如Internet连接
Ptr pgw=epc->GetPgwNode();
//创建一个romotehost节点并安装协议栈
NodeContainer remoteHostContainer;
remoteHostContainer.Create(1);
Ptr 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 remoteHostStaticRouting=ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject());
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 positionAlloc=CreateObject();
for (uint16_t i=0;iAdd(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 ue=ueNodes.Get(u);
   Ptr ueStaticRouting=ipv4RoutingHelper.GetStaticRouting(ue->GetObject());//为UE设置默认网关
   ueStaticRouting->SetDefaultRoute(epc->GetUeDefaultGatewayAddress(),1);
  }
//关联UE 和基站eNB,根据eNB配置来配置每一个UE并创建UE-ENB之间的RRC连接
for(uint16_t i=0;iAttach(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 tft=Create();
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;uEnableTraces();
//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
NS3 LTE网络仿真程序, 含LTE无线接入网与EPC_第1张图片

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

你可能感兴趣的:(计算机网络区)