【5G核心网】 free5gc Handover procedures切换流程源码分析

结构体 HandoverRequiredIEsValue

type HandoverRequiredIEsValue struct {
	Present                            int
	AMFUENGAPID                        *AMFUENGAPID                        `aper:"referenceFieldValue:10"`
	RANUENGAPID                        *RANUENGAPID                        `aper:"referenceFieldValue:85"`
	HandoverType                       *HandoverType                       `aper:"referenceFieldValue:29"`
	Cause                              *Cause                              `aper:"referenceFieldValue:15,valueLB:0,valueUB:5"`
	TargetID                           *TargetID                           `aper:"referenceFieldValue:105,valueLB:0,valueUB:2"`
	DirectForwardingPathAvailability   *DirectForwardingPathAvailability   `aper:"referenceFieldValue:22"`
	PDUSessionResourceListHORqd        *PDUSessionResourceListHORqd        `aper:"referenceFieldValue:61"`
	SourceToTargetTransparentContainer *SourceToTargetTransparentContainer `aper:"referenceFieldValue:101"`
}

     结构体定义根据 TS 38413 9.2.3.1 定义

IE/Group Name

Presence

Range

IE type and reference

Semantics description

Criticality

Assigned Criticality

Message Type

M

 

9.3.1.1

 

YES

reject

AMF UE NGAP ID

M

 

9.3.3.1

 

YES

reject

RAN UE NGAP ID

M

 

9.3.3.2

 

YES

reject

Handover Type

M

 

9.3.1.22

 

YES

reject

Cause

M

 

9.3.1.2

 

YES

ignore

Target ID

M

 

9.3.1.25

 

YES

reject

Direct Forwarding Path Availability

O

 

9.3.1.64

 

YES

ignore

PDU Session Resource List

 

1

 

 

YES

reject

>PDU Session Resource Item

 

1..

 

 

-

 

>>PDU Session ID

M

 

9.3.1.50

 

-

 

>>Handover Required Transfer

M

 

OCTET STRING

Containing the Handover Required Transfer IE specified in subclause 9.3.4.14.

-

 

Source to Target Transparent Container

M

 

9.3.1.20

 

YES

reject

 

1. Handover Required (S-RAN -> S-AMF)

    BuildHandoverRequired 创建 NGAP 消息,类型为 NGAPPDUPresentInitiatingMessage,ProcedureCode 设置为 ProcedureCodeHandoverPreparationInitiatingMessagePresentHandoverRequired,包括的 IE 如下:

    -  AMF UE NGAP ID

    -  RAN UE NGAP ID

    -  Handover Type  (TS 38413 9.3.1.22) Intra5GS, 5GStoEPS, EPSto5GS

    -  Cause  (TS 38413 9.3.1.2)

    -  Target ID(TS 38413 9.3.1.25) 

    -  Direct Forwarding Path Availability [optional]

    -  PDU Session Resource List

    -  Source to Target Transparent Container

   1.1 AMF 处理 Handover Required 请求

    根据目标 RAN 如果未缓存则需要(未实现),缺少 T-AMF 选择

var aMFSelf = context.AMF_Self()
targetRanNodeId := ngapConvert.RanIdToModels(targetID.TargetRANNodeID.GlobalRANNodeID)
targetRan := aMFSelf.AmfRanFindByRanId(targetRanNodeId)
if targetRan == nil {
	// handover between different AMF
	logger.NgapLog.Warnf("Handover required : cannot find target Ran Node Id[%+v] in this AMF", targetRanNodeId)
	logger.NgapLog.Error("Handover between different AMF has not been implemented yet")
	return
	// TODO: Send to T-AMF
	// Described in (23.502 4.9.1.3.2) step 3.Namf_Communication_CreateUEContext Request

}

   1.2 在同一个 AMF 切换

    如果存在 PDU 会话则更新 SMF 会话上下文,BuildUpdateSmContextRequsetHandover 实例化 SmContextUpdateData,向 SMF 发送 Nsmf_PDUSession_UpdateSMContext 请求 (/sm-contexts/{smContextRef}/modify),结构体为 SmContextUpdateData

// Handover in same AMF
sourceUe.HandOverType.Value = handoverType.Value
tai := ngapConvert.TaiToModels(targetID.TargetRANNodeID.SelectedTAI)
targetId := models.NgRanTargetId{
	RanNodeId: &targetRanNodeId,
	Tai:       &tai,
}
var pduSessionReqList ngapType.PDUSessionResourceSetupListHOReq
for _, pDUSessionResourceHoItem := range pDUSessionResourceListHORqd.List {
	pduSessionId := int32(pDUSessionResourceHoItem.PDUSessionID.Value)
	if smContext, exist := amfUe.SmContextList[pduSessionId]; exist {
		response, _, _, _ := consumer.SendUpdateSmContextN2HandoverPreparing(amfUe, pduSessionId, models.N2SmInfoType_HANDOVER_REQUIRED, pDUSessionResourceHoItem.HandoverRequiredTransfer, "", &targetId)
		if response == nil {
			logger.NgapLog.Errorf("SendUpdateSmContextN2HandoverPreparing Error for PduSessionId[%d]", pduSessionId)
			continue
		} else if response.BinaryDataN2SmInformation != nil {
			ngap_message.AppendPDUSessionResourceSetupListHOReq(&pduSessionReqList, pduSessionId, *smContext.PduSessionContext.SNssai, response.BinaryDataN2SmInformation)
		}
	}

}

 

2. SMF 处理上下文更新操作

    UpdateSmContext 函数设置消息类型为 PDUSessionSMContextUpdate,丢进队列进行处理,定位到函数 HandlePDUSessionSMContextUpdate,根据 AMF 只设置 N2 信息

    

 

你可能感兴趣的:(5G)