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