20#include "ns3/applications-module.h"
21#include "ns3/core-module.h"
22#include "ns3/internet-module.h"
23#include "ns3/lte-module.h"
24#include "ns3/mobility-module.h"
25#include "ns3/network-module.h"
26#include "ns3/point-to-point-module.h"
56 for (
int j = 0; j < nDevs; j++)
61 if (imsi == uedev->GetImsi())
64 std::cout <<
"IMSI : " << uedev->GetImsi() <<
" at " << pos.x <<
"," << pos.y
83 std::cout <<
Simulator::Now().
As(Time::S) <<
" " << context <<
" UE IMSI " << imsi
84 <<
": connected to cell id " << cellid <<
" with RNTI " << rnti << std::endl;
98 std::cout <<
Simulator::Now().
As(Time::S) <<
" " << context <<
" eNB cell id " << cellId
99 <<
": successful connection of UE with IMSI " << imsi <<
" RNTI " << rnti
117 "IDLE_WAIT_MIB_SIB1",
120 "IDLE_CAMPED_NORMALLY",
122 "IDLE_RANDOM_ACCESS",
124 "CONNECTED_NORMALLY",
125 "CONNECTED_HANDOVER",
126 "CONNECTED_PHY_PROBLEM",
127 "CONNECTED_REESTABLISHING"};
133static const std::string&
155 std::cout <<
Simulator::Now().
As(Time::S) <<
" UE with IMSI " << imsi <<
" RNTI " << rnti
156 <<
" connected to cell " << cellId <<
" transitions from " <<
ToString(oldState)
157 <<
" to " <<
ToString(newState) << std::endl;
169EnbRrcTimeout(uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string cause)
171 std::cout <<
Simulator::Now().
As(Time::S) <<
" IMSI " << imsi <<
", RNTI " << rnti
172 <<
", Cell id " << cellId <<
", ENB RRC " << cause << std::endl;
185 std::cout <<
Simulator::Now() <<
" IMSI " << imsi <<
", RNTI " << rnti <<
", Cell id " << cellId
186 <<
", UE context destroyed at eNodeB" << std::endl;
207 std::cout <<
Simulator::Now().
As(Time::S) <<
" IMSI " << imsi <<
", RNTI " << rnti
208 <<
", Cell id " << cellId <<
", " <<
type <<
", no of sync indications: " << +count
211 if (
type ==
"Notify out of sync" && cellId == 1)
233 std::cout <<
Simulator::Now() <<
" IMSI " << imsi <<
", RNTI " << rnti <<
", Cell id " << cellId
234 <<
", radio link failure detected" << std::endl
242 "T310 timer expired at wrong time");
256 std::cout <<
Simulator::Now().
As(Time::S) <<
" IMSI " << imsi <<
", RNTI " << rnti
257 <<
", Cell id " << cellId <<
", UE RRC Random access Failed" << std::endl;
271 std::cout <<
Simulator::Now().
As(Time::S) <<
" IMSI " << imsi <<
", RNTI " << rnti
272 <<
", Cell id " << cellId <<
", T300 expiration counter "
273 << (uint16_t)connEstFailCount <<
", UE RRC Connection timeout" << std::endl;
287 uint8_t preambleTxCounter,
288 uint8_t maxPreambleTxLimit)
290 std::cout <<
Simulator::Now().
As(Time::S) <<
" IMSI " << imsi <<
", Contention flag "
291 << contention <<
", preamble Tx Counter " << (uint16_t)preambleTxCounter
292 <<
", Max Preamble Tx Limit " << (uint16_t)maxPreambleTxLimit
293 <<
", UE RA response timeout" << std::endl;
317 std::ofstream output;
319 if (firstWrite ==
true)
321 output.open(fileName, std::ofstream::out);
326 output.open(fileName, std::ofstream::app);
334 Simulator::Schedule(binSize, &
Throughput, firstWrite, binSize, fileName);
353main(
int argc,
char* argv[])
357 uint16_t numberOfEnbs = 1;
358 double interSiteDistance = 1200;
362 bool useIdealRrc =
true;
363 bool enableCtrlErrorModel =
true;
364 bool enableDataErrorModel =
true;
365 bool enableNsLogs =
false;
368 cmd.AddValue(
"simTime",
"Total duration of the simulation (in seconds)", simTime);
369 cmd.AddValue(
"numberOfEnbs",
"Number of eNBs", numberOfEnbs);
370 cmd.AddValue(
"n311",
"Number of in-synch indication", n311);
371 cmd.AddValue(
"n310",
"Number of out-of-synch indication", n310);
372 cmd.AddValue(
"t310",
"Timer for detecting the Radio link failure (in seconds)", t310);
373 cmd.AddValue(
"interSiteDistance",
"Inter-site distance in meter", interSiteDistance);
374 cmd.AddValue(
"useIdealRrc",
"Use ideal RRC protocol", useIdealRrc);
375 cmd.AddValue(
"enableCtrlErrorModel",
"Enable control error model", enableCtrlErrorModel);
376 cmd.AddValue(
"enableDataErrorModel",
"Enable data error model", enableDataErrorModel);
377 cmd.AddValue(
"enableNsLogs",
"Enable ns-3 logging (debug builds)", enableNsLogs);
378 cmd.Parse(argc, argv);
395 uint16_t numberOfUes = 1;
396 uint16_t numBearersPerUe = 1;
397 double eNodeB_txPower = 43;
449 remoteHostContainer.
Create(1);
452 internet.
Install(remoteHostContainer);
459 ipv4h.
SetBase(
"1.0.0.0",
"255.0.0.0");
465 remoteHostStaticRouting->AddNetworkRouteTo(
Ipv4Address(
"7.0.0.0"),
Ipv4Mask(
"255.0.0.0"), 1);
470 enbNodes.
Create(numberOfEnbs);
471 ueNodes.
Create(numberOfUes);
476 for (uint16_t i = 0; i < numberOfEnbs; i++)
478 positionAllocEnb->Add(
Vector(interSiteDistance * i, 0, 0));
481 mobility.SetMobilityModel(
"ns3::ConstantPositionMobilityModel");
482 mobility.SetPositionAllocator(positionAllocEnb);
487 for (
int i = 0; i < numberOfUes; i++)
489 positionAllocUe->Add(
Vector(200, 0, 0));
492 mobility.SetPositionAllocator(positionAllocUe);
493 mobility.SetMobilityModel(
"ns3::ConstantVelocityMobilityModel");
496 for (
int i = 0; i < numberOfUes; i++)
502 NS_LOG_INFO(
"Install LTE Devices in eNB and UEs and fix random number stream");
506 int64_t randomStream = 1;
509 randomStream += lteHelper->
AssignStreams(enbDevs, randomStream);
511 randomStream += lteHelper->
AssignStreams(ueDevs, randomStream);
519 lteHelper->
Attach(ueDevs);
521 NS_LOG_INFO(
"Install and start applications on UEs and remote host");
522 uint16_t dlPort = 10000;
523 uint16_t ulPort = 20000;
527 uint64_t bitRate = dataRateValue.Get().GetBitRate();
533 double interPacketInterval =
static_cast<double>(
packetSize * 8) / bitRate;
537 NS_LOG_DEBUG(
"UDP will use application interval " << udpInterval.
As(Time::S) <<
" sec");
539 for (
uint32_t u = 0; u < numberOfUes; ++u)
547 for (
uint32_t b = 0; b < numBearersPerUe; ++b)
559 dlClientHelper.SetAttribute(
"Interval",
TimeValue(udpInterval));
561 dlClientHelper.SetAttribute(
"MaxPackets",
UintegerValue(1000000));
562 dlClientApps.
Add(dlClientHelper.Install(remoteHost));
566 dlServerApps.
Add(dlPacketSinkHelper.Install(ue));
570 ulClientHelper.SetAttribute(
"Interval",
TimeValue(udpInterval));
572 ulClientHelper.SetAttribute(
"MaxPackets",
UintegerValue(1000000));
573 ulClientApps.
Add(ulClientHelper.Install(ue));
577 ulServerApps.
Add(ulPacketSinkHelper.Install(remoteHost));
597 NS_LOG_INFO(
"Enable Lte traces and connect custom trace sinks");
605 Config::Connect(
"/NodeList/*/DeviceList/*/LteEnbRrc/ConnectionEstablished",
607 Config::Connect(
"/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
624 "ComponentCarrierMapUe/*/LteUeMac/RaResponseTimeout",
628 std::ostringstream oss;
629 oss <<
"/NodeList/" << ueNodes.
Get(0)->
GetId() <<
"/ApplicationList/0/$ns3::PacketSink/Rx";
632 bool firstWrite =
true;
633 std::string rrcType = useIdealRrc == 1 ?
"ideal_rrc" :
"real_rrc";
634 std::string fileName =
"rlf_dl_thrput_" + std::to_string(enbNodes.
GetN()) +
"_eNB_" + rrcType;
640 Simulator::Stop(simTime);
645 "UE RRC should receive " << n310
646 <<
" out-of-sync indications in Cell 1."
650 Simulator::Destroy();
a polymophic address class
holds a vector of ns3::Application pointers.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
AttributeValue implementation for Boolean.
Parse command-line arguments.
Mobility model for which the current speed does not change once it has been set and until it is set a...
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold variables of type enum.
This class contains the specification of EPS Bearers.
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Access to the IPv4 forwarding table, interfaces, and configuration.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
a class to represent an Ipv4 address mask
Helper class that adds ns3::Ipv4StaticRouting objects.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
void SetEpcHelper(Ptr< EpcHelper > h)
Set the EpcHelper to be used to setup the EPC network in conjunction with the setup of the LTE radio ...
Ptr< RadioBearerStatsCalculator > GetRlcStats()
Ptr< RadioBearerStatsCalculator > GetPdcpStats()
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
void SetPathlossModelType(TypeId type)
Set the type of path loss model to be used for both DL and UL channels.
void EnableTraces()
Enables trace sinks for PHY, MAC, RLC and PDCP.
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB devices (LteEnbNetDevice) to be created.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used.
uint8_t ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
Activate a dedicated EPS bearer on a given set of UE devices.
The LteUeNetDevice class implements the UE net device.
State
The states of the UE RRC entity.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Ptr< Node > GetPgwNode() const override
Get the PGW node.
Ipv4Address GetUeDefaultGatewayAddress() override
Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices) override
Assign IPv4 addresses to UE devices.
keep track of a set of node pointers.
uint32_t GetN() const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t GetNDevices() const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
AttributeValue implementation for Time.
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
Hold an unsigned integer type.
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs... bargs)
Make Callbacks with varying number of bound arguments.
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Time Now()
create an ns3::Time instance which contains the current simulation time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time t310StartTimeFirstEnb
Time of first N310 indication.
void NotifyConnectionEstablishedEnb(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
eNB Notify connection established.
static const std::string & ToString(LteUeRrc::State s)
void NotifyRaResponseTimeoutUe(uint64_t imsi, bool contention, uint8_t preambleTxCounter, uint8_t maxPreambleTxLimit)
UE RA response timeout notification.
void NotifyConnectionTimeoutUe(uint64_t imsi, uint16_t cellId, uint16_t rnti, uint8_t connEstFailCount)
UE Connection timeout notification.
uint32_t ByteCounter
Byte counter.
void EnbRrcTimeout(uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string cause)
eNB RRC timeout tracer.
uint16_t counterN310FirsteNB
Counter of N310 indications.
void NotifyConnectionEstablishedUe(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
UE Notify connection established.
static const std::string g_ueRrcStateName[LteUeRrc::NUM_STATES]
Map each of UE RRC states to its string representation.
uint32_t oldByteCounter
Old Byte counter,.
void PhySyncDetection(uint16_t n310, uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string type, uint8_t count)
PHY sync detection tracer.
void PrintUePosition(uint64_t imsi)
Print the position of a UE with given IMSI.
void UeStateTransition(uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
UE state transition tracer.
void NotifyRandomAccessErrorUe(uint64_t imsi, uint16_t cellId, uint16_t rnti)
UE Random access error notification.
void RadioLinkFailure(Time t310, uint64_t imsi, uint16_t cellId, uint16_t rnti)
Radio link failure tracer.
void NotifyConnectionReleaseAtEnodeB(uint64_t imsi, uint16_t cellId, uint16_t rnti)
Notification of connection release at eNB.
void Throughput(bool firstWrite, Time binSize, std::string fileName)
Write the troughput to file.
void ReceivePacket(Ptr< const Packet > packet, const Address &)
Receive a packet.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
LogLevel
Logging severity classes and levels.
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
void LogComponentEnable(const char *name, enum LogLevel level)
Enable the logging output associated with that log component.
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
uint16_t localPortEnd
end of the port number range of the UE
uint16_t remotePortEnd
end of the port number range of the remote host
uint16_t remotePortStart
start of the port number range of the remote host
uint16_t localPortStart
start of the port number range of the UE
static const uint32_t packetSize
Packet size generated at the AP.