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: Refactor SMF consumer processor service #104

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a52a61a
refactor: consumer nrf_service smf_service udm_service
ming-hsien Apr 24, 2024
f60eaa1
fixed: datapath.go (Correction by mistake)
ming-hsien Apr 28, 2024
19e8cff
fixed: nrf_service (move SendNFDiscoveryXXX from udm_service to nrf_s…
ming-hsien Apr 29, 2024
711ae11
Merge branch 'refator/sbi-logic' of https://github.com/ming-hsien/smf…
ming-hsien Apr 29, 2024
ecd42ed
refactor: copy server side code
pf-lin Apr 27, 2024
b489313
refactor: implement server structure & add two services (callback and…
pf-lin Apr 28, 2024
5182a61
refactor: add processor & remove legacy code
pf-lin Apr 30, 2024
e1f71aa
refactor: consumer (pcf_service, chf_service), Pull out APIClient fro…
ming-hsien Apr 30, 2024
a374ca2
fix: import cycle
pf-lin May 3, 2024
b3794fc
Merge branch 'free5gc:main' into refactor/sbi-logic
ming-hsien May 8, 2024
2cf5c7f
fix: nrf_service (move SendNFDiscoveryXXX from udm_service to nrf_ser…
ming-hsien Apr 29, 2024
c2b12ed
refactor: copy server side code
pf-lin Apr 27, 2024
aec59c4
refactor: implement server structure & add two services (callback and…
pf-lin Apr 28, 2024
69955db
refactor: add processor & remove legacy code
pf-lin Apr 30, 2024
e612db0
refactor: consumer (pcf_service, chf_service), Pull out APIClient fro…
ming-hsien Apr 30, 2024
86f6630
fix: import cycle
pf-lin May 3, 2024
ad52ae2
Bump golang.org/x/net from 0.17.0 to 0.23.0 (#102)
dependabot[bot] Apr 23, 2024
504e918
feat: Create commit-msg-check.yml
andy89923 May 2, 2024
0a508ec
Merge branch 'refactor/sbi-logic' of github.com:ming-hsien/smf into r…
ming-hsien May 8, 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
17 changes: 15 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"github.com/free5gc/smf/pkg/factory"
"github.com/free5gc/smf/pkg/service"
logger_util "github.com/free5gc/util/logger"
"github.com/free5gc/smf/pkg/utils"
"github.com/free5gc/util/version"
)

Expand Down Expand Up @@ -59,8 +60,18 @@

logger.MainLog.Infoln("SMF 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.SmfConfig = cfg
Expand All @@ -71,13 +82,15 @@
}
factory.UERoutingConfig = ueRoutingCfg

smf, err := service.NewApp(cfg)
pfcpStart, pfcpTerminate := utils.InitPFCPFunc()
smf, err := service.NewApp(cfg, tlsKeyLogPath, pfcpStart, pfcpTerminate)
if err != nil {
return err
}
SMF = smf

smf.Start(tlsKeyLogPath)
smf.Start()

Check failure on line 92 in cmd/main.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

Error return value of `smf.Start` is not checked (errcheck)
// SMF.WaitRoutineStopped()

return nil
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/smartystreets/goconvey v1.6.4
github.com/stretchr/testify v1.8.3
github.com/urfave/cli v1.22.5
go.uber.org/mock v0.4.0
gopkg.in/h2non/gock.v1 v1.1.2
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 @@ -239,6 +239,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
3 changes: 2 additions & 1 deletion internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type SMFContext struct {
ListenAddr string

UDMProfile models.NfProfile
NfProfile NFProfile

Key string
PEM string
Expand Down Expand Up @@ -255,7 +256,7 @@ func InitSmfContext(config *factory.Config) {

smfContext.ChargingIDGenerator = idgenerator.NewGenerator(1, math.MaxUint32)

SetupNFProfile(config)
smfContext.SetupNFProfile(config)

smfContext.Locality = configuration.Locality

Expand Down
22 changes: 11 additions & 11 deletions internal/context/nf_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import (
"github.com/free5gc/smf/pkg/factory"
)

var NFProfile struct {
type NFProfile struct {
NFServices *[]models.NfService
NFServiceVersion *[]models.NfServiceVersion
SMFInfo *models.SmfInfo
PLMNList *[]models.PlmnId
}

func SetupNFProfile(config *factory.Config) {
func (c *SMFContext) SetupNFProfile(NFProfileconfig *factory.Config) {
// Set time
nfSetupTime := time.Now()

// set NfServiceVersion
NFProfile.NFServiceVersion = &[]models.NfServiceVersion{
c.NfProfile.NFServiceVersion = &[]models.NfServiceVersion{
{
ApiVersionInUri: "v1",
ApiFullVersion: fmt.
Expand All @@ -30,28 +30,28 @@ func SetupNFProfile(config *factory.Config) {
}

// set NFServices
NFProfile.NFServices = new([]models.NfService)
for _, serviceName := range config.Configuration.ServiceNameList {
*NFProfile.NFServices = append(*NFProfile.NFServices, models.NfService{
c.NfProfile.NFServices = new([]models.NfService)
for _, serviceName := range NFProfileconfig.Configuration.ServiceNameList {
*c.NfProfile.NFServices = append(*c.NfProfile.NFServices, models.NfService{
ServiceInstanceId: GetSelf().NfInstanceID + serviceName,
ServiceName: models.ServiceName(serviceName),
Versions: NFProfile.NFServiceVersion,
Versions: c.NfProfile.NFServiceVersion,
Scheme: models.UriScheme_HTTPS,
NfServiceStatus: models.NfServiceStatus_REGISTERED,
ApiPrefix: fmt.Sprintf("%s://%s:%d", GetSelf().URIScheme, GetSelf().RegisterIPv4, GetSelf().SBIPort),
})
}

// set smfInfo
NFProfile.SMFInfo = &models.SmfInfo{
c.NfProfile.SMFInfo = &models.SmfInfo{
SNssaiSmfInfoList: SNssaiSmfInfo(),
}

// set PlmnList if exists
if plmnList := config.Configuration.PLMNList; plmnList != nil {
NFProfile.PLMNList = new([]models.PlmnId)
if plmnList := NFProfileconfig.Configuration.PLMNList; plmnList != nil {
c.NfProfile.PLMNList = new([]models.PlmnId)
for _, plmn := range plmnList {
*NFProfile.PLMNList = append(*NFProfile.PLMNList, models.PlmnId{
*c.NfProfile.PLMNList = append(*c.NfProfile.PLMNList, models.PlmnId{
Mcc: plmn.Mcc,
Mnc: plmn.Mnc,
})
Expand Down
29 changes: 3 additions & 26 deletions internal/context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ import (
"time"

"github.com/antihax/optional"
"github.com/google/uuid"
"github.com/sirupsen/logrus"

"github.com/free5gc/nas/nasConvert"
"github.com/free5gc/nas/nasMessage"
"github.com/free5gc/ngap/ngapType"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Namf_Communication"
"github.com/free5gc/openapi/Nchf_ConvergedCharging"
"github.com/free5gc/openapi/Nnrf_NFDiscovery"
"github.com/free5gc/openapi/Npcf_SMPolicyControl"
"github.com/free5gc/openapi/models"
"github.com/free5gc/pfcp/pfcpType"
"github.com/free5gc/smf/internal/logger"
"github.com/free5gc/smf/pkg/factory"

"github.com/free5gc/util/idgenerator"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -159,9 +157,7 @@ type SMContext struct {
UpSecurityFromPathSwitchRequestSameAsLocalStored bool

// Client
SMPolicyClient *Npcf_SMPolicyControl.APIClient
CommunicationClient *Namf_Communication.APIClient
ChargingClient *Nchf_ConvergedCharging.APIClient

AMFProfile models.NfProfile
SelectedPCFProfile models.NfProfile
Expand Down Expand Up @@ -506,18 +502,8 @@ func (smContext *SMContext) CHFSelection() error {
}

// Select CHF from available CHF

smContext.SelectedCHFProfile = rsp.NfInstances[0]

// Create Converged Charging Client for this SM Context
for _, service := range *smContext.SelectedCHFProfile.NfServices {
if service.ServiceName == models.ServiceName_NCHF_CONVERGEDCHARGING {
ConvergedChargingConf := Nchf_ConvergedCharging.NewConfiguration()
ConvergedChargingConf.SetBasePath(service.ApiPrefix)
smContext.ChargingClient = Nchf_ConvergedCharging.NewAPIClient(ConvergedChargingConf)
}
}

return nil
}

Expand Down Expand Up @@ -561,15 +547,6 @@ func (smContext *SMContext) PCFSelection() error {

smContext.SelectedPCFProfile = rsp.NfInstances[0]

// Create SMPolicyControl Client for this SM Context
for _, service := range *smContext.SelectedPCFProfile.NfServices {
if service.ServiceName == models.ServiceName_NPCF_SMPOLICYCONTROL {
SmPolicyControlConf := Npcf_SMPolicyControl.NewConfiguration()
SmPolicyControlConf.SetBasePath(service.ApiPrefix)
smContext.SMPolicyClient = Npcf_SMPolicyControl.NewAPIClient(SmPolicyControlConf)
}
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
CfgLog *logrus.Entry
CtxLog *logrus.Entry
GinLog *logrus.Entry
SBILog *logrus.Entry
ConsumerLog *logrus.Entry
GsmLog *logrus.Entry
PfcpLog *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")
GsmLog = NfLog.WithField(logger_util.FieldCategory, "GSM")
PfcpLog = NfLog.WithField(logger_util.FieldCategory, "PFCP")
Expand Down
4 changes: 2 additions & 2 deletions internal/pfcp/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
smf_context "github.com/free5gc/smf/internal/context"
"github.com/free5gc/smf/internal/logger"
pfcp_message "github.com/free5gc/smf/internal/pfcp/message"
"github.com/free5gc/smf/internal/sbi/producer"
"github.com/free5gc/smf/pkg/service"
)

func HandlePfcpHeartbeatRequest(msg *pfcpUdp.Message) {
Expand Down Expand Up @@ -200,7 +200,7 @@ func HandlePfcpSessionReportRequest(msg *pfcpUdp.Message) {
// After receiving the Usage Report, it should send charging request to the CHF
// and update the URR with the quota or other charging information according to
// the charging response
producer.ReportUsageAndUpdateQuota(smContext)
service.GetApp().Processor().ReportUsageAndUpdateQuota(smContext)
}

// TS 23.502 4.2.3.3 2b. Send Data Notification Ack, SMF->UPF
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
/*
* Nsmf_EventExposure
*
* Session Management Event Exposure Service API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package callback
package sbi

import (
"net/http"
Expand All @@ -18,12 +9,32 @@ import (
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/models"
"github.com/free5gc/smf/internal/logger"
"github.com/free5gc/smf/internal/sbi/producer"
"github.com/free5gc/smf/internal/sbi/processor"
"github.com/free5gc/util/httpwrapper"
)

func (s *Server) getCallbackRoutes() []Route {
return []Route{
{
Method: http.MethodPost,
Pattern: "/sm-policies/:smContextRef/update",
APIFunc: s.HTTPSmPolicyUpdateNotification,
},
{
Method: http.MethodPost,
Pattern: "/sm-policies/:smContextRef/terminate",
APIFunc: s.SmPolicyControlTerminationRequestNotification,
},
{
Method: http.MethodPost,
Pattern: "/:notifyUri",
APIFunc: s.HTTPChargingNotification,
},
}
}

// SubscriptionsPost -
func HTTPSmPolicyUpdateNotification(c *gin.Context) {
func (s *Server) HTTPSmPolicyUpdateNotification(c *gin.Context) {
var request models.SmPolicyNotification

reqBody, err := c.GetRawData()
Expand All @@ -40,7 +51,7 @@ func HTTPSmPolicyUpdateNotification(c *gin.Context) {
reqWrapper.Params["smContextRef"] = c.Params.ByName("smContextRef")

smContextRef := reqWrapper.Params["smContextRef"]
HTTPResponse := producer.HandleSMPolicyUpdateNotify(smContextRef, reqWrapper.Body.(models.SmPolicyNotification))
HTTPResponse := processor.HandleSMPolicyUpdateNotify(smContextRef, reqWrapper.Body.(models.SmPolicyNotification))

for key, val := range HTTPResponse.Header {
c.Header(key, val[0])
Expand All @@ -58,11 +69,11 @@ func HTTPSmPolicyUpdateNotification(c *gin.Context) {
c.Status(HTTPResponse.Status)
}

func SmPolicyControlTerminationRequestNotification(c *gin.Context) {
func (s *Server) SmPolicyControlTerminationRequestNotification(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

func HTTPChargingNotification(c *gin.Context) {
func (s *Server) HTTPChargingNotification(c *gin.Context) {
var req models.ChargingNotifyRequest

requestBody, err := c.GetRawData()
Expand All @@ -79,7 +90,7 @@ func HTTPChargingNotification(c *gin.Context) {
reqWrapper.Params["notifyUri"] = c.Params.ByName("notifyUri")
smContextRef := strings.Split(reqWrapper.Params["notifyUri"], "_")[1]

HTTPResponse := producer.HandleChargingNotification(reqWrapper.Body.(models.ChargingNotifyRequest), smContextRef)
HTTPResponse := s.processor.HandleChargingNotification(reqWrapper.Body.(models.ChargingNotifyRequest), smContextRef)

for key, val := range HTTPResponse.Header {
c.Header(key, val[0])
Expand Down
68 changes: 68 additions & 0 deletions internal/sbi/api_eventexposure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Nsmf_EventExposure
*
* Session Management Event Exposure Service API
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/

package sbi

import (
"net/http"

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

func (s *Server) getEventExposureRoutes() []Route {
return []Route{
{
Method: http.MethodGet,
Pattern: "/",
APIFunc: func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{"status": "Service Available"})
},
},
{
Method: http.MethodPost,
Pattern: "subscriptions",
APIFunc: s.SubscriptionsPost,
},
{
Method: http.MethodDelete,
Pattern: "subscriptions/:subId",
APIFunc: s.SubscriptionsSubIdDelete,
},
{
Method: http.MethodGet,
Pattern: "subscriptions/:subId",
APIFunc: s.SubscriptionsSubIdGet,
},
{
Method: http.MethodPut,
Pattern: "subscriptions/:subId",
APIFunc: s.SubscriptionsSubIdPut,
},
}
}

// SubscriptionsPost -
func (s *Server) SubscriptionsPost(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

// SubscriptionsSubIdDelete -
func (s *Server) SubscriptionsSubIdDelete(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

// SubscriptionsSubIdGet -
func (s *Server) SubscriptionsSubIdGet(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}

// SubscriptionsSubIdPut -
func (s *Server) SubscriptionsSubIdPut(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{})
}
Loading
Loading