diff --git a/context/amf_ran.go b/context/amf_ran.go index 2abf5647..291858a6 100644 --- a/context/amf_ran.go +++ b/context/amf_ran.go @@ -180,6 +180,18 @@ func (ran *AmfRan) ConvertGnbIdToRanId(gnbId string) (ranNodeId *models.GlobalRa return ranId } +func (ran *AmfRan) ConvertN3iwfIdToRanId(n3iwfId string) (ranNodeId *models.GlobalRanNodeId) { + ranId := &models.GlobalRanNodeId{} + val := strings.Split(n3iwfId, ":") + if len(val) != 3 { + return nil + } + ranId.PlmnId = &models.PlmnId{Mcc: val[0], Mnc: val[1]} + ranId.N3IwfId = val[2] + ran.RanPresent = RanPresentN3IwfId + return ranId +} + func (ran *AmfRan) RanID() string { switch ran.RanPresent { case RanPresentGNbId: diff --git a/nas/handler.go b/nas/handler.go index af998494..1a003e0a 100644 --- a/nas/handler.go +++ b/nas/handler.go @@ -48,7 +48,11 @@ func HandleNAS(ctx ctxt.Context, ue *context.RanUe, procedureCode int64, nasPdu rsp.AmfId = os.Getenv("HOSTNAME") /* TODO for this release setting pod ip to simplify logic in sctplb */ rsp.RedirectId = id.PodIp - rsp.GnbId = ue.Ran.GnbId + if ue.Ran.RanPresent == context.RanPresentN3IwfId { + rsp.N3IwfId = ue.Ran.GnbId + } else { + rsp.GnbId = ue.Ran.GnbId + } rsp.Msg = ue.SctplbMsg if ue.AmfUe != nil { ue.AmfUe.Remove() @@ -72,7 +76,11 @@ func HandleNAS(ctx ctxt.Context, ue *context.RanUe, procedureCode int64, nasPdu // we dont call this function when AMF restarts. So we // need to set the AnType from stored Information. if amfSelf.EnableSctpLb { - ue.Ran.AnType = models.AccessType__3_GPP_ACCESS + if ue.Ran.RanPresent == context.RanPresentN3IwfId { + ue.Ran.AnType = models.AccessType_NON_3_GPP_ACCESS + } else { + ue.Ran.AnType = models.AccessType__3_GPP_ACCESS + } } ue.AmfUe.AttachRanUe(ue) diff --git a/ngap/dispatcher.go b/ngap/dispatcher.go index b8d8c552..0bf3d3f5 100644 --- a/ngap/dispatcher.go +++ b/ngap/dispatcher.go @@ -22,6 +22,7 @@ import ( "github.com/omec-project/amf/protos/sdcoreAmfServer" "github.com/omec-project/ngap" "github.com/omec-project/ngap/ngapType" + "github.com/omec-project/openapi/models" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -43,6 +44,16 @@ func DispatchLb(ctx ctxt.Context, sctplbMsg *sdcoreAmfServer.SctplbMessage, Amf2 ran.Amf2RanMsgChan = Amf2RanMsgChan logger.NgapLog.Infof("dispatchLb, Create new Amf RAN", sctplbMsg.GnbId) } + } else if sctplbMsg.N3IwfId != "" { + var ok bool + ran, ok = amfSelf.AmfRanFindByGnbId(sctplbMsg.N3IwfId) + if !ok { + logger.NgapLog.Infof("create a new NG connection for N3IWF: %s", sctplbMsg.N3IwfId) + ran = amfSelf.NewAmfRanId(sctplbMsg.N3IwfId) + ran.RanId = ran.ConvertN3iwfIdToRanId(sctplbMsg.N3IwfId) + ran.AnType = models.AccessType_NON_3_GPP_ACCESS + ran.Amf2RanMsgChan = Amf2RanMsgChan + } } else if sctplbMsg.GnbIpAddr != "" { logger.NgapLog.Infoln("GnbIpAddress received but no GnbId") ran = &context.AmfRan{} @@ -84,7 +95,11 @@ func DispatchLb(ctx ctxt.Context, sctplbMsg *sdcoreAmfServer.SctplbMessage, Amf2 /* TODO set only pod name, for this release setting pod ip to simplify logic in sctplb */ logger.NgapLog.Infof("dispatchLb, amfNgapId: %v is not for this amf instance, redirect to amf instance: %v %v", ngapId.Value, id.PodName, id.PodIp) rsp.RedirectId = id.PodIp - rsp.GnbId = ran.GnbId + if ran.RanPresent == context.RanPresentN3IwfId { + rsp.N3IwfId = ran.GnbId + } else { + rsp.GnbId = ran.GnbId + } rsp.Msg = make([]byte, len(sctplbMsg.Msg)) copy(rsp.Msg, sctplbMsg.Msg) ran.Amf2RanMsgChan = Amf2RanMsgChan diff --git a/ngap/handler.go b/ngap/handler.go index 81a920cc..324d65ee 100644 --- a/ngap/handler.go +++ b/ngap/handler.go @@ -1565,7 +1565,11 @@ func HandleInitialUEMessage(ctx ctxt.Context, ran *context.AmfRan, message *ngap rsp.AmfId = os.Getenv("HOSTNAME") /* TODO for this release setting pod ip to simplify logic in sctplb */ rsp.RedirectId = id.PodIp - rsp.GnbId = ran.GnbId + if ran.RanPresent == context.RanPresentN3IwfId { + rsp.N3IwfId = ran.GnbId + } else { + rsp.GnbId = ran.GnbId + } rsp.Msg = sctplbMsg.Msg if ranUe != nil && ranUe.AmfUe != nil { ranUe.AmfUe.Remove() diff --git a/ngap/message/send.go b/ngap/message/send.go index 19a1e0fa..add2c6c9 100644 --- a/ngap/message/send.go +++ b/ngap/message/send.go @@ -41,7 +41,11 @@ func SendToRan(ran *context.AmfRan, packet []byte) { msg.Msgtype = sdcoreAmfServer.MsgType_AMF_MSG msg.AmfId = os.Getenv("HOSTNAME") msg.GnbIpAddr = ran.GnbIp - msg.GnbId = ran.GnbId + if ran.RanPresent == context.RanPresentN3IwfId { + msg.N3IwfId = ran.GnbId + } else { + msg.GnbId = ran.GnbId + } ran.Amf2RanMsgChan <- msg } else { if ran.Conn == nil { diff --git a/protos/sdcoreAmfServer/server.pb.go b/protos/sdcoreAmfServer/server.pb.go index f47bca9e..fe9ad048 100644 --- a/protos/sdcoreAmfServer/server.pb.go +++ b/protos/sdcoreAmfServer/server.pb.go @@ -5,17 +5,16 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.35.1 -// protoc v5.28.2 -// source: server.proto +// protoc v3.21.12 +// source: protos/server.proto package sdcoreAmfServer import ( - reflect "reflect" - sync "sync" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) const ( @@ -35,6 +34,9 @@ const ( MsgType_REDIRECT_MSG MsgType = 4 MsgType_GNB_DISC MsgType = 5 MsgType_GNB_CONN MsgType = 6 + MsgType_N3IWF_MSG MsgType = 7 + MsgType_N3IWF_DISC MsgType = 8 + MsgType_N3IWF_CONN MsgType = 9 ) // Enum value maps for MsgType. @@ -47,6 +49,9 @@ var ( 4: "REDIRECT_MSG", 5: "GNB_DISC", 6: "GNB_CONN", + 7: "N3IWF_MSG", + 8: "N3IWF_DISC", + 9: "N3IWF_CONN", } MsgType_value = map[string]int32{ "UNKNOWN": 0, @@ -56,6 +61,9 @@ var ( "REDIRECT_MSG": 4, "GNB_DISC": 5, "GNB_CONN": 6, + "N3IWF_MSG": 7, + "N3IWF_DISC": 8, + "N3IWF_CONN": 9, } ) @@ -70,11 +78,11 @@ func (x MsgType) String() string { } func (MsgType) Descriptor() protoreflect.EnumDescriptor { - return file_server_proto_enumTypes[0].Descriptor() + return file_protos_server_proto_enumTypes[0].Descriptor() } func (MsgType) Type() protoreflect.EnumType { - return &file_server_proto_enumTypes[0] + return &file_protos_server_proto_enumTypes[0] } func (x MsgType) Number() protoreflect.EnumNumber { @@ -83,7 +91,7 @@ func (x MsgType) Number() protoreflect.EnumNumber { // Deprecated: Use MsgType.Descriptor instead. func (MsgType) EnumDescriptor() ([]byte, []int) { - return file_server_proto_rawDescGZIP(), []int{0} + return file_protos_server_proto_rawDescGZIP(), []int{0} } type SctplbMessage struct { @@ -97,11 +105,12 @@ type SctplbMessage struct { VerboseMsg string `protobuf:"bytes,4,opt,name=VerboseMsg,proto3" json:"VerboseMsg,omitempty"` Msg []byte `protobuf:"bytes,5,opt,name=Msg,proto3" json:"Msg,omitempty"` GnbId string `protobuf:"bytes,6,opt,name=GnbId,proto3" json:"GnbId,omitempty"` + N3IwfId string `protobuf:"bytes,7,opt,name=N3iwfId,proto3" json:"N3iwfId,omitempty"` } func (x *SctplbMessage) Reset() { *x = SctplbMessage{} - mi := &file_server_proto_msgTypes[0] + mi := &file_protos_server_proto_msgTypes[0] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -113,7 +122,7 @@ func (x *SctplbMessage) String() string { func (*SctplbMessage) ProtoMessage() {} func (x *SctplbMessage) ProtoReflect() protoreflect.Message { - mi := &file_server_proto_msgTypes[0] + mi := &file_protos_server_proto_msgTypes[0] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -126,7 +135,7 @@ func (x *SctplbMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use SctplbMessage.ProtoReflect.Descriptor instead. func (*SctplbMessage) Descriptor() ([]byte, []int) { - return file_server_proto_rawDescGZIP(), []int{0} + return file_protos_server_proto_rawDescGZIP(), []int{0} } func (x *SctplbMessage) GetSctplbId() string { @@ -171,6 +180,13 @@ func (x *SctplbMessage) GetGnbId() string { return "" } +func (x *SctplbMessage) GetN3IwfId() string { + if x != nil { + return x.N3IwfId + } + return "" +} + type AmfMessage struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -183,11 +199,12 @@ type AmfMessage struct { GnbId string `protobuf:"bytes,5,opt,name=GnbId,proto3" json:"GnbId,omitempty"` VerboseMsg string `protobuf:"bytes,6,opt,name=VerboseMsg,proto3" json:"VerboseMsg,omitempty"` Msg []byte `protobuf:"bytes,7,opt,name=Msg,proto3" json:"Msg,omitempty"` + N3IwfId string `protobuf:"bytes,8,opt,name=N3iwfId,proto3" json:"N3iwfId,omitempty"` } func (x *AmfMessage) Reset() { *x = AmfMessage{} - mi := &file_server_proto_msgTypes[1] + mi := &file_protos_server_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -199,7 +216,7 @@ func (x *AmfMessage) String() string { func (*AmfMessage) ProtoMessage() {} func (x *AmfMessage) ProtoReflect() protoreflect.Message { - mi := &file_server_proto_msgTypes[1] + mi := &file_protos_server_proto_msgTypes[1] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -212,7 +229,7 @@ func (x *AmfMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use AmfMessage.ProtoReflect.Descriptor instead. func (*AmfMessage) Descriptor() ([]byte, []int) { - return file_server_proto_rawDescGZIP(), []int{1} + return file_protos_server_proto_rawDescGZIP(), []int{1} } func (x *AmfMessage) GetAmfId() string { @@ -264,75 +281,88 @@ func (x *AmfMessage) GetMsg() []byte { return nil } -var File_server_proto protoreflect.FileDescriptor +func (x *AmfMessage) GetN3IwfId() string { + if x != nil { + return x.N3IwfId + } + return "" +} -var file_server_proto_rawDesc = []byte{ - 0x0a, 0x0c, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, - 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, - 0xc5, 0x01, 0x0a, 0x0d, 0x53, 0x63, 0x74, 0x70, 0x6c, 0x62, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x74, 0x70, 0x6c, 0x62, 0x49, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x53, 0x63, 0x74, 0x70, 0x6c, 0x62, 0x49, 0x64, 0x12, 0x32, 0x0a, - 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, +var File_protos_server_proto protoreflect.FileDescriptor + +var file_protos_server_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, + 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0xdf, 0x01, 0x0a, 0x0d, 0x53, 0x63, 0x74, 0x70, 0x6c, + 0x62, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x53, 0x63, 0x74, 0x70, + 0x6c, 0x62, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x53, 0x63, 0x74, 0x70, + 0x6c, 0x62, 0x49, 0x64, 0x12, 0x32, 0x0a, 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, + 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x52, + 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x47, 0x6e, 0x62, 0x49, + 0x70, 0x41, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x47, 0x6e, 0x62, + 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, + 0x65, 0x4d, 0x73, 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x56, 0x65, 0x72, 0x62, + 0x6f, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x47, 0x6e, 0x62, 0x49, + 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x47, 0x6e, 0x62, 0x49, 0x64, 0x12, 0x18, + 0x0a, 0x07, 0x4e, 0x33, 0x69, 0x77, 0x66, 0x49, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x4e, 0x33, 0x69, 0x77, 0x66, 0x49, 0x64, 0x22, 0xf6, 0x01, 0x0a, 0x0a, 0x41, 0x6d, 0x66, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x6d, 0x66, 0x49, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x6d, 0x66, 0x49, 0x64, 0x12, 0x1e, 0x0a, + 0x0a, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x49, 0x64, 0x12, 0x32, 0x0a, + 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, - 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x47, 0x6e, 0x62, 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x18, 0x03, + 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x47, 0x6e, 0x62, 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x47, 0x6e, 0x62, 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, - 0x1e, 0x0a, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, - 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, 0x4d, 0x73, - 0x67, 0x12, 0x14, 0x0a, 0x05, 0x47, 0x6e, 0x62, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x47, 0x6e, 0x62, 0x49, 0x64, 0x22, 0xdc, 0x01, 0x0a, 0x0a, 0x41, 0x6d, 0x66, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x41, 0x6d, 0x66, 0x49, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x41, 0x6d, 0x66, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, - 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0a, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x49, 0x64, 0x12, 0x32, 0x0a, 0x07, - 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x18, 0x2e, - 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, - 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x52, 0x07, 0x4d, 0x73, 0x67, 0x74, 0x79, 0x70, 0x65, - 0x12, 0x1c, 0x0a, 0x09, 0x47, 0x6e, 0x62, 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x47, 0x6e, 0x62, 0x49, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, 0x14, - 0x0a, 0x05, 0x47, 0x6e, 0x62, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x47, - 0x6e, 0x62, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, 0x4d, - 0x73, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, - 0x65, 0x4d, 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x0c, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x2a, 0x6c, 0x0a, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0c, - 0x0a, 0x08, 0x49, 0x4e, 0x49, 0x54, 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, - 0x47, 0x4e, 0x42, 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x41, 0x4d, 0x46, - 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, 0x52, 0x45, 0x44, 0x49, 0x52, 0x45, - 0x43, 0x54, 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x47, 0x4e, 0x42, 0x5f, - 0x44, 0x49, 0x53, 0x43, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x47, 0x4e, 0x42, 0x5f, 0x43, 0x4f, - 0x4e, 0x4e, 0x10, 0x06, 0x32, 0x61, 0x0a, 0x0b, 0x4e, 0x67, 0x61, 0x70, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x12, 0x52, 0x0a, 0x0d, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, - 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x63, 0x74, 0x70, 0x6c, 0x62, 0x4d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x1a, 0x1b, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, - 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x41, 0x6d, 0x66, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x73, 0x64, 0x63, - 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x14, 0x0a, 0x05, 0x47, 0x6e, 0x62, 0x49, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x47, 0x6e, 0x62, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, 0x73, 0x65, + 0x4d, 0x73, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x56, 0x65, 0x72, 0x62, 0x6f, + 0x73, 0x65, 0x4d, 0x73, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, 0x67, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x4e, 0x33, 0x69, 0x77, 0x66, + 0x49, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x4e, 0x33, 0x69, 0x77, 0x66, 0x49, + 0x64, 0x2a, 0x9b, 0x01, 0x0a, 0x07, 0x6d, 0x73, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, + 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x49, 0x4e, + 0x49, 0x54, 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x47, 0x4e, 0x42, 0x5f, + 0x4d, 0x53, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x41, 0x4d, 0x46, 0x5f, 0x4d, 0x53, 0x47, + 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, 0x52, 0x45, 0x44, 0x49, 0x52, 0x45, 0x43, 0x54, 0x5f, 0x4d, + 0x53, 0x47, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x47, 0x4e, 0x42, 0x5f, 0x44, 0x49, 0x53, 0x43, + 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x47, 0x4e, 0x42, 0x5f, 0x43, 0x4f, 0x4e, 0x4e, 0x10, 0x06, + 0x12, 0x0d, 0x0a, 0x09, 0x4e, 0x33, 0x49, 0x57, 0x46, 0x5f, 0x4d, 0x53, 0x47, 0x10, 0x07, 0x12, + 0x0e, 0x0a, 0x0a, 0x4e, 0x33, 0x49, 0x57, 0x46, 0x5f, 0x44, 0x49, 0x53, 0x43, 0x10, 0x08, 0x12, + 0x0e, 0x0a, 0x0a, 0x4e, 0x33, 0x49, 0x57, 0x46, 0x5f, 0x43, 0x4f, 0x4e, 0x4e, 0x10, 0x09, 0x32, + 0x61, 0x0a, 0x0b, 0x4e, 0x67, 0x61, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x52, + 0x0a, 0x0d, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, + 0x1e, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x2e, 0x53, 0x63, 0x74, 0x70, 0x6c, 0x62, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x1a, + 0x1b, 0x2e, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x2e, 0x41, 0x6d, 0x66, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, 0x01, + 0x30, 0x01, 0x42, 0x13, 0x5a, 0x11, 0x2e, 0x2f, 0x73, 0x64, 0x63, 0x6f, 0x72, 0x65, 0x41, 0x6d, + 0x66, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - file_server_proto_rawDescOnce sync.Once - file_server_proto_rawDescData = file_server_proto_rawDesc + file_protos_server_proto_rawDescOnce sync.Once + file_protos_server_proto_rawDescData = file_protos_server_proto_rawDesc ) -func file_server_proto_rawDescGZIP() []byte { - file_server_proto_rawDescOnce.Do(func() { - file_server_proto_rawDescData = protoimpl.X.CompressGZIP(file_server_proto_rawDescData) +func file_protos_server_proto_rawDescGZIP() []byte { + file_protos_server_proto_rawDescOnce.Do(func() { + file_protos_server_proto_rawDescData = protoimpl.X.CompressGZIP(file_protos_server_proto_rawDescData) }) - return file_server_proto_rawDescData + return file_protos_server_proto_rawDescData } -var file_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_server_proto_msgTypes = make([]protoimpl.MessageInfo, 2) -var file_server_proto_goTypes = []any{ +var file_protos_server_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_protos_server_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_protos_server_proto_goTypes = []any{ (MsgType)(0), // 0: sdcoreAmfServer.msgType (*SctplbMessage)(nil), // 1: sdcoreAmfServer.SctplbMessage (*AmfMessage)(nil), // 2: sdcoreAmfServer.AmfMessage } -var file_server_proto_depIdxs = []int32{ +var file_protos_server_proto_depIdxs = []int32{ 0, // 0: sdcoreAmfServer.SctplbMessage.Msgtype:type_name -> sdcoreAmfServer.msgType 0, // 1: sdcoreAmfServer.AmfMessage.Msgtype:type_name -> sdcoreAmfServer.msgType 1, // 2: sdcoreAmfServer.NgapService.HandleMessage:input_type -> sdcoreAmfServer.SctplbMessage @@ -344,28 +374,28 @@ var file_server_proto_depIdxs = []int32{ 0, // [0:2] is the sub-list for field type_name } -func init() { file_server_proto_init() } -func file_server_proto_init() { - if File_server_proto != nil { +func init() { file_protos_server_proto_init() } +func file_protos_server_proto_init() { + if File_protos_server_proto != nil { return } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_server_proto_rawDesc, + RawDescriptor: file_protos_server_proto_rawDesc, NumEnums: 1, NumMessages: 2, NumExtensions: 0, NumServices: 1, }, - GoTypes: file_server_proto_goTypes, - DependencyIndexes: file_server_proto_depIdxs, - EnumInfos: file_server_proto_enumTypes, - MessageInfos: file_server_proto_msgTypes, + GoTypes: file_protos_server_proto_goTypes, + DependencyIndexes: file_protos_server_proto_depIdxs, + EnumInfos: file_protos_server_proto_enumTypes, + MessageInfos: file_protos_server_proto_msgTypes, }.Build() - File_server_proto = out.File - file_server_proto_rawDesc = nil - file_server_proto_goTypes = nil - file_server_proto_depIdxs = nil + File_protos_server_proto = out.File + file_protos_server_proto_rawDesc = nil + file_protos_server_proto_goTypes = nil + file_protos_server_proto_depIdxs = nil } diff --git a/protos/sdcoreAmfServer/server_grpc.pb.go b/protos/sdcoreAmfServer/server_grpc.pb.go index 737bbfce..527fedff 100644 --- a/protos/sdcoreAmfServer/server_grpc.pb.go +++ b/protos/sdcoreAmfServer/server_grpc.pb.go @@ -1,20 +1,18 @@ // SPDX-FileCopyrightText: 2022-present Intel Corporation // SPDX-FileCopyrightText: 2021 Open Networking Foundation -// Copyright 2019 free5GC.org // // SPDX-License-Identifier: Apache-2.0 -// + // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.21.5 -// source: server.proto +// - protoc v3.21.12 +// source: protos/server.proto package sdcoreAmfServer import ( context "context" - grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -140,5 +138,5 @@ var NgapService_ServiceDesc = grpc.ServiceDesc{ ClientStreams: true, }, }, - Metadata: "server.proto", + Metadata: "protos/server.proto", } diff --git a/protos/server.proto b/protos/server.proto index 76b1d7dc..90141558 100644 --- a/protos/server.proto +++ b/protos/server.proto @@ -6,32 +6,37 @@ package sdcoreAmfServer; option go_package = "./sdcoreAmfServer"; enum msgType { - UNKNOWN = 0; - INIT_MSG = 1; - GNB_MSG = 2; - AMF_MSG = 3; + UNKNOWN = 0; + INIT_MSG = 1; + GNB_MSG = 2; + AMF_MSG = 3; REDIRECT_MSG = 4; - GNB_DISC = 5; - GNB_CONN = 6; + GNB_DISC = 5; + GNB_CONN = 6; + N3IWF_MSG = 7; + N3IWF_DISC = 8; + N3IWF_CONN = 9; } message SctplbMessage { - string SctplbId = 1; - msgType Msgtype = 2; - string GnbIpAddr = 3; - string VerboseMsg = 4; - bytes Msg = 5; - string GnbId = 6; + string SctplbId = 1; + msgType Msgtype = 2; + string GnbIpAddr = 3; + string VerboseMsg = 4; + bytes Msg = 5; + string GnbId = 6; + string N3iwfId = 7; } message AmfMessage { - string AmfId = 1; - string RedirectId = 2; - msgType Msgtype = 3; - string GnbIpAddr = 4; - string GnbId = 5; - string VerboseMsg = 6; - bytes Msg = 7; + string AmfId = 1; + string RedirectId = 2; + msgType Msgtype = 3; + string GnbIpAddr = 4; + string GnbId = 5; + string VerboseMsg = 6; + bytes Msg = 7; + string N3iwfId = 8; } service NgapService { diff --git a/service/amf_server.go b/service/amf_server.go index efe854ee..7a9bdcb7 100644 --- a/service/amf_server.go +++ b/service/amf_server.go @@ -17,6 +17,7 @@ import ( "github.com/omec-project/amf/metrics" "github.com/omec-project/amf/ngap" "github.com/omec-project/amf/protos/sdcoreAmfServer" + "github.com/omec-project/openapi/models" mi "github.com/omec-project/util/metricinfo" "google.golang.org/grpc" ) @@ -56,26 +57,36 @@ func (s *Server) HandleMessage(srv sdcoreAmfServer.NgapService_HandleMessageServ amfSelf := amfContext.AMF_Self() var ran *amfContext.AmfRan var ok bool - if ran, ok = amfSelf.AmfRanFindByGnbId(req.GnbId); !ok { - ran = amfSelf.NewAmfRanId(req.GnbId) - if req.GnbId != "" { - ran.GnbId = req.GnbId - ran.RanId = ran.ConvertGnbIdToRanId(ran.GnbId) - logger.GrpcLog.Debugf("RanID: %v for GnbId: %v", ran.RanID(), req.GnbId) - rsp.GnbId = req.GnbId + if req.N3IwfId != "" { + if ran, ok = amfSelf.AmfRanFindByGnbId(req.N3IwfId); !ok { + ran = amfSelf.NewAmfRanId(req.N3IwfId) + ran.RanId = ran.ConvertN3iwfIdToRanId(req.N3IwfId) + ran.AnType = models.AccessType_NON_3_GPP_ACCESS + logger.GrpcLog.Debugf("new N3IWF RAN: %v", req.N3IwfId) + } + rsp.N3IwfId = req.N3IwfId + } else { + if ran, ok = amfSelf.AmfRanFindByGnbId(req.GnbId); !ok { + ran = amfSelf.NewAmfRanId(req.GnbId) + if req.GnbId != "" { + ran.GnbId = req.GnbId + ran.RanId = ran.ConvertGnbIdToRanId(ran.GnbId) + logger.GrpcLog.Debugf("RanID: %v for GnbId: %v", ran.RanID(), req.GnbId) + rsp.GnbId = req.GnbId - // send nf(gnb) status notification - gnbStatus := mi.MetricEvent{ - EventType: mi.CNfStatusEvt, - NfStatusData: mi.CNfStatus{ - NfType: mi.NfTypeGnb, - NfStatus: mi.NfStatusConnected, NfName: req.GnbId, - }, - } + // send nf(gnb) status notification + gnbStatus := mi.MetricEvent{ + EventType: mi.CNfStatusEvt, + NfStatusData: mi.CNfStatus{ + NfType: mi.NfTypeGnb, + NfStatus: mi.NfStatusConnected, NfName: req.GnbId, + }, + } - if *factory.AmfConfig.Configuration.KafkaInfo.EnableKafka { - if err := metrics.StatWriter.PublishNfStatusEvent(gnbStatus); err != nil { - logger.GrpcLog.Errorf("error publishing NfStatusEvent: %v", err) + if *factory.AmfConfig.Configuration.KafkaInfo.EnableKafka { + if err := metrics.StatWriter.PublishNfStatusEvent(gnbStatus); err != nil { + logger.GrpcLog.Errorf("error publishing NfStatusEvent: %v", err) + } } } } @@ -115,6 +126,35 @@ func (s *Server) HandleMessage(srv sdcoreAmfServer.NgapService_HandleMessageServ logger.GrpcLog.Errorf("error publishing NfStatusEvent: %v", err) } } + case sdcoreAmfServer.MsgType_N3IWF_DISC: + logger.GrpcLog.Infoln("N3IWF disconnected") + ngap.HandleSCTPNotificationLb(req.N3IwfId) + n3iwfStatus := mi.MetricEvent{ + EventType: mi.CNfStatusEvt, + NfStatusData: mi.CNfStatus{ + NfType: mi.NfTypeGnb, + NfStatus: mi.NfStatusDisconnected, NfName: req.N3IwfId, + }, + } + if *factory.AmfConfig.Configuration.KafkaInfo.EnableKafka { + if err := metrics.StatWriter.PublishNfStatusEvent(n3iwfStatus); err != nil { + logger.GrpcLog.Errorf("error publishing NfStatusEvent: %v", err) + } + } + case sdcoreAmfServer.MsgType_N3IWF_CONN: + logger.GrpcLog.Infoln("new N3IWF Connected") + n3iwfStatus := mi.MetricEvent{ + EventType: mi.CNfStatusEvt, + NfStatusData: mi.CNfStatus{ + NfType: mi.NfTypeGnb, + NfStatus: mi.NfStatusConnected, NfName: req.N3IwfId, + }, + } + if *factory.AmfConfig.Configuration.KafkaInfo.EnableKafka { + if err := metrics.StatWriter.PublishNfStatusEvent(n3iwfStatus); err != nil { + logger.GrpcLog.Errorf("error publishing NfStatusEvent: %v", err) + } + } default: ngap.DispatchLb(ctx, req, Amf2RanMsgChan) }