Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ func NewSupportedTAIList() []SupportedTAI {
return make([]SupportedTAI, 0, maxNumOfTAI*maxNumOfBroadcastPLMNs)
}

// NewAmfRanDefault returns a bare AmfRan with Log pre-initialised to the
// package-level NgapLog. All AmfRan construction paths that lack an address
// or ID at creation time should use this function so that ran.Log is never
// nil when ran itself is non-nil.
func NewAmfRanDefault() *AmfRan {
return &AmfRan{Log: logger.NgapLog}
}

// RatInformationForTAC returns the RATInformation advertised by this RAN
// for the given TAC, or nil when the RAN's NGSetup did not carry the
// optional extension for that TAC.
Expand Down
19 changes: 9 additions & 10 deletions gmm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ func TestHandleMobilityAndPeriodicRegistrationUpdatingRejectsNilRegistrationRequ
AllowedNssai: make(map[models.AccessType][]models.AllowedSnssai),
State: make(map[models.AccessType]*fsm.State),
}
ran := &context.AmfRan{
AnType: models.ACCESSTYPE__3_GPP_ACCESS,
Log: zap.NewNop().Sugar(),
}
ran := context.NewAmfRanDefault()
ran.AnType = models.ACCESSTYPE__3_GPP_ACCESS
ue.RanUe[models.ACCESSTYPE__3_GPP_ACCESS] = &context.RanUe{
AmfUe: ue,
Ran: ran,
Expand Down Expand Up @@ -316,10 +314,13 @@ func TestHandleServiceRequestHighPriorityAccessHandledAsData(t *testing.T) {
ue.OnGoing[models.ACCESSTYPE__3_GPP_ACCESS] = &context.OnGoingProcedureWithPrio{Procedure: context.OnGoingProcedureNothing}
ue.NgKsi.Ksi = 1

ran := context.NewAmfRanDefault()
ran.AnType = models.ACCESSTYPE__3_GPP_ACCESS

ranUe := &context.RanUe{
AmfUe: ue,
Log: zap.NewNop().Sugar(),
Ran: &context.AmfRan{AnType: models.ACCESSTYPE__3_GPP_ACCESS, Log: zap.NewNop().Sugar()},
Ran: ran,
Tai: models.Tai{
PlmnId: models.PlmnId{Mcc: "001", Mnc: "01"},
Tac: "000002",
Expand Down Expand Up @@ -464,11 +465,9 @@ func TestHandleInitialRegistrationSnapshotsRegistrationRequest(t *testing.T) {
ue.State[models.ACCESSTYPE__3_GPP_ACCESS] = fsm.NewState(context.Deregistered)
ue.State[models.ACCESSTYPE_NON_3_GPP_ACCESS] = fsm.NewState(context.Deregistered)

ran := &context.AmfRan{
Log: zap.NewNop().Sugar(),
RanId: models.NewGlobalRanNodeId(models.PlmnId{Mcc: "001", Mnc: "01"}),
GnbIp: "10.0.0.1",
}
ran := context.NewAmfRanDefault()
ran.RanId = models.NewGlobalRanNodeId(models.PlmnId{Mcc: "001", Mnc: "01"})
ran.GnbIp = "10.0.0.1"
ranUe := &context.RanUe{
AmfUe: ue,
Ran: ran,
Expand Down
33 changes: 11 additions & 22 deletions ngap/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func DispatchLb(ctx ctxt.Context, sctplbMsg *sdcoreAmfServer.SctplbMessage, Amf2
}
} else if sctplbMsg.GnbIpAddr != "" {
logger.NgapLog.Infoln("GnbIpAddress received but no GnbId")
ran = &context.AmfRan{}
ran = context.NewAmfRanDefault()
ran.SupportedTAList = context.NewSupportedTAIList()
ran.Amf2RanMsgChan = Amf2RanMsgChan
ran.Log = logger.NgapLog.With(logger.FieldRanAddr, sctplbMsg.GnbIpAddr)
Expand Down Expand Up @@ -190,12 +190,13 @@ func NgapMsgHandler(ue *context.AmfUe, msg context.NgapMsg) {
}

func DispatchNgapMsg(ctx ctxt.Context, ran *context.AmfRan, pdu *ngapType.NGAPPDU, sctplbMsg *sdcoreAmfServer.SctplbMessage) {
if ran == nil {
logger.NgapLog.Errorln("DispatchNgapMsg called with nil RAN")
return
}

if pdu == nil {
if ran != nil && ran.Log != nil {
ran.Log.Errorln("DispatchNgapMsg received nil NGAP PDU")
} else {
logger.NgapLog.Errorln("DispatchNgapMsg received nil NGAP PDU")
}
ran.Log.Errorln("DispatchNgapMsg received nil NGAP PDU")
return
}
Comment thread
gab-arrobo marked this conversation as resolved.

Expand All @@ -217,7 +218,7 @@ func DispatchNgapMsg(ctx ctxt.Context, ran *context.AmfRan, pdu *ngapType.NGAPPD
procName := ngapType.ProcedureName(code)

peer := "unknown"
if ran != nil && ran.Conn != nil {
if ran.Conn != nil {
if addr := ran.Conn.RemoteAddr(); addr != nil {
peer = addr.String()
}
Expand All @@ -243,11 +244,7 @@ func DispatchNgapMsg(ctx ctxt.Context, ran *context.AmfRan, pdu *ngapType.NGAPPD
case ngapType.NGAPPDUPresentInitiatingMessage:
initiatingMessage := pdu.InitiatingMessage
if initiatingMessage == nil {
if ran != nil && ran.Log != nil {
ran.Log.Errorln("Initiating Message is nil")
} else {
logger.NgapLog.Errorln("Initiating Message is nil")
}
ran.Log.Errorln("Initiating Message is nil")
return
}

Expand Down Expand Up @@ -309,11 +306,7 @@ func DispatchNgapMsg(ctx ctxt.Context, ran *context.AmfRan, pdu *ngapType.NGAPPD
case ngapType.NGAPPDUPresentSuccessfulOutcome:
successfulOutcome := pdu.SuccessfulOutcome
if successfulOutcome == nil {
if ran != nil && ran.Log != nil {
ran.Log.Errorln("successful Outcome is nil")
} else {
logger.NgapLog.Errorln("successful Outcome is nil")
}
ran.Log.Errorln("successful Outcome is nil")
return
}
metrics.IncrementNgapMsgStats(context.AMF_Self().NfId,
Expand Down Expand Up @@ -348,11 +341,7 @@ func DispatchNgapMsg(ctx ctxt.Context, ran *context.AmfRan, pdu *ngapType.NGAPPD
case ngapType.NGAPPDUPresentUnsuccessfulOutcome:
unsuccessfulOutcome := pdu.UnsuccessfulOutcome
if unsuccessfulOutcome == nil {
if ran != nil && ran.Log != nil {
ran.Log.Errorln("unsuccessful Outcome is nil")
} else {
logger.NgapLog.Errorln("unsuccessful Outcome is nil")
}
ran.Log.Errorln("unsuccessful Outcome is nil")
return
}
metrics.IncrementNgapMsgStats(context.AMF_Self().NfId,
Expand Down
3 changes: 1 addition & 2 deletions ngap/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/omec-project/amf/context"
"github.com/omec-project/amf/protos/sdcoreAmfServer"
"go.uber.org/zap"
)

func TestDispatchLbIgnoresMissingRanContext(t *testing.T) {
Expand All @@ -29,7 +28,7 @@ func TestDispatchLbIgnoresMissingRanContext(t *testing.T) {
}

func TestDispatchNgapMsgIgnoresNilPdu(t *testing.T) {
ran := &context.AmfRan{Log: zap.NewNop().Sugar()}
ran := context.NewAmfRanDefault()

defer func() {
if recovered := recover(); recovered != nil {
Expand Down
Loading
Loading