From 0e58b60a82f5912f815be9292fe0c072a80b79a7 Mon Sep 17 00:00:00 2001 From: is005q Date: Mon, 9 Sep 2019 16:10:41 +0300 Subject: [PATCH] [RICPLT-1854] Refactor X2/ENDC Setup/Setup Failure Response Change-Id: I73742cbe41230eaf15f3463fcbcc9a98afae3491 Signed-off-by: is005q --- .../endc_configuration_update_handler.go | 4 + .../endc_setup_response_notification_handler.go | 75 --------- ...2Setup_failure_response_notification_handler.go | 74 --------- .../rmrmsghandlers/notification_handler.go | 6 + .../setup_response_notification_handler.go | 22 +-- .../setup_response_notification_handler_bak.go | 48 ------ ...setup_response_notification_handler_bak_test.go | 60 ------- .../setup_response_notification_handler_test.go | 172 +++++++++++++++++++++ ...2Setup_failure_response_notification_handler.go | 71 --------- .../x2apSetup_response_notification_handler.go | 75 --------- .../x2enb_configuration_update_handler.go | 21 +-- E2Manager/main/http_server_test.go | 62 ++++---- .../endc_setup_failure_response_manager.go | 30 ++++ E2Manager/managers/endc_setup_response_manager.go | 33 ++++ .../managers/x2_setup_failure_response_manager.go | 7 +- E2Manager/managers/x2_setup_response_manager.go | 36 ++--- .../notification_handler_provider.go | 16 +- .../notification_handler_provider_test.go | 12 +- 18 files changed, 337 insertions(+), 487 deletions(-) delete mode 100644 E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go delete mode 100644 E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go delete mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go delete mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go create mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_test.go delete mode 100644 E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go delete mode 100644 E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go diff --git a/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go index a988d48..ea8c000 100644 --- a/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go @@ -34,6 +34,10 @@ import ( type EndcConfigurationUpdateHandler struct{} +func NewEndcConfigurationUpdateHandler() EndcConfigurationUpdateHandler { + return EndcConfigurationUpdateHandler{} +} + func (src EndcConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { diff --git a/E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go deleted file mode 100644 index 14ac6da..0000000 --- a/E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package rmrmsghandlers - -import ( - "e2mgr/converters" - "e2mgr/e2pdus" - "e2mgr/logger" - "e2mgr/models" - "e2mgr/rNibWriter" - "e2mgr/sessions" - "fmt" - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" -) - -type EndcX2SetupResponseNotificationHandler struct{} - -func (src EndcX2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - - e2session, ok := e2Sessions[request.TransactionId] - gnbId, gnb, err := converters.UnpackEndcX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) - - if err != nil { - logger.Errorf("#endc_setup_response_notification_handler.Handle - unpack failed. Error: %v", err) - } - - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#endc_setup_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime) - if ok { - - if gnb != nil { - nb := &entities.NodebInfo{} - nbIdentity := &entities.NbIdentity{} - - nbIdentity.InventoryName = e2session.Request.RanName - nbIdentity.GlobalNbId = gnbId - nb.GlobalNbId = nbIdentity.GlobalNbId - nb.RanName = e2session.Request.RanName - nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED - nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST - nb.Ip = e2session.Request.RanIp - nb.Port = uint32(e2session.Request.RanPort) - nb.NodeType = entities.Node_GNB - nb.Configuration = &entities.NodebInfo_Gnb{Gnb: gnb} - - //insert/update database - if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil { - logger.Errorf("#endc_setup_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save GNB data for gnbId: %v. Error: %s", request.TransactionId, gnbId, rNibErr.Error()) - } else { - logger.Infof("#endc_setup_response_notification_handler.Handle - transactionId %s: saved to rNib gnbId: %v", request.TransactionId, gnbId) - if logger.DebugEnabled() { - logger.Debugf("#endc_setup_response_notification_handler..Handle - transactionId %s: saved to rNib gnbId: %v, v:[%s]", request.TransactionId, gnbId, fmt.Sprintf("%s %s", nb.ConnectionStatus, gnb.ServedNrCells)) - } - } - - } - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#endc_setup_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart) - delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) - } - -} diff --git a/E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go deleted file mode 100644 index 46a245e..0000000 --- a/E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package rmrmsghandlers - -import ( - "e2mgr/converters" - "e2mgr/e2pdus" - "e2mgr/rNibWriter" - "fmt" - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" - - "e2mgr/logger" - "e2mgr/models" - "e2mgr/sessions" -) - -type EndcX2SetupFailureResponseNotificationHandler struct{} - -func (src EndcX2SetupFailureResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - - e2session, ok := e2Sessions[request.TransactionId] - - failureResponse, err := converters.UnpackEndcX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) - if err != nil { - logger.Errorf("#endc_x2Setup_failure_response_notification_handler.Handle - unpack failed. Error: %v", err) - } - - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#endc_x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime) - if ok { - if failureResponse != nil { - nb := &entities.NodebInfo{} - nbIdentity := &entities.NbIdentity{} - - nb.RanName = e2session.Request.RanName - nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED - nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST - nb.Ip = e2session.Request.RanIp - nb.Port = uint32(e2session.Request.RanPort) - nb.SetupFailure = failureResponse - nb.FailureType = entities.Failure_ENDC_X2_SETUP_FAILURE - nbIdentity.InventoryName = e2session.Request.RanName - - //insert/update database - if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil { - logger.Errorf("#endc_x2Setup_failure_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save failure response data. Error: %s", request.TransactionId, rNibErr.Error()) - } else { - logger.Infof("#endc_x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib", request.TransactionId) - if logger.DebugEnabled() { - logger.Debugf("#endc_x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib , value:[%s]", request.TransactionId, fmt.Sprintf("%s %s", nb.ConnectionStatus, failureResponse)) - } - } - } - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#endc_x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart) - delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) - } - - -} diff --git a/E2Manager/handlers/rmrmsghandlers/notification_handler.go b/E2Manager/handlers/rmrmsghandlers/notification_handler.go index a44b965..ae25dde 100644 --- a/E2Manager/handlers/rmrmsghandlers/notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/notification_handler.go @@ -21,8 +21,14 @@ import ( "e2mgr/logger" "e2mgr/models" "e2mgr/sessions" + "time" ) type NotificationHandler interface { Handle(*logger.Logger, sessions.E2Sessions, *models.NotificationRequest, chan<- *models.NotificationResponse) } + +//TODO: remove that +func printHandlingSetupResponseElapsedTimeInMs(logger *logger.Logger, msg string, startTime time.Time) { + logger.Infof("%s: %f ms", msg, float64(time.Since(startTime))/float64(time.Millisecond)) +} \ No newline at end of file diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go index 86843ef..99329ff 100644 --- a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go @@ -30,33 +30,37 @@ type SetupResponseNotificationHandler struct { rnibReaderProvider func() reader.RNibReader rnibWriterProvider func() rNibWriter.RNibWriter setupResponseManager managers.ISetupResponseManager + notificationType string } -func NewSetupResponseNotificationHandler(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, setupResponseManager managers.ISetupResponseManager) SetupResponseNotificationHandler { +func NewSetupResponseNotificationHandler(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, setupResponseManager managers.ISetupResponseManager, notificationType string) SetupResponseNotificationHandler { return SetupResponseNotificationHandler{ rnibReaderProvider: rnibReaderProvider, rnibWriterProvider: rnibWriterProvider, setupResponseManager: setupResponseManager, + notificationType: notificationType, } } func (h SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - logger.Infof("#SetupResponseNotificationHandler - RAN name : %s - Received X2 Setup Response Notification", request.RanName) + logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Received %s notification", request.RanName, h.notificationType) - nodebInfo, rnibErr := h.rnibReaderProvider().GetNodeb(request.RanName) + inventoryName := request.RanName + + nodebInfo, rnibErr := h.rnibReaderProvider().GetNodeb(inventoryName) if rnibErr != nil { - logger.Errorf("#X2SetupResponseNotificationHandler - RAN name : %s - Error fetching ran from rNib: %v", request.RanName, rnibErr) + logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error fetching RAN from rNib: %v", request.RanName, rnibErr) return } if !isConnectionStatusValid(nodebInfo.ConnectionStatus) { - logger.Errorf("#X2SetupResponseNotificationHandler - RAN name : %s - Invalid connection status: %s", request.RanName, nodebInfo.ConnectionStatus) + logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Invalid RAN connection status: %s", request.RanName, nodebInfo.ConnectionStatus) return } - nbIdentity := &entities.NbIdentity{} - + nodebInfo.ConnectionAttempts = 0 + nbIdentity := &entities.NbIdentity{InventoryName: inventoryName} err := h.setupResponseManager.SetNodeb(logger, nbIdentity, nodebInfo, request.Payload) if err != nil { @@ -66,11 +70,11 @@ func (h SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessio rnibErr = h.rnibWriterProvider().SaveNodeb(nbIdentity, nodebInfo) if rnibErr != nil { - logger.Errorf("#X2SetupResponseNotificationHandler - RAN name : %s - Error saving RAN to rNib: %v", request.RanName, rnibErr) + logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error saving RAN to rNib: %v", request.RanName, rnibErr) return } - logger.Infof("#X2SetupResponseNotificationHandler - RAN name : %s - Successfully saved RAN to rNib", request.RanName) + logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Successfully saved RAN to rNib", request.RanName) } func isConnectionStatusValid(connectionStatus entities.ConnectionStatus) bool { diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go deleted file mode 100644 index 2864aa1..0000000 --- a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go +++ /dev/null @@ -1,48 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package rmrmsghandlers - -import ( - "e2mgr/logger" - "time" -) - -//import "C" - -//type SetupResponseNotificationHandler struct{} -// -//func (src SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, -// request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { -// -// refinedResponse, err := UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize) -// if err != nil { -// logger.Errorf("#setup_response_notification_handler_bak.Handle - unpack failed. Error: %v", err) -// } -// -// e2session, ok := e2Sessions[request.TransactionId] -// printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#setupResponseNotificationHandler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime) -// if ok { -// printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#setupResponseNotificationHandler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart) -// delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) -// } -// logger.Debugf("#setupResponseNotificationHandler.handle - transactionId %s: PDU: %v", request.TransactionId, refinedResponse.PduPrint) -//} -// -func printHandlingSetupResponseElapsedTimeInMs(logger *logger.Logger, msg string, startTime time.Time) { - logger.Infof("%s: %f ms", msg, float64(time.Since(startTime))/float64(time.Millisecond)) -} diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go deleted file mode 100644 index 0203498..0000000 --- a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go +++ /dev/null @@ -1,60 +0,0 @@ -//// -//// Copyright 2019 AT&T Intellectual Property -//// Copyright 2019 Nokia -//// -//// Licensed under the Apache License, Version 2.0 (the "License"); -//// you may not use this file except in compliance with the License. -//// You may obtain a copy of the License at -//// -//// http://www.apache.org/licenses/LICENSE-2.0 -//// -//// Unless required by applicable law or agreed to in writing, software -//// distributed under the License is distributed on an "AS IS" BASIS, -//// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -//// See the License for the specific language governing permissions and -//// limitations under the License. -//// -// -package rmrmsghandlers -// -//import ( -// "e2mgr/logger" -// "e2mgr/models" -// "e2mgr/rmrCgo" -// "e2mgr/sessions" -// "e2mgr/tests" -// "github.com/stretchr/testify/assert" -// "testing" -// "time" -//) -// -//func TestHandleSuccess(t *testing.T){ -// log, err := logger.InitLogger(logger.InfoLevel) -// if err!=nil{ -// t.Errorf("#setup_request_handler_test.TestHandleSuccess - failed to initialize logger, error: %s", err) -// } -// h := SetupResponseNotificationHandler{} -// E2Sessions := make(sessions.E2Sessions) -// -// payload := tests.GetPackedPayload(t) -// mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &tests.DummyXAction) -// notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now()} -// var messageChannel chan<- *models.NotificationResponse -// -// assert.NotPanics(t, func(){ h.Handle(log, E2Sessions, ¬ificationRequest, messageChannel)}) -//} -// -//func TestHandleFailure(t *testing.T){ -// log, err := logger.InitLogger(logger.InfoLevel) -// if err!=nil{ -// t.Errorf("#setup_request_handler_test.TestHandleFailure - failed to initialize logger, error: %s", err) -// } -// h := SetupResponseNotificationHandler{} -// E2Sessions := make(sessions.E2Sessions) -// -// mBuf := rmrCgo.NewMBuf(tests.MessageType, 4,"RanName", &tests.DummyPayload, &tests.DummyXAction) -// notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now()} -// var messageChannel chan<- *models.NotificationResponse -// -// assert.Panics(t, func(){ h.Handle(log, E2Sessions, ¬ificationRequest, messageChannel)}) -//} \ No newline at end of file diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_test.go new file mode 100644 index 0000000..3898eb4 --- /dev/null +++ b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_test.go @@ -0,0 +1,172 @@ +package rmrmsghandlers + +import ( + "e2mgr/logger" + "e2mgr/managers" + "e2mgr/mocks" + "e2mgr/models" + "e2mgr/rNibWriter" + "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "testing" +) + +const ( + RanName = "test" + X2SetupResponsePackedPdu = "2006002a000002001500080002f82900007a8000140017000000630002f8290007ab50102002f829000001000133" + EndcSetupResponsePackedPdu = "202400808e00000100f600808640000200fc00090002f829504a952a0a00fd007200010c0005001e3f271f2e3d4ff03d44d34e4f003e4e5e4400010000150400000a000211e148033e4e5e4c0005001e3f271f2e3d4ff03d44d34e4f003e4e5e4400010000150400000a00021a0044033e4e5e000000002c001e3f271f2e3d4ff0031e3f274400010000150400000a00020000" + X2SetupFailureResponsePackedPdu = "4006001a0000030005400200000016400100001140087821a00000008040" + EndcSetupFailureResponsePackedPdu = "4024001a0000030005400200000016400100001140087821a00000008040" +) + +type setupResponseTestContext struct { + logger *logger.Logger + readerMock *mocks.RnibReaderMock + writerMock *mocks.RnibWriterMock + rnibReaderProvider func() reader.RNibReader + rnibWriterProvider func() rNibWriter.RNibWriter + setupResponseManager managers.ISetupResponseManager +} + +func NewSetupResponseTestContext(manager managers.ISetupResponseManager) *setupResponseTestContext { + logger, _ := logger.InitLogger(logger.InfoLevel) + readerMock := &mocks.RnibReaderMock{} + writerMock := &mocks.RnibWriterMock{} + + return &setupResponseTestContext{ + logger: logger, + readerMock: readerMock, + writerMock: writerMock, + rnibReaderProvider: func() reader.RNibReader { + return readerMock + }, + rnibWriterProvider: func() rNibWriter.RNibWriter { + return writerMock + }, + setupResponseManager: manager, + } +} + +func TestSetupResponseGetNodebFailure(t *testing.T) { + notificationRequest := models.NotificationRequest{RanName: RanName} + testContext := NewSetupResponseTestContext(nil) + handler := NewSetupResponseNotificationHandler(testContext.rnibReaderProvider, testContext.rnibWriterProvider, &managers.X2SetupResponseManager{}, "X2 Setup Response") + testContext.readerMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{}, common.NewInternalError(errors.New("Error"))) + handler.Handle(testContext.logger, nil, ¬ificationRequest, nil) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertNotCalled(t, "SaveNodeb") +} + +func TestSetupResponseInvalidConnectionStatus(t *testing.T) { + ranName := "test" + notificationRequest := models.NotificationRequest{RanName: ranName} + testContext := NewSetupResponseTestContext(nil) + handler := NewSetupResponseNotificationHandler(testContext.rnibReaderProvider, testContext.rnibWriterProvider, &managers.X2SetupResponseManager{}, "X2 Setup Response") + var rnibErr error + testContext.readerMock.On("GetNodeb", ranName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}, rnibErr) + handler.Handle(testContext.logger, nil, ¬ificationRequest, nil) + testContext.readerMock.AssertCalled(t, "GetNodeb", ranName) + testContext.writerMock.AssertNotCalled(t, "SaveNodeb") +} + +func executeHandleSuccessSetupResponse(t *testing.T, packedPdu string, setupResponseManager managers.ISetupResponseManager, notificationType string, saveNodebMockReturnValue error) (*setupResponseTestContext, *entities.NodebInfo) { + var payload []byte + _, err := fmt.Sscanf(packedPdu, "%x", &payload) + if err != nil { + t.Fatalf("Failed converting packed pdu. Error: %v\n", err) + } + + notificationRequest := models.NotificationRequest{RanName: RanName, Payload: payload} + testContext := NewSetupResponseTestContext(setupResponseManager) + + handler := NewSetupResponseNotificationHandler(testContext.rnibReaderProvider, testContext.rnibWriterProvider, testContext.setupResponseManager, notificationType) + + var rnibErr error + + nodebInfo := &entities.NodebInfo{ + ConnectionStatus: entities.ConnectionStatus_CONNECTING, + ConnectionAttempts: 1, + RanName: RanName, + Ip: "10.0.2.2", + Port: 1231, + } + + testContext.readerMock.On("GetNodeb", RanName).Return(nodebInfo, rnibErr) + testContext.writerMock.On("SaveNodeb", mock.Anything, mock.Anything).Return(saveNodebMockReturnValue) + handler.Handle(testContext.logger, nil, ¬ificationRequest, nil) + + return testContext, nodebInfo +} + +func TestX2SetupResponse(t *testing.T) { + var rnibErr error + testContext, nodebInfo := executeHandleSuccessSetupResponse(t, X2SetupResponsePackedPdu, &managers.X2SetupResponseManager{}, "X2 Setup Response", rnibErr) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, nodebInfo) + assert.EqualValues(t, entities.ConnectionStatus_CONNECTED, nodebInfo.ConnectionStatus) + assert.EqualValues(t, 0, nodebInfo.ConnectionAttempts) + assert.EqualValues(t, entities.Node_ENB, nodebInfo.NodeType) + + assert.IsType(t, &entities.NodebInfo_Enb{}, nodebInfo.Configuration) + i, _ := nodebInfo.Configuration.(*entities.NodebInfo_Enb) + assert.NotNil(t, i.Enb) +} + +func TestX2SetupFailureResponse(t *testing.T) { + var rnibErr error + testContext, nodebInfo := executeHandleSuccessSetupResponse(t, X2SetupFailureResponsePackedPdu, &managers.X2SetupFailureResponseManager{}, "X2 Setup Failure Response", rnibErr) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, nodebInfo) + assert.EqualValues(t, entities.ConnectionStatus_CONNECTED_SETUP_FAILED, nodebInfo.ConnectionStatus) + assert.EqualValues(t, 0, nodebInfo.ConnectionAttempts) + assert.EqualValues(t, entities.Failure_X2_SETUP_FAILURE, nodebInfo.FailureType) + assert.NotNil(t, nodebInfo.SetupFailure) +} + +func TestEndcSetupResponse(t *testing.T) { + var rnibErr error + testContext, nodebInfo := executeHandleSuccessSetupResponse(t, EndcSetupResponsePackedPdu, &managers.EndcSetupResponseManager{}, "ENDC Setup Response", rnibErr) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, nodebInfo) + assert.EqualValues(t, entities.ConnectionStatus_CONNECTED, nodebInfo.ConnectionStatus) + assert.EqualValues(t, 0, nodebInfo.ConnectionAttempts) + assert.EqualValues(t, entities.Node_GNB, nodebInfo.NodeType) + assert.IsType(t, &entities.NodebInfo_Gnb{}, nodebInfo.Configuration) + + i, _ := nodebInfo.Configuration.(*entities.NodebInfo_Gnb) + assert.NotNil(t, i.Gnb) +} +func TestEndcSetupFailureResponse(t *testing.T) { + var rnibErr error + testContext, nodebInfo := executeHandleSuccessSetupResponse(t, EndcSetupFailureResponsePackedPdu, &managers.EndcSetupFailureResponseManager{}, "ENDC Setup Failure Response", rnibErr) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, nodebInfo) + assert.EqualValues(t, entities.ConnectionStatus_CONNECTED_SETUP_FAILED, nodebInfo.ConnectionStatus) + assert.EqualValues(t, 0, nodebInfo.ConnectionAttempts) + assert.EqualValues(t, entities.Failure_ENDC_X2_SETUP_FAILURE, nodebInfo.FailureType) + assert.NotNil(t, nodebInfo.SetupFailure) +} + +func TestSetupResponseInvalidPayload(t *testing.T) { + ranName := "test" + notificationRequest := models.NotificationRequest{RanName: ranName, Payload: []byte("123")} + testContext := NewSetupResponseTestContext(nil) + handler := NewSetupResponseNotificationHandler(testContext.rnibReaderProvider, testContext.rnibWriterProvider, &managers.X2SetupResponseManager{}, "X2 Setup Response") + var rnibErr error + testContext.readerMock.On("GetNodeb", ranName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 1}, rnibErr) + handler.Handle(testContext.logger, nil, ¬ificationRequest, nil) + testContext.readerMock.AssertCalled(t, "GetNodeb", ranName) + testContext.writerMock.AssertNotCalled(t, "SaveNodeb") +} + +func TestSetupResponseSaveNodebFailure(t *testing.T) { + rnibErr := common.NewInternalError(errors.New("Error")) + testContext, nodebInfo := executeHandleSuccessSetupResponse(t, X2SetupResponsePackedPdu, &managers.X2SetupResponseManager{},"X2 Setup Response", rnibErr) + testContext.readerMock.AssertCalled(t, "GetNodeb", RanName) + testContext.writerMock.AssertCalled(t, "SaveNodeb", mock.Anything, nodebInfo) +} \ No newline at end of file diff --git a/E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go deleted file mode 100644 index 6c11467..0000000 --- a/E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package rmrmsghandlers - -import ( - "e2mgr/converters" - "e2mgr/e2pdus" - "e2mgr/logger" - "e2mgr/models" - "e2mgr/rNibWriter" - "e2mgr/sessions" - "fmt" - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" -) - -type X2SetupFailureResponseNotificationHandler struct{} - -func (src X2SetupFailureResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - - e2session, ok := e2Sessions[request.TransactionId] - - failureResponse, err := converters.UnpackX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize) - if err != nil { - logger.Errorf("#x2Setup_failure_response_notification_handler.Handle - unpack failed. Error: %v", err) - } - - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime) - if ok { - if failureResponse != nil { - nb := &entities.NodebInfo{} - nbIdentity := &entities.NbIdentity{} - - nb.RanName = e2session.Request.RanName - nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED - nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST - nb.Ip = e2session.Request.RanIp - nb.Port = uint32(e2session.Request.RanPort) - nb.SetupFailure = failureResponse - nb.FailureType = entities.Failure_X2_SETUP_FAILURE - nbIdentity.InventoryName = e2session.Request.RanName - - //insert/update database - if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil { - logger.Errorf("#x2Setup_failure_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save failure response data. Error: %s", request.TransactionId, rNibErr.Error()) - } else { - logger.Infof("#x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib", request.TransactionId) - if logger.DebugEnabled() { - logger.Debugf("x2Setup_failure_response_notification_handler.Handle - transactionId %s: saved to rNib , value:[%s]", request.TransactionId, fmt.Sprintf("%s %s", nb.ConnectionStatus, failureResponse)) - } - } - } - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2Setup_failure_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart) - delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) - } -} diff --git a/E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go deleted file mode 100644 index 555e37b..0000000 --- a/E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package rmrmsghandlers - -import ( - "e2mgr/converters" - "e2mgr/e2pdus" - "e2mgr/models" - "e2mgr/rNibWriter" - "fmt" - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" - - "e2mgr/logger" - "e2mgr/sessions" -) - -type X2SetupResponseNotificationHandler struct{} - -func (src X2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - - e2session, ok := e2Sessions[request.TransactionId] - - enbId, enb, err := converters.UnpackX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) - if err != nil { - logger.Errorf("#x2apSetup_response_notification_handler.Handle - unpack failed. Error: %v", err) - } - - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2apSetup_response_notification_handler.handle - transactionId %s: Summary: Elapsed time for receiving and handling setup response from E2 terminator", request.TransactionId), request.StartTime) - //TODO if !ok exit - if ok { - if enb != nil { - nb := &entities.NodebInfo{} - nbIdentity := &entities.NbIdentity{} - - nbIdentity.InventoryName = e2session.Request.RanName - nbIdentity.GlobalNbId = enbId - nb.GlobalNbId = nbIdentity.GlobalNbId - nb.RanName = e2session.Request.RanName - nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED - nb.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST - nb.Ip = e2session.Request.RanIp - nb.Port = uint32(e2session.Request.RanPort) - nb.NodeType = entities.Node_ENB - nb.Configuration = &entities.NodebInfo_Enb{Enb: enb} - - //insert/update database - if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil { - logger.Errorf("#x2apSetup_response_notification_handler.Handle - transactionId %s: rNibWriter failed to save ENB data for enbId: %v. Error: %s", request.TransactionId, enbId, rNibErr.Error()) - } else { - logger.Infof("#x2apSetup_response_notification_handler.Handle - transactionId %s: saved to rNib enbId: %v", request.TransactionId, enbId) - if logger.DebugEnabled() { - logger.Debugf("#x2apSetup_response_notification_handler.Handle - transactionId %s: saved to rNib enbId: %v, v:[%s]", request.TransactionId, enbId, fmt.Sprintf("%s %s %s %s", nb.ConnectionStatus, enb.EnbType, enb.ServedCells, enb.GuGroupIds)) - } - } - } - printHandlingSetupResponseElapsedTimeInMs(logger, fmt.Sprintf("#x2apSetup_response_notification_handler.handle - transactionId %s: Summary: Total roundtrip elapsed time", request.TransactionId), e2session.SessionStart) - delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) - } -} diff --git a/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go index 152f00a..e95e871 100644 --- a/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go @@ -34,6 +34,10 @@ import ( type X2EnbConfigurationUpdateHandler struct{} +func NewX2EnbConfigurationUpdateHandler() X2EnbConfigurationUpdateHandler { + return X2EnbConfigurationUpdateHandler{} +} + func (src X2EnbConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { @@ -41,14 +45,14 @@ func (src X2EnbConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessi payloadSize = e2pdus.MaxAsn1PackedBufferSize packedBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.uchar{} errorBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.char{} - refinedMessage, err := converters.UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize ) + refinedMessage, err := converters.UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize) if err != nil { - status := C.build_pack_x2enb_configuration_update_failure( &payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) - if status{ - payload := (*[1<<30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize] + status := C.build_pack_x2enb_configuration_update_failure(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) + if status { + payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize] logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update negative ack message payload: (%d) %02x", len(payload), payload) - response := models.NotificationResponse{RanName:request.RanName, Payload:payload, MgsType: rmrCgo.RIC_ENB_CONFIGURATION_UPDATE_FAILURE} - messageChannel<- &response + response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_ENB_CONFIGURATION_UPDATE_FAILURE} + messageChannel <- &response } else { logger.Errorf("#x2enb_configuration_update_handler.Handle - failed to build and pack Enb configuration update unsuccessful outcome message. Error: %v", errorBuffer) } @@ -57,16 +61,15 @@ func (src X2EnbConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessi logger.Infof("#x2enb_configuration_update_handler.Handle - Enb configuration update initiating message received") logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update initiating message payload: %s", refinedMessage.PduPrint) - status := C.build_pack_x2enb_configuration_update_ack( &payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) + status := C.build_pack_x2enb_configuration_update_ack(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) if status { payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize] logger.Debugf("#x2enb_configuration_update_handler.Handle - Enb configuration update positive ack message payload: (%d) %02x", len(payload), payload) response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_ENB_CONFIGURATION_UPDATE_ACK} - messageChannel<- &response + messageChannel <- &response } else { logger.Errorf("#x2enb_configuration_update_handler.Handle - failed to build and pack enb configuration update successful outcome message. Error: %v", errorBuffer) } } printHandlingSetupResponseElapsedTimeInMs(logger, "#x2enb_configuration_update_handler.Handle - Summary: Elapsed time for receiving and handling enb configuration update initiating message from E2 terminator", request.StartTime) } - diff --git a/E2Manager/main/http_server_test.go b/E2Manager/main/http_server_test.go index ccfe503..aaac4db 100644 --- a/E2Manager/main/http_server_test.go +++ b/E2Manager/main/http_server_test.go @@ -56,7 +56,7 @@ func TestRoutePostNodebMessageType(t *testing.T) { rr := httptest.NewRecorder() router.ServeHTTP(rr, req) - nodebControllerMock.AssertNumberOfCalls(t,"HandleRequest", 1) + nodebControllerMock.AssertNumberOfCalls(t, "HandleRequest", 1) } func TestRouteGetNodebIds(t *testing.T) { @@ -69,7 +69,7 @@ func TestRouteGetNodebIds(t *testing.T) { rr := httptest.NewRecorder() router.ServeHTTP(rr, req) - nodebControllerMock.AssertNumberOfCalls(t,"GetNodebIdList", 1) + nodebControllerMock.AssertNumberOfCalls(t, "GetNodebIdList", 1) } func TestRouteGetNodebRanName(t *testing.T) { @@ -84,7 +84,7 @@ func TestRouteGetNodebRanName(t *testing.T) { assert.Equal(t, http.StatusOK, rr.Code, "handler returned wrong status code") assert.Equal(t, "ran1", rr.Body.String(), "handler returned wrong body") - nodebControllerMock.AssertNumberOfCalls(t,"GetNodeb", 1) + nodebControllerMock.AssertNumberOfCalls(t, "GetNodeb", 1) } func TestRouteGetHealth(t *testing.T) { @@ -97,7 +97,7 @@ func TestRouteGetHealth(t *testing.T) { rr := httptest.NewRecorder() router.ServeHTTP(rr, req) - nodebControllerMock.AssertNumberOfCalls(t,"HandleHealthCheckRequest", 1) + nodebControllerMock.AssertNumberOfCalls(t, "HandleHealthCheckRequest", 1) } func TestRoutePutNodebShutdown(t *testing.T) { @@ -110,7 +110,7 @@ func TestRoutePutNodebShutdown(t *testing.T) { rr := httptest.NewRecorder() router.ServeHTTP(rr, req) - controllerMock.AssertNumberOfCalls(t,"ShutdownHandler", 1) + controllerMock.AssertNumberOfCalls(t, "ShutdownHandler", 1) } func TestRoutePutNodebResetRanName(t *testing.T) { @@ -125,7 +125,7 @@ func TestRoutePutNodebResetRanName(t *testing.T) { assert.Equal(t, http.StatusOK, rr.Code, "handler returned wrong status code") assert.Equal(t, "ran1", rr.Body.String(), "handler returned wrong body") - controllerMock.AssertNumberOfCalls(t,"X2ResetHandler", 1) + controllerMock.AssertNumberOfCalls(t, "X2ResetHandler", 1) } func TestRouteNotFound(t *testing.T) { @@ -148,107 +148,107 @@ func TestParseConfigurationSuccess(t *testing.T) { assert.Equal(t, 4096, config.Rmr.MaxMsgSize) assert.Equal(t, "info", config.Logging.LogLevel) assert.Equal(t, 100, config.NotificationResponseBuffer) - assert.Equal(t,5, config.BigRedButtonTimeoutSec) + assert.Equal(t, 5, config.BigRedButtonTimeoutSec) } func TestParseConfigurationFileNotFoundFailure(t *testing.T) { configPath := "../resources/configuration.yaml" configPathTmp := "../resources/configuration.yaml_tmp" err := os.Rename(configPath, configPathTmp) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath) } defer func() { err = os.Rename(configPathTmp, configPath) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath) } }() - assert.Panics(t, func (){configuration.ParseConfiguration()}) + assert.Panics(t, func() { configuration.ParseConfiguration() }) } func TestRmrConfigNotFoundFailure(t *testing.T) { configPath := "../resources/configuration.yaml" configPathTmp := "../resources/configuration.yaml_tmp" err := os.Rename(configPath, configPathTmp) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } defer func() { err = os.Rename(configPathTmp, configPath) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } }() yamlMap := map[string]interface{}{ - "logging":map[string]interface{}{"logLevel":"info"}, - "http":map[string]interface{}{"port":3800}, + "logging": map[string]interface{}{"logLevel": "info"}, + "http": map[string]interface{}{"port": 3800}, } buf, err := yaml.Marshal(yamlMap) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to marshal configuration map\n") } err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath) } - assert.PanicsWithValue(t, "#http_server.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func (){configuration.ParseConfiguration()}) + assert.PanicsWithValue(t, "#http_server.fillRmrConfig - failed to fill RMR configuration: The entry 'rmr' not found\n", func() { configuration.ParseConfiguration() }) } func TestLoggingConfigNotFoundFailure(t *testing.T) { configPath := "../resources/configuration.yaml" configPathTmp := "../resources/configuration.yaml_tmp" err := os.Rename(configPath, configPathTmp) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } defer func() { err = os.Rename(configPathTmp, configPath) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } }() yamlMap := map[string]interface{}{ - "rmr":map[string]interface{}{"port":3801, "maxMsgSize":4096}, - "http":map[string]interface{}{"port":3800}, + "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096}, + "http": map[string]interface{}{"port": 3800}, } buf, err := yaml.Marshal(yamlMap) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to marshal configuration map\n") } err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath) } assert.PanicsWithValue(t, "#http_server.fillLoggingConfig - failed to fill logging configuration: The entry 'logging' not found\n", - func (){configuration.ParseConfiguration()}) + func() { configuration.ParseConfiguration() }) } func TestHttpConfigNotFoundFailure(t *testing.T) { configPath := "../resources/configuration.yaml" configPathTmp := "../resources/configuration.yaml_tmp" err := os.Rename(configPath, configPathTmp) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } defer func() { err = os.Rename(configPathTmp, configPath) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath) } }() yamlMap := map[string]interface{}{ - "rmr":map[string]interface{}{"port":3801, "maxMsgSize":4096}, - "logging":map[string]interface{}{"logLevel":"info"}, + "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096}, + "logging": map[string]interface{}{"logLevel": "info"}, } buf, err := yaml.Marshal(yamlMap) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to marshal configuration map\n") } err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644) - if err != nil{ + if err != nil { t.Errorf("#http_server_test.TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath) } assert.PanicsWithValue(t, "#http_server.fillHttpConfig - failed to fill HTTP configuration: The entry 'http' not found\n", - func (){configuration.ParseConfiguration()}) + func() { configuration.ParseConfiguration() }) } diff --git a/E2Manager/managers/endc_setup_failure_response_manager.go b/E2Manager/managers/endc_setup_failure_response_manager.go index 5aef343..98f500a 100644 --- a/E2Manager/managers/endc_setup_failure_response_manager.go +++ b/E2Manager/managers/endc_setup_failure_response_manager.go @@ -1 +1,31 @@ package managers + +import ( + "e2mgr/converters" + "e2mgr/e2pdus" + "e2mgr/logger" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" +) + +type EndcSetupFailureResponseManager struct{} + +func NewEndcSetupFailureResponseManager() *EndcSetupFailureResponseManager { + return &EndcSetupFailureResponseManager{} +} + +func (m *EndcSetupFailureResponseManager) SetNodeb(logger *logger.Logger, nbIdentity *entities.NbIdentity, nodebInfo *entities.NodebInfo, payload []byte) error { + + failureResponse, err := converters.UnpackEndcX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) + + if err != nil { + logger.Errorf("#EndcSetupFailureResponseManager.SetNodeb - RAN name: %s - Unpack & extract failed. Error: %v", nodebInfo.RanName, err) + return err + } + + logger.Infof("#EndcSetupFailureResponseManager.SetNodeb - RAN name: %s - Unpacked payload and extracted protobuf successfully", nodebInfo.RanName) + + nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED + nodebInfo.SetupFailure = failureResponse + nodebInfo.FailureType = entities.Failure_ENDC_X2_SETUP_FAILURE + return nil +} diff --git a/E2Manager/managers/endc_setup_response_manager.go b/E2Manager/managers/endc_setup_response_manager.go index 5aef343..70da301 100644 --- a/E2Manager/managers/endc_setup_response_manager.go +++ b/E2Manager/managers/endc_setup_response_manager.go @@ -1 +1,34 @@ package managers + +import ( + "e2mgr/converters" + "e2mgr/e2pdus" + "e2mgr/logger" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" +) + +type EndcSetupResponseManager struct{} + +func NewEndcSetupResponseManager() *EndcSetupResponseManager { + return &EndcSetupResponseManager{} +} + +func (m *EndcSetupResponseManager) SetNodeb(logger *logger.Logger, nbIdentity *entities.NbIdentity, nodebInfo *entities.NodebInfo, payload []byte) error { + + gnbId, gnb, err := converters.UnpackEndcX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) + + if err != nil { + logger.Errorf("#EndcSetupResponseManager.SetNodeb - RAN name: %s - Unpack & extract failed. Error: %v", nodebInfo.RanName, err) + return err + } + + logger.Infof("#EndcSetupResponseManager.SetNodeb - RAN name: %s - Unpacked payload and extracted protobuf successfully", nodebInfo.RanName) + + nbIdentity.GlobalNbId = gnbId + nodebInfo.GlobalNbId = gnbId + nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED + nodebInfo.NodeType = entities.Node_GNB + nodebInfo.Configuration = &entities.NodebInfo_Gnb{Gnb: gnb} + + return nil +} diff --git a/E2Manager/managers/x2_setup_failure_response_manager.go b/E2Manager/managers/x2_setup_failure_response_manager.go index 77098eb..dc03eaa 100644 --- a/E2Manager/managers/x2_setup_failure_response_manager.go +++ b/E2Manager/managers/x2_setup_failure_response_manager.go @@ -18,13 +18,14 @@ func (m *X2SetupFailureResponseManager) SetNodeb(logger *logger.Logger, nbIdenti failureResponse, err := converters.UnpackX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) if err != nil { - logger.Errorf("#x2Setup_failure_response_notification_handler.Handle - unpack failed. Error: %v", err) + logger.Errorf("#X2SetupFailureResponseManager.SetNodeb - RAN name: %s - Unpack & extract failed. Error: %v", nodebInfo.RanName, err) return err } + logger.Infof("#X2SetupFailureResponseManager.SetNodeb - RAN name: %s - Unpacked payload and extracted protobuf successfully", nodebInfo.RanName) + nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED - nodebInfo.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST nodebInfo.SetupFailure = failureResponse nodebInfo.FailureType = entities.Failure_X2_SETUP_FAILURE return nil -} \ No newline at end of file +} diff --git a/E2Manager/managers/x2_setup_response_manager.go b/E2Manager/managers/x2_setup_response_manager.go index 9de2aee..948ec11 100644 --- a/E2Manager/managers/x2_setup_response_manager.go +++ b/E2Manager/managers/x2_setup_response_manager.go @@ -7,28 +7,28 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" ) -type X2SetupResponseManager struct {} +type X2SetupResponseManager struct{} func NewX2SetupResponseManager() *X2SetupResponseManager { return &X2SetupResponseManager{} } func (m *X2SetupResponseManager) SetNodeb(logger *logger.Logger, nbIdentity *entities.NbIdentity, nodebInfo *entities.NodebInfo, payload []byte) error { - enbId, enb, err := converters.UnpackX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) - - if err != nil || enbId == nil || enb == nil { - logger.Errorf("#X2SetupResponseNotificationHandler.SetNodeb - Unpack failed. Error: %v", err) - return err - } - - nbIdentity.InventoryName = nodebInfo.RanName - nbIdentity.GlobalNbId = enbId - nodebInfo.GlobalNbId = nbIdentity.GlobalNbId - nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED - nodebInfo.E2ApplicationProtocol = entities.E2ApplicationProtocol_X2_SETUP_REQUEST - nodebInfo.NodeType = entities.Node_ENB - nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: enb} - - return nil -} + enbId, enb, err := converters.UnpackX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) + + if err != nil { + logger.Errorf("#X2SetupResponseManager.SetNodeb - RAN name: %s - Unpack & extract failed. Error: %v", nodebInfo.RanName, err) + return err + } + + logger.Infof("#X2SetupResponseManager.SetNodeb - RAN name: %s - Unpacked payload and extracted protobuf successfully", nodebInfo.RanName) + + nbIdentity.GlobalNbId = enbId + nodebInfo.GlobalNbId = enbId + nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTED + nodebInfo.NodeType = entities.Node_ENB + nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: enb} + + return nil +} diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go index 4cd55c7..0a01b76 100644 --- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go +++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go @@ -36,20 +36,20 @@ func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, } } +//TODO change handlers.NotificationHandler to *handlers.NotificationHandler func initNotificationHandlersMap(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranReconnectionManager *managers.RanReconnectionManager) map[int]rmrmsghandlers.NotificationHandler { return map[int]rmrmsghandlers.NotificationHandler{ - //TODO change handlers.NotificationHandler to *handlers.NotificationHandler - rmrCgo.RIC_X2_SETUP_RESP: rmrmsghandlers.X2SetupResponseNotificationHandler{}, - rmrCgo.RIC_X2_SETUP_FAILURE: rmrmsghandlers.X2SetupFailureResponseNotificationHandler{}, - rmrCgo.RIC_ENDC_X2_SETUP_RESP: rmrmsghandlers.EndcX2SetupResponseNotificationHandler{}, - rmrCgo.RIC_ENDC_X2_SETUP_FAILURE: rmrmsghandlers.EndcX2SetupFailureResponseNotificationHandler{}, + rmrCgo.RIC_X2_SETUP_RESP: rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewX2SetupResponseManager(), "X2 Setup Response"), + rmrCgo.RIC_X2_SETUP_FAILURE: rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewX2SetupFailureResponseManager(), "X2 Setup Failure Response"), + rmrCgo.RIC_ENDC_X2_SETUP_RESP: rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewEndcSetupResponseManager(), "ENDC Setup Response"), + rmrCgo.RIC_ENDC_X2_SETUP_FAILURE: rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewEndcSetupFailureResponseManager(), "ENDC Setup Failure Response"), rmrCgo.RIC_SCTP_CONNECTION_FAILURE: rmrmsghandlers.NewRanLostConnectionHandler(ranReconnectionManager), rmrCgo.RIC_ENB_LOAD_INFORMATION: rmrmsghandlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider), - rmrCgo.RIC_ENB_CONF_UPDATE: rmrmsghandlers.X2EnbConfigurationUpdateHandler{}, - rmrCgo.RIC_ENDC_CONF_UPDATE: rmrmsghandlers.EndcConfigurationUpdateHandler{}, + rmrCgo.RIC_ENB_CONF_UPDATE: rmrmsghandlers.NewX2EnbConfigurationUpdateHandler(), + rmrCgo.RIC_ENDC_CONF_UPDATE: rmrmsghandlers.NewEndcConfigurationUpdateHandler(), rmrCgo.RIC_X2_RESET_RESP: rmrmsghandlers.NewX2ResetResponseHandler(rnibReaderProvider), rmrCgo.RIC_X2_RESET: rmrmsghandlers.NewX2ResetRequestNotificationHandler(rnibReaderProvider), - rmrCgo.RIC_E2_TERM_INIT: rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider ), + rmrCgo.RIC_E2_TERM_INIT: rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider), } } diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go index 1792e9b..9238b2d 100644 --- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go +++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go @@ -60,15 +60,15 @@ func TestGetNotificationHandlerSuccess(t *testing.T) { msgType int handler rmrmsghandlers.NotificationHandler }{ - {rmrCgo.RIC_X2_SETUP_RESP /*successful x2 setup response*/, rmrmsghandlers.X2SetupResponseNotificationHandler{}}, - {rmrCgo.RIC_X2_SETUP_FAILURE /*unsuccessful x2 setup response*/, rmrmsghandlers.X2SetupFailureResponseNotificationHandler{}}, - {rmrCgo.RIC_ENDC_X2_SETUP_RESP /*successful en-dc x2 setup response*/, rmrmsghandlers.EndcX2SetupResponseNotificationHandler{}}, - {rmrCgo.RIC_ENDC_X2_SETUP_FAILURE /*unsuccessful en-dc x2 setup response*/, rmrmsghandlers.EndcX2SetupFailureResponseNotificationHandler{}}, - {rmrCgo.RIC_SCTP_CONNECTION_FAILURE /*sctp errors*/, rmrmsghandlers.NewRanLostConnectionHandler(ranReconnectionManager)}, + {rmrCgo.RIC_X2_SETUP_RESP, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewX2SetupResponseManager(), "X2 Setup Response")}, + {rmrCgo.RIC_X2_SETUP_FAILURE, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewX2SetupFailureResponseManager(),"X2 Setup Failure Response")}, + {rmrCgo.RIC_ENDC_X2_SETUP_RESP, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewEndcSetupResponseManager(),"ENDC Setup Response")}, + {rmrCgo.RIC_ENDC_X2_SETUP_FAILURE, rmrmsghandlers.NewSetupResponseNotificationHandler(rnibReaderProvider, rnibWriterProvider, managers.NewEndcSetupFailureResponseManager(),"ENDC Setup Failure Response"),}, + {rmrCgo.RIC_SCTP_CONNECTION_FAILURE, rmrmsghandlers.NewRanLostConnectionHandler(ranReconnectionManager)}, {rmrCgo.RIC_ENB_LOAD_INFORMATION, rmrmsghandlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider)}, {rmrCgo.RIC_ENB_CONF_UPDATE, rmrmsghandlers.X2EnbConfigurationUpdateHandler{}}, {rmrCgo.RIC_ENDC_CONF_UPDATE, rmrmsghandlers.EndcConfigurationUpdateHandler{}}, - {rmrCgo.RIC_E2_TERM_INIT, rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider)}, + {rmrCgo.RIC_E2_TERM_INIT, rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider)}, } for _, tc := range testCases { -- 2.16.6