Skip to content

Commit

Permalink
(wip) Handover; close #12; close #13; close #14
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Dec 23, 2024
1 parent 08cd8b5 commit 67dfe0e
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 49 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/adrg/xdg v0.5.3
github.com/gin-gonic/gin v1.10.0
github.com/nextmn/go-pfcp-networking v0.0.41
github.com/nextmn/json-api v0.0.14
github.com/nextmn/json-api v0.0.15-0.20241223151312-9ece63d06e84
github.com/nextmn/logrus-formatter v0.0.1
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli/v2 v2.27.5
Expand All @@ -15,7 +15,7 @@ require (
)

require (
github.com/bytedance/sonic v1.12.5 // indirect
github.com/bytedance/sonic v1.12.6 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
Expand All @@ -39,8 +39,8 @@ require (
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
google.golang.org/protobuf v1.36.0 // indirect
)
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78=
github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ=
github.com/bytedance/sonic v1.12.5 h1:hoZxY8uW+mT+OpkcUWw4k0fDINtOcVavEsGfzwzFU/w=
github.com/bytedance/sonic v1.12.5/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk=
github.com/bytedance/sonic v1.12.6/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E=
github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
Expand Down Expand Up @@ -50,8 +50,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/nextmn/go-pfcp-networking v0.0.41 h1:vA8TfjlxZMxZIZiJ3eEdllwYjmBurvZvD9J4xcCPheo=
github.com/nextmn/go-pfcp-networking v0.0.41/go.mod h1:KYoKLiltDmHL2YMU5mz2k/E1xMoz4TpmzTz6Nr5u5gA=
github.com/nextmn/json-api v0.0.14 h1:m4uHOVcXsxkXoxbrhqemLTRG4T86eYkejjirew1nDUU=
github.com/nextmn/json-api v0.0.14/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak=
github.com/nextmn/json-api v0.0.15-0.20241218142156-a64418a36b7d h1:lhybNMDI+qjJB+rKDgJiHrXuhkoR7FWhQ4nEfpqZy1g=
github.com/nextmn/json-api v0.0.15-0.20241218142156-a64418a36b7d/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak=
github.com/nextmn/json-api v0.0.15-0.20241223150142-2189fb1dc3af h1:/YGOPznGEQ0x/2E1Yk9HZ/3FosWtK5FouI0NDSiN2sE=
github.com/nextmn/json-api v0.0.15-0.20241223150142-2189fb1dc3af/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak=
github.com/nextmn/json-api v0.0.15-0.20241223151312-9ece63d06e84 h1:eMjBBW9K21ffZ0CmbY7nKZd8d7O41DMB10t2HOTkUHw=
github.com/nextmn/json-api v0.0.15-0.20241223151312-9ece63d06e84/go.mod h1:CQXeNPj9MDGsEExtnqJFIGjLgZAKsmOoO2fy+mep7Ak=
github.com/nextmn/logrus-formatter v0.0.1 h1:Bsf78jjiEESc+rV8xE6IyKj4frDPGMwXFNrLQzm6A1E=
github.com/nextmn/logrus-formatter v0.0.1/go.mod h1:vdSZ+sIcSna8vjbXkSFxsnsKHqRwaUEed4JCPcXoGyM=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
Expand Down Expand Up @@ -86,16 +90,16 @@ golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg=
golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.0 h1:mjIs9gYtt56AzC4ZaffQuh88TZurBGhIJMBZGSxNerQ=
google.golang.org/protobuf v1.36.0/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 3 additions & 0 deletions internal/amf/amf.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func NewAmf(bindAddr netip.AddrPort, control jsonapi.ControlURI, userAgent strin
// PDU Sessions
r.POST("/ps/establishment-request", amf.EstablishmentRequest)
r.POST("/ps/n2-establishment-response", amf.N2EstablishmentResponse)
r.POST("/ps/handover-requered", amf.HandoverRequired)
r.POST("/ps/handover-request-ack", amf.HandoverRequestAck)
r.POST("/ps/handover-notify", amf.HandoverNotify)

logrus.WithFields(logrus.Fields{"http-addr": bindAddr}).Info("HTTP Server created")
amf.srv = &http.Server{
Expand Down
3 changes: 1 addition & 2 deletions internal/amf/establishment_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func (amf *Amf) HandleEstablishmentRequest(ps n1n2.PduSessionEstabReqMsg) {
Header: ps,
Addr: pduSession.UeIpAddr,
},
Upf: pduSession.UplinkFteid.Addr,
UplinkTeid: pduSession.UplinkFteid.Teid,
UplinkFteid: *pduSession.UplinkFteid,
}
reqBody, err := json.Marshal(n2PsReq)
if err != nil {
Expand Down
31 changes: 31 additions & 0 deletions internal/amf/handover_notify.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package amf

import (
"net/http"

"github.com/nextmn/json-api/jsonapi"
"github.com/nextmn/json-api/jsonapi/n1n2"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

func (amf *Amf) HandoverNotify(c *gin.Context) {
var m n1n2.HandoverNotify
if err := c.BindJSON(&m); err != nil {
logrus.WithError(err).Error("could not deserialize")
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err})
return
}
go amf.HandleHandoverNotify(m)
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"})
}

func (amf *Amf) HandleHandoverNotify(m n1n2.HandoverNotify) {
logrus.Error("Handover Notify: Not implemented")
}
31 changes: 31 additions & 0 deletions internal/amf/handover_request_ack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package amf

import (
"net/http"

"github.com/nextmn/json-api/jsonapi"
"github.com/nextmn/json-api/jsonapi/n1n2"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

func (amf *Amf) HandoverRequestAck(c *gin.Context) {
var m n1n2.HandoverRequestAck
if err := c.BindJSON(&m); err != nil {
logrus.WithError(err).Error("could not deserialize")
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err})
return
}
go amf.HandleHandoverRequestAck(m)
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"})
}

func (amf *Amf) HandleHandoverRequestAck(m n1n2.HandoverRequestAck) {
logrus.Error("Handover Request Ack: Not implemented")
}
31 changes: 31 additions & 0 deletions internal/amf/handover_required.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Louis Royer and the NextMN contributors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT

package amf

import (
"net/http"

"github.com/nextmn/json-api/jsonapi"
"github.com/nextmn/json-api/jsonapi/n1n2"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)

func (amf *Amf) HandoverRequired(c *gin.Context) {
var m n1n2.HandoverRequired
if err := c.BindJSON(&m); err != nil {
logrus.WithError(err).Error("could not deserialize")
c.JSON(http.StatusBadRequest, jsonapi.MessageWithError{Message: "could not deserialize", Error: err})
return
}
go amf.HandleHandoverRequired(m)
c.JSON(http.StatusAccepted, jsonapi.Message{Message: "please refer to logs for more information"})
}

func (amf *Amf) HandleHandoverRequired(m n1n2.HandoverRequired) {
logrus.Error("Handover Required: Not implemented")
}
2 changes: 1 addition & 1 deletion internal/amf/n2_establishment_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (amf *Amf) N2EstablishmentResponse(c *gin.Context) {

func (amf *Amf) HandleN2EstablishmentResponse(ps n1n2.N2PduSessionRespMsg) {
ctx := amf.Context()
pduSession, err := amf.smf.CreateSessionDownlinkContext(ctx, ps.UeInfo.Header.Ue, ps.UeInfo.Addr, ps.UeInfo.Header.Dnn, ps.Gnb, ps.DownlinkTeid)
pduSession, err := amf.smf.CreateSessionDownlinkContext(ctx, ps.UeInfo.Header.Ue, ps.UeInfo.Addr, ps.UeInfo.Header.Dnn, ps.DownlinkFteid.Addr, ps.DownlinkFteid.Teid)
if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{
"ue-ip-addr": ps.UeInfo.Addr,
Expand Down
15 changes: 0 additions & 15 deletions internal/smf/fteid.go

This file was deleted.

6 changes: 4 additions & 2 deletions internal/smf/pdu-session-n3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ package smf

import (
"net/netip"

"github.com/nextmn/json-api/jsonapi"
)

type PduSessionN3 struct {
UeIpAddr netip.Addr
UplinkFteid *Fteid
DownlinkFteid *Fteid
UplinkFteid *jsonapi.Fteid
DownlinkFteid *jsonapi.Fteid
}
5 changes: 1 addition & 4 deletions internal/smf/smf.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ func (smf *Smf) CreateSessionDownlinkContext(ctx context.Context, ueCtrl jsonapi
if err != nil {
return nil, err
}
session.DownlinkFteid = &Fteid{
Addr: gnb,
Teid: gnb_teid,
}
session.DownlinkFteid = jsonapi.NewFteid(gnb, gnb_teid)
if len(slice.Upfs) == 0 {
return nil, ErrUpfNotFound
}
Expand Down
27 changes: 14 additions & 13 deletions internal/smf/upf.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

pfcp "github.com/nextmn/go-pfcp-networking/pfcp"
pfcpapi "github.com/nextmn/go-pfcp-networking/pfcp/api"
"github.com/nextmn/json-api/jsonapi"

"github.com/wmnsk/go-pfcp/ie"
)
Expand Down Expand Up @@ -95,11 +96,11 @@ func (upf *Upf) Rules(ueIp netip.Addr) *Pfcprules {
return rules
}

func (upf *Upf) NextListenFteid(listenInterface netip.Addr) (*Fteid, error) {
func (upf *Upf) NextListenFteid(listenInterface netip.Addr) (*jsonapi.Fteid, error) {
return upf.NextListenFteidContext(upf.ctx, listenInterface)
}

func (upf *Upf) NextListenFteidContext(ctx context.Context, listenInterface netip.Addr) (*Fteid, error) {
func (upf *Upf) NextListenFteidContext(ctx context.Context, listenInterface netip.Addr) (*jsonapi.Fteid, error) {
if ctx == nil || upf.ctx == nil {
return nil, ErrNilCtx
}
Expand All @@ -118,17 +119,17 @@ func (upf *Upf) NextListenFteidContext(ctx context.Context, listenInterface neti
if err != nil {
return nil, err
}
return &Fteid{
return &jsonapi.Fteid{
Addr: listenInterface,
Teid: teid,
}, nil
}

func (upf *Upf) CreateUplinkIntermediate(ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *Fteid) (*Fteid, error) {
func (upf *Upf) CreateUplinkIntermediate(ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *jsonapi.Fteid) (*jsonapi.Fteid, error) {
return upf.CreateUplinkIntermediateContext(upf.ctx, ueIp, dnn, listenInterface, forwardFteid)
}

func (upf *Upf) CreateUplinkIntermediateContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *Fteid) (*Fteid, error) {
func (upf *Upf) CreateUplinkIntermediateContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *jsonapi.Fteid) (*jsonapi.Fteid, error) {
if ctx == nil || upf.ctx == nil {
return nil, ErrNilCtx
}
Expand All @@ -147,7 +148,7 @@ func (upf *Upf) CreateUplinkIntermediateContext(ctx context.Context, ueIp netip.
return listenFteid, nil
}

func (upf *Upf) CreateUplinkIntermediateWithFteid(ueIp netip.Addr, dnn string, listenFteid *Fteid, forwardFteid *Fteid) {
func (upf *Upf) CreateUplinkIntermediateWithFteid(ueIp netip.Addr, dnn string, listenFteid *jsonapi.Fteid, forwardFteid *jsonapi.Fteid) {
r := upf.Rules(ueIp)
r.Lock()
defer r.Unlock()
Expand Down Expand Up @@ -180,10 +181,10 @@ func (upf *Upf) CreateUplinkIntermediateWithFteid(ueIp netip.Addr, dnn string, l
// TODO: QER, to avoid wrong gtp size set by F5GC's UPF
}

func (upf *Upf) CreateUplinkAnchor(ueIp netip.Addr, dnn string, listenInterface netip.Addr) (*Fteid, error) {
func (upf *Upf) CreateUplinkAnchor(ueIp netip.Addr, dnn string, listenInterface netip.Addr) (*jsonapi.Fteid, error) {
return upf.CreateUplinkAnchorContext(upf.ctx, ueIp, dnn, listenInterface)
}
func (upf *Upf) CreateUplinkAnchorContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr) (*Fteid, error) {
func (upf *Upf) CreateUplinkAnchorContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr) (*jsonapi.Fteid, error) {
if ctx == nil {
return nil, ErrNilCtx
}
Expand All @@ -195,7 +196,7 @@ func (upf *Upf) CreateUplinkAnchorContext(ctx context.Context, ueIp netip.Addr,
return listenFteid, nil
}

func (upf *Upf) CreateUplinkAnchorWithFteid(ueIp netip.Addr, dnn string, listenFteid *Fteid) {
func (upf *Upf) CreateUplinkAnchorWithFteid(ueIp netip.Addr, dnn string, listenFteid *jsonapi.Fteid) {
r := upf.Rules(ueIp)
r.Lock()
defer r.Unlock()
Expand All @@ -221,7 +222,7 @@ func (upf *Upf) CreateUplinkAnchorWithFteid(ueIp netip.Addr, dnn string, listenF
))
}

func (upf *Upf) UpdateDownlinkAnchor(ueIp netip.Addr, dnn string, forwardFteid *Fteid) {
func (upf *Upf) UpdateDownlinkAnchor(ueIp netip.Addr, dnn string, forwardFteid *jsonapi.Fteid) {
r := upf.Rules(ueIp)
r.Lock()
defer r.Unlock()
Expand Down Expand Up @@ -252,10 +253,10 @@ func (upf *Upf) UpdateDownlinkAnchor(ueIp netip.Addr, dnn string, forwardFteid *
// TODO: QER, to avoid wrong gtp size set by F5GC's UPF
}

func (upf *Upf) UpdateDownlinkIntermediate(ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *Fteid) (*Fteid, error) {
func (upf *Upf) UpdateDownlinkIntermediate(ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *jsonapi.Fteid) (*jsonapi.Fteid, error) {
return upf.UpdateDownlinkIntermediateContext(upf.ctx, ueIp, dnn, listenInterface, forwardFteid)
}
func (upf *Upf) UpdateDownlinkIntermediateContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *Fteid) (*Fteid, error) {
func (upf *Upf) UpdateDownlinkIntermediateContext(ctx context.Context, ueIp netip.Addr, dnn string, listenInterface netip.Addr, forwardFteid *jsonapi.Fteid) (*jsonapi.Fteid, error) {
if ctx == nil {
return nil, ErrNilCtx
}
Expand All @@ -267,7 +268,7 @@ func (upf *Upf) UpdateDownlinkIntermediateContext(ctx context.Context, ueIp neti
return listenFteid, nil
}

func (upf *Upf) UpdateDownlinkIntermediateWithFteid(ueIp netip.Addr, dnn string, listenFteid *Fteid, forwardFteid *Fteid) {
func (upf *Upf) UpdateDownlinkIntermediateWithFteid(ueIp netip.Addr, dnn string, listenFteid *jsonapi.Fteid, forwardFteid *jsonapi.Fteid) {
r := upf.Rules(ueIp)
r.Lock()
defer r.Unlock()
Expand Down

0 comments on commit 67dfe0e

Please sign in to comment.