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