-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from yccodr/refactor/server
refactor: NSSF app, sbi, processor, consumer
- Loading branch information
Showing
33 changed files
with
1,371 additions
and
1,234 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
package sbi | ||
|
||
import ( | ||
"net/http" | ||
"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 { | ||
return []Route{ | ||
{ | ||
"Health Check", | ||
strings.ToUpper("Get"), | ||
"/", | ||
func(ctx *gin.Context) { | ||
ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"}) | ||
}, | ||
}, | ||
|
||
{ | ||
"NSSAIAvailabilityDelete", | ||
strings.ToUpper("Delete"), | ||
"/nssai-availability/:nfId", | ||
s.NSSAIAvailabilityDelete, | ||
}, | ||
|
||
{ | ||
"NSSAIAvailabilityPatch", | ||
strings.ToUpper("Patch"), | ||
"/nssai-availability/:nfId", | ||
s.NSSAIAvailabilityPatch, | ||
}, | ||
|
||
{ | ||
"NSSAIAvailabilityPut", | ||
strings.ToUpper("Put"), | ||
"/nssai-availability/:nfId", | ||
s.NSSAIAvailabilityPut, | ||
}, | ||
|
||
// Regular expressions for route matching should be unique in Gin package | ||
// 'subscriptions' would conflict with existing wildcard ':nfId' | ||
// Simply replace 'subscriptions' with ':nfId' and check if ':nfId' is 'subscriptions' in handler function | ||
{ | ||
"NSSAIAvailabilityUnsubscribe", | ||
strings.ToUpper("Delete"), | ||
// "/nssai-availability/subscriptions/:subscriptionId", | ||
"/nssai-availability/:nfId/:subscriptionId", | ||
s.NSSAIAvailabilityUnsubscribeDelete, | ||
}, | ||
|
||
{ | ||
"NSSAIAvailabilityPost", | ||
strings.ToUpper("Post"), | ||
"/nssai-availability/subscriptions", | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sbi | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/gin-gonic/gin" | ||
|
||
"github.com/free5gc/nssf/internal/logger" | ||
) | ||
|
||
func (s *Server) getNsSelectionRoutes() []Route { | ||
return []Route{ | ||
{ | ||
"Health Check", | ||
strings.ToUpper("Get"), | ||
"/", | ||
func(ctx *gin.Context) { | ||
ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"}) | ||
}, | ||
}, | ||
|
||
{ | ||
"NSSelectionGet", | ||
strings.ToUpper("Get"), | ||
"/network-slice-information", | ||
s.NetworkSliceInformationGet, | ||
}, | ||
} | ||
} | ||
|
||
func (s *Server) NetworkSliceInformationGet(c *gin.Context) { | ||
logger.NsselLog.Infof("Handle NSSelectionGet") | ||
|
||
query := c.Request.URL.Query() | ||
s.Processor().NSSelectionSliceInformationGet(c, query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package consumer | ||
|
||
import ( | ||
"github.com/free5gc/nssf/pkg/app" | ||
"github.com/free5gc/openapi/Nnrf_NFManagement" | ||
) | ||
|
||
type Consumer struct { | ||
app.NssfApp | ||
|
||
*NrfService | ||
} | ||
|
||
func NewConsumer(nssf app.NssfApp) *Consumer { | ||
configuration := Nnrf_NFManagement.NewConfiguration() | ||
configuration.SetBasePath(nssf.Context().NrfUri) | ||
nrfService := &NrfService{ | ||
nrfNfMgmtClient: Nnrf_NFManagement.NewAPIClient(configuration), | ||
} | ||
|
||
return &Consumer{ | ||
NssfApp: nssf, | ||
NrfService: nrfService, | ||
} | ||
} |
Oops, something went wrong.