Skip to content

Commit

Permalink
refactor: move gtpuConn setup to nwuup and update go-gtp version
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-ywliu committed Jul 29, 2024
1 parent 0758594 commit 01c10b4
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 428 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli v1.22.5
github.com/vishvananda/netlink v1.1.0
github.com/wmnsk/go-gtp v0.8.0
golang.org/x/net v0.25.0
golang.org/x/sys v0.20.0
github.com/wmnsk/go-gtp v0.8.11-0.20240705144331-f53bfdd4233b
golang.org/x/net v0.27.0
golang.org/x/sys v0.22.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -48,10 +48,10 @@ require (
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
github.com/vishvananda/netns v0.0.4 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
203 changes: 20 additions & 183 deletions go.sum

Large diffs are not rendered by default.

139 changes: 0 additions & 139 deletions internal/ngap/gtp.go

This file was deleted.

89 changes: 27 additions & 62 deletions internal/ngap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net"
"time"

"github.com/wmnsk/go-gtp/gtpv1"

"github.com/free5gc/aper"
"github.com/free5gc/n3iwf/internal/logger"
"github.com/free5gc/n3iwf/internal/ngap/message"
Expand Down Expand Up @@ -863,75 +865,38 @@ func (s *Server) handlePDUSessionResourceSetupRequestTransfer(
OutgoingTEID: binary.BigEndian.Uint32(ulNGUUPTNLInformation.GTPTunnel.GTPTEID.Value),
}

if userPlaneConnection, ok := n3iwfCtx.GTPConnectionWithUPFLoad(upfIPv4); ok {
// UPF UDP address
upfUDPAddr, err := net.ResolveUDPAddr("udp", upfIPv4+":2152")
// UPF UDP address
upfAddr := upfIPv4 + gtpv1.GTPUPort
upfUDPAddr, err := net.ResolveUDPAddr("udp", upfAddr)
if err != nil {
ngapLog.Errorf("Resolve UPF addr [%s] failed: %v", upfAddr, err)
cause := message.BuildCause(ngapType.CausePresentTransport,
ngapType.CauseTransportPresentTransportResourceUnavailable)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Resolve UDP address failed: %v", err)
cause := message.BuildCause(ngapType.CausePresentTransport,
ngapType.CauseTransportPresentTransportResourceUnavailable)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}
return false, responseTransfer
}

// UE TEID
ueTEID := n3iwfCtx.NewTEID(ranUe)
if ueTEID == 0 {
ngapLog.Error("Invalid TEID (0).")
cause := message.BuildCause(
ngapType.CausePresentProtocol,
ngapType.CauseProtocolPresentUnspecified)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}
return false, responseTransfer
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}
return false, responseTransfer
}

// Set UE associated GTP connection
gtpConnection.UPFUDPAddr = upfUDPAddr
gtpConnection.IncomingTEID = ueTEID
gtpConnection.UserPlaneConnection = userPlaneConnection
} else {
// Setup GTP connection with UPF
userPlaneConnection, upfUDPAddr, err := s.setupGTPTunnelWithUPF(upfIPv4)
// UE TEID
ueTEID := n3iwfCtx.NewTEID(ranUe)
if ueTEID == 0 {
ngapLog.Error("Invalid TEID (0).")
cause := message.BuildCause(
ngapType.CausePresentProtocol,
ngapType.CauseProtocolPresentUnspecified)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Setup GTP connection with UPF failed: %v", err)
cause := message.BuildCause(ngapType.CausePresentTransport,
ngapType.CauseTransportPresentTransportResourceUnavailable)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}
return false, responseTransfer
}

// UE TEID
ueTEID := n3iwfCtx.NewTEID(ranUe)
if ueTEID == 0 {
ngapLog.Error("Invalid TEID (0).")
cause := message.BuildCause(
ngapType.CausePresentProtocol,
ngapType.CauseProtocolPresentUnspecified)
responseTransfer, err := message.BuildPDUSessionResourceSetupUnsuccessfulTransfer(*cause, nil)
if err != nil {
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}
return false, responseTransfer
ngapLog.Errorf("Build PDUSessionResourceSetupUnsuccessfulTransfer Error: %v\n", err)
}

// Setup GTP connection with UPF
gtpConnection.UPFUDPAddr = upfUDPAddr
gtpConnection.IncomingTEID = ueTEID
gtpConnection.UserPlaneConnection = userPlaneConnection

// Store GTP connection with UPF into N3IWF context
n3iwfCtx.GTPConnectionWithUPFStore(upfIPv4, userPlaneConnection)
return false, responseTransfer
}

// Setup GTP connection with UPF
gtpConnection.UPFUDPAddr = upfUDPAddr
gtpConnection.IncomingTEID = ueTEID

pduSession.GTPConnection = gtpConnection
} else {
ngapLog.Error(
Expand Down
3 changes: 0 additions & 3 deletions internal/ngap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"sync"
"time"

"golang.org/x/net/ipv4"

"github.com/free5gc/n3iwf/internal/logger"
"github.com/free5gc/n3iwf/internal/ngap/message"
n3iwf_context "github.com/free5gc/n3iwf/pkg/context"
Expand All @@ -28,7 +26,6 @@ type n3iwf interface {
Context() *n3iwf_context.N3IWFContext
CancelContext() context.Context
IkeEvtCh() chan n3iwf_context.IkeEvt
NwuupIPv4PktConn() *ipv4.PacketConn
}

type Server struct {
Expand Down
Loading

0 comments on commit 01c10b4

Please sign in to comment.