Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) {
return &ranUe, nil
}

func (ran *AmfRan) NewRanUeFromAmfUeNgapID(amfUeNgapID int64) (*RanUe, error) {
ranUe := RanUe{}
self := GetSelf()
ranUe.AmfUeNgapId = amfUeNgapID
ranUe.RanUeNgapId = RanUeNgapIdUnspecified
ranUe.Ran = ran
ranUe.Log = ran.Log
ranUe.HoldingAmfUe = nil
ranUe.UpdateLogFields()
self.RanUePool.Store(ranUe.AmfUeNgapId, &ranUe)
ranUe.Log.Infof("New RanUe [RanUeNgapID:%d][AmfUeNgapID:%d]", ranUe.RanUeNgapId, ranUe.AmfUeNgapId)
return &ranUe, nil
}

func (ran *AmfRan) RemoveAllRanUe(removeAmfUe bool) {
// Using revered removal since ranUe.Remove() will also modify the slice r.RanUeList
ran.RanUeList.Range(func(k, v interface{}) bool {
Expand Down
19 changes: 17 additions & 2 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,24 @@ func (context *AMFContext) AmfUeFindByPolicyAssociationID(polAssoId string) (*Am
return ue, ok
}

func (context *AMFContext) RanUeFindByAmfUeNgapID(amfUeNgapID int64) *RanUe {
func (context *AMFContext) RanUeFindSourceByAmfUeNgapID(amfUeNgapID int64) *RanUe {
if value, ok := context.RanUePool.Load(amfUeNgapID); ok {
return value.(*RanUe)
r := value.(*RanUe)
if r.SourceUe != nil {
return r.SourceUe
}
return r
}
return nil
}

func (context *AMFContext) RanUeFindTargetByAmfUeNgapID(amfUeNgapID int64) *RanUe {
if value, ok := context.RanUePool.Load(amfUeNgapID); ok {
r := value.(*RanUe)
if r.TargetUe != nil {
return r.TargetUe
}
return r
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions internal/ngap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func handleUEContextReleaseCompleteMain(ran *context.AmfRan,
case context.UeContextReleaseHandover:
ran.Log.Infof("Release UE[%s] Context : Release for Handover", amfUe.Supi)
// TODO: it's a workaround, need to fix it.
targetRanUe := context.GetSelf().RanUeFindByAmfUeNgapID(ranUe.TargetUe.AmfUeNgapId)
targetRanUe := context.GetSelf().RanUeFindTargetByAmfUeNgapID(ranUe.TargetUe.AmfUeNgapId)

context.DetachSourceUeTargetUe(ranUe)
err := ranUe.Remove()
Expand Down Expand Up @@ -1227,7 +1227,7 @@ func handlePathSwitchRequestMain(ran *context.AmfRan,
pduSessionResourceToBeSwitchedInDLList *ngapType.PDUSessionResourceToBeSwitchedDLList,
pduSessionResourceFailedToSetupList *ngapType.PDUSessionResourceFailedToSetupListPSReq,
) {
ranUe := context.GetSelf().RanUeFindByAmfUeNgapID(sourceAMFUENGAPID.Value)
ranUe := context.GetSelf().RanUeFindSourceByAmfUeNgapID(sourceAMFUENGAPID.Value)
if ranUe == nil {
ran.Log.Errorf("Cannot find UE from sourceAMfUeNgapID[%d]", sourceAMFUENGAPID.Value)
ngap_message.SendPathSwitchRequestFailure(ran, sourceAMFUENGAPID.Value, rANUENGAPID.Value, nil, nil)
Expand Down Expand Up @@ -1946,7 +1946,7 @@ func handleErrorIndicationMain(ran *context.AmfRan,
// > AP ID as either the local or remote identifier.
// So we think that these Cause codes that represent incorrect AP ID(s) need to trigger local release.
if aMFUENGAPID != nil {
ranUe := context.GetSelf().RanUeFindByAmfUeNgapID(aMFUENGAPID.Value)
ranUe := context.GetSelf().RanUeFindTargetByAmfUeNgapID(aMFUENGAPID.Value)
if ranUe != nil && ranUe.Ran == ran {
removeRanUeByInvalidId(ran, ranUe, fmt.Sprintf("ErrorIndication (AmfUeNgapID: %d)", aMFUENGAPID.Value))
}
Expand Down Expand Up @@ -2142,7 +2142,7 @@ func removeRanUeByInvalidId(ran *context.AmfRan, ranUe *context.RanUe, reason st
// > having the erroneous AP ID as either the local or remote identifier.
func removeRanUeByInvalidUE(ran *context.AmfRan, aMFUENGAPID *ngapType.AMFUENGAPID, rANUENGAPID *ngapType.RANUENGAPID) {
if aMFUENGAPID != nil {
ranUe := context.GetSelf().RanUeFindByAmfUeNgapID(aMFUENGAPID.Value)
ranUe := context.GetSelf().RanUeFindTargetByAmfUeNgapID(aMFUENGAPID.Value)
if ranUe != nil && ranUe.Ran == ran {
removeRanUeByInvalidId(ran, ranUe, fmt.Sprintf("Invalid UE ID (AmfUeNgapID: %d)", aMFUENGAPID.Value))
}
Expand Down Expand Up @@ -2175,7 +2175,7 @@ func ranUeFind(ran *context.AmfRan,
rANUENGAPID_string = fmt.Sprintf("%d", rANUENGAPID.Value)
}

ranUe = context.GetSelf().RanUeFindByAmfUeNgapID(aMFUENGAPID.Value)
ranUe = context.GetSelf().RanUeFindTargetByAmfUeNgapID(aMFUENGAPID.Value)
if ranUe == nil {
cause := &ngapType.Cause{
Present: ngapType.CausePresentRadioNetwork,
Expand Down
2 changes: 1 addition & 1 deletion internal/ngap/message/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ func SendHandoverRequest(sourceUe *context.RanUe, targetRan *context.AmfRan, cau
}

var targetUe *context.RanUe
if targetUeTmp, err := targetRan.NewRanUe(context.RanUeNgapIdUnspecified); err != nil {
if targetUeTmp, err := targetRan.NewRanUeFromAmfUeNgapID(sourceUe.AmfUeNgapId); err != nil {
sourceUe.Log.Errorf("Create target UE error: %+v", err)
} else {
targetUe = targetUeTmp
Expand Down
Loading