Skip to content

Commit

Permalink
Merge pull request #29 from TYuan0816/refactor/server
Browse files Browse the repository at this point in the history
Refactor AUSF app, sbi, processor, consumer
  • Loading branch information
ianchen0119 authored Jun 28, 2024
2 parents 252a187 + d333b08 commit 842217c
Show file tree
Hide file tree
Showing 27 changed files with 1,834 additions and 1,863 deletions.
18 changes: 16 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
package main

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

"github.com/urfave/cli"

Expand Down Expand Up @@ -60,19 +63,30 @@ func action(cliCtx *cli.Context) error {

logger.MainLog.Infoln("AUSF 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 {
sigCh <- nil
return err
}
factory.AusfConfig = cfg

ausf, err := service.NewApp(cfg)
ausf, err := service.NewApp(ctx, cfg, tlsKeyLogPath)
if err != nil {
sigCh <- nil
return err
}
AUSF = ausf

ausf.Start(tlsKeyLogPath)
ausf.Start()

return nil
}
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
github.com/google/uuid v1.3.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.8.3
github.com/urfave/cli v1.22.5
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -22,7 +21,6 @@ require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand All @@ -40,7 +38,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
InitLog *logrus.Entry
CfgLog *logrus.Entry
CtxLog *logrus.Entry
SBILog *logrus.Entry
GinLog *logrus.Entry
ConsumerLog *logrus.Entry
UeAuthLog *logrus.Entry
Expand All @@ -33,6 +34,7 @@ func init() {
InitLog = NfLog.WithField(logger_util.FieldCategory, "Init")
CfgLog = NfLog.WithField(logger_util.FieldCategory, "CFG")
CtxLog = NfLog.WithField(logger_util.FieldCategory, "CTX")
SBILog = NfLog.WithField(logger_util.FieldCategory, "SBI")
GinLog = NfLog.WithField(logger_util.FieldCategory, "GIN")
ConsumerLog = NfLog.WithField(logger_util.FieldCategory, "Consumer")
UeAuthLog = NfLog.WithField(logger_util.FieldCategory, "UeAuth")
Expand Down
26 changes: 26 additions & 0 deletions internal/sbi/api_sorprotection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sbi

import (
"net/http"

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

func (s *Server) getSorprotectionRoutes() []Route {
return []Route{
{
Method: http.MethodGet,
Pattern: "/",
APIFunc: Index,
},
{
Method: http.MethodPost,
Pattern: "/:supi/ue-sor",
APIFunc: s.SupiUeSorPost,
},
}
}

func (s *Server) SupiUeSorPost(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{})
}
153 changes: 153 additions & 0 deletions internal/sbi/api_ueauthentication.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Nausf_UeAuthentication
*
* UeAuthentication Service
* © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC).
* All rights reserved.
*
* API version: 3.0.3
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package sbi

import (
"net/http"

"github.com/gin-gonic/gin"

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

// Index is the index handler.
func Index(c *gin.Context) {
c.String(http.StatusOK, "Hello World!")
}

func (s *Server) getUeAuthenticationRoutes() []Route {
return []Route{
{
Method: http.MethodGet,
Pattern: "/",
APIFunc: Index,
},
{
Method: http.MethodPost,
Pattern: "/ue-authentications/:authCtxId/eap-session",
APIFunc: s.EapAuthMethodPost,
},
{
Method: http.MethodPost,
Pattern: "/ue-authentications",
APIFunc: s.UeAuthenticationsPost,
},
{
Method: http.MethodPut,
Pattern: "/ue-authentications/:authCtxId/5g-aka-confirmation",
APIFunc: s.UeAuthenticationsAuthCtxID5gAkaConfirmationPut,
},
}
}

// EapAuthMethodPost -
func (s *Server) EapAuthMethodPost(c *gin.Context) {
var eapSessionReq models.EapSession

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

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

s.Processor().HandleEapAuthComfirmRequest(c, eapSessionReq, eapSessionId)
}

// UeAuthenticationsPost
func (s *Server) UeAuthenticationsPost(c *gin.Context) {
var authInfo models.AuthenticationInfo

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

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

s.Processor().HandleUeAuthPostRequest(c, authInfo)
}

// UeAuthenticationsAuthCtxID5gAkaConfirmationPut
func (s *Server) UeAuthenticationsAuthCtxID5gAkaConfirmationPut(c *gin.Context) {
var confirmationData models.ConfirmationData

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

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

s.Processor().HandleAuth5gAkaComfirmRequest(c, confirmationData, confirmationDataResponseId)
}
26 changes: 26 additions & 0 deletions internal/sbi/api_upuprotection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sbi

import (
"net/http"

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

func (s *Server) getUpuprotectionRoutes() []Route {
return []Route{
{
Method: http.MethodGet,
Pattern: "/",
APIFunc: Index,
},
{
Method: http.MethodPost,
Pattern: "/:supi/ue-upu",
APIFunc: s.SupiUeUpuPost,
},
}
}

func (s *Server) SupiUeUpuPost(c *gin.Context) {
c.JSON(http.StatusNotImplemented, gin.H{})
}
38 changes: 38 additions & 0 deletions internal/sbi/consumer/consumer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package consumer

import (
"github.com/free5gc/ausf/pkg/app"
"github.com/free5gc/openapi/Nnrf_NFDiscovery"
"github.com/free5gc/openapi/Nnrf_NFManagement"
"github.com/free5gc/openapi/Nudm_UEAuthentication"
)

type ConsumerAusf interface {
app.App
}

type Consumer struct {
ConsumerAusf

*nnrfService
*nudmService
}

func NewConsumer(ausf ConsumerAusf) (*Consumer, error) {
c := &Consumer{
ConsumerAusf: ausf,
}

c.nnrfService = &nnrfService{
consumer: c,
nfMngmntClients: make(map[string]*Nnrf_NFManagement.APIClient),
nfDiscClients: make(map[string]*Nnrf_NFDiscovery.APIClient),
}

c.nudmService = &nudmService{
consumer: c,
ueauClients: make(map[string]*Nudm_UEAuthentication.APIClient),
}

return c, nil
}
40 changes: 0 additions & 40 deletions internal/sbi/consumer/nf_discovery.go

This file was deleted.

Loading

0 comments on commit 842217c

Please sign in to comment.