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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Danilo Abrignani <danilo.abrignani@unibo.it> (Carrier Aggregation - GSoC 2015)
18 */
19
20#include "cc-helper.h"
21
22#include <ns3/abort.h>
23#include <ns3/component-carrier.h>
24#include <ns3/log.h>
25#include <ns3/lte-spectrum-value-helper.h>
26#include <ns3/pointer.h>
27#include <ns3/string.h>
28#include <ns3/uinteger.h>
29
30#include <iostream>
31
32#define MIN_CC 1
33#define MAX_CC 2
34
35namespace ns3
36{
37
38NS_LOG_COMPONENT_DEFINE("CcHelper");
39
41
43{
44 NS_LOG_FUNCTION(this);
46}
47
48void
50{
51 NS_LOG_FUNCTION(this);
52}
53
56{
57 static TypeId tid =
58 TypeId("ns3::CcHelper")
60 .AddConstructor<CcHelper>()
61 .AddAttribute("NumberOfComponentCarriers",
62 "Set the number of Component Carriers to setup per eNodeB"
63 "Currently the maximum Number of Component Carriers allowed is 2",
66 MakeUintegerChecker<uint16_t>(MIN_CC, MAX_CC))
67 .AddAttribute("UlEarfcn",
68 "Set Ul Channel [EARFCN] for the first carrier component",
71 MakeUintegerChecker<uint32_t>())
72 .AddAttribute("DlEarfcn",
73 "Set Dl Channel [EARFCN] for the first carrier component",
76 MakeUintegerChecker<uint32_t>(0))
77 .AddAttribute("DlBandwidth",
78 "Set Dl Bandwidth for the first carrier component",
79 UintegerValue(25),
81 MakeUintegerChecker<uint16_t>(0, 100))
82 .AddAttribute("UlBandwidth",
83 "Set Dl Bandwidth for the first carrier component",
84 UintegerValue(25),
86 MakeUintegerChecker<uint16_t>(0, 100));
87
88 return tid;
89}
90
92{
93 NS_LOG_FUNCTION(this);
94}
95
96void
98{
99 NS_LOG_FUNCTION(this);
101}
102
103void
105{
106 NS_LOG_FUNCTION(this << n);
107 m_ccFactory.Set(n, v);
108}
109
110void
112{
114}
115
116void
118{
119 m_ulEarfcn = ulEarfcn;
120}
121
122void
124{
125 m_dlEarfcn = dlEarfcn;
126}
127
128void
129CcHelper::SetDlBandwidth(uint16_t dlBandwidth)
130{
131 m_dlBandwidth = dlBandwidth;
132}
133
134void
135CcHelper::SetUlBandwidth(uint16_t ulBandwidth)
136{
137 m_ulBandwidth = ulBandwidth;
138}
139
140uint16_t
142{
144}
145
148{
149 return m_ulEarfcn;
150}
151
154{
155 return m_dlEarfcn;
156}
157
158uint16_t
160{
161 return m_dlBandwidth;
162}
163
164uint16_t
166{
167 return m_ulBandwidth;
168}
169
171CcHelper::DoCreateSingleCc(uint16_t ulBandwidth,
172 uint16_t dlBandwidth,
173 uint32_t ulEarfcn,
174 uint32_t dlEarfcn,
175 bool isPrimary)
176{
177 return CreateSingleCc(ulBandwidth, dlBandwidth, ulEarfcn, dlEarfcn, isPrimary);
178}
179
180std::map<uint8_t, ComponentCarrier>
182{
183 std::map<uint8_t, ComponentCarrier> ccmap;
184
185 uint32_t ulEarfcn = m_ulEarfcn;
186 uint32_t dlEarfcn = m_dlEarfcn;
187 uint16_t maxBandwidthRb = std::max<uint16_t>(m_ulBandwidth, m_dlBandwidth);
188
189 // Convert bandwidth from RBs to kHz
190 uint32_t maxBandwidthKhz = LteSpectrumValueHelper::GetChannelBandwidth(maxBandwidthRb) / 1e3;
191
192 for (uint16_t i = 0; i < m_numberOfComponentCarriers; i++)
193 {
194 // Make sure we stay within the same band.
199 {
200 NS_FATAL_ERROR("Band is not wide enough to allocate " << +m_numberOfComponentCarriers
201 << " CCs");
202 }
203
204 bool pc = false;
205
206 if (i == 0)
207 {
208 pc = true;
209 }
210 ComponentCarrier cc = CreateSingleCc(m_ulBandwidth, m_dlBandwidth, ulEarfcn, dlEarfcn, pc);
211 ccmap.insert(std::pair<uint8_t, ComponentCarrier>(i, cc));
212
213 NS_LOG_INFO("ulBandwidth: " << m_ulBandwidth << ", dlBandwidth: " << m_dlBandwidth
214 << ", ulEarfcn: " << ulEarfcn << ", dlEarfcn: " << dlEarfcn);
215
216 // The spacing between the centre frequencies of two contiguous CCs should be multiple of
217 // 300 kHz. Round spacing up to 300 kHz.
218 uint32_t frequencyShift = 300 * (1 + (maxBandwidthKhz - 1) / 300);
219
220 // Unit of EARFCN corresponds to 100kHz.
221 uint32_t earfcnShift = frequencyShift / 100;
222 ulEarfcn += earfcnShift;
223 dlEarfcn += earfcnShift;
224 }
225
226 return ccmap;
227}
228
230CcHelper::CreateSingleCc(uint16_t ulBandwidth,
231 uint16_t dlBandwidth,
232 uint32_t ulEarfcn,
233 uint32_t dlEarfcn,
234 bool isPrimary) const
235{
237 if (m_ulEarfcn != 0)
238 {
239 cc.SetUlEarfcn(ulEarfcn);
240 }
241 else
242 {
243 uint16_t ul = cc.GetUlEarfcn() + ulEarfcn;
244 cc.SetUlEarfcn(ul);
245 }
246 if (m_dlEarfcn != 0)
247 {
248 cc.SetDlEarfcn(dlEarfcn);
249 }
250 else
251 {
252 uint16_t dl = cc.GetDlEarfcn() + dlEarfcn;
253 cc.SetDlEarfcn(dl);
254 }
255 cc.SetDlBandwidth(dlBandwidth);
256 cc.SetUlBandwidth(ulBandwidth);
257
258 cc.SetAsPrimary(isPrimary);
259
260 return cc;
261}
262
263} // namespace ns3
#define MAX_CC
Definition: cc-helper.cc:33
#define MIN_CC
Definition: cc-helper.cc:32
Hold a value for an Attribute.
Definition: attribute.h:70
uint32_t GetUlEarfcn() const
Get UL EARFCN.
Definition: cc-helper.cc:147
ObjectFactory m_ccFactory
Factory for each Carrier Component.
Definition: cc-helper.h:194
void SetNumberOfComponentCarriers(uint16_t nCc)
Set number of CCs.
Definition: cc-helper.cc:111
ComponentCarrier DoCreateSingleCc(uint16_t ulBandwidth, uint16_t dlBandwidth, uint32_t ulEarfcn, uint32_t dlEarfcn, bool isPrimary)
Create single CC.
Definition: cc-helper.cc:171
void SetDlEarfcn(uint32_t dlEarfcn)
Set DL EARFCN.
Definition: cc-helper.cc:123
void DoDispose() override
Destructor implementation.
Definition: cc-helper.cc:97
uint16_t GetDlBandwidth() const
Get DL bandwidth.
Definition: cc-helper.cc:159
uint32_t GetDlEarfcn() const
Get DL EARFCN.
Definition: cc-helper.cc:153
void SetUlBandwidth(uint16_t ulBandwidth)
Set UL bandwidth.
Definition: cc-helper.cc:135
~CcHelper() override
Definition: cc-helper.cc:91
void SetDlBandwidth(uint16_t dlBandwidth)
Set DL bandwidth.
Definition: cc-helper.cc:129
uint16_t m_numberOfComponentCarriers
Number of component carriers.
Definition: cc-helper.h:200
uint16_t GetUlBandwidth() const
Get UL bandwidth.
Definition: cc-helper.cc:165
uint16_t m_ulBandwidth
Uplink Bandwidth.
Definition: cc-helper.h:199
uint16_t m_dlBandwidth
Downlink Bandwidth.
Definition: cc-helper.h:198
static TypeId GetTypeId()
Register this type.
Definition: cc-helper.cc:55
std::map< uint8_t, ComponentCarrier > EquallySpacedCcs()
EquallySpacedCcs() create a valid std::map< uint8_t, Ptr<ComponentCarrier> > The Primary Component Ca...
Definition: cc-helper.cc:181
void SetUlEarfcn(uint32_t ulEarfcn)
Set UL EARFCN.
Definition: cc-helper.cc:117
uint16_t GetNumberOfComponentCarriers() const
Get number of component carriers.
Definition: cc-helper.cc:141
void DoInitialize() override
Initialize() implementation.
Definition: cc-helper.cc:49
uint32_t m_ulEarfcn
Uplink EARFCN.
Definition: cc-helper.h:196
uint32_t m_dlEarfcn
Downlink EARFCN.
Definition: cc-helper.h:197
void SetCcAttribute(std::string n, const AttributeValue &v)
Set an attribute for the Component Carrier to be created.
Definition: cc-helper.cc:104
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:230
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:89
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:444
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Hold an unsigned integer type.
Definition: uinteger.h:45
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.