A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-rrc-protocol-ideal.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 #include <ns3/fatal-error.h>
22 #include <ns3/log.h>
23 #include <ns3/nstime.h>
24 #include <ns3/node-list.h>
25 #include <ns3/node.h>
26 #include <ns3/simulator.h>
27 
28 #include "lte-rrc-protocol-ideal.h"
29 #include "lte-ue-rrc.h"
30 #include "lte-enb-rrc.h"
31 #include "lte-enb-net-device.h"
32 #include "lte-ue-net-device.h"
33 
34 NS_LOG_COMPONENT_DEFINE ("LteRrcProtocolIdeal");
35 
36 
37 namespace ns3 {
38 
39 
40 const Time RRC_IDEAL_MSG_DELAY = MilliSeconds (0);
41 
43 
45  : m_ueRrcSapProvider (0),
46  m_enbRrcSapProvider (0)
47 {
49 }
50 
52 {
53 }
54 
55 void
57 {
58  NS_LOG_FUNCTION (this);
59  delete m_ueRrcSapUser;
60  m_rrc = 0;
61 }
62 
63 TypeId
65 {
66  static TypeId tid = TypeId ("ns3::LteUeRrcProtocolIdeal")
67  .SetParent<Object> ()
68  .AddConstructor<LteUeRrcProtocolIdeal> ()
69  ;
70  return tid;
71 }
72 
73 void
75 {
77 }
78 
81 {
82  return m_ueRrcSapUser;
83 }
84 
85 void
87 {
88  m_rrc = rrc;
89 }
90 
91 void
93 {
94  NS_LOG_FUNCTION (this);
95  // We don't care about SRB0/SRB1 since we use ideal RRC messages.
96 }
97 
98 void
100 {
101  // initialize the RNTI and get the EnbLteRrcSapProvider for the
102  // eNB we are currently attached to
103  m_rnti = m_rrc->GetRnti ();
105 
109  m_rnti,
110  msg);
111 }
112 
113 void
115 {
119  m_rnti,
120  msg);
121 }
122 
123 void
125 {
126  // re-initialize the RNTI and get the EnbLteRrcSapProvider for the
127  // eNB we are currently attached to
128  m_rnti = m_rrc->GetRnti ();
130 
134  m_rnti,
135  msg);
136 }
137 
138 void
140 {
144  m_rnti,
145  msg);
146 }
147 
148 void
150 {
154  m_rnti,
155 msg);
156 }
157 
158 void
160 {
164  m_rnti,
165  msg);
166 }
167 
168 void
170 {
171  uint16_t cellId = m_rrc->GetCellId ();
172 
173  // walk list of all nodes to get the peer eNB
174  Ptr<LteEnbNetDevice> enbDev;
175  NodeList::Iterator listEnd = NodeList::End ();
176  bool found = false;
177  for (NodeList::Iterator i = NodeList::Begin ();
178  (i != listEnd) && (!found);
179  ++i)
180  {
181  Ptr<Node> node = *i;
182  int nDevs = node->GetNDevices ();
183  for (int j = 0;
184  (j < nDevs) && (!found);
185  j++)
186  {
187  enbDev = node->GetDevice (j)->GetObject <LteEnbNetDevice> ();
188  if (enbDev == 0)
189  {
190  continue;
191  }
192  else
193  {
194  if (enbDev->GetCellId () == cellId)
195  {
196  found = true;
197  break;
198  }
199  }
200  }
201  }
202  NS_ASSERT_MSG (found, " Unable to find eNB with CellId =" << cellId);
203  m_enbRrcSapProvider = enbDev->GetRrc ()->GetLteEnbRrcSapProvider ();
204  Ptr<LteEnbRrcProtocolIdeal> enbRrcProtocolIdeal = enbDev->GetRrc ()->GetObject<LteEnbRrcProtocolIdeal> ();
205  enbRrcProtocolIdeal->SetUeRrcSapProvider (m_rnti, m_ueRrcSapProvider);
206 }
207 
208 
210 
212  : m_enbRrcSapProvider (0)
213 {
214  NS_LOG_FUNCTION (this);
216 }
217 
219 {
220  NS_LOG_FUNCTION (this);
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION (this);
227  delete m_enbRrcSapUser;
228 }
229 
230 TypeId
232 {
233  static TypeId tid = TypeId ("ns3::LteEnbRrcProtocolIdeal")
234  .SetParent<Object> ()
235  .AddConstructor<LteEnbRrcProtocolIdeal> ()
236  ;
237  return tid;
238 }
239 
240 void
242 {
244 }
245 
248 {
249  return m_enbRrcSapUser;
250 }
251 
252 void
254 {
255  m_cellId = cellId;
256 }
257 
260 {
261  std::map<uint16_t, LteUeRrcSapProvider*>::const_iterator it;
262  it = m_enbRrcSapProviderMap.find (rnti);
263  NS_ASSERT_MSG (it != m_enbRrcSapProviderMap.end (), "could not find RNTI = " << rnti);
264  return it->second;
265 }
266 
267 void
269 {
270  std::map<uint16_t, LteUeRrcSapProvider*>::iterator it;
271  it = m_enbRrcSapProviderMap.find (rnti);
272  NS_ASSERT_MSG (it != m_enbRrcSapProviderMap.end (), "could not find RNTI = " << rnti);
273  it->second = p;
274 }
275 
276 void
278 {
279  NS_LOG_FUNCTION (this << rnti);
280 
281  // // walk list of all nodes to get the peer UE RRC SAP Provider
282  // Ptr<LteUeRrc> ueRrc;
283  // NodeList::Iterator listEnd = NodeList::End ();
284  // bool found = false;
285  // for (NodeList::Iterator i = NodeList::Begin (); (i != listEnd) && (found == false); i++)
286  // {
287  // Ptr<Node> node = *i;
288  // int nDevs = node->GetNDevices ();
289  // for (int j = 0; j < nDevs; j++)
290  // {
291  // Ptr<LteUeNetDevice> ueDev = node->GetDevice (j)->GetObject <LteUeNetDevice> ();
292  // if (!ueDev)
293  // {
294  // continue;
295  // }
296  // else
297  // {
298  // ueRrc = ueDev->GetRrc ();
299  // if ((ueRrc->GetRnti () == rnti) && (ueRrc->GetCellId () == m_cellId))
300  // {
301  // found = true;
302  // break;
303  // }
304  // }
305  // }
306  // }
307  // NS_ASSERT_MSG (found , " Unable to find UE with RNTI=" << rnti << " cellId=" << m_cellId);
308  // m_enbRrcSapProviderMap[rnti] = ueRrc->GetLteUeRrcSapProvider ();
309 
310 
311  // just create empty entry, the UeRrcSapProvider will be set by the
312  // ue upon connection request or connection reconfiguration
313  // completed
314  m_enbRrcSapProviderMap[rnti] = 0;
315 
316 }
317 
318 void
320 {
321  NS_LOG_FUNCTION (this << rnti);
322  m_enbRrcSapProviderMap.erase (rnti);
323 }
324 
325 void
327 {
328  NS_LOG_FUNCTION (this);
329  for (std::map<uint16_t, LteUeRrcSapProvider*>::const_iterator it = m_enbRrcSapProviderMap.begin ();
330  it != m_enbRrcSapProviderMap.end ();
331  ++it)
332  {
335  it->second,
336  msg);
337  }
338 }
339 
340 void
342 {
343  NS_LOG_FUNCTION (this << m_cellId);
344  // walk list of all nodes to get UEs with this cellId
345  Ptr<LteUeRrc> ueRrc;
346  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
347  {
348  Ptr<Node> node = *i;
349  int nDevs = node->GetNDevices ();
350  for (int j = 0; j < nDevs; ++j)
351  {
352  Ptr<LteUeNetDevice> ueDev = node->GetDevice (j)->GetObject <LteUeNetDevice> ();
353  if (ueDev != 0)
354  {
355  NS_LOG_LOGIC ("considering UE " << ueDev->GetImsi ());
356  Ptr<LteUeRrc> ueRrc = ueDev->GetRrc ();
357  if (ueRrc->GetCellId () == m_cellId)
358  {
361  ueRrc->GetLteUeRrcSapProvider (),
362  msg);
363  }
364  }
365  }
366  }
367 }
368 
369 void
371 {
372  NS_LOG_FUNCTION (this << m_cellId);
373  // walk list of all nodes to get UEs with this cellId
374  Ptr<LteUeRrc> ueRrc;
375  for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); ++i)
376  {
377  Ptr<Node> node = *i;
378  int nDevs = node->GetNDevices ();
379  for (int j = 0; j < nDevs; ++j)
380  {
381  Ptr<LteUeNetDevice> ueDev = node->GetDevice (j)->GetObject <LteUeNetDevice> ();
382  if (ueDev != 0)
383  {
384  Ptr<LteUeRrc> ueRrc = ueDev->GetRrc ();
385  NS_LOG_LOGIC ("considering UE IMSI " << ueDev->GetImsi () << " that has cellId " << ueRrc->GetCellId ());
386  if (ueRrc->GetCellId () == m_cellId)
387  {
388  NS_LOG_LOGIC ("sending SI to IMSI " << ueDev->GetImsi ());
389  ueRrc->GetLteUeRrcSapProvider ()->RecvSystemInformation (msg);
392  ueRrc->GetLteUeRrcSapProvider (),
393  msg);
394  }
395  }
396  }
397  }
398 }
399 
400 void
402 {
405  GetUeRrcSapProvider (rnti),
406  msg);
407 }
408 
409 void
411 {
414  GetUeRrcSapProvider (rnti),
415  msg);
416 }
417 
418 void
420 {
423  GetUeRrcSapProvider (rnti),
424  msg);
425 }
426 
427 void
429 {
432  GetUeRrcSapProvider (rnti),
433  msg);
434 }
435 
436 void
438 {
441  GetUeRrcSapProvider (rnti),
442  msg);
443 }
444 
445 void
447 {
450  GetUeRrcSapProvider (rnti),
451  msg);
452 }
453 
454 /*
455  * The purpose of LteEnbRrcProtocolIdeal is to avoid encoding
456  * messages. In order to do so, we need to have some form of encoding for
457  * inter-node RRC messages like HandoverPreparationInfo and HandoverCommand. Doing so
458  * directly is not practical (these messages includes a lot of
459  * information elements, so encoding all of them would defeat the
460  * purpose of LteEnbRrcProtocolIdeal. The workaround is to store the
461  * actual message in a global map, so that then we can just encode the
462  * key in a header and send that between eNBs over X2.
463  *
464  */
465 
466 std::map<uint32_t, LteRrcSap::HandoverPreparationInfo> g_handoverPreparationInfoMsgMap;
468 
469 /*
470  * This header encodes the map key discussed above. We keep this
471  * private since it should not be used outside this file.
472  *
473  */
475 {
476 public:
477  uint32_t GetMsgId ();
478  void SetMsgId (uint32_t id);
479  static TypeId GetTypeId (void);
480  virtual TypeId GetInstanceTypeId (void) const;
481  virtual void Print (std::ostream &os) const;
482  virtual uint32_t GetSerializedSize (void) const;
483  virtual void Serialize (Buffer::Iterator start) const;
484  virtual uint32_t Deserialize (Buffer::Iterator start);
485 
486 private:
487  uint32_t m_msgId;
488 };
489 
490 uint32_t
492 {
493  return m_msgId;
494 }
495 
496 void
498 {
499  m_msgId = id;
500 }
501 
502 
503 TypeId
505 {
506  static TypeId tid = TypeId ("ns3::IdealHandoverPreparationInfoHeader")
507  .SetParent<Header> ()
508  .AddConstructor<IdealHandoverPreparationInfoHeader> ()
509  ;
510  return tid;
511 }
512 
513 TypeId
515 {
516  return GetTypeId ();
517 }
518 
519 void IdealHandoverPreparationInfoHeader::Print (std::ostream &os) const
520 {
521  os << " msgId=" << m_msgId;
522 }
523 
525 {
526  return 4;
527 }
528 
530 {
531  start.WriteU32 (m_msgId);
532 }
533 
535 {
536  m_msgId = start.ReadU32 ();
537  return GetSerializedSize ();
538 }
539 
540 
541 
544 {
545  uint32_t msgId = ++g_handoverPreparationInfoMsgIdCounter;
546  NS_ASSERT_MSG (g_handoverPreparationInfoMsgMap.find (msgId) == g_handoverPreparationInfoMsgMap.end (), "msgId " << msgId << " already in use");
547  NS_LOG_INFO (" encoding msgId = " << msgId);
548  g_handoverPreparationInfoMsgMap.insert (std::pair<uint32_t, LteRrcSap::HandoverPreparationInfo> (msgId, msg));
550  h.SetMsgId (msgId);
551  Ptr<Packet> p = Create<Packet> ();
552  p->AddHeader (h);
553  return p;
554 }
555 
558 {
560  p->RemoveHeader (h);
561  uint32_t msgId = h.GetMsgId ();
562  NS_LOG_INFO (" decoding msgId = " << msgId);
563  std::map<uint32_t, LteRrcSap::HandoverPreparationInfo>::iterator it = g_handoverPreparationInfoMsgMap.find (msgId);
564  NS_ASSERT_MSG (it != g_handoverPreparationInfoMsgMap.end (), "msgId " << msgId << " not found");
565  LteRrcSap::HandoverPreparationInfo msg = it->second;
567  return msg;
568 }
569 
570 
571 
572 std::map<uint32_t, LteRrcSap::RrcConnectionReconfiguration> g_handoverCommandMsgMap;
574 
575 /*
576  * This header encodes the map key discussed above. We keep this
577  * private since it should not be used outside this file.
578  *
579  */
581 {
582 public:
583  uint32_t GetMsgId ();
584  void SetMsgId (uint32_t id);
585  static TypeId GetTypeId (void);
586  virtual TypeId GetInstanceTypeId (void) const;
587  virtual void Print (std::ostream &os) const;
588  virtual uint32_t GetSerializedSize (void) const;
589  virtual void Serialize (Buffer::Iterator start) const;
590  virtual uint32_t Deserialize (Buffer::Iterator start);
591 
592 private:
593  uint32_t m_msgId;
594 };
595 
596 uint32_t
598 {
599  return m_msgId;
600 }
601 
602 void
604 {
605  m_msgId = id;
606 }
607 
608 
609 TypeId
611 {
612  static TypeId tid = TypeId ("ns3::IdealHandoverCommandHeader")
613  .SetParent<Header> ()
614  .AddConstructor<IdealHandoverCommandHeader> ()
615  ;
616  return tid;
617 }
618 
619 TypeId
621 {
622  return GetTypeId ();
623 }
624 
625 void IdealHandoverCommandHeader::Print (std::ostream &os) const
626 {
627  os << " msgId=" << m_msgId;
628 }
629 
631 {
632  return 4;
633 }
634 
636 {
637  start.WriteU32 (m_msgId);
638 }
639 
641 {
642  m_msgId = start.ReadU32 ();
643  return GetSerializedSize ();
644 }
645 
646 
647 
650 {
651  uint32_t msgId = ++g_handoverCommandMsgIdCounter;
652  NS_ASSERT_MSG (g_handoverCommandMsgMap.find (msgId) == g_handoverCommandMsgMap.end (), "msgId " << msgId << " already in use");
653  NS_LOG_INFO (" encoding msgId = " << msgId);
654  g_handoverCommandMsgMap.insert (std::pair<uint32_t, LteRrcSap::RrcConnectionReconfiguration> (msgId, msg));
656  h.SetMsgId (msgId);
657  Ptr<Packet> p = Create<Packet> ();
658  p->AddHeader (h);
659  return p;
660 }
661 
664 {
666  p->RemoveHeader (h);
667  uint32_t msgId = h.GetMsgId ();
668  NS_LOG_INFO (" decoding msgId = " << msgId);
669  std::map<uint32_t, LteRrcSap::RrcConnectionReconfiguration>::iterator it = g_handoverCommandMsgMap.find (msgId);
670  NS_ASSERT_MSG (it != g_handoverCommandMsgMap.end (), "msgId " << msgId << " not found");
672  g_handoverCommandMsgMap.erase (it);
673  return msg;
674 }
675 
676 
677 
678 
679 
680 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:268
LteUeRrcSapProvider * m_ueRrcSapProvider
void DoSendRrcConnectionReestablishmentReject(uint16_t rnti, LteRrcSap::RrcConnectionReestablishmentReject msg)
LteEnbRrcSapProvider * m_enbRrcSapProvider
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
uint32_t ReadU32(void)
Definition: buffer.cc:997
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual void RecvMasterInformationBlock(MasterInformationBlock msg)=0
virtual void RecvRrcConnectionSetupCompleted(uint16_t rnti, RrcConnectionSetupCompleted msg)=0
void DoSendRrcConnectionReconfigurationCompleted(LteRrcSap::RrcConnectionReconfigurationCompleted msg)
void DoSendRrcConnectionReestablishmentRequest(LteRrcSap::RrcConnectionReestablishmentRequest msg)
std::map< uint32_t, LteRrcSap::HandoverPreparationInfo > g_handoverPreparationInfoMsgMap
void DoSendRrcConnectionReconfiguration(uint16_t rnti, LteRrcSap::RrcConnectionReconfiguration msg)
void DoSendRrcConnectionRelease(uint16_t rnti, LteRrcSap::RrcConnectionRelease msg)
virtual uint32_t GetSerializedSize(void) const
void SetUeRrc(Ptr< LteUeRrc > rrc)
void SetLteEnbRrcSapProvider(LteEnbRrcSapProvider *p)
#define NS_LOG_INFO(msg)
Definition: log.h:264
void DoSendMasterInformationBlock(LteRrcSap::MasterInformationBlock msg)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:824
void DoSendRrcConnectionSetup(uint16_t rnti, LteRrcSap::RrcConnectionSetup msg)
uint32_t g_handoverPreparationInfoMsgIdCounter
void SetLteUeRrcSapProvider(LteUeRrcSapProvider *p)
virtual void RecvRrcConnectionRelease(RrcConnectionRelease msg)=0
iterator in a Buffer instance
Definition: buffer.h:98
void DoSetupUe(uint16_t rnti, LteEnbRrcSapUser::SetupUeParameters params)
virtual void RecvRrcConnectionReestablishmentReject(RrcConnectionReestablishmentReject msg)=0
virtual void RecvRrcConnectionReject(RrcConnectionReject msg)=0
const Time RRC_IDEAL_MSG_DELAY
void DoSendSystemInformation(LteRrcSap::SystemInformation msg)
virtual void Serialize(Buffer::Iterator start) const
virtual void RecvSystemInformationBlockType1(SystemInformationBlockType1 msg)=0
Ptr< Packet > DoEncodeHandoverPreparationInformation(LteRrcSap::HandoverPreparationInfo msg)
void DoSendRrcConnectionSetupCompleted(LteRrcSap::RrcConnectionSetupCompleted msg)
static Iterator End(void)
Definition: node-list.cc:186
virtual void RecvRrcConnectionReconfiguration(RrcConnectionReconfiguration msg)=0
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
virtual void RecvRrcConnectionReestablishment(RrcConnectionReestablishment msg)=0
virtual void Print(std::ostream &os) const
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:131
virtual uint32_t Deserialize(Buffer::Iterator start)
void DoSendRrcConnectionRequest(LteRrcSap::RrcConnectionRequest msg)
virtual void Print(std::ostream &os) const
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
std::map< uint16_t, LteUeRrcSapProvider * > m_enbRrcSapProviderMap
LteRrcSap::HandoverPreparationInfo DoDecodeHandoverPreparationInformation(Ptr< Packet > p)
virtual void Serialize(Buffer::Iterator start) const
uint32_t GetNDevices(void) const
Definition: node.cc:139
LteUeRrcSapUser * GetLteUeRrcSapUser()
virtual void RecvRrcConnectionSetup(RrcConnectionSetup msg)=0
std::vector< Ptr< Node > >::const_iterator Iterator
Definition: node-list.h:43
virtual void RecvRrcConnectionRequest(uint16_t rnti, RrcConnectionRequest msg)=0
virtual void RecvSystemInformation(SystemInformation msg)=0
NS_LOG_COMPONENT_DEFINE("LteRrcProtocolIdeal")
LteUeRrcSapProvider * GetUeRrcSapProvider(uint16_t rnti)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
LteRrcSap::RrcConnectionReconfiguration DoDecodeHandoverCommand(Ptr< Packet > p)
void DoSendRrcConnectionReject(uint16_t rnti, LteRrcSap::RrcConnectionReject msg)
std::map< uint32_t, LteRrcSap::RrcConnectionReconfiguration > g_handoverCommandMsgMap
void DoSetup(LteUeRrcSapUser::SetupParameters params)
virtual void RecvRrcConnectionReestablishmentRequest(uint16_t rnti, RrcConnectionReestablishmentRequest msg)=0
void DoSendRrcConnectionReestablishmentComplete(LteRrcSap::RrcConnectionReestablishmentComplete msg)
static Iterator Begin(void)
Definition: node-list.cc:180
void DoSendRrcConnectionReestablishment(uint16_t rnti, LteRrcSap::RrcConnectionReestablishment msg)
void SetUeRrcSapProvider(uint16_t rnti, LteUeRrcSapProvider *p)
virtual void RecvMeasurementReport(uint16_t rnti, MeasurementReport msg)=0
virtual uint32_t Deserialize(Buffer::Iterator start)
LteEnbRrcSapProvider * m_enbRrcSapProvider
uint32_t g_handoverCommandMsgIdCounter
virtual void RecvRrcConnectionReestablishmentComplete(uint16_t rnti, RrcConnectionReestablishmentComplete msg)=0
a base class which provides memory management and object aggregation
Definition: object.h:63
Ptr< Packet > DoEncodeHandoverCommand(LteRrcSap::RrcConnectionReconfiguration msg)
virtual TypeId GetInstanceTypeId(void) const
LteEnbRrcSapUser * GetLteEnbRrcSapUser()
void WriteU32(uint32_t data)
Definition: buffer.cc:903
virtual void RecvRrcConnectionReconfigurationCompleted(uint16_t rnti, RrcConnectionReconfigurationCompleted msg)=0
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void DoSendSystemInformationBlockType1(LteRrcSap::SystemInformationBlockType1 msg)
void DoSendMeasurementReport(LteRrcSap::MeasurementReport msg)
void AddHeader(const Header &header)
Definition: packet.cc:253
virtual uint32_t GetSerializedSize(void) const