From 70a1adcdcf3ba61d0e17e89cd0b6f34f812ec878 Mon Sep 17 00:00:00 2001 From: irina Date: Thu, 22 Aug 2019 23:09:26 +0300 Subject: [PATCH] [RICPLT-1705] Reset Request received from E2T (Remote RAN) Change-Id: Ieeb40b4bb35aa041af5c4cef2109703f917e119b Signed-off-by: irina --- E2Manager/asn1codec/Makefile | 9 +- E2Manager/asn1codec/inc/x2reset_response_wrapper.h | 40 +++++++ .../src/tests/x2reset_response_wrapper_test.c | 52 +++++++++ E2Manager/asn1codec/src/x2reset_response_wrapper.c | 80 +++++++++++++ E2Manager/handlers/delete_all_request_handler.go | 22 ++-- .../handlers/delete_all_request_handler_test.go | 2 +- .../handlers/enb_load_information_to_protobuf.go | 2 +- .../x2_reset_request_notification_handler.go | 92 +++++++++++++++ .../x2_reset_request_notification_handler_test.go | 127 +++++++++++++++++++++ E2Manager/managers/notification_manager.go | 11 +- .../providers/notification_handler_provider.go | 5 +- E2Manager/router.txt | 2 +- 12 files changed, 418 insertions(+), 26 deletions(-) create mode 100644 E2Manager/asn1codec/inc/x2reset_response_wrapper.h create mode 100644 E2Manager/asn1codec/src/tests/x2reset_response_wrapper_test.c create mode 100644 E2Manager/asn1codec/src/x2reset_response_wrapper.c create mode 100644 E2Manager/handlers/x2_reset_request_notification_handler.go create mode 100644 E2Manager/handlers/x2_reset_request_notification_handler_test.go diff --git a/E2Manager/asn1codec/Makefile b/E2Manager/asn1codec/Makefile index 97596ce..c2e0be9 100644 --- a/E2Manager/asn1codec/Makefile +++ b/E2Manager/asn1codec/Makefile @@ -19,16 +19,17 @@ CFLAGS=-Wall -Wpedantic -std=c11 -Og -I./inc -I./src -I./e2ap_engine -DASN_DISA export CFLAGS OBJDIR=lib LIB=$(OBJDIR)/libe2ap_codec.a -LIBSRC=configuration_update_wrapper.c x2setup_request_wrapper.c x2reset_request_wrapper.c asn1codec_utils.c +LIBSRC=configuration_update_wrapper.c x2setup_request_wrapper.c x2reset_request_wrapper.c x2reset_response_wrapper.c asn1codec_utils.c LIBOBJ=$(addprefix $(OBJDIR)/,$(LIBSRC:.c=.o)) TESTX2SETUPREQUEST=tests/x2setup_request_wrapper_test TESTCONFUPDATE=tests/configuration_update_wrapper_test TESTX2RESETREQUEST=tests/x2reset_request_wrapper_test +TESTX2RESETRESPONSE=tests/x2reset_response_wrapper_test TESTUNPACKXER=tests/unpack_xer .PHONY: all clean e2ap_engine -all: $(LIB) $(TESTX2SETUPREQUEST) $(TESTCONFUPDATE) $(TESTX2RESETREQUEST) $(TESTUNPACKXER) +all: $(LIB) $(TESTX2SETUPREQUEST) $(TESTCONFUPDATE) $(TESTX2RESETREQUEST) $(TESTUNPACKXER) $(TESTX2RESETRESPONSE) e2ap_engine/libasncodec.a: cd e2ap_engine/ && make -f converter-example.mk @@ -56,6 +57,10 @@ $(TESTUNPACKXER): % : $(LIB) src/%.c mkdir -p $(dir $@) $(CC) $(CFLAGS) src/$@.c -o $@ $(LIB) e2ap_engine/libasncodec.a +$(TESTX2RESETRESPONSE): % : $(LIB) src/%.c + mkdir -p $(dir $@) + $(CC) $(CFLAGS) src/$@.c -o $@ $(LIB) e2ap_engine/libasncodec.a + clean: rm -rf $(OBJDIR) tests clobber: diff --git a/E2Manager/asn1codec/inc/x2reset_response_wrapper.h b/E2Manager/asn1codec/inc/x2reset_response_wrapper.h new file mode 100644 index 0000000..45f01f8 --- /dev/null +++ b/E2Manager/asn1codec/inc/x2reset_response_wrapper.h @@ -0,0 +1,40 @@ +/* + * + * 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. + * + */ + + +#include +#include +#include +#include + +#ifndef INC_X2RESET_RESPONSE_WRAPPER_H +#define INC_X2RESET_RESPONSE_WRAPPER_H + +#ifdef __cplusplus +extern "C" +{ +#endif +bool +build_pack_x2reset_response(size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf); +#ifdef __cplusplus +} +#endif + +#endif /* INC_X2RESET_RESPONSE_WRAPPER_H */ + diff --git a/E2Manager/asn1codec/src/tests/x2reset_response_wrapper_test.c b/E2Manager/asn1codec/src/tests/x2reset_response_wrapper_test.c new file mode 100644 index 0000000..c146e1d --- /dev/null +++ b/E2Manager/asn1codec/src/tests/x2reset_response_wrapper_test.c @@ -0,0 +1,52 @@ + /* + * + * 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. + * + */ + + + #include + #include + #include + #include + + void test_build_pack_x2reset_response(); + void test_unpack(void); + + int + main(int argc, char* argv[]) + { + test_build_pack_x2reset_response(); + exit(0); + } + + void test_build_pack_x2reset_response(){ + size_t error_buf_size = 8192; + size_t packed_buf_size = 4096; + unsigned char responseDataBuf[packed_buf_size]; + char responseErrorBuf[error_buf_size]; + bool result = build_pack_x2reset_response(&packed_buf_size, responseDataBuf, error_buf_size, responseErrorBuf); + + if (!result) { + printf("#test_build_pack_x2reset_response failed. Packing error %s\n", responseErrorBuf); + return; + } + printf("x2reset response packed size:%lu\nPayload:\n", packed_buf_size); + for (size_t i = 0; i < packed_buf_size; ++i) + printf("%02x",responseDataBuf[i]); + printf("\n"); + } + diff --git a/E2Manager/asn1codec/src/x2reset_response_wrapper.c b/E2Manager/asn1codec/src/x2reset_response_wrapper.c new file mode 100644 index 0000000..035941e --- /dev/null +++ b/E2Manager/asn1codec/src/x2reset_response_wrapper.c @@ -0,0 +1,80 @@ +/* + * + * 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. + * + */ + +#include +#include +#undef NDEBUG +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * Build and pack a reset response. + * Abort the process on allocation failure. + * packed_buf_size - in: size of packed_buf; out: number of chars used. + */ + +bool +build_pack_x2reset_response(size_t* packed_buf_size, unsigned char* packed_buf,size_t err_buf_size, char* err_buf) +{ + bool rc = true; + E2AP_PDU_t *pdu = calloc(1, sizeof(E2AP_PDU_t)); + + ResetResponse_t *resetResponse; + SuccessfulOutcome_t *successfulOutcome = calloc(1, sizeof(SuccessfulOutcome_t)); + ResetResponse_IEs_t *resetResponse_ie = calloc(1, sizeof(ResetResponse_IEs_t)); + + assert(pdu != 0); + assert(successfulOutcome != 0); + assert(resetResponse_ie != 0); + + pdu->present = E2AP_PDU_PR_successfulOutcome; + pdu->choice.successfulOutcome = successfulOutcome; + + successfulOutcome->procedureCode = ProcedureCode_id_reset; + successfulOutcome->criticality = Criticality_reject; + successfulOutcome->value.present = SuccessfulOutcome__value_PR_ResetResponse; + resetResponse = &successfulOutcome->value.choice.ResetResponse; + + resetResponse_ie->id = ProtocolIE_ID_id_CriticalityDiagnostics; + resetResponse_ie->criticality = Criticality_ignore; + resetResponse_ie->value.present = ResetResponse_IEs__value_PR_CriticalityDiagnostics; + + ASN_SEQUENCE_ADD(&resetResponse->protocolIEs, resetResponse_ie); + + CriticalityDiagnostics_IE_List_t *critList = calloc(1, sizeof(CriticalityDiagnostics_IE_List_t)); + assert(critList != 0); + + CriticalityDiagnostics_IE_List__Member *member= calloc(1, sizeof(CriticalityDiagnostics_IE_List__Member)); + assert(member != 0); + + ASN_SEQUENCE_ADD(critList ,member); + ASN_SEQUENCE_ADD(resetResponse_ie->value.choice.CriticalityDiagnostics.iEsCriticalityDiagnostics, critList); + + rc = per_pack_pdu(pdu, packed_buf_size, packed_buf,err_buf_size, err_buf); + ASN_STRUCT_FREE(asn_DEF_E2AP_PDU, pdu); + + return rc; +} + diff --git a/E2Manager/handlers/delete_all_request_handler.go b/E2Manager/handlers/delete_all_request_handler.go index c5240e2..b0899ba 100644 --- a/E2Manager/handlers/delete_all_request_handler.go +++ b/E2Manager/handlers/delete_all_request_handler.go @@ -63,12 +63,12 @@ func (handler *DeleteAllRequestHandler) Handle(logger *logger.Logger, request mo //TODO change to rmr_request response := models.NotificationResponse{MgsType: rmrCgo.RIC_SCTP_CLEAR_ALL} if err:= handler.rmrService.SendRmrMessage(&response); err != nil { - logger.Errorf("#delete_all_request_handler.Handle - failed to send sctp clear all message to RMR: %s", err) + logger.Errorf("#DeleteAllRequestHandler.Handle - failed to send sctp clear all message to RMR: %s", err) return e2managererrors.NewRmrError() } time.Sleep(time.Duration(handler.config.BigRedButtonTimeoutSec) * time.Second) - logger.Infof("#delete_all_request_handler.Handle - timer expired") + logger.Infof("#DeleteAllRequestHandler.Handle - timer expired") err, _ = handler.updateNodebStates(logger, true) if err != nil { @@ -82,7 +82,7 @@ func (handler *DeleteAllRequestHandler) updateNodebStates(logger *logger.Logger, nbIdentityList, err := handler.readerProvider().GetListNodebIds() if err != nil { - logger.Errorf("#delete_all_request_handler.updateNodebStates - failed to get nodes list from RNIB. Error: %s", err.Error()) + logger.Errorf("#DeleteAllRequestHandler.updateNodebStates - failed to get nodes list from RNIB. Error: %s", err.Error()) return e2managererrors.NewRnibDbError(), false } @@ -96,7 +96,7 @@ func (handler *DeleteAllRequestHandler) updateNodebStates(logger *logger.Logger, node, err := handler.readerProvider().GetNodeb((*nbIdentity).GetInventoryName()) if err != nil { - logger.Errorf("#delete_all_request_handler.updateNodebStates - failed to get nodeB entity for ran name: %v from RNIB. Error: %s", + logger.Errorf("#DeleteAllRequestHandler.updateNodebStates - failed to get nodeB entity for ran name: %v from RNIB. Error: %s", (*nbIdentity).GetInventoryName(), err.Error()) continue } @@ -114,9 +114,9 @@ func (handler *DeleteAllRequestHandler) updateNodebStates(logger *logger.Logger, } if numOfRanToShutDown > 0{ - logger.Infof("#delete_all_request_handler.updateNodebStates - update nodebs states in RNIB completed") + logger.Infof("#DeleteAllRequestHandler.updateNodebStates - update nodebs states in RNIB completed") }else { - logger.Infof("#delete_all_request_handler.updateNodebStates - nodebs states are not updated ") + logger.Infof("#DeleteAllRequestHandler.updateNodebStates - nodebs states are not updated ") return nil, false } @@ -139,13 +139,13 @@ func (handler *DeleteAllRequestHandler) saveNodebNextState(logger *logger.Logger err := handler.writerProvider().SaveNodeb(nbIdentity, node) if err != nil { - logger.Errorf("#delete_all_request_handler.saveNodebNextState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s", + logger.Errorf("#DeleteAllRequestHandler.saveNodebNextState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s", (*nbIdentity).GetInventoryName(), err.Error()) return false } if logger.DebugEnabled() { - logger.Debugf("#delete_all_request_handler.saveNodebNextState - connection status of inventory name: %v changed to %v", + logger.Debugf("#DeleteAllRequestHandler.saveNodebNextState - connection status of inventory name: %v changed to %v", (*nbIdentity).GetInventoryName(), nextStatus.String()) } return true @@ -158,7 +158,7 @@ func (handler *DeleteAllRequestHandler) saveNodebShutDownState(logger *logger.Lo } if node.ConnectionStatus != entities.ConnectionStatus_SHUTTING_DOWN { - logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - ignore, status is not Shutting Down, inventory name: %v ", (*nbIdentity).GetInventoryName()) + logger.Errorf("#DeleteAllRequestHandler.saveNodebShutDownState - ignore, status is not Shutting Down, inventory name: %v ", (*nbIdentity).GetInventoryName()) return false } @@ -167,11 +167,11 @@ func (handler *DeleteAllRequestHandler) saveNodebShutDownState(logger *logger.Lo err := handler.writerProvider().SaveNodeb(nbIdentity, node) if err != nil { - logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s", + logger.Errorf("#DeleteAllRequestHandler.saveNodebShutDownState - failed to save nodeB entity for inventory name: %v to RNIB. Error: %s", (*nbIdentity).GetInventoryName(), err.Error()) return false } - logger.Errorf("#delete_all_request_handler.saveNodebShutDownState - Shut Down , inventory name: %v ", (*nbIdentity).GetInventoryName()) + logger.Errorf("#DeleteAllRequestHandler.saveNodebShutDownState - Shut Down , inventory name: %v ", (*nbIdentity).GetInventoryName()) return true } diff --git a/E2Manager/handlers/delete_all_request_handler_test.go b/E2Manager/handlers/delete_all_request_handler_test.go index 62214a8..8dfa188 100644 --- a/E2Manager/handlers/delete_all_request_handler_test.go +++ b/E2Manager/handlers/delete_all_request_handler_test.go @@ -457,7 +457,7 @@ func createIdentityList() []*entities.NbIdentity { func initLog(t *testing.T) *logger.Logger { log, err := logger.InitLogger(logger.InfoLevel) if err != nil { - t.Errorf("#delete_all_request_handler_test.TestHandleSuccessFlow - failed to initialize logger, error: %s", err) + t.Errorf("#initLog test - failed to initialize logger, error: %s", err) } return log } diff --git a/E2Manager/handlers/enb_load_information_to_protobuf.go b/E2Manager/handlers/enb_load_information_to_protobuf.go index f40fa0e..51d6efa 100644 --- a/E2Manager/handlers/enb_load_information_to_protobuf.go +++ b/E2Manager/handlers/enb_load_information_to_protobuf.go @@ -36,7 +36,7 @@ func extractPduCellInformationItemIEs(pdu *C.E2AP_PDU_t) ([]*C.CellInformation_I initiatingMessage := *(**C.InitiatingMessage_t)(unsafe.Pointer(&pdu.choice[0])) - if (initiatingMessage == nil || initiatingMessage.value.present != C.InitiatingMessage__value_PR_LoadInformation) { + if initiatingMessage == nil || initiatingMessage.value.present != C.InitiatingMessage__value_PR_LoadInformation { return nil, fmt.Errorf("#extractPduCellInformationItemIEs - Invalid InitiatingMessage value") } diff --git a/E2Manager/handlers/x2_reset_request_notification_handler.go b/E2Manager/handlers/x2_reset_request_notification_handler.go new file mode 100644 index 0000000..3a68755 --- /dev/null +++ b/E2Manager/handlers/x2_reset_request_notification_handler.go @@ -0,0 +1,92 @@ +// +// 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 handlers + +// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ +// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec +// #include +// #include +import "C" +import ( + "e2mgr/logger" + "e2mgr/models" + "e2mgr/rmrCgo" + "e2mgr/sessions" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" + "unsafe" +) + +type X2ResetRequestNotificationHandler struct { + rnibReaderProvider func() reader.RNibReader +} + +func NewX2ResetRequestNotificationHandler(rnibReaderProvider func() reader.RNibReader) X2ResetRequestNotificationHandler { + return X2ResetRequestNotificationHandler{ + rnibReaderProvider: rnibReaderProvider, + } +} + +func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, + request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { + + logger.Debugf("#X2ResetRequestNotificationHandler.Handle - Ran name: %s", request.RanName) + + nb, rNibErr := src.rnibReaderProvider().GetNodeb(request.RanName) + if rNibErr != nil { + logger.Errorf("#X2ResetRequestNotificationHandler.Handle - failed to retrieve nodeB entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error()) + printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime) + + return + } + logger.Debugf("#X2ResetRequestNotificationHandler.Handle - nodeB entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus) + + if nb.ConnectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { + logger.Warnf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus) + printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime) + + return + } + + if nb.ConnectionStatus != entities.ConnectionStatus_CONNECTED { + logger.Errorf("#X2ResetRequestNotificationHandler.Handle - nodeB entity in incorrect state. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus) + printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime) + + return + } + src.createAndAddToChannel(logger, request, messageChannel) + + //TODO change name of printHandlingSetupResponseElapsedTimeInMs (remove setup response) and move to utils? + printHandlingSetupResponseElapsedTimeInMs(logger, "#X2ResetRequestNotificationHandler.Handle - Summary: Elapsed time for receiving and handling reset request message from E2 terminator", request.StartTime) +} + +func (src X2ResetRequestNotificationHandler) createAndAddToChannel(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { + + packedBuffer := make([]C.uchar, MaxAsn1PackedBufferSize) + errorBuffer := make([]C.char, MaxAsn1CodecMessageBufferSize) + var payloadSize = C.ulong(MaxAsn1PackedBufferSize) + + if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(MaxAsn1CodecMessageBufferSize), &errorBuffer[0]); !status { + logger.Errorf("#X2ResetRequestNotificationHandler.createAndAddToChannel - failed to build and pack the reset response message %s ", C.GoString(&errorBuffer[0])) + return + } + payload := C.GoBytes(unsafe.Pointer(&packedBuffer[0]), C.int(payloadSize)) + response := models.NotificationResponse{RanName: request.RanName, Payload: payload, MgsType: rmrCgo.RIC_X2_RESET_RESP} + + messageChannel <- &response +} diff --git a/E2Manager/handlers/x2_reset_request_notification_handler_test.go b/E2Manager/handlers/x2_reset_request_notification_handler_test.go new file mode 100644 index 0000000..7ce83e0 --- /dev/null +++ b/E2Manager/handlers/x2_reset_request_notification_handler_test.go @@ -0,0 +1,127 @@ +// +// 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 handlers + +import ( + "e2mgr/mocks" + "e2mgr/models" + "e2mgr/rmrCgo" + "e2mgr/tests" + "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/stretchr/testify/assert" + "testing" + "time" +) + +func TestX2ResetRequestNotifSuccess(t *testing.T) { + log := initLog(t) + payload := []byte("payload") + readerMock := &mocks.RnibReaderMock{} + readerProvider := func() reader.RNibReader { + return readerMock + } + + h := NewX2ResetRequestNotificationHandler(readerProvider) + + xaction := []byte("RanName") + mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, + StartTime: time.Now(), TransactionId: string(xaction)} + + nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED,} + var rnibErr common.IRNibError + readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) + + messageChannel := make(chan *models.NotificationResponse) + + go h.Handle(log,nil, ¬ificationRequest, messageChannel) + + result := <-messageChannel + assert.Equal(t, result.RanName, mBuf.Meid) + assert.Equal(t, result.MgsType, rmrCgo.RIC_X2_RESET_RESP) +} + +func TestHandleX2ResetRequestNotifShuttingDownStatus(t *testing.T) { + log := initLog(t) + var payload []byte + readerMock := &mocks.RnibReaderMock{} + readerProvider := func() reader.RNibReader { + return readerMock + } + + h := NewX2ResetRequestNotificationHandler(readerProvider) + + xaction := []byte("RanName") + mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, + StartTime: time.Now(), TransactionId: string(xaction)} + + nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,} + var rnibErr common.IRNibError + + readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) + + h.Handle(log,nil, ¬ificationRequest, nil) +} + +func TestHandleX2ResetRequestNotifDisconnectStatus(t *testing.T) { + log := initLog(t) + var payload []byte + readerMock := &mocks.RnibReaderMock{} + readerProvider := func() reader.RNibReader { + return readerMock + } + + h := NewX2ResetRequestNotificationHandler(readerProvider) + + xaction := []byte("RanName") + mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, + StartTime: time.Now(), TransactionId: string(xaction)} + + nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,} + var rnibErr common.IRNibError + + readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) + + h.Handle(log,nil, ¬ificationRequest, nil) +} + +func TestHandleX2ResetRequestNotifGetNodebFailed(t *testing.T){ + + log := initLog(t) + var payload []byte + readerMock := &mocks.RnibReaderMock{} + readerProvider := func() reader.RNibReader { + return readerMock + } + + h := NewX2ResetRequestNotificationHandler(readerProvider) + xaction := []byte("RanName") + mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction) + notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, + StartTime: time.Now(), TransactionId: string(xaction)} + + var nb *entities.NodebInfo + rnibErr := &common.RNibError{} + readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) + + h.Handle(log,nil, ¬ificationRequest, nil) +} diff --git a/E2Manager/managers/notification_manager.go b/E2Manager/managers/notification_manager.go index 9e9673d..5533c52 100644 --- a/E2Manager/managers/notification_manager.go +++ b/E2Manager/managers/notification_manager.go @@ -30,22 +30,21 @@ import ( ) type NotificationManager struct { - rnibReaderProvider func() reader.RNibReader - rnibWriterProvider func() rNibWriter.RNibWriter + notificationHandlerProvider *providers.NotificationHandlerProvider } func NewNotificationManager(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) *NotificationManager { + notificationHandlerProvider := providers.NewNotificationHandlerProvider(rnibReaderProvider, rnibWriterProvider) + return &NotificationManager{ - rnibReaderProvider: rnibReaderProvider, - rnibWriterProvider: rnibWriterProvider, + notificationHandlerProvider: notificationHandlerProvider, } } //TODO add NEWHandler with log func (m NotificationManager) HandleMessage(logger *logger.Logger, e2Sessions sessions.E2Sessions, mbuf *rmrCgo.MBuf, responseChannel chan<- *models.NotificationResponse) { - provider := providers.NewNotificationHandlerProvider(m.rnibReaderProvider, m.rnibWriterProvider) - notificationHandler, err := provider.GetNotificationHandler(mbuf.MType) + notificationHandler, err := m.notificationHandlerProvider.GetNotificationHandler(mbuf.MType) if err != nil { logger.Errorf(fmt.Sprintf("%s", err)) diff --git a/E2Manager/providers/notification_handler_provider.go b/E2Manager/providers/notification_handler_provider.go index cae4e95..cb9862e 100644 --- a/E2Manager/providers/notification_handler_provider.go +++ b/E2Manager/providers/notification_handler_provider.go @@ -27,14 +27,10 @@ import ( type NotificationHandlerProvider struct{ notificationHandlers map[int]handlers.NotificationHandler - rnibReaderProvider func() reader.RNibReader - rnibWriterProvider func() rNibWriter.RNibWriter } func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) *NotificationHandlerProvider { return &NotificationHandlerProvider{ - rnibReaderProvider: rnibReaderProvider, - rnibWriterProvider: rnibWriterProvider, notificationHandlers: initNotificationHandlersMap(rnibReaderProvider, rnibWriterProvider), } } @@ -51,6 +47,7 @@ func initNotificationHandlersMap(rnibReaderProvider func() reader.RNibReader, rn rmrCgo.RIC_ENB_CONF_UPDATE: handlers.X2EnbConfigurationUpdateHandler{}, rmrCgo.RIC_ENDC_CONF_UPDATE: handlers.EndcConfigurationUpdateHandler{}, rmrCgo.RIC_X2_RESET_RESP: handlers.NewX2ResetResponseHandler(rnibReaderProvider), + rmrCgo.RIC_X2_RESET: handlers.NewX2ResetRequestNotificationHandler(rnibReaderProvider), } } diff --git a/E2Manager/router.txt b/E2Manager/router.txt index 5ff2cbe..20f2f58 100644 --- a/E2Manager/router.txt +++ b/E2Manager/router.txt @@ -2,7 +2,7 @@ newrt|start rte|10060|10.0.2.15:38000 rte|10360|10.0.2.15:38000 rte|10070|10.0.2.15:38000 -rte|10071|10.0.2.15:3801 +rte|10071|10.0.2.15:38000 rte|10061|10.0.2.15:3801 rte|10361|10.0.2.15:3801 rte|10062|10.0.2.15:3801 -- 2.16.6