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