forked from free5gc/amf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_profile.go
More file actions
145 lines (131 loc) · 5.17 KB
/
Copy pathuser_profile.go
File metadata and controls
145 lines (131 loc) · 5.17 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
package common
import (
"github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/internal/logger"
business_metrics "github.com/free5gc/amf/internal/metrics/business"
ngap_message "github.com/free5gc/amf/internal/ngap/message"
"github.com/free5gc/amf/internal/sbi/consumer"
"github.com/free5gc/ngap/ngapType"
"github.com/free5gc/openapi/models"
)
func RemoveAmfUe(ue *context.AmfUe, notifyNF bool) {
if notifyNF {
// notify SMF to release all sessions
ue.SmContextList.Range(func(key, value interface{}) bool {
smContext := value.(*context.SmContext)
problemDetail, err := consumer.GetConsumer().SendReleaseSmContextRequest(ue, smContext, nil, "", nil)
if problemDetail != nil {
ue.GmmLog.Errorf("Release SmContext Failed Problem[%+v]", problemDetail)
} else if err != nil {
ue.GmmLog.Errorf("Release SmContext Error[%v]", err.Error())
}
return true
})
// notify PCF to terminate AmPolicy association
if ue.AmPolicyAssociation != nil {
problemDetails, err := consumer.GetConsumer().AMPolicyControlDelete(ue)
if problemDetails != nil {
ue.GmmLog.Errorf("AM Policy Control Delete Failed Problem[%+v]", problemDetails)
} else if err != nil {
ue.GmmLog.Errorf("AM Policy Control Delete Error[%v]", err.Error())
}
}
}
PurgeAmfUeSubscriberData(ue)
ue.Remove()
}
func PurgeAmfUeSubscriberData(ue *context.AmfUe) {
if ue.RanUe[models.AccessType__3_GPP_ACCESS] != nil {
err := PurgeSubscriberData(ue, models.AccessType__3_GPP_ACCESS)
if err != nil {
logger.GmmLog.Errorf("Purge subscriber data Error[%v]", err.Error())
}
}
if ue.RanUe[models.AccessType_NON_3_GPP_ACCESS] != nil {
err := PurgeSubscriberData(ue, models.AccessType_NON_3_GPP_ACCESS)
if err != nil {
logger.GmmLog.Errorf("Purge subscriber data Error[%v]", err.Error())
}
}
}
func AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe *context.AmfUe, ranUe *context.RanUe) {
if oldRanUe := amfUe.RanUe[ranUe.Ran.AnType]; oldRanUe != nil {
oldRanUe.Log.Infof("Implicit Deregistration - RanUeNgapID[%d]", oldRanUe.RanUeNgapId)
oldRanUe.DetachAmfUe()
if amfUe.T3550 != nil {
amfUe.State[ranUe.Ran.AnType].Set(context.Registered)
}
StopAll5GSMMTimers(amfUe)
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason
ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
} else {
// We don't increase in AttachRanUe because we don't want to fidle with the counters in a ngap handover procedure
if amfUe.AnTypeFlags[ranUe.Ran.AnType] {
business_metrics.DecrUeCmIdleStateGauge(ranUe.Ran.AnType)
}
business_metrics.IncrUeCmConnectedStateGauge(ranUe.Ran.AnType)
amfUe.AnTypeFlags[ranUe.Ran.AnType] = true
}
amfUe.AttachRanUe(ranUe)
}
func AttachRanUeToAmfUeAndReleaseOldHandover(amfUe *context.AmfUe, sourceRanUe, targetRanUe *context.RanUe) {
logger.GmmLog.Debugln("In AttachRanUeToAmfUeAndReleaseOldHandover")
if sourceRanUe != nil {
sourceRanUe.DetachAmfUe()
if amfUe.T3550 != nil {
amfUe.State[targetRanUe.Ran.AnType].Set(context.Registered)
}
StopAll5GSMMTimers(amfUe)
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentSuccessfulHandover
ngap_message.SendUEContextReleaseCommand(sourceRanUe, context.UeContextReleaseHandover, causeGroup, causeValue)
} else {
// This function will be call only by N2 Handover, so we can assume sourceRanUe will not be nil
logger.GmmLog.Errorln("AttachRanUeToAmfUeAndReleaseOldHandover() is called but sourceRanUe is nil")
}
amfUe.AttachRanUe(targetRanUe)
if sourceRanUe != nil && sourceRanUe.Ran != nil &&
amfUe.OnGoing(sourceRanUe.Ran.AnType).Procedure == context.OnGoingProcedureN2Handover {
amfUe.SetOnGoing(sourceRanUe.Ran.AnType, &context.OnGoing{
Procedure: context.OnGoingProcedureNothing,
})
}
}
func ClearHoldingRanUe(ranUe *context.RanUe) {
if ranUe != nil {
ranUe.DetachAmfUe()
ranUe.Log.Infof("Clear Holding RanUE")
causeGroup := ngapType.CausePresentRadioNetwork
causeValue := ngapType.CauseRadioNetworkPresentReleaseDueToNgranGeneratedReason
ngap_message.SendUEContextReleaseCommand(ranUe, context.UeContextReleaseUeContext, causeGroup, causeValue)
} else {
logger.GmmLog.Warnf("RanUE is nil")
}
}
func PurgeSubscriberData(ue *context.AmfUe, accessType models.AccessType) error {
logger.GmmLog.Debugln("PurgeSubscriberData")
if !ue.ContextValid {
return nil
}
// Purge of subscriber data in AMF described in TS 23.502 4.5.3
if ue.SdmSubscriptionId != "" {
problemDetails, err := consumer.GetConsumer().SDMUnsubscribe(ue)
if problemDetails != nil {
logger.GmmLog.Errorf("SDM Unubscribe Failed Problem[%+v]", problemDetails)
} else if err != nil {
logger.GmmLog.Errorf("SDM Unubscribe Error[%+v]", err)
}
ue.SdmSubscriptionId = ""
}
if ue.UeCmRegistered[accessType] {
problemDetails, err := consumer.GetConsumer().UeCmDeregistration(ue, accessType)
if problemDetails != nil {
logger.GmmLog.Errorf("UECM Deregistration Failed Problem[%+v]", problemDetails)
} else if err != nil {
logger.GmmLog.Errorf("UECM Deregistration Error[%+v]", err)
}
ue.UeCmRegistered[accessType] = false
}
return nil
}