forked from free5gc/amf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.go
More file actions
1353 lines (1150 loc) · 46.1 KB
/
Copy pathsend.go
File metadata and controls
1353 lines (1150 loc) · 46.1 KB
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
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package message
import (
"time"
"github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/internal/logger"
business_metrics "github.com/free5gc/amf/internal/metrics/business"
callback "github.com/free5gc/amf/internal/sbi/processor/notifier"
"github.com/free5gc/aper"
"github.com/free5gc/ngap/ngapType"
"github.com/free5gc/openapi/models"
ngap_metrics "github.com/free5gc/util/metrics/ngap"
"github.com/free5gc/util/metrics/utils"
)
var emptyCause = ngapType.Cause{Present: 0}
func SendToRan(ran *context.AmfRan, packet []byte) (bool, string) {
defer func() {
// This is workaround.
// TODO: Handle ran.Conn close event correctly
err := recover()
if err != nil {
logger.NgapLog.Warnf("Send error, gNB may have been lost: %+v", err)
}
}()
if ran == nil {
logger.NgapLog.Error("Ran is nil")
return false, ngap_metrics.RAN_NIL_ERR
}
if len(packet) == 0 {
ran.Log.Error("packet len is 0")
return false, "packet len is 0"
}
if ran.Conn == nil {
ran.Log.Error("Ran conn is nil")
return false, "Ran conn is nil"
}
if ran.Conn.RemoteAddr() == nil {
ran.Log.Error("Ran addr is nil")
return false, "Ran addr is nil"
}
ran.Log.Debugf("Send NGAP message To Ran")
if n, err := ran.Conn.Write(packet); err != nil {
ran.Log.Errorf("Send error: %+v", err)
return false, ngap_metrics.SCTP_SOCKET_WRITE_ERR
} else {
ran.Log.Debugf("Write %d bytes", n)
}
return true, ""
}
func SendToRanUe(ue *context.RanUe, packet []byte) (bool, string) {
var ran *context.AmfRan
if ue == nil {
logger.NgapLog.Error("RanUe is nil")
return false, ngap_metrics.RAN_UE_NIL_ERR
}
if ran = ue.Ran; ran == nil {
logger.NgapLog.Error("Ran is nil")
return false, ngap_metrics.RAN_NIL_ERR
}
if ue.AmfUe == nil {
ue.Log.Warn("AmfUe is nil")
}
return SendToRan(ran, packet)
}
func NasSendToRan(ue *context.AmfUe, accessType models.AccessType, packet []byte) (bool, string) {
if ue == nil {
logger.NgapLog.Error("AmfUe is nil")
return false, ngap_metrics.AMF_UE_NIL_ERR
}
ranUe := ue.RanUe[accessType]
if ranUe == nil {
logger.NgapLog.Error("RanUe is nil")
return false, ngap_metrics.RAN_UE_NIL_ERR
}
return SendToRanUe(ranUe, packet)
}
func SendNGSetupResponse(ran *context.AmfRan, criticalityDiagnostics *ngapType.CriticalityDiagnostics) {
isNGSetupRespSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.NG_SETUP_RESPONSE, &isNGSetupRespSent, emptyCause, &additionalCause)
ran.Log.Info("Send NG-Setup response")
pkt, err := BuildNGSetupResponse(criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build NGSetupResponse failed : %s", err.Error())
return
}
isNGSetupRespSent, additionalCause = SendToRan(ran, pkt)
}
func SendNGSetupFailure(
ran *context.AmfRan,
cause ngapType.Cause,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isNGSetupFailSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.NG_SETUP_FAILURE, &isNGSetupFailSent, cause, &additionalCause)
ran.Log.Info("Send NG-Setup failure")
if cause.Present == ngapType.CausePresentNothing {
additionalCause = ngap_metrics.CAUSE_NIL_ERR
ran.Log.Errorf("Cause present is nil")
return
}
pkt, err := BuildNGSetupFailure(cause, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build NGSetupFailure failed : %s", err.Error())
return
}
isNGSetupFailSent, additionalCause = SendToRan(ran, pkt)
}
// partOfNGInterface: if reset type is "reset all", set it to nil TS 38.413 9.2.6.11
func SendNGReset(ran *context.AmfRan, cause ngapType.Cause,
partOfNGInterface *ngapType.UEAssociatedLogicalNGConnectionList,
) {
isNGResetSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.NG_RESET, &isNGResetSent, cause, &additionalCause)
ran.Log.Info("Send NG Reset")
pkt, err := BuildNGReset(cause, partOfNGInterface)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build NGReset failed : %s", err.Error())
return
}
isNGResetSent, additionalCause = SendToRan(ran, pkt)
}
func SendNGResetAcknowledge(ran *context.AmfRan, partOfNGInterface *ngapType.UEAssociatedLogicalNGConnectionList,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isNGResetAckSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.NG_RESET_ACKNOWLEDGE, &isNGResetAckSent, emptyCause, &additionalCause)
ran.Log.Info("Send NG Reset Acknowledge")
if partOfNGInterface != nil && len(partOfNGInterface.List) == 0 {
additionalCause = "length of partOfNGInterface is 0"
ran.Log.Error("length of partOfNGInterface is 0")
return
}
pkt, err := BuildNGResetAcknowledge(partOfNGInterface, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build NGResetAcknowledge failed : %s", err.Error())
return
}
isNGResetAckSent, additionalCause = SendToRan(ran, pkt)
}
func SendDownlinkNasTransport(ue *context.RanUe, nasPdu []byte,
mobilityRestrictionList *ngapType.MobilityRestrictionList,
) {
isDLNASTransportSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.DOWNLINK_NAS_TRANSPORT, &isDLNASTransportSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send Downlink Nas Transport")
if len(nasPdu) == 0 {
ue.Log.Errorf("Send DownlinkNasTransport Error: nasPdu is nil")
}
pkt, err := BuildDownlinkNasTransport(ue, nasPdu, mobilityRestrictionList)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build DownlinkNasTransport failed : %s", err.Error())
return
}
isDLNASTransportSent, additionalCause = SendToRanUe(ue, pkt)
}
func SendPDUSessionResourceReleaseCommand(ue *context.RanUe, nasPdu []byte,
pduSessionResourceReleasedList ngapType.PDUSessionResourceToReleaseListRelCmd,
) {
isPDUSessResRelCmdSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PDUSESSION_RESOURCE_RELEASE_COMMAND, &isPDUSessResRelCmdSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send PDU Session Resource Release Command")
pkt, err := BuildPDUSessionResourceReleaseCommand(ue, nasPdu, pduSessionResourceReleasedList)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build PDUSessionResourceReleaseCommand failed : %s", err.Error())
return
}
isPDUSessResRelCmdSent, additionalCause = SendToRanUe(ue, pkt)
}
func SendUEContextReleaseCommand(ue *context.RanUe, action context.RelAction, causePresent int, cause aper.Enumerated) {
isUECtxReleaseCmd := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.UE_CONTEXT_RELEASE_COMMAND, &isUECtxReleaseCmd, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send UE Context Release Command")
pkt, err := BuildUEContextReleaseCommand(ue, causePresent, cause)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build UEContextReleaseCommand failed : %s", err.Error())
return
}
ue.ReleaseAction = action
if ue.AmfUe != nil && ue.Ran != nil {
ue.AmfUe.ReleaseCause[ue.Ran.AnType] = &context.CauseAll{
NgapCause: &models.NgApCause{
Group: int32(causePresent),
Value: int32(cause),
},
}
}
ue.InitialContextSetup = false
isUECtxReleaseCmd, additionalCause = SendToRanUe(ue, pkt)
}
func SendErrorIndication(ran *context.AmfRan, amfUeNgapId *ngapType.AMFUENGAPID, ranUeNgapId *ngapType.RANUENGAPID,
cause *ngapType.Cause, criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isErrorIndicationSent := false
additionalCause := ""
if cause == nil {
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.ERROR_INDICATION, &isErrorIndicationSent,
emptyCause, &additionalCause)
} else {
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.ERROR_INDICATION, &isErrorIndicationSent, *cause,
&additionalCause)
}
if ran == nil {
additionalCause = ngap_metrics.RAN_NIL_ERR
logger.NgapLog.Error("Ran is nil")
return
}
ran.Log.Info("Send Error Indication")
var amfUeNgapIdValue *int64
if amfUeNgapId != nil {
amfUeNgapIdValue = &amfUeNgapId.Value
}
var ranUeNgapIdValue *int64
if ranUeNgapId != nil {
ranUeNgapIdValue = &ranUeNgapId.Value
}
pkt, err := BuildErrorIndication(amfUeNgapIdValue, ranUeNgapIdValue, cause, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build ErrorIndication failed : %s", err.Error())
return
}
isErrorIndicationSent, additionalCause = SendToRan(ran, pkt)
}
func SendUERadioCapabilityCheckRequest(ue *context.RanUe) {
isUERadioCapCheckReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.UE_RADIO_CAPABILITY_CHECK_REQUEST, &isUERadioCapCheckReqSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send UE Radio Capability Check Request")
pkt, err := BuildUERadioCapabilityCheckRequest(ue)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build UERadioCapabilityCheckRequest failed : %s", err.Error())
return
}
isUERadioCapCheckReqSent, additionalCause = SendToRanUe(ue, pkt)
}
func SendHandoverCancelAcknowledge(ue *context.RanUe, criticalityDiagnostics *ngapType.CriticalityDiagnostics) {
isHoCancelAckSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.HANDOVER_CANCEL_ACKNOWLEDGE, &isHoCancelAckSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send Handover Cancel Acknowledge")
pkt, err := BuildHandoverCancelAcknowledge(ue, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build HandoverCancelAcknowledge failed : %s", err.Error())
return
}
isHoCancelAckSent, additionalCause = SendToRanUe(ue, pkt)
}
// nasPDU: from nas layer
// pduSessionResourceSetupRequestList: provided by AMF, and transfer data is from SMF
func SendPDUSessionResourceSetupRequest(ue *context.RanUe, nasPdu []byte,
pduSessionResourceSetupRequestList *ngapType.PDUSessionResourceSetupListSUReq,
) {
isPDUSessResSetupReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PDUSESSION_RESOURCE_SETUP_REQUEST, &isPDUSessResSetupReqSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send PDU Session Resource Setup Request")
if len(pduSessionResourceSetupRequestList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ue.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildPDUSessionResourceSetupRequest(ue, nasPdu, pduSessionResourceSetupRequestList)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build PDUSessionResourceSetupRequest failed : %s", err.Error())
return
}
isPDUSessResSetupReqSent, additionalCause = SendToRanUe(ue, pkt)
}
// pduSessionResourceModifyConfirmList: provided by AMF, and transfer data is return from SMF
// pduSessionResourceFailedToModifyList: provided by AMF, and transfer data is return from SMF
func SendPDUSessionResourceModifyConfirm(
ue *context.RanUe,
pduSessionResourceModifyConfirmList ngapType.PDUSessionResourceModifyListModCfm,
pduSessionResourceFailedToModifyList ngapType.PDUSessionResourceFailedToModifyListModCfm,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isPDUSessResModifyConfirmSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PDUSESSION_RESOURCE_MODIFY_CONFIRM, &isPDUSessResModifyConfirmSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send PDU Session Resource Modify Confirm")
if len(pduSessionResourceModifyConfirmList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ue.Log.Error("Pdu List out of range")
return
}
if len(pduSessionResourceFailedToModifyList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ue.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildPDUSessionResourceModifyConfirm(ue, pduSessionResourceModifyConfirmList,
pduSessionResourceFailedToModifyList, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build PDUSessionResourceModifyConfirm failed : %s", err.Error())
return
}
isPDUSessResModifyConfirmSent, additionalCause = SendToRanUe(ue, pkt)
}
// pduSessionResourceModifyRequestList: from SMF
func SendPDUSessionResourceModifyRequest(ue *context.RanUe,
pduSessionResourceModifyRequestList ngapType.PDUSessionResourceModifyListModReq,
) {
isPDUSessResModifyReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PDUSESSION_RESOURCE_MODIFY_REQUEST, &isPDUSessResModifyReqSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send PDU Session Resource Modify Request")
if len(pduSessionResourceModifyRequestList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ue.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildPDUSessionResourceModifyRequest(ue, pduSessionResourceModifyRequestList)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build PDUSessionResourceModifyRequest failed : %s", err.Error())
return
}
isPDUSessResModifyReqSent, additionalCause = SendToRanUe(ue, pkt)
}
func SendInitialContextSetupRequest(
amfUe *context.AmfUe,
anType models.AccessType,
nasPdu []byte,
pduSessionResourceSetupRequestList *ngapType.PDUSessionResourceSetupListCxtReq,
rrcInactiveTransitionReportRequest *ngapType.RRCInactiveTransitionReportRequest,
coreNetworkAssistanceInfo *ngapType.CoreNetworkAssistanceInformation,
emergencyFallbackIndicator *ngapType.EmergencyFallbackIndicator,
) {
isInitialCtxSetupReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.INITIAL_CONTEXT_SETUP_REQUEST, &isInitialCtxSetupReqSent, emptyCause, &additionalCause)
if amfUe == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
logger.NgapLog.Error("AmfUe is nil")
return
}
amfUe.RanUe[anType].Log.Info("Send Initial Context Setup Request")
if pduSessionResourceSetupRequestList != nil {
if len(pduSessionResourceSetupRequestList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
amfUe.RanUe[anType].Log.Error("Pdu List out of range")
return
}
}
pkt, err := BuildInitialContextSetupRequest(amfUe, anType, nasPdu, pduSessionResourceSetupRequestList,
rrcInactiveTransitionReportRequest, coreNetworkAssistanceInfo, emergencyFallbackIndicator)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
amfUe.RanUe[anType].Log.Errorf("Build InitialContextSetupRequest failed : %s", err.Error())
return
}
isInitialCtxSetupReqSent, additionalCause = NasSendToRan(amfUe, anType, pkt)
}
func SendUEContextModificationRequest(
amfUe *context.AmfUe,
anType models.AccessType,
oldAmfUeNgapID *int64,
rrcInactiveTransitionReportRequest *ngapType.RRCInactiveTransitionReportRequest,
coreNetworkAssistanceInfo *ngapType.CoreNetworkAssistanceInformation,
mobilityRestrictionList *ngapType.MobilityRestrictionList,
emergencyFallbackIndicator *ngapType.EmergencyFallbackIndicator,
) {
isUeCtxModifReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.UE_CONTEXT_MODIFICATION_REQUEST, &isUeCtxModifReqSent, emptyCause, &additionalCause)
if amfUe == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
logger.NgapLog.Error("AmfUe is nil")
return
}
amfUe.RanUe[anType].Log.Info("Send UE Context Modification Request")
pkt, err := BuildUEContextModificationRequest(amfUe, anType, oldAmfUeNgapID, rrcInactiveTransitionReportRequest,
coreNetworkAssistanceInfo, mobilityRestrictionList, emergencyFallbackIndicator)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
amfUe.RanUe[anType].Log.Errorf("Build UEContextModificationRequest failed : %s", err.Error())
return
}
isUeCtxModifReqSent, additionalCause = NasSendToRan(amfUe, anType, pkt)
}
// pduSessionResourceHandoverList: provided by amf and transfer is return from smf
// pduSessionResourceToReleaseList: provided by amf and transfer is return from smf
// criticalityDiagnostics = criticalityDiagonstics IE in receiver node's error indication
// when received node can't comprehend the IE or missing IE
func SendHandoverCommand(
sourceUe *context.RanUe,
pduSessionResourceHandoverList ngapType.PDUSessionResourceHandoverList,
pduSessionResourceToReleaseList ngapType.PDUSessionResourceToReleaseListHOCmd,
container ngapType.TargetToSourceTransparentContainer,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isHoCmdSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.HANDOVER_COMMAND, &isHoCmdSent, emptyCause, &additionalCause)
if sourceUe == nil {
additionalCause = ngap_metrics.SOURCE_UE_NIL_ERR
logger.NgapLog.Error("SourceUe is nil")
return
}
sourceUe.Log.Info("Send Handover Command")
if len(pduSessionResourceHandoverList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
sourceUe.Log.Error("Pdu List out of range")
return
}
if len(pduSessionResourceToReleaseList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
sourceUe.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildHandoverCommand(sourceUe, pduSessionResourceHandoverList, pduSessionResourceToReleaseList,
container, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
sourceUe.Log.Errorf("Build HandoverCommand failed : %s", err.Error())
return
}
isHoCmdSent, additionalCause = SendToRanUe(sourceUe, pkt)
}
// cause = initiate the Handover Cancel procedure with the appropriate value for the Cause IE.
// criticalityDiagnostics = criticalityDiagonstics IE in receiver node's error indication
// when received node can't comprehend the IE or missing IE
func SendHandoverPreparationFailure(sourceUe *context.RanUe, cause ngapType.Cause,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isHoPrepFailSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.HANDOVER_PREPARATION_FAILURE, &isHoPrepFailSent, cause, &additionalCause)
if sourceUe == nil {
additionalCause = ngap_metrics.SOURCE_UE_NIL_ERR
logger.NgapLog.Error("SourceUe is nil")
return
}
sourceUe.Log.Info("Send Handover Preparation Failure")
amfUe := sourceUe.AmfUe
if amfUe == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
sourceUe.Log.Error("amfUe is nil")
return
}
if amfUe.OnGoing(sourceUe.Ran.AnType).Procedure == context.OnGoingProcedureN2Handover {
amfUe.SetOnGoing(sourceUe.Ran.AnType, &context.OnGoing{
Procedure: context.OnGoingProcedureNothing,
})
}
pkt, err := BuildHandoverPreparationFailure(sourceUe, cause, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
sourceUe.Log.Errorf("Build HandoverPreparationFailure failed : %s", err.Error())
return
}
isHoPrepFailSent, additionalCause = SendToRanUe(sourceUe, pkt)
}
/*The PGW-C+SMF (V-SMF in the case of home-routed roaming scenario only) sends
a Nsmf_PDUSession_CreateSMContext Response(N2 SM Information (PDU Session ID, cause code)) to the AMF.*/
// Cause is from SMF
// pduSessionResourceSetupList provided by AMF, and the transfer data is from SMF
// sourceToTargetTransparentContainer is received from S-RAN
// nsci: new security context indicator, if amfUe has updated security context, set nsci to true, otherwise set to false
// N2 handover in same AMF
func SendHandoverRequest(sourceUe *context.RanUe, targetRan *context.AmfRan, cause ngapType.Cause,
pduSessionResourceSetupListHOReq ngapType.PDUSessionResourceSetupListHOReq,
sourceToTargetTransparentContainer ngapType.SourceToTargetTransparentContainer, nsci bool,
) {
isHoReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.HANDOVER_REQUEST, &isHoReqSent, cause, &additionalCause)
defer func(msgSent *bool, cause ngapType.Cause) {
hoCause := ngap_metrics.GetCauseErrorStr(&cause)
if hoCause == "unknown ngapType.Cause" {
hoCause = additionalCause
}
if msgSent != nil && !*msgSent {
business_metrics.IncrHoEventCounter(business_metrics.HANDOVER_TYPE_NGAP_VALUE,
utils.FailureMetric, hoCause, sourceUe.HandOverStartTime)
}
}(&isHoReqSent, cause)
if sourceUe == nil {
additionalCause = ngap_metrics.SOURCE_UE_NIL_ERR
logger.NgapLog.Error("sourceUe is nil")
return
}
sourceUe.Log.Info("Send Handover Request")
amfUe := sourceUe.AmfUe
if amfUe == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
sourceUe.Log.Error("amfUe is nil")
return
}
if targetRan == nil {
additionalCause = ngap_metrics.TARGET_RAN_NIL_ERR
sourceUe.Log.Error("targetRan is nil")
return
}
if sourceUe.TargetUe != nil {
additionalCause = ngap_metrics.HANDOVER_REQUIRED_DUP_ERR
sourceUe.Log.Error("Handover Required Duplicated")
return
}
if len(pduSessionResourceSetupListHOReq.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
sourceUe.Log.Error("Pdu List out of range")
return
}
if len(sourceToTargetTransparentContainer.Value) == 0 {
additionalCause = ngap_metrics.SRC_TO_TARGET_TRANSPARENT_CONTAINER_NIL_ERR
sourceUe.Log.Error("Source To Target TransparentContainer is nil")
return
}
var targetUe *context.RanUe
if targetUeTmp, err := targetRan.NewRanUe(context.RanUeNgapIdUnspecified); err != nil {
sourceUe.Log.Errorf("Create target UE error: %+v", err)
} else {
targetUe = targetUeTmp
}
sourceUe.Log.Tracef("Source : AMF_UE_NGAP_ID[%d], RAN_UE_NGAP_ID[%d]", sourceUe.AmfUeNgapId, sourceUe.RanUeNgapId)
// Possible nil pointer here
if targetUe != nil {
sourceUe.Log.Tracef("Target : AMF_UE_NGAP_ID[%d], RAN_UE_NGAP_ID[Unknown]", targetUe.AmfUeNgapId)
}
context.AttachSourceUeTargetUe(sourceUe, targetUe)
pkt, err := BuildHandoverRequest(targetUe, cause, pduSessionResourceSetupListHOReq,
sourceToTargetTransparentContainer, nsci)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
sourceUe.Log.Errorf("Build HandoverRequest failed : %s", err.Error())
return
}
isHoReqSent, additionalCause = SendToRanUe(targetUe, pkt)
}
// pduSessionResourceSwitchedList: provided by AMF, and the transfer data is from SMF
// pduSessionResourceReleasedList: provided by AMF, and the transfer data is from SMF
// newSecurityContextIndicator: if AMF has activated a new 5G NAS security context, set it to true,
// otherwise set to false
// coreNetworkAssistanceInformation: provided by AMF, based on collection of UE behavior statistics
// and/or other available
// information about the expected UE behavior. TS 23.501 5.4.6, 5.4.6.2
// rrcInactiveTransitionReportRequest: configured by amf
// criticalityDiagnostics: from received node when received not comprehended IE or missing IE
func SendPathSwitchRequestAcknowledge(
ue *context.RanUe,
pduSessionResourceSwitchedList ngapType.PDUSessionResourceSwitchedList,
pduSessionResourceReleasedList ngapType.PDUSessionResourceReleasedListPSAck,
newSecurityContextIndicator bool,
coreNetworkAssistanceInformation *ngapType.CoreNetworkAssistanceInformation,
rrcInactiveTransitionReportRequest *ngapType.RRCInactiveTransitionReportRequest,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
hoStartTime time.Time,
) {
isPathSwitchReqAckSent := false
business_metrics.IncrHoEventCounter(business_metrics.HANDOVER_TYPE_XN_VALUE,
utils.SuccessMetric, business_metrics.HANDOVER_EMPTY_CAUSE, hoStartTime)
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PATH_SWITCH_REQUEST_ACKNOWLEDGE, &isPathSwitchReqAckSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send Path Switch Request Acknowledge")
if len(pduSessionResourceSwitchedList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_SESS_RESOURCE_SWITCH_OOO_ERR
ue.Log.Error("Pdu Session Resource Switched List out of range")
return
}
if len(pduSessionResourceReleasedList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_SESS_RESOURCE_SWITCH_OOO_ERR
ue.Log.Error("Pdu Session Resource Released List out of range")
return
}
pkt, err := BuildPathSwitchRequestAcknowledge(ue, pduSessionResourceSwitchedList, pduSessionResourceReleasedList,
newSecurityContextIndicator, coreNetworkAssistanceInformation, rrcInactiveTransitionReportRequest,
criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build PathSwitchRequestAcknowledge failed : %s", err.Error())
return
}
isPathSwitchReqAckSent, additionalCause = SendToRanUe(ue, pkt)
}
// pduSessionResourceReleasedList: provided by AMF, and the transfer data is from SMF
// criticalityDiagnostics: from received node when received not comprehended IE or missing IE
func SendPathSwitchRequestFailure(
ran *context.AmfRan,
amfUeNgapId,
ranUeNgapId int64,
pduSessionResourceReleasedList *ngapType.PDUSessionResourceReleasedListPSFail,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
commonError string,
hoStartTime time.Time,
) {
business_metrics.IncrHoEventCounter(business_metrics.HANDOVER_TYPE_XN_VALUE, utils.FailureMetric, commonError,
hoStartTime)
isPathSwitchReqFailSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.PATH_SWITCH_REQUEST_FAILURE, &isPathSwitchReqFailSent, emptyCause, &additionalCause)
ran.Log.Info("Send Path Switch Request Failure")
if pduSessionResourceReleasedList != nil && len(pduSessionResourceReleasedList.List) > context.MaxNumOfPDUSessions {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ran.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildPathSwitchRequestFailure(amfUeNgapId, ranUeNgapId, pduSessionResourceReleasedList,
criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build PathSwitchRequestFailure failed : %s", err.Error())
return
}
isPathSwitchReqFailSent, additionalCause = SendToRan(ran, pkt)
}
// RanStatusTransferTransparentContainer from Uplink Ran Configuration Transfer
func SendDownlinkRanStatusTransfer(ue *context.RanUe, container ngapType.RANStatusTransferTransparentContainer) {
isDLRANStatusTransfertSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.DOWNLINK_RAN_STATUS_TRANSFER, &isDLRANStatusTransfertSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.RAN_UE_NIL_ERR
logger.NgapLog.Error("RanUe is nil")
return
}
ue.Log.Info("Send Downlink Ran Status Transfer")
if len(container.DRBsSubjectToStatusTransferList.List) > context.MaxNumOfDRBs {
additionalCause = ngap_metrics.PDU_LIST_OOR_ERR
ue.Log.Error("Pdu List out of range")
return
}
pkt, err := BuildDownlinkRanStatusTransfer(ue, container)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.Log.Errorf("Build DownlinkRanStatusTransfer failed : %s", err.Error())
return
}
isDLRANStatusTransfertSent, additionalCause = SendToRanUe(ue, pkt)
}
// anType indicate amfUe send this msg for which accessType
// Paging Priority: is included only if the AMF receives an Namf_Communication_N1N2MessageTransfer message
// with an ARP value associated with
// priority services (e.g., MPS, MCS), as configured by the operator. (TS 23.502 4.2.3.3, TS 23.501 5.22.3)
// pagingOriginNon3GPP: TS 23.502 4.2.3.3 step 4b: If the UE is simultaneously registered over 3GPP and non-3GPP
// accesses in the same PLMN,
// the UE is in CM-IDLE state in both 3GPP access and non-3GPP access, and the PDU Session ID in step 3a
// is associated with non-3GPP access, the AMF sends a Paging message with associated access "non-3GPP" to
// NG-RAN node(s) via 3GPP access.
// more paging policy with 3gpp/non-3gpp access is described in TS 23.501 5.6.8
func SendPaging(ue *context.AmfUe, ngapBuf []byte) {
isPagingSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(ngap_metrics.PAGING, &isPagingSent, emptyCause, &additionalCause)
// var pagingPriority *ngapType.PagingPriority
if ue == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
logger.NgapLog.Error("AmfUe is nil")
return
}
// if ppi != nil {
// pagingPriority = new(ngapType.PagingPriority)
// pagingPriority.Value = aper.Enumerated(*ppi)
// }
// pkt, err := BuildPaging(ue, pagingPriority, pagingOriginNon3GPP)
// if err != nil {
// ngaplog.Errorf("Build Paging failed : %s", err.Error())
// }
taiList := ue.RegistrationArea[models.AccessType__3_GPP_ACCESS]
context.GetSelf().AmfRanPool.Range(func(key, value interface{}) bool {
ran := value.(*context.AmfRan)
for _, item := range ran.SupportedTAList {
if context.InTaiList(item.Tai, taiList) {
ue.GmmLog.Infof("Send Paging to TAI(%+v, Tac:%+v)", item.Tai.PlmnId, item.Tai.Tac)
isPagingSent, additionalCause = SendToRan(ran, ngapBuf)
break
}
}
return true
})
if context.GetSelf().T3513Cfg.Enable {
cfg := context.GetSelf().T3513Cfg
ue.GmmLog.Infof("Start T3513 timer")
ue.T3513 = context.NewTimer(cfg.ExpireTime, cfg.MaxRetryTimes, func(expireTimes int32) {
ue.GmmLog.Warnf("T3513 expires, retransmit Paging (retry: %d)", expireTimes)
context.GetSelf().AmfRanPool.Range(func(key, value interface{}) bool {
ran := value.(*context.AmfRan)
for _, item := range ran.SupportedTAList {
if context.InTaiList(item.Tai, taiList) {
isPagingSent, additionalCause = SendToRan(ran, ngapBuf)
break
}
}
return true
})
}, func() {
ue.GmmLog.Warnf("T3513 expires %d times, abort paging procedure", cfg.MaxRetryTimes)
ue.T3513 = nil // clear the timer
if ue.OnGoing(models.AccessType__3_GPP_ACCESS).Procedure != context.OnGoingProcedureN2Handover {
callback.SendN1N2TransferFailureNotification(ue, models.N1N2MessageTransferCause_UE_NOT_RESPONDING)
}
})
}
}
// TS 23.502 4.2.2.2.3
// anType: indicate amfUe send this msg for which accessType
// amfUeNgapID: initial AMF get it from target AMF
// ngapMessage: initial UE Message to reroute
// allowedNSSAI: provided by AMF, and AMF get it from NSSF (4.2.2.2.3 step 4b)
func SendRerouteNasRequest(ue *context.AmfUe, anType models.AccessType, amfUeNgapID *int64, ngapMessage []byte,
allowedNSSAI *ngapType.AllowedNSSAI,
) {
isRerouteNasReqSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.REROUTE_NAS_REQUEST, &isRerouteNasReqSent, emptyCause, &additionalCause)
if ue == nil {
additionalCause = ngap_metrics.AMF_UE_NIL_ERR
logger.NgapLog.Error("AmfUe is nil")
return
}
ue.RanUe[anType].Log.Info("Send Reroute Nas Request")
if len(ngapMessage) == 0 {
additionalCause = ngap_metrics.NGAP_MSG_NIL_ERR
ue.RanUe[anType].Log.Error("Ngap Message is nil")
return
}
pkt, err := BuildRerouteNasRequest(ue, anType, amfUeNgapID, ngapMessage, allowedNSSAI)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ue.RanUe[anType].Log.Errorf("Build RerouteNasRequest failed : %s", err.Error())
return
}
isRerouteNasReqSent, additionalCause = NasSendToRan(ue, anType, pkt)
}
// criticality ->from received node when received node can't comprehend the IE or missing IE
func SendRanConfigurationUpdateAcknowledge(
ran *context.AmfRan, criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isRanConfigurationUpdateAckSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.RAN_CONFIGURATION_UPDATE_ACKNOWLEDGE, &isRanConfigurationUpdateAckSent, emptyCause, &additionalCause)
if ran == nil {
additionalCause = ngap_metrics.RAN_NIL_ERR
logger.NgapLog.Error("Ran is nil")
return
}
ran.Log.Info("Send Ran Configuration Update Acknowledge")
pkt, err := BuildRanConfigurationUpdateAcknowledge(criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build RanConfigurationUpdateAcknowledge failed : %s", err.Error())
return
}
isRanConfigurationUpdateAckSent, additionalCause = SendToRan(ran, pkt)
}
// criticality ->from received node when received node can't comprehend the IE or missing IE
// If the AMF cannot accept the update,
// it shall respond with a RAN CONFIGURATION UPDATE FAILURE message and appropriate cause value.
func SendRanConfigurationUpdateFailure(ran *context.AmfRan, cause ngapType.Cause,
criticalityDiagnostics *ngapType.CriticalityDiagnostics,
) {
isRanConfigurationUpdateFailSent := false
additionalCause := ""
defer ngap_metrics.IncrMetricsSentMsg(
ngap_metrics.RAN_CONFIGURATION_UPDATE_FAILURE, &isRanConfigurationUpdateFailSent, cause, &additionalCause)
if ran == nil {
additionalCause = ngap_metrics.RAN_NIL_ERR
logger.NgapLog.Error("Ran is nil")
return
}
ran.Log.Info("Send Ran Configuration Update Failure")
pkt, err := BuildRanConfigurationUpdateFailure(cause, criticalityDiagnostics)
if err != nil {
additionalCause = ngap_metrics.NGAP_MSG_BUILD_ERR
ran.Log.Errorf("Build RanConfigurationUpdateFailure failed : %s", err.Error())
return
}
isRanConfigurationUpdateFailSent, additionalCause = SendToRan(ran, pkt)
}
// An AMF shall be able to instruct other peer CP NFs, subscribed to receive such a notification,
// that it will be unavailable on this AMF and its corresponding target AMF(s).
// If CP NF does not subscribe to receive AMF unavailable notification, the CP NF may attempt
// forwarding the transaction towards the old AMF and detect that the AMF is unavailable. When
// it detects unavailable, it marks the AMF and its associated GUAMI(s) as unavailable.
// Defined in 23.501 5.21.2.2.2
func SendAMFStatusIndication(ran *context.AmfRan, unavailableGUAMIList ngapType.UnavailableGUAMIList) {