2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
21 package rmrmsghandlers
34 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
35 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
36 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
41 func initX2ResetRequestNotificationHandlerTest(t *testing.T) (X2ResetRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RmrMessengerMock) {
43 config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
44 readerMock := &mocks.RnibReaderMock{}
45 readerProvider := func() reader.RNibReader {
48 rnibDataService := services.NewRnibDataService(log, config, readerProvider, nil)
50 rmrMessengerMock := &mocks.RmrMessengerMock{}
51 rmrSender := initRmrSender(rmrMessengerMock, log)
52 ranStatusChangeManager := managers.NewRanStatusChangeManager(log, rmrSender)
53 h := NewX2ResetRequestNotificationHandler(log, rnibDataService, ranStatusChangeManager, rmrSender)
54 return h, readerMock, rmrMessengerMock
57 func getRanRestartedMbuf(nodeType entities.Node_Type, messageDirection enums.MessageDirection) *rmrCgo.MBuf {
58 xaction := []byte(RanName)
59 resourceStatusPayload := models.NewResourceStatusPayload(nodeType, messageDirection)
60 resourceStatusJson, _ := json.Marshal(resourceStatusPayload)
61 return rmrCgo.NewMBuf(rmrCgo.RAN_RESTARTED, len(resourceStatusJson), RanName, &resourceStatusJson, &xaction)
64 func TestHandleX2ResetRequestNotificationSuccess(t *testing.T) {
65 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
67 xaction := []byte(ranName)
68 notificationRequest := models.NewNotificationRequest(ranName, []byte{}, time.Now(), ranName)
70 nb := &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, NodeType: entities.Node_ENB}
72 readerMock.On("GetNodeb", ranName).Return(nb, err)
73 resetResponseMbuf := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET_RESP, len(e2pdus.PackedX2ResetResponse), ranName, &e2pdus.PackedX2ResetResponse, &xaction)
74 rmrMessengerMock.On("SendMsg", resetResponseMbuf).Return(&rmrCgo.MBuf{}, err)
75 ranRestartedMbuf := getRanRestartedMbuf(nb.NodeType, enums.RAN_TO_RIC)
76 rmrMessengerMock.On("SendMsg", ranRestartedMbuf).Return(&rmrCgo.MBuf{}, err)
77 h.Handle(notificationRequest)
78 rmrMessengerMock.AssertCalled(t, "SendMsg", resetResponseMbuf)
79 rmrMessengerMock.AssertCalled(t, "SendMsg", ranRestartedMbuf)
82 func TestHandleX2ResetRequestNotificationShuttingDownStatus(t *testing.T) {
83 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
86 xaction := []byte("RanName")
87 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
88 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
89 StartTime: time.Now(), TransactionId: string(xaction)}
91 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN,}
94 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
96 h.Handle(¬ificationRequest)
97 rmrMessengerMock.AssertNotCalled(t, "SendMsg")
100 func TestHandleX2ResetRequestNotificationDisconnectStatus(t *testing.T) {
101 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
103 xaction := []byte("RanName")
104 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
105 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(), TransactionId: string(xaction)}
106 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,}
108 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
110 h.Handle(¬ificationRequest)
111 rmrMessengerMock.AssertNotCalled(t, "SendMsg")
114 func TestHandleX2ResetRequestNotificationGetNodebFailed(t *testing.T) {
116 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
118 xaction := []byte("RanName")
119 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
120 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
121 StartTime: time.Now(), TransactionId: string(xaction)}
123 var nb *entities.NodebInfo
124 rnibErr := &common.ResourceNotFoundError{}
125 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
127 h.Handle(¬ificationRequest)
128 rmrMessengerMock.AssertNotCalled(t, "SendMsg")