Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #37

Merged
merged 25 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
23b2cdc
feat: consumer nrf_service
a3828162 Apr 24, 2024
f50f25d
feat: add nudm_service.go and nudr_service.go in consumer/
a3828162 Apr 27, 2024
21c90fb
feat: refactor processor ee, pp, callback
a3828162 Apr 29, 2024
aef8bce
feat: refactor uecm api_{SRV}.go and sdm api_{SRV}.go
a3828162 Apr 30, 2024
1e67491
feat: change func name http to handle, add (processor) method
a3828162 Apr 30, 2024
2d42b1a
feat: refactor server, processsor, consumer, router
a3828162 May 13, 2024
b8715f9
Merge branch 'main' into refactor/sbi-logic
a3828162 May 15, 2024
4076213
feat: refactor router
a3828162 May 15, 2024
d2386b3
Merge branch 'refactor/sbi-logic' of github.com:a3828162/udm into ref…
a3828162 May 15, 2024
c563d3e
fix: fix lint error
a3828162 May 15, 2024
dfb8312
feat: move procedure, hand func
a3828162 May 22, 2024
2decf1b
fix: name error
a3828162 May 23, 2024
f066b7c
fix: fix run error, remove unuse line
a3828162 May 26, 2024
e3f5dea
fix: consumer init error, url.Value init error
a3828162 May 27, 2024
bc28dff
fix: add mock app interface & fix unit test
ianchen0119 May 29, 2024
8f668bb
delete: remove legacy code
a3828162 May 29, 2024
76c53ec
fix: fix with PR comment
a3828162 Jun 4, 2024
6cf39c6
fix: fix PR comment & terminate problem
a3828162 Jun 21, 2024
2d138ca
fix: fix PR comment
a3828162 Jun 24, 2024
0465bd4
fix: fix log
a3828162 Jun 24, 2024
4e578fd
fix: fix wrong file name & fix implementation of processor follow sta…
a3828162 Jun 25, 2024
0001050
fix: fix PR comment
a3828162 Jun 25, 2024
d4025e0
fix: fix PR comment
a3828162 Jun 25, 2024
395e622
fix : fix PR comment
a3828162 Jun 26, 2024
972efcf
fix: fix PR comment
a3828162 Jun 27, 2024
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
20 changes: 15 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"context"
"os"
"os/signal"
"path/filepath"
"runtime/debug"
"syscall"

"github.com/urfave/cli"

Expand All @@ -14,8 +17,6 @@ import (
"github.com/free5gc/util/version"
)

var UDM *service.UdmApp

