[RICPLT-2157] Restructure handlers and converters....... 99/899/1
authoris005q <idan.shalom@intl.att.com>
Thu, 5 Sep 2019 16:28:18 +0000 (19:28 +0300)
committeris005q <idan.shalom@intl.att.com>
Thu, 5 Sep 2019 16:28:25 +0000 (19:28 +0300)
Change-Id: I5cd677438b2add27ac87b638762069e1a79af69f
Signed-off-by: is005q <idan.shalom@intl.att.com>
61 files changed:
E2Manager/container-tag.yaml
E2Manager/controllers/controller.go
E2Manager/controllers/nodeb_controller.go
E2Manager/converters/enb_load_information_to_protobuf.go [moved from E2Manager/handlers/enb_load_information_to_protobuf.go with 99% similarity]
E2Manager/converters/enb_load_information_to_protobuf_test.go [moved from E2Manager/handlers/enb_load_information_to_protobuf_test.go with 99% similarity]
E2Manager/converters/endc_x2setupFailureResponseToProtobuf.go [moved from E2Manager/handlers/endc_x2setupFailureResponseToProtobuf.go with 93% similarity]
E2Manager/converters/endc_x2setupFailureResponseToProtobuf_test.go [moved from E2Manager/handlers/endc_x2setupFailureResponseToProtobuf_test.go with 63% similarity]
E2Manager/converters/endc_x2setupResponseToProtobuf.go [moved from E2Manager/handlers/endc_x2setupResponseToProtobuf.go with 99% similarity]
E2Manager/converters/endc_x2setupResponseToProtobuf_test.go [moved from E2Manager/handlers/endc_x2setupResponseToProtobuf_test.go with 99% similarity]
E2Manager/converters/x2apPdu_asn1_unpacker.go [moved from E2Manager/handlers/x2apPdu_asn1_unpacker.go with 88% similarity]
E2Manager/converters/x2apPdu_asn1_unpacker_test.go [moved from E2Manager/handlers/x2apPdu_asn1_unpacker_test.go with 87% similarity]
E2Manager/converters/x2setupFailureResponseToProtobuf.go [moved from E2Manager/handlers/x2setupFailureResponseToProtobuf.go with 97% similarity]
E2Manager/converters/x2setupFailureResponseToProtobuf_test.go [moved from E2Manager/handlers/x2setupFailureResponseToProtobuf_test.go with 97% similarity]
E2Manager/converters/x2setupResponseToProtobuf.go [moved from E2Manager/handlers/x2setupResponseToProtobuf.go with 99% similarity]
E2Manager/converters/x2setupResponseToProtobuf_test.go [moved from E2Manager/handlers/x2setupResponseToProtobuf_test.go with 99% similarity]
E2Manager/e2pdus/x2_reset_known_causes.go
E2Manager/handlers/httpmsghandlers/delete_all_request_handler.go [moved from E2Manager/handlers/delete_all_request_handler.go with 97% similarity]
E2Manager/handlers/httpmsghandlers/delete_all_request_handler_test.go [moved from E2Manager/handlers/delete_all_request_handler_test.go with 99% similarity]
E2Manager/handlers/httpmsghandlers/endc_setup_request_handler.go [moved from E2Manager/handlers/endc_setup_request_handler.go with 99% similarity]
E2Manager/handlers/httpmsghandlers/endc_setup_request_handler_test.go [moved from E2Manager/handlers/endc_setup_request_handler_test.go with 98% similarity]
E2Manager/handlers/httpmsghandlers/handler.go [moved from E2Manager/handlers/handler.go with 97% similarity]
E2Manager/handlers/httpmsghandlers/request_handler.go [moved from E2Manager/handlers/request_handler.go with 96% similarity]
E2Manager/handlers/httpmsghandlers/setup_request_handler.go [moved from E2Manager/handlers/setup_request_handler.go with 99% similarity]
E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go [moved from E2Manager/handlers/setup_request_handler_test.go with 99% similarity]
E2Manager/handlers/httpmsghandlers/x2_reset_request_handler.go [moved from E2Manager/handlers/x2_reset_request_handler.go with 99% similarity]
E2Manager/handlers/httpmsghandlers/x2_reset_request_handler_test.go [moved from E2Manager/handlers/x2_reset_request_handler_test.go with 94% similarity]
E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler.go [moved from E2Manager/handlers/e2_term_init_notification_handler.go with 90% similarity]
E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go [moved from E2Manager/handlers/e2_term_init_notification_handler_test.go with 76% similarity]
E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler.go [moved from E2Manager/handlers/enb_load_information_notification_handler.go with 85% similarity]
E2Manager/handlers/rmrmsghandlers/enb_load_information_notification_handler_test.go [moved from E2Manager/handlers/enb_load_information_notification_handler_test.go with 99% similarity]
E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler.go [moved from E2Manager/handlers/endc_configuration_update_handler.go with 79% similarity]
E2Manager/handlers/rmrmsghandlers/endc_configuration_update_handler_test.go [moved from E2Manager/handlers/endc_configuration_update_handler_test.go with 99% similarity]
E2Manager/handlers/rmrmsghandlers/endc_setup_response_notification_handler.go [moved from E2Manager/handlers/endc_setup_response_notification_handler.go with 87% similarity]
E2Manager/handlers/rmrmsghandlers/endc_x2Setup_failure_response_notification_handler.go [moved from E2Manager/handlers/endc_x2Setup_failure_response_notification_handler.go with 91% similarity]
E2Manager/handlers/rmrmsghandlers/notification_handler.go [moved from E2Manager/handlers/notification_handler.go with 97% similarity]
E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler.go [moved from E2Manager/handlers/ran_lost_connection_handler.go with 98% similarity]
E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go [moved from E2Manager/handlers/ran_lost_connection_handler_test.go with 98% similarity]
E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler.go [new file with mode: 0644]
E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak.go [new file with mode: 0644]
E2Manager/handlers/rmrmsghandlers/setup_response_notification_handler_bak_test.go [new file with mode: 0644]
E2Manager/handlers/rmrmsghandlers/x2Setup_failure_response_notification_handler.go [moved from E2Manager/handlers/x2Setup_failure_response_notification_handler.go with 92% similarity]
E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler.go [moved from E2Manager/handlers/x2_reset_request_notification_handler.go with 71% similarity]
E2Manager/handlers/rmrmsghandlers/x2_reset_request_notification_handler_test.go [moved from E2Manager/handlers/x2_reset_request_notification_handler_test.go with 99% similarity]
E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler.go [moved from E2Manager/handlers/x2_reset_response_handler.go with 81% similarity]
E2Manager/handlers/rmrmsghandlers/x2_reset_response_handler_test.go [moved from E2Manager/handlers/x2_reset_response_handler_test.go with 99% similarity]
E2Manager/handlers/rmrmsghandlers/x2apSetup_response_notification_handler.go [moved from E2Manager/handlers/x2apSetup_response_notification_handler.go with 92% similarity]
E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler.go [moved from E2Manager/handlers/x2enb_configuration_update_handler.go with 80% similarity]
E2Manager/handlers/rmrmsghandlers/x2enb_configuration_update_handler_test.go [moved from E2Manager/handlers/x2enb_configuration_update_handler_test.go with 99% similarity]
E2Manager/handlers/setup_response_notification_handler.go [deleted file]
E2Manager/handlers/setup_response_notification_handler_test.go [deleted file]
E2Manager/managers/endc_setup_failure_response_manager.go [new file with mode: 0644]
E2Manager/managers/endc_setup_response_manager.go [new file with mode: 0644]
E2Manager/managers/i_setup_response_manager.go [new file with mode: 0644]
E2Manager/managers/x2_setup_failure_response_manager.go [new file with mode: 0644]
E2Manager/managers/x2_setup_response_manager.go [new file with mode: 0644]
E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider.go
E2Manager/providers/httpmsghandlerprovider/incoming_request_handler_provider_test.go
E2Manager/providers/httpmsghandlerprovider/request_handler_provider.go
E2Manager/providers/httpmsghandlerprovider/request_handler_provider_test.go
E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go
E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go

index 4add8c7..bad22ad 100644 (file)
@@ -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
index 7d549b2..6c86816 100644 (file)
@@ -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
index 5a82f10..802537d 100644 (file)
@@ -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{
@@ -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)
 
@@ -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)
@@ -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 <asn1codec_utils.h>
 // #include <x2setup_response_wrapper.h>
@@ -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
        }
  *   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:<procedure_code:33 triggering_message:UNSUCCESSFUL_OUTCOME procedure_criticality:NOTIFY information_element_criticality_diagnostics:<ie_criticality:REJECT ie_id:128 type_of_error:MISSING > > ",
+                       response:   "CONNECTED_SETUP_FAILED network_layer_cause:HANDOVER_DESIRABLE_FOR_RADIO_REASONS time_to_wait:V1S criticality_diagnostics:<procedure_code:33 triggering_message:UNSUCCESSFUL_OUTCOME procedure_criticality:NOTIFY information_element_criticality_diagnostics:<ie_criticality:REJECT ie_id:128 type_of_error:MISSING > > ",
                        /*
-                       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) {
                })
        }
 }
-
@@ -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
        }
  *   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 {
similarity index 88%
rename from E2Manager/handlers/x2apPdu_asn1_unpacker.go
rename to E2Manager/converters/x2apPdu_asn1_unpacker.go
index 3a89e5c..9506b9f 100644 (file)
@@ -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
 }
 
 
  *   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) {
 
        }
 }
-
-
@@ -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
        }
  *   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 {
@@ -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 <x2setup_response_wrapper.h>
 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
        }
  *   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 {
index df84a4b..9140f3d 100644 (file)
@@ -31,6 +31,7 @@ import (
 const (
        MaxAsn1PackedBufferSize       = 4096
        MaxAsn1CodecMessageBufferSize = 4096
+       MaxAsn1CodecAllocationBufferSize = 4096 // TODO: remove later
 )
 
 // Used as default by the x2_reset_request
@@ -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,
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package httpmsghandlers
 
 import (
        "e2mgr/e2pdus"
similarity index 97%
rename from E2Manager/handlers/handler.go
rename to E2Manager/handlers/httpmsghandlers/handler.go
index 2a53c00..474f20a 100644 (file)
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package httpmsghandlers
 
 import (
        "e2mgr/logger"
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package httpmsghandlers
 
 import (
        "e2mgr/logger"
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package httpmsghandlers
 
 import (
        "e2mgr/e2pdus"
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package httpmsghandlers
 
 import (
        "e2mgr/configuration"
@@ -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 }
@@ -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 {
@@ -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
+}
@@ -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
        }
 
 // 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 <asn1codec_utils.h>
 // #include <configuration_update_wrapper.h>
 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)
@@ -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"
 // 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)
        }
 
-
 }
 // 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)
        }
@@ -15,7 +15,7 @@
 // limitations under the License.
 //
 
-package handlers
+package rmrmsghandlers
 
 import (
        "e2mgr/logger"
@@ -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 (file)
index 0000000..86843ef
--- /dev/null
@@ -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 (file)
index 0000000..2864aa1
--- /dev/null
@@ -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 (file)
index 0000000..0203498
--- /dev/null
@@ -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, &notificationRequest, 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, &notificationRequest, messageChannel)})
+//}
\ No newline at end of file
 // 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)
        }
 // 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 <asn1codec_utils.h>
+// #include <x2reset_response_wrapper.h>
+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
+}
@@ -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, &notificationRequest, nil)
-}
+}
\ No newline at end of file
 // 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 <asn1codec_utils.h>
 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)
                }
        }
 }
 // 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)
        }
-
-
-
 }
 // 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 <asn1codec_utils.h>
 // #include <configuration_update_wrapper.h>
 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)
@@ -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 (file)
index 121c65b..0000000
+++ /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 (file)
index f57df71..0000000
+++ /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, &notificationRequest, 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, &notificationRequest, 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 (file)
index 0000000..5aef343
--- /dev/null
@@ -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 (file)
index 0000000..5aef343
--- /dev/null
@@ -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 (file)
index 0000000..665c584
--- /dev/null
@@ -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 (file)
index 0000000..77098eb
--- /dev/null
@@ -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 (file)
index 0000000..9de2aee
--- /dev/null
@@ -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
+}
+
index e461bfc..99585fc 100644 (file)
@@ -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 {
index 718704b..a6c4e49 100644 (file)
@@ -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 {
index ce9f397..6fa2807 100644 (file)
 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 {
index f610126..8c5f133 100644 (file)
@@ -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")
index 159c44d..4cd55c7 100644 (file)
@@ -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 {
index 66f2e36..1792e9b 100644 (file)
@@ -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 {