From 1ec13d4076e7c7abefac6176462c1fee31229213 Mon Sep 17 00:00:00 2001 From: is005q Date: Thu, 5 Sep 2019 19:28:18 +0300 Subject: [PATCH] [RICPLT-2157] Restructure handlers and converters....... Change-Id: I5cd677438b2add27ac87b638762069e1a79af69f Signed-off-by: is005q --- E2Manager/container-tag.yaml | 2 +- E2Manager/controllers/controller.go | 14 ++-- E2Manager/controllers/nodeb_controller.go | 3 +- .../enb_load_information_to_protobuf.go | 4 +- .../enb_load_information_to_protobuf_test.go | 4 +- .../endc_x2setupFailureResponseToProtobuf.go | 8 +-- .../endc_x2setupFailureResponseToProtobuf_test.go | 82 +++++++++++----------- .../endc_x2setupResponseToProtobuf.go | 6 +- .../endc_x2setupResponseToProtobuf_test.go | 7 +- .../x2apPdu_asn1_unpacker.go | 16 ++--- .../x2apPdu_asn1_unpacker_test.go | 21 +++--- .../x2setupFailureResponseToProtobuf.go | 6 +- .../x2setupFailureResponseToProtobuf_test.go | 7 +- .../x2setupResponseToProtobuf.go | 8 +-- .../x2setupResponseToProtobuf_test.go | 7 +- E2Manager/e2pdus/x2_reset_known_causes.go | 1 + .../delete_all_request_handler.go | 5 +- .../delete_all_request_handler_test.go | 2 +- .../endc_setup_request_handler.go | 2 +- .../endc_setup_request_handler_test.go | 2 +- .../handlers/{ => httpmsghandlers}/handler.go | 2 +- .../{ => httpmsghandlers}/request_handler.go | 2 +- .../{ => httpmsghandlers}/setup_request_handler.go | 2 +- .../setup_request_handler_test.go | 2 +- .../x2_reset_request_handler.go | 2 +- .../x2_reset_request_handler_test.go | 16 ++--- .../e2_term_init_notification_handler.go | 7 +- .../e2_term_init_notification_handler_test.go | 73 +++++++++++-------- .../enb_load_information_notification_handler.go | 10 +-- ...b_load_information_notification_handler_test.go | 2 +- .../endc_configuration_update_handler.go | 22 +++--- .../endc_configuration_update_handler_test.go | 2 +- .../endc_setup_response_notification_handler.go | 17 ++--- ...2Setup_failure_response_notification_handler.go | 6 +- .../{ => rmrmsghandlers}/notification_handler.go | 2 +- .../ran_lost_connection_handler.go | 2 +- .../ran_lost_connection_handler_test.go | 2 +- .../setup_response_notification_handler.go | 78 ++++++++++++++++++++ .../setup_response_notification_handler_bak.go | 48 +++++++++++++ ...setup_response_notification_handler_bak_test.go | 60 ++++++++++++++++ ...2Setup_failure_response_notification_handler.go | 6 +- .../x2_reset_request_notification_handler.go | 32 +++++++-- .../x2_reset_request_notification_handler_test.go | 4 +- .../x2_reset_response_handler.go | 12 ++-- .../x2_reset_response_handler_test.go | 2 +- .../x2apSetup_response_notification_handler.go | 9 ++- .../x2enb_configuration_update_handler.go | 22 +++--- .../x2enb_configuration_update_handler_test.go | 2 +- .../setup_response_notification_handler.go | 51 -------------- .../setup_response_notification_handler_test.go | 60 ---------------- .../endc_setup_failure_response_manager.go | 1 + E2Manager/managers/endc_setup_response_manager.go | 1 + E2Manager/managers/i_setup_response_manager.go | 10 +++ .../managers/x2_setup_failure_response_manager.go | 30 ++++++++ E2Manager/managers/x2_setup_response_manager.go | 34 +++++++++ .../incoming_request_handler_provider.go | 17 +++-- .../incoming_request_handler_provider_test.go | 4 +- .../request_handler_provider.go | 14 ++-- .../request_handler_provider_test.go | 6 +- .../notification_handler_provider.go | 32 ++++----- .../notification_handler_provider_test.go | 22 +++--- 61 files changed, 565 insertions(+), 370 deletions(-) rename E2Manager/{handlers => converters}/enb_load_information_to_protobuf.go (99%) rename E2Manager/{handlers => converters}/enb_load_information_to_protobuf_test.go (99%) rename E2Manager/{handlers => converters}/endc_x2setupFailureResponseToProtobuf.go (93%) rename E2Manager/{handlers => converters}/endc_x2setupFailureResponseToProtobuf_test.go (63%) rename E2Manager/{handlers => converters}/endc_x2setupResponseToProtobuf.go (99%) rename E2Manager/{handlers => converters}/endc_x2setupResponseToProtobuf_test.go (99%) rename E2Manager/{handlers => converters}/x2apPdu_asn1_unpacker.go (88%) rename E2Manager/{handlers => converters}/x2apPdu_asn1_unpacker_test.go (87%) rename E2Manager/{handlers => converters}/x2setupFailureResponseToProtobuf.go (97%) rename E2Manager/{handlers => converters}/x2setupFailureResponseToProtobuf_test.go (97%) rename E2Manager/{handlers => converters}/x2setupResponseToProtobuf.go (99%) rename E2Manager/{handlers => converters}/x2setupResponseToProtobuf_test.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/delete_all_request_handler.go (97%) rename E2Manager/handlers/{ => httpmsghandlers}/delete_all_request_handler_test.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/endc_setup_request_handler.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/endc_setup_request_handler_test.go (98%) rename E2Manager/handlers/{ => httpmsghandlers}/handler.go (97%) rename E2Manager/handlers/{ => httpmsghandlers}/request_handler.go (96%) rename E2Manager/handlers/{ => httpmsghandlers}/setup_request_handler.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/setup_request_handler_test.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/x2_reset_request_handler.go (99%) rename E2Manager/handlers/{ => httpmsghandlers}/x2_reset_request_handler_test.go (94%) rename E2Manager/handlers/{ => rmrmsghandlers}/e2_term_init_notification_handler.go (90%) rename E2Manager/handlers/{ => rmrmsghandlers}/e2_term_init_notification_handler_test.go (76%) rename E2Manager/handlers/{ => rmrmsghandlers}/enb_load_information_notification_handler.go (85%) rename E2Manager/handlers/{ => rmrmsghandlers}/enb_load_information_notification_handler_test.go (99%) rename E2Manager/handlers/{ => rmrmsghandlers}/endc_configuration_update_handler.go (79%) rename E2Manager/handlers/{ => rmrmsghandlers}/endc_configuration_update_handler_test.go (99%) rename E2Manager/handlers/{ => rmrmsghandlers}/endc_setup_response_notification_handler.go (87%) rename E2Manager/handlers/{ => rmrmsghandlers}/endc_x2Setup_failure_response_notification_handler.go (91%) rename E2Manager/handlers/{ => rmrmsghandlers}/notification_handler.go (97%) rename E2Manager/handlers/{ => rmrmsghandlers}/ran_lost_connection_handler.go (98%) rename E2Manager/handlers/{ => rmrmsghandlers}/ran_lost_connection_handler_test.go (98%) create mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go create mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go create mode 100644 E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go rename E2Manager/handlers/{ => rmrmsghandlers}/x2Setup_failure_response_notification_handler.go (92%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2_reset_request_notification_handler.go (71%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2_reset_request_notification_handler_test.go (99%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2_reset_response_handler.go (81%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2_reset_response_handler_test.go (99%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2apSetup_response_notification_handler.go (92%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2enb_configuration_update_handler.go (80%) rename E2Manager/handlers/{ => rmrmsghandlers}/x2enb_configuration_update_handler_test.go (99%) delete mode 100644 E2Manager/handlers/setup_response_notification_handler.go delete mode 100644 E2Manager/handlers/setup_response_notification_handler_test.go create mode 100644 E2Manager/managers/endc_setup_failure_response_manager.go create mode 100644 E2Manager/managers/endc_setup_response_manager.go create mode 100644 E2Manager/managers/i_setup_response_manager.go create mode 100644 E2Manager/managers/x2_setup_failure_response_manager.go create mode 100644 E2Manager/managers/x2_setup_response_manager.go diff --git a/E2Manager/container-tag.yaml b/E2Manager/container-tag.yaml index 4add8c7..bad22ad 100644 --- a/E2Manager/container-tag.yaml +++ b/E2Manager/container-tag.yaml @@ -1,4 +1,4 @@ # The Jenkins job requires a tag to build the Docker image. # Global-JJB script assumes this file is in the repo root. --- -tag: 2.0.4 +tag: 2.0.5 diff --git a/E2Manager/controllers/controller.go b/E2Manager/controllers/controller.go index 7d549b2..6c86816 100644 --- a/E2Manager/controllers/controller.go +++ b/E2Manager/controllers/controller.go @@ -79,12 +79,13 @@ func (c *Controller) extractJsonBody(r *http.Request, request models.Request, wr } decoder := json.NewDecoder(r.Body) - if err := decoder.Decode(request); err != nil { - if err != nil { - c.logger.Errorf("[Client -> E2 Manager] #controller.extractJsonBody - unable to extract json body - error: %s", err) - c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer) - return false - } + + err := decoder.Decode(request) + + if err != nil { + c.logger.Errorf("[Client -> E2 Manager] #controller.extractJsonBody - unable to extract json body - error: %s", err) + c.handleErrorResponse(e2managererrors.NewInvalidJsonError(), writer) + return false } return true @@ -103,6 +104,7 @@ func (c *Controller) handleRequest(writer http.ResponseWriter, header *http.Head } handler, err := c.handlerProvider.GetHandler(requestName) + if err != nil { c.handleErrorResponse(err, writer) return diff --git a/E2Manager/controllers/nodeb_controller.go b/E2Manager/controllers/nodeb_controller.go index 5a82f10..802537d 100644 --- a/E2Manager/controllers/nodeb_controller.go +++ b/E2Manager/controllers/nodeb_controller.go @@ -72,8 +72,7 @@ type NodebController struct { rnibWriterProvider func() rNibWriter.RNibWriter } -func NewNodebController(logger *logger.Logger, rmrService *services.RmrService, rnibReaderProvider func() reader.RNibReader, - rnibWriterProvider func() rNibWriter.RNibWriter) *NodebController { +func NewNodebController(logger *logger.Logger, rmrService *services.RmrService, rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter) *NodebController { messageChannel = make(chan *models.E2RequestMessage) errorChannel = make(chan error) return &NodebController{ diff --git a/E2Manager/handlers/enb_load_information_to_protobuf.go b/E2Manager/converters/enb_load_information_to_protobuf.go similarity index 99% rename from E2Manager/handlers/enb_load_information_to_protobuf.go rename to E2Manager/converters/enb_load_information_to_protobuf.go index 51d6efa..0a6a315 100644 --- a/E2Manager/handlers/enb_load_information_to_protobuf.go +++ b/E2Manager/converters/enb_load_information_to_protobuf.go @@ -1,4 +1,4 @@ -package handlers +package converters // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec @@ -632,7 +632,7 @@ func populateCellLoadInformationExtensionIEs(cellId string, cellLoadInformation return nil } -func extractAndBuildRanLoadInformation(pdu *C.E2AP_PDU_t, ranLoadInformation *entities.RanLoadInformation) error { +func ExtractAndBuildRanLoadInformation(pdu *C.E2AP_PDU_t, ranLoadInformation *entities.RanLoadInformation) error { defer C.delete_pdu(pdu) diff --git a/E2Manager/handlers/enb_load_information_to_protobuf_test.go b/E2Manager/converters/enb_load_information_to_protobuf_test.go similarity index 99% rename from E2Manager/handlers/enb_load_information_to_protobuf_test.go rename to E2Manager/converters/enb_load_information_to_protobuf_test.go index bf91125..020012f 100644 --- a/E2Manager/handlers/enb_load_information_to_protobuf_test.go +++ b/E2Manager/converters/enb_load_information_to_protobuf_test.go @@ -15,7 +15,7 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" @@ -80,7 +80,7 @@ var testCases = []LoadInformationTestCase{ // // actualRanLoadInformation := &entities.RanLoadInformation{LoadTimestamp: LoadTimestamp} // -// err = extractAndBuildRanLoadInformation(pdu, actualRanLoadInformation) +// err = ExtractAndBuildRanLoadInformation(pdu, actualRanLoadInformation) // // if err != nil { // t.Errorf("want: success, got: error: %v\n", err) diff --git a/E2Manager/handlers/endc_x2setupFailureResponseToProtobuf.go b/E2Manager/converters/endc_x2setupFailureResponseToProtobuf.go similarity index 93% rename from E2Manager/handlers/endc_x2setupFailureResponseToProtobuf.go rename to E2Manager/converters/endc_x2setupFailureResponseToProtobuf.go index 4b956d3..3283f0a 100644 --- a/E2Manager/handlers/endc_x2setupFailureResponseToProtobuf.go +++ b/E2Manager/converters/endc_x2setupFailureResponseToProtobuf.go @@ -15,9 +15,9 @@ // limitations under the License. // -package handlers +package converters -// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ +// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec // #include // #include @@ -68,8 +68,8 @@ func endcX2SetupFailureResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.SetupFai return &setupFailure, nil } -func unpackEndcX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) { - pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) +func UnpackEndcX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) { + pdu, err := UnpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) if err != nil { return nil, err } diff --git a/E2Manager/handlers/endc_x2setupFailureResponseToProtobuf_test.go b/E2Manager/converters/endc_x2setupFailureResponseToProtobuf_test.go similarity index 63% rename from E2Manager/handlers/endc_x2setupFailureResponseToProtobuf_test.go rename to E2Manager/converters/endc_x2setupFailureResponseToProtobuf_test.go index 05d7bce..f51b987 100644 --- a/E2Manager/handlers/endc_x2setupFailureResponseToProtobuf_test.go +++ b/E2Manager/converters/endc_x2setupFailureResponseToProtobuf_test.go @@ -15,68 +15,69 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/rNibWriter" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "strings" "testing" ) /* Test permutations of x2 setup response to protobuf enb - */ +*/ func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) { logger, _ := logger.InitLogger(logger.InfoLevel) var testCases = []struct { - saveToRNib bool - response string - packedPdu string - failure error + saveToRNib bool + response string + packedPdu string + failure error }{ { saveToRNib: false, //TODO: use MOCK? - response: "CONNECTED_SETUP_FAILED network_layer_cause:HANDOVER_DESIRABLE_FOR_RADIO_REASONS time_to_wait:V1S criticality_diagnostics: > ", + response: "CONNECTED_SETUP_FAILED network_layer_cause:HANDOVER_DESIRABLE_FOR_RADIO_REASONS time_to_wait:V1S criticality_diagnostics: > ", /* - E2AP-PDU: - unsuccessfulOutcome_t - procedureCode_t = 0x24 - criticality_t = 0 - ENDCX2SetupFailure - protocolIEs_t: - ProtocolIE_Container_elm - id_t = 0x5 - criticality_t = 0x1 - Cause: - radioNetwork_t = 0 - ProtocolIE_Container_elm - id_t = 0x16 - criticality_t = 0x1 - TimeToWait = 0 - ProtocolIE_Container_elm - id_t = 0x11 - criticality_t = 0x1 - CriticalityDiagnostics - procedureCode_t = 0x21 - triggeringMessage_t = 0x2 - procedureCriticality_t = 0x2 - iEsCriticalityDiagnostics_t: - CriticalityDiagnostics_IE_List_elm - iECriticality_t = 0 - iE_ID_t = 0x80 - typeOfError_t = 0x1 + E2AP-PDU: + unsuccessfulOutcome_t + procedureCode_t = 0x24 + criticality_t = 0 + ENDCX2SetupFailure + protocolIEs_t: + ProtocolIE_Container_elm + id_t = 0x5 + criticality_t = 0x1 + Cause: + radioNetwork_t = 0 + ProtocolIE_Container_elm + id_t = 0x16 + criticality_t = 0x1 + TimeToWait = 0 + ProtocolIE_Container_elm + id_t = 0x11 + criticality_t = 0x1 + CriticalityDiagnostics + procedureCode_t = 0x21 + triggeringMessage_t = 0x2 + procedureCriticality_t = 0x2 + iEsCriticalityDiagnostics_t: + CriticalityDiagnostics_IE_List_elm + iECriticality_t = 0 + iE_ID_t = 0x80 + typeOfError_t = 0x1 */ packedPdu: "4024001a0000030005400200000016400100001140087821a00000008040"}, - /**** shares the same code with x2setup failure response to protobuf ****/ + /**** shares the same code with x2setup failure response to protobuf ****/ } - initDb_f := true + initDb_f := true for _, tc := range testCases { t.Run(tc.packedPdu, func(t *testing.T) { @@ -86,7 +87,7 @@ func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - response, err := unpackEndcX2SetupFailureResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + response, err := UnpackEndcX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { if tc.failure == nil { @@ -105,7 +106,7 @@ func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) { } else { nb := &entities.NodebInfo{} nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED_SETUP_FAILED - nb.SetupFailure = response + nb.SetupFailure = response nb.FailureType = entities.Failure_X2_SETUP_FAILURE respStr := fmt.Sprintf("%s %s", nb.ConnectionStatus, response) if !strings.EqualFold(respStr, tc.response) { @@ -118,7 +119,7 @@ func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) { rNibWriter.Init("e2Manager", 1) initDb_f = false } - nbIdentity := &entities.NbIdentity{InventoryName:"RanName"} + nbIdentity := &entities.NbIdentity{InventoryName: "RanName"} if rNibErr := rNibWriter.GetRNibWriter().SaveNodeb(nbIdentity, nb); rNibErr != nil { if tc.failure == nil { t.Errorf("rNibWriter failed to save ENB. Error: %s\n", rNibErr.Error()) @@ -133,4 +134,3 @@ func TestUnpackEndcX2SetupFailureResponseAndExtract(t *testing.T) { }) } } - diff --git a/E2Manager/handlers/endc_x2setupResponseToProtobuf.go b/E2Manager/converters/endc_x2setupResponseToProtobuf.go similarity index 99% rename from E2Manager/handlers/endc_x2setupResponseToProtobuf.go rename to E2Manager/converters/endc_x2setupResponseToProtobuf.go index b4d098d..01e901a 100644 --- a/E2Manager/handlers/endc_x2setupResponseToProtobuf.go +++ b/E2Manager/converters/endc_x2setupResponseToProtobuf.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package converters // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec @@ -315,8 +315,8 @@ func endcX2SetupResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.GlobalNbId, *en return globalNbId, gnb, nil } -func unpackEndcX2SetupResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.GlobalNbId, *entities.Gnb, error) { - pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) +func UnpackEndcX2SetupResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.GlobalNbId, *entities.Gnb, error) { + pdu, err := UnpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) if err != nil { return nil, nil, err } diff --git a/E2Manager/handlers/endc_x2setupResponseToProtobuf_test.go b/E2Manager/converters/endc_x2setupResponseToProtobuf_test.go similarity index 99% rename from E2Manager/handlers/endc_x2setupResponseToProtobuf_test.go rename to E2Manager/converters/endc_x2setupResponseToProtobuf_test.go index 5fe9147..60b7e6d 100644 --- a/E2Manager/handlers/endc_x2setupResponseToProtobuf_test.go +++ b/E2Manager/converters/endc_x2setupResponseToProtobuf_test.go @@ -15,13 +15,14 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/rNibWriter" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "strings" "testing" ) @@ -573,7 +574,7 @@ func TestUnpackEndcX2SetupResponseAndExtract(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - key, gnb, err := unpackEndcX2SetupResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + key, gnb, err := UnpackEndcX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize) if err != nil { if tc.failure == nil { diff --git a/E2Manager/handlers/x2apPdu_asn1_unpacker.go b/E2Manager/converters/x2apPdu_asn1_unpacker.go similarity index 88% rename from E2Manager/handlers/x2apPdu_asn1_unpacker.go rename to E2Manager/converters/x2apPdu_asn1_unpacker.go index 3a89e5c..9506b9f 100644 --- a/E2Manager/handlers/x2apPdu_asn1_unpacker.go +++ b/E2Manager/converters/x2apPdu_asn1_unpacker.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package converters // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec @@ -30,7 +30,7 @@ import ( ) type X2PduRefinedResponse struct { - pduPrint string + PduPrint string } //func unpackX2apPduUPer(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*C.E2AP_PDU_t, error) { @@ -55,14 +55,14 @@ type X2PduRefinedResponse struct { // return pdu, nil //} -func unpackX2apPdu(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*C.E2AP_PDU_t, error) { +func UnpackX2apPdu(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*C.E2AP_PDU_t, error) { pdu := C.new_pdu(C.ulong(allocationBufferSize)) if pdu == nil { return nil, errors.New("allocation failure (pdu)") } - logger.Infof("#x2apPdu_asn1_unpacker.unpackX2apPdu - Packed pdu(%d):%x", packedBufferSize, packedBuf) + logger.Infof("#x2apPdu_asn1_unpacker.UnpackX2apPdu - Packed pdu(%d):%x", packedBufferSize, packedBuf) errBuf := make([]C.char, maxMessageBufferSize) if !C.per_unpack_pdu(pdu, C.ulong(packedBufferSize), (*C.uchar)(unsafe.Pointer(&packedBuf[0])), C.ulong(len(errBuf)), &errBuf[0]) { @@ -71,14 +71,14 @@ func unpackX2apPdu(logger *logger.Logger, allocationBufferSize int, packedBuffer if logger.DebugEnabled() { C.asn1_pdu_printer(pdu, C.size_t(len(errBuf)), &errBuf[0]) - logger.Debugf("#x2apPdu_asn1_unpacker.unpackX2apPdu - PDU: %v packed size:%d", C.GoString(&errBuf[0]), packedBufferSize) + logger.Debugf("#x2apPdu_asn1_unpacker.UnpackX2apPdu - PDU: %v packed size:%d", C.GoString(&errBuf[0]), packedBufferSize) } return pdu, nil } -func unpackX2apPduAndRefine(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*X2PduRefinedResponse, error) { - pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) +func UnpackX2apPduAndRefine(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*X2PduRefinedResponse, error) { + pdu, err := UnpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) if err != nil { return nil, err } @@ -92,7 +92,7 @@ func unpackX2apPduAndRefine(logger *logger.Logger, allocationBufferSize int, pac refinedResponse = C.GoString(&buf[0]) } - return &X2PduRefinedResponse{pduPrint: refinedResponse}, nil + return &X2PduRefinedResponse{PduPrint: refinedResponse}, nil } diff --git a/E2Manager/handlers/x2apPdu_asn1_unpacker_test.go b/E2Manager/converters/x2apPdu_asn1_unpacker_test.go similarity index 87% rename from E2Manager/handlers/x2apPdu_asn1_unpacker_test.go rename to E2Manager/converters/x2apPdu_asn1_unpacker_test.go index 89527f5..7622f85 100644 --- a/E2Manager/handlers/x2apPdu_asn1_unpacker_test.go +++ b/E2Manager/converters/x2apPdu_asn1_unpacker_test.go @@ -15,9 +15,10 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( + "e2mgr/e2pdus" "e2mgr/logger" "fmt" "strings" @@ -82,19 +83,19 @@ func TestUnpackX2apSetupResponse(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - response, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + response, err := UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { t.Errorf("want: success, got: unpack failed. Error: %v\n", err) } - want:= strings.Fields(wantPduAsStr) - got:= strings.Fields(response.pduPrint) + want := strings.Fields(wantPduAsStr) + got := strings.Fields(response.PduPrint) if len(want) != len(got) { - t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.pduPrint) + t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, response.PduPrint) } - for i:=0; i < len(want); i++ { - if strings.Compare(want[i], got[i] ) != 0 { - t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.pduPrint)) + for i := 0; i < len(want); i++ { + if strings.Compare(want[i], got[i]) != 0 { + t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", wantPduAsStr, strings.TrimSpace(response.PduPrint)) } } @@ -114,7 +115,7 @@ func TestUnpackX2apSetupResponseUnpackError(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - _, err = unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + _, err = UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { if 0 != strings.Compare(fmt.Sprintf("%s", err), wantError) { t.Errorf("want failure: %s, got: %s", wantError, err) @@ -124,5 +125,3 @@ func TestUnpackX2apSetupResponseUnpackError(t *testing.T) { } } - - diff --git a/E2Manager/handlers/x2setupFailureResponseToProtobuf.go b/E2Manager/converters/x2setupFailureResponseToProtobuf.go similarity index 97% rename from E2Manager/handlers/x2setupFailureResponseToProtobuf.go rename to E2Manager/converters/x2setupFailureResponseToProtobuf.go index d72cae3..e43ded4 100644 --- a/E2Manager/handlers/x2setupFailureResponseToProtobuf.go +++ b/E2Manager/converters/x2setupFailureResponseToProtobuf.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package converters // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec @@ -138,8 +138,8 @@ func x2SetupFailureResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.SetupFailure return &setupFailure, nil } -func unpackX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) { - pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) +func UnpackX2SetupFailureResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.SetupFailure, error) { + pdu, err := UnpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) if err != nil { return nil, err } diff --git a/E2Manager/handlers/x2setupFailureResponseToProtobuf_test.go b/E2Manager/converters/x2setupFailureResponseToProtobuf_test.go similarity index 97% rename from E2Manager/handlers/x2setupFailureResponseToProtobuf_test.go rename to E2Manager/converters/x2setupFailureResponseToProtobuf_test.go index 2080058..3bc099b 100644 --- a/E2Manager/handlers/x2setupFailureResponseToProtobuf_test.go +++ b/E2Manager/converters/x2setupFailureResponseToProtobuf_test.go @@ -15,13 +15,14 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/rNibWriter" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "strings" "testing" ) @@ -277,7 +278,7 @@ func TestUnpackX2SetupFailureResponseAndExtract(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - response, err := unpackX2SetupFailureResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + response, err := UnpackX2SetupFailureResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { if tc.failure == nil { diff --git a/E2Manager/handlers/x2setupResponseToProtobuf.go b/E2Manager/converters/x2setupResponseToProtobuf.go similarity index 99% rename from E2Manager/handlers/x2setupResponseToProtobuf.go rename to E2Manager/converters/x2setupResponseToProtobuf.go index 3e8ee26..880d88e 100644 --- a/E2Manager/handlers/x2setupResponseToProtobuf.go +++ b/E2Manager/converters/x2setupResponseToProtobuf.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package converters // #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ // #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec @@ -23,9 +23,9 @@ package handlers // #include import "C" import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "e2mgr/logger" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "github.com/pkg/errors" "unsafe" ) @@ -427,8 +427,8 @@ func x2SetupResponseToProtobuf(pdu *C.E2AP_PDU_t) (*entities.GlobalNbId, *entiti return globalNbId, &enb, nil } -func unpackX2SetupResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.GlobalNbId, *entities.Enb, error) { - pdu, err := unpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) +func UnpackX2SetupResponseAndExtract(logger *logger.Logger, allocationBufferSize int, packedBufferSize int, packedBuf []byte, maxMessageBufferSize int) (*entities.GlobalNbId, *entities.Enb, error) { + pdu, err := UnpackX2apPdu(logger, allocationBufferSize, packedBufferSize, packedBuf, maxMessageBufferSize) if err != nil { return nil, nil, err } diff --git a/E2Manager/handlers/x2setupResponseToProtobuf_test.go b/E2Manager/converters/x2setupResponseToProtobuf_test.go similarity index 99% rename from E2Manager/handlers/x2setupResponseToProtobuf_test.go rename to E2Manager/converters/x2setupResponseToProtobuf_test.go index 666794e..7ab91d1 100644 --- a/E2Manager/handlers/x2setupResponseToProtobuf_test.go +++ b/E2Manager/converters/x2setupResponseToProtobuf_test.go @@ -15,13 +15,14 @@ * limitations under the License. * *******************************************************************************/ -package handlers +package converters import ( - "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/rNibWriter" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "strings" "testing" ) @@ -1158,7 +1159,7 @@ func TestUnpackX2SetupResponseAndExtract(t *testing.T) { t.Errorf("convert inputPayloadAsStr to payloadAsByte. Error: %v\n", err) } - key, enb, err := unpackX2SetupResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, len(payload), payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + key, enb, err := UnpackX2SetupResponseAndExtract(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, len(payload), payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { if tc.failure == nil { diff --git a/E2Manager/e2pdus/x2_reset_known_causes.go b/E2Manager/e2pdus/x2_reset_known_causes.go index df84a4b..9140f3d 100644 --- a/E2Manager/e2pdus/x2_reset_known_causes.go +++ b/E2Manager/e2pdus/x2_reset_known_causes.go @@ -31,6 +31,7 @@ import ( const ( MaxAsn1PackedBufferSize = 4096 MaxAsn1CodecMessageBufferSize = 4096 + MaxAsn1CodecAllocationBufferSize = 4096 // TODO: remove later ) // Used as default by the x2_reset_request diff --git a/E2Manager/handlers/delete_all_request_handler.go b/E2Manager/handlers/httpmsghandlers/delete_all_request_handler.go similarity index 97% rename from E2Manager/handlers/delete_all_request_handler.go rename to E2Manager/handlers/httpmsghandlers/delete_all_request_handler.go index b0899ba..6e70deb 100644 --- a/E2Manager/handlers/delete_all_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/delete_all_request_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import "C" import ( @@ -39,8 +39,7 @@ type DeleteAllRequestHandler struct { config *configuration.Configuration } -func NewDeleteAllRequestHandler(rmrService *services.RmrService, config *configuration.Configuration, writerProvider func() rNibWriter.RNibWriter, - readerProvider func() reader.RNibReader) *DeleteAllRequestHandler { +func NewDeleteAllRequestHandler(rmrService *services.RmrService, config *configuration.Configuration, writerProvider func() rNibWriter.RNibWriter, readerProvider func() reader.RNibReader) *DeleteAllRequestHandler { return &DeleteAllRequestHandler { readerProvider: readerProvider, writerProvider: writerProvider, diff --git a/E2Manager/handlers/delete_all_request_handler_test.go b/E2Manager/handlers/httpmsghandlers/delete_all_request_handler_test.go similarity index 99% rename from E2Manager/handlers/delete_all_request_handler_test.go rename to E2Manager/handlers/httpmsghandlers/delete_all_request_handler_test.go index e4e57b8..aae7322 100644 --- a/E2Manager/handlers/delete_all_request_handler_test.go +++ b/E2Manager/handlers/httpmsghandlers/delete_all_request_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/configuration" diff --git a/E2Manager/handlers/endc_setup_request_handler.go b/E2Manager/handlers/httpmsghandlers/endc_setup_request_handler.go similarity index 99% rename from E2Manager/handlers/endc_setup_request_handler.go rename to E2Manager/handlers/httpmsghandlers/endc_setup_request_handler.go index 6954149..8f3658b 100644 --- a/E2Manager/handlers/endc_setup_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/endc_setup_request_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/e2pdus" diff --git a/E2Manager/handlers/endc_setup_request_handler_test.go b/E2Manager/handlers/httpmsghandlers/endc_setup_request_handler_test.go similarity index 98% rename from E2Manager/handlers/endc_setup_request_handler_test.go rename to E2Manager/handlers/httpmsghandlers/endc_setup_request_handler_test.go index 0c3b8e1..2a55532 100644 --- a/E2Manager/handlers/endc_setup_request_handler_test.go +++ b/E2Manager/handlers/httpmsghandlers/endc_setup_request_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/handler.go b/E2Manager/handlers/httpmsghandlers/handler.go similarity index 97% rename from E2Manager/handlers/handler.go rename to E2Manager/handlers/httpmsghandlers/handler.go index 2a53c00..474f20a 100644 --- a/E2Manager/handlers/handler.go +++ b/E2Manager/handlers/httpmsghandlers/handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/request_handler.go b/E2Manager/handlers/httpmsghandlers/request_handler.go similarity index 96% rename from E2Manager/handlers/request_handler.go rename to E2Manager/handlers/httpmsghandlers/request_handler.go index a8745f9..c5c84ec 100644 --- a/E2Manager/handlers/request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/request_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/setup_request_handler.go b/E2Manager/handlers/httpmsghandlers/setup_request_handler.go similarity index 99% rename from E2Manager/handlers/setup_request_handler.go rename to E2Manager/handlers/httpmsghandlers/setup_request_handler.go index 4c49b1d..f3cf7b6 100644 --- a/E2Manager/handlers/setup_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/setup_request_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/e2pdus" diff --git a/E2Manager/handlers/setup_request_handler_test.go b/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go similarity index 99% rename from E2Manager/handlers/setup_request_handler_test.go rename to E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go index afd093d..dddda35 100644 --- a/E2Manager/handlers/setup_request_handler_test.go +++ b/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "bytes" diff --git a/E2Manager/handlers/x2_reset_request_handler.go b/E2Manager/handlers/httpmsghandlers/x2_reset_request_handler.go similarity index 99% rename from E2Manager/handlers/x2_reset_request_handler.go rename to E2Manager/handlers/httpmsghandlers/x2_reset_request_handler.go index f61e60c..2455ac6 100644 --- a/E2Manager/handlers/x2_reset_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/x2_reset_request_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package httpmsghandlers import ( "e2mgr/configuration" diff --git a/E2Manager/handlers/x2_reset_request_handler_test.go b/E2Manager/handlers/httpmsghandlers/x2_reset_request_handler_test.go similarity index 94% rename from E2Manager/handlers/x2_reset_request_handler_test.go rename to E2Manager/handlers/httpmsghandlers/x2_reset_request_handler_test.go index 991b582..35370c0 100644 --- a/E2Manager/handlers/x2_reset_request_handler_test.go +++ b/E2Manager/handlers/httpmsghandlers/x2_reset_request_handler_test.go @@ -1,4 +1,4 @@ -package handlers +package httpmsghandlers import ( "e2mgr/configuration" @@ -38,7 +38,7 @@ func TestHandleSuccessfulDefaultCause(t *testing.T){ rmrMessengerMock.On("SendMsg",msg,mock.Anything).Return(msg,nil) config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED } @@ -71,7 +71,7 @@ func TestHandleSuccessfulRequestedCause(t *testing.T){ rmrMessengerMock.On("SendMsg",msg,mock.Anything).Return(msg,nil) config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED } @@ -101,7 +101,7 @@ func TestHandleFailureUnknownCause(t *testing.T){ config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED } @@ -132,7 +132,7 @@ func TestHandleFailureWrongState(t *testing.T){ config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED } @@ -165,7 +165,7 @@ func TestHandleFailureRanNotFound(t *testing.T){ config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) readerMock.On("GetNodeb",ranName).Return(&entities.NodebInfo{}, common.NewResourceNotFoundError("nodeb not found")) @@ -196,7 +196,7 @@ func TestHandleFailureRnibError(t *testing.T){ config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) readerMock.On("GetNodeb",ranName).Return(&entities.NodebInfo{}, common.NewInternalError(fmt.Errorf("internal error"))) @@ -229,7 +229,7 @@ func TestHandleFailureRmrError(t *testing.T){ rmrMessengerMock.On("SendMsg",msg,mock.Anything).Return(&rmrCgo.MBuf{},fmt.Errorf("rmr error")) config := configuration.ParseConfiguration() - rmrService:=getRmrService(rmrMessengerMock, log) + rmrService:= getRmrService(rmrMessengerMock, log) handler := NewX2ResetRequestHandler(rmrService, config, writerProvider, readerProvider) var nodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED } diff --git a/E2Manager/handlers/e2_term_init_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go similarity index 90% rename from E2Manager/handlers/e2_term_init_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go index 6cc88ae..86bf3f2 100644 --- a/E2Manager/handlers/e2_term_init_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" @@ -38,10 +38,9 @@ func NewE2TermInitNotificationHandler(ranReconnectionManager *managers.RanReconn } } -func (handler E2TermInitNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { +func (handler E2TermInitNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT") +logger.Infof("#E2TermInitNotificationHandler.Handle - Handling E2_TERM_INIT") nbIdentityList, err := handler.rnibReaderProvider().GetListNodebIds() if err != nil { diff --git a/E2Manager/handlers/e2_term_init_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go similarity index 76% rename from E2Manager/handlers/e2_term_init_notification_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go index 2086c46..7948f9e 100644 --- a/E2Manager/handlers/e2_term_init_notification_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go @@ -1,4 +1,4 @@ -package handlers +package rmrmsghandlers import ( "e2mgr/configuration" @@ -9,6 +9,9 @@ import ( "e2mgr/models" "e2mgr/rNibWriter" "e2mgr/rmrCgo" + "e2mgr/services" + "e2mgr/sessions" + "e2mgr/tests" "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" @@ -44,7 +47,7 @@ func TestE2TerminInitHandlerSuccessOneRan(t *testing.T) { return readerMock } - ids := []*entities.NbIdentity {{InventoryName:"test1"}} + ids := []*entities.NbIdentity{{InventoryName: "test1"}} readerMock.On("GetListNodebIds").Return(ids, rnibErr) var initialNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} @@ -74,7 +77,7 @@ func TestE2TerminInitHandlerSuccessTwoRans(t *testing.T) { return readerMock } - ids := []*entities.NbIdentity {{InventoryName:"test1"}, {InventoryName:"test2"} } + ids := []*entities.NbIdentity{{InventoryName: "test1"}, {InventoryName: "test2"}} readerMock.On("GetListNodebIds").Return(ids, rnibErr) var initialNodeb0 = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} @@ -85,7 +88,6 @@ func TestE2TerminInitHandlerSuccessTwoRans(t *testing.T) { var argNodeb = &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} writerMock.On("UpdateNodebInfo", argNodeb).Return(rnibErr) - payload := e2pdus.PackedX2setupRequest xaction := []byte(ids[0].InventoryName) msg := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[0].InventoryName, &payload, &xaction) @@ -107,7 +109,7 @@ func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { return readerMock } - ids := []*entities.NbIdentity {{InventoryName:"test1"}, {InventoryName:"test2"},{InventoryName:"test3"} } + ids := []*entities.NbIdentity{{InventoryName: "test1"}, {InventoryName: "test2"}, {InventoryName: "test3"}} readerMock.On("GetListNodebIds").Return(ids, rnibErr) var initialNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} @@ -117,13 +119,12 @@ func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { readerMock.On("GetNodeb", ids[1].InventoryName).Return(initialNodeb1, rnibErr) readerMock.On("GetNodeb", ids[2].InventoryName).Return(initialNodeb2, rnibErr) - var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var argNodeb0Fail = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0} + var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb0Fail = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 0} writerMock.On("UpdateNodebInfo", argNodeb0).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodeb0Fail).Return(rnibErr) - - payload :=models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0,ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) + payload := models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0, ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) xaction := []byte(ids[0].InventoryName) msg0 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[0].InventoryName, &payload, &xaction) @@ -132,7 +133,7 @@ func TestE2TerminInitHandlerSuccessThreeRansFirstRmrFailure(t *testing.T) { //xaction = []byte(ids[1].InventoryName) //msg1 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[1].InventoryName, &payload, &xaction) - rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, fmt.Errorf("RMR Error")) + rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, fmt.Errorf("RMR Error")) handler := NewE2TermInitNotificationHandler(ranReconnectMgr, readerProvider) handler.Handle(log, nil, nil, nil) @@ -151,7 +152,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) return readerMock } - ids := []*entities.NbIdentity {{InventoryName:"test1"}, {InventoryName:"test2"},{InventoryName:"test3"} } + ids := []*entities.NbIdentity{{InventoryName: "test1"}, {InventoryName: "test2"}, {InventoryName: "test3"}} readerMock.On("GetListNodebIds").Return(ids, rnibErr) var initialNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} @@ -161,18 +162,17 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) readerMock.On("GetNodeb", ids[1].InventoryName).Return(initialNodeb1, common.NewResourceNotFoundError("not found")) readerMock.On("GetNodeb", ids[2].InventoryName).Return(initialNodeb2, rnibErr) - var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var argNodeb0Success = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb0Success = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} writerMock.On("UpdateNodebInfo", argNodeb0).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodeb0Success).Return(rnibErr) - var argNodeb2 = &entities.NodebInfo{RanName: ids[2].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var argNodeb2Success = &entities.NodebInfo{RanName: ids[2].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb2 = &entities.NodebInfo{RanName: ids[2].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb2Success = &entities.NodebInfo{RanName: ids[2].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} writerMock.On("UpdateNodebInfo", argNodeb2).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodeb2Success).Return(rnibErr) - - payload :=models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0,ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) + payload := models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0, ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) xaction := []byte(ids[0].InventoryName) msg0 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[0].InventoryName, &payload, &xaction) @@ -181,7 +181,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) //xaction = []byte(ids[1].InventoryName) //msg1 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[1].InventoryName, &payload, &xaction) - rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, nil) + rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, nil) handler := NewE2TermInitNotificationHandler(ranReconnectMgr, readerProvider) handler.Handle(log, nil, nil, nil) @@ -193,7 +193,6 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondNotFoundFailure(t *testing.T) rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 2) } - func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *testing.T) { log, readerMock, writerMock, rmrMessengerMock, ranReconnectMgr := initRanLostConnectionTest(t) var rnibErr error @@ -202,7 +201,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te return readerMock } - ids := []*entities.NbIdentity {{InventoryName:"test1"}, {InventoryName:"test2"},{InventoryName:"test3"} } + ids := []*entities.NbIdentity{{InventoryName: "test1"}, {InventoryName: "test2"}, {InventoryName: "test3"}} readerMock.On("GetListNodebIds").Return(ids, rnibErr) var initialNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST} @@ -212,18 +211,17 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te readerMock.On("GetNodeb", ids[1].InventoryName).Return(initialNodeb1, common.NewInternalError(fmt.Errorf("internal error"))) readerMock.On("GetNodeb", ids[2].InventoryName).Return(initialNodeb2, rnibErr) - var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var argNodeb0Success = &entities.NodebInfo{RanName: ids[0].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb0 = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb0Success = &entities.NodebInfo{RanName: ids[0].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} writerMock.On("UpdateNodebInfo", argNodeb0).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodeb0Success).Return(rnibErr) - var argNodeb2 = &entities.NodebInfo{RanName: ids[2].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} - var argNodeb2Success = &entities.NodebInfo{RanName: ids[2].InventoryName,ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb2 = &entities.NodebInfo{RanName: ids[2].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTING, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} + var argNodeb2Success = &entities.NodebInfo{RanName: ids[2].InventoryName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol: entities.E2ApplicationProtocol_X2_SETUP_REQUEST, ConnectionAttempts: 1} writerMock.On("UpdateNodebInfo", argNodeb2).Return(rnibErr) writerMock.On("UpdateNodebInfo", argNodeb2Success).Return(rnibErr) - - payload :=models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0,ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) + payload := models.NewE2RequestMessage(ids[0].InventoryName /*tid*/, "", 0, ids[0].InventoryName, e2pdus.PackedX2setupRequest).GetMessageAsBytes(log) xaction := []byte(ids[0].InventoryName) msg0 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[0].InventoryName, &payload, &xaction) @@ -232,7 +230,7 @@ func TestE2TerminInitHandlerSuccessThreeRansSecondRnibInternalErrorFailure(t *te //xaction = []byte(ids[1].InventoryName) //msg1 := rmrCgo.NewMBuf(rmrCgo.RIC_X2_SETUP_REQ, len(payload), ids[1].InventoryName, &payload, &xaction) - rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, nil) + rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(msg0, nil) handler := NewE2TermInitNotificationHandler(ranReconnectMgr, readerProvider) handler.Handle(log, nil, nil, nil) @@ -252,7 +250,7 @@ func TestE2TerminInitHandlerSuccessZeroRans(t *testing.T) { return readerMock } - readerMock.On("GetListNodebIds").Return( []*entities.NbIdentity{} , rnibErr) + readerMock.On("GetListNodebIds").Return([]*entities.NbIdentity{}, rnibErr) handler := NewE2TermInitNotificationHandler(ranReconnectMgr, readerProvider) handler.Handle(log, nil, nil, nil) @@ -268,7 +266,7 @@ func TestE2TerminInitHandlerFailureGetListNodebIds(t *testing.T) { return readerMock } - readerMock.On("GetListNodebIds").Return( []*entities.NbIdentity{} , common.NewInternalError(fmt.Errorf("internal error"))) + readerMock.On("GetListNodebIds").Return([]*entities.NbIdentity{}, common.NewInternalError(fmt.Errorf("internal error"))) handler := NewE2TermInitNotificationHandler(ranReconnectMgr, readerProvider) handler.Handle(log, nil, nil, nil) @@ -276,3 +274,20 @@ func TestE2TerminInitHandlerFailureGetListNodebIds(t *testing.T) { writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 0) rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 0) } + +// TODO: extract to test_utils +func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService { + rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock) + messageChannel := make(chan *models.NotificationResponse) + rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger) + return services.NewRmrService(services.NewRmrConfig(tests.Port, tests.MaxMsgSize, tests.Flags, log), rmrMessenger, make(sessions.E2Sessions), messageChannel) +} + +// TODO: extract to test_utils +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) + } + return log +} diff --git a/E2Manager/handlers/enb_load_information_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler.go similarity index 85% rename from E2Manager/handlers/enb_load_information_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler.go index 91461f9..ceee190 100644 --- a/E2Manager/handlers/enb_load_information_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler.go @@ -1,7 +1,9 @@ -package handlers +package rmrmsghandlers import "C" import ( + "e2mgr/converters" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/models" "e2mgr/rNibWriter" @@ -26,7 +28,7 @@ func elapsed(startTime time.Time) float64 { func (src EnbLoadInformationNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - pdu, err := unpackX2apPdu(logger, MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize) + pdu, err := converters.UnpackX2apPdu(logger, e2pdus.MaxAsn1CodecAllocationBufferSize, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize) if err != nil { logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Unpack failed. Error: %v", request.RanName, err) @@ -37,10 +39,10 @@ func (src EnbLoadInformationNotificationHandler) Handle(logger *logger.Logger, e ranLoadInformation := &entities.RanLoadInformation{LoadTimestamp: uint64(request.StartTime.UnixNano())} - err = extractAndBuildRanLoadInformation(pdu, ranLoadInformation) + err = converters.ExtractAndBuildRanLoadInformation(pdu, ranLoadInformation) if (err != nil) { - logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed at extractAndBuildRanLoadInformation. Error: %v", request.RanName, err) + logger.Errorf("#EnbLoadInformationNotificationHandler.Handle - RAN name: %s - Failed at ExtractAndBuildRanLoadInformation. Error: %v", request.RanName, err) return } diff --git a/E2Manager/handlers/enb_load_information_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler_test.go similarity index 99% rename from E2Manager/handlers/enb_load_information_notification_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler_test.go index 89ec80a..c507ec3 100644 --- a/E2Manager/handlers/enb_load_information_notification_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/endc_configuration_update_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go similarity index 79% rename from E2Manager/handlers/endc_configuration_update_handler.go rename to E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go index 1c3736f..a988d48 100644 --- a/E2Manager/handlers/endc_configuration_update_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go @@ -15,14 +15,16 @@ // limitations under the License. // -package handlers +package rmrmsghandlers -// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ -// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec +// #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/converters" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/models" "e2mgr/rmrCgo" @@ -36,12 +38,12 @@ func (src EndcConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessio messageChannel chan<- *models.NotificationResponse) { var payloadSize C.ulong - payloadSize = MaxAsn1PackedBufferSize - packedBuffer := [MaxAsn1PackedBufferSize]C.uchar{} - errorBuffer := [MaxAsn1PackedBufferSize]C.char{} - refinedMessage, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + payloadSize = e2pdus.MaxAsn1PackedBufferSize + packedBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.uchar{} + errorBuffer := [e2pdus.MaxAsn1PackedBufferSize]C.char{} + refinedMessage, err := converters.UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { - status := C.build_pack_endc_configuration_update_failure(&payloadSize, &packedBuffer[0], MaxAsn1PackedBufferSize, &errorBuffer[0]) + status := C.build_pack_endc_configuration_update_failure(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) if status { payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize] logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update negative ack message payload: (%d) %02x", len(payload), payload) @@ -53,8 +55,8 @@ func (src EndcConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessio logger.Errorf("#endc_configuration_update_handler.Handle - unpack failed. Error: %v", err) } else { logger.Infof("#endc_configuration_update_handler.Handle - Endc configuration update initiating message received") - logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update initiating message payload: %s", refinedMessage.pduPrint) - status := C.build_pack_endc_configuration_update_ack(&payloadSize, &packedBuffer[0], MaxAsn1PackedBufferSize, &errorBuffer[0]) + logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update initiating message payload: %s", refinedMessage.PduPrint) + status := C.build_pack_endc_configuration_update_ack(&payloadSize, &packedBuffer[0], e2pdus.MaxAsn1PackedBufferSize, &errorBuffer[0]) if status { payload := (*[1 << 30]byte)(unsafe.Pointer(&packedBuffer))[:payloadSize:payloadSize] logger.Debugf("#endc_configuration_update_handler.Handle - Endc configuration update positive ack message payload: (%d) %02x", len(payload), payload) diff --git a/E2Manager/handlers/endc_configuration_update_handler_test.go b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go similarity index 99% rename from E2Manager/handlers/endc_configuration_update_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go index 9a115c6..450ac8d 100644 --- a/E2Manager/handlers/endc_configuration_update_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/endc_setup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go similarity index 87% rename from E2Manager/handlers/endc_setup_response_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go index 2e64f3e..14ac6da 100644 --- a/E2Manager/handlers/endc_setup_response_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go @@ -15,27 +15,25 @@ // limitations under the License. // -package handlers +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" - - "e2mgr/logger" - "e2mgr/sessions" ) type EndcX2SetupResponseNotificationHandler struct{} -func (src EndcX2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { +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 := unpackEndcX2SetupResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) - + 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) @@ -74,5 +72,4 @@ func (src EndcX2SetupResponseNotificationHandler) Handle(logger *logger.Logger, delete(e2Sessions, request.TransactionId) // Avoid pinning memory (help GC) } - } diff --git a/E2Manager/handlers/endc_x2Setup_failure_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go similarity index 91% rename from E2Manager/handlers/endc_x2Setup_failure_response_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go index d987a34..46a245e 100644 --- a/E2Manager/handlers/endc_x2Setup_failure_response_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go @@ -15,9 +15,11 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( + "e2mgr/converters" + "e2mgr/e2pdus" "e2mgr/rNibWriter" "fmt" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" @@ -34,7 +36,7 @@ func (src EndcX2SetupFailureResponseNotificationHandler) Handle(logger *logger.L e2session, ok := e2Sessions[request.TransactionId] - failureResponse, err := unpackEndcX2SetupFailureResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + 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) } diff --git a/E2Manager/handlers/notification_handler.go b/E2Manager/handlers/rmrmsghandlers/notification_handler.go similarity index 97% rename from E2Manager/handlers/notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/notification_handler.go index 3a31a30..a44b965 100644 --- a/E2Manager/handlers/notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/notification_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/ran_lost_connection_handler.go b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler.go similarity index 98% rename from E2Manager/handlers/ran_lost_connection_handler.go rename to E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler.go index e899202..7933963 100644 --- a/E2Manager/handlers/ran_lost_connection_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/ran_lost_connection_handler_test.go b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go similarity index 98% rename from E2Manager/handlers/ran_lost_connection_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go index 52b71d8..8e1464f 100644 --- a/E2Manager/handlers/ran_lost_connection_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go @@ -14,7 +14,7 @@ //// See the License for the specific language governing permissions and //// limitations under the License. //// -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go new file mode 100644 index 0000000..86843ef --- /dev/null +++ b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go @@ -0,0 +1,78 @@ +// +// 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/managers" + "e2mgr/models" + "e2mgr/rNibWriter" + "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" +) + +type SetupResponseNotificationHandler struct { + rnibReaderProvider func() reader.RNibReader + rnibWriterProvider func() rNibWriter.RNibWriter + setupResponseManager managers.ISetupResponseManager +} + +func NewSetupResponseNotificationHandler(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, setupResponseManager managers.ISetupResponseManager) SetupResponseNotificationHandler { + return SetupResponseNotificationHandler{ + rnibReaderProvider: rnibReaderProvider, + rnibWriterProvider: rnibWriterProvider, + setupResponseManager: setupResponseManager, + } +} + +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) + + nodebInfo, rnibErr := h.rnibReaderProvider().GetNodeb(request.RanName) + + if rnibErr != nil { + logger.Errorf("#X2SetupResponseNotificationHandler - 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) + return + } + + nbIdentity := &entities.NbIdentity{} + + err := h.setupResponseManager.SetNodeb(logger, nbIdentity, nodebInfo, request.Payload) + + if err != nil { + return + } + + rnibErr = h.rnibWriterProvider().SaveNodeb(nbIdentity, nodebInfo) + + if rnibErr != nil { + logger.Errorf("#X2SetupResponseNotificationHandler - 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) +} + +func isConnectionStatusValid(connectionStatus entities.ConnectionStatus) bool { + return connectionStatus == entities.ConnectionStatus_CONNECTING || connectionStatus == entities.ConnectionStatus_CONNECTED +} diff --git a/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go new file mode 100644 index 0000000..2864aa1 --- /dev/null +++ b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go @@ -0,0 +1,48 @@ +// +// 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 new file mode 100644 index 0000000..0203498 --- /dev/null +++ b/E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go @@ -0,0 +1,60 @@ +//// +//// 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/x2Setup_failure_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go similarity index 92% rename from E2Manager/handlers/x2Setup_failure_response_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go index 2994851..6c11467 100644 --- a/E2Manager/handlers/x2Setup_failure_response_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go @@ -15,9 +15,11 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( + "e2mgr/converters" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/models" "e2mgr/rNibWriter" @@ -33,7 +35,7 @@ func (src X2SetupFailureResponseNotificationHandler) Handle(logger *logger.Logge e2session, ok := e2Sessions[request.TransactionId] - failureResponse, err := unpackX2SetupFailureResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + 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) } diff --git a/E2Manager/handlers/x2_reset_request_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler.go similarity index 71% rename from E2Manager/handlers/x2_reset_request_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler.go index 28a50e5..367b936 100644 --- a/E2Manager/handlers/x2_reset_request_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler.go @@ -15,8 +15,13 @@ // limitations under the License. // -package handlers +package rmrmsghandlers +// #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/e2pdus" "e2mgr/logger" @@ -25,6 +30,7 @@ import ( "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 { @@ -37,8 +43,7 @@ func NewX2ResetRequestNotificationHandler(rnibReaderProvider func() reader.RNibR } } -func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { +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) @@ -64,9 +69,24 @@ func (src X2ResetRequestNotificationHandler) Handle(logger *logger.Logger, e2Ses return } - response := models.NotificationResponse{RanName: request.RanName, Payload: e2pdus.PackedX2ResetResponse, MgsType: rmrCgo.RIC_X2_RESET_RESP} - messageChannel <- &response + 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) -} \ No newline at end of file +} + +func (src X2ResetRequestNotificationHandler) createAndAddToChannel(logger *logger.Logger, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { + + packedBuffer := make([]C.uchar, e2pdus.MaxAsn1PackedBufferSize) + errorBuffer := make([]C.char, e2pdus.MaxAsn1CodecMessageBufferSize) + var payloadSize = C.ulong(e2pdus.MaxAsn1PackedBufferSize) + + if status := C.build_pack_x2reset_response(&payloadSize, &packedBuffer[0], C.ulong(e2pdus.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/rmrmsghandlers/x2_reset_request_notification_handler_test.go similarity index 99% rename from E2Manager/handlers/x2_reset_request_notification_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler_test.go index 60264b4..998330b 100644 --- a/E2Manager/handlers/x2_reset_request_notification_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/mocks" @@ -124,4 +124,4 @@ func TestHandleX2ResetRequestNotifGetNodebFailed(t *testing.T){ readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr) h.Handle(log,nil, ¬ificationRequest, nil) -} +} \ No newline at end of file diff --git a/E2Manager/handlers/x2_reset_response_handler.go b/E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler.go similarity index 81% rename from E2Manager/handlers/x2_reset_response_handler.go rename to E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler.go index 8279577..96b1186 100644 --- a/E2Manager/handlers/x2_reset_response_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler.go @@ -15,13 +15,15 @@ // limitations under the License. // -package handlers +package rmrmsghandlers -// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ -// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec +// #cgo CFLAGS: -I../../asn1codec/inc/ -I../../asn1codec/e2ap_engine/ +// #cgo LDFLAGS: -L ../../asn1codec/lib/ -L../../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec // #include import "C" import ( + "e2mgr/converters" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/models" "e2mgr/sessions" @@ -47,11 +49,11 @@ func (src X2ResetResponseHandler) Handle(logger *logger.Logger, e2Sessions sessi logger.Errorf("#x2ResetResponseHandler.Handle - failed to retrieve nb entity. RanName: %s. Error: %s", request.RanName, rNibErr.Error()) } else { logger.Debugf("#x2ResetResponseHandler.Handle - nb entity retrieved. RanName %s, ConnectionStatus %s", nb.RanName, nb.ConnectionStatus) - refinedMessage, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + refinedMessage, err := converters.UnpackX2apPduAndRefine(logger, e2pdus.MaxAsn1CodecAllocationBufferSize , request.Len, request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize /*message buffer*/) if err != nil { logger.Errorf("#x2ResetResponseHandler.Handle - failed to unpack reset response message. RanName %s, Payload: %s", request.RanName, request.Payload) } else { - logger.Debugf("#x2ResetResponseHandler.Handle - reset response message payload unpacked. RanName %s, Message: %s", request.RanName, refinedMessage.pduPrint) + logger.Debugf("#x2ResetResponseHandler.Handle - reset response message payload unpacked. RanName %s, Message: %s", request.RanName, refinedMessage.PduPrint) } } } diff --git a/E2Manager/handlers/x2_reset_response_handler_test.go b/E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler_test.go similarity index 99% rename from E2Manager/handlers/x2_reset_response_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler_test.go index 95485dc..513596f 100644 --- a/E2Manager/handlers/x2_reset_response_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler_test.go @@ -15,7 +15,7 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/x2apSetup_response_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go similarity index 92% rename from E2Manager/handlers/x2apSetup_response_notification_handler.go rename to E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go index b69cf58..555e37b 100644 --- a/E2Manager/handlers/x2apSetup_response_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go @@ -15,9 +15,11 @@ // limitations under the License. // -package handlers +package rmrmsghandlers import ( + "e2mgr/converters" + "e2mgr/e2pdus" "e2mgr/models" "e2mgr/rNibWriter" "fmt" @@ -34,7 +36,7 @@ func (src X2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Se e2session, ok := e2Sessions[request.TransactionId] - enbId, enb, err := unpackX2SetupResponseAndExtract(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + 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) } @@ -70,7 +72,4 @@ func (src X2SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Se 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/x2enb_configuration_update_handler.go b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go similarity index 80% rename from E2Manager/handlers/x2enb_configuration_update_handler.go rename to E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go index 93383c1..152f00a 100644 --- a/E2Manager/handlers/x2enb_configuration_update_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go @@ -15,14 +15,16 @@ // limitations under the License. // -package handlers +package rmrmsghandlers -// #cgo CFLAGS: -I../asn1codec/inc/ -I../asn1codec/e2ap_engine/ -// #cgo LDFLAGS: -L ../asn1codec/lib/ -L../asn1codec/e2ap_engine/ -le2ap_codec -lasncodec +// #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/converters" + "e2mgr/e2pdus" "e2mgr/logger" "e2mgr/models" "e2mgr/rmrCgo" @@ -36,12 +38,12 @@ func (src X2EnbConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessi messageChannel chan<- *models.NotificationResponse) { var payloadSize C.ulong - payloadSize = MaxAsn1PackedBufferSize - packedBuffer := [MaxAsn1PackedBufferSize]C.uchar{} - errorBuffer := [MaxAsn1PackedBufferSize]C.char{} - refinedMessage, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) + 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 ) if err != nil { - status := C.build_pack_x2enb_configuration_update_failure( &payloadSize, &packedBuffer[0], MaxAsn1PackedBufferSize, &errorBuffer[0]) + 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) @@ -53,9 +55,9 @@ func (src X2EnbConfigurationUpdateHandler) Handle(logger *logger.Logger, e2Sessi logger.Errorf("#x2enb_configuration_update_handler.Handle - unpack failed. Error: %v", err) } else { 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) + 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], 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) diff --git a/E2Manager/handlers/x2enb_configuration_update_handler_test.go b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler_test.go similarity index 99% rename from E2Manager/handlers/x2enb_configuration_update_handler_test.go rename to E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler_test.go index 20aa3d4..e0e22dd 100644 --- a/E2Manager/handlers/x2enb_configuration_update_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler_test.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -package handlers +package rmrmsghandlers import ( "e2mgr/logger" diff --git a/E2Manager/handlers/setup_response_notification_handler.go b/E2Manager/handlers/setup_response_notification_handler.go deleted file mode 100644 index 121c65b..0000000 --- a/E2Manager/handlers/setup_response_notification_handler.go +++ /dev/null @@ -1,51 +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 handlers - -import "C" -import ( - "e2mgr/models" - "fmt" - "time" - - "e2mgr/logger" - "e2mgr/sessions" -) - -type SetupResponseNotificationHandler struct{} - -func (src SetupResponseNotificationHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, - request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) { - - refinedResponse, err := unpackX2apPduAndRefine(logger, MaxAsn1CodecAllocationBufferSize /*allocation buffer*/, request.Len, request.Payload, MaxAsn1CodecMessageBufferSize /*message buffer*/) - if err != nil { - logger.Errorf("#setup_response_notification_handler.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/setup_response_notification_handler_test.go b/E2Manager/handlers/setup_response_notification_handler_test.go deleted file mode 100644 index f57df71..0000000 --- a/E2Manager/handlers/setup_response_notification_handler_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 handlers - -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/managers/endc_setup_failure_response_manager.go b/E2Manager/managers/endc_setup_failure_response_manager.go new file mode 100644 index 0000000..5aef343 --- /dev/null +++ b/E2Manager/managers/endc_setup_failure_response_manager.go @@ -0,0 +1 @@ +package managers diff --git a/E2Manager/managers/endc_setup_response_manager.go b/E2Manager/managers/endc_setup_response_manager.go new file mode 100644 index 0000000..5aef343 --- /dev/null +++ b/E2Manager/managers/endc_setup_response_manager.go @@ -0,0 +1 @@ +package managers diff --git a/E2Manager/managers/i_setup_response_manager.go b/E2Manager/managers/i_setup_response_manager.go new file mode 100644 index 0000000..665c584 --- /dev/null +++ b/E2Manager/managers/i_setup_response_manager.go @@ -0,0 +1,10 @@ +package managers + +import ( + "e2mgr/logger" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" +) + +type ISetupResponseManager interface { + SetNodeb(logger *logger.Logger, nbIdentity *entities.NbIdentity, nodebInfo *entities.NodebInfo, payload []byte) error +} diff --git a/E2Manager/managers/x2_setup_failure_response_manager.go b/E2Manager/managers/x2_setup_failure_response_manager.go new file mode 100644 index 0000000..77098eb --- /dev/null +++ b/E2Manager/managers/x2_setup_failure_response_manager.go @@ -0,0 +1,30 @@ +package managers + +import ( + "e2mgr/converters" + "e2mgr/e2pdus" + "e2mgr/logger" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" +) + +type X2SetupFailureResponseManager struct{} + +func NewX2SetupFailureResponseManager() *X2SetupFailureResponseManager { + return &X2SetupFailureResponseManager{} +} + +func (m *X2SetupFailureResponseManager) SetNodeb(logger *logger.Logger, nbIdentity *entities.NbIdentity, nodebInfo *entities.NodebInfo, payload []byte) error { + + 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) + return err + } + + 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 new file mode 100644 index 0000000..9de2aee --- /dev/null +++ b/E2Manager/managers/x2_setup_response_manager.go @@ -0,0 +1,34 @@ +package managers + +import ( + "e2mgr/converters" + "e2mgr/e2pdus" + "e2mgr/logger" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" +) + +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 +} + diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go index e461bfc..99585fc 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go @@ -20,7 +20,7 @@ package httpmsghandlerprovider import ( "e2mgr/configuration" "e2mgr/e2managererrors" - "e2mgr/handlers" + "e2mgr/handlers/httpmsghandlers" "e2mgr/logger" "e2mgr/rNibWriter" "e2mgr/services" @@ -35,12 +35,11 @@ const ( ) type IncomingRequestHandlerProvider struct { - requestMap map[IncomingRequest]handlers.RequestHandler + requestMap map[IncomingRequest]httpmsghandlers.RequestHandler logger *logger.Logger } -func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrService *services.RmrService, config *configuration.Configuration, rNibWriterProvider func() rNibWriter.RNibWriter, - rNibReaderProvider func() reader.RNibReader) *IncomingRequestHandlerProvider { +func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrService *services.RmrService, config *configuration.Configuration, rNibWriterProvider func() rNibWriter.RNibWriter, rNibReaderProvider func() reader.RNibReader) *IncomingRequestHandlerProvider { return &IncomingRequestHandlerProvider{ requestMap: initRequestHandlerMap(rmrService, config, rNibWriterProvider, rNibReaderProvider), @@ -49,15 +48,15 @@ func NewIncomingRequestHandlerProvider(logger *logger.Logger, rmrService *servic } func initRequestHandlerMap(rmrService *services.RmrService, config *configuration.Configuration, rNibWriterProvider func() rNibWriter.RNibWriter, - rNibReaderProvider func() reader.RNibReader) map[IncomingRequest]handlers.RequestHandler { + rNibReaderProvider func() reader.RNibReader) map[IncomingRequest]httpmsghandlers.RequestHandler { - return map[IncomingRequest]handlers.RequestHandler{ - ShutdownRequest: handlers.NewDeleteAllRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer - ResetRequest: handlers.NewX2ResetRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer + return map[IncomingRequest]httpmsghandlers.RequestHandler{ + ShutdownRequest: httpmsghandlers.NewDeleteAllRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer + ResetRequest: httpmsghandlers.NewX2ResetRequestHandler(rmrService, config, rNibWriterProvider, rNibReaderProvider), //TODO change to pointer } } -func (provider IncomingRequestHandlerProvider) GetHandler(requestType IncomingRequest) (handlers.RequestHandler, error) { +func (provider IncomingRequestHandlerProvider) GetHandler(requestType IncomingRequest) (httpmsghandlers.RequestHandler, error) { handler, ok := provider.requestMap[requestType] if !ok { diff --git a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go index 718704b..a6c4e49 100644 --- a/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go +++ b/E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go @@ -20,7 +20,7 @@ package httpmsghandlerprovider import ( "e2mgr/configuration" "e2mgr/e2managererrors" - "e2mgr/handlers" + "e2mgr/handlers/httpmsghandlers" "e2mgr/logger" "e2mgr/mocks" "e2mgr/models" @@ -82,7 +82,7 @@ func TestShutdownRequestHandler(t *testing.T) { assert.NotNil(t, provider) assert.Nil(t, err) - _, ok := handler.(*handlers.DeleteAllRequestHandler) + _, ok := handler.(*httpmsghandlers.DeleteAllRequestHandler) assert.True(t, ok) /*if !ok { diff --git a/E2Manager/providers/httpmsghandlerprovider/request_handler_provider.go b/E2Manager/providers/httpmsghandlerprovider/request_handler_provider.go index ce9f397..6fa2807 100644 --- a/E2Manager/providers/httpmsghandlerprovider/request_handler_provider.go +++ b/E2Manager/providers/httpmsghandlerprovider/request_handler_provider.go @@ -18,14 +18,14 @@ package httpmsghandlerprovider import ( - "e2mgr/handlers" + "e2mgr/handlers/httpmsghandlers" "e2mgr/logger" "e2mgr/rNibWriter" "errors" "fmt" ) -var requestMap map[string]handlers.Handler +var requestMap map[string]httpmsghandlers.Handler type RequestHandlerProvider struct{} @@ -34,14 +34,14 @@ func NewRequestHandlerProvider(rnibWriterProvider func() rNibWriter.RNibWriter) return &RequestHandlerProvider{} } -func initRequestMap(rnibWriterProvider func() rNibWriter.RNibWriter) map[string]handlers.Handler { - return map[string]handlers.Handler{ - "x2-setup": handlers.NewSetupRequestHandler(rnibWriterProvider), - "endc-setup": handlers.NewEndcSetupRequestHandler(rnibWriterProvider), +func initRequestMap(rnibWriterProvider func() rNibWriter.RNibWriter) map[string]httpmsghandlers.Handler { + return map[string]httpmsghandlers.Handler{ + "x2-setup": httpmsghandlers.NewSetupRequestHandler(rnibWriterProvider), + "endc-setup": httpmsghandlers.NewEndcSetupRequestHandler(rnibWriterProvider), } } -func (provider RequestHandlerProvider) GetHandler(logger *logger.Logger, requestType string) (handlers.Handler, error) { +func (provider RequestHandlerProvider) GetHandler(logger *logger.Logger, requestType string) (httpmsghandlers.Handler, error) { handler, ok := requestMap[requestType] if !ok { diff --git a/E2Manager/providers/httpmsghandlerprovider/request_handler_provider_test.go b/E2Manager/providers/httpmsghandlerprovider/request_handler_provider_test.go index f610126..8c5f133 100644 --- a/E2Manager/providers/httpmsghandlerprovider/request_handler_provider_test.go +++ b/E2Manager/providers/httpmsghandlerprovider/request_handler_provider_test.go @@ -18,7 +18,7 @@ package httpmsghandlerprovider import ( - "e2mgr/handlers" + "e2mgr/handlers/httpmsghandlers" "e2mgr/logger" "e2mgr/mocks" "e2mgr/rNibWriter" @@ -66,7 +66,7 @@ func TestGetX2SetupRequestHandler(t *testing.T) { t.Errorf("failed to get x2 setup handler") } - _, ok := handler.(*handlers.SetupRequestHandler) + _, ok := handler.(*httpmsghandlers.SetupRequestHandler) if !ok { t.Errorf("failed to get x2 setup handler") @@ -92,7 +92,7 @@ func TestGetEndcSetupRequestHandler(t *testing.T) { t.Errorf("failed to get endc setup handler") } - _, ok := handler.(*handlers.EndcSetupRequestHandler) + _, ok := handler.(*httpmsghandlers.EndcSetupRequestHandler) if !ok { t.Errorf("failed to get endc setup handler") diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go index 159c44d..4cd55c7 100644 --- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go +++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go @@ -18,7 +18,7 @@ package rmrmsghandlerprovider import ( - "e2mgr/handlers" + "e2mgr/handlers/rmrmsghandlers" "e2mgr/managers" "e2mgr/rNibWriter" "e2mgr/rmrCgo" @@ -27,7 +27,7 @@ import ( ) type NotificationHandlerProvider struct { - notificationHandlers map[int]handlers.NotificationHandler + notificationHandlers map[int]rmrmsghandlers.NotificationHandler } func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranReconnectionManager *managers.RanReconnectionManager) *NotificationHandlerProvider { @@ -36,24 +36,24 @@ func NewNotificationHandlerProvider(rnibReaderProvider func() reader.RNibReader, } } -func initNotificationHandlersMap(rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, ranReconnectionManager *managers.RanReconnectionManager) map[int]handlers.NotificationHandler { - return map[int]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: handlers.X2SetupResponseNotificationHandler{}, - rmrCgo.RIC_X2_SETUP_FAILURE: handlers.X2SetupFailureResponseNotificationHandler{}, - rmrCgo.RIC_ENDC_X2_SETUP_RESP: handlers.EndcX2SetupResponseNotificationHandler{}, - rmrCgo.RIC_ENDC_X2_SETUP_FAILURE: handlers.EndcX2SetupFailureResponseNotificationHandler{}, - rmrCgo.RIC_SCTP_CONNECTION_FAILURE: handlers.NewRanLostConnectionHandler(ranReconnectionManager), - rmrCgo.RIC_ENB_LOAD_INFORMATION: handlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider), - 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), - rmrCgo.RIC_E2_TERM_INIT: handlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider ), + 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_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_X2_RESET_RESP: rmrmsghandlers.NewX2ResetResponseHandler(rnibReaderProvider), + rmrCgo.RIC_X2_RESET: rmrmsghandlers.NewX2ResetRequestNotificationHandler(rnibReaderProvider), + rmrCgo.RIC_E2_TERM_INIT: rmrmsghandlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider ), } } -func (provider NotificationHandlerProvider) GetNotificationHandler(messageType int) (handlers.NotificationHandler, error) { +func (provider NotificationHandlerProvider) GetNotificationHandler(messageType int) (rmrmsghandlers.NotificationHandler, error) { handler, ok := provider.notificationHandlers[messageType] if !ok { diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go index 66f2e36..1792e9b 100644 --- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go +++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go @@ -19,6 +19,7 @@ package rmrmsghandlerprovider import ( "e2mgr/configuration" + "e2mgr/handlers/rmrmsghandlers" "e2mgr/logger" "e2mgr/managers" "e2mgr/mocks" @@ -32,7 +33,6 @@ import ( "strings" "testing" - "e2mgr/handlers" "e2mgr/rmrCgo" ) @@ -58,17 +58,17 @@ func TestGetNotificationHandlerSuccess(t *testing.T) { var testCases = []struct { msgType int - handler handlers.NotificationHandler + handler rmrmsghandlers.NotificationHandler }{ - {rmrCgo.RIC_X2_SETUP_RESP /*successful x2 setup response*/, handlers.X2SetupResponseNotificationHandler{}}, - {rmrCgo.RIC_X2_SETUP_FAILURE /*unsuccessful x2 setup response*/, handlers.X2SetupFailureResponseNotificationHandler{}}, - {rmrCgo.RIC_ENDC_X2_SETUP_RESP /*successful en-dc x2 setup response*/, handlers.EndcX2SetupResponseNotificationHandler{}}, - {rmrCgo.RIC_ENDC_X2_SETUP_FAILURE /*unsuccessful en-dc x2 setup response*/, handlers.EndcX2SetupFailureResponseNotificationHandler{}}, - {rmrCgo.RIC_SCTP_CONNECTION_FAILURE /*sctp errors*/, handlers.NewRanLostConnectionHandler(ranReconnectionManager)}, - {rmrCgo.RIC_ENB_LOAD_INFORMATION, handlers.NewEnbLoadInformationNotificationHandler(rnibWriterProvider)}, - {rmrCgo.RIC_ENB_CONF_UPDATE, handlers.X2EnbConfigurationUpdateHandler{}}, - {rmrCgo.RIC_ENDC_CONF_UPDATE, handlers.EndcConfigurationUpdateHandler{}}, - {rmrCgo.RIC_E2_TERM_INIT, handlers.NewE2TermInitNotificationHandler(ranReconnectionManager, rnibReaderProvider)}, + {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_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)}, } for _, tc := range testCases { -- 2.16.6