From 30b37986d7b6741d426527ed5721ed9fb9e76233 Mon Sep 17 00:00:00 2001 From: donald1218 Date: Mon, 16 Sep 2024 11:33:46 +0000 Subject: [PATCH 1/4] fix: release twice uecontext when handover --- internal/gmm/common/user_profile.go | 14 ++++++++++++++ internal/ngap/handler.go | 4 +--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index 00b08a2..cd2cd7f 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -69,6 +69,20 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe *context.AmfUe, ranUe *context.R amfUe.AttachRanUe(ranUe) } +func AttachRanUeToAmfUeAndReleaseOldIfHandover(amfUe *context.AmfUe, ranUe *context.RanUe) { + if oldRanUe := amfUe.RanUe[ranUe.Ran.AnType]; oldRanUe != nil { + oldRanUe.DetachAmfUe() + if amfUe.T3550 != nil { + amfUe.State[ranUe.Ran.AnType].Set(context.Registered) + } + StopAll5GSMMTimers(amfUe) + causeGroup := ngapType.CausePresentNas + causeValue := ngapType.CauseNasPresentNormalRelease + ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseHandover, causeGroup, causeValue) + } + amfUe.AttachRanUe(ranUe) +} + func ClearHoldingRanUe(ranUe *context.RanUe) { if ranUe != nil { ranUe.DetachAmfUe() diff --git a/internal/ngap/handler.go b/internal/ngap/handler.go index d10116d..3924139 100644 --- a/internal/ngap/handler.go +++ b/internal/ngap/handler.go @@ -1211,10 +1211,8 @@ func handleHandoverNotifyMain(ran *context.AmfRan, ran.Log.Errorf("Send UpdateSmContextN2HandoverComplete Error[%s]", err.Error()) } } - gmm_common.AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe, targetUe) - ngap_message.SendUEContextReleaseCommand(sourceUe, context.UeContextReleaseHandover, ngapType.CausePresentNas, - ngapType.CauseNasPresentNormalRelease) + gmm_common.AttachRanUeToAmfUeAndReleaseOldIfHandover(amfUe, targetUe) } // TODO: The UE initiates Mobility Registration Update procedure as described in clause 4.2.2.2.2. From c0bb2bf8000bc3ddc964c279815fc24a3211371d Mon Sep 17 00:00:00 2001 From: donald1218 Date: Mon, 16 Sep 2024 14:41:08 +0000 Subject: [PATCH 2/4] fix: rename func and change var name --- internal/gmm/common/user_profile.go | 12 ++++++------ internal/ngap/handler.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index cd2cd7f..3e6165a 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -69,18 +69,18 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe *context.AmfUe, ranUe *context.R amfUe.AttachRanUe(ranUe) } -func AttachRanUeToAmfUeAndReleaseOldIfHandover(amfUe *context.AmfUe, ranUe *context.RanUe) { - if oldRanUe := amfUe.RanUe[ranUe.Ran.AnType]; oldRanUe != nil { - oldRanUe.DetachAmfUe() +func AttachRanUeToAmfUeAndReleaseOldHandover(amfUe *context.AmfUe, sourceRanUe, targetRanUe *context.RanUe) { + if sourceRanUe != nil { + sourceRanUe.DetachAmfUe() if amfUe.T3550 != nil { - amfUe.State[ranUe.Ran.AnType].Set(context.Registered) + amfUe.State[targetRanUe.Ran.AnType].Set(context.Registered) } StopAll5GSMMTimers(amfUe) causeGroup := ngapType.CausePresentNas causeValue := ngapType.CauseNasPresentNormalRelease - ngap_message.SendUEContextReleaseCommand(oldRanUe, context.UeContextReleaseHandover, causeGroup, causeValue) + ngap_message.SendUEContextReleaseCommand(sourceRanUe, context.UeContextReleaseHandover, causeGroup, causeValue) } - amfUe.AttachRanUe(ranUe) + amfUe.AttachRanUe(targetRanUe) } func ClearHoldingRanUe(ranUe *context.RanUe) { diff --git a/internal/ngap/handler.go b/internal/ngap/handler.go index 3924139..75025f2 100644 --- a/internal/ngap/handler.go +++ b/internal/ngap/handler.go @@ -1212,7 +1212,7 @@ func handleHandoverNotifyMain(ran *context.AmfRan, } } - gmm_common.AttachRanUeToAmfUeAndReleaseOldIfHandover(amfUe, targetUe) + gmm_common.AttachRanUeToAmfUeAndReleaseOldHandover(amfUe, sourceUe, targetUe) } // TODO: The UE initiates Mobility Registration Update procedure as described in clause 4.2.2.2.2. From cc4682b188665e5903ebb383c1bb0e2edfed8a31 Mon Sep 17 00:00:00 2001 From: "CTFang@WireLab" Date: Tue, 17 Sep 2024 13:49:43 +0000 Subject: [PATCH 3/4] fix: add comment and log --- internal/gmm/common/user_profile.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index 3e6165a..6787926 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -70,6 +70,8 @@ func AttachRanUeToAmfUeAndReleaseOldIfAny(amfUe *context.AmfUe, ranUe *context.R } func AttachRanUeToAmfUeAndReleaseOldHandover(amfUe *context.AmfUe, sourceRanUe, targetRanUe *context.RanUe) { + logger.GmmLog.Debugln("In AttachRanUeToAmfUeAndReleaseOldHandover") + if sourceRanUe != nil { sourceRanUe.DetachAmfUe() if amfUe.T3550 != nil { @@ -79,6 +81,9 @@ func AttachRanUeToAmfUeAndReleaseOldHandover(amfUe *context.AmfUe, sourceRanUe, causeGroup := ngapType.CausePresentNas causeValue := ngapType.CauseNasPresentNormalRelease 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) } From 1c21d51822d0c0a9aabfd71ea08d385787621346 Mon Sep 17 00:00:00 2001 From: donald1218 Date: Wed, 18 Sep 2024 07:51:45 +0000 Subject: [PATCH 4/4] fix: change release ue context cause --- internal/gmm/common/user_profile.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/gmm/common/user_profile.go b/internal/gmm/common/user_profile.go index 6787926..4ece2af 100644 --- a/internal/gmm/common/user_profile.go +++ b/internal/gmm/common/user_profile.go @@ -78,8 +78,8 @@ func AttachRanUeToAmfUeAndReleaseOldHandover(amfUe *context.AmfUe, sourceRanUe, amfUe.State[targetRanUe.Ran.AnType].Set(context.Registered) } StopAll5GSMMTimers(amfUe) - causeGroup := ngapType.CausePresentNas - causeValue := ngapType.CauseNasPresentNormalRelease + 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