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: NSSF app, sbi, processor, consumer #24

Merged
merged 32 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e8eac91
refactor: sbi server
yccodr Apr 24, 2024
8210039
refactor: processor as route handler
yccodr Apr 25, 2024
d866a36
fix: nil dereference
yccodr Apr 25, 2024
99a72d3
fix: ci complains
yccodr Apr 25, 2024
9bbfecf
refactor: interface design
yccodr Apr 25, 2024
6f939e0
test: nssaiavailability `NfInstanceDelete`
yccodr Apr 25, 2024
e9e39ad
feat: graceful shutdown sbi server
yccodr Apr 25, 2024
155556c
fix: loop dependency on nssf app interface
yccodr Apr 29, 2024
fdee497
fix: missing oauth check
yccodr Apr 29, 2024
5838a20
fix: Init NSSF context
andy89923 Apr 29, 2024
cfe9ecd
chore: change logger to align with the right context
yccodr Apr 29, 2024
e6953eb
refactor: add services only when they are configured
yccodr Apr 29, 2024
25fe2c1
Revert "fix: loop dependency on nssf app interface"
yccodr Apr 30, 2024
db71e05
refactor: general app interface
yccodr May 8, 2024
01f38b7
refactor: app statr interface
yccodr May 8, 2024
6d27b3a
refactor: consumer
yccodr May 8, 2024
8a74e48
fix: should not access nssf context before assignment
yccodr May 9, 2024
4488ffb
feat: register procedure graceful shutdown
yccodr May 9, 2024
7f4cf20
fix: init nssf context with wrong function
yccodr May 9, 2024
b00f843
refactor: align naming of route handler
yccodr May 9, 2024
0ed8569
refactor: processor architecture that aligns with other nf repo
yccodr May 10, 2024
4700f68
refactor: nssf context init function
yccodr May 10, 2024
d666c0b
fix: duplicate processor
yccodr May 20, 2024
18cbb37
fix: magic number
yccodr May 20, 2024
54d7510
fix: possibly -1 in index range
yccodr May 20, 2024
f0b8da4
fix: linter complains
yccodr May 20, 2024
277815f
fix: instantiate processor in `NewApp()`
yccodr Jun 4, 2024
d1e1d5f
chore: add comment
yccodr Jun 11, 2024
5827322
chore: fix typo
yccodr Jun 12, 2024
d04c2e4
refactor: create context before `NewApp`
yccodr Jun 14, 2024
0e29e65
fix(nsselection): if `tai` and `homePlmnId` are both missing, return 400
yccodr Jun 14, 2024
201cb73
fix: prevent `app.Terminate()` being called twice
yccodr Jun 25, 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
21 changes: 19 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package main

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

"github.com/urfave/cli"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/repository"
"github.com/free5gc/nssf/pkg/factory"
"github.com/free5gc/nssf/pkg/service"
logger_util "github.com/free5gc/util/logger"
Expand Down Expand Up @@ -56,13 +61,25 @@ func action(cliCtx *cli.Context) error {
}
factory.NssfConfig = cfg

nssf, err := service.NewApp(cfg)
runtimeRepo := repository.NewRuntimeRepository(cfg)
nssf_context.InitNssfContext()
nssf, err := service.NewApp(runtimeRepo, tlsKeyLogPath)
if err != nil {
return err
}
NSSF = nssf

nssf.Start(tlsKeyLogPath)
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
}()

nssf.Start(ctx)
nssf.Wait()

return nil
}
Expand Down
2 changes: 2 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type NSSFContext struct {

// Initialize NSSF context with configuration factory
func InitNssfContext() {
Init()
andy89923 marked this conversation as resolved.
Show resolved Hide resolved

andy89923 marked this conversation as resolved.
Show resolved Hide resolved
nssfConfig := factory.NssfConfig
if nssfConfig.Configuration.NssfName != "" {
nssfContext.Name = nssfConfig.Configuration.NssfName
Expand Down
26 changes: 26 additions & 0 deletions internal/repository/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package repository

import (
nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/pkg/factory"
)

type RuntimeRepository struct {
config *factory.Config
nssfCtx *nssf_context.NSSFContext
}

func NewRuntimeRepository(cfg *factory.Config) *RuntimeRepository {
return &RuntimeRepository{
config: cfg,
nssfCtx: nssf_context.GetSelf(),
}
}

func (rr RuntimeRepository) Config() *factory.Config {
return rr.config
}

func (rr RuntimeRepository) Context() *nssf_context.NSSFContext {
return rr.nssfCtx
}
60 changes: 60 additions & 0 deletions internal/sbi/api_nssaiavailability.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package sbi

import (
"net/http"
"strings"

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

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.Processor().HandleNSSAIAvailabilityDelete,
},

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

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

// 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.Processor().HTTPNSSAIAvailabilityUnsubscribe,
},

{
"NSSAIAvailabilityPost",
strings.ToUpper("Post"),
"/nssai-availability/subscriptions",
s.Processor().HTTPNSSAIAvailabilityPost,
},
}
}
28 changes: 28 additions & 0 deletions internal/sbi/api_nsselection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sbi

