A Discrete-Event Network Simulator
API
lte-enb-net-device.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 TELEMATICS LAB, DEE - Politecnico di Bari
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: Giuseppe Piro <g.piro@poliba.it>
18  * Author: Marco Miozzo <mmiozzo@cttc.es> : Update to FF API Architecture
19  * Author: Nicola Baldo <nbaldo@cttc.es> : Integrated with new RRC and MAC architecture
20  * Author: Danilo Abrignani <danilo.abrignani@unibo.it> : Integrated with new architecture - GSoC
21  * 2015 - Carrier Aggregation
22  */
23 
24 #include "lte-enb-net-device.h"
25 
26 #include "component-carrier-enb.h"
27 #include "lte-anr.h"
29 #include "lte-enb-mac.h"
30 #include "lte-enb-phy.h"
31 #include "lte-enb-rrc.h"
32 #include "lte-ffr-algorithm.h"
33 #include "lte-handover-algorithm.h"
34 #include "lte-net-device.h"
35 
36 #include <ns3/abort.h>
37 #include <ns3/callback.h>
38 #include <ns3/enum.h>
39 #include <ns3/ipv4-l3-protocol.h>
40 #include <ns3/ipv6-l3-protocol.h>
41 #include <ns3/llc-snap-header.h>
42 #include <ns3/log.h>
43 #include <ns3/node.h>
44 #include <ns3/object-factory.h>
45 #include <ns3/object-map.h>
46 #include <ns3/packet-burst.h>
47 #include <ns3/packet.h>
48 #include <ns3/pointer.h>
49 #include <ns3/simulator.h>
50 #include <ns3/trace-source-accessor.h>
51 #include <ns3/uinteger.h>
52 
53 namespace ns3
54 {
55 
56 NS_LOG_COMPONENT_DEFINE("LteEnbNetDevice");
57 
58 NS_OBJECT_ENSURE_REGISTERED(LteEnbNetDevice);
59 
60 TypeId
62 {
63  static TypeId tid =
64  TypeId("ns3::LteEnbNetDevice")
66  .AddConstructor<LteEnbNetDevice>()
67  .AddAttribute("LteEnbRrc",
68  "The RRC associated to this EnbNetDevice",
69  PointerValue(),
71  MakePointerChecker<LteEnbRrc>())
72  .AddAttribute("LteHandoverAlgorithm",
73  "The handover algorithm associated to this EnbNetDevice",
74  PointerValue(),
76  MakePointerChecker<LteHandoverAlgorithm>())
77  .AddAttribute(
78  "LteAnr",
79  "The automatic neighbour relation function associated to this EnbNetDevice",
80  PointerValue(),
82  MakePointerChecker<LteAnr>())
83  .AddAttribute("LteFfrAlgorithm",
84  "The FFR algorithm associated to this EnbNetDevice",
85  PointerValue(),
87  MakePointerChecker<LteFfrAlgorithm>())
88  .AddAttribute("LteEnbComponentCarrierManager",
89  "The RRC associated to this EnbNetDevice",
90  PointerValue(),
92  MakePointerChecker<LteEnbComponentCarrierManager>())
93  .AddAttribute("ComponentCarrierMap",
94  "List of component carriers.",
97  MakeObjectMapChecker<ComponentCarrierEnb>())
98  .AddAttribute(
99  "UlBandwidth",
100  "Uplink Transmission Bandwidth Configuration in number of Resource Blocks",
101  UintegerValue(25),
104  MakeUintegerChecker<uint8_t>())
105  .AddAttribute(
106  "DlBandwidth",
107  "Downlink Transmission Bandwidth Configuration in number of Resource Blocks",
108  UintegerValue(25),
111  MakeUintegerChecker<uint8_t>())
112  .AddAttribute("CellId",
113  "Cell Identifier",
114  UintegerValue(0),
116  MakeUintegerChecker<uint16_t>())
117  .AddAttribute("DlEarfcn",
118  "Downlink E-UTRA Absolute Radio Frequency Channel Number (EARFCN) "
119  "as per 3GPP 36.101 Section 5.7.3.",
120  UintegerValue(100),
122  MakeUintegerChecker<uint32_t>(0, 262143))
123  .AddAttribute("UlEarfcn",
124  "Uplink E-UTRA Absolute Radio Frequency Channel Number (EARFCN) "
125  "as per 3GPP 36.101 Section 5.7.3.",
126  UintegerValue(18100),
128  MakeUintegerChecker<uint32_t>(0, 262143))
129  .AddAttribute(
130  "CsgId",
131  "The Closed Subscriber Group (CSG) identity that this eNodeB belongs to",
132  UintegerValue(0),
134  MakeUintegerChecker<uint32_t>())
135  .AddAttribute(
136  "CsgIndication",
137  "If true, only UEs which are members of the CSG (i.e. same CSG ID) "
138  "can gain access to the eNodeB, therefore enforcing closed access mode. "
139  "Otherwise, the eNodeB operates as a non-CSG cell and implements open access mode.",
140  BooleanValue(false),
144  return tid;
145 }
146 
148  : m_isConstructed(false),
149  m_isConfigured(false),
150  m_anr(nullptr),
151  m_componentCarrierManager(nullptr)
152 {
153  NS_LOG_FUNCTION(this);
154 }
155 
157 {
158  NS_LOG_FUNCTION(this);
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION(this);
165 
166  m_rrc->Dispose();
167  m_rrc = nullptr;
168 
169  m_handoverAlgorithm->Dispose();
170  m_handoverAlgorithm = nullptr;
171 
172  if (m_anr)
173  {
174  m_anr->Dispose();
175  m_anr = nullptr;
176  }
177  m_componentCarrierManager->Dispose();
178  m_componentCarrierManager = nullptr;
179  // ComponentCarrierEnb::DoDispose() will call DoDispose
180  // of its PHY, MAC, FFR and scheduler instance
181  for (uint32_t i = 0; i < m_ccMap.size(); i++)
182  {
183  m_ccMap.at(i)->Dispose();
184  m_ccMap.at(i) = nullptr;
185  }
186 
188 }
189 
192 {
193  return GetMac(0);
194 }
195 
198 {
199  return GetPhy(0);
200 }
201 
203 LteEnbNetDevice::GetMac(uint8_t index) const
204 {
205  return DynamicCast<ComponentCarrierEnb>(m_ccMap.at(index))->GetMac();
206 }
207 
209 LteEnbNetDevice::GetPhy(uint8_t index) const
210 {
211  return DynamicCast<ComponentCarrierEnb>(m_ccMap.at(index))->GetPhy();
212 }
213 
216 {
217  return m_rrc;
218 }
219 
222 {
224 }
225 
226 uint16_t
228 {
229  return m_cellId;
230 }
231 
232 std::vector<uint16_t>
234 {
235  std::vector<uint16_t> cellIds;
236 
237  cellIds.reserve(m_ccMap.size());
238  for (auto& it : m_ccMap)
239  {
240  cellIds.push_back(it.second->GetCellId());
241  }
242  return cellIds;
243 }
244 
245 bool
246 LteEnbNetDevice::HasCellId(uint16_t cellId) const
247 {
248  return m_rrc->HasCellId(cellId);
249 }
250 
251 uint16_t
253 {
254  return m_ulBandwidth;
255 }
256 
257 void
259 {
260  NS_LOG_FUNCTION(this << bw);
261  switch (bw)
262  {
263  case 6:
264  case 15:
265  case 25:
266  case 50:
267  case 75:
268  case 100:
269  m_ulBandwidth = bw;
270  break;
271 
272  default:
273  NS_FATAL_ERROR("invalid bandwidth value " << bw);
274  break;
275  }
276 }
277 
278 uint16_t
280 {
281  return m_dlBandwidth;
282 }
283 
284 void
286 {
287  NS_LOG_FUNCTION(this << uint16_t(bw));
288  switch (bw)
289  {
290  case 6:
291  case 15:
292  case 25:
293  case 50:
294  case 75:
295  case 100:
296  m_dlBandwidth = bw;
297  break;
298 
299  default:
300  NS_FATAL_ERROR("invalid bandwidth value " << bw);
301  break;
302  }
303 }
304 
305 uint32_t
307 {
308  return m_dlEarfcn;
309 }
310 
311 void
313 {
314  NS_LOG_FUNCTION(this << earfcn);
315  m_dlEarfcn = earfcn;
316 }
317 
318 uint32_t
320 {
321  return m_ulEarfcn;
322 }
323 
324 void
326 {
327  NS_LOG_FUNCTION(this << earfcn);
328  m_ulEarfcn = earfcn;
329 }
330 
331 uint32_t
333 {
334  return m_csgId;
335 }
336 
337 void
339 {
340  NS_LOG_FUNCTION(this << csgId);
341  m_csgId = csgId;
342  UpdateConfig(); // propagate the change to RRC level
343 }
344 
345 bool
347 {
348  return m_csgIndication;
349 }
350 
351 void
353 {
354  NS_LOG_FUNCTION(this << csgIndication);
355  m_csgIndication = csgIndication;
356  UpdateConfig(); // propagate the change to RRC level
357 }
358 
359 std::map<uint8_t, Ptr<ComponentCarrierBaseStation>>
361 {
362  return m_ccMap;
363 }
364 
365 void
367 {
368  NS_ASSERT_MSG(!m_isConfigured, "attempt to set CC map after configuration");
369  m_ccMap = ccm;
370 }
371 
372 void
374 {
375  NS_LOG_FUNCTION(this);
376  m_isConstructed = true;
377  UpdateConfig();
378  for (auto it = m_ccMap.begin(); it != m_ccMap.end(); ++it)
379  {
380  it->second->Initialize();
381  }
382  m_rrc->Initialize();
383  m_componentCarrierManager->Initialize();
384  m_handoverAlgorithm->Initialize();
385 
386  if (m_anr)
387  {
388  m_anr->Initialize();
389  }
390 
391  m_ffrAlgorithm->Initialize();
392 }
393 
394 bool
395 LteEnbNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
396 {
397  NS_LOG_FUNCTION(this << packet << dest << protocolNumber);
398  NS_ABORT_MSG_IF(protocolNumber != Ipv4L3Protocol::PROT_NUMBER &&
399  protocolNumber != Ipv6L3Protocol::PROT_NUMBER,
400  "unsupported protocol " << protocolNumber
401  << ", only IPv4 and IPv6 are supported");
402  return m_rrc->SendData(packet);
403 }
404 
405 void
407 {
408  NS_LOG_FUNCTION(this);
409 
410  if (m_isConstructed)
411  {
412  if (!m_isConfigured)
413  {
414  NS_LOG_LOGIC(this << " Configure cell " << m_cellId);
415  // we have to make sure that this function is called only once
416  NS_ASSERT(!m_ccMap.empty());
417  m_rrc->ConfigureCell(m_ccMap);
418  m_isConfigured = true;
419  }
420 
421  NS_LOG_LOGIC(this << " Updating SIB1 of cell " << m_cellId << " with CSG ID " << m_csgId
422  << " and CSG indication " << m_csgIndication);
423  m_rrc->SetCsgId(m_csgId, m_csgIndication);
424  }
425  else
426  {
427  /*
428  * Lower layers are not ready yet, so do nothing now and expect
429  * ``DoInitialize`` to re-invoke this function.
430  */
431  }
432 }
433 
434 } // namespace ns3
a polymophic address class
Definition: address.h:101
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
void SetUlEarfcn(uint32_t earfcn)
std::map< uint8_t, Ptr< ComponentCarrierBaseStation > > GetCcMap() const
bool HasCellId(uint16_t cellId) const
Ptr< LteAnr > m_anr
ANR.
void UpdateConfig()
Propagate attributes and configuration to sub-modules.
uint32_t m_dlEarfcn
DEPRECATE - It is maintained for backward compatibility after adding CA feature- downlink carrier fre...
void SetCsgId(uint32_t csgId)
Associate the eNodeB device with a particular CSG.
Ptr< LteHandoverAlgorithm > m_handoverAlgorithm
the handover algorithm
void SetDlEarfcn(uint32_t earfcn)
bool m_isConfigured
is configured?
bool GetCsgIndication() const
Returns the CSG indication flag of the eNodeB.
void SetUlBandwidth(uint16_t bw)
uint16_t m_dlBandwidth
DEPRECATE - It is maintained for backward compatibility after adding CA feature- downlink bandwidth i...
bool m_isConstructed
is constructed?
uint32_t GetCsgId() const
Returns the CSG ID of the eNodeB.
uint16_t GetDlBandwidth() const
uint32_t GetUlEarfcn() const
uint32_t GetDlEarfcn() const
Ptr< LteEnbRrc > GetRrc() const
void SetCsgIndication(bool csgIndication)
Enable or disable the CSG indication flag.
Ptr< LteEnbRrc > m_rrc
the RRC
void SetCcMap(std::map< uint8_t, Ptr< ComponentCarrierBaseStation >> ccm)
Set the ComponentCarrier Map of the Enb.
Ptr< LteEnbPhy > GetPhy() const
uint16_t m_cellId
Cell Identifier.
uint16_t GetUlBandwidth() const
void DoInitialize() override
Initialize() implementation.
std::vector< uint16_t > GetCellIds() const
Ptr< LteEnbComponentCarrierManager > GetComponentCarrierManager() const
bool m_csgIndication
CSG indication.
void SetDlBandwidth(uint16_t bw)
uint32_t m_ulEarfcn
DEPRECATE - It is maintained for backward compatibility after adding CA feature- uplink carrier frequ...
Ptr< LteFfrAlgorithm > m_ffrAlgorithm
DEPRECATED - It is maintained for backward compatibility after adding CA feature.
Ptr< LteEnbComponentCarrierManager > m_componentCarrierManager
the component carrier manager of this eNb
static TypeId GetTypeId()
Get the type ID.
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
Ptr< LteEnbMac > GetMac() const
std::map< uint8_t, Ptr< ComponentCarrierBaseStation > > m_ccMap
ComponentCarrier map.
uint16_t GetCellId() const
uint16_t m_ulBandwidth
DEPRECATE - It is maintained for backward compatibility after adding CA feature- uplink bandwidth in ...
void DoDispose() override
Destructor implementation.
LteNetDevice provides basic implementation for all LTE network devices.
void DoDispose() override
Destructor implementation.
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition: object-map.h:40
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-map.h:76