Skip to content

Commit

Permalink
fix: new app interface
Browse files Browse the repository at this point in the history
  • Loading branch information
donald1218 committed May 1, 2024
1 parent 8abf37d commit 3c4187d
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 68 deletions.
2 changes: 1 addition & 1 deletion internal/nas/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Dispatch(ue *context.AmfUe, accessType models.AccessType, procedureCode int64, msg *nas.Message) error {
if msg.GmmMessage == nil {
return errors.New("Gmm Message is nil")
return errors.New("gmm Message is nil")
}

if msg.GsmMessage != nil {
Expand Down
5 changes: 3 additions & 2 deletions internal/nas/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,10 @@ func FuzzHandleNAS2(f *testing.F) {

f.Fuzz(func(t *testing.T, d []byte) {
ctrl := gomock.NewController(t)
m := service.NewMockApp(ctrl)
service.AMF = m
// m := app.NewMockApp(ctrl)
m := service.NewMockAmfAppInterface(ctrl)
c, err := consumer.NewConsumer(m)
service.AMF = m
require.NoError(t, err)
m.EXPECT().
Consumer().
Expand Down
17 changes: 6 additions & 11 deletions internal/sbi/consumer/consumer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package consumer

import (
"context"

amf_context "github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/pkg/factory"
"github.com/free5gc/amf/pkg/app"
"github.com/free5gc/openapi/Namf_Communication"
"github.com/free5gc/openapi/Nausf_UEAuthentication"
"github.com/free5gc/openapi/Nnrf_NFDiscovery"
Expand All @@ -16,14 +13,12 @@ import (
"github.com/free5gc/openapi/Nudm_UEContextManagement"
)

type amf interface {
Config() *factory.Config
Context() *amf_context.AMFContext
CancelContext() context.Context
type ConsumerAmf interface {
app.App
}

type Consumer struct {
amf
ConsumerAmf

// consumer services
*namfService
Expand All @@ -35,9 +30,9 @@ type Consumer struct {
*nausfService
}

func NewConsumer(amf amf) (*Consumer, error) {
func NewConsumer(amf ConsumerAmf) (*Consumer, error) {
c := &Consumer{
amf: amf,
ConsumerAmf: amf,
}

c.namfService = &namfService{
Expand Down
2 changes: 1 addition & 1 deletion internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (s *nnrfService) SendRegisterNFInstance(nrfUri, nfInstanceId string, profil

func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
logger.ConsumerLog.Infof("[AMF] Send Deregister NFInstance")
amfContext := s.consumer.amf.Context()
amfContext := s.consumer.Context()

client := s.getNFManagementClient(amfContext.NrfUri)
if client == nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package app

import (
amf_context "github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/pkg/factory"
)

type App interface {
SetLogEnable(enable bool)
SetLogLevel(level string)
SetReportCaller(reportCaller bool)

// tlsKeyLogPath would be remove
Start(tlsKeyLogPath string)
Terminate()

Context() *amf_context.AMFContext
Config() *factory.Config
}
129 changes: 129 additions & 0 deletions pkg/app/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import (
amf_context "github.com/free5gc/amf/internal/context"
"github.com/free5gc/amf/internal/logger"
"github.com/free5gc/amf/internal/sbi/consumer"
"github.com/free5gc/amf/pkg/app"
"github.com/free5gc/amf/pkg/factory"
)

var _ App = &AmfApp{}

type App interface {
Context() *amf_context.AMFContext
Config() *factory.Config
type AmfAppInterface interface {
app.App
consumer.ConsumerAmf
Consumer() *consumer.Consumer
}

var AMF AmfAppInterface

var _ app.App = &AmfApp{}

type AmfApp struct {
AmfAppInterface

cfg *factory.Config
amfCtx *amf_context.AMFContext
ctx context.Context
Expand All @@ -33,9 +38,7 @@ type AmfApp struct {
terminate func(*AmfApp)
}

var AMF App

func GetApp() App {
func GetApp() AmfAppInterface {
return AMF
}

Expand Down
Loading

0 comments on commit 3c4187d

Please sign in to comment.