import (
"net/http"
"strings"

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

func (s *Server) getNsSelectionRoutes() []Route {
return []Route{
{
"Helth Check",
yccodr marked this conversation as resolved.
Show resolved Hide resolved
strings.ToUpper("Get"),
"/",
func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"})
},
},

{
"NSSelectionGet",
strings.ToUpper("Get"),
"/network-slice-information",
s.Processor().HandleNetworkSliceInformationGet,
},
}
}
139 changes: 0 additions & 139 deletions internal/sbi/nssaiavailability/api_nf_instance_id_document.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* NSSF NSSAI Availability Service
*/

package producer
package nssaiavailability

import (
"bytes"
Expand All @@ -22,8 +22,7 @@ import (
"github.com/free5gc/openapi/models"
)

// NSSAIAvailability DELETE method
func NSSAIAvailabilityDeleteProcedure(nfId string) *models.ProblemDetails {
func NfInstanceDelete(nfId string) *models.ProblemDetails {
var problemDetails *models.ProblemDetails
for i, amfConfig := range factory.NssfConfig.Configuration.AmfList {
if amfConfig.NfId == nfId {
Expand All @@ -34,16 +33,15 @@ func NSSAIAvailabilityDeleteProcedure(nfId string) *models.ProblemDetails {
}
}

*problemDetails = models.ProblemDetails{
problemDetails = &models.ProblemDetails{
Title: util.UNSUPPORTED_RESOURCE,
Status: http.StatusNotFound,
Detail: fmt.Sprintf("AMF ID '%s' does not exist", nfId),
}
return problemDetails
}

// NSSAIAvailability PATCH method
func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDocument, nfId string) (
func NfInstancePatch(nssaiAvailabilityUpdateInfo plugin.PatchDocument, nfId string) (
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails,
) {
var (
Expand Down Expand Up @@ -83,7 +81,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc
}
factory.NssfConfig.RUnlock()
if !hitAmf {
*problemDetails = models.ProblemDetails{
problemDetails = &models.ProblemDetails{
Title: util.UNSUPPORTED_RESOURCE,
Status: http.StatusNotFound,
Detail: fmt.Sprintf("AMF ID '%s' does not exist", nfId),
Expand All @@ -110,7 +108,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc

patch, err := jsonpatch.DecodePatch(patchJSON)
if err != nil {
*problemDetails = models.ProblemDetails{
problemDetails = &models.ProblemDetails{
Title: util.MALFORMED_REQUEST,
Status: http.StatusBadRequest,
Detail: err.Error(),
Expand All @@ -120,7 +118,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc

modified, err := patch.Apply(original)
if err != nil {
*problemDetails = models.ProblemDetails{
problemDetails = &models.ProblemDetails{
Title: util.INVALID_REQUEST,
Status: http.StatusConflict,
Detail: err.Error(),
Expand All @@ -132,7 +130,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc
err = json.Unmarshal(modified, &factory.NssfConfig.Configuration.AmfList[amfIdx].SupportedNssaiAvailabilityData)
factory.NssfConfig.Unlock()
if err != nil {
*problemDetails = models.ProblemDetails{
problemDetails = &models.ProblemDetails{
Title: util.INVALID_REQUEST,
Status: http.StatusBadRequest,
Detail: err.Error(),
Expand All @@ -152,7 +150,7 @@ func NSSAIAvailabilityPatchProcedure(nssaiAvailabilityUpdateInfo plugin.PatchDoc
}

// NSSAIAvailability PUT method
func NSSAIAvailabilityPutProcedure(nssaiAvailabilityInfo models.NssaiAvailabilityInfo, nfId string) (
func NfInstanceUpdate(nssaiAvailabilityInfo models.NssaiAvailabilityInfo, nfId string) (
*models.AuthorizedNssaiAvailabilityInfo, *models.ProblemDetails,
) {
var (
Expand Down
Loading
Loading