5G-LENA  nr-v3.0-29-g83cc959
The 5G/NR module for the ns-3 simulator
nr-phy-mac-common.h
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 
3 // Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 // Copyright (c) 2015, NYU WIRELESS, Tandon School of Engineering, New York University
5 // Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
6 //
7 // SPDX-License-Identifier: GPL-2.0-only
8 
9 #ifndef SRC_NR_MODEL_NR_PHY_MAC_COMMON_H
10 #define SRC_NR_MODEL_NR_PHY_MAC_COMMON_H
11 
12 #include "sfnsf.h"
13 
14 #include <ns3/log.h>
15 #include <ns3/matrix-array.h>
16 #include <ns3/object.h>
17 #include <ns3/string.h>
18 
19 #include <deque>
20 #include <list>
21 #include <map>
22 #include <memory>
23 #include <unordered_map>
24 #include <vector>
25 
26 namespace ns3
27 {
28 
29 struct GetFirst
30 {
31  template <class First, class Second>
32  First& operator()(std::pair<First, Second>& p)
33  {
34  return p.first;
35  }
36 
37  template <class First, class Second>
38  First& operator()(typename std::map<First, Second>::iterator& p)
39  {
40  return p.first;
41  }
42 
43  template <class First, class Second>
44  const First& operator()(const std::pair<First, Second>& p)
45  {
46  return p.first;
47  }
48 
49  template <class First, class Second>
50  const First& operator()(const typename std::map<First, Second>::iterator& p)
51  {
52  return p.first;
53  }
54 };
55 
56 struct GetSecond
57 {
58  template <class First, class Second>
59  Second& operator()(std::pair<First, Second>& p)
60  {
61  return p.second;
62  }
63 
64  template <class First, class Second>
65  Second& operator()(typename std::map<First, Second>::iterator& p)
66  {
67  return p.second;
68  }
69 
70  template <class First, class Second>
71  Second& operator()(typename std::unordered_map<First, Second>::iterator& p)
72  {
73  return p.second;
74  }
75 
76  template <class First, class Second>
77  const Second& operator()(const std::pair<First, Second>& p)
78  {
79  return p.second;
80  }
81 
82  template <class First, class Second>
83  const Second& operator()(const typename std::map<First, Second>::iterator& p)
84  {
85  return p.second;
86  }
87 
88  template <class First, class Second>
89  const Second& operator()(const typename std::unordered_map<First, Second>::iterator& p)
90  {
91  return p.second;
92  }
93 };
94 
100 {
105  {
106  DL = 0,
107  UL = 1
108  };
109 
114  {
115  SRS = 0,
116  DATA = 1,
117  CTRL = 2,
118  };
119 
126  DciInfoElementTdma(uint8_t symStart,
127  uint8_t numSym,
128  DciFormat format,
129  VarTtiType type,
130  const std::vector<uint8_t>& rbgBitmask)
131  : m_format(format),
132  m_symStart(symStart),
133  m_numSym(numSym),
134  m_type(type),
135  m_rbgBitmask(rbgBitmask)
136  {
137  }
138 
154  DciInfoElementTdma(uint16_t rnti,
155  DciFormat format,
156  uint8_t symStart,
157  uint8_t numSym,
158  uint8_t mcs,
159  uint8_t rank,
160  Ptr<const ComplexMatrixArray> precMats,
161  uint32_t tbs,
162  uint8_t ndi,
163  uint8_t rv,
164  VarTtiType type,
165  uint8_t bwpIndex,
166  uint8_t tpc)
167  : m_rnti(rnti),
168  m_format(format),
169  m_symStart(symStart),
170  m_numSym(numSym),
171  m_mcs(mcs),
172  m_rank(rank),
173  m_precMats(precMats),
174  m_tbSize(tbs),
175  m_ndi(ndi),
176  m_rv(rv),
177  m_type(type),
178  m_bwpIndex(bwpIndex),
179  m_tpc(tpc)
180  {
181  }
182 
191  DciInfoElementTdma(uint8_t symStart,
192  uint8_t numSym,
193  uint8_t ndi,
194  uint8_t rv,
195  const DciInfoElementTdma& o)
196  : m_rnti(o.m_rnti),
197  m_format(o.m_format),
198  m_symStart(symStart),
199  m_numSym(numSym),
200  m_mcs(o.m_mcs),
201  m_rank(o.m_rank),
202  m_precMats(o.m_precMats),
203  m_tbSize(o.m_tbSize),
204  m_ndi(ndi),
205  m_rv(rv),
206  m_type(o.m_type),
210  m_tpc(o.m_tpc)
211  {
212  }
213 
214  const uint16_t m_rnti{0};
216  const uint8_t m_symStart{0};
217  const uint8_t m_numSym{0};
218  const uint8_t m_mcs{0};
219  const uint8_t m_rank{1};
220  Ptr<const ComplexMatrixArray> m_precMats{nullptr};
221  const uint32_t m_tbSize{0};
222  const uint8_t m_ndi{0};
223  const uint8_t m_rv{0};
225  const uint8_t m_bwpIndex{0};
226  uint8_t m_harqProcess{0};
227  std::vector<uint8_t> m_rbgBitmask{};
228  const uint8_t m_tpc{0};
229 };
230 
236 {
237  RlcPduInfo() = default;
238  RlcPduInfo(const RlcPduInfo& o) = default;
239  ~RlcPduInfo() = default;
240 
241  RlcPduInfo(uint8_t lcid, uint32_t size)
242  : m_lcid(lcid),
243  m_size(size)
244  {
245  }
246 
247  uint8_t m_lcid{0};
248  uint32_t m_size{0};
249 };
250 
252 {
253  VarTtiAllocInfo(const VarTtiAllocInfo& o) = default;
254 
255  VarTtiAllocInfo(const std::shared_ptr<DciInfoElementTdma>& dci)
256  : m_dci(dci)
257  {
258  }
259 
260  bool m_isOmni{false};
261  std::shared_ptr<DciInfoElementTdma> m_dci;
262  std::vector<RlcPduInfo> m_rlcPduInfo;
263 
264  bool operator<(const VarTtiAllocInfo& o) const
265  {
266  NS_ASSERT(m_dci != nullptr);
267  return (m_dci->m_symStart < o.m_dci->m_symStart);
268  }
269 };
270 
276 {
277  SlotAllocInfo(SfnSf sfn)
278  : m_sfnSf(sfn)
279  {
280  }
281 
286  {
287  NONE = 0,
288  DL = 1,
289  UL = 2,
290  BOTH = 3
291  };
292 
299  void Merge(const SlotAllocInfo& other);
300 
305  bool ContainsDataAllocation() const;
306 
310  bool ContainsDlCtrlAllocation() const;
311 
315  bool ContainsUlCtrlAllocation() const;
316 
318  uint32_t m_numSymAlloc{0};
319  std::deque<VarTtiAllocInfo> m_varTtiAllocInfo;
321 
329  bool operator<(const SlotAllocInfo& rhs) const;
330 };
331 
336 struct DlCqiInfo
337 {
338  uint16_t m_rnti{0};
339  // TODO: Rename to m_rank (m_ri is set directly to the rank).
340  uint8_t m_ri{0};
341 
342  // TODO: use NrMacSchedulerUeInfo::CqiInfo
343  enum DlCqiType
344  {
345  WB,
346  SB
347  } m_cqiType{WB};
348 
349  uint8_t m_wbCqi{0};
350  size_t m_wbPmi{0};
351 
352  std::vector<uint8_t> m_sbCqis;
353  std::vector<size_t> m_sbPmis;
354  uint8_t m_mcs{0};
355  Ptr<const ComplexMatrixArray> m_optPrecMat{};
356 };
357 
362 struct PmCqiInfo
363 {
364  uint8_t m_mcs{0};
365  uint8_t m_rank{0};
366  size_t m_wbPmi{0};
367  uint8_t m_wbCqi{0};
368  std::vector<uint8_t> m_sbCqis;
369  std::vector<size_t> m_sbPmis;
370  Ptr<const ComplexMatrixArray> m_optPrecMat{};
371 
372  // TODO: Fix/remove empty DlSBCQIReported, then change default type to SB.
373 
374  DlCqiInfo::DlCqiType m_cqiType{DlCqiInfo::WB};
375  size_t m_tbSize{};
376 };
377 
382 struct UlCqiInfo
383 {
384  // std::vector <uint16_t> m_sinr;
385  std::vector<double> m_sinr;
386 
387  enum UlCqiType
388  {
389  SRS,
390  PUSCH,
391  PUCCH_1,
392  PUCCH_2,
393  PRACH
394  } m_type;
395 };
396 
402 {
403  MacCeValue()
404  : m_phr(0),
405  m_crnti(0)
406  {
407  }
408 
409  uint8_t m_phr;
410  uint8_t m_crnti;
411  std::vector<uint8_t> m_bufferStatus;
412 };
413 
419 {
420  MacCeElement()
421  : m_rnti(0)
422  {
423  }
424 
425  uint16_t m_rnti;
426 
427  enum MacCeType
428  {
429  BSR,
430  PHR,
431  CRNTI
432  } m_macCeType;
433  struct MacCeValue m_macCeValue;
434 };
435 
441 {
442  std::vector<struct RlcPduInfo> m_rlcPduElements;
443 };
444 
450 {
451  uint64_t m_imsi;
452  uint32_t m_noBytes;
453  bool m_isTx; // Set to false if Rx and true if tx
454  uint32_t m_subframeno;
455 };
456 
462 {
463  uint64_t m_cellId;
464  uint32_t m_noBytes;
465  bool m_isTx; // Set to false if Rx and true if tx
466  uint32_t m_subframeno;
467 };
468 
474 {
475  uint64_t m_cellId{0};
476  uint16_t m_rnti{0};
477  uint32_t m_frameNum{std::numeric_limits<uint32_t>::max()};
478  uint8_t m_subframeNum{std::numeric_limits<uint8_t>::max()};
479  uint16_t m_slotNum{std::numeric_limits<uint16_t>::max()};
480  uint8_t m_symStart{std::numeric_limits<uint8_t>::max()};
481  uint8_t m_numSym{std::numeric_limits<uint8_t>::max()};
482  uint32_t m_tbSize{0};
483  uint8_t m_mcs{std::numeric_limits<uint8_t>::max()};
484  uint8_t m_rank{std::numeric_limits<uint8_t>::max()};
485  uint8_t m_rv{std::numeric_limits<uint8_t>::max()};
486  double m_sinr{-1.0};
487  double m_sinrMin{-1.0};
488  double m_tbler{-1.0};
489  bool m_corrupt{false};
490  uint16_t m_bwpId{std::numeric_limits<uint16_t>::max()};
491  uint32_t m_rbAssignedNum{std::numeric_limits<uint32_t>::max()};
492  uint8_t m_cqi{std::numeric_limits<uint8_t>::max()};
493 };
494 
502 struct HarqInfo
503 {
504  virtual ~HarqInfo()
505  {
506  }
507 
508  uint16_t m_rnti{UINT16_MAX};
509  uint8_t m_harqProcessId{UINT8_MAX};
510  uint8_t m_bwpIndex{UINT8_MAX};
511 
516  virtual bool IsReceivedOk() const = 0;
517 };
518 
526 struct DlHarqInfo : public HarqInfo
527 {
532  {
533  ACK,
534  NACK
535  } m_harqStatus{NACK};
536 
537  uint8_t m_numRetx;
538 
539  bool IsReceivedOk() const override
540  {
541  return m_harqStatus == ACK;
542  }
543 };
544 
549 struct UlHarqInfo : public HarqInfo
550 {
551  std::vector<uint16_t> m_ulReception;
552 
553  enum ReceptionStatus
554  {
555  Ok,
556  NotOk,
557  NotValid
558  } m_receptionStatus;
559 
560  uint8_t m_tpc{UINT8_MAX};
561  uint8_t m_numRetx{UINT8_MAX};
562 
563  bool IsReceivedOk() const override
564  {
565  return m_receptionStatus == Ok;
566  }
567 };
568 
569 std::ostream& operator<<(std::ostream& os, const DciInfoElementTdma& item);
570 std::ostream& operator<<(std::ostream& os, const DciInfoElementTdma::DciFormat& item);
571 std::ostream& operator<<(std::ostream& os, const DlHarqInfo& item);
572 std::ostream& operator<<(std::ostream& os, const UlHarqInfo& item);
573 std::ostream& operator<<(std::ostream& os, const SfnSf& item);
574 std::ostream& operator<<(std::ostream& os, const SlotAllocInfo& item);
575 std::ostream& operator<<(std::ostream& os, const SlotAllocInfo::AllocationType& item);
576 } // namespace ns3
577 
580 {
581  uint16_t m_frameNum{UINT16_MAX};
582  uint8_t m_subframeNum{UINT8_MAX};
583  uint16_t m_slotNum{UINT16_MAX};
584  uint8_t m_symStart{UINT8_MAX};
585  uint8_t m_numSym{UINT8_MAX};
586  uint16_t m_rnti{UINT16_MAX};
587  uint8_t m_mcs{UINT8_MAX};
588  uint32_t m_tbSize{UINT32_MAX};
589  uint8_t m_bwpId{UINT8_MAX};
590  uint8_t m_ndi{UINT8_MAX};
591  uint8_t m_rv{UINT8_MAX};
592  uint8_t m_harqId{UINT8_MAX};
593 };
594 
595 #endif /* SRC_NR_MODEL_NR_PHY_MAC_COMMON_H_ */
The SfnSf class.
Definition: sfnsf.h:34
static std::ostream & operator<<(std::ostream &os, const TrafficTypeConf &item)
operator << for TrafficTypeConf
NrSchedulingCallbackInfo structure.
uint8_t m_ndi
New data indicator.
uint8_t m_symStart
starting symbol index
uint8_t m_subframeNum
subframe number
uint16_t m_frameNum
frame number
uint8_t m_bwpId
Bandwidth Part ID.
uint16_t m_slotNum
slot number
uint8_t m_numSym
number of symbols
Scheduling information. Despite the name, it is not TDMA.
const uint8_t m_tpc
Tx power control command.
const uint32_t m_tbSize
TB size.
DciInfoElementTdma(uint16_t rnti, DciFormat format, uint8_t symStart, uint8_t numSym, uint8_t mcs, uint8_t rank, Ptr< const ComplexMatrixArray > precMats, uint32_t tbs, uint8_t ndi, uint8_t rv, VarTtiType type, uint8_t bwpIndex, uint8_t tpc)
Construct to build brand new DCI. Please remember to update manually the HARQ process ID and the RBG ...
const DciFormat m_format
DCI format.
const uint8_t m_rank
the rank number (the number of MIMO layers)
const uint16_t m_rnti
RNTI of the UE.
const uint8_t m_bwpIndex
BWP Index to identify to which BWP this DCI applies to.
uint8_t m_harqProcess
HARQ process id.
DciInfoElementTdma(uint8_t symStart, uint8_t numSym, uint8_t ndi, uint8_t rv, const DciInfoElementTdma &o)
Copy constructor except for some values that have to be overwritten.
VarTtiType
The VarTtiType enum.
@ CTRL
Used for DL/UL CTRL.
@ DATA
Used for DL/UL DATA.
@ SRS
Used for SRS (it would be like DCI format 2_3)
std::vector< uint8_t > m_rbgBitmask
RBG mask: 0 if the RBG is not used, 1 otherwise.
DciInfoElementTdma(uint8_t symStart, uint8_t numSym, DciFormat format, VarTtiType type, const std::vector< uint8_t > &rbgBitmask)
Constructor used in NrUePhy to build local DCI for DL and UL control.
const VarTtiType m_type
Var TTI type.
const uint8_t m_symStart
starting symbol index for flexible TTI scheme
const uint8_t m_numSym
number of symbols for flexible TTI scheme
const uint8_t m_rv
Redundancy Version.
const uint8_t m_ndi
New Data Indicator.
DciFormat
Format of the DCI.
The DlCqiInfo struct.
Ptr< const ComplexMatrixArray > m_optPrecMat
Precoding matrix for each RB.
std::vector< size_t > m_sbPmis
Subband PMI values (i2, indices of W2 matrices)
uint8_t m_mcs
MCS (can be derived from CQI feedback)
size_t m_wbPmi
Wideband precoding matrix index.
uint8_t m_wbCqi
Wideband CQI.
std::vector< uint8_t > m_sbCqis
Subband CQI values.
uint8_t m_ri
the rank indicator, or simply the rank number
enum ns3::DlCqiInfo::DlCqiType WB
The type of the CQI.
uint16_t m_rnti
The RNTI.
A struct that contains info for the DL HARQ.
uint8_t m_numRetx
Num of Retx.
enum ns3::DlHarqInfo::HarqStatus NACK
HARQ status.
HarqStatus
Status of the DL Harq: ACKed or NACKed.
bool IsReceivedOk() const override
The GnbPhyPacketCountParameter struct.
Store information about HARQ.
uint8_t m_harqProcessId
ProcessId.
uint8_t m_bwpIndex
BWP identifier, uniquely identifies BWP within the UE.
uint16_t m_rnti
RNTI.
virtual bool IsReceivedOk() const =0
See section 4.3.14 macCEListElement.
The MacCeValue struct.
The structure used for the CQI feedback message that contains the optimum CQI, RI,...
Ptr< const ComplexMatrixArray > m_optPrecMat
Precoding matrix for each RB.
DlCqiInfo::DlCqiType m_cqiType
CQI type (WB or SB)
size_t m_wbPmi
Wideband precoding matrix index.
uint8_t m_rank
Rank of the channel matrix (supported number of MIMO layers)
uint8_t m_mcs
Modulation and coding scheme supported by current channel.
std::vector< size_t > m_sbPmis
Subband PMI values (i2, indices of W2 matrices)
uint8_t m_wbCqi
Wideband CQI.
size_t m_tbSize
Expected TB size when allocating all resources.
std::vector< uint8_t > m_sbCqis
Subband CQI values.
The RlcListElement struct.
The RlcPduInfo struct.
The RxPacketTraceParams struct.
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
The UePhyPacketCountParameter struct.
The UlCqiInfo struct.
A struct that contains info for the UL HARQ.
uint8_t m_tpc
Transmit Power Control.
uint8_t m_numRetx
Num of Retx.
bool IsReceivedOk() const override