func main() {
defer func() {
if p := recover(); p != nil {
Expand Down Expand Up @@ -52,18 +53,27 @@ func action(cliCtx *cli.Context) error {

logger.MainLog.Infoln("UDM version: ", version.GetVersion())

ctx, cancel := context.WithCancel(context.Background())
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)

go func() {
<-sigCh // Wait for interrupt signal to gracefully shutdown
cancel() // Notify each goroutine and wait them stopped
}()

cfg, err := factory.ReadConfig(cliCtx.String("config"))
if err != nil {
return err
}
factory.UdmConfig = cfg
udm, err := service.NewApp(cfg)

udm, err := service.NewApp(ctx, cfg, tlsKeyLogPath)
if err != nil {
return err
}
UDM = udm

udm.Start(tlsKeyLogPath)
udm.Start()

return nil
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.5
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.21.0
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
Expand Down
1 change: 1 addition & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
func Init() {
GetSelf().NfService = make(map[models.ServiceName]models.NfService)
GetSelf().EeSubscriptionIDGenerator = idgenerator.NewGenerator(1, math.MaxInt32)
InitUdmContext(GetSelf())
}

type NFContext interface {
Expand Down
2 changes: 2 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
CfgLog *logrus.Entry
CtxLog *logrus.Entry
GinLog *logrus.Entry
SBILog *logrus.Entry
ConsumerLog *logrus.Entry
HttpLog *logrus.Entry
UeauLog *logrus.Entry
Expand All @@ -40,6 +41,7 @@ func init() {
CfgLog = NfLog.WithField(logger_util.FieldCategory, "CFG")
CtxLog = NfLog.WithField(logger_util.FieldCategory, "CTX")
GinLog = NfLog.WithField(logger_util.FieldCategory, "GIN")
SBILog = NfLog.WithField(logger_util.FieldCategory, "SBI")
ConsumerLog = NfLog.WithField(logger_util.FieldCategory, "Consumer")
ProcLog = NfLog.WithField(logger_util.FieldCategory, "Proc")
HttpLog = NfLog.WithField(logger_util.FieldCategory, "HTTP")
Expand Down
154 changes: 154 additions & 0 deletions internal/sbi/api_eventexposure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package sbi

import (
"net/http"
"strings"

"github.com/gin-gonic/gin"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/udm/internal/logger"
)

func (s *Server) getEventExposureRoutes() []Route {
return []Route{
{
"Index",
"GET",
"/",
s.HandleIndex,
},

{
"HTTPCreateEeSubscription",
strings.ToUpper("Post"),
"/:ueIdentity/ee-subscriptions",
s.HandleCreateEeSubscription,
},

{
"HTTPDeleteEeSubscription",
strings.ToUpper("Delete"),
"/:ueIdentity/ee-subscriptions/:subscriptionId",
s.HandleDeleteEeSubscription,
},

{
"HTTPUpdateEeSubscription",
strings.ToUpper("Patch"),
"/:ueIdentity/ee-subscriptions/:subscriptionId",
s.HandleUpdateEeSubscription,
},
}
}

// HTTPCreateEeSubscription - Subscribe
func (s *Server) HandleCreateEeSubscription(c *gin.Context) {
var eesubscription models.EeSubscription

requestBody, err := c.GetRawData()
if err != nil {
logger.EeLog.Errorf("Get Request Body error: %+v", err)
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
c.JSON(http.StatusInternalServerError, problemDetail)
return
}

err = openapi.Deserialize(&eesubscription, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.EeLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}

// Start
logger.EeLog.Infoln("Handle Create EE Subscription")

ueIdentity := c.Params.ByName("ueIdentity")

createdEESubscription, problemDetails := s.Processor().CreateEeSubscriptionProcedure(ueIdentity, eesubscription)
if createdEESubscription != nil {
c.JSON(http.StatusCreated, createdEESubscription)
return
} else if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
return
} else {
problemDetails = &models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "UNSPECIFIED_NF_FAILURE",
}
c.JSON(http.StatusInternalServerError, problemDetails)
return
}
}

func (s *Server) HandleDeleteEeSubscription(c *gin.Context) {
ueIdentity := c.Params.ByName("ueIdentity")
subscriptionID := c.Params.ByName("subscriptionId")

s.Processor().DeleteEeSubscriptionProcedure(ueIdentity, subscriptionID)
// only return 204 no content
c.Status(http.StatusNoContent)
}

func (s *Server) HandleUpdateEeSubscription(c *gin.Context) {
var patchList []models.PatchItem

requestBody, err := c.GetRawData()
if err != nil {
logger.EeLog.Errorf("Get Request Body error: %+v", err)
problemDetail := models.ProblemDetails{
Title: "System failure",
Status: http.StatusInternalServerError,
Detail: err.Error(),
Cause: "SYSTEM_FAILURE",
}
c.JSON(http.StatusInternalServerError, problemDetail)
return
}

err = openapi.Deserialize(&patchList, requestBody, "application/json")
if err != nil {
problemDetail := "[Request Body] " + err.Error()
rsp := models.ProblemDetails{
Title: "Malformed request syntax",
Status: http.StatusBadRequest,
Detail: problemDetail,
}
logger.EeLog.Errorln(problemDetail)
c.JSON(http.StatusBadRequest, rsp)
return
}

ueIdentity := c.Params.ByName("ueIdentity")
subscriptionID := c.Params.ByName("subscriptionId")

logger.EeLog.Infoln("Handle Update EE subscription")
logger.EeLog.Warnln("Update EE Subscription is not implemented")

problemDetails := s.Processor().UpdateEeSubscriptionProcedure(ueIdentity, subscriptionID, patchList)
if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
return
} else {
c.Status(http.StatusNoContent)
return
}
}

func (s *Server) HandleIndex(c *gin.Context) {
c.String(http.StatusOK, "Hello World!")
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package httpcallback
package sbi

import (
"net/http"
"strings"

"github.com/gin-gonic/gin"

"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/udm/internal/logger"
"github.com/free5gc/udm/internal/sbi/producer"
"github.com/free5gc/util/httpwrapper"
)

func HTTPDataChangeNotificationToNF(c *gin.Context) {
func (s *Server) getHttpCallBackRoutes() []Route {
return []Route{
{
"Index",
"GET",
"/",
s.HandleIndex,
},

{
"DataChangeNotificationToNF",
strings.ToUpper("Post"),
"/sdm-subscriptions",
s.HandleDataChangeNotificationToNF,
},
}
}

func (s *Server) HandleDataChangeNotificationToNF(c *gin.Context) {
var dataChangeNotify models.DataChangeNotify
// step 1: retrieve http request body
requestBody, err := c.GetRawData()
Expand Down Expand Up @@ -42,20 +59,18 @@ func HTTPDataChangeNotificationToNF(c *gin.Context) {
return
}

req := httpwrapper.NewRequest(c.Request, dataChangeNotify)
req.Params["supi"] = c.Params.ByName("supi")
supi := c.Params.ByName("supi")

rsp := producer.HandleDataChangeNotificationToNFRequest(req)
responseBody, err := openapi.Serialize(rsp.Body, "application/json")
if err != nil {
logger.CallbackLog.Errorln(err)
problemDetails := models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
Detail: err.Error(),
}
c.JSON(http.StatusInternalServerError, problemDetails)
logger.CallbackLog.Infof("Handle DataChangeNotificationToNF")

problemDetails := s.Processor().DataChangeNotificationProcedure(dataChangeNotify.NotifyItems, supi)

// step 4: process the return value from step 3
if problemDetails != nil {
c.JSON(int(problemDetails.Status), problemDetails)
return
} else {
c.Data(rsp.Status, "application/json", responseBody)
c.Status(http.StatusNoContent)
return
}
}
Loading
Loading