|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
21 #include "ns3/core-module.h"
22 #include "ns3/network-module.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/lte-module.h"
26 #include "ns3/applications-module.h"
27 #include "ns3/point-to-point-module.h"
53 for (
int j = 0; j < nDevs; j++)
61 std::cout <<
"IMSI : " << uedev->
GetImsi () <<
" at " << pos.x <<
"," << pos.y << std::endl;
76 <<
" UE IMSI " << imsi
77 <<
": connected to cell id " << cellid
78 <<
" with RNTI " << rnti
90 <<
" eNB cell id " << cellId
91 <<
": successful connection of UE with IMSI " << imsi
112 "IDLE_WAIT_MIB_SIB1",
115 "IDLE_CAMPED_NORMALLY",
117 "IDLE_RANDOM_ACCESS",
119 "CONNECTED_NORMALLY",
120 "CONNECTED_HANDOVER",
121 "CONNECTED_PHY_PROBLEM",
122 "CONNECTED_REESTABLISHING"
139 <<
" UE with IMSI " << imsi <<
" RNTI " << rnti
140 <<
" connected to cell " << cellId <<
" transitions from "
146 EnbRrcTimeout (uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string cause)
150 <<
" IMSI " << imsi <<
", RNTI " << rnti <<
", Cell id " << cellId
151 <<
", ENB RRC " << cause << std::endl;
158 <<
" IMSI " << imsi <<
", RNTI " << rnti <<
", Cell id " << cellId
159 <<
", UE context destroyed at eNodeB" << std::endl;
162 void PhySyncDetection (uint16_t n310, uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string type, uint8_t count)
166 <<
" IMSI " << imsi <<
", RNTI " << rnti
167 <<
", Cell id " << cellId <<
", " << type <<
", no of sync indications: " << +count
170 if (type ==
"Notify out of sync" && cellId == 1)
184 <<
" IMSI " << imsi <<
", RNTI " << rnti
185 <<
", Cell id " << cellId <<
", radio link failure detected"
186 << std::endl << std::endl;
200 <<
" IMSI " << imsi <<
", RNTI " << rnti <<
", Cell id " << cellId
201 <<
", UE RRC Random access Failed" << std::endl;
206 uint8_t connEstFailCount)
209 <<
" IMSI " << imsi <<
", RNTI " << rnti
210 <<
", Cell id " << cellId
211 <<
", T300 expiration counter " << (uint16_t) connEstFailCount
212 <<
", UE RRC Connection timeout" << std::endl;
217 uint8_t preambleTxCounter,
218 uint8_t maxPreambleTxLimit)
221 <<
" IMSI " << imsi <<
", Contention flag " << contention
222 <<
", preamble Tx Counter " << (uint16_t) preambleTxCounter
223 <<
", Max Preamble Tx Limit " << (uint16_t) maxPreambleTxLimit
224 <<
", UE RA response timeout" << std::endl;
236 std::ofstream output;
238 if (firstWrite ==
true)
240 output.open (fileName.c_str (), std::ofstream::out);
245 output.open (fileName.c_str (), std::ofstream::app);
272 main (
int argc,
char *argv[])
276 uint16_t numberOfEnbs = 1;
277 double interSiteDistance = 1200;
281 bool useIdealRrc =
true;
282 bool enableCtrlErrorModel =
true;
283 bool enableDataErrorModel =
true;
284 bool enableNsLogs =
false;
287 cmd.AddValue (
"simTime",
"Total duration of the simulation (in seconds)", simTime);
288 cmd.AddValue (
"numberOfEnbs",
"Number of eNBs", numberOfEnbs);
289 cmd.AddValue (
"n311",
"Number of in-synch indication", n311);
290 cmd.AddValue (
"n310",
"Number of out-of-synch indication", n310);
291 cmd.AddValue (
"t310",
"Timer for detecting the Radio link failure (in seconds)", t310);
292 cmd.AddValue (
"interSiteDistance",
"Inter-site distance in meter", interSiteDistance);
293 cmd.AddValue (
"useIdealRrc",
"Use ideal RRC protocol", useIdealRrc);
294 cmd.AddValue (
"enableCtrlErrorModel",
"Enable control error model", enableCtrlErrorModel);
295 cmd.AddValue (
"enableDataErrorModel",
"Enable data error model", enableDataErrorModel);
296 cmd.AddValue (
"enableNsLogs",
"Enable ns-3 logging (debug builds)", enableNsLogs);
297 cmd.Parse (argc, argv);
313 uint16_t numberOfUes = 1;
314 uint16_t numBearersPerUe = 1;
315 double eNodeB_txPower = 43;
364 remoteHostContainer.
Create (1);
367 internet.
Install (remoteHostContainer);
374 ipv4h.
SetBase (
"1.0.0.0",
"255.0.0.0");
384 enbNodes.
Create (numberOfEnbs);
385 ueNodes.
Create (numberOfUes);
390 for (uint16_t i = 0; i < numberOfEnbs; i++)
392 positionAllocEnb->
Add (Vector (interSiteDistance * i, 0, 0));
395 mobility.SetMobilityModel (
"ns3::ConstantPositionMobilityModel");
396 mobility.SetPositionAllocator (positionAllocEnb);
401 for (
int i = 0; i < numberOfUes; i++)
403 positionAllocUe->
Add (Vector (200, 0, 0));
406 mobility.SetPositionAllocator (positionAllocUe);
407 mobility.SetMobilityModel (
"ns3::ConstantVelocityMobilityModel");
410 for (
int i = 0; i < numberOfUes; i++)
415 NS_LOG_INFO (
"Install LTE Devices in eNB and UEs and fix random number stream");
419 int64_t randomStream = 1;
422 randomStream += lteHelper->
AssignStreams (enbDevs, randomStream);
424 randomStream += lteHelper->
AssignStreams (ueDevs, randomStream);
433 lteHelper->
Attach (ueDevs);
435 NS_LOG_INFO (
"Install and start applications on UEs and remote host");
436 uint16_t dlPort = 10000;
437 uint16_t ulPort = 20000;
447 double interPacketInterval =
static_cast<double> (
packetSize * 8) / bitRate;
454 for (uint32_t u = 0; u < numberOfUes; ++u)
461 for (uint32_t b = 0; b < numBearersPerUe; ++b)
471 NS_LOG_LOGIC (
"installing UDP DL app for UE " << u + 1);
473 dlClientHelper.SetAttribute (
"Interval",
TimeValue (udpInterval));
475 dlClientHelper.SetAttribute (
"MaxPackets",
UintegerValue (1000000));
476 dlClientApps.
Add (dlClientHelper.Install (remoteHost));
479 dlServerApps.
Add (dlPacketSinkHelper.Install (ue));
481 NS_LOG_LOGIC (
"installing UDP UL app for UE " << u + 1);
483 ulClientHelper.SetAttribute (
"Interval",
TimeValue (udpInterval));
485 ulClientHelper.SetAttribute (
"MaxPackets",
UintegerValue (1000000));
486 ulClientApps.
Add (ulClientHelper.Install (ue));
489 ulServerApps.
Add (ulPacketSinkHelper.Install (remoteHost));
509 NS_LOG_INFO (
"Enable Lte traces and connect custom trace sinks");
517 Config::Connect (
"/NodeList/*/DeviceList/*/LteEnbRrc/ConnectionEstablished",
519 Config::Connect (
"/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
539 std::ostringstream oss;
540 oss <<
"/NodeList/" << ueNodes.
Get (0)->
GetId () <<
"/ApplicationList/0/$ns3::PacketSink/Rx";
543 bool firstWrite =
true;
544 std::string rrcType = useIdealRrc == 1 ?
"ideal_rrc" :
"real_rrc";
545 std::string fileName =
"rlf_dl_thrput_" + std::to_string (enbNodes.
GetN ()) +
"_eNB_" + rrcType;
556 << n310 <<
" out-of-sync indications in Cell 1."
holds a vector of ns3::NetDevice pointers
static Vector GetPosition(Ptr< Node > node)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void EnbRrcTimeout(uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string cause)
AttributeValue implementation for DataRate.
void Throughput(bool firstWrite, Time binSize, std::string fileName)
Create a client application which sends UDP packets carrying a 32bit sequence number and a 64 bit tim...
uint16_t remotePortStart
start of the port number range of the remote host
Parse command-line arguments.
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
void Add(Vector v)
Add a position to the list of positions.
static const std::string g_ueRrcStateName[LteUeRrc::NUM_STATES]
Map each of UE RRC states to its string representation.
AttributeValue implementation for Boolean.
void NotifyConnectionEstablishedUe(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
virtual Ptr< Node > GetPgwNode() const
Get the PGW node.
static Iterator Begin(void)
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
uint32_t GetId(void) const
State
The states of the UE RRC entity.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Implement the data structure representing a TrafficFlowTemplate Packet Filter.
void NotifyRaResponseTimeoutUe(uint64_t imsi, bool contention, uint8_t preambleTxCounter, uint8_t maxPreambleTxLimit)
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB devices (LteEnbNetDevice) to be created.
static const std::string & ToString(EpcUeNas::State s)
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
@ LOG_PREFIX_NODE
Prefix all trace prints with simulation node.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
@ LOG_LEVEL_ALL
Print everything.
uint16_t remotePortEnd
end of the port number range of the remote host
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
uint8_t Add(PacketFilter f)
add a PacketFilter to the Traffic Flow Template
NetDeviceContainer Install(NodeContainer c)
Ipv4 addresses are stored in host order in this class.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
@ NGBR_IMS
Non-GBR IMS Signalling.
Time t310StartTimeFirstEnb
uint64_t GetImsi() const
Get the IMSI.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold variables of type enum.
void NotifyConnectionEstablishedEnb(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
void UeStateTransition(uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
virtual Ipv4Address GetUeDefaultGatewayAddress()
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
void PhySyncDetection(uint16_t n310, uint64_t imsi, uint16_t rnti, uint16_t cellId, std::string type, uint8_t count)
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Access to the IPv4 forwarding table, interfaces, and configuration.
Helper class that adds ns3::Ipv4StaticRouting objects.
Class for representing data rates.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
void ReceivePacket(Ptr< const Packet > packet, const Address &)
void NotifyConnectionTimeoutUe(uint64_t imsi, uint16_t cellId, uint16_t rnti, uint8_t connEstFailCount)
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...
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void SetPathlossModelType(TypeId type)
Set the type of path loss model to be used for both DL and UL channels.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< RadioBearerStatsCalculator > GetPdcpStats(void)
a polymophic address class
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 ...
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
virtual Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices)
Assign IPv4 addresses to UE devices.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
The LteUeNetDevice class implements the UE net device.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
uint8_t ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
Activate a dedicated EPS bearer on a given set of UE devices.
void EnableTraces(void)
Enables trace sinks for PHY, MAC, RLC and PDCP.
uint64_t GetBitRate() const
Get the underlying bitrate.
int64_t AssignStreams(NetDeviceContainer c, int64_t stream)
Assign a fixed random variable stream number to the random variables used.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
static void Run(void)
Run the simulation.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
static Iterator End(void)
@ LOG_PREFIX_TIME
Prefix all trace prints with simulation time.
void Connect(std::string path, const CallbackBase &cb)
This class contains the specification of EPS Bearers.
static Ipv4Address GetAny(void)
void PrintUePosition(uint64_t imsi)
static const uint32_t packetSize
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Mobility model for which the current speed does not change once it has been set and until it is set a...
void NotifyConnectionReleaseAtEnodeB(uint64_t imsi, uint16_t cellId, uint16_t rnti)
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
Time Seconds(double value)
Construct a Time in the indicated unit.
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
uint16_t counterN310FirsteNB
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
LogLevel
Logging severity classes and levels.
holds a vector of ns3::Application pointers.
AttributeValue implementation for Time.
Build a set of PointToPointNetDevice objects.
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
a class to represent an Ipv4 address mask
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
uint16_t localPortStart
start of the port number range of the UE
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
uint32_t GetNDevices(void) const
void RadioLinkFailure(Time t310, uint64_t imsi, uint16_t cellId, uint16_t rnti)
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
void NotifyRandomAccessErrorUe(uint64_t imsi, uint16_t cellId, uint16_t rnti)
aggregate IP/TCP/UDP functionality to existing Nodes.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Helper class used to assign positions and mobility models to nodes.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
uint16_t localPortEnd
end of the port number range of the UE