diff --git a/internal/context/ngap_handler.go b/internal/context/ngap_handler.go index 286f555e..81ff12e0 100644 --- a/internal/context/ngap_handler.go +++ b/internal/context/ngap_handler.go @@ -1,15 +1,12 @@ package context import ( - "bytes" "encoding/binary" "errors" - "fmt" "github.com/free5gc/aper" "github.com/free5gc/ngap/ngapType" "github.com/free5gc/openapi/models" - "github.com/free5gc/pfcp/pfcpType" "github.com/free5gc/smf/internal/logger" ) @@ -29,25 +26,11 @@ func HandlePDUSessionResourceSetupResponseTransfer(b []byte, ctx *SMContext) (er return errors.New("resourceSetupResponseTransfer.QosFlowPerTNLInformation.UPTransportLayerInformation.Present") } - gtpTunnel := QosFlowPerTNLInformation.UPTransportLayerInformation.GTPTunnel + GTPTunnel := QosFlowPerTNLInformation.UPTransportLayerInformation.GTPTunnel - teid := binary.BigEndian.Uint32(gtpTunnel.GTPTEID.Value) - - ctx.Tunnel.ANInformation.IPAddress = gtpTunnel.TransportLayerAddress.Value.Bytes - ctx.Tunnel.ANInformation.TEID = teid - - for _, dataPath := range ctx.Tunnel.DataPathPool { - if dataPath.Activated { - ANUPF := dataPath.FirstDPNode - DLPDR := ANUPF.DownLinkTunnel.PDR - - DLPDR.FAR.ForwardingParameters.OuterHeaderCreation = new(pfcpType.OuterHeaderCreation) - dlOuterHeaderCreation := DLPDR.FAR.ForwardingParameters.OuterHeaderCreation - dlOuterHeaderCreation.OuterHeaderCreationDescription = pfcpType.OuterHeaderCreationGtpUUdpIpv4 - dlOuterHeaderCreation.Teid = teid - dlOuterHeaderCreation.Ipv4Address = ctx.Tunnel.ANInformation.IPAddress.To4() - } - } + ctx.Tunnel.UpdateANInformation( + GTPTunnel.TransportLayerAddress.Value.Bytes, + binary.BigEndian.Uint32(GTPTunnel.GTPTEID.Value)) ctx.UpCnxState = models.UpCnxState_ACTIVATED return nil @@ -99,26 +82,11 @@ func HandlePathSwitchRequestTransfer(b []byte, ctx *SMContext) error { return errors.New("pathSwitchRequestTransfer.DLNGUUPTNLInformation.Present") } - gtpTunnel := pathSwitchRequestTransfer.DLNGUUPTNLInformation.GTPTunnel - - teid := binary.BigEndian.Uint32(gtpTunnel.GTPTEID.Value) - - ctx.Tunnel.ANInformation.IPAddress = gtpTunnel.TransportLayerAddress.Value.Bytes - ctx.Tunnel.ANInformation.TEID = teid + GTPTunnel := pathSwitchRequestTransfer.DLNGUUPTNLInformation.GTPTunnel - for _, dataPath := range ctx.Tunnel.DataPathPool { - if dataPath.Activated { - ANUPF := dataPath.FirstDPNode - DLPDR := ANUPF.DownLinkTunnel.PDR - - DLPDR.FAR.ForwardingParameters.OuterHeaderCreation = new(pfcpType.OuterHeaderCreation) - dlOuterHeaderCreation := DLPDR.FAR.ForwardingParameters.OuterHeaderCreation - dlOuterHeaderCreation.OuterHeaderCreationDescription = pfcpType.OuterHeaderCreationGtpUUdpIpv4 - dlOuterHeaderCreation.Teid = teid - dlOuterHeaderCreation.Ipv4Address = ctx.Tunnel.ANInformation.IPAddress.To4() - DLPDR.FAR.State = RULE_UPDATE - } - } + ctx.Tunnel.UpdateANInformation( + GTPTunnel.TransportLayerAddress.Value.Bytes, + binary.BigEndian.Uint32(GTPTunnel.GTPTEID.Value)) ctx.UpSecurityFromPathSwitchRequestSameAsLocalStored = true @@ -189,28 +157,12 @@ func HandleHandoverRequestAcknowledgeTransfer(b []byte, ctx *SMContext) (err err if err != nil { return err } - DLNGUUPTNLInformation := handoverRequestAcknowledgeTransfer.DLNGUUPTNLInformation - GTPTunnel := DLNGUUPTNLInformation.GTPTunnel - TEIDReader := bytes.NewBuffer(GTPTunnel.GTPTEID.Value) - teid, err := binary.ReadUvarint(TEIDReader) - if err != nil { - return fmt.Errorf("Parse TEID error %s", err.Error()) - } + DLNGUUPGTPTunnel := handoverRequestAcknowledgeTransfer.DLNGUUPTNLInformation.GTPTunnel - for _, dataPath := range ctx.Tunnel.DataPathPool { - if dataPath.Activated { - ANUPF := dataPath.FirstDPNode - DLPDR := ANUPF.DownLinkTunnel.PDR - - DLPDR.FAR.ForwardingParameters.OuterHeaderCreation = new(pfcpType.OuterHeaderCreation) - dlOuterHeaderCreation := DLPDR.FAR.ForwardingParameters.OuterHeaderCreation - dlOuterHeaderCreation.OuterHeaderCreationDescription = pfcpType.OuterHeaderCreationGtpUUdpIpv4 - dlOuterHeaderCreation.Teid = uint32(teid) - dlOuterHeaderCreation.Ipv4Address = GTPTunnel.TransportLayerAddress.Value.Bytes - DLPDR.FAR.State = RULE_UPDATE - } - } + ctx.Tunnel.UpdateANInformation( + DLNGUUPGTPTunnel.TransportLayerAddress.Value.Bytes, + binary.BigEndian.Uint32(DLNGUUPGTPTunnel.GTPTEID.Value)) return nil } diff --git a/internal/context/pfcp_rules.go b/internal/context/pfcp_rules.go index 3234a2c3..18a09509 100644 --- a/internal/context/pfcp_rules.go +++ b/internal/context/pfcp_rules.go @@ -55,6 +55,7 @@ type ForwardingParameters struct { NetworkInstance *pfcpType.NetworkInstance OuterHeaderCreation *pfcpType.OuterHeaderCreation ForwardingPolicyID string + SendEndMarker bool } // Buffering Action Rule 7.5.2.6-1 diff --git a/internal/context/upf.go b/internal/context/upf.go index 64d062e0..8cc45815 100644 --- a/internal/context/upf.go +++ b/internal/context/upf.go @@ -30,6 +30,30 @@ type UPTunnel struct { } } +func (t *UPTunnel) UpdateANInformation(ip net.IP, teid uint32) { + t.ANInformation.IPAddress = ip + t.ANInformation.TEID = teid + + for _, dataPath := range t.DataPathPool { + if dataPath.Activated { + ANUPF := dataPath.FirstDPNode + DLPDR := ANUPF.DownLinkTunnel.PDR + + if DLPDR.FAR.ForwardingParameters.OuterHeaderCreation != nil { + // Old AN tunnel exists + DLPDR.FAR.ForwardingParameters.SendEndMarker = true + } + + DLPDR.FAR.ForwardingParameters.OuterHeaderCreation = new(pfcpType.OuterHeaderCreation) + dlOuterHeaderCreation := DLPDR.FAR.ForwardingParameters.OuterHeaderCreation + dlOuterHeaderCreation.OuterHeaderCreationDescription = pfcpType.OuterHeaderCreationGtpUUdpIpv4 + dlOuterHeaderCreation.Teid = t.ANInformation.TEID + dlOuterHeaderCreation.Ipv4Address = t.ANInformation.IPAddress.To4() + DLPDR.FAR.State = RULE_UPDATE + } + } +} + type UPFStatus int const ( diff --git a/internal/pfcp/message/build.go b/internal/pfcp/message/build.go index 81e95644..a1da60b1 100644 --- a/internal/pfcp/message/build.go +++ b/internal/pfcp/message/build.go @@ -119,16 +119,16 @@ func farToCreateFAR(far *context.FAR) *pfcp.CreateFAR { } if far.ForwardingParameters != nil { - createFAR.ForwardingParameters = new(pfcp.ForwardingParametersIEInFAR) - createFAR.ForwardingParameters.DestinationInterface = &far.ForwardingParameters.DestinationInterface - createFAR.ForwardingParameters.NetworkInstance = far.ForwardingParameters.NetworkInstance - createFAR.ForwardingParameters.OuterHeaderCreation = far.ForwardingParameters.OuterHeaderCreation + createFAR.ForwardingParameters = &pfcp.ForwardingParametersIEInFAR{ + DestinationInterface: &far.ForwardingParameters.DestinationInterface, + NetworkInstance: far.ForwardingParameters.NetworkInstance, + OuterHeaderCreation: far.ForwardingParameters.OuterHeaderCreation, + } if far.ForwardingParameters.ForwardingPolicyID != "" { - createFAR.ForwardingParameters.ForwardingPolicy = new(pfcpType.ForwardingPolicy) - createFAR.ForwardingParameters.ForwardingPolicy.ForwardingPolicyIdentifierLength = - uint8(len(far.ForwardingParameters.ForwardingPolicyID)) - createFAR.ForwardingParameters.ForwardingPolicy.ForwardingPolicyIdentifier = - []byte(far.ForwardingParameters.ForwardingPolicyID) + createFAR.ForwardingParameters.ForwardingPolicy = &pfcpType.ForwardingPolicy{ + ForwardingPolicyIdentifierLength: uint8(len(far.ForwardingParameters.ForwardingPolicyID)), + ForwardingPolicyIdentifier: []byte(far.ForwardingParameters.ForwardingPolicyID), + } } } @@ -220,16 +220,19 @@ func farToUpdateFAR(far *context.FAR) *pfcp.UpdateFAR { updateFAR.ApplyAction.Drop = far.ApplyAction.Drop if far.ForwardingParameters != nil { - updateFAR.UpdateForwardingParameters = new(pfcp.UpdateForwardingParametersIEInFAR) - updateFAR.UpdateForwardingParameters.DestinationInterface = &far.ForwardingParameters.DestinationInterface - updateFAR.UpdateForwardingParameters.NetworkInstance = far.ForwardingParameters.NetworkInstance - updateFAR.UpdateForwardingParameters.OuterHeaderCreation = far.ForwardingParameters.OuterHeaderCreation + updateFAR.UpdateForwardingParameters = &pfcp.UpdateForwardingParametersIEInFAR{ + DestinationInterface: &far.ForwardingParameters.DestinationInterface, + NetworkInstance: far.ForwardingParameters.NetworkInstance, + OuterHeaderCreation: far.ForwardingParameters.OuterHeaderCreation, + PFCPSMReqFlags: &pfcpType.PFCPSMReqFlags{ + Sndem: far.ForwardingParameters.SendEndMarker, + }, + } if far.ForwardingParameters.ForwardingPolicyID != "" { - updateFAR.UpdateForwardingParameters.ForwardingPolicy = new(pfcpType.ForwardingPolicy) - updateFAR.UpdateForwardingParameters.ForwardingPolicy.ForwardingPolicyIdentifierLength = - uint8(len(far.ForwardingParameters.ForwardingPolicyID)) - updateFAR.UpdateForwardingParameters.ForwardingPolicy.ForwardingPolicyIdentifier = - []byte(far.ForwardingParameters.ForwardingPolicyID) + updateFAR.UpdateForwardingParameters.ForwardingPolicy = &pfcpType.ForwardingPolicy{ + ForwardingPolicyIdentifierLength: uint8(len(far.ForwardingParameters.ForwardingPolicyID)), + ForwardingPolicyIdentifier: []byte(far.ForwardingParameters.ForwardingPolicyID), + } } } @@ -242,7 +245,8 @@ func BuildPfcpSessionEstablishmentRequest( pdrList []*context.PDR, farList []*context.FAR, barList []*context.BAR, - qerList []*context.QER) (pfcp.PFCPSessionEstablishmentRequest, error) { + qerList []*context.QER, +) (pfcp.PFCPSessionEstablishmentRequest, error) { msg := pfcp.PFCPSessionEstablishmentRequest{} msg.NodeID = &context.SMF_Self().CPNodeID @@ -351,7 +355,8 @@ func BuildPfcpSessionModificationRequest( pdrList []*context.PDR, farList []*context.FAR, barList []*context.BAR, - qerList []*context.QER) (pfcp.PFCPSessionModificationRequest, error) { + qerList []*context.QER, +) (pfcp.PFCPSessionModificationRequest, error) { msg := pfcp.PFCPSessionModificationRequest{} msg.UpdatePDR = make([]*pfcp.UpdatePDR, 0, 2)