5G-LENA nr-v3.3-161-gad18933f
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-phy-mac-common.cc
1// Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering, New York University
2// Copyright (c) 2018 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "nr-phy-mac-common.h"
8
9#include "ns3/attribute-accessor-helper.h"
10#include "ns3/log.h"
11
12#include <algorithm>
13
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("NrPhyMacCommon");
18
19void
21{
22 NS_LOG_FUNCTION(this);
23 NS_ASSERT(other.m_type != NONE && m_type != NONE);
24 NS_ASSERT(other.m_sfnSf == m_sfnSf);
25
26 if (other.m_type * m_type == 6)
27 {
28 m_type = BOTH;
29 }
30
32
33 for (const auto& extAlloc : other.m_varTtiAllocInfo)
34 {
35 m_varTtiAllocInfo.push_front(extAlloc);
36 }
37
38 // Sort over the symStart of the DCI (VarTtiAllocInfo::operator <)
39 std::stable_sort(m_varTtiAllocInfo.begin(), m_varTtiAllocInfo.end());
40}
41
42bool
44{
45 NS_LOG_FUNCTION(this);
46 for (const auto& allocation : m_varTtiAllocInfo)
47 {
48 if (allocation.m_dci->m_type == DciInfoElementTdma::DATA)
49 {
50 return true;
51 }
52 }
53 return false;
54}
55
56bool
58{
59 NS_LOG_FUNCTION(this);
60
61 for (const auto& allocation : m_varTtiAllocInfo)
62 {
63 if (allocation.m_dci->m_type == DciInfoElementTdma::CTRL &&
64 allocation.m_dci->m_format == DciInfoElementTdma::DL)
65 {
66 return true;
67 }
68 }
69 return false;
70}
71
72bool
74{
75 NS_LOG_FUNCTION(this);
76 for (const auto& allocation : m_varTtiAllocInfo)
77 {
78 if (allocation.m_dci->m_type == DciInfoElementTdma::MSG3)
79 {
80 return true;
81 }
82 }
83 return false;
84}
85
86bool
88{
89 NS_LOG_FUNCTION(this);
90
91 for (const auto& allocation : m_varTtiAllocInfo)
92 {
93 if (allocation.m_dci->m_type == DciInfoElementTdma::SRS)
94 {
95 return true;
96 }
97 }
98 return false;
99}
100
101bool
103{
104 return m_sfnSf < rhs.m_sfnSf;
105}
106
107std::ostream&
108operator<<(std::ostream& os, const DciInfoElementTdma::DciFormat& item)
109{
110 if (item == DciInfoElementTdma::DL)
111 {
112 os << "DL";
113 }
114 else if (item == DciInfoElementTdma::UL)
115 {
116 os << "UL";
117 }
118 else
119 {
120 os << "NA";
121 }
122 return os;
123}
124
125std::ostream&
126operator<<(std::ostream& os, const DlHarqInfo& item)
127{
128 if (item.IsReceivedOk())
129 {
130 os << "ACK feedback ";
131 }
132 else
133 {
134 os << "NACK feedback ";
135 }
136 os << "for ProcessID: " << static_cast<uint32_t>(item.m_harqProcessId) << " of UE "
137 << static_cast<uint32_t>(item.m_rnti)
138 << " Num Retx: " << static_cast<uint32_t>(item.m_numRetx)
139 << " BWP index: " << static_cast<uint32_t>(item.m_bwpIndex);
140 return os;
141}
142
143std::ostream&
144operator<<(std::ostream& os, const UlHarqInfo& item)
145{
146 if (item.IsReceivedOk())
147 {
148 os << "ACK feedback ";
149 }
150 else
151 {
152 os << "NACK feedback ";
153 }
154 os << "for ProcessID: " << static_cast<uint32_t>(item.m_harqProcessId) << " of UE "
155 << static_cast<uint32_t>(item.m_rnti)
156 << " Num Retx: " << static_cast<uint32_t>(item.m_numRetx);
157
158 return os;
159}
160
161std::ostream&
162operator<<(std::ostream& os, const SfnSf& item)
163{
164 os << "FrameNum: " << static_cast<uint32_t>(item.GetFrame())
165 << " SubFrameNum: " << static_cast<uint32_t>(item.GetSubframe())
166 << " SlotNum: " << static_cast<uint32_t>(item.GetSlot());
167 return os;
168}
169
170std::ostream&
171operator<<(std::ostream& os, const SlotAllocInfo& item)
172{
173 os << "Allocation for slot " << item.m_sfnSf
174 << " total symbols allocated: " << item.m_numSymAlloc << " of type " << item.m_type
175 << ", tti: " << item.m_varTtiAllocInfo.size()
176 << " composed by the following allocations: " << std::endl;
177 for (const auto& alloc : item.m_varTtiAllocInfo)
178 {
179 std::string direction;
180 std::string type;
181 if (alloc.m_dci->m_type == DciInfoElementTdma::CTRL)
182 {
183 type = "CTRL";
184 }
185 else if (alloc.m_dci->m_type == DciInfoElementTdma::SRS)
186 {
187 type = "SRS";
188 }
189 else if (alloc.m_dci->m_type == DciInfoElementTdma::MSG3)
190 {
191 type = "MSG3";
192 }
193 else
194 {
195 type = "DATA";
196 }
197
198 if (alloc.m_dci->m_format == DciInfoElementTdma::UL)
199 {
200 direction = "UL";
201 }
202 else
203 {
204 direction = "DL";
205 }
206 os << "[Allocation from sym " << static_cast<uint32_t>(alloc.m_dci->m_symStart)
207 << " to sym " << static_cast<uint32_t>(alloc.m_dci->m_numSym + alloc.m_dci->m_symStart)
208 << " direction " << direction << " type " << type << "]" << std::endl;
209 }
210 return os;
211}
212
213std::ostream&
214operator<<(std::ostream& os, const SlotAllocInfo::AllocationType& item)
215{
216 switch (item)
217 {
219 os << "NONE";
220 break;
222 os << "DL";
223 break;
225 os << "UL";
226 break;
228 os << "BOTH";
229 break;
230 }
231
232 return os;
233}
234
235std::ostream&
236operator<<(std::ostream& os, const DciInfoElementTdma& item)
237{
238 os << "RNTI=" << item.m_rnti << "|" << item.m_format << "|SYM=" << +item.m_symStart
239 << "|NSYM=" << +item.m_numSym << "|MCS=" << +item.m_mcs << "|TBS=" << item.m_tbSize
240 << "|NDI=" << +item.m_ndi << "|RV=" << +item.m_rv << "|TYPE=" << item.m_type
241 << "|BWP=" << +item.m_bwpIndex << "|HARQP=" << +item.m_harqProcess << "|RBG=";
242
243 uint16_t start = 65000;
244 uint16_t end = 0;
245 bool canPrint = false;
246 for (uint32_t i = 0; i < item.m_rbgBitmask.size(); ++i)
247 {
248 if (item.m_rbgBitmask[i] == 1)
249 {
250 canPrint = true;
251 }
252
253 if (item.m_rbgBitmask[i] == 1 && end < i)
254 {
255 end = i;
256 }
257 if (item.m_rbgBitmask[i] == 1 && start > i)
258 {
259 start = i;
260 }
261
262 if (item.m_rbgBitmask[i] == 0 && canPrint)
263 {
264 os << "[" << +start << ";" << +end << "]";
265 start = 65000;
266 end = 0;
267 canPrint = false;
268 }
269 }
270
271 if (canPrint)
272 {
273 os << "[" << +start << ";" << +end << "]";
274 }
275
276 return os;
277}
278
279} // namespace ns3
@ CTRL
Used for DL/UL CTRL.
@ DATA
Used for DL/UL DATA.
@ SRS
Used for SRS (it would be like DCI format 2_3)
DciFormat
Format of the DCI.
The SlotAllocInfo struct.
SfnSf m_sfnSf
SfnSf of this allocation.
bool operator<(const SlotAllocInfo &rhs) const
operator < (less than)
AllocationType m_type
Allocations type.
bool ContainsDlCtrlAllocation() const
void Merge(const SlotAllocInfo &other)
Merge the input parameter to this SlotAllocInfo.
uint32_t m_numSymAlloc
Number of allocated symbols.
bool ContainsUlCtrlAllocation() const
bool ContainsDataAllocation() const
Check if we have data allocations.
AllocationType
Enum which indicates the allocations that are inside the allocation info.
@ NONE
No allocations.
@ BOTH
DL and UL allocations.
@ UL
UL Allocations.
@ DL
DL Allocations.
bool ContainsUlMsg3Allocation() const
Check if we have UL MSG3 allocations.
std::deque< VarTtiAllocInfo > m_varTtiAllocInfo
queue of allocations