From: is005q Date: Sun, 1 Dec 2019 16:56:34 +0000 (+0200) Subject: [RICPLT-2585 / RICPLT-1528] Fix E2TermInit payload / xAppMock fixes X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F88%2F1888%2F1;p=ric-plt%2Fe2mgr.git [RICPLT-2585 / RICPLT-1528] Fix E2TermInit payload / xAppMock fixes Change-Id: Idf38e38c85544b63b92bd75ede262088b72c066a Signed-off-by: is005q --- diff --git a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go index fd2ec81..ccb726c 100644 --- a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go @@ -22,6 +22,7 @@ import ( "e2mgr/managers" "e2mgr/models" "e2mgr/services" + "encoding/json" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" ) @@ -45,7 +46,15 @@ func (h E2TermInitNotificationHandler) Handle(request *models.NotificationReques h.logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT") - e2tAddress := string(request.Payload) // TODO: make sure E2T sends this as the only value of the message + unmarshalledPayload := models.E2TermInitPayload{} + err := json.Unmarshal(request.Payload, &unmarshalledPayload) + + if err != nil { + h.logger.Errorf("#E2TermInitNotificationHandler - Error unmarshaling E2 Term Init payload: %s", err) + return + } + + e2tAddress := unmarshalledPayload.Address e2tInstance, err := h.e2tInstancesManager.GetE2TInstance(e2tAddress) diff --git a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go index 6a20d33..d476b1f 100644 --- a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go @@ -34,6 +34,9 @@ import ( "testing" ) +const e2tInstanceAddress = "10.0.2.15" +const e2tInitPayload = "{\"address\":\"10.0.2.15\", \"fqdn\":\"\"}" + func initRanLostConnectionTest(t *testing.T) (*logger.Logger, E2TermInitNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock, *mocks.E2TInstancesManagerMock) { logger := initLog(t) @@ -57,32 +60,29 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, E2TermInitNotifica func TestE2TermInitGetE2TInstanceFailure(t *testing.T) { _, handler, _, _, _, e2tInstancesManagerMock := initRanLostConnectionTest(t) - e2tInstanceAddress := "10.0.2.15" var e2tInstance *entities.E2TInstance e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, common.NewInternalError(fmt.Errorf("internal error"))) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) e2tInstancesManagerMock.AssertNotCalled(t, "AddE2TInstance") } func TestE2TermInitNewE2TInstance(t *testing.T) { _, handler, _, _, _, e2tInstancesManagerMock := initRanLostConnectionTest(t) - e2tInstanceAddress := "10.0.2.15" var e2tInstance *entities.E2TInstance e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, common.NewResourceNotFoundError("not found")) e2tInstance = entities.NewE2TInstance(e2tInstanceAddress) e2tInstancesManagerMock.On("AddE2TInstance", e2tInstanceAddress).Return(nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) e2tInstancesManagerMock.AssertCalled(t, "AddE2TInstance", e2tInstanceAddress) } func TestE2TermInitExistingE2TInstanceNoAssociatedRans(t *testing.T) { _, handler, _, _, _, e2tInstancesManagerMock := initRanLostConnectionTest(t) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) e2tInstancesManagerMock.AssertCalled(t, "GetE2TInstance", e2tInstanceAddress) } @@ -103,11 +103,10 @@ func TestE2TerminInitHandlerSuccessOneRan(t *testing.T) { rmrMessengerMock.On("SendMsg", mock.Anything).Return(msg, nil) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, RanName) e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -134,11 +133,10 @@ func TestE2TerminInitHandlerSuccessTwoRans(t *testing.T) { rmrMessengerMock.On("SendMsg", mock.Anything).Return(msg, nil) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, RanName, "test2") e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -175,11 +173,10 @@ func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { rmrMessengerMock.On("SendMsg", mock.Anything).Return(msg0, fmt.Errorf("RMR Error")) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, "test1", "test2", "test3") e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -223,11 +220,10 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) rmrMessengerMock.On("SendMsg", mock.Anything).Return(msg0, nil) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, "test1", "test2", "test3") e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -272,11 +268,10 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te rmrMessengerMock.On("SendMsg", mock.Anything).Return(msg0, nil) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, "test1", "test2", "test3") e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -290,10 +285,9 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te func TestE2TerminInitHandlerSuccessZeroRans(t *testing.T) { _, handler, _, writerMock, rmrMessengerMock, e2tInstancesManagerMock := initRanLostConnectionTest(t) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) @@ -307,11 +301,10 @@ func TestE2TerminInitHandlerFailureGetListNodebIds(t *testing.T) { var nodebInfo *entities.NodebInfo readerMock.On("GetNodeb", "test1").Return(nodebInfo, common.NewInternalError(fmt.Errorf("internal error"))) - e2tInstanceAddress := "10.0.2.15" e2tInstance := entities.NewE2TInstance(e2tInstanceAddress) e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, "test1") e2tInstancesManagerMock.On("GetE2TInstance", e2tInstanceAddress).Return(e2tInstance, nil) - notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInstanceAddress)} + notificationRequest := &models.NotificationRequest{RanName: RanName, Payload: []byte(e2tInitPayload)} handler.Handle(notificationRequest) writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 0) diff --git a/E2Manager/models/e2_term_init_payload.go b/E2Manager/models/e2_term_init_payload.go new file mode 100644 index 0000000..0aa1521 --- /dev/null +++ b/E2Manager/models/e2_term_init_payload.go @@ -0,0 +1,6 @@ +package models + +type E2TermInitPayload struct { + Address string `json:"address"` + Fqdn string `json:"fqdn"` +} \ No newline at end of file diff --git a/tools/xappmock/main/xappmock.go b/tools/xappmock/main/xappmock.go index 4901de0..8ae62f7 100644 --- a/tools/xappmock/main/xappmock.go +++ b/tools/xappmock/main/xappmock.go @@ -100,7 +100,7 @@ func main() { pr := dispatcherDesc.GetProcessResult() if pr.Err != nil { - logger.Errorf("#main - command processing Error: %s", err) + logger.Errorf("#main - command processing Error: %s", pr.Err) } if pr.StartTime != nil { diff --git a/tools/xappmock/models/json_command.go b/tools/xappmock/models/json_command.go index 382ee8d..6ebd731 100644 --- a/tools/xappmock/models/json_command.go +++ b/tools/xappmock/models/json_command.go @@ -24,7 +24,6 @@ type JsonCommand struct { ReceiveCommandId string TransactionId string RanName string - Meid string RanIp string RanPort int PayloadHeader string diff --git a/tools/xappmock/rmr/rmrEndPoint.go b/tools/xappmock/rmr/rmrEndPoint.go index 957d4f0..82d01bd 100644 --- a/tools/xappmock/rmr/rmrEndPoint.go +++ b/tools/xappmock/rmr/rmrEndPoint.go @@ -32,9 +32,9 @@ func NewService(rmrConfig Config, messenger Messenger) *Service { } } -func (r *Service) SendMessage(messageType int, meid string, msg []byte, transactionId []byte) (*MBuf, error) { +func (r *Service) SendMessage(messageType int, ranName string, msg []byte, transactionId []byte) (*MBuf, error) { mbuf := NewMBuf(messageType, len(msg), msg, transactionId) - mbuf.Meid = meid + mbuf.Meid = ranName return (*r.messenger).SendMsg(mbuf) } diff --git a/tools/xappmock/sender/jsonSender.go b/tools/xappmock/sender/jsonSender.go index a40b675..7815f84 100644 --- a/tools/xappmock/sender/jsonSender.go +++ b/tools/xappmock/sender/jsonSender.go @@ -62,10 +62,10 @@ func (s *JsonSender) SendJsonRmrMessage(command models.JsonCommand /*the copy is } msg := append([]byte(command.PayloadHeader), payload...) - messageInfo := models.NewMessageInfo(int(rmrMsgId), command.Meid, msg, []byte(command.TransactionId)) + messageInfo := models.NewMessageInfo(int(rmrMsgId), command.RanName, msg, []byte(command.TransactionId)) s.logger.Infof("#JsonSender.SendJsonRmrMessage - going to send message: %s", messageInfo) - _, err = r.SendMessage(int(rmrMsgId), command.Meid, msg, []byte(command.TransactionId)) + _, err = r.SendMessage(int(rmrMsgId), command.RanName, msg, []byte(command.TransactionId)) return err }