5G-LENA nr-v3.1-14-g738b08bc
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
sfnsf.cc
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "sfnsf.h"
6
7#include "ns3/abort.h"
8
9namespace ns3
10{
11
12SfnSf::SfnSf(uint32_t frameNum, uint8_t sfNum, uint8_t slotNum, uint8_t numerology)
13 : m_frameNum(frameNum),
14 m_subframeNum(sfNum),
15 m_slotNum(slotNum),
16 m_numerology(numerology)
17{
18 // Numerology > 5 unsupported; if you want to define a new one,
19 // relax this constraint
20 NS_ABORT_MSG_IF(numerology > 5, "Numerology > 5 unsupported");
21}
22
23uint64_t
25{
26 // represented by 3 bits, but we do not expect the numerology higher than 6, SCS = 960 KHz
27 NS_ASSERT(m_numerology < 7);
28 // represented by 8 bits, but we do not expect the value higher than 64 which
29 // corresponds to numerology 6
30 NS_ASSERT(m_slotNum < 64);
31 // represented by 8 bits, but we do not expect values higher than 9
32 NS_ASSERT(m_subframeNum < 10);
33 // encoded into 24 bits which corresponds to the maximum value of 16777215
34 NS_ASSERT(m_frameNum < 16777215);
35 uint64_t ret = 0ULL;
36 ret = (static_cast<uint64_t>(m_frameNum) << 24) | (static_cast<uint64_t>(m_subframeNum) << 16) |
37 (static_cast<uint64_t>(m_slotNum) << 8) | (static_cast<uint64_t>(m_numerology) << 5);
38 return ret;
39}
40
41uint64_t
42SfnSf::GetEncodingWithSymStartRnti(uint8_t symStart, uint16_t rnti) const
43{
44 // represented by 5 bits, but we do not expect the values higher than 13
45 NS_ASSERT(symStart < 14);
46 // represented by 3 bits, but we do not expect the numerology higher than 6, SCS = 960 KHz
47 NS_ASSERT(m_numerology < 7);
48 // represented by 8 bits, but we do not expect the value higher than 64 which
49 // corresponds to numerology 6
50 NS_ASSERT(m_slotNum < 64);
51 // represented by 8 bits, but we do not expect values higher than 9
52 NS_ASSERT(m_subframeNum < 10);
53 // frame number is encoded into 24 bits which corresponds to the maximum value of 16777215
54 NS_ASSERT(m_frameNum < 16777215);
55 uint64_t ret = 0ULL;
56 ret = (static_cast<uint64_t>(rnti) << 48) | (static_cast<uint64_t>(m_frameNum) << 24) |
57 (static_cast<uint64_t>(m_subframeNum) << 16) | (static_cast<uint64_t>(m_slotNum) << 8) |
58 (static_cast<uint64_t>(m_numerology) << 5) | (static_cast<uint64_t>(symStart));
59 return ret;
60}
61
62void
64{
65 m_frameNum = (sfn & 0x0000FFFFFF000000) >> 24;
66 m_subframeNum = (sfn & 0x0000000000FF0000) >> 16;
67 m_slotNum = (sfn & 0x000000000000FF00) >> 8;
68 m_numerology = (sfn & 0x00000000000000E0) >> 5;
69}
70
71// Static functions
72uint32_t
74{
75 return 10;
76}
77
78uint32_t
80{
81 return 1 << m_numerology;
82}
83
84uint64_t
86{
87 return p.GetEncoding();
88}
89
91SfnSf::Decode(uint64_t sfn)
92{
93 SfnSf ret;
94 ret.FromEncoding(sfn);
95 return ret;
96}
97
98uint64_t
100{
101 uint64_t ret = 0;
102 ret += m_slotNum;
103 ret += m_subframeNum * GetSlotPerSubframe();
104 ret += m_frameNum * GetSubframesPerFrame() * GetSlotPerSubframe();
105 return ret;
106}
107
108SfnSf
110{
111 SfnSf ret = *this;
112 ret.Add(slotN);
113 return ret;
114}
115
116void
117SfnSf::Add(uint32_t slotN)
118{
119 NS_ASSERT_MSG(m_numerology <= 5, "Numerology " << m_numerology << " invalid");
120 m_frameNum +=
121 (m_subframeNum + (m_slotNum + slotN) / GetSlotPerSubframe()) / GetSubframesPerFrame();
122 m_subframeNum =
123 (m_subframeNum + (m_slotNum + slotN) / GetSlotPerSubframe()) % GetSubframesPerFrame();
124 m_slotNum = (m_slotNum + slotN) % GetSlotPerSubframe();
125}
126
127bool
128SfnSf::operator<(const SfnSf& rhs) const
129{
130 NS_ASSERT_MSG(rhs.m_numerology == m_numerology, "Numerology does not match");
131 if (m_frameNum < rhs.m_frameNum)
132 {
133 return true;
134 }
135 if ((m_frameNum == rhs.m_frameNum) && (m_subframeNum < rhs.m_subframeNum))
136 {
137 return true;
138 }
139 return (((m_frameNum == rhs.m_frameNum) && (m_subframeNum == rhs.m_subframeNum)) &&
140 (m_slotNum < rhs.m_slotNum));
141}
142
143bool
145{
146 NS_ASSERT_MSG(o.m_numerology == m_numerology, "Numerology does not match");
147 return (m_frameNum == o.m_frameNum) && (m_subframeNum == o.m_subframeNum) &&
148 (m_slotNum == o.m_slotNum);
149}
150
151uint32_t
153{
154 return m_frameNum;
155}
156
157uint8_t
159{
160 return m_subframeNum;
161}
162
163uint8_t
165{
166 return m_slotNum;
167}
168
169uint8_t
171{
172 NS_ASSERT_MSG(m_numerology <= 5, "Numerology " << m_numerology << " invalid");
173 return m_numerology;
174}
175
176} // namespace ns3
The SfnSf class.
Definition sfnsf.h:32
static SfnSf Decode(uint64_t sfn)
Decode the parameter and return a SfnSf.
Definition sfnsf.cc:91
uint8_t GetNumerology() const
GetNumerology.
Definition sfnsf.cc:170
uint8_t GetSubframe() const
GetSubframe.
Definition sfnsf.cc:158
uint64_t Normalize() const
Normalize the SfnSf in slot number.
Definition sfnsf.cc:99
uint32_t GetSlotPerSubframe() const
Get SlotPerSubframe.
Definition sfnsf.cc:79
SfnSf GetFutureSfnSf(uint32_t slotN)
Get a Future SfnSf.
Definition sfnsf.cc:109
static uint64_t Encode(const SfnSf &p)
Encode the parameter in a uint64_t.
Definition sfnsf.cc:85
uint64_t GetEncoding() const
Get encoding for this SfnSf.
Definition sfnsf.cc:24
void Add(uint32_t slotN)
Add to this SfnSf a number of slot indicated by the first parameter.
Definition sfnsf.cc:117
uint64_t GetEncodingWithSymStartRnti(uint8_t symStart, uint16_t rnti) const
Get an encoding of frame & slot number, plus starting OFDM symbol and RNTI.
Definition sfnsf.cc:42
bool operator<(const SfnSf &rhs) const
operator < (less than)
Definition sfnsf.cc:128
uint8_t GetSlot() const
GetSlot.
Definition sfnsf.cc:164
SfnSf()=default
constructor
bool operator==(const SfnSf &o) const
operator ==, compares frame, subframe, and slot
Definition sfnsf.cc:144
void FromEncoding(uint64_t sfn)
Fill the private fields with the value extracted from the parameter.
Definition sfnsf.cc:63
static uint32_t GetSubframesPerFrame()
Definition sfnsf.cc:73
uint32_t GetFrame() const
GetFrame.
Definition sfnsf.cc:152