Skip to content

Commit

Permalink
refactor: processor architecture that aligns with other nf repo
Browse files Browse the repository at this point in the history
  • Loading branch information
yccodr committed May 10, 2024
1 parent b00f843 commit 0ed8569
Show file tree
Hide file tree
Showing 18 changed files with 739 additions and 734 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/urfave/cli v1.22.5
go.uber.org/mock v0.4.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 @@ -212,6 +212,8 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
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
185 changes: 180 additions & 5 deletions internal/sbi/api_nssaiavailability.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import (
"strings"

"github.com/gin-gonic/gin"

"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/plugin"
"github.com/free5gc/nssf/internal/util"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
)

func (s *Server) getNssaiAvailabilityRoutes() []Route {
Expand All @@ -22,21 +28,21 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route {
"NSSAIAvailabilityDelete",
strings.ToUpper("Delete"),
"/nssai-availability/:nfId",
s.Processor().HandleNSSAIAvailabilityDelete,
s.NSSAIAvailabilityDelete,
},

{
"NSSAIAvailabilityPatch",
strings.ToUpper("Patch"),
"/nssai-availability/:nfId",
s.Processor().HandleNSSAIAvailabilityPatch,
s.NSSAIAvailabilityPatch,
},

{
"NSSAIAvailabilityPut",
strings.ToUpper("Put"),
"/nssai-availability/:nfId",
s.Processor().HandleNSSAIAvailabilityPut,
s.NSSAIAvailabilityPut,
},

// Regular expressions for route matching should be unique in Gin package
Expand All @@ -47,14 +53,183 @@ func (s *Server) getNssaiAvailabilityRoutes() []Route {
strings.ToUpper("Delete"),
// "/nssai-availability/subscriptions/:subscriptionId",
"/nssai-availability/:nfId/:subscriptionId",
s.Processor().HandleNSSAIAvailabilityUnsubscribeDelete,
s.NSSAIAvailabilityUnsubscribeDelete,
},

{
"NSSAIAvailabilityPost",
strings.ToUpper("Post"),
"/nssai-availability/subscriptions",
s.Processor().HandleNSSAIAvailabilityPost,
s.NSSAIAvailabilityPost,
},
}
}

// NSSAIAvailabilityDelete - Deletes an already existing S-NSSAIs per TA
// provided by the NF service consumer (e.g AMF)
func (s *Server) NSSAIAvailabilityDelete(c *gin.Context) {
logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityDelete")

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

if nfId == "" {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

util.GinProblemJson(c, problemDetails)
return
}

s.Processor().NssaiAvailabilityNfInstanceDelete(c, nfId)
}

// NSSAIAvailabilityPatch - Updates an already existing S-NSSAIs per TA
// provided by the NF service consumer (e.g AMF)
func (s *Server) NSSAIAvailabilityPatch(c *gin.Context) {
logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityPatch")

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

if nfId == "" {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

util.GinProblemJson(c, problemDetails)
return
}

var patchDocument plugin.PatchDocument

requestBody, err := c.GetRawData()
if err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
}

util.GinProblemJson(c, problemDetails)
return
}

if err = openapi.Deserialize(&patchDocument, requestBody, "application/json"); err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

logger.SBILog.Errorf("Error deserializing patch document: %+v", err)
util.GinProblemJson(c, problemDetails)
return
}

// TODO: Request NfProfile of NfId from NRF
// Check if NfId is valid AMF and obtain AMF Set ID
// If NfId is invalid, return ProblemDetails with code 404 Not Found
// If NF consumer is not authorized to update NSSAI availability, return ProblemDetails with code 403 Forbidden

s.Processor().NssaiAvailabilityNfInstancePatch(c, patchDocument, nfId)
}

// NSSAIAvailabilityPut - Updates/replaces the NSSF
// with the S-NSSAIs the NF service consumer (e.g AMF) supports per TA
func (s *Server) NSSAIAvailabilityPut(c *gin.Context) {
logger.NssaiavailLog.Infof("Handle NSSAIAvailabilityPut")

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

if nfId == "" {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

util.GinProblemJson(c, problemDetails)
return
}

var nssaiAvailabilityInfo models.NssaiAvailabilityInfo
data, err := c.GetRawData()
if err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusInternalServerError,
Cause: "SYSTEM_FAILURE",
}

util.GinProblemJson(c, problemDetails)
return
}

if err = openapi.Deserialize(&nssaiAvailabilityInfo, data, "application/json"); err != nil {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

logger.SBILog.Errorf("Error deserializing NSSAI availability info: %+v", err)
util.GinProblemJson(c, problemDetails)
return
}

s.Processor().NssaiAvailabilityNfInstanceUpdate(c, nssaiAvailabilityInfo, nfId)
}

func (s *Server) NSSAIAvailabilityPost(c *gin.Context) {
var createData models.NssfEventSubscriptionCreateData

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

util.GinProblemJson(c, problemDetail)
return
}

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

util.GinProblemJson(c, rsp)
return
}

s.Processor().NssaiAvailabilitySubscriptionCreate(c, createData)
}

func (s *Server) NSSAIAvailabilityUnsubscribeDelete(c *gin.Context) {
// Due to conflict of route matching, 'subscriptions' in the route is replaced with the existing wildcard ':nfId'
nfID := c.Param("nfId")
if nfID != "subscriptions" {
c.JSON(http.StatusNotFound, gin.H{})
logger.NssaiavailLog.Infof("404 Not Found")
return
}

subscriptionId := c.Params.ByName("subscriptionId")
if subscriptionId == "" {
problemDetails := &models.ProblemDetails{
Status: http.StatusBadRequest,
Cause: "UNSPECIFIED", // TODO: Check if this is the correct cause
}

util.GinProblemJson(c, problemDetails)
return
}

s.Processor().NssaiAvailabilitySubscriptionUnsubscribe(c, subscriptionId)
}
11 changes: 10 additions & 1 deletion internal/sbi/api_nsselection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"

"github.com/gin-gonic/gin"

"github.com/free5gc/nssf/internal/logger"
)

func (s *Server) getNsSelectionRoutes() []Route {
Expand All @@ -22,7 +24,14 @@ func (s *Server) getNsSelectionRoutes() []Route {
"NSSelectionGet",
strings.ToUpper("Get"),
"/network-slice-information",
s.Processor().HandleNetworkSliceInformationGet,
s.NetworkSliceInformationGet,
},
}
}

func (s *Server) NetworkSliceInformationGet(c *gin.Context) {
logger.NsselLog.Infof("Handle NSSelectionGet")

query := c.Request.URL.Query()
s.Processor().NSSelectionSliceInformationGet(c, query)
}
73 changes: 0 additions & 73 deletions internal/sbi/nssaiavailability/nssaiavailability_store_test.go

This file was deleted.

Loading

0 comments on commit 0ed8569

Please sign in to comment.