A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lena-profiling.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Jaume Nin <jnin@cttc.es>
7
*/
8
9
#include "ns3/buildings-module.h"
10
#include "ns3/config-store.h"
11
#include "ns3/core-module.h"
12
#include "ns3/lte-module.h"
13
#include "ns3/mobility-module.h"
14
#include "ns3/network-module.h"
15
16
#include <iomanip>
17
#include <string>
18
#include <vector>
19
// #include "ns3/gtk-config-store.h"
20
21
using namespace
ns3
;
22
23
int
24
main(
int
argc
,
char
*
argv
[])
25
{
26
uint32_t
nEnbPerFloor
= 1;
27
uint32_t
nUe
= 1;
28
uint32_t
nFloors
= 0;
29
double
simTime
= 1.0;
30
CommandLine
cmd
(
__FILE__
);
31
32
cmd
.AddValue(
"nEnb"
,
"Number of eNodeBs per floor"
,
nEnbPerFloor
);
33
cmd
.AddValue(
"nUe"
,
"Number of UEs"
,
nUe
);
34
cmd
.AddValue(
"nFloors"
,
"Number of floors, 0 for Friis propagation model"
,
nFloors
);
35
cmd
.AddValue(
"simTime"
,
"Total duration of the simulation (in seconds)"
,
simTime
);
36
cmd
.Parse(
argc
,
argv
);
37
38
ConfigStore
inputConfig
;
39
inputConfig
.
ConfigureDefaults
();
40
41
// parse again so you can override default values from the command line
42
cmd
.Parse(
argc
,
argv
);
43
44
// Geometry of the scenario (in meters)
45
// Assume squared building
46
double
nodeHeight
= 1.5;
47
double
roomHeight
= 3;
48
double
roomLength
= 8;
49
uint32_t
nRooms
= std::ceil(std::sqrt(
nEnbPerFloor
));
50
uint32_t
nEnb
;
51
52
Ptr<LteHelper>
lteHelper
=
CreateObject<LteHelper>
();
53
// lteHelper->EnableLogComponents ();
54
// LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
55
if
(
nFloors
== 0)
56
{
57
lteHelper
->SetAttribute(
"PathlossModel"
,
StringValue
(
"ns3::FriisPropagationLossModel"
));
58
nEnb
=
nEnbPerFloor
;
59
}
60
else
61
{
62
lteHelper
->SetAttribute(
"PathlossModel"
,
63
StringValue
(
"ns3::HybridBuildingsPropagationLossModel"
));
64
nEnb
=
nFloors
*
nEnbPerFloor
;
65
}
66
67
// Create Nodes: eNodeB and UE
68
NodeContainer
enbNodes
;
69
std::vector<NodeContainer>
ueNodes
;
70
71
enbNodes
.
Create
(
nEnb
);
72
for
(
uint32_t
i
= 0;
i
<
nEnb
;
i
++)
73
{
74
NodeContainer
ueNode
;
75
ueNode
.
Create
(
nUe
);
76
ueNodes
.push_back(
ueNode
);
77
}
78
79
MobilityHelper
mobility
;
80
mobility
.SetMobilityModel(
"ns3::ConstantPositionMobilityModel"
);
81
std::vector<Vector>
enbPosition
;
82
Ptr<ListPositionAllocator>
positionAlloc
=
CreateObject<ListPositionAllocator>
();
83
Ptr<Building>
building
;
84
85
if
(
nFloors
== 0)
86
{
87
// Position of eNBs
88
uint32_t
plantedEnb
= 0;
89
for
(
uint32_t
row
= 0;
row
<
nRooms
;
row
++)
90
{
91
for
(
uint32_t
column
= 0;
column
<
nRooms
&&
plantedEnb
<
nEnbPerFloor
;
92
column
++,
plantedEnb
++)
93
{
94
Vector v(
roomLength
* (
column
+ 0.5),
roomLength
* (
row
+ 0.5),
nodeHeight
);
95
positionAlloc
->Add(v);
96
enbPosition
.push_back(v);
97
mobility
.Install(
ueNodes
.at(
plantedEnb
));
98
}
99
}
100
mobility
.SetPositionAllocator(
positionAlloc
);
101
mobility
.Install(
enbNodes
);
102
BuildingsHelper::Install
(
enbNodes
);
103
104
// Position of UEs attached to eNB
105
for
(
uint32_t
i
= 0;
i
<
nEnb
;
i
++)
106
{
107
Ptr<UniformRandomVariable>
posX
=
CreateObject<UniformRandomVariable>
();
108
posX
->SetAttribute(
"Min"
,
DoubleValue
(
enbPosition
.at(
i
).x -
roomLength
* 0.5));
109
posX
->SetAttribute(
"Max"
,
DoubleValue
(
enbPosition
.at(
i
).x +
roomLength
* 0.5));
110
Ptr<UniformRandomVariable>
posY
=
CreateObject<UniformRandomVariable>
();
111
posY
->SetAttribute(
"Min"
,
DoubleValue
(
enbPosition
.at(
i
).y -
roomLength
* 0.5));
112
posY
->SetAttribute(
"Max"
,
DoubleValue
(
enbPosition
.at(
i
).y +
roomLength
* 0.5));
113
positionAlloc
=
CreateObject<ListPositionAllocator>
();
114
for
(
uint32_t
j
= 0;
j
<
nUe
;
j
++)
115
{
116
positionAlloc
->Add(Vector(
posX
->GetValue(),
posY
->GetValue(),
nodeHeight
));
117
mobility
.SetPositionAllocator(
positionAlloc
);
118
}
119
mobility
.Install(
ueNodes
.at(
i
));
120
BuildingsHelper::Install
(
ueNodes
.at(
i
));
121
}
122
}
123
else
124
{
125
building
=
CreateObject<Building>
();
126
building
->SetBoundaries(
127
Box
(0.0,
nRooms
*
roomLength
, 0.0,
nRooms
*
roomLength
, 0.0,
nFloors
*
roomHeight
));
128
building
->SetBuildingType(
Building::Residential
);
129
building
->SetExtWallsType(
Building::ConcreteWithWindows
);
130
building
->SetNFloors(
nFloors
);
131
building
->SetNRoomsX(
nRooms
);
132
building
->SetNRoomsY(
nRooms
);
133
mobility
.Install(
enbNodes
);
134
BuildingsHelper::Install
(
enbNodes
);
135
uint32_t
plantedEnb
= 0;
136
for
(
uint32_t
floor = 0; floor <
nFloors
; floor++)
137
{
138
uint32_t
plantedEnbPerFloor
= 0;
139
for
(
uint32_t
row
= 0;
row
<
nRooms
;
row
++)
140
{
141
for
(
uint32_t
column
= 0;
column
<
nRooms
&&
plantedEnbPerFloor
<
nEnbPerFloor
;
142
column
++,
plantedEnb
++,
plantedEnbPerFloor
++)
143
{
144
Vector v(
roomLength
* (
column
+ 0.5),
145
roomLength
* (
row
+ 0.5),
146
nodeHeight
+
roomHeight
* floor);
147
positionAlloc
->Add(v);
148
enbPosition
.push_back(v);
149
Ptr<MobilityModel>
mmEnb
=
enbNodes
.Get(
plantedEnb
)->GetObject<
MobilityModel
>();
150
mmEnb
->
SetPosition
(v);
151
152
// Positioning UEs attached to eNB
153
mobility
.Install(
ueNodes
.at(
plantedEnb
));
154
BuildingsHelper::Install
(
ueNodes
.at(
plantedEnb
));
155
for
(
uint32_t
ue
= 0;
ue
<
nUe
;
ue
++)
156
{
157
Ptr<MobilityModel>
mmUe
=
158
ueNodes
.at(
plantedEnb
).Get(
ue
)->GetObject<
MobilityModel
>();
159
Vector
vUe
(v.x, v.y, v.z);
160
mmUe
->SetPosition(
vUe
);
161
}
162
}
163
}
164
}
165
}
166
167
// Create Devices and install them in the Nodes (eNB and UE)
168
NetDeviceContainer
enbDevs
;
169
std::vector<NetDeviceContainer>
ueDevs
;
170
enbDevs
=
lteHelper
->InstallEnbDevice(
enbNodes
);
171
for
(
uint32_t
i
= 0;
i
<
nEnb
;
i
++)
172
{
173
NetDeviceContainer
ueDev
=
lteHelper
->InstallUeDevice(
ueNodes
.at(
i
));
174
ueDevs
.push_back(
ueDev
);
175
lteHelper
->Attach(
ueDev
,
enbDevs
.Get(
i
));
176
EpsBearer::Qci
q =
EpsBearer::GBR_CONV_VOICE
;
177
EpsBearer
bearer(q);
178
lteHelper
->ActivateDataRadioBearer(
ueDev
, bearer);
179
}
180
181
Simulator::Stop
(
Seconds
(
simTime
));
182
lteHelper
->EnableTraces();
183
184
Simulator::Run
();
185
186
/*GtkConfigStore config;
187
config.ConfigureAttributes ();*/
188
189
Simulator::Destroy
();
190
return
0;
191
}
ns3::Box
a 3d box
Definition
box.h:24
ns3::Building::ConcreteWithWindows
@ ConcreteWithWindows
Definition
building.h:58
ns3::Building::Residential
@ Residential
Definition
building.h:47
ns3::BuildingsHelper::Install
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
Definition
buildings-helper.cc:34
ns3::CommandLine
Parse command-line arguments.
Definition
command-line.h:221
ns3::ConfigStore
Introspection did not find any typical Config paths.
Definition
config-store.h:50
ns3::ConfigStore::ConfigureDefaults
void ConfigureDefaults()
Configure the default values.
Definition
config-store.cc:181
ns3::DoubleValue
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition
double.h:31
ns3::EpsBearer
This class contains the specification of EPS Bearers.
Definition
eps-bearer.h:80
ns3::EpsBearer::Qci
Qci
QoS Class Indicator.
Definition
eps-bearer.h:95
ns3::EpsBearer::GBR_CONV_VOICE
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition
eps-bearer.h:96
ns3::MobilityHelper
Helper class used to assign positions and mobility models to nodes.
Definition
mobility-helper.h:33
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition
mobility-model.h:29
ns3::MobilityModel::SetPosition
void SetPosition(const Vector &position)
Definition
mobility-model.cc:81
ns3::NetDeviceContainer
holds a vector of ns3::NetDevice pointers
Definition
net-device-container.h:32
ns3::NodeContainer
keep track of a set of node pointers.
Definition
node-container.h:29
ns3::NodeContainer::Create
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Definition
node-container.cc:73
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
ns3::Simulator::Stop
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition
simulator.cc:175
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
uint32_t
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1344
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
second.cmd
cmd
Definition
second.py:29
third.mobility
mobility
Definition
third.py:92
src
lte
examples
lena-profiling.cc
Generated on Mon Dec 15 2025 15:21:56 for ns-3 by
1.9.8