A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
cc-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Danilo Abrignani
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
7 */
8
9#include "cc-helper.h"
10
11#include <ns3/abort.h>
12#include <ns3/component-carrier.h>
13#include <ns3/log.h>
14#include <ns3/lte-spectrum-value-helper.h>
15#include <ns3/pointer.h>
16#include <ns3/string.h>
17#include <ns3/uinteger.h>
18
19#include <iostream>
20
21#define MIN_CC 1
22#define MAX_CC 2
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("CcHelper");
28
30
36
37void
42
45{
46 static TypeId tid =
47 TypeId("ns3::CcHelper")
49 .AddConstructor<CcHelper>()
50 .AddAttribute("NumberOfComponentCarriers",
51 "Set the number of Component Carriers to setup per eNodeB"
52 "Currently the maximum Number of Component Carriers allowed is 2",
56 .AddAttribute("UlEarfcn",
57 "Set Ul Channel [EARFCN] for the first carrier component",
61 .AddAttribute("DlEarfcn",
62 "Set Dl Channel [EARFCN] for the first carrier component",
66 .AddAttribute("DlBandwidth",
67 "Set Dl Bandwidth for the first carrier component",
68 UintegerValue(25),
71 .AddAttribute("UlBandwidth",
72 "Set Dl Bandwidth for the first carrier component",
73 UintegerValue(25),
76
77 return tid;
78}
79
84
85void
91
92void
94{
95 NS_LOG_FUNCTION(this << n);
96 m_ccFactory.Set(n, v);
97}
98
99void
104
105void
107{
108 m_ulEarfcn = ulEarfcn;
109}
110
111void
113{
114 m_dlEarfcn = dlEarfcn;
115}
116
117void
118CcHelper::SetDlBandwidth(uint16_t dlBandwidth)
119{
120 m_dlBandwidth = dlBandwidth;
121}
122
123void
124CcHelper::SetUlBandwidth(uint16_t ulBandwidth)
125{
126 m_ulBandwidth = ulBandwidth;
127}
128
129uint16_t
134
137{
138 return m_ulEarfcn;
139}
140
143{
144 return m_dlEarfcn;
145}
146
147uint16_t
149{
150 return m_dlBandwidth;
151}
152
153uint16_t
155{
156 return m_ulBandwidth;
157}
158
160CcHelper::DoCreateSingleCc(uint16_t ulBandwidth,
161 uint16_t dlBandwidth,
162 uint32_t ulEarfcn,
163 uint32_t dlEarfcn,
164 bool isPrimary)
165{
166 return CreateSingleCc(ulBandwidth, dlBandwidth, ulEarfcn, dlEarfcn, isPrimary);
167}
168
169std::map<uint8_t, ComponentCarrier>
171{
172 std::map<uint8_t, ComponentCarrier> ccmap;
173
174 uint32_t ulEarfcn = m_ulEarfcn;
175 uint32_t dlEarfcn = m_dlEarfcn;
176 uint16_t maxBandwidthRb = std::max<uint16_t>(m_ulBandwidth, m_dlBandwidth);
177
178 // Convert bandwidth from RBs to kHz
179 uint32_t maxBandwidthKhz = LteSpectrumValueHelper::GetChannelBandwidth(maxBandwidthRb) / 1e3;
180
181 for (uint16_t i = 0; i < m_numberOfComponentCarriers; i++)
182 {
183 // Make sure we stay within the same band.
188 {
189 NS_FATAL_ERROR("Band is not wide enough to allocate " << +m_numberOfComponentCarriers
190 << " CCs");
191 }
192
193 bool pc = false;
194
195 if (i == 0)
196 {
197 pc = true;
198 }
199 ComponentCarrier cc = CreateSingleCc(m_ulBandwidth, m_dlBandwidth, ulEarfcn, dlEarfcn, pc);
200 ccmap.insert(std::pair<uint8_t, ComponentCarrier>(i, cc));
201
202 NS_LOG_INFO("ulBandwidth: " << m_ulBandwidth << ", dlBandwidth: " << m_dlBandwidth
203 << ", ulEarfcn: " << ulEarfcn << ", dlEarfcn: " << dlEarfcn);
204
205 // The spacing between the centre frequencies of two contiguous CCs should be multiple of
206 // 300 kHz. Round spacing up to 300 kHz.
207 uint32_t frequencyShift = 300 * (1 + (maxBandwidthKhz - 1) / 300);
208
209 // Unit of EARFCN corresponds to 100kHz.
210 uint32_t earfcnShift = frequencyShift / 100;
211 ulEarfcn += earfcnShift;
212 dlEarfcn += earfcnShift;
213 }
214
215 return ccmap;
216}
217
219CcHelper::CreateSingleCc(uint16_t ulBandwidth,
220 uint16_t dlBandwidth,
221 uint32_t ulEarfcn,
222 uint32_t dlEarfcn,
223 bool isPrimary) const
224{
226 if (m_ulEarfcn != 0)
227 {
228 cc.SetUlEarfcn(ulEarfcn);
229 }
230 else
231 {
232 uint16_t ul = cc.GetUlEarfcn() + ulEarfcn;
233 cc.SetUlEarfcn(ul);
234 }
235 if (m_dlEarfcn != 0)
236 {
237 cc.SetDlEarfcn(dlEarfcn);
238 }
239 else
240 {
241 uint16_t dl = cc.GetDlEarfcn() + dlEarfcn;
242 cc.SetDlEarfcn(dl);
243 }
244 cc.SetDlBandwidth(dlBandwidth);
245 cc.SetUlBandwidth(ulBandwidth);
246
247 cc.SetAsPrimary(isPrimary);
248
249 return cc;
250}
251
252} // namespace ns3
#define MAX_CC
Definition cc-helper.cc:22
#define MIN_CC
Definition cc-helper.cc:21
Hold a value for an Attribute.
Definition attribute.h:59
uint32_t GetUlEarfcn() const
Get UL EARFCN.
Definition cc-helper.cc:136
ObjectFactory m_ccFactory
Factory for each Carrier Component.
Definition cc-helper.h:183
void SetNumberOfComponentCarriers(uint16_t nCc)
Set number of CCs.
Definition cc-helper.cc:100
ComponentCarrier DoCreateSingleCc(uint16_t ulBandwidth, uint16_t dlBandwidth, uint32_t ulEarfcn, uint32_t dlEarfcn, bool isPrimary)
Create single CC.
Definition cc-helper.cc:160
void SetDlEarfcn(uint32_t dlEarfcn)
Set DL EARFCN.
Definition cc-helper.cc:112
void DoDispose() override
Destructor implementation.
Definition cc-helper.cc:86
uint16_t GetDlBandwidth() const
Get DL bandwidth.
Definition cc-helper.cc:148
uint32_t GetDlEarfcn() const
Get DL EARFCN.
Definition cc-helper.cc:142
void SetUlBandwidth(uint16_t ulBandwidth)
Set UL bandwidth.
Definition cc-helper.cc:124
~CcHelper() override
Definition cc-helper.cc:80
void SetDlBandwidth(uint16_t dlBandwidth)
Set DL bandwidth.
Definition cc-helper.cc:118
uint16_t m_numberOfComponentCarriers
Number of component carriers.
Definition cc-helper.h:189
uint16_t GetUlBandwidth() const
Get UL bandwidth.
Definition cc-helper.cc:154
uint16_t m_ulBandwidth
Uplink Bandwidth.
Definition cc-helper.h:188
uint16_t m_dlBandwidth
Downlink Bandwidth.
Definition cc-helper.h:187
static TypeId GetTypeId()
Register this type.
Definition cc-helper.cc:44
std::map< uint8_t, ComponentCarrier > EquallySpacedCcs()
EquallySpacedCcs() create a valid std::map< uint8_t, Ptr<ComponentCarrier> > The Primary Component Ca...
Definition cc-helper.cc:170
void SetUlEarfcn(uint32_t ulEarfcn)
Set UL EARFCN.
Definition cc-helper.cc:106
uint16_t GetNumberOfComponentCarriers() const
Get number of component carriers.
Definition cc-helper.cc:130
void DoInitialize() override
Initialize() implementation.
Definition cc-helper.cc:38
uint32_t m_ulEarfcn
Uplink EARFCN.
Definition cc-helper.h:185
uint32_t m_dlEarfcn
Downlink EARFCN.
Definition cc-helper.h:186
void SetCcAttribute(std::string n, const AttributeValue &v)
Set an attribute for the Component Carrier to be created.
Definition cc-helper.cc:93
ComponentCarrier CreateSingleCc(uint16_t ulBandwidth, uint16_t dlBandwidth, uint32_t ulEarfcn, uint32_t dlEarfcn, bool isPrimary) const
Create a single component carrier.
Definition cc-helper.cc:219
ComponentCarrier Object, it defines a single Carrier This is the parent class for both ComponentCarri...
void SetDlEarfcn(uint32_t earfcn)
uint32_t GetDlEarfcn() const
void SetUlEarfcn(uint32_t earfcn)
void SetAsPrimary(bool primaryCarrier)
Set as primary carrier.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetUlEarfcn() const
virtual void SetUlBandwidth(uint16_t bw)
virtual void SetDlBandwidth(uint16_t bw)
static uint16_t GetUplinkCarrierBand(uint32_t nUl)
Converts uplink EARFCN to corresponding LTE frequency band number.
static uint16_t GetDownlinkCarrierBand(uint32_t nDl)
Converts downlink EARFCN to corresponding LTE frequency band number.
static double GetChannelBandwidth(uint16_t txBandwidthConf)
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Definition object.h:78
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.