5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
grid-scenario-helper.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "grid-scenario-helper.h"
6
7#include "ns3/core-module.h"
8#include "ns3/mobility-model.h"
9#include <ns3/double.h>
10#include <ns3/log.h>
11#include <ns3/mobility-helper.h>
12#include <ns3/position-allocator.h>
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("GridScenarioHelper");
18
20{
21 m_x = CreateObject<UniformRandomVariable>();
22 m_y = CreateObject<UniformRandomVariable>();
23 m_initialPos.x = 0.0;
24 m_initialPos.y = 0.0;
25 m_initialPos.z = 0.0;
26}
27
31
32void
34{
35 m_horizontalBsDistance = d;
36}
37
38void
40{
41 m_verticalBsDistance = d;
42}
43
44void
46{
47 m_rows = r;
48}
49
50void
52{
53 m_columns = c;
54}
55
56void
58{
59 m_initialPos = initialPos;
60}
61
62void
63GridScenarioHelper::SetScenarioLength(double m)
64{
65 m_length = m;
66}
67
68void
69GridScenarioHelper::SetScenarioHeight(double m)
70{
71 m_height = m;
72}
73
74void
76{
77 NS_ASSERT(m_rows > 0);
78 NS_ASSERT(m_columns > 0);
79 NS_ASSERT(m_bsHeight >= 0.0);
80 NS_ASSERT(m_utHeight >= 0.0);
81 NS_ASSERT(m_numBs > 0);
82 NS_ASSERT(m_numUt > 0);
83
84 m_bs.Create(m_numBs);
85 m_ut.Create(m_numUt);
86
87 MobilityHelper mobility;
88 Ptr<ListPositionAllocator> bsPos = CreateObject<ListPositionAllocator>();
89 Ptr<ListPositionAllocator> utPos = CreateObject<ListPositionAllocator>();
90
91 // BS position
92 if (m_bs.GetN() > 0)
93 {
94 uint32_t bsN = m_bs.GetN();
95 for (uint32_t i = 0; i < m_rows; ++i)
96 {
97 for (uint32_t j = 0; j < m_columns; ++j)
98 {
99 if (bsN == 0)
100 {
101 break;
102 }
103
104 Vector pos(m_initialPos);
105 pos.z = m_bsHeight;
106
107 pos.x = m_initialPos.x + (j * m_horizontalBsDistance);
108 pos.y = m_initialPos.y + (i * m_verticalBsDistance);
109
110 NS_LOG_DEBUG("GNB Position: " << pos);
111 bsPos->Add(pos);
112
113 bsN--;
114 }
115 }
116 }
117
118 m_x->SetAttribute("Min", DoubleValue(0.0));
119 m_x->SetAttribute("Max", DoubleValue(m_length));
120 m_y->SetAttribute("Min", DoubleValue(0.0));
121 m_y->SetAttribute("Max", DoubleValue(m_height));
122 // UT position
123 if (m_ut.GetN() > 0)
124 {
125 uint32_t utN = m_ut.GetN();
126
127 for (uint32_t i = 0; i < utN; ++i)
128 {
129 Vector pos = bsPos->GetNext();
130
131 pos.x += m_x->GetValue();
132 pos.y += m_y->GetValue();
133 pos.z = m_utHeight;
134
135 NS_LOG_DEBUG("UE Position: " << pos);
136
137 utPos->Add(pos);
138 }
139 }
140
141 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
142 mobility.SetPositionAllocator(bsPos);
143 mobility.Install(m_bs);
144
145 mobility.SetPositionAllocator(utPos);
146 mobility.Install(m_ut);
147}
148
149int64_t
151{
152 m_x->SetStream(stream);
153 m_y->SetStream(stream + 1);
154 return 2;
155}
156
157} // namespace ns3
void SetRows(uint32_t r)
SetRows.
void SetHorizontalBsDistance(double d)
SetHorizontalBsDistance.
void SetVerticalBsDistance(double d)
SetVerticalBsDistance.
void CreateScenario() override
Create the scenario, with the configured parameter.
int64_t AssignStreams(int64_t stream)
~GridScenarioHelper() override
~GridScenarioHelper
GridScenarioHelper()
GridScenarioHelper.
void SetColumns(uint32_t c)
SetColumns.
void SetStartingPosition(const Vector &initialPos)
Set starting position of the grid.
std::size_t m_numBs
Number of base stations to create.
std::size_t m_numUt
Number of user terminals to create.
double m_bsHeight
Height of gNB nodes.
double m_utHeight
Height of UE nodes.