1. 程式人生 > >基於ns3的LTE模擬基本架構程式碼

基於ns3的LTE模擬基本架構程式碼

#include <ns3/core-module.h>
#include <ns3/network-module.h>
#include <ns3/mobility-module.h>
#include <ns3/lte-module.h>
#include <ns3/config-store.h>

using namespace ns3;

int main (int argc, char *argv[])
{
	CommandLine cmd;
	cmd.Parse (argc, argv);

	// Set the Configure File in input-defaults.txt
	ConfigStore inputConfig;
	inputConfig.ConfigureDefaults ();
	inputConfig.SetFileFormat (ConfigStore::RAW_TEXT);
	inputConfig.SetMode (ConfigStore::LOAD);
	inputConfig.SetFilename ("input-defaults.txt");

	// Create an LteHelper object:
	Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();

	// Create Node objects for the eNB(s) and the UEs -- JUST Empty Nodes
	NodeContainer enbNodes;
	NodeContainer ueNodes;
	enbNodes.Create (1);
	ueNodes.Create (2);

	// Configure the Mobility model for all the nodes:
	// The following will place all nodes at the coordinates (0,0,0).
	MobilityHelper mobility;
	mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
	mobility.Install (enbNodes);
	mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
	mobility.Install (ueNodes);

	// Install an LTE protocol stack on the eNB(s) and UEs:
	NetDeviceContainer enbDevs;
	NetDeviceContainer ueDevs;
	enbDevs = lteHelper->InstallEnbDevice (enbNodes);
	ueDevs = lteHelper->InstallUeDevice (ueNodes);

	// Attach the UEs to an eNB. This will configure each UE according to
	// the eNB configuration, and create an RRC connection between them:
	lteHelper->Attach (ueDevs, enbDevs.Get (0));

	// Activate a data radio bearer between each UE and the eNB it is attached to:
	// This method will also activate two saturation traffic generators for that bearer,
	// one in uplink and one in downlink.
	enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
	EpsBearer bearer (q);
	lteHelper->ActivateDataRadioBearer (ueDevs, bearer);

	// Set the stop time -- this is needed otherwise the simulation will last forever:
	Simulator::Stop (Seconds (0.05));

	// configure all the simulation scenario here...
	lteHelper->EnablePhyTraces ();
	lteHelper->EnableMacTraces ();
	lteHelper->EnableRlcTraces ();
	lteHelper->EnablePdcpTraces ();

	// Run the simulation:
	Simulator::Run ();

	// Cleanup and exit:
	Simulator::Destroy ();

	return 0;
<span style="font-size:14px;">}
</span>

需要在waf執行目錄下放置一個配置文字檔案input-defaults.txt

文字檔案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"