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