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

Metric Function changes #91

Merged
merged 3 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/omec-project/amf/logger"
"github.com/omec-project/amf/metrics"
"github.com/omec-project/amf/protos/sdcoreAmfServer"
mi "github.com/omec-project/metricfunc/pkg/metricinfo"
"github.com/omec-project/ngap/ngapConvert"
"github.com/omec-project/ngap/ngapType"
"github.com/omec-project/openapi/models"
Expand Down Expand Up @@ -64,6 +65,12 @@ func NewSupportedTAIList() []SupportedTAI {
}

func (ran *AmfRan) Remove() {
//send nf(gnb) status notification
gnbStatus := mi.MetricEvent{EventType: mi.CNfStatusEvt,
NfStatusData: mi.CNfStatus{NfType: mi.NfTypeGnb,
NfStatus: mi.NfStatusDisconnected, NfName: ran.GnbId}}
metrics.StatWriter.PublishNfStatusEvent(gnbStatus)

ran.SetRanStats(RanDisconnected)
ran.Log.Infof("Remove RAN Context[ID: %+v]", ran.RanID())
ran.RemoveAllUeInRan()
Expand Down
47 changes: 47 additions & 0 deletions context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (

"github.com/omec-project/UeauCommon"
"github.com/omec-project/amf/logger"
"github.com/omec-project/amf/metrics"
"github.com/omec-project/amf/protos/sdcoreAmfServer"
"github.com/omec-project/fsm"
"github.com/omec-project/idgenerator"
mi "github.com/omec-project/metricfunc/pkg/metricinfo"
"github.com/omec-project/nas/nasMessage"
"github.com/omec-project/nas/nasType"
"github.com/omec-project/nas/security"
Expand Down Expand Up @@ -1023,3 +1025,48 @@ func (ue *AmfUe) NewEventChannel() (tx *EventChannel) {
//tx.Message <- msg
return tx
}

func getPublishUeCtxtInfoOp(state fsm.StateType) mi.SubscriberOp {

switch state {
case Deregistered:
return mi.SubsOpDel
case DeregistrationInitiated:
return mi.SubsOpDel
case Authentication:
return mi.SubsOpAdd
case SecurityMode:
return mi.SubsOpMod
case ContextSetup:
return mi.SubsOpMod
case Registered:
return mi.SubsOpMod
default:
return mi.SubsOpMod
}
}

//Collect Ctxt info and publish on Kafka stream
func (ueContext *AmfUe) PublishUeCtxtInfo() {
op := getPublishUeCtxtInfoOp(ueContext.State[models.AccessType__3_GPP_ACCESS].Current())
kafkaSmCtxt := mi.CoreSubscriber{}

//Populate kafka sm ctxt struct
kafkaSmCtxt.Imsi = ueContext.Supi
kafkaSmCtxt.AmfId = ueContext.servingAMF.NfId
kafkaSmCtxt.Guti = ueContext.Guti
kafkaSmCtxt.Tmsi = ueContext.Tmsi
kafkaSmCtxt.AmfIp = ueContext.AmfInstanceIp
if ueContext.RanUe != nil && ueContext.RanUe[models.AccessType__3_GPP_ACCESS] != nil {
kafkaSmCtxt.AmfNgapId = ueContext.RanUe[models.AccessType__3_GPP_ACCESS].AmfUeNgapId
kafkaSmCtxt.RanNgapId = ueContext.RanUe[models.AccessType__3_GPP_ACCESS].RanUeNgapId
kafkaSmCtxt.GnbId = ueContext.RanUe[models.AccessType__3_GPP_ACCESS].Ran.GnbId
kafkaSmCtxt.TacId = ueContext.RanUe[models.AccessType__3_GPP_ACCESS].Tai.Tac
}
kafkaSmCtxt.AmfSubState = string(ueContext.State[models.AccessType__3_GPP_ACCESS].Current())
ueState := ueContext.GetCmInfo()
kafkaSmCtxt.UeState = string(ueState[0].CmState)

//Send to stream
metrics.GetWriter().PublishUeCtxtEvent(kafkaSmCtxt, op)
}
1 change: 0 additions & 1 deletion context/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func SetupAmfCollection() {
factory.AmfConfig.Configuration.AmfDBName = "sdcore_amf"
}


if (factory.AmfConfig.Configuration.Mongodb != nil) &&
(factory.AmfConfig.Configuration.Mongodb.Url != "") {
mongoDbUrl = factory.AmfConfig.Configuration.Mongodb.Url
Expand Down
14 changes: 11 additions & 3 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ type Mongodb struct {
Url string `yaml:"url"`
}

type KafkaInfo struct {
BrokerUri string `yaml:"brokerUri,omitempty"`
BrokerPort int `yaml:"brokerPort,omitempty"`
Topic string `yaml:"topicName,omitempty"`
}

type Configuration struct {
AmfName string `yaml:"amfName,omitempty"`
AmfDBName string `yaml:"amfDBName,omitempty"`
Expand Down Expand Up @@ -70,9 +76,11 @@ type Configuration struct {
T3565 TimerValue `yaml:"t3565"`

//Maintain TaiList per slice
SliceTaiList map[string][]models.Tai `yaml:"sliceTaiList,omitempty"`
EnableSctpLb bool `yaml:"enableSctpLb"`
EnableDbStore bool `yaml:"enableDBStore"`
SliceTaiList map[string][]models.Tai `yaml:"sliceTaiList,omitempty"`
EnableSctpLb bool `yaml:"enableSctpLb"`
EnableDbStore bool `yaml:"enableDBStore"`
KafkaInfo KafkaInfo `yaml:"kafkaInfo,omitempty"`
DebugProfilePort int `yaml:"debugProfilePort,omitempty"`
}

func (c *Configuration) Get5gsNwFeatSuppEnable() bool {
Expand Down
2 changes: 2 additions & 0 deletions gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func transport5GSMMessage(ue *context.AmfUe, anType models.AccessType,
newSmContext.SetUserLocation(deepcopy.Copy(ue.Location).(models.UserLocation))
ue.StoreSmContext(pduSessionID, newSmContext)
ue.GmmLog.Infof("create smContext[pduSessionID: %d] Success", pduSessionID)
ue.PublishUeCtxtInfo()
// TODO: handle response(response N2SmInfo to RAN if exists)
}
}
Expand Down Expand Up @@ -363,6 +364,7 @@ func forward5GSMMessageToSMF(
ngap_message.SendDownlinkNasTransport(ue.RanUe[accessType], n1Msg, nil)
}
}
ue.PublishUeCtxtInfo()
return nil
}

Expand Down
7 changes: 5 additions & 2 deletions gmm/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func Registered(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
amfUe.ClearRegistrationRequestData(accessType)
amfUe.GmmLog.Debugln("EntryEvent at GMM State[Registered]")
//store context in DB. Registration procedure is complete.
amfUe.PublishUeCtxtInfo()
context.StoreContextInDB(amfUe)
case GmmMessageEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
Expand Down Expand Up @@ -198,6 +199,7 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
if err := HandleAuthenticationResponse(amfUe, accessType, gmmMessage.AuthenticationResponse); err != nil {
logger.GmmLog.Errorln(err)
}
amfUe.PublishUeCtxtInfo()
case nas.MsgTypeAuthenticationFailure:
if err := HandleAuthenticationFailure(amfUe, accessType, gmmMessage.AuthenticationFailure); err != nil {
logger.GmmLog.Errorln(err)
Expand Down Expand Up @@ -245,7 +247,7 @@ func SecurityMode(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
amfUe.TxLog = amfUe.NASLog.WithField(logger.FieldSupi, fmt.Sprintf("SUPI:%s", amfUe.Supi))
amfUe.GmmLog = amfUe.GmmLog.WithField(logger.FieldSupi, fmt.Sprintf("SUPI:%s", amfUe.Supi))
amfUe.ProducerLog = logger.ProducerLog.WithField(logger.FieldSupi, fmt.Sprintf("SUPI:%s", amfUe.Supi))

amfUe.PublishUeCtxtInfo()
amfUe.GmmLog.Debugln("EntryEvent at GMM State[SecurityMode]")
if amfUe.SecurityContextIsValid() {
amfUe.GmmLog.Debugln("UE has a valid security context - skip security mode control procedure")
Expand Down Expand Up @@ -357,7 +359,7 @@ func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
gmmMessage := args[ArgNASMessage]
accessType := args[ArgAccessType].(models.AccessType)
amfUe.GmmLog.Debugln("EntryEvent at GMM State[ContextSetup]")

amfUe.PublishUeCtxtInfo()
switch message := gmmMessage.(type) {
case *nasMessage.RegistrationRequest:
amfUe.RegistrationRequest = message
Expand Down Expand Up @@ -462,6 +464,7 @@ func DeregisteredInitiated(state *fsm.State, event fsm.EventType, args fsm.ArgsT
}
}
}
amfUe.PublishUeCtxtInfo()
case GmmMessageEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
gmmMessage := args[ArgNASMessage].(*nas.GmmMessage)
Expand Down
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.7.3
github.com/gin-gonic/gin v1.8.1
github.com/google/uuid v1.3.0
github.com/mitchellh/mapstructure v1.4.1
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
Expand All @@ -25,16 +25,19 @@ require (
github.com/omec-project/ngap v1.1.0
github.com/omec-project/openapi v1.1.0
github.com/omec-project/path_util v1.1.0
github.com/prometheus/client_golang v1.13.0
github.com/omec-project/util v1.0.6
github.com/prometheus/client_golang v1.11.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.8.0
github.com/urfave/cli v1.22.4
github.com/urfave/cli v1.22.9
go.mongodb.org/mongo-driver v1.10.1
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
)

require github.com/leodido/go-urn v1.2.1 // indirect
require (
github.com/omec-project/metricfunc v1.1.1
github.com/segmentio/kafka-go v0.4.38
)