-
Notifications
You must be signed in to change notification settings - Fork 0
/
epc-x2.cc
764 lines (590 loc) · 28.5 KB
/
epc-x2.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Manuel Requena <manuel.requena@cttc.es>
*/
#include "ns3/log.h"
#include "ns3/inet-socket-address.h"
#include "ns3/packet.h"
#include "ns3/node.h"
#include "ns3/epc-gtpu-header.h"
#include "ns3/epc-x2-header.h"
#include "ns3/epc-x2.h"
namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("EpcX2");
X2IfaceInfo::X2IfaceInfo (Ipv4Address remoteIpAddr, Ptr<Socket> localCtrlPlaneSocket, Ptr<Socket> localUserPlaneSocket)
{
m_remoteIpAddr = remoteIpAddr;
m_localCtrlPlaneSocket = localCtrlPlaneSocket;
m_localUserPlaneSocket = localUserPlaneSocket;
}
X2IfaceInfo::~X2IfaceInfo (void)
{
m_localCtrlPlaneSocket = 0;
m_localUserPlaneSocket = 0;
}
X2IfaceInfo&
X2IfaceInfo::operator= (const X2IfaceInfo& value)
{
NS_LOG_FUNCTION (this);
m_remoteIpAddr = value.m_remoteIpAddr;
m_localCtrlPlaneSocket = value.m_localCtrlPlaneSocket;
m_localUserPlaneSocket = value.m_localUserPlaneSocket;
return *this;
}
///////////////////////////////////////////
X2CellInfo::X2CellInfo (uint16_t localCellId, uint16_t remoteCellId)
{
m_localCellId = localCellId;
m_remoteCellId = remoteCellId;
}
X2CellInfo::~X2CellInfo (void)
{
m_localCellId = 0;
m_remoteCellId = 0;
}
X2CellInfo&
X2CellInfo::operator= (const X2CellInfo& value)
{
NS_LOG_FUNCTION (this);
m_localCellId = value.m_localCellId;
m_remoteCellId = value.m_remoteCellId;
return *this;
}
///////////////////////////////////////////
NS_OBJECT_ENSURE_REGISTERED (EpcX2);
EpcX2::EpcX2 ()
: m_x2cUdpPort (4444),
m_x2uUdpPort (2152)
{
NS_LOG_FUNCTION (this);
m_x2SapProvider = new EpcX2SpecificEpcX2SapProvider<EpcX2> (this);
}
EpcX2::~EpcX2 ()
{
NS_LOG_FUNCTION (this);
}
void
EpcX2::DoDispose (void)
{
NS_LOG_FUNCTION (this);
m_x2InterfaceSockets.clear ();
m_x2InterfaceCellIds.clear ();
delete m_x2SapProvider;
}
TypeId
EpcX2::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::EpcX2")
.SetParent<Object> ()
.SetGroupName("Lte");
return tid;
}
void
EpcX2::SetEpcX2SapUser (EpcX2SapUser * s)
{
NS_LOG_FUNCTION (this << s);
m_x2SapUser = s;
}
EpcX2SapProvider*
EpcX2::GetEpcX2SapProvider ()
{
NS_LOG_FUNCTION (this);
return m_x2SapProvider;
}
void
EpcX2::AddX2Interface (uint16_t localCellId, Ipv4Address localX2Address, uint16_t remoteCellId, Ipv4Address remoteX2Address)
{
NS_LOG_FUNCTION (this << localCellId << localX2Address << remoteCellId << remoteX2Address);
int retval;
// Get local eNB where this X2 entity belongs to
Ptr<Node> localEnb = GetObject<Node> ();
// Create X2-C socket for the local eNB
Ptr<Socket> localX2cSocket = Socket::CreateSocket (localEnb, TypeId::LookupByName ("ns3::UdpSocketFactory"));
retval = localX2cSocket->Bind (InetSocketAddress (localX2Address, m_x2cUdpPort));
NS_ASSERT (retval == 0);
localX2cSocket->SetRecvCallback (MakeCallback (&EpcX2::RecvFromX2cSocket, this));
// Create X2-U socket for the local eNB
Ptr<Socket> localX2uSocket = Socket::CreateSocket (localEnb, TypeId::LookupByName ("ns3::UdpSocketFactory"));
retval = localX2uSocket->Bind (InetSocketAddress (localX2Address, m_x2uUdpPort));
NS_ASSERT (retval == 0);
localX2uSocket->SetRecvCallback (MakeCallback (&EpcX2::RecvFromX2uSocket, this));
NS_ASSERT_MSG (m_x2InterfaceSockets.find (remoteCellId) == m_x2InterfaceSockets.end (),
"Mapping for remoteCellId = " << remoteCellId << " is already known");
m_x2InterfaceSockets [remoteCellId] = Create<X2IfaceInfo> (remoteX2Address, localX2cSocket, localX2uSocket);
NS_ASSERT_MSG (m_x2InterfaceCellIds.find (localX2cSocket) == m_x2InterfaceCellIds.end (),
"Mapping for control plane localSocket = " << localX2cSocket << " is already known");
m_x2InterfaceCellIds [localX2cSocket] = Create<X2CellInfo> (localCellId, remoteCellId);
NS_ASSERT_MSG (m_x2InterfaceCellIds.find (localX2uSocket) == m_x2InterfaceCellIds.end (),
"Mapping for data plane localSocket = " << localX2uSocket << " is already known");
m_x2InterfaceCellIds [localX2uSocket] = Create<X2CellInfo> (localCellId, remoteCellId);
}
void
EpcX2::RecvFromX2cSocket (Ptr<Socket> socket)
{
NS_LOG_FUNCTION (this << socket);
NS_LOG_LOGIC ("Recv X2 message: from Socket");
Ptr<Packet> packet = socket->Recv ();
NS_LOG_LOGIC ("packetLen = " << packet->GetSize ());
NS_ASSERT_MSG (m_x2InterfaceCellIds.find (socket) != m_x2InterfaceCellIds.end (),
"Missing infos of local and remote CellId");
Ptr<X2CellInfo> cellsInfo = m_x2InterfaceCellIds [socket];
EpcX2Header x2Header;
packet->RemoveHeader (x2Header);
NS_LOG_LOGIC ("X2 header: " << x2Header);
uint8_t messageType = x2Header.GetMessageType ();
uint8_t procedureCode = x2Header.GetProcedureCode ();
if (procedureCode == EpcX2Header::HandoverPreparation)
{
if (messageType == EpcX2Header::InitiatingMessage)
{
NS_LOG_LOGIC ("Recv X2 message: HANDOVER REQUEST");
EpcX2HandoverRequestHeader x2HoReqHeader;
packet->RemoveHeader (x2HoReqHeader);
NS_LOG_INFO ("X2 HandoverRequest header: " << x2HoReqHeader);
EpcX2SapUser::HandoverRequestParams params;
params.oldEnbUeX2apId = x2HoReqHeader.GetOldEnbUeX2apId ();
params.cause = x2HoReqHeader.GetCause ();
params.sourceCellId = cellsInfo->m_remoteCellId;
params.targetCellId = x2HoReqHeader.GetTargetCellId ();
params.mmeUeS1apId = x2HoReqHeader.GetMmeUeS1apId ();
params.ueAggregateMaxBitRateDownlink = x2HoReqHeader.GetUeAggregateMaxBitRateDownlink ();
params.ueAggregateMaxBitRateUplink = x2HoReqHeader.GetUeAggregateMaxBitRateUplink ();
params.bearers = x2HoReqHeader.GetBearers ();
params.rrcContext = packet;
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("mmeUeS1apId = " << params.mmeUeS1apId);
NS_LOG_LOGIC ("cellsInfo->m_localCellId = " << cellsInfo->m_localCellId);
NS_ASSERT_MSG (params.targetCellId == cellsInfo->m_localCellId,
"TargetCellId mismatches with localCellId");
m_x2SapUser->RecvHandoverRequest (params);
}
else if (messageType == EpcX2Header::SuccessfulOutcome)
{
NS_LOG_LOGIC ("Recv X2 message: HANDOVER REQUEST ACK");
EpcX2HandoverRequestAckHeader x2HoReqAckHeader;
packet->RemoveHeader (x2HoReqAckHeader);
NS_LOG_INFO ("X2 HandoverRequestAck header: " << x2HoReqAckHeader);
EpcX2SapUser::HandoverRequestAckParams params;
params.oldEnbUeX2apId = x2HoReqAckHeader.GetOldEnbUeX2apId ();
params.newEnbUeX2apId = x2HoReqAckHeader.GetNewEnbUeX2apId ();
params.sourceCellId = cellsInfo->m_localCellId;
params.targetCellId = cellsInfo->m_remoteCellId;
params.admittedBearers = x2HoReqAckHeader.GetAdmittedBearers ();
params.notAdmittedBearers = x2HoReqAckHeader.GetNotAdmittedBearers ();
params.rrcContext = packet;
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
m_x2SapUser->RecvHandoverRequestAck (params);
}
else // messageType == EpcX2Header::UnsuccessfulOutcome
{
NS_LOG_LOGIC ("Recv X2 message: HANDOVER PREPARATION FAILURE");
EpcX2HandoverPreparationFailureHeader x2HoPrepFailHeader;
packet->RemoveHeader (x2HoPrepFailHeader);
NS_LOG_INFO ("X2 HandoverPreparationFailure header: " << x2HoPrepFailHeader);
EpcX2SapUser::HandoverPreparationFailureParams params;
params.oldEnbUeX2apId = x2HoPrepFailHeader.GetOldEnbUeX2apId ();
params.sourceCellId = cellsInfo->m_localCellId;
params.targetCellId = cellsInfo->m_remoteCellId;
params.cause = x2HoPrepFailHeader.GetCause ();
params.criticalityDiagnostics = x2HoPrepFailHeader.GetCriticalityDiagnostics ();
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("cause = " << params.cause);
NS_LOG_LOGIC ("criticalityDiagnostics = " << params.criticalityDiagnostics);
m_x2SapUser->RecvHandoverPreparationFailure (params);
}
}
else if (procedureCode == EpcX2Header::LoadIndication)
{
if (messageType == EpcX2Header::InitiatingMessage)
{
NS_LOG_LOGIC ("Recv X2 message: LOAD INFORMATION");
EpcX2LoadInformationHeader x2LoadInfoHeader;
packet->RemoveHeader (x2LoadInfoHeader);
NS_LOG_INFO ("X2 LoadInformation header: " << x2LoadInfoHeader);
EpcX2SapUser::LoadInformationParams params;
params.cellInformationList = x2LoadInfoHeader.GetCellInformationList ();
NS_LOG_LOGIC ("cellInformationList size = " << params.cellInformationList.size ());
m_x2SapUser->RecvLoadInformation (params);
}
}
else if (procedureCode == EpcX2Header::SnStatusTransfer)
{
if (messageType == EpcX2Header::InitiatingMessage)
{
NS_LOG_LOGIC ("Recv X2 message: SN STATUS TRANSFER");
EpcX2SnStatusTransferHeader x2SnStatusXferHeader;
packet->RemoveHeader (x2SnStatusXferHeader);
NS_LOG_INFO ("X2 SnStatusTransfer header: " << x2SnStatusXferHeader);
EpcX2SapUser::SnStatusTransferParams params;
params.oldEnbUeX2apId = x2SnStatusXferHeader.GetOldEnbUeX2apId ();
params.newEnbUeX2apId = x2SnStatusXferHeader.GetNewEnbUeX2apId ();
params.sourceCellId = cellsInfo->m_remoteCellId;
params.targetCellId = cellsInfo->m_localCellId;
params.erabsSubjectToStatusTransferList = x2SnStatusXferHeader.GetErabsSubjectToStatusTransferList ();
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("erabsList size = " << params.erabsSubjectToStatusTransferList.size ());
m_x2SapUser->RecvSnStatusTransfer (params);
}
}
else if (procedureCode == EpcX2Header::UeContextRelease)
{
if (messageType == EpcX2Header::InitiatingMessage)
{
NS_LOG_LOGIC ("Recv X2 message: UE CONTEXT RELEASE");
EpcX2UeContextReleaseHeader x2UeCtxReleaseHeader;
packet->RemoveHeader (x2UeCtxReleaseHeader);
NS_LOG_INFO ("X2 UeContextRelease header: " << x2UeCtxReleaseHeader);
EpcX2SapUser::UeContextReleaseParams params;
params.oldEnbUeX2apId = x2UeCtxReleaseHeader.GetOldEnbUeX2apId ();
params.newEnbUeX2apId = x2UeCtxReleaseHeader.GetNewEnbUeX2apId ();
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
m_x2SapUser->RecvUeContextRelease (params);
}
}
else if (procedureCode == EpcX2Header::ResourceStatusReporting)
{
if (messageType == EpcX2Header::InitiatingMessage)
{
NS_LOG_LOGIC ("Recv X2 message: RESOURCE STATUS UPDATE");
EpcX2ResourceStatusUpdateHeader x2ResStatUpdHeader;
packet->RemoveHeader (x2ResStatUpdHeader);
NS_LOG_INFO ("X2 ResourceStatusUpdate header: " << x2ResStatUpdHeader);
EpcX2SapUser::ResourceStatusUpdateParams params;
params.targetCellId = 0;
params.enb1MeasurementId = x2ResStatUpdHeader.GetEnb1MeasurementId ();
params.enb2MeasurementId = x2ResStatUpdHeader.GetEnb2MeasurementId ();
params.cellMeasurementResultList = x2ResStatUpdHeader.GetCellMeasurementResultList ();
NS_LOG_LOGIC ("enb1MeasurementId = " << params.enb1MeasurementId);
NS_LOG_LOGIC ("enb2MeasurementId = " << params.enb2MeasurementId);
NS_LOG_LOGIC ("cellMeasurementResultList size = " << params.cellMeasurementResultList.size ());
m_x2SapUser->RecvResourceStatusUpdate (params);
}
}
else
{
NS_ASSERT_MSG (false, "ProcedureCode NOT SUPPORTED!!!");
}
}
void
EpcX2::RecvFromX2uSocket (Ptr<Socket> socket)
{
NS_LOG_FUNCTION (this << socket);
NS_LOG_LOGIC ("Recv UE DATA through X2-U interface from Socket");
Ptr<Packet> packet = socket->Recv ();
NS_LOG_LOGIC ("packetLen = " << packet->GetSize ());
NS_ASSERT_MSG (m_x2InterfaceCellIds.find (socket) != m_x2InterfaceCellIds.end (),
"Missing infos of local and remote CellId");
Ptr<X2CellInfo> cellsInfo = m_x2InterfaceCellIds [socket];
GtpuHeader gtpu;
packet->RemoveHeader (gtpu);
NS_LOG_LOGIC ("GTP-U header: " << gtpu);
EpcX2SapUser::UeDataParams params;
params.sourceCellId = cellsInfo->m_remoteCellId;
params.targetCellId = cellsInfo->m_localCellId;
params.gtpTeid = gtpu.GetTeid ();
params.ueData = packet;
m_x2SapUser->RecvUeData (params);
}
//
// Implementation of the X2 SAP Provider
//
void
EpcX2::DoSendHandoverRequest (EpcX2SapProvider::HandoverRequestParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("mmeUeS1apId = " << params.mmeUeS1apId);
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.targetCellId) != m_x2InterfaceSockets.end (),
"Missing infos for targetCellId = " << params.targetCellId);
Ptr<X2IfaceInfo> socketInfo = m_x2InterfaceSockets [params.targetCellId];
Ptr<Socket> sourceSocket = socketInfo->m_localCtrlPlaneSocket;
Ipv4Address targetIpAddr = socketInfo->m_remoteIpAddr;
NS_LOG_LOGIC ("sourceSocket = " << sourceSocket);
NS_LOG_LOGIC ("targetIpAddr = " << targetIpAddr);
NS_LOG_INFO ("Send X2 message: HANDOVER REQUEST");
// Build the X2 message
EpcX2HandoverRequestHeader x2HoReqHeader;
x2HoReqHeader.SetOldEnbUeX2apId (params.oldEnbUeX2apId);
x2HoReqHeader.SetCause (params.cause);
x2HoReqHeader.SetTargetCellId (params.targetCellId);
x2HoReqHeader.SetMmeUeS1apId (params.mmeUeS1apId);
x2HoReqHeader.SetUeAggregateMaxBitRateDownlink (params.ueAggregateMaxBitRateDownlink);
x2HoReqHeader.SetUeAggregateMaxBitRateUplink (params.ueAggregateMaxBitRateUplink);
x2HoReqHeader.SetBearers (params.bearers);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::InitiatingMessage);
x2Header.SetProcedureCode (EpcX2Header::HandoverPreparation);
x2Header.SetLengthOfIes (x2HoReqHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2HoReqHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 HandoverRequest header: " << x2HoReqHeader);
// Build the X2 packet
Ptr<Packet> packet = (params.rrcContext != 0) ? (params.rrcContext) : (Create <Packet> ());
packet->AddHeader (x2HoReqHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
sourceSocket->SendTo (packet, 0, InetSocketAddress (targetIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendHandoverRequestAck (EpcX2SapProvider::HandoverRequestAckParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.sourceCellId) != m_x2InterfaceSockets.end (),
"Socket infos not defined for sourceCellId = " << params.sourceCellId);
Ptr<Socket> localSocket = m_x2InterfaceSockets [params.sourceCellId]->m_localCtrlPlaneSocket;
Ipv4Address remoteIpAddr = m_x2InterfaceSockets [params.sourceCellId]->m_remoteIpAddr;
NS_LOG_LOGIC ("localSocket = " << localSocket);
NS_LOG_LOGIC ("remoteIpAddr = " << remoteIpAddr);
NS_LOG_INFO ("Send X2 message: HANDOVER REQUEST ACK");
// Build the X2 message
EpcX2HandoverRequestAckHeader x2HoAckHeader;
x2HoAckHeader.SetOldEnbUeX2apId (params.oldEnbUeX2apId);
x2HoAckHeader.SetNewEnbUeX2apId (params.newEnbUeX2apId);
x2HoAckHeader.SetAdmittedBearers (params.admittedBearers);
x2HoAckHeader.SetNotAdmittedBearers (params.notAdmittedBearers);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::SuccessfulOutcome);
x2Header.SetProcedureCode (EpcX2Header::HandoverPreparation);
x2Header.SetLengthOfIes (x2HoAckHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2HoAckHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 HandoverAck header: " << x2HoAckHeader);
NS_LOG_INFO ("RRC context: " << params.rrcContext);
// Build the X2 packet
Ptr<Packet> packet = (params.rrcContext != 0) ? (params.rrcContext) : (Create <Packet> ());
packet->AddHeader (x2HoAckHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
localSocket->SendTo (packet, 0, InetSocketAddress (remoteIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendHandoverPreparationFailure (EpcX2SapProvider::HandoverPreparationFailureParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("cause = " << params.cause);
NS_LOG_LOGIC ("criticalityDiagnostics = " << params.criticalityDiagnostics);
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.sourceCellId) != m_x2InterfaceSockets.end (),
"Socket infos not defined for sourceCellId = " << params.sourceCellId);
Ptr<Socket> localSocket = m_x2InterfaceSockets [params.sourceCellId]->m_localCtrlPlaneSocket;
Ipv4Address remoteIpAddr = m_x2InterfaceSockets [params.sourceCellId]->m_remoteIpAddr;
NS_LOG_LOGIC ("localSocket = " << localSocket);
NS_LOG_LOGIC ("remoteIpAddr = " << remoteIpAddr);
NS_LOG_INFO ("Send X2 message: HANDOVER PREPARATION FAILURE");
// Build the X2 message
EpcX2HandoverPreparationFailureHeader x2HoPrepFailHeader;
x2HoPrepFailHeader.SetOldEnbUeX2apId (params.oldEnbUeX2apId);
x2HoPrepFailHeader.SetCause (params.cause);
x2HoPrepFailHeader.SetCriticalityDiagnostics (params.criticalityDiagnostics);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::UnsuccessfulOutcome);
x2Header.SetProcedureCode (EpcX2Header::HandoverPreparation);
x2Header.SetLengthOfIes (x2HoPrepFailHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2HoPrepFailHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 HandoverPrepFail header: " << x2HoPrepFailHeader);
// Build the X2 packet
Ptr<Packet> packet = Create <Packet> ();
packet->AddHeader (x2HoPrepFailHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
localSocket->SendTo (packet, 0, InetSocketAddress (remoteIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendSnStatusTransfer (EpcX2SapProvider::SnStatusTransferParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("erabsList size = " << params.erabsSubjectToStatusTransferList.size ());
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.targetCellId) != m_x2InterfaceSockets.end (),
"Socket infos not defined for targetCellId = " << params.targetCellId);
Ptr<Socket> localSocket = m_x2InterfaceSockets [params.targetCellId]->m_localCtrlPlaneSocket;
Ipv4Address remoteIpAddr = m_x2InterfaceSockets [params.targetCellId]->m_remoteIpAddr;
NS_LOG_LOGIC ("localSocket = " << localSocket);
NS_LOG_LOGIC ("remoteIpAddr = " << remoteIpAddr);
NS_LOG_INFO ("Send X2 message: SN STATUS TRANSFER");
// Build the X2 message
EpcX2SnStatusTransferHeader x2SnStatusXferHeader;
x2SnStatusXferHeader.SetOldEnbUeX2apId (params.oldEnbUeX2apId);
x2SnStatusXferHeader.SetNewEnbUeX2apId (params.newEnbUeX2apId);
x2SnStatusXferHeader.SetErabsSubjectToStatusTransferList (params.erabsSubjectToStatusTransferList);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::InitiatingMessage);
x2Header.SetProcedureCode (EpcX2Header::SnStatusTransfer);
x2Header.SetLengthOfIes (x2SnStatusXferHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2SnStatusXferHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 SnStatusTransfer header: " << x2SnStatusXferHeader);
// Build the X2 packet
Ptr<Packet> packet = Create <Packet> ();
packet->AddHeader (x2SnStatusXferHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
localSocket->SendTo (packet, 0, InetSocketAddress (remoteIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendUeContextRelease (EpcX2SapProvider::UeContextReleaseParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("oldEnbUeX2apId = " << params.oldEnbUeX2apId);
NS_LOG_LOGIC ("newEnbUeX2apId = " << params.newEnbUeX2apId);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.sourceCellId) != m_x2InterfaceSockets.end (),
"Socket infos not defined for sourceCellId = " << params.sourceCellId);
Ptr<Socket> localSocket = m_x2InterfaceSockets [params.sourceCellId]->m_localCtrlPlaneSocket;
Ipv4Address remoteIpAddr = m_x2InterfaceSockets [params.sourceCellId]->m_remoteIpAddr;
NS_LOG_LOGIC ("localSocket = " << localSocket);
NS_LOG_LOGIC ("remoteIpAddr = " << remoteIpAddr);
NS_LOG_INFO ("Send X2 message: UE CONTEXT RELEASE");
// Build the X2 message
EpcX2UeContextReleaseHeader x2UeCtxReleaseHeader;
x2UeCtxReleaseHeader.SetOldEnbUeX2apId (params.oldEnbUeX2apId);
x2UeCtxReleaseHeader.SetNewEnbUeX2apId (params.newEnbUeX2apId);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::InitiatingMessage);
x2Header.SetProcedureCode (EpcX2Header::UeContextRelease);
x2Header.SetLengthOfIes (x2UeCtxReleaseHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2UeCtxReleaseHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 UeContextRelease header: " << x2UeCtxReleaseHeader);
// Build the X2 packet
Ptr<Packet> packet = Create <Packet> ();
packet->AddHeader (x2UeCtxReleaseHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
localSocket->SendTo (packet, 0, InetSocketAddress (remoteIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendLoadInformation (EpcX2SapProvider::LoadInformationParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("cellInformationList size = " << params.cellInformationList.size ());
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.targetCellId) != m_x2InterfaceSockets.end (),
"Missing infos for targetCellId = " << params.targetCellId);
Ptr<X2IfaceInfo> socketInfo = m_x2InterfaceSockets [params.targetCellId];
Ptr<Socket> sourceSocket = socketInfo->m_localCtrlPlaneSocket;
Ipv4Address targetIpAddr = socketInfo->m_remoteIpAddr;
NS_LOG_LOGIC ("sourceSocket = " << sourceSocket);
NS_LOG_LOGIC ("targetIpAddr = " << targetIpAddr);
NS_LOG_INFO ("Send X2 message: LOAD INFORMATION");
// Build the X2 message
EpcX2LoadInformationHeader x2LoadInfoHeader;
x2LoadInfoHeader.SetCellInformationList (params.cellInformationList);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::InitiatingMessage);
x2Header.SetProcedureCode (EpcX2Header::LoadIndication);
x2Header.SetLengthOfIes (x2LoadInfoHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2LoadInfoHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 LoadInformation header: " << x2LoadInfoHeader);
// Build the X2 packet
Ptr<Packet> packet = Create <Packet> ();
packet->AddHeader (x2LoadInfoHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
sourceSocket->SendTo (packet, 0, InetSocketAddress (targetIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendResourceStatusUpdate (EpcX2SapProvider::ResourceStatusUpdateParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("enb1MeasurementId = " << params.enb1MeasurementId);
NS_LOG_LOGIC ("enb2MeasurementId = " << params.enb2MeasurementId);
NS_LOG_LOGIC ("cellMeasurementResultList size = " << params.cellMeasurementResultList.size ());
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.targetCellId) != m_x2InterfaceSockets.end (),
"Missing infos for targetCellId = " << params.targetCellId);
Ptr<X2IfaceInfo> socketInfo = m_x2InterfaceSockets [params.targetCellId];
Ptr<Socket> sourceSocket = socketInfo->m_localCtrlPlaneSocket;
Ipv4Address targetIpAddr = socketInfo->m_remoteIpAddr;
NS_LOG_LOGIC ("sourceSocket = " << sourceSocket);
NS_LOG_LOGIC ("targetIpAddr = " << targetIpAddr);
NS_LOG_INFO ("Send X2 message: RESOURCE STATUS UPDATE");
// Build the X2 message
EpcX2ResourceStatusUpdateHeader x2ResourceStatUpdHeader;
x2ResourceStatUpdHeader.SetEnb1MeasurementId (params.enb1MeasurementId);
x2ResourceStatUpdHeader.SetEnb2MeasurementId (params.enb2MeasurementId);
x2ResourceStatUpdHeader.SetCellMeasurementResultList (params.cellMeasurementResultList);
EpcX2Header x2Header;
x2Header.SetMessageType (EpcX2Header::InitiatingMessage);
x2Header.SetProcedureCode (EpcX2Header::ResourceStatusReporting);
x2Header.SetLengthOfIes (x2ResourceStatUpdHeader.GetLengthOfIes ());
x2Header.SetNumberOfIes (x2ResourceStatUpdHeader.GetNumberOfIes ());
NS_LOG_INFO ("X2 header: " << x2Header);
NS_LOG_INFO ("X2 ResourceStatusUpdate header: " << x2ResourceStatUpdHeader);
// Build the X2 packet
Ptr<Packet> packet = Create <Packet> ();
packet->AddHeader (x2ResourceStatUpdHeader);
packet->AddHeader (x2Header);
NS_LOG_INFO ("packetLen = " << packet->GetSize ());
// Send the X2 message through the socket
sourceSocket->SendTo (packet, 0, InetSocketAddress (targetIpAddr, m_x2cUdpPort));
}
void
EpcX2::DoSendUeData (EpcX2SapProvider::UeDataParams params)
{
NS_LOG_FUNCTION (this);
NS_LOG_LOGIC ("sourceCellId = " << params.sourceCellId);
NS_LOG_LOGIC ("targetCellId = " << params.targetCellId);
NS_LOG_LOGIC ("gtpTeid = " << params.gtpTeid);
NS_ASSERT_MSG (m_x2InterfaceSockets.find (params.targetCellId) != m_x2InterfaceSockets.end (),
"Missing infos for targetCellId = " << params.targetCellId);
Ptr<X2IfaceInfo> socketInfo = m_x2InterfaceSockets [params.targetCellId];
Ptr<Socket> sourceSocket = socketInfo->m_localUserPlaneSocket;
Ipv4Address targetIpAddr = socketInfo->m_remoteIpAddr;
NS_LOG_LOGIC ("sourceSocket = " << sourceSocket);
NS_LOG_LOGIC ("targetIpAddr = " << targetIpAddr);
GtpuHeader gtpu;
gtpu.SetTeid (params.gtpTeid);
gtpu.SetLength (params.ueData->GetSize () + gtpu.GetSerializedSize () - 8); /// \todo This should be done in GtpuHeader
NS_LOG_INFO ("GTP-U header: " << gtpu);
Ptr<Packet> packet = params.ueData;
packet->AddHeader (gtpu);
NS_LOG_INFO ("Forward UE DATA through X2 interface");
sourceSocket->SendTo (packet, 0, InetSocketAddress (targetIpAddr, m_x2uUdpPort));
}
} // namespace ns3