[RICPLT-2537] Resource Status Initiate huge commit 63/1563/1
authoris005q <idan.shalom@intl.att.com>
Wed, 13 Nov 2019 12:39:28 +0000 (14:39 +0200)
committeris005q <idan.shalom@intl.att.com>
Wed, 13 Nov 2019 12:39:51 +0000 (14:39 +0200)
Signed-off-by: is005q <idan.shalom@intl.att.com>
Change-Id: I6660c7adb1a2e557bfcc8be025940a63dce6b967

71 files changed:
.gitignore
RSM/app/main.go
RSM/configuration/configuration_test.go
RSM/controllers/controller.go
RSM/controllers/controller_test.go
RSM/controllers/root_controller_test.go
RSM/converters/resource_status_response_unpacker.go
RSM/converters/resource_status_response_unpacker_test.go
RSM/converters/x2apPdu_asn1_unpacker.go
RSM/e2pdus/resource_status_request_test.go
RSM/enums/constants.go [new file with mode: 0644]
RSM/enums/message_direction.go
RSM/enums/registration_request.go
RSM/enums/reporting_periodicity.go
RSM/enums/reporting_periodicity_csir.go
RSM/enums/reporting_periodicity_rsr_pmr.go
RSM/enums/rsm_action.go [new file with mode: 0644]
RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler.go
RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go
RSM/handlers/rmrmsghandlers/resource_status_response_handler.go
RSM/handlers/rmrmsghandlers/resource_status_response_handler_test.go
RSM/handlers/rmrmsghandlers/rmr_message_handler.go
RSM/httpserver/http_server_test.go
RSM/logger/logger.go
RSM/logger/logger_test.go
RSM/managers/resource_status_initiate_manager.go [deleted file]
RSM/managers/resource_status_initiate_manager_test.go [deleted file]
RSM/managers/rmrmanagers/rmr_message_manager.go
RSM/managers/rmrmanagers/rmr_message_manager_test.go
RSM/mocks/controller_mock.go
RSM/mocks/resource_status_failure_converter_mock.go
RSM/mocks/resource_status_initiate_manager_mock.go
RSM/mocks/resource_status_response_converter_mock.go
RSM/mocks/resource_status_service_mock.go [new file with mode: 0644]
RSM/mocks/rmr_messenger_mock.go
RSM/mocks/root_controller_mock.go
RSM/mocks/rsm_reader_mock.go [new file with mode: 0644]
RSM/mocks/rsm_writer_mock.go [new file with mode: 0644]
RSM/mocks/sdl_instance_mock.go
RSM/models/request_interface.go
RSM/models/resource_status_payload.go
RSM/models/resource_status_response.go
RSM/models/response_interface.go
RSM/models/rmr_message.go
RSM/models/rmr_request.go
RSM/models/rsm_general_configuration.go [new file with mode: 0644]
RSM/models/rsm_ran_info.go [new file with mode: 0644]
RSM/providers/httpmsghandlerprovider/request_handler_provider.go
RSM/providers/httpmsghandlerprovider/request_handler_provider_test.go
RSM/providers/rmrmsghandlerprovider/message_handler_provider.go
RSM/providers/rmrmsghandlerprovider/message_handler_provider_test.go
RSM/rmrcgo/rmr_c_go_api_test.go
RSM/rmrcgo/rmr_c_go_utils.go
RSM/rsmdb/rsm_reader.go [new file with mode: 0644]
RSM/rsmdb/rsm_writer.go [new file with mode: 0644]
RSM/rsmerrors/base_error.go
RSM/rsmerrors/header_validation_error.go
RSM/rsmerrors/internal_error.go
RSM/rsmerrors/invalid_json_error.go
RSM/rsmerrors/rnib_db_error.go
RSM/rsmerrors/wrong_state_error.go
RSM/services/resource_status_service.go [new file with mode: 0644]
RSM/services/resource_status_service_test.go [new file with mode: 0644]
RSM/services/rmrreceiver/rmr_receiver.go
RSM/services/rmrreceiver/rmr_receiver_test.go
RSM/services/rmrsender/rmr_sender.go
RSM/services/rmrsender/rmr_sender_test.go
RSM/services/rnib_data_service.go
RSM/services/rnib_data_service_test.go
RSM/tests/payloadProvider.go
RSM/tests/testhelper/test_utils.go

index 4b046db..9a23fb0 100644 (file)
@@ -2,6 +2,8 @@
 .vscode/launch.json
 *.o
 *.a
+RSM/RSM
+coverage.txt
 RSM/asn1codec/e2ap_engine/converter-example
 RSM/asn1codec/tests/
 RSM/cp.out
index 0cb9b75..854470e 100644 (file)
@@ -28,9 +28,9 @@ import (
        "rsm/e2pdus"
        "rsm/httpserver"
        "rsm/logger"
-       "rsm/managers"
        "rsm/managers/rmrmanagers"
        "rsm/rmrcgo"
+       "rsm/rsmdb"
        "rsm/services"
        "rsm/services/rmrreceiver"
        "rsm/services/rmrsender"
@@ -50,17 +50,21 @@ func main() {
                os.Exit(1)
        }
        db := sdlgo.NewDatabase()
-       sdl := sdlgo.NewSdlInstance("e2Manager", db)
-       defer sdl.Close()
+       e2mSdl := sdlgo.NewSdlInstance("e2Manager", db)
+       rsmSdl := sdlgo.NewSdlInstance("rsm", db)
+
+       defer e2mSdl.Close()
+       defer rsmSdl.Close()
+
        logger.Infof("#app.main - Configuration %s", config)
-       rnibDataService := services.NewRnibDataService(logger, config, reader.GetRNibReader(sdl))
+       rnibDataService := services.NewRnibDataService(logger, config, reader.GetRNibReader(e2mSdl), rsmdb.GetRsmReader(rsmSdl), rsmdb.GetRsmWriter(rsmSdl))
        var msgImpl *rmrcgo.Context
        rmrMessenger := msgImpl.Init(config.Rmr.ReadyIntervalSec, "tcp:"+strconv.Itoa(config.Rmr.Port), config.Rmr.MaxMsgSize, 0, logger)
        rmrSender := rmrsender.NewRmrSender(logger, rmrMessenger)
 
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
-       unpacker := converters.NewX2apPduUnpacker(logger,e2pdus.MaxAsn1CodecMessageBufferSize)
-       var rmrManager = rmrmanagers.NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager,converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
+       unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
+       var rmrManager = rmrmanagers.NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
 
        rmrReceiver := rmrreceiver.NewRmrReceiver(logger, rmrMessenger, rmrManager)
        defer rmrMessenger.Close()
index 3bc2e13..7fed95a 100644 (file)
@@ -72,10 +72,10 @@ func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
 
 func TestRmrConfigNotFoundFailure(t *testing.T) {
        yamlMap := map[string]interface{}{
-               "logging":         map[string]interface{}{"logLevel": "info"},
-               "http":            map[string]interface{}{"port": 631},
+               "logging":              map[string]interface{}{"logLevel": "info"},
+               "http":                 map[string]interface{}{"port": 631},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityCsiMs": 5},
-               "rnib":            map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
        defer cleanUp()
@@ -86,10 +86,10 @@ func TestRmrConfigNotFoundFailure(t *testing.T) {
 
 func TestLoggingConfigNotFoundFailure(t *testing.T) {
        yamlMap := map[string]interface{}{
-               "rmr":             map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "http":            map[string]interface{}{"port": 631},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "http":                 map[string]interface{}{"port": 631},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityCsiMs": 5},
-               "rnib":            map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
        defer cleanUp()
@@ -100,10 +100,10 @@ func TestLoggingConfigNotFoundFailure(t *testing.T) {
 
 func TestHttpConfigNotFoundFailure(t *testing.T) {
        yamlMap := map[string]interface{}{
-               "rmr":             map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "logging":         map[string]interface{}{"logLevel": "info"},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "logging":              map[string]interface{}{"logLevel": "info"},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityCsiMs": 5},
-               "rnib":            map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
        defer cleanUp()
@@ -114,9 +114,9 @@ func TestHttpConfigNotFoundFailure(t *testing.T) {
 
 func TestRnibConfigNotFoundFailure(t *testing.T) {
        yamlMap := map[string]interface{}{
-               "rmr":             map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "logging":         map[string]interface{}{"logLevel": "info"},
-               "http":            map[string]interface{}{"port": 631},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "logging":              map[string]interface{}{"logLevel": "info"},
+               "http":                 map[string]interface{}{"port": 631},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityCsiMs": 5},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
@@ -144,10 +144,10 @@ func TestResourceStatusParamsConfigNotFoundFailure(t *testing.T) {
 func TestCharacteristicsConfigInvalidPeriodicityMs(t *testing.T) {
 
        yamlMap := map[string]interface{}{
-               "rmr":     map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "logging": map[string]interface{}{"logLevel": "info"},
-               "http":    map[string]interface{}{"port": 631},
-               "rnib":    map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "logging":              map[string]interface{}{"logLevel": "info"},
+               "http":                 map[string]interface{}{"port": 631},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityMs": 50, "periodicityRsrpMeasurementMs": 480, "periodicityCsiMs": 20},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
@@ -160,10 +160,10 @@ func TestCharacteristicsConfigInvalidPeriodicityMs(t *testing.T) {
 func TestResourceStatusParamsConfigInvalidPeriodicityRsrpMeasurementMs(t *testing.T) {
 
        yamlMap := map[string]interface{}{
-               "rmr":     map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "logging": map[string]interface{}{"logLevel": "info"},
-               "http":    map[string]interface{}{"port": 631},
-               "rnib":    map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "logging":              map[string]interface{}{"logLevel": "info"},
+               "http":                 map[string]interface{}{"port": 631},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityMs": 1000, "periodicityRsrpMeasurementMs": 50, "periodicityCsiMs": 20},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
@@ -176,10 +176,10 @@ func TestResourceStatusParamsConfigInvalidPeriodicityRsrpMeasurementMs(t *testin
 func TestResourceStatusParamsConfigInvalidPeriodicityCsiMs(t *testing.T) {
 
        yamlMap := map[string]interface{}{
-               "rmr":     map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
-               "logging": map[string]interface{}{"logLevel": "info"},
-               "http":    map[string]interface{}{"port": 631},
-               "rnib":    map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
+               "rmr":                  map[string]interface{}{"port": 6942, "maxMsgSize": 4096},
+               "logging":              map[string]interface{}{"logLevel": "info"},
+               "http":                 map[string]interface{}{"port": 631},
+               "rnib":                 map[string]interface{}{"maxRnibConnectionAttempts": 3, "rnibRetryIntervalMs": 10},
                "resourceStatusParams": map[string]interface{}{"enableResourceStatus": true, "periodicityMs": 1000, "periodicityRsrpMeasurementMs": 480, "periodicityCsiMs": 50},
        }
        cleanUp := prepareTempConfigForTest(t, yamlMap)
index f41591d..9194279 100644 (file)
@@ -19,6 +19,7 @@ package controllers
 
 type IController interface {
 }
+
 /*
 import (
        "encoding/json"
@@ -185,4 +186,4 @@ func (c *Controller) prettifyRequest(request *http.Request) string {
        requestPrettyPrint := strings.Replace(string(dump), "\r\n", " ", -1)
        return strings.Replace(requestPrettyPrint, "\n", "", -1)
 }
-*/
\ No newline at end of file
+*/
index 5d0c666..40af65f 100644 (file)
@@ -131,4 +131,4 @@ func TestHandleErrorResponse(t *testing.T) {
        controller.handleErrorResponse(fmt.Errorf("ErrorError"), writer)
        assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
 }
-*/
\ No newline at end of file
+*/
index 5cda9c2..109117f 100644 (file)
@@ -41,10 +41,12 @@ func setupRootControllerTest(t *testing.T) (services.RNibDataService, *mocks.Rni
        if err != nil {
                t.Errorf("#... - failed to parse configuration error: %s", err)
        }
-       readerMock := &mocks.RnibReaderMock{}
+       rnibReaderMock := &mocks.RnibReaderMock{}
+       rsmReaderMock := &mocks.RsmReaderMock{}
+       rsmWriterMock := &mocks.RsmWriterMock{}
 
-       rnibDataService := services.NewRnibDataService(logger, config, readerMock)
-       return rnibDataService, readerMock
+       rnibDataService := services.NewRnibDataService(logger, config, rnibReaderMock, rsmReaderMock, rsmWriterMock)
+       return rnibDataService, rnibReaderMock
 }
 
 func TestNewRequestController(t *testing.T) {
index 9bf3722..ff2c52e 100644 (file)
@@ -33,7 +33,7 @@ const (
        maxFailedMeasObjects = 32
 )
 
-type  IResourceStatusResponseConverter interface {
+type IResourceStatusResponseConverter interface {
        Convert(packedBuf []byte) (*models.ResourceStatusResponse, error)
        UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error)
 }
@@ -42,7 +42,6 @@ type ResourceStatusResponseConverter struct {
        X2apPduUnpacker
 }
 
-
 func NewResourceStatusResponseConverter(unpacker X2apPduUnpacker) ResourceStatusResponseConverter {
        return ResourceStatusResponseConverter{unpacker}
 }
@@ -53,8 +52,6 @@ func buildCellId(cellId C.ECGI_t) string {
        return fmt.Sprintf("%x:%x", plmnId, eutranCellIdentifier)
 }
 
-
-
 func convertMeasurementFailureCauses(measurementFailureCause_List *C.MeasurementFailureCause_List_t, measurementInitiationResult *models.MeasurementInitiationResult) error {
        var MeasurementFailureCauses []*models.MeasurementFailureCause
 
@@ -79,7 +76,6 @@ func convertMeasurementFailureCauses(measurementFailureCause_List *C.Measurement
        return nil
 }
 
-
 func convertMeasurementInitiationResult(measurementInitiationResult_List *C.MeasurementInitiationResult_List_t) ([]*models.MeasurementInitiationResult, error) {
        var measurementInitiationResults []*models.MeasurementInitiationResult
 
index db7b5fe..114afd4 100644 (file)
@@ -248,7 +248,7 @@ func TestResourceStatusResponseConverterPduOfFailure(t *testing.T) {
 
 func TestResourceStatusResponseConverterWrongPdu(t *testing.T) {
        logger, _ := logger.InitLogger(logger.InfoLevel)
-       unpacker := NewX2apPduUnpacker(logger,e2pdus.MaxAsn1CodecMessageBufferSize)
+       unpacker := NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
        rsConverters := NewResourceStatusResponseConverter(unpacker)
 
        wantError := "unexpected PDU - not a resource status response"
index c19e5ae..e95b7ee 100644 (file)
@@ -29,13 +29,12 @@ import (
 )
 
 type X2apPduUnpacker struct {
-       logger *logger.Logger
+       logger               *logger.Logger
        maxMessageBufferSize int
-
 }
 
 func NewX2apPduUnpacker(logger *logger.Logger, maxMessageBufferSize int) X2apPduUnpacker {
-       return X2apPduUnpacker{logger :logger, maxMessageBufferSize: maxMessageBufferSize}
+       return X2apPduUnpacker{loggerlogger, maxMessageBufferSize: maxMessageBufferSize}
 }
 
 func (r X2apPduUnpacker) UnpackX2apPdu(packedBuf []byte) (*C.E2AP_PDU_t, error) {
@@ -60,7 +59,7 @@ func (r X2apPduUnpacker) UnpackX2apPdu(packedBuf []byte) (*C.E2AP_PDU_t, error)
        return pdu, nil
 }
 
-func (r X2apPduUnpacker)UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error) {
+func (r X2apPduUnpacker) UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error) {
        pdu, err := r.UnpackX2apPdu(packedBuf)
        if err != nil {
                return "", err
@@ -72,6 +71,3 @@ func (r X2apPduUnpacker)UnpackX2apPduAsString(packedBuf []byte, maxMessageBuffer
        C.asn1_pdu_printer(pdu, C.size_t(len(buf)), &buf[0])
        return C.GoString(&buf[0]), nil
 }
-
-
-
index 829816a..a9d6226 100644 (file)
@@ -15,6 +15,7 @@
  *   limitations under the License.
  *
  *******************************************************************************/
+
 package e2pdus
 
 import (
@@ -25,8 +26,8 @@ import (
 )
 
 /*
- * Create and pack an x2ap setup request.
- * Verify the packed representation matches the want value.
+* Create and pack an x2ap setup request.
+* Verify the packed representation matches the want value.
  */
 func TestBuildPackedResourceStatusRequest(t *testing.T) {
        var testCases = []struct {
@@ -230,7 +231,7 @@ func TestBuildPackedResourceStatusInvalidPeriodicity(t *testing.T) {
 }
 
 func TestBuildPackedResourceStatusTooManyCells(t *testing.T) {
-       request :=      ResourceStatusRequestData{
+       request := ResourceStatusRequestData{
                CellIdList: []string{
                        "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000",
                        "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000", "0a0b0c:abcd8000", "0b0c0d:acde8000",
diff --git a/RSM/enums/constants.go b/RSM/enums/constants.go
new file mode 100644 (file)
index 0000000..4e5d618
--- /dev/null
@@ -0,0 +1,21 @@
+//
+// 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 enums
+
+const Enb1MeasurementId int64 = 1
index 6697e13..eb4b703 100644 (file)
@@ -1,3 +1,20 @@
+//
+// 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 enums
 
 import (
@@ -31,9 +48,9 @@ func (md MessageDirection) MarshalJSON() ([]byte, error) {
        _, ok := messageDirectionEnumName[int32(md)]
 
        if !ok {
-               return nil,&json.UnsupportedValueError{}
+               return nil, &json.UnsupportedValueError{}
        }
 
-       v:= int32(md)
+       v := int32(md)
        return json.Marshal(v)
 }
index 1afb010..5fcc67a 100644 (file)
@@ -1,3 +1,21 @@
+//
+// 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 enums
 
 type Registration_Request int
index e5d5bbc..282a08e 100644 (file)
@@ -1,3 +1,21 @@
+//
+// 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 enums
 
 import (
@@ -48,4 +66,3 @@ func GetReportingPeriodicityValuesAsKeys() []int {
 
        return keys
 }
-
index b0be47f..9ef36a7 100644 (file)
@@ -1,3 +1,21 @@
+//
+// 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 enums
 
 import "strconv"
index baf840e..6addf13 100644 (file)
@@ -1,3 +1,21 @@
+//
+// 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 enums
 
 import (
@@ -47,4 +65,4 @@ func GetReportingPeriodicityRsrPmrValuesAsKeys() []int {
        }
 
        return keys
-}
\ No newline at end of file
+}
diff --git a/RSM/enums/rsm_action.go b/RSM/enums/rsm_action.go
new file mode 100644 (file)
index 0000000..ab0e1f1
--- /dev/null
@@ -0,0 +1,26 @@
+//
+// 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 enums
+
+type RsmAction string
+
+const (
+       Start RsmAction = "start"
+       Stop  RsmAction = "stop"
+)
index 624837e..68d5298 100644 (file)
@@ -18,73 +18,120 @@ package rmrmsghandlers
 
 import (
        "encoding/json"
+       "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
-       "rsm/configuration"
-       "rsm/e2pdus"
+       "rsm/enums"
        "rsm/logger"
-       "rsm/managers"
        "rsm/models"
+       "rsm/services"
 )
 
 type ResourceStatusInitiateNotificationHandler struct {
-       logger                        *logger.Logger
-       config                        *configuration.Configuration
-       resourceStatusInitiateManager managers.IResourceStatusInitiateManager
-       requestName                   string
+       logger                *logger.Logger
+       rnibDataService       services.RNibDataService
+       resourceStatusService services.IResourceStatusService
+       requestName           string
 }
 
-func NewResourceStatusInitiateNotificationHandler(logger *logger.Logger, config *configuration.Configuration, resourceStatusInitiateManager managers.IResourceStatusInitiateManager, requestName string) ResourceStatusInitiateNotificationHandler {
+func NewResourceStatusInitiateNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, resourceStatusService services.IResourceStatusService, requestName string) ResourceStatusInitiateNotificationHandler {
        return ResourceStatusInitiateNotificationHandler{
-               logger:                        logger,
-               config:                        config,
-               resourceStatusInitiateManager: resourceStatusInitiateManager,
-               requestName:                   requestName,
+               logger:                logger,
+               rnibDataService:       rnibDataService,
+               resourceStatusService: resourceStatusService,
+               requestName:           requestName,
        }
 }
 
+func (h ResourceStatusInitiateNotificationHandler) UnmarshalResourceStatusPayload(inventoryName string, payload []byte) (*models.ResourceStatusPayload, error) {
+       unmarshalledPayload := models.ResourceStatusPayload{}
+       err := json.Unmarshal(payload, &unmarshalledPayload)
+
+       if err != nil {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - RAN name: %s - Error unmarshaling RMR request payload: %v", inventoryName, err)
+               return nil, err
+       }
+
+       if unmarshalledPayload.NodeType == entities.Node_UNKNOWN {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - RAN name: %s - Unknown Node Type", inventoryName)
+               return nil, fmt.Errorf("unknown node type for RAN %s", inventoryName)
+       }
+
+       h.logger.Infof("#ResourceStatusInitiateNotificationHandler.UnmarshalResourceStatusPayload - Unmarshaled payload successfully: %+v", payload)
+       return &unmarshalledPayload, nil
+
+}
+
+func (h ResourceStatusInitiateNotificationHandler) SaveRsmRanInfoStopTrue(inventoryName string) {
+       rsmRanInfo := models.NewRsmRanInfo(inventoryName, 0, 0, enums.Stop, true)
+       err := h.rnibDataService.SaveRsmRanInfo(rsmRanInfo)
+
+       if err != nil {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.SaveRsmRanInfoStopTrue - RAN name: %s - Failed saving RSM data", inventoryName)
+               return
+       }
+
+       h.logger.Infof("#ResourceStatusInitiateNotificationHandler.SaveRsmRanInfoStopTrue - RAN name: %s - Successfully saved RSM data", inventoryName)
+
+}
+
 func (h ResourceStatusInitiateNotificationHandler) Handle(request *models.RmrRequest) {
        inventoryName := request.RanName
-       h.logger.Infof("#ResourceStatusInitiateNotificationHandler - RAN name: %s - Received %s notification", inventoryName, h.requestName)
+       h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Received %s notification", inventoryName, h.requestName)
+
+       payload, err := h.UnmarshalResourceStatusPayload(inventoryName, request.Payload)
+
+       if err != nil {
+               return
+       }
 
-       if !isResourceStatusEnabled(h.config) {
-               h.logger.Warnf("#ResourceStatusInitiateNotificationHandler - RAN name: %s - resource status is disabled", inventoryName)
+       if payload.NodeType != entities.Node_ENB {
+               h.logger.Debugf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s, Node type isn't ENB", inventoryName)
                return
        }
 
-       payload := models.ResourceStatusPayload{}
-       err := json.Unmarshal(request.Payload, &payload)
+       nodeb, err := h.rnibDataService.GetNodeb(inventoryName)
 
        if err != nil {
-               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler - RAN name: %s - Error unmarshaling RMR request payload: %v", inventoryName, err)
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Error fetching RAN from rNib: %v", inventoryName, err)
                return
        }
 
-       h.logger.Infof("#ResourceStatusInitiateNotificationHandler - Unmarshaled payload successfully: %+v", payload)
+       nodebConnectionStatus := nodeb.GetConnectionStatus()
 
-       if payload.NodeType != entities.Node_ENB {
-               h.logger.Debugf("#ResourceStatusInitiateNotificationHandler - RAN name: %s, Node type isn't ENB", inventoryName)
+       if nodebConnectionStatus != entities.ConnectionStatus_CONNECTED {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - RAN's connection status isn't CONNECTED", inventoryName)
+               //h.SaveRsmRanInfoStopTrue(inventoryName)
                return
        }
 
-       resourceStatusInitiateRequestParams := &e2pdus.ResourceStatusRequestData{}
-       populateResourceStatusInitiateRequestParams(resourceStatusInitiateRequestParams, h.config)
+       config, err := h.rnibDataService.GetRsmGeneralConfiguration()
 
-       _ = h.resourceStatusInitiateManager.Execute(inventoryName, resourceStatusInitiateRequestParams)
-}
+       if err != nil {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Failed retrieving RSM general configuration", inventoryName)
+               return
+       }
 
-func isResourceStatusEnabled(configuration *configuration.Configuration) bool {
-       return configuration.ResourceStatusParams.EnableResourceStatus
-}
+       h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Successfully retrieved RSM general configuration", inventoryName)
+
+       if !config.EnableResourceStatus {
+               h.SaveRsmRanInfoStopTrue(inventoryName)
+               return
+       }
 
-func populateResourceStatusInitiateRequestParams(params *e2pdus.ResourceStatusRequestData, config *configuration.Configuration) {
-       params.PartialSuccessAllowed = config.ResourceStatusParams.PartialSuccessAllowed
-       params.PrbPeriodic = config.ResourceStatusParams.PrbPeriodic
-       params.TnlLoadIndPeriodic = config.ResourceStatusParams.TnlLoadIndPeriodic
-       params.HwLoadIndPeriodic = config.ResourceStatusParams.HwLoadIndPeriodic
-       params.AbsStatusPeriodic = config.ResourceStatusParams.AbsStatusPeriodic
-       params.RsrpMeasurementPeriodic = config.ResourceStatusParams.RsrpMeasurementPeriodic
-       params.CsiPeriodic = config.ResourceStatusParams.CsiPeriodic
-       params.PeriodicityMS = config.ResourceStatusParams.PeriodicityMs
-       params.PeriodicityRsrpMeasurementMS = config.ResourceStatusParams.PeriodicityRsrpMeasurementMs
-       params.PeriodicityCsiMS = config.ResourceStatusParams.PeriodicityCsiMs
+       rsmRanInfo := models.NewRsmRanInfo(inventoryName, enums.Enb1MeasurementId, 0, enums.Start, false)
+       err = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo)
+
+       if err != nil {
+               h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Failed saving RSM data", inventoryName)
+               return
+       }
+
+       h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Successfully saved RSM data", inventoryName)
+
+       err = h.resourceStatusService.BuildAndSendInitiateRequest(nodeb, config, rsmRanInfo.Enb1MeasurementId)
+
+       if err != nil {
+               h.SaveRsmRanInfoStopTrue(inventoryName)
+               return
+       }
 }
index 8474306..ddc0474 100644 (file)
 package rmrmsghandlers
 
 import (
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "github.com/pkg/errors"
        "github.com/stretchr/testify/assert"
        "github.com/stretchr/testify/mock"
        "rsm/configuration"
-       "rsm/e2pdus"
+       "rsm/enums"
        "rsm/logger"
        "rsm/mocks"
        "rsm/models"
+       "rsm/services"
        "testing"
        "time"
 )
 
-func initRanConnectedNotificationHandlerTest(t *testing.T, requestName string) (ResourceStatusInitiateNotificationHandler, *mocks.ResourceStatusInitiateManagerMock, *configuration.Configuration) {
+const RanName = "test"
+
+func getRsmGeneralConfiguration(enableResourceStatus bool) *models.RsmGeneralConfiguration {
+       return &models.RsmGeneralConfiguration{
+               EnableResourceStatus:         enableResourceStatus,
+               PartialSuccessAllowed:        true,
+               PrbPeriodic:                  true,
+               TnlLoadIndPeriodic:           true,
+               HwLoadIndPeriodic:            true,
+               AbsStatusPeriodic:            true,
+               RsrpMeasurementPeriodic:      true,
+               CsiPeriodic:                  true,
+               PeriodicityMs:                enums.ReportingPeriodicity_one_thousand_ms,
+               PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
+               PeriodicityCsiMs:             enums.ReportingPeriodicityCSIR_ms20,
+       }
+}
+
+func initRanConnectedNotificationHandlerTest(t *testing.T, requestName string) (ResourceStatusInitiateNotificationHandler, *mocks.RnibReaderMock, *mocks.ResourceStatusServiceMock, *mocks.RsmWriterMock, *mocks.RsmReaderMock) {
        log, err := logger.InitLogger(logger.DebugLevel)
        if err != nil {
                t.Errorf("#... - failed to initialize logger, error: %s", err)
        }
+
        config, err := configuration.ParseConfiguration()
        if err != nil {
                t.Errorf("#... - failed to parse configuration error: %s", err)
        }
-       managerMock := &mocks.ResourceStatusInitiateManagerMock{}
-       h := NewResourceStatusInitiateNotificationHandler(log, config, managerMock, requestName)
-       return h, managerMock, config
+
+       resourceStatusServiceMock := &mocks.ResourceStatusServiceMock{}
+       rnibReaderMock := &mocks.RnibReaderMock{}
+       rsmReaderMock := &mocks.RsmReaderMock{}
+       rsmWriterMock := &mocks.RsmWriterMock{}
+
+       rnibDataService := services.NewRnibDataService(log, config, rnibReaderMock, rsmReaderMock, rsmWriterMock)
+
+       h := NewResourceStatusInitiateNotificationHandler(log, rnibDataService, resourceStatusServiceMock, requestName)
+       return h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock
 }
 
 func TestHandlerInit(t *testing.T) {
-       h, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       h, _, _, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
        assert.NotNil(t, h)
 }
 
-func TestHandleSuccess(t *testing.T) {
-       h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+func TestJsonUnmarshalError(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
 
-       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payloadStr := "blabla"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+
+       rnibReaderMock.On("GetNodeb", RanName).Return(mock.AnythingOfType("*entities.NodebInfo"))
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertNumberOfCalls(t, "GetNodeb", 0)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
+
+func TestUnknownJsonValue(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+
+       payloadStr := "{\"whatever\":3}"
        payload := []byte(payloadStr)
-       rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
-       managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+
+       rnibReaderMock.On("GetNodeb", RanName).Return(mock.AnythingOfType("*entities.NodebInfo"))
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertNumberOfCalls(t, "GetNodeb", 0)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
+
+func TestHandleGnbNode(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+
+       payloadStr := "{\"nodeType\":2, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: "RAN1", Payload: payload, Len: len(payload), StartTime: time.Now()}
+       rnibReaderMock.On("GetNodeb", RanName).Return(mock.AnythingOfType("*entities.NodebInfo"))
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertNumberOfCalls(t, "GetNodeb", 0)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
+
+func TestGetNodebFailure(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var nodebInfo *entities.NodebInfo
 
-       resourceStatusInitiateRequestParams := &e2pdus.ResourceStatusRequestData{}
-       populateResourceStatusInitiateRequestParams(resourceStatusInitiateRequestParams, config)
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
 
+       rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, common.NewInternalError(errors.New("Error")))
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
        h.Handle(rmrReq)
-       managerMock.AssertCalled(t, "Execute", rmrReq.RanName, resourceStatusInitiateRequestParams)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
 }
 
-func TestHandleResourceStatusNotEnabled(t *testing.T) {
-       h, managerMock, config := initRanConnectedNotificationHandlerTest(t, "RanConnected")
-       config.ResourceStatusParams.EnableResourceStatus = false
+func TestInvalidConnectionStatus(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _/*rsmWriterMock*/, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, err)
+       //rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true}
+       //rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err)
 
        payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
        payload := []byte(payloadStr)
-       rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
-       managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       //rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
 
+func TestGetRsmGeneralConfigurationFailure(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, _, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err)
+       var rgc models.RsmGeneralConfiguration
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(&rgc, common.NewInternalError(errors.New("Error")))
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
        h.Handle(rmrReq)
-       managerMock.AssertNumberOfCalls(t, "Execute", 0)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
 }
 
-func TestHandleUnknownJson(t *testing.T) {
-       h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+func TestEnableResourceStatusFalse(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err)
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err)
+       rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err)
 
-       payloadStr := "blablabla"
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
        payload := []byte(payloadStr)
-       rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
-       managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
+
+func TestEnableResourceStatusFalseRsmRanInfoFailure(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err)
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err)
+       rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error")))
 
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
        h.Handle(rmrReq)
-       managerMock.AssertNumberOfCalls(t, "Execute", 0)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
 }
 
-func TestHandleGnbNode(t *testing.T) {
-       h, managerMock, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected")
 
-       payloadStr := "{\"nodeType\":2, \"messageDirection\":1}"
+func TestEnableResourceStatusTrueSaveRsmRanInfoFailure(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err)
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(true), err)
+       rsmRanInfo := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error")))
+
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
        payload := []byte(payloadStr)
-       rmrReq := &models.RmrRequest{RanName:"RAN1", Payload:payload, Len:len(payload), StartTime:time.Now()}
-       managerMock.On("Execute", rmrReq.RanName, mock.AnythingOfType("*e2pdus.ResourceStatusRequestData")).Return(nil)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0)
+}
+
+func TestBuildAndSendSuccess(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       nodebInfo := &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+       rgc := getRsmGeneralConfiguration(true)
+       rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err)
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(rgc, err)
+       rsmRanInfo := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err)
 
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", nodebInfo, rgc, enums.Enb1MeasurementId).Return(nil)
+       h.Handle(rmrReq)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1)
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 1)
+}
+
+func TestBuildAndSendError(t *testing.T) {
+       h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected")
+       var err error
+       nodebInfo := &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+       rgc := getRsmGeneralConfiguration(true)
+       rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err)
+       rsmReaderMock.On("GetRsmGeneralConfiguration").Return(rgc, err)
+       rsmRanInfoStart := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfoStart).Return(err)
+       rsmRanInfoStop := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true}
+       rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfoStop).Return(err)
+       payloadStr := "{\"nodeType\":1, \"messageDirection\":1}"
+       payload := []byte(payloadStr)
+       rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()}
+       resourceStatusServiceMock.On("BuildAndSendInitiateRequest", nodebInfo, rgc, enums.Enb1MeasurementId).Return(common.NewInternalError(errors.New("Error")))
        h.Handle(rmrReq)
-       managerMock.AssertNumberOfCalls(t, "Execute", 0)
+       rnibReaderMock.AssertCalled(t, "GetNodeb", RanName)
+       rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration")
+       resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 1)
+       rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 2)
 }
index 456110b..a0d9ab1 100644 (file)
@@ -38,6 +38,7 @@ func NewResourceStatusResponseHandler(logger *logger.Logger, converter converter
 
 func (h ResourceStatusResponseHandler) Handle(request *models.RmrRequest) {
        h.logger.Infof("#ResourceStatusResponseHandler.Handle - RAN name: %s - Received resource status response notification", request.RanName)
+
        if h.logger.DebugEnabled() {
                pduAsString, err := h.converter.UnpackX2apPduAsString(request.Payload, e2pdus.MaxAsn1CodecMessageBufferSize)
                if err != nil {
@@ -46,11 +47,14 @@ func (h ResourceStatusResponseHandler) Handle(request *models.RmrRequest) {
                }
                h.logger.Debugf("#ResourceStatusResponseHandler.Handle - RAN name: %s - pdu: %s", request.RanName, pduAsString)
        }
+
        response, err := h.converter.Convert(request.Payload)
+
        if err != nil {
                h.logger.Errorf("#ResourceStatusResponseHandler.Handle - RAN name: %s - unpack failed. Error: %v", request.RanName, err)
                return
        }
+
        if response.ENB2_Measurement_ID == 0 {
                h.logger.Errorf("#ResourceStatusResponseHandler.Handle - RAN name: %s - ignoring response without ENB2_Measurement_ID for ENB1_Measurement_ID = %d", request.RanName, response.ENB1_Measurement_ID)
                return
index 6e47041..ad8a0dc 100644 (file)
@@ -33,12 +33,12 @@ func TestResourceStatusResponseHandler(t *testing.T) {
        if err != nil {
                t.Errorf("#... - failed to initialize logger, error: %s", err)
        }
-       payload:= []byte("aaa")
-       req:= models.RmrRequest{RanName: "test", StartTime:time.Now(), Payload:payload,Len:len(payload)}
-       converterMock:= mocks.ResourceStatusResponseConverterMock{}
+       payload := []byte("aaa")
+       req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)}
+       converterMock := mocks.ResourceStatusResponseConverterMock{}
        converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil)
        converterMock.On("Convert", req.Payload).Return((*models.ResourceStatusResponse)(nil), fmt.Errorf("error"))
-       h:= NewResourceStatusResponseHandler(logger, &converterMock)
+       h := NewResourceStatusResponseHandler(logger, &converterMock)
 
        h.Handle(&req)
 
@@ -46,21 +46,20 @@ func TestResourceStatusResponseHandler(t *testing.T) {
        converterMock.AssertNumberOfCalls(t, "Convert", 1)
 }
 
-
 func TestResourceStatusResponseHandlerError(t *testing.T) {
        logger, err := logger.InitLogger(logger.DebugLevel)
        if err != nil {
                t.Errorf("#... - failed to initialize logger, error: %s", err)
        }
-       payload:= []byte("aaa")
-       req:= models.RmrRequest{RanName: "test", StartTime:time.Now(), Payload:payload,Len:len(payload)}
-       converterMock:= mocks.ResourceStatusResponseConverterMock{}
+       payload := []byte("aaa")
+       req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)}
+       converterMock := mocks.ResourceStatusResponseConverterMock{}
 
        err = fmt.Errorf("error")
        var payloadAsString string
        converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(payloadAsString, err)
        converterMock.On("Convert", req.Payload).Return((*models.ResourceStatusResponse)(nil), fmt.Errorf("error"))
-       h:= NewResourceStatusResponseHandler(logger, &converterMock)
+       h := NewResourceStatusResponseHandler(logger, &converterMock)
 
        h.Handle(&req)
 
@@ -68,19 +67,18 @@ func TestResourceStatusResponseHandlerError(t *testing.T) {
        converterMock.AssertNumberOfCalls(t, "Convert", 0)
 }
 
-
 func TestResourceStatusResponseHandlerEnb2Mid0(t *testing.T) {
        logger, err := logger.InitLogger(logger.DebugLevel)
        if err != nil {
                t.Errorf("#... - failed to initialize logger, error: %s", err)
        }
-       payload:= []byte("aaa")
-       req:= models.RmrRequest{RanName: "test", StartTime:time.Now(), Payload:payload,Len:len(payload)}
+       payload := []byte("aaa")
+       req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)}
        response := &models.ResourceStatusResponse{}
-       converterMock:= mocks.ResourceStatusResponseConverterMock{}
+       converterMock := mocks.ResourceStatusResponseConverterMock{}
        converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil)
        converterMock.On("Convert", req.Payload).Return(response, nil)
-       h:= NewResourceStatusResponseHandler(logger, &converterMock)
+       h := NewResourceStatusResponseHandler(logger, &converterMock)
 
        h.Handle(&req)
 
@@ -93,13 +91,13 @@ func TestResourceStatusResponseHandlerWithMid(t *testing.T) {
        if err != nil {
                t.Errorf("#... - failed to initialize logger, error: %s", err)
        }
-       payload:= []byte("aaa")
-       req:= models.RmrRequest{RanName: "test", StartTime:time.Now(), Payload:payload,Len:len(payload)}
-       response := &models.ResourceStatusResponse{ENB1_Measurement_ID:1, ENB2_Measurement_ID:2}
-       converterMock:= mocks.ResourceStatusResponseConverterMock{}
+       payload := []byte("aaa")
+       req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)}
+       response := &models.ResourceStatusResponse{ENB1_Measurement_ID: 1, ENB2_Measurement_ID: 2}
+       converterMock := mocks.ResourceStatusResponseConverterMock{}
        converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil)
        converterMock.On("Convert", req.Payload).Return(response, nil)
-       h:= NewResourceStatusResponseHandler(logger, &converterMock)
+       h := NewResourceStatusResponseHandler(logger, &converterMock)
 
        h.Handle(&req)
 
index df6c8dd..34596c2 100644 (file)
@@ -23,4 +23,4 @@ import (
 
 type RmrMessageHandler interface {
        Handle(*models.RmrRequest)
-}
\ No newline at end of file
+}
index 2185220..26bc243 100644 (file)
@@ -82,4 +82,4 @@ func TestRun(t *testing.T) {
                t.Fatalf("failed to perform GET to http://localhost:11223/v1/health")
        }
        assert.Equal(t, 200, resp.StatusCode)
-}
\ No newline at end of file
+}
index 05730f7..9cc4414 100644 (file)
@@ -26,7 +26,7 @@ import (
 )
 
 type Logger struct {
-       Logger     *zap.Logger
+       Logger *zap.Logger
 }
 
 // Copied from zap logger
@@ -58,21 +58,21 @@ const (
        _maxLevel = FatalLevel
 )
 
-var logLevelTokenToLevel = map[string] LogLevel {
-       "debug" : DebugLevel,
-       "info": InfoLevel,
-       "warn": WarnLevel,
-       "error": ErrorLevel,
+var logLevelTokenToLevel = map[string]LogLevel{
+       "debug" DebugLevel,
+       "info":   InfoLevel,
+       "warn":   WarnLevel,
+       "error":  ErrorLevel,
        "dpanic": DPanicLevel,
-       "panic": PanicLevel,
-       "fatal": FatalLevel,
+       "panic":  PanicLevel,
+       "fatal":  FatalLevel,
 }
 
 func LogLevelTokenToLevel(level string) (LogLevel, bool) {
-       if level, ok := logLevelTokenToLevel[strings.TrimSpace(strings.ToLower(level))];ok {
+       if level, ok := logLevelTokenToLevel[strings.TrimSpace(strings.ToLower(level))]; ok {
                return level, true
        }
-       return _maxLevel+1, false
+       return _maxLevel + 1, false
 }
 
 func InitLogger(requested LogLevel) (*Logger, error) {
@@ -94,39 +94,39 @@ func InitLogger(requested LogLevel) (*Logger, error) {
        case FatalLevel:
                logger, err = initLoggerByLevel(zapcore.FatalLevel)
        default:
-               err = fmt.Errorf("Invalid logging Level :%d",requested)
+               err = fmt.Errorf("Invalid logging Level :%d", requested)
        }
        if err != nil {
                return nil, err
        }
-       return &Logger{Logger:logger}, nil
+       return &Logger{Logger: logger}, nil
 
 }
-func(l *Logger)Sync() error {
+func (l *Logger) Sync() error {
        l.Debugf("#logger.Sync - Going to flush buffered log")
        return l.Logger.Sync()
 }
 
-func (l *Logger)Infof(formatMsg string, a ...interface{})  {
+func (l *Logger) Infof(formatMsg string, a ...interface{}) {
        if l.InfoEnabled() {
                msg := fmt.Sprintf(formatMsg, a...)
                l.Logger.Info(msg, zap.Any("mdc", l.getTimeStampMdc()))
        }
 }
 
-func (l *Logger)Debugf(formatMsg string, a ...interface{})  {
-       if l.DebugEnabled(){
+func (l *Logger) Debugf(formatMsg string, a ...interface{}) {
+       if l.DebugEnabled() {
                msg := fmt.Sprintf(formatMsg, a...)
                l.Logger.Debug(msg, zap.Any("mdc", l.getTimeStampMdc()))
        }
 }
 
-func (l *Logger)Errorf(formatMsg string, a ...interface{})  {
+func (l *Logger) Errorf(formatMsg string, a ...interface{}) {
        msg := fmt.Sprintf(formatMsg, a...)
        l.Logger.Error(msg, zap.Any("mdc", l.getTimeStampMdc()))
 }
 
-func (l *Logger)Warnf(formatMsg string, a ...interface{})  {
+func (l *Logger) Warnf(formatMsg string, a ...interface{}) {
        msg := fmt.Sprintf(formatMsg, a...)
        l.Logger.Warn(msg, zap.Any("mdc", l.getTimeStampMdc()))
 }
@@ -137,15 +137,15 @@ func (l *Logger) getTimeStampMdc() map[string]string {
        return mdc
 }
 
-func (l *Logger)InfoEnabled()bool{
+func (l *Logger) InfoEnabled() bool {
        return l.Logger.Core().Enabled(zap.InfoLevel)
 }
 
-func (l *Logger)DebugEnabled()bool{
+func (l *Logger) DebugEnabled() bool {
        return l.Logger.Core().Enabled(zap.DebugLevel)
 }
 
-func (l *Logger)DPanicf(formatMsg string, a ...interface{})  {
+func (l *Logger) DPanicf(formatMsg string, a ...interface{}) {
        msg := fmt.Sprintf(formatMsg, a...)
        l.Logger.DPanic(msg, zap.Any("mdc", l.getTimeStampMdc()))
 }
@@ -181,4 +181,3 @@ func epochMillisIntegerTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncode
        millis := int64(nanos) / int64(time.Millisecond)
        enc.AppendInt64(millis)
 }
-
index b06ab9d..e93c56b 100644 (file)
@@ -75,9 +75,9 @@ func TestInitInfoLoggerFailure(t *testing.T) {
        assert.Nil(t, log)
 }
 
-func TestSyncSuccess(t *testing.T){
+func TestSyncSuccess(t *testing.T) {
        logFile, err := os.Create("./loggerTest.txt")
-       if err != nil{
+       if err != nil {
                t.Errorf("logger_test.TestSyncSuccess - failed to create file, error: %s", err)
        }
        old := os.Stdout
@@ -91,7 +91,7 @@ func TestSyncSuccess(t *testing.T){
 
        os.Stdout = old
        logFile, err = os.Open("./loggerTest.txt")
-       if err != nil{
+       if err != nil {
                t.Errorf("logger_test.TestSyncSuccess - failed to open file, error: %s", err)
        }
        var buf bytes.Buffer
@@ -99,8 +99,8 @@ func TestSyncSuccess(t *testing.T){
        if err != nil {
                t.Errorf("logger_test.TestSyncSuccess - failed to copy bytes, error: %s", err)
        }
-       debugRecord,_ :=buf.ReadString('\n')
-       errorRecord,_ :=buf.ReadString('\n')
+       debugRecord, _ := buf.ReadString('\n')
+       errorRecord, _ := buf.ReadString('\n')
 
        assert.NotEmpty(t, debugRecord)
        assert.Empty(t, errorRecord)
@@ -111,78 +111,78 @@ func TestSyncSuccess(t *testing.T){
 
 }
 
-func TestSyncFailure(t *testing.T){
+func TestSyncFailure(t *testing.T) {
        log, err := InitLogger(DebugLevel)
        err = log.Sync()
        assert.NotNil(t, err)
 }
 
-func TestDebugEnabledFalse(t *testing.T){
+func TestDebugEnabledFalse(t *testing.T) {
        entryNum, log := countRecords(InfoLevel, t)
        assert.False(t, log.DebugEnabled())
-       assert.Equal(t,3, entryNum)
+       assert.Equal(t, 3, entryNum)
 }
 
-func TestDebugEnabledTrue(t *testing.T){
+func TestDebugEnabledTrue(t *testing.T) {
        entryNum, log := countRecords(DebugLevel, t)
        assert.True(t, log.DebugEnabled())
-       assert.Equal(t,4, entryNum)
+       assert.Equal(t, 4, entryNum)
 }
 
-func TestDPanicfDebugLevel(t *testing.T){
-       assert.True(t,validateRecordExists(DebugLevel, zap.DPanicLevel, t))
+func TestDPanicfDebugLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(DebugLevel, zap.DPanicLevel, t))
 }
 
-func TestDPanicfInfoLevel(t *testing.T){
-       assert.True(t,validateRecordExists(InfoLevel, zap.DPanicLevel, t))
+func TestDPanicfInfoLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(InfoLevel, zap.DPanicLevel, t))
 }
 
-func TestErrorfDebugLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(DebugLevel, zap.ErrorLevel, t))
+func TestErrorfDebugLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(DebugLevel, zap.ErrorLevel, t))
 }
 
-func TestErrorfInfoLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(InfoLevel, zap.ErrorLevel, t))
+func TestErrorfInfoLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(InfoLevel, zap.ErrorLevel, t))
 }
 
-func TestInfofDebugLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(DebugLevel, zap.InfoLevel, t))
+func TestInfofDebugLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(DebugLevel, zap.InfoLevel, t))
 }
 
-func TestInfofInfoLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(InfoLevel, zap.InfoLevel, t))
+func TestInfofInfoLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(InfoLevel, zap.InfoLevel, t))
 }
 
-func TestDebugfDebugLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(DebugLevel, zap.DebugLevel, t))
+func TestDebugfDebugLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(DebugLevel, zap.DebugLevel, t))
 }
 
-func TestDebugfInfoLevel(t *testing.T)  {
-       assert.False(t,validateRecordExists(InfoLevel, zap.DebugLevel, t))
+func TestDebugfInfoLevel(t *testing.T) {
+       assert.False(t, validateRecordExists(InfoLevel, zap.DebugLevel, t))
 }
 
-func TestInfofFatalLevel(t *testing.T)  {
-       assert.False(t,validateRecordExists(FatalLevel, zap.InfoLevel, t))
+func TestInfofFatalLevel(t *testing.T) {
+       assert.False(t, validateRecordExists(FatalLevel, zap.InfoLevel, t))
 }
 
-func TestDebugfFatalLevel(t *testing.T)  {
-       assert.False(t,validateRecordExists(FatalLevel, zap.DebugLevel, t))
+func TestDebugfFatalLevel(t *testing.T) {
+       assert.False(t, validateRecordExists(FatalLevel, zap.DebugLevel, t))
 }
 
-func TestWarnfWarnLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(WarnLevel, zap.WarnLevel, t))
+func TestWarnfWarnLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(WarnLevel, zap.WarnLevel, t))
 }
 
-func TestWarnfDebugLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(DebugLevel, zap.WarnLevel, t))
+func TestWarnfDebugLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(DebugLevel, zap.WarnLevel, t))
 }
 
-func TestWarnfInfoLevel(t *testing.T)  {
-       assert.True(t,validateRecordExists(InfoLevel, zap.WarnLevel, t))
+func TestWarnfInfoLevel(t *testing.T) {
+       assert.True(t, validateRecordExists(InfoLevel, zap.WarnLevel, t))
 }
 
-func TestWarnfFatalLevel(t *testing.T)  {
-       assert.False(t,validateRecordExists(FatalLevel, zap.WarnLevel, t))
+func TestWarnfFatalLevel(t *testing.T) {
+       assert.False(t, validateRecordExists(FatalLevel, zap.WarnLevel, t))
 }
 
 func TestLogLevelTokenToLevel(t *testing.T) {
@@ -219,9 +219,9 @@ func TestLogLevelTokenToLevel(t *testing.T) {
        assert.True(t, level > FatalLevel)
 
 }
-func countRecords(logLevel LogLevel, t *testing.T) (int, *Logger){
+func countRecords(logLevel LogLevel, t *testing.T) (int, *Logger) {
        old := os.Stdout
-       r, w, _ :=os.Pipe()
+       r, w, _ := os.Pipe()
        os.Stdout = w
        log, err := InitLogger(logLevel)
        if err != nil {
@@ -242,24 +242,24 @@ func countRecords(logLevel LogLevel, t *testing.T) (int, *Logger){
                t.Errorf("logger_test.TestSyncFailure - failed to copy bytes, error: %s", err)
        }
        entryNum := 0
-       s,_:= buf.ReadString('\n')
-       for len(s) > 0{
-               entryNum +=1
-               s,_= buf.ReadString('\n')
+       s, _ := buf.ReadString('\n')
+       for len(s) > 0 {
+               entryNum += 1
+               s, _ = buf.ReadString('\n')
        }
        return entryNum, log
 }
 
 func validateRecordExists(logLevel LogLevel, recordLevel zapcore.Level, t *testing.T) bool {
        old := os.Stdout
-       r, w, _ :=os.Pipe()
+       r, w, _ := os.Pipe()
        os.Stdout = w
        log, err := InitLogger(logLevel)
        if err != nil {
                t.Errorf("logger_test.TestSyncFailure - failed to initialize logger, error: %s", err)
        }
-       switch recordLevel{
-       case  zap.DebugLevel:
+       switch recordLevel {
+       case zap.DebugLevel:
                log.Debugf("%v, %v, %v", 1, "abc", 0.1)
        case zap.InfoLevel:
                log.Infof("%v, %v, %v", 1, "abc", 0.1)
@@ -281,10 +281,10 @@ func validateRecordExists(logLevel LogLevel, recordLevel zapcore.Level, t *testi
                t.Errorf("logger_test.TestSyncFailure - failed to copy bytes, error: %s", err)
        }
        entryNum := 0
-       s,_:= buf.ReadString('\n')
-       for len(s) > 0{
-               entryNum +=1
-               s,_= buf.ReadString('\n')
+       s, _ := buf.ReadString('\n')
+       for len(s) > 0 {
+               entryNum += 1
+               s, _ = buf.ReadString('\n')
        }
        return entryNum == 1
-}
\ No newline at end of file
+}
diff --git a/RSM/managers/resource_status_initiate_manager.go b/RSM/managers/resource_status_initiate_manager.go
deleted file mode 100644 (file)
index 4ff7e1d..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-package managers
-
-import (
-       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
-       "rsm/e2pdus"
-       "rsm/enums"
-       "rsm/logger"
-       "rsm/models"
-       "rsm/rmrcgo"
-       "rsm/rsmerrors"
-       "rsm/services"
-       "rsm/services/rmrsender"
-)
-
-type ResourceStatusInitiateManager struct {
-       logger          *logger.Logger
-       rnibDataService services.RNibDataService
-       rmrSender       *rmrsender.RmrSender
-}
-
-type IResourceStatusInitiateManager interface {
-       Execute(inventoryName string, resourceStatusInitiateRequestParams *e2pdus.ResourceStatusRequestData) error
-}
-
-func NewResourceStatusInitiateManager(logger *logger.Logger, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender) *ResourceStatusInitiateManager {
-       return &ResourceStatusInitiateManager{
-               logger:          logger,
-               rnibDataService: rnibDataService,
-               rmrSender:       rmrSender,
-       }
-}
-
-func (m *ResourceStatusInitiateManager) Execute(inventoryName string, resourceStatusInitiateRequestParams *e2pdus.ResourceStatusRequestData) error {
-
-       nodebInfo, err := m.rnibDataService.GetNodeb(inventoryName)
-
-       if err != nil {
-               m.logger.Errorf("#ResourceStatusInitiateManager.Execute - RAN name: %s - Error fetching RAN from rNib: %v", inventoryName, err)
-               return rsmerrors.NewRnibDbError()
-       }
-
-       m.logger.Infof("#ResourceStatusInitiateManager.Execute - RAN name: %s, connection status: %s", nodebInfo.GetRanName(), nodebInfo.GetConnectionStatus())
-
-       if nodebInfo.GetConnectionStatus() != entities.ConnectionStatus_CONNECTED {
-               m.logger.Errorf("#ResourceStatusInitiateManager.Execute - RAN name: %s - RAN's connection status isn't CONNECTED", inventoryName)
-               return rsmerrors.NewWrongStateError("Resource Status Initiate", entities.ConnectionStatus_name[int32(nodebInfo.ConnectionStatus)])
-       }
-
-       m.sendResourceStatusInitiatePerCell(nodebInfo, *resourceStatusInitiateRequestParams)
-
-       return nil
-}
-
-func (m *ResourceStatusInitiateManager) sendResourceStatusInitiatePerCell(nodebInfo *entities.NodebInfo, requestParams e2pdus.ResourceStatusRequestData) {
-       enb, _ := nodebInfo.Configuration.(*entities.NodebInfo_Enb)
-       cells := enb.Enb.ServedCells
-
-       for index, cellInfo := range cells {
-               requestParams.CellIdList = []string{cellInfo.CellId}
-               requestParams.MeasurementID = e2pdus.Measurement_ID(index + 1)
-
-               m.logger.Infof("#ResourceStatusInitiateManager.sendResourceStatusInitiatePerCell - RAN name: %s, Going to send request for cell id %v, measurement id %d", nodebInfo.RanName, requestParams.CellIdList, requestParams.MeasurementID)
-
-               payload, payloadAsString, err := e2pdus.BuildPackedResourceStatusRequest(enums.Registration_Request_start, &requestParams, e2pdus.MaxAsn1PackedBufferSize, e2pdus.MaxAsn1CodecMessageBufferSize, m.logger.DebugEnabled())
-               if err != nil {
-                       m.logger.Errorf("#ResourceStatusInitiateManager.sendResourceStatusInitiatePerCell - RAN name: %s. Failed to build and pack the resource status initiate request for cell id %v, measurement id %d. error: %s", nodebInfo.RanName, requestParams.CellIdList, requestParams.MeasurementID, err)
-                       continue
-               }
-
-               m.logger.Debugf("#ResourceStatusInitiateManager.sendResourceStatusInitiatePerCell - RAN name: %s, cell id: %v, measurement id: %d, payload: %s", nodebInfo.RanName, requestParams.CellIdList, requestParams.MeasurementID, payloadAsString)
-
-               rmrMsg := models.NewRmrMessage(rmrcgo.RicResStatusReq, nodebInfo.RanName, payload)
-               go m.rmrSender.Send(rmrMsg)
-       }
-}
diff --git a/RSM/managers/resource_status_initiate_manager_test.go b/RSM/managers/resource_status_initiate_manager_test.go
deleted file mode 100644 (file)
index a136177..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-package managers
-
-import (
-       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
-       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
-       "github.com/pkg/errors"
-       "github.com/stretchr/testify/assert"
-       "rsm/configuration"
-       "rsm/e2pdus"
-       "rsm/enums"
-       "rsm/logger"
-       "rsm/mocks"
-       "rsm/rmrcgo"
-       "rsm/rsmerrors"
-       "rsm/services"
-       "rsm/tests/testhelper"
-       "testing"
-       "time"
-)
-
-const RanName = "test"
-
-func initResourceStatusInitiateManagerTest(t *testing.T) (*mocks.RmrMessengerMock, *mocks.RnibReaderMock, *e2pdus.ResourceStatusRequestData, *ResourceStatusInitiateManager) {
-       logger, err := logger.InitLogger(logger.InfoLevel)
-       if err != nil {
-               t.Errorf("#... - failed to initialize logger, error: %s", err)
-       }
-
-       config, err := configuration.ParseConfiguration()
-       if err != nil {
-               t.Errorf("#... - failed to parse configuration error: %s", err)
-       }
-
-       rmrMessengerMock := &mocks.RmrMessengerMock{}
-       rmrSender := testhelper.InitRmrSender(rmrMessengerMock, logger)
-
-       readerMock := &mocks.RnibReaderMock{}
-
-       resourceStatusRequestData := &e2pdus.ResourceStatusRequestData{}
-       populateResourceStatusInitiateRequestParams(resourceStatusRequestData, config)
-
-       rnibDataService := services.NewRnibDataService(logger, config, readerMock)
-       resourceStatusInitiateManager := NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
-       return rmrMessengerMock, readerMock, resourceStatusRequestData, resourceStatusInitiateManager
-}
-
-func TestGetNodebFailure(t *testing.T) {
-       rmrMessengerMock, readerMock, resourceStatusInitiateRequestParams, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       var nodebInfo *entities.NodebInfo
-       readerMock.On("GetNodeb", RanName).Return(nodebInfo, common.NewInternalError(errors.New("Error")))
-       err := resourceStatusInitiateManager.Execute(RanName, resourceStatusInitiateRequestParams)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       assert.IsType(t, &rsmerrors.RnibDbError{}, err)
-       rmrMessengerMock.AssertNotCalled(t, "SendMsg")
-}
-
-func TestInvalidConnectionStatus(t *testing.T) {
-       rmrMessengerMock, readerMock, resourceStatusInitiateRequestParams, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       var err error
-       readerMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, err)
-       err = resourceStatusInitiateManager.Execute(RanName, resourceStatusInitiateRequestParams)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       assert.IsType(t, &rsmerrors.WrongStateError{}, err)
-       rmrMessengerMock.AssertNotCalled(t, "SendMsg")
-}
-
-func TestPackFailure(t *testing.T) {
-       rmrMessengerMock, readerMock, resourceRequestData, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       var err error
-       nodebInfo := &entities.NodebInfo{
-               RanName:          RanName,
-               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
-               Configuration: &entities.NodebInfo_Enb{
-                       Enb: &entities.Enb{
-                               ServedCells: []*entities.ServedCellInfo{{CellId: ""}},
-                       },
-               },
-       }
-
-       readerMock.On("GetNodeb", RanName).Return(nodebInfo, err)
-       err = resourceStatusInitiateManager.Execute(RanName, resourceRequestData)
-       assert.Nil(t, err)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       rmrMessengerMock.AssertNotCalled(t, "SendMsg")
-}
-
-func TestOneCellSuccess(t *testing.T) {
-       cellId := "02f829:0007ab00"
-       rmrMessengerMock, readerMock, resourceRequestData, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       xaction := []byte(RanName)
-       var err error
-       nodebInfo := &entities.NodebInfo{
-               RanName:          RanName,
-               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
-               Configuration: &entities.NodebInfo_Enb{
-                       Enb: &entities.Enb{
-                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId}},
-                       },
-               },
-       }
-
-       readerMock.On("GetNodeb", RanName).Return(nodebInfo, err)
-       expectedPayload := getPackedPayloadForCell(cellId, 1, *resourceRequestData)
-       expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction)
-       rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, err)
-       err = resourceStatusInitiateManager.Execute(RanName, resourceRequestData)
-       time.Sleep(100 * time.Millisecond)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       assert.Nil(t, err)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf)
-       rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 1)
-}
-
-func TestTwoCellOneFailureOneSuccess(t *testing.T) {
-       cellId1 := "02f829:0007ab00"
-       cellId2 := "02f829:0007ab50"
-       rmrMessengerMock, readerMock, resourceRequestData, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       xaction := []byte(RanName)
-       var err error
-       nodebInfo := &entities.NodebInfo{
-               RanName:          RanName,
-               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
-               Configuration: &entities.NodebInfo_Enb{
-                       Enb: &entities.Enb{
-                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId1}, {CellId: cellId2}},
-                       },
-               },
-       }
-
-       readerMock.On("GetNodeb", RanName).Return(nodebInfo, err)
-       expectedPayload1 := getPackedPayloadForCell(cellId1, 1, *resourceRequestData)
-       expectedMbuf1 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload1), RanName, &expectedPayload1, &xaction)
-
-       expectedPayload2 := getPackedPayloadForCell(cellId2, 2, *resourceRequestData)
-       expectedMbuf2 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload2), RanName, &expectedPayload2, &xaction)
-       rmrMessengerMock.On("SendMsg", expectedMbuf1).Return(&rmrcgo.MBuf{}, rsmerrors.NewRmrError())
-       rmrMessengerMock.On("SendMsg", expectedMbuf2).Return(&rmrcgo.MBuf{}, err)
-       err = resourceStatusInitiateManager.Execute(RanName, resourceRequestData)
-       time.Sleep(100 * time.Millisecond)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       assert.Nil(t, err)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf1)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf2)
-       rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 2)
-}
-
-func TestFiveCellsSuccess(t *testing.T) {
-       cellId1 := "02f829:0007ab00"
-       cellId2 := "02f829:0007ab50"
-       cellId3 := "02f829:0007ab60"
-       cellId4 := "02f829:0007ab70"
-       cellId5 := "02f829:0007ab80"
-
-       rmrMessengerMock, readerMock, resourceRequestData, resourceStatusInitiateManager := initResourceStatusInitiateManagerTest(t)
-       xaction := []byte(RanName)
-       var err error
-       nodebInfo := &entities.NodebInfo{
-               RanName:          RanName,
-               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
-               Configuration: &entities.NodebInfo_Enb{
-                       Enb: &entities.Enb{
-                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId1}, {CellId: cellId2}, {CellId: cellId3}, {CellId: cellId4}, {CellId: cellId5}},
-                       },
-               },
-       }
-
-       readerMock.On("GetNodeb", RanName).Return(nodebInfo, err)
-       expectedPayload1 := getPackedPayloadForCell(cellId1, 1, *resourceRequestData)
-       expectedMbuf1 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload1), RanName, &expectedPayload1, &xaction)
-
-       expectedPayload2 := getPackedPayloadForCell(cellId2, 2, *resourceRequestData)
-       expectedMbuf2 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload2), RanName, &expectedPayload2, &xaction)
-
-       expectedPayload3 := getPackedPayloadForCell(cellId3, 3, *resourceRequestData)
-       expectedMbuf3 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload3), RanName, &expectedPayload3, &xaction)
-
-       expectedPayload4 := getPackedPayloadForCell(cellId4, 4, *resourceRequestData)
-       expectedMbuf4 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload4), RanName, &expectedPayload4, &xaction)
-
-       expectedPayload5 := getPackedPayloadForCell(cellId5, 5, *resourceRequestData)
-       expectedMbuf5 := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload5), RanName, &expectedPayload5, &xaction)
-
-       rmrMessengerMock.On("SendMsg", expectedMbuf1).Return(&rmrcgo.MBuf{}, err)
-       rmrMessengerMock.On("SendMsg", expectedMbuf2).Return(&rmrcgo.MBuf{}, err)
-       rmrMessengerMock.On("SendMsg", expectedMbuf3).Return(&rmrcgo.MBuf{}, err)
-       rmrMessengerMock.On("SendMsg", expectedMbuf4).Return(&rmrcgo.MBuf{}, err)
-       rmrMessengerMock.On("SendMsg", expectedMbuf5).Return(&rmrcgo.MBuf{}, err)
-
-       err = resourceStatusInitiateManager.Execute(RanName, resourceRequestData)
-       time.Sleep(100 * time.Millisecond)
-       readerMock.AssertCalled(t, "GetNodeb", RanName)
-       assert.Nil(t, err)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf1)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf2)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf3)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf4)
-       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf5)
-
-       rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 5)
-}
-
-func getPackedPayloadForCell(cellId string, index int, resourceStatusRequestData e2pdus.ResourceStatusRequestData) []byte {
-       resourceStatusRequestData.CellIdList = []string{cellId}
-       resourceStatusRequestData.MeasurementID = e2pdus.Measurement_ID(index)
-       expectedPayload, _, _ := e2pdus.BuildPackedResourceStatusRequest(enums.Registration_Request_start, &resourceStatusRequestData, e2pdus.MaxAsn1PackedBufferSize, e2pdus.MaxAsn1CodecMessageBufferSize, false)
-       return expectedPayload
-}
-
-func populateResourceStatusInitiateRequestParams(params *e2pdus.ResourceStatusRequestData, config *configuration.Configuration) {
-       params.PartialSuccessAllowed = config.ResourceStatusParams.PartialSuccessAllowed
-       params.PrbPeriodic = config.ResourceStatusParams.PrbPeriodic
-       params.TnlLoadIndPeriodic = config.ResourceStatusParams.TnlLoadIndPeriodic
-       params.HwLoadIndPeriodic = config.ResourceStatusParams.HwLoadIndPeriodic
-       params.AbsStatusPeriodic = config.ResourceStatusParams.AbsStatusPeriodic
-       params.RsrpMeasurementPeriodic = config.ResourceStatusParams.RsrpMeasurementPeriodic
-       params.CsiPeriodic = config.ResourceStatusParams.CsiPeriodic
-       params.PeriodicityMS = config.ResourceStatusParams.PeriodicityMs
-       params.PeriodicityRsrpMeasurementMS = config.ResourceStatusParams.PeriodicityRsrpMeasurementMs
-       params.PeriodicityCsiMS = config.ResourceStatusParams.PeriodicityCsiMs
-}
index e1eaf1b..898be0c 100644 (file)
@@ -21,7 +21,6 @@ import (
        "rsm/configuration"
        "rsm/converters"
        "rsm/logger"
-       "rsm/managers"
        "rsm/models"
        "rsm/providers/rmrmsghandlerprovider"
        "rsm/rmrcgo"
@@ -35,12 +34,12 @@ type RmrMessageManager struct {
        handlerProvider *rmrmsghandlerprovider.MessageHandlerProvider
 }
 
-func NewRmrMessageManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusInitiateManager *managers.ResourceStatusInitiateManager, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) *RmrMessageManager {
-       handlerProvider := rmrmsghandlerprovider.NewMessageHandlerProvider(logger,config, rnibDataService, rmrSender, resourceStatusInitiateManager, rsConverter, rsFailureConverter)
+func NewRmrMessageManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusService *services.ResourceStatusService, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) *RmrMessageManager {
+       handlerProvider := rmrmsghandlerprovider.NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusService, rsConverter, rsFailureConverter)
 
        return &RmrMessageManager{
                handlerProvider: handlerProvider,
-               logger: logger,
+               logger:          logger,
        }
 }
 
index c102754..573466a 100644 (file)
@@ -20,8 +20,8 @@ import (
        "rsm/configuration"
        "rsm/converters"
        "rsm/e2pdus"
-       "rsm/managers"
        "rsm/rmrcgo"
+       "rsm/services"
        "rsm/tests/testhelper"
        "testing"
 )
@@ -30,9 +30,9 @@ func TestRmrMessageManagerSuccess(t *testing.T) {
 
        rnibDataService, rmrSender, logger := testhelper.InitTestCase(t)
        config, _ := configuration.ParseConfiguration()
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
        unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
-       manager := NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+       manager := NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
 
        xactionByteArr := []byte("1111111")
        payloadByteArr := []byte("payload")
@@ -45,9 +45,9 @@ func TestRmrMessageManagerFailure(t *testing.T) {
 
        rnibDataService, rmrSender, logger := testhelper.InitTestCase(t)
        config, _ := configuration.ParseConfiguration()
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
        unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
-       manager := NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager,converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+       manager := NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
 
        xactionByteArr := []byte("1111111")
        payloadByteArr := []byte("payload")
index 6a66569..d860857 100644 (file)
@@ -1,3 +1,20 @@
+//
+// 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 mocks
 
 import (
index 099900b..2722ffe 100644 (file)
@@ -26,14 +26,12 @@ type ResourceStatusFailureConverterMock struct {
        mock.Mock
 }
 
-
-func (m *ResourceStatusFailureConverterMock)Convert(packedBuf []byte) (*models.ResourceStatusResponse, error){
+func (m *ResourceStatusFailureConverterMock) Convert(packedBuf []byte) (*models.ResourceStatusResponse, error) {
        args := m.Called(packedBuf)
        return args.Get(0).(*models.ResourceStatusResponse), args.Error(1)
 }
 
-func (m *ResourceStatusFailureConverterMock)UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error){
+func (m *ResourceStatusFailureConverterMock) UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error) {
        args := m.Called(packedBuf, maxMessageBufferSize)
        return args.Get(0).(string), args.Error(1)
 }
-
index 9251f60..269353b 100644 (file)
@@ -1,3 +1,20 @@
+//
+// 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 mocks
 
 import (
index 592b12d..674d244 100644 (file)
@@ -26,13 +26,12 @@ type ResourceStatusResponseConverterMock struct {
        mock.Mock
 }
 
-func (m *ResourceStatusResponseConverterMock)Convert(packedBuf []byte) (*models.ResourceStatusResponse, error){
+func (m *ResourceStatusResponseConverterMock) Convert(packedBuf []byte) (*models.ResourceStatusResponse, error) {
        args := m.Called(packedBuf)
        return args.Get(0).(*models.ResourceStatusResponse), args.Error(1)
 }
 
-func (m *ResourceStatusResponseConverterMock)UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error){
+func (m *ResourceStatusResponseConverterMock) UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error) {
        args := m.Called(packedBuf, maxMessageBufferSize)
        return args.Get(0).(string), args.Error(1)
 }
-
diff --git a/RSM/mocks/resource_status_service_mock.go b/RSM/mocks/resource_status_service_mock.go
new file mode 100644 (file)
index 0000000..1597795
--- /dev/null
@@ -0,0 +1,33 @@
+//
+// 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 mocks
+
+import (
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "github.com/stretchr/testify/mock"
+       "rsm/models"
+)
+
+type ResourceStatusServiceMock struct {
+       mock.Mock
+}
+
+func (m *ResourceStatusServiceMock) BuildAndSendInitiateRequest(nodeb *entities.NodebInfo, config *models.RsmGeneralConfiguration, enb1MeasurementId int64) error {
+       args := m.Called(nodeb, config, enb1MeasurementId)
+       return args.Error(0)
+}
index 134d145..f2b3ad8 100644 (file)
@@ -27,34 +27,34 @@ type RmrMessengerMock struct {
        mock.Mock
 }
 
-func (m *RmrMessengerMock) Init(readyIntervalSec int, port string, maxMsgSize int, flags int, logger *logger.Logger) rmrcgo.RmrMessenger{
+func (m *RmrMessengerMock) Init(readyIntervalSec int, port string, maxMsgSize int, flags int, logger *logger.Logger) rmrcgo.RmrMessenger {
        args := m.Called(readyIntervalSec, port, maxMsgSize, flags, logger)
        return args.Get(0).(rmrcgo.RmrMessenger)
 }
 
-func (m *RmrMessengerMock) SendMsg(msg *rmrcgo.MBuf) (*rmrcgo.MBuf, error){
+func (m *RmrMessengerMock) SendMsg(msg *rmrcgo.MBuf) (*rmrcgo.MBuf, error) {
        args := m.Called(msg)
        return args.Get(0).(*rmrcgo.MBuf), args.Error(1)
 }
 
-func (m *RmrMessengerMock) RecvMsg() (*rmrcgo.MBuf, error){
-       args := m.Called( )
+func (m *RmrMessengerMock) RecvMsg() (*rmrcgo.MBuf, error) {
+       args := m.Called()
        return args.Get(0).(*rmrcgo.MBuf), args.Error(1)
 }
 
-func (m *RmrMessengerMock) RtsMsg(msg *rmrcgo.MBuf){
-       m.Called( )
+func (m *RmrMessengerMock) RtsMsg(msg *rmrcgo.MBuf) {
+       m.Called()
 }
 
-func (m *RmrMessengerMock) FreeMsg(){
-       m.Called( )
+func (m *RmrMessengerMock) FreeMsg() {
+       m.Called()
 }
 
-func (m *RmrMessengerMock) IsReady() bool{
-       args := m.Called( )
+func (m *RmrMessengerMock) IsReady() bool {
+       args := m.Called()
        return args.Bool(0)
 }
 
-func (m *RmrMessengerMock) Close(){
-       m.Called( )
-}
\ No newline at end of file
+func (m *RmrMessengerMock) Close() {
+       m.Called()
+}
index bc304c1..46bd86f 100644 (file)
@@ -1,3 +1,20 @@
+//
+// 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 mocks
 
 import (
diff --git a/RSM/mocks/rsm_reader_mock.go b/RSM/mocks/rsm_reader_mock.go
new file mode 100644 (file)
index 0000000..4ade9cd
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// 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 mocks
+
+import (
+       "github.com/stretchr/testify/mock"
+       "rsm/models"
+)
+
+type RsmReaderMock struct {
+       mock.Mock
+}
+
+func (m *RsmReaderMock) GetRsmRanInfo(inventoryName string) (*models.RsmRanInfo, error) {
+       args := m.Called(inventoryName)
+       return args.Get(0).(*models.RsmRanInfo), args.Error(1)
+}
+
+func (m *RsmReaderMock) GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error) {
+       args := m.Called()
+       return args.Get(0).(*models.RsmGeneralConfiguration), args.Error(1)
+}
diff --git a/RSM/mocks/rsm_writer_mock.go b/RSM/mocks/rsm_writer_mock.go
new file mode 100644 (file)
index 0000000..a2a62d8
--- /dev/null
@@ -0,0 +1,31 @@
+//
+// 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 mocks
+
+import (
+       "github.com/stretchr/testify/mock"
+       "rsm/models"
+)
+
+type RsmWriterMock struct {
+       mock.Mock
+}
+
+func (m *RsmWriterMock) SaveRsmRanInfo(rsmRanInfo *models.RsmRanInfo) error {
+       args := m.Called(rsmRanInfo)
+       return args.Error(0)
+}
index 505ca62..c006fa4 100644 (file)
@@ -106,7 +106,7 @@ func (m *MockSdlInstance) RemoveIf(key string, data interface{}) (bool, error) {
        return a.Bool(0), a.Error(1)
 }
 
-func (m *MockSdlInstance) AddMember(group string, member ...interface{}) error{
+func (m *MockSdlInstance) AddMember(group string, member ...interface{}) error {
        a := m.Called(group, member)
        return a.Error(0)
 }
@@ -123,11 +123,11 @@ func (m *MockSdlInstance) GetMembers(group string) ([]string, error) {
        a := m.Called(group)
        return a.Get(0).([]string), a.Error(1)
 }
-func (m *MockSdlInstance) IsMember(group string, member interface{}) (bool, error){
+func (m *MockSdlInstance) IsMember(group string, member interface{}) (bool, error) {
        a := m.Called(group, member)
        return a.Bool(0), a.Error(1)
 }
-func (m *MockSdlInstance) GroupSize(group string) (int64, error){
-       a := m.Called(group,)
+func (m *MockSdlInstance) GroupSize(group string) (int64, error) {
+       a := m.Called(group)
        return int64(a.Int(0)), a.Error(1)
 }
index cde078b..8001a1c 100644 (file)
@@ -18,5 +18,4 @@
 package models
 
 type Request interface {
-
 }
index 5e5c1c9..bca52dc 100644 (file)
@@ -1,8 +1,25 @@
+//
+// 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 models
 
 import (
-       "rsm/enums"
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "rsm/enums"
 )
 
 type ResourceStatusPayload struct {
index 26af8de..dae459e 100644 (file)
@@ -1,3 +1,20 @@
+//
+// 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 models
 
 import (
@@ -18,7 +35,7 @@ type MeasurementInitiationResult struct {
        MeasurementFailureCauses []*MeasurementFailureCause
 }
 
-func (r MeasurementInitiationResult)String() string {
+func (r MeasurementInitiationResult) String() string {
        var strBuilder strings.Builder
        strBuilder.WriteString("[ ")
        for _, cause := range r.MeasurementFailureCauses {
@@ -35,7 +52,7 @@ type ResourceStatusResponse struct {
        MeasurementInitiationResults []*MeasurementInitiationResult
 }
 
-func (r ResourceStatusResponse)String() string{
+func (r ResourceStatusResponse) String() string {
        var strBuilder strings.Builder
        strBuilder.WriteString("[ ")
        for _, result := range r.MeasurementInitiationResults {
@@ -44,4 +61,4 @@ func (r ResourceStatusResponse)String() string{
        }
        strBuilder.WriteString(" ]")
        return fmt.Sprintf("ENB1_Measurement_ID: %d, ENB2_Measurement_ID: %d, MeasurementInitiationResults:%s", r.ENB1_Measurement_ID, r.ENB2_Measurement_ID, strBuilder.String())
-}
\ No newline at end of file
+}
index 6a01932..27423ce 100644 (file)
@@ -19,4 +19,4 @@ package models
 
 type IResponse interface {
        Marshal() (string, error)
-}
\ No newline at end of file
+}
index 70d2740..55abd45 100644 (file)
@@ -37,4 +37,4 @@ func NewRmrMessage(msgType int, ranName string, payload []byte) *RmrMessage {
 
 func (response RmrMessage) GetMessageAsBytes(logger *logger.Logger) []byte {
        return response.Payload
-}
\ No newline at end of file
+}
index fbead1b..3e1e78e 100644 (file)
@@ -20,10 +20,10 @@ package models
 import "time"
 
 type RmrRequest struct {
-       RanName       string
-       Len           int
-       Payload       []byte
-       StartTime     time.Time
+       RanName   string
+       Len       int
+       Payload   []byte
+       StartTime time.Time
 }
 
 func NewRmrRequest(ranName string, payload []byte, startTime time.Time) *RmrRequest {
@@ -33,4 +33,4 @@ func NewRmrRequest(ranName string, payload []byte, startTime time.Time) *RmrRequ
                payload,
                startTime,
        }
-}
\ No newline at end of file
+}
diff --git a/RSM/models/rsm_general_configuration.go b/RSM/models/rsm_general_configuration.go
new file mode 100644 (file)
index 0000000..d892d81
--- /dev/null
@@ -0,0 +1,34 @@
+//
+// 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 models
+
+import "rsm/enums"
+
+type RsmGeneralConfiguration struct {
+       EnableResourceStatus         bool                             `json:"enableResourceStatus"`
+       PartialSuccessAllowed        bool                             `json:"partialSuccessAllowed"`
+       PrbPeriodic                  bool                             `json:"prbPeriodic"`
+       TnlLoadIndPeriodic           bool                             `json:"tnlLoadIndPeriodic"`
+       HwLoadIndPeriodic            bool                             `json:"wwLoadIndPeriodic"`
+       AbsStatusPeriodic            bool                             `json:"absStatusPeriodic"`
+       RsrpMeasurementPeriodic      bool                             `json:"rsrpMeasurementPeriodic"`
+       CsiPeriodic                  bool                             `json:"csiPeriodic"`
+       PeriodicityMs                enums.ReportingPeriodicity       `json:"periodicityMs"`
+       PeriodicityRsrpMeasurementMs enums.ReportingPeriodicityRSRPMR `json:"periodicityRsrpMeasurementMs"`
+       PeriodicityCsiMs             enums.ReportingPeriodicityCSIR   `json:"periodicityCsiMs"`
+}
diff --git a/RSM/models/rsm_ran_info.go b/RSM/models/rsm_ran_info.go
new file mode 100644 (file)
index 0000000..b67b983
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// Copyright 2019 AT&T Intellectual Property
+// Copyright 2019 Nokia
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package models
+
+import (
+       "rsm/enums"
+)
+
+type RsmRanInfo struct {
+       RanName           string          `json:"ranName"`
+       Enb1MeasurementId int64           `json:"enb1MeasurementId"`
+       Enb2MeasurementId int64           `json:"enb2MeasurementId"`
+       Action            enums.RsmAction `json:"action"`
+       ActionStatus      bool            `json:"actionStatus"`
+}
+
+func NewRsmRanInfo(ranName string, enb1MeasurementId int64, enb2MeasurementId int64, action enums.RsmAction, actionStatus bool) *RsmRanInfo {
+       return &RsmRanInfo{
+               RanName:           ranName,
+               Enb1MeasurementId: enb1MeasurementId,
+               Enb2MeasurementId: enb2MeasurementId,
+               Action:            action,
+               ActionStatus:      actionStatus,
+       }
+}
index abc8f08..7c6fa4e 100644 (file)
@@ -46,8 +46,7 @@ func NewRequestHandlerProvider(logger *logger.Logger, rmrSender *rmrsender.RmrSe
 
 func initRequestHandlerMap(logger *logger.Logger, rmrSender *rmrsender.RmrSender, config *configuration.Configuration, rNibDataService services.RNibDataService) map[IncomingRequest]*httpmsghandlers.RequestHandler {
 
-       return map[IncomingRequest]*httpmsghandlers.RequestHandler{
-       }
+       return map[IncomingRequest]*httpmsghandlers.RequestHandler{}
 }
 
 func (provider RequestHandlerProvider) GetHandler(requestType IncomingRequest) (*httpmsghandlers.RequestHandler, error) {
index d9d4da3..b3d656f 100644 (file)
@@ -51,4 +51,4 @@ func TestNewRequestHandlerProvider_InternalError(t *testing.T) {
        if reflect.TypeOf(actual) != reflect.TypeOf(expected) {
                t.Errorf("Error actual = %v, and Expected = %v.", actual, expected)
        }
-}
\ No newline at end of file
+}
index 46eeff5..ca87c0a 100644 (file)
@@ -24,7 +24,6 @@ import (
        "rsm/converters"
        "rsm/handlers/rmrmsghandlers"
        "rsm/logger"
-       "rsm/managers"
        "rsm/rmrcgo"
        "rsm/services"
        "rsm/services/rmrsender"
@@ -39,16 +38,16 @@ type MessageHandlerProvider struct {
        msgHandlers map[int]rmrmsghandlers.RmrMessageHandler
 }
 
-func NewMessageHandlerProvider(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusInitiateManager *managers.ResourceStatusInitiateManager, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) *MessageHandlerProvider {
+func NewMessageHandlerProvider(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusService *services.ResourceStatusService, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) *MessageHandlerProvider {
        return &MessageHandlerProvider{
-               msgHandlers: initMessageHandlersMap(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, rsConverter, rsFailureConverter),
+               msgHandlers: initMessageHandlersMap(logger, config, rnibDataService, rmrSender, resourceStatusService, rsConverter, rsFailureConverter),
        }
 }
 
-func initMessageHandlersMap(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusInitiateManager *managers.ResourceStatusInitiateManager, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) map[int]rmrmsghandlers.RmrMessageHandler {
+func initMessageHandlersMap(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, resourceStatusService *services.ResourceStatusService, rsConverter converters.ResourceStatusResponseConverter, rsFailureConverter converters.ResourceStatusFailureConverter) map[int]rmrmsghandlers.RmrMessageHandler {
        return map[int]rmrmsghandlers.RmrMessageHandler{
-               rmrcgo.RanConnected:        rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanConnected),
-               rmrcgo.RanRestarted:        rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanRestarted),
+               rmrcgo.RanConnected:        rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanConnected),
+               rmrcgo.RanRestarted:        rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanRestarted),
                rmrcgo.RicResStatusFailure: rmrmsghandlers.NewResourceStatusFailureHandler(logger, rsFailureConverter),
                rmrcgo.RicResStatusResp:    rmrmsghandlers.NewResourceStatusResponseHandler(logger, rsConverter),
        }
@@ -58,7 +57,7 @@ func (provider MessageHandlerProvider) GetMessageHandler(messageType int) (rmrms
        handler, ok := provider.msgHandlers[messageType]
 
        if !ok {
-               msg := fmt.Sprintf("#MessageHandlerProvider.GetMessageHandler - notification handler not found for message %d",messageType )
+               msg := fmt.Sprintf("#MessageHandlerProvider.GetMessageHandler - notification handler not found for message %d", messageType)
                return nil, errors.New(msg)
        }
 
index b4957eb..6a485ed 100644 (file)
@@ -23,7 +23,7 @@ import (
        "rsm/converters"
        "rsm/e2pdus"
        "rsm/handlers/rmrmsghandlers"
-       "rsm/managers"
+       "rsm/services"
        "rsm/tests/testhelper"
        "strings"
        "testing"
@@ -41,18 +41,18 @@ func TestGetNotificationHandlerSuccess(t *testing.T) {
        if err != nil {
                t.Errorf("#... - failed to parse configuration error: %s", err)
        }
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
        unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
        var testCases = []struct {
                msgType int
                handler rmrmsghandlers.RmrMessageHandler
        }{
-               {rmrcgo.RanConnected, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanConnected)},
-               {rmrcgo.RanRestarted, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, config, resourceStatusInitiateManager, RanRestarted)},
+               {rmrcgo.RanConnected, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanConnected)},
+               {rmrcgo.RanRestarted, rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanRestarted)},
        }
 
        for _, tc := range testCases {
-               provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+               provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
                t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
                        handler, err := provider.GetMessageHandler(tc.msgType)
                        if err != nil {
@@ -76,7 +76,7 @@ func TestGetNotificationHandlerFailure(t *testing.T) {
        if err != nil {
                t.Errorf("#... - failed to parse configuration error: %s", err)
        }
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
        unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
 
        var testCases = []struct {
@@ -86,7 +86,7 @@ func TestGetNotificationHandlerFailure(t *testing.T) {
                {9999 /*unknown*/, "notification handler not found"},
        }
        for _, tc := range testCases {
-               provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+               provider := NewMessageHandlerProvider(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
                t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
                        _, err := provider.GetMessageHandler(tc.msgType)
                        if err == nil {
index 7704636..ab7feb8 100644 (file)
@@ -56,7 +56,7 @@ func TestSendRecvMsgSuccess(t *testing.T) {
        log := initLog(t)
 
        initRmr(tests.ReadyIntervalSec, tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
-       if msgr == nil || !msgr.IsReady()  {
+       if msgr == nil || !msgr.IsReady() {
                t.Errorf("#rmr_c_go_api_test.TestSendRecvMsgSuccess - The rmr router is not ready")
        }
 
@@ -77,8 +77,8 @@ func TestSendRecvMsgSuccess(t *testing.T) {
 func TestSendMsgRmrInvalidPortError(t *testing.T) {
        log := initLog(t)
 
-       initRmr(tests.ReadyIntervalSec, "tcp:" + strconv.Itoa(5555), tests.MaxMsgSize, tests.Flags, log)
-       if msgr == nil || !msgr.IsReady()  {
+       initRmr(tests.ReadyIntervalSec, "tcp:"+strconv.Itoa(5555), tests.MaxMsgSize, tests.Flags, log)
+       if msgr == nil || !msgr.IsReady() {
                t.Errorf("#rmr_c_go_api_test.TestSendMsgRmrInvalidPortError - The rmr router is not ready")
        }
 
@@ -96,7 +96,7 @@ func TestSendMsgRmrInvalidMsgNumError(t *testing.T) {
        log := initLog(t)
 
        initRmr(tests.ReadyIntervalSec, tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
-       if msgr == nil || !msgr.IsReady()  {
+       if msgr == nil || !msgr.IsReady() {
                t.Errorf("#rmr_c_go_api_test.TestSendMsgRmrInvalidMsgNumError - The rmr router is not ready")
        }
 
@@ -114,14 +114,14 @@ func TestIsReadySuccess(t *testing.T) {
        log := initLog(t)
 
        initRmr(tests.ReadyIntervalSec, tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
-       if msgr == nil || !msgr.IsReady()  {
+       if msgr == nil || !msgr.IsReady() {
                t.Errorf("#rmr_c_go_api_test.TestIsReadySuccess - The rmr router is not ready")
        }
 
        msgr.Close()
 }
 
-func initRmr(readyIntervalSec int, port string, maxMsgSize int, flags int, log *logger.Logger){
+func initRmr(readyIntervalSec int, port string, maxMsgSize int, flags int, log *logger.Logger) {
        var ctx *Context
        msgr = ctx.Init(readyIntervalSec, port, maxMsgSize, flags, log)
 }
@@ -132,4 +132,4 @@ func initLog(t *testing.T) *logger.Logger {
                t.Errorf("#rmr_c_go_api_test.initLog - failed to initialize logger, error: %s", err)
        }
        return log
-}
\ No newline at end of file
+}
index 777f81a..945c06a 100644 (file)
@@ -30,23 +30,23 @@ import (
 )
 
 func convertToMBuf(m *C.rmr_mbuf_t) *MBuf {
-       payloadArr := C.GoBytes(unsafe.Pointer(m.payload),C.int(m.len))
-       xActionArr := C.GoBytes(unsafe.Pointer(m.xaction),C.int(RMR_MAX_XACTION_LEN))
+       payloadArr := C.GoBytes(unsafe.Pointer(m.payload), C.int(m.len))
+       xActionArr := C.GoBytes(unsafe.Pointer(m.xaction), C.int(RMR_MAX_XACTION_LEN))
 
        // Trim padding (space and 0)
-       xActionStr :=  strings.TrimRight(string(xActionArr),"\040\000")
+       xActionStr := strings.TrimRight(string(xActionArr), "\040\000")
        xActionArr = []byte(xActionStr)
 
        mbuf := &MBuf{
-               MType: int(m.mtype),
-               Len:   int(m.len),
+               MType:   int(m.mtype),
+               Len:     int(m.len),
                Payload: &payloadArr,
                XAction: &xActionArr,
        }
 
        meidBuf := make([]byte, RMR_MAX_MEID_LEN)
        if meidCstr := C.rmr_get_meid(m, (*C.uchar)(unsafe.Pointer(&meidBuf[0]))); meidCstr != nil {
-               mbuf.Meid =     strings.TrimRight(string(meidBuf), "\000")
+               mbuf.Meid = strings.TrimRight(string(meidBuf), "\000")
        }
 
        return mbuf
@@ -54,7 +54,7 @@ func convertToMBuf(m *C.rmr_mbuf_t) *MBuf {
 
 func (ctx *Context) getAllocatedCRmrMBuf(logger *logger.Logger, mBuf *MBuf, maxMsgSize int) (cMBuf *C.rmr_mbuf_t) {
        var xActionBuf [RMR_MAX_XACTION_LEN]byte
-       var meidBuf[RMR_MAX_MEID_LEN]byte
+       var meidBuf [RMR_MAX_MEID_LEN]byte
 
        cMBuf = C.rmr_alloc_msg(ctx.RmrCtx, C.int(maxMsgSize))
        cMBuf.mtype = C.int(mBuf.MType)
@@ -65,13 +65,13 @@ func (ctx *Context) getAllocatedCRmrMBuf(logger *logger.Logger, mBuf *MBuf, maxM
 
        //Add padding
        copy(xActionBuf[:], *mBuf.XAction)
-       for i:= xActionLen; i < RMR_MAX_XACTION_LEN; i++{
+       for i := xActionLen; i < RMR_MAX_XACTION_LEN; i++ {
                xActionBuf[i] = '\040' //space
        }
 
        // Add padding
        copy(meidBuf[:], mBuf.Meid)
-       for i:= len(mBuf.Meid); i < RMR_MAX_MEID_LEN; i++{
+       for i := len(mBuf.Meid); i < RMR_MAX_MEID_LEN; i++ {
                meidBuf[i] = 0
        }
 
@@ -88,7 +88,7 @@ func (ctx *Context) getAllocatedCRmrMBuf(logger *logger.Logger, mBuf *MBuf, maxM
                ctx.Logger.Errorf(
                        "#rmrCgoUtils.getAllocatedCRmrMBuf - Failed to read xAction data to allocated RMR message buffer")
        }
-       len := C.rmr_bytes2meid(cMBuf,  (*C.uchar)(unsafe.Pointer(&meidBuf[0])), C.int(RMR_MAX_MEID_LEN))
+       len := C.rmr_bytes2meid(cMBuf, (*C.uchar)(unsafe.Pointer(&meidBuf[0])), C.int(RMR_MAX_MEID_LEN))
        if int(len) != RMR_MAX_MEID_LEN {
                ctx.Logger.Errorf(
                        "#rmrCgoUtils.getAllocatedCRmrMBuf - Failed to copy meid data to allocated RMR message buffer")
diff --git a/RSM/rsmdb/rsm_reader.go b/RSM/rsmdb/rsm_reader.go
new file mode 100644 (file)
index 0000000..cb47ad2
--- /dev/null
@@ -0,0 +1,94 @@
+//
+// 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 rsmdb
+
+import (
+       "encoding/json"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
+       "reflect"
+       "rsm/enums"
+       "rsm/models"
+)
+
+type rsmReaderInstance struct {
+       sdl common.ISdlInstance
+}
+
+/*
+RNibReader interface allows retrieving data from redis BD by various keys
+*/
+type RsmReader interface {
+       GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error)
+       GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error)
+}
+
+/*
+GetRNibReader returns reference to RNibReader
+*/
+func GetRsmReader(sdl common.ISdlInstance) RsmReader {
+       return &rsmReaderInstance{sdl: sdl}
+}
+
+func (r *rsmReaderInstance) GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error) {
+
+       key, err := common.ValidateAndBuildNodeBNameKey(ranName)
+       if err != nil {
+               return nil, err
+       }
+
+       rsmRanInfo := &models.RsmRanInfo{}
+
+       err = r.getByKeyAndUnmarshal(key, rsmRanInfo)
+
+       if err != nil {
+               return nil, err
+       }
+
+       return rsmRanInfo, nil
+}
+
+// TODO: implement
+func (r *rsmReaderInstance) GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error) {
+       return &models.RsmGeneralConfiguration{
+               EnableResourceStatus:         true,
+               PartialSuccessAllowed:        true,
+               PrbPeriodic:                  true,
+               TnlLoadIndPeriodic:           true,
+               HwLoadIndPeriodic:            true,
+               AbsStatusPeriodic:            true,
+               RsrpMeasurementPeriodic:      true,
+               CsiPeriodic:                  true,
+               PeriodicityMs:                enums.ReportingPeriodicity_one_thousand_ms,
+               PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
+               PeriodicityCsiMs:             enums.ReportingPeriodicityCSIR_ms20,
+       }, nil
+}
+
+func (r *rsmReaderInstance) getByKeyAndUnmarshal(key string, entity interface{}) error {
+       data, err := r.sdl.Get([]string{key})
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+       if data != nil && data[key] != nil {
+               err = json.Unmarshal([]byte(data[key].(string)), entity)
+               if err != nil {
+                       return common.NewInternalError(err)
+               }
+               return nil
+       }
+       return common.NewResourceNotFoundErrorf("#rsmReader.getByKeyAndUnmarshal - entity of type %s not found. Key: %s", reflect.TypeOf(entity).String(), key)
+}
diff --git a/RSM/rsmdb/rsm_writer.go b/RSM/rsmdb/rsm_writer.go
new file mode 100644 (file)
index 0000000..fe7fa56
--- /dev/null
@@ -0,0 +1,67 @@
+//
+// 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 rsmdb
+
+import (
+       "encoding/json"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
+       "rsm/models"
+)
+
+type rsmWriterInstance struct {
+       sdl common.ISdlInstance
+}
+
+/*
+RNibReader interface allows retrieving data from redis BD by various keys
+*/
+type RsmWriter interface {
+       SaveRsmRanInfo(rsmRanInfo *models.RsmRanInfo) error
+}
+
+/*
+GetRNibReader returns reference to RNibReader
+*/
+func GetRsmWriter(sdl common.ISdlInstance) RsmWriter {
+       return &rsmWriterInstance{sdl: sdl}
+}
+
+func (r *rsmWriterInstance) SaveRsmRanInfo(rsmRanInfo *models.RsmRanInfo) error {
+
+       nodebNameKey, err := common.ValidateAndBuildNodeBNameKey(rsmRanInfo.RanName)
+
+       if err != nil {
+               return err
+       }
+
+       data, err := json.Marshal(rsmRanInfo)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       var pairs []interface{}
+       pairs = append(pairs, nodebNameKey, data)
+
+       err = r.sdl.Set(pairs)
+
+       if err != nil {
+               return common.NewInternalError(err)
+       }
+
+       return nil
+}
index e63fd0b..e46e13c 100644 (file)
@@ -18,6 +18,6 @@
 package rsmerrors
 
 type BaseError struct {
-       Code int
+       Code    int
        Message string
 }
index f3903f1..2e396a3 100644 (file)
@@ -22,9 +22,9 @@ type HeaderValidationError struct {
 }
 
 func NewHeaderValidationError() *HeaderValidationError {
-       return &HeaderValidationError {
+       return &HeaderValidationError{
                &BaseError{
-                       Code: 415,
+                       Code:    415,
                        Message: "Header validation error",
                },
        }
index ffa8712..4d85846 100644 (file)
@@ -22,9 +22,9 @@ type InternalError struct {
 }
 
 func NewInternalError() *InternalError {
-       return &InternalError {
+       return &InternalError{
                &BaseError{
-                       Code: 501,
+                       Code:    501,
                        Message: "Internal Server Error. Please try again later",
                },
        }
index 38a9d69..f374578 100644 (file)
@@ -17,7 +17,6 @@
 
 package rsmerrors
 
-
 type InvalidJsonError struct {
        *BaseError
 }
@@ -34,4 +33,3 @@ func NewInvalidJsonError() *InvalidJsonError {
 func (e *InvalidJsonError) Error() string {
        return e.Message
 }
-
index dac4ef9..f52423c 100644 (file)
@@ -22,9 +22,9 @@ type RnibDbError struct {
 }
 
 func NewRnibDbError() *RnibDbError {
-       return &RnibDbError {
+       return &RnibDbError{
                &BaseError{
-                       Code: 500,
+                       Code:    500,
                        Message: "RNIB error",
                },
        }
@@ -32,4 +32,4 @@ func NewRnibDbError() *RnibDbError {
 
 func (e *RnibDbError) Error() string {
        return e.Message
-}
\ No newline at end of file
+}
index 7f5232b..4c30463 100644 (file)
@@ -27,7 +27,7 @@ func NewWrongStateError(activityName string, state string) *WrongStateError {
        return &WrongStateError{
                &BaseError{
                        Code:    403,
-                       Message: fmt.Sprintf("Activity %s rejected. RAN current state %s does not allow its execution ", activityName, state) ,
+                       Message: fmt.Sprintf("Activity %s rejected. RAN current state %s does not allow its execution ", activityName, state),
                },
        }
 }
diff --git a/RSM/services/resource_status_service.go b/RSM/services/resource_status_service.go
new file mode 100644 (file)
index 0000000..e0bc10c
--- /dev/null
@@ -0,0 +1,104 @@
+//
+// 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 services
+
+import (
+       "fmt"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "rsm/e2pdus"
+       "rsm/enums"
+       "rsm/logger"
+       "rsm/models"
+       "rsm/rmrcgo"
+       "rsm/services/rmrsender"
+)
+
+type ResourceStatusService struct {
+       logger    *logger.Logger
+       rmrSender *rmrsender.RmrSender
+}
+
+type IResourceStatusService interface {
+       BuildAndSendInitiateRequest(nodeb *entities.NodebInfo, config *models.RsmGeneralConfiguration, enb1MeasurementId int64) error
+}
+
+func NewResourceStatusService(logger *logger.Logger, rmrSender *rmrsender.RmrSender) *ResourceStatusService {
+       return &ResourceStatusService{
+               logger:    logger,
+               rmrSender: rmrSender,
+       }
+}
+
+func (m *ResourceStatusService) BuildAndSendInitiateRequest(nodeb *entities.NodebInfo, config *models.RsmGeneralConfiguration, enb1MeasurementId int64) error {
+
+       cellIdList, err := m.extractCellIdList(nodeb)
+
+       if err != nil {
+               return err
+       }
+
+       requestParams := buildResourceStatusInitiateRequestParams(config, cellIdList, enb1MeasurementId)
+
+       payload, payloadAsString, err := e2pdus.BuildPackedResourceStatusRequest(enums.Registration_Request_start, requestParams, e2pdus.MaxAsn1PackedBufferSize, e2pdus.MaxAsn1CodecMessageBufferSize, m.logger.DebugEnabled())
+
+       if err != nil {
+               m.logger.Errorf("#ResourceStatusService.BuildAndSendInitiateRequest - RAN name: %s. Failed to build and pack resource status initiate request. error: %s", nodeb.RanName, err)
+               return err
+       }
+
+       m.logger.Debugf("#ResourceStatusService.BuildAndSendInitiateRequest - RAN name: %s. Successfully build packed payload: %s", nodeb.RanName, payloadAsString)
+       rmrMsg := models.NewRmrMessage(rmrcgo.RicResStatusReq, nodeb.RanName, payload)
+
+       return m.rmrSender.Send(rmrMsg)
+}
+
+func (m *ResourceStatusService) extractCellIdList(nodeb *entities.NodebInfo) ([]string, error) {
+
+       enb, ok := nodeb.Configuration.(*entities.NodebInfo_Enb)
+
+       if !ok {
+               m.logger.Errorf("#ResourceStatusService.extractCellIdList - Invalid configuration for RAN %s", nodeb.RanName)
+               return []string{}, fmt.Errorf("Invalid configuration for RAN %s", nodeb.RanName)
+       }
+
+       cells := enb.Enb.ServedCells
+
+       cellIdList := make([]string, len(cells))
+       for index, cellInfo := range cells {
+               cellIdList[index] = cellInfo.CellId
+       }
+
+       return cellIdList, nil
+}
+
+func buildResourceStatusInitiateRequestParams(config *models.RsmGeneralConfiguration, cellIdList []string, enb1MeasurementId int64) *e2pdus.ResourceStatusRequestData {
+       return &e2pdus.ResourceStatusRequestData{
+               CellIdList:                   cellIdList,
+               MeasurementID:                e2pdus.Measurement_ID(enb1MeasurementId),
+               PartialSuccessAllowed:        config.PartialSuccessAllowed,
+               PrbPeriodic:                  config.PrbPeriodic,
+               TnlLoadIndPeriodic:           config.TnlLoadIndPeriodic,
+               HwLoadIndPeriodic:            config.HwLoadIndPeriodic,
+               AbsStatusPeriodic:            config.AbsStatusPeriodic,
+               RsrpMeasurementPeriodic:      config.RsrpMeasurementPeriodic,
+               CsiPeriodic:                  config.CsiPeriodic,
+               PeriodicityMS:                config.PeriodicityMs,
+               PeriodicityRsrpMeasurementMS: config.PeriodicityRsrpMeasurementMs,
+               PeriodicityCsiMS:             config.PeriodicityCsiMs,
+       }
+}
diff --git a/RSM/services/resource_status_service_test.go b/RSM/services/resource_status_service_test.go
new file mode 100644 (file)
index 0000000..12f756a
--- /dev/null
@@ -0,0 +1,174 @@
+//
+// 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 services
+
+import (
+       "fmt"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "github.com/stretchr/testify/assert"
+       "rsm/enums"
+       "rsm/logger"
+       "rsm/mocks"
+       "rsm/models"
+       "rsm/rmrcgo"
+       "rsm/rsmerrors"
+       "rsm/services/rmrsender"
+       "rsm/tests"
+       "testing"
+)
+
+const RanName = "test"
+const NodebOneCellPackedExample = "0009003c00000800270003000000001c00010000260004fe000000001d400d00001f40080002f8290007ab00001e4001000040400100006d4001400091400120"
+const NodebTwoCellsPackedExample = "0009004800000800270003000000001c00010000260004fe000000001d401901001f40080002f8290007ab00001f40080002f8290007ab50001e4001000040400100006d4001400091400120"
+
+func initResourceStatusServiceTest(t *testing.T) (*mocks.RmrMessengerMock, *models.RsmGeneralConfiguration, *ResourceStatusService) {
+       logger, err := logger.InitLogger(logger.DebugLevel)
+       if err != nil {
+               t.Errorf("#... - failed to initialize logger, error: %s", err)
+       }
+
+       rmrMessengerMock := &mocks.RmrMessengerMock{}
+       rmrSender := InitRmrSender(rmrMessengerMock, logger)
+       resourceStatusService := NewResourceStatusService(logger, rmrSender)
+
+       rsmGeneralConfiguration := models.RsmGeneralConfiguration{
+               EnableResourceStatus:         true,
+               PartialSuccessAllowed:        true,
+               PrbPeriodic:                  true,
+               TnlLoadIndPeriodic:           true,
+               HwLoadIndPeriodic:            true,
+               AbsStatusPeriodic:            true,
+               RsrpMeasurementPeriodic:      true,
+               CsiPeriodic:                  true,
+               PeriodicityMs:                enums.ReportingPeriodicity_one_thousand_ms,
+               PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
+               PeriodicityCsiMs:             enums.ReportingPeriodicityCSIR_ms20,
+       }
+
+       return rmrMessengerMock, &rsmGeneralConfiguration, resourceStatusService
+}
+
+func TestOneCellSuccess(t *testing.T) {
+       cellId := "02f829:0007ab00"
+       rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t)
+
+       xaction := []byte(RanName)
+       nodebInfo := &entities.NodebInfo{
+               RanName:          RanName,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+               Configuration: &entities.NodebInfo_Enb{
+                       Enb: &entities.Enb{
+                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId}},
+                       },
+               },
+       }
+
+       var expectedPayload []byte
+       _, _ = fmt.Sscanf(NodebOneCellPackedExample, "%x", &expectedPayload)
+       var err error
+       expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction)
+       rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, err)
+       err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId)
+       assert.Nil(t, err)
+       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf)
+}
+
+func TestOneCellSendFailure(t *testing.T) {
+       cellId := "02f829:0007ab00"
+       rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t)
+
+       xaction := []byte(RanName)
+       var err error
+       nodebInfo := &entities.NodebInfo{
+               RanName:          RanName,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+               Configuration: &entities.NodebInfo_Enb{
+                       Enb: &entities.Enb{
+                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId}},
+                       },
+               },
+       }
+
+       var expectedPayload []byte
+       _, _ = fmt.Sscanf(NodebOneCellPackedExample, "%x", &expectedPayload)
+       expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction)
+       rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, rsmerrors.NewRmrError())
+       err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, 1)
+       assert.NotNil(t, err)
+       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf)
+}
+
+func TestTwoCellsSuccess(t *testing.T) {
+       cellId1 := "02f829:0007ab00"
+       cellId2 := "02f829:0007ab50"
+       rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t)
+       xaction := []byte(RanName)
+       nodebInfo := &entities.NodebInfo{
+               RanName:          RanName,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+               Configuration: &entities.NodebInfo_Enb{
+                       Enb: &entities.Enb{
+                               ServedCells: []*entities.ServedCellInfo{{CellId: cellId1}, {CellId: cellId2}},
+                       },
+               },
+       }
+
+       var expectedPayload []byte
+       _, _ = fmt.Sscanf(NodebTwoCellsPackedExample, "%x", &expectedPayload)
+       expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction)
+       var err error
+       rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, err)
+       err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId)
+       assert.Nil(t, err)
+       rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf)
+}
+
+func TestNodebConfigurationFailure(t *testing.T) {
+       rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t)
+       nodebInfo := &entities.NodebInfo{
+               RanName:          RanName,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+       }
+
+       err := resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId)
+       assert.NotNil(t, err)
+       rmrMessengerMock.AssertNotCalled(t, "SendMsg")
+}
+
+func TestPackFailure(t *testing.T) {
+       rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t)
+       nodebInfo := &entities.NodebInfo{
+               RanName:          RanName,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+               Configuration: &entities.NodebInfo_Enb{
+                       Enb: &entities.Enb{
+                               ServedCells: []*entities.ServedCellInfo{{CellId: ""}},
+                       },
+               },
+       }
+
+       err := resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId)
+       assert.NotNil(t, err)
+       rmrMessengerMock.AssertNotCalled(t, "SendMsg")
+}
+
+func InitRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {
+       rmrMessenger := rmrcgo.RmrMessenger(rmrMessengerMock)
+       rmrMessengerMock.On("Init", tests.GetPort(), tests.MaxMsgSize, tests.Flags, log).Return(&rmrMessenger)
+       return rmrsender.NewRmrSender(log, rmrMessenger)
+}
index 0d44821..62a4ab5 100644 (file)
@@ -51,4 +51,4 @@ func (r *RmrReceiver) ListenAndHandle() {
                // TODO: go routine?
                r.nManager.HandleMessage(mbuf)
        }
-}
\ No newline at end of file
+}
index 881d2fe..b47ffa3 100644 (file)
@@ -23,10 +23,10 @@ import (
        "rsm/converters"
        "rsm/e2pdus"
        "rsm/logger"
-       "rsm/managers"
        "rsm/managers/rmrmanagers"
        "rsm/mocks"
        "rsm/rmrcgo"
+       "rsm/services"
        "rsm/tests"
        "rsm/tests/testhelper"
        "testing"
@@ -57,11 +57,11 @@ func initRmrReceiver(t *testing.T) *RmrReceiver {
        if err != nil {
                t.Errorf("#... - failed to parse configuration error: %s", err)
        }
-       resourceStatusInitiateManager := managers.NewResourceStatusInitiateManager(logger, rnibDataService, rmrSender)
+       resourceStatusService := services.NewResourceStatusService(logger, rmrSender)
 
        rmrMessenger := initRmrMessenger(logger)
        unpacker := converters.NewX2apPduUnpacker(logger, e2pdus.MaxAsn1CodecMessageBufferSize)
-       manager := rmrmanagers.NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusInitiateManager,converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
+       manager := rmrmanagers.NewRmrMessageManager(logger, config, rnibDataService, rmrSender, resourceStatusService, converters.NewResourceStatusResponseConverter(unpacker), converters.NewResourceStatusFailureConverter(unpacker))
 
        return NewRmrReceiver(logger, rmrMessenger, manager)
 }
index 31fa092..cb49c6d 100644 (file)
@@ -48,4 +48,4 @@ func (r *RmrSender) Send(rmrMessage *models.RmrMessage) error {
 
        r.logger.Infof("#RmrSender.Send - RAN name: %s , Message type: %d - Successfully sent RMR message", rmrMessage.RanName, rmrMessage.MsgType)
        return nil
-}
\ No newline at end of file
+}
index 8b5849e..fa124b4 100644 (file)
@@ -74,4 +74,4 @@ func InitLog(t *testing.T) *logger.Logger {
                t.Errorf("#tests.initLog - failed to initialize logger, error: %s", err)
        }
        return log
-}
\ No newline at end of file
+}
index f2db2a8..95fb1a9 100644 (file)
@@ -24,31 +24,77 @@ import (
        "net"
        "rsm/configuration"
        "rsm/logger"
+       "rsm/models"
+       "rsm/rsmdb"
        "time"
 )
 
 type RNibDataService interface {
+       GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error)
+       GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error)
+       SaveRsmRanInfo(rsmData *models.RsmRanInfo) error
        GetNodeb(ranName string) (*entities.NodebInfo, error)
        GetListNodebIds() ([]*entities.NbIdentity, error)
        PingRnib() bool
 }
 
 type rNibDataService struct {
-       logger             *logger.Logger
-       rnibReader         reader.RNibReader
-       maxAttempts        int
-       retryInterval      time.Duration
+       logger        *logger.Logger
+       rnibReader    reader.RNibReader
+       rsmReader     rsmdb.RsmReader
+       rsmWriter     rsmdb.RsmWriter
+       maxAttempts   int
+       retryInterval time.Duration
 }
 
-func NewRnibDataService(logger *logger.Logger, config *configuration.Configuration, rnibReader reader.RNibReader) *rNibDataService {
+func NewRnibDataService(logger *logger.Logger, config *configuration.Configuration, rnibReader reader.RNibReader, rsmReader rsmdb.RsmReader, rsmWriter rsmdb.RsmWriter) *rNibDataService {
        return &rNibDataService{
-               logger:             logger,
-               rnibReader:         rnibReader,
-               maxAttempts:        config.Rnib.MaxRnibConnectionAttempts,
-               retryInterval:      time.Duration(config.Rnib.RnibRetryIntervalMs) * time.Millisecond,
+               logger:        logger,
+               rnibReader:    rnibReader,
+               rsmReader:     rsmReader,
+               rsmWriter:     rsmWriter,
+               maxAttempts:   config.Rnib.MaxRnibConnectionAttempts,
+               retryInterval: time.Duration(config.Rnib.RnibRetryIntervalMs) * time.Millisecond,
        }
 }
 
+func (w *rNibDataService) GetRsmGeneralConfiguration() (*models.RsmGeneralConfiguration, error) {
+       w.logger.Infof("#RnibDataService.GetRsmGeneralConfiguration")
+
+       var rsmGeneralConfiguration *models.RsmGeneralConfiguration = nil
+
+       err := w.retry("GetRsmGeneralConfiguration", func() (err error) {
+               rsmGeneralConfiguration, err = w.rsmReader.GetRsmGeneralConfiguration()
+               return
+       })
+
+       return rsmGeneralConfiguration, err
+}
+
+func (w *rNibDataService) GetRsmRanInfo(ranName string) (*models.RsmRanInfo, error) {
+       w.logger.Infof("#RnibDataService.GetRsmRanInfo - RAN name: %s", ranName)
+
+       var rsmData *models.RsmRanInfo = nil
+
+       err := w.retry("GetRsmRanInfo", func() (err error) {
+               rsmData, err = w.rsmReader.GetRsmRanInfo(ranName)
+               return
+       })
+
+       return rsmData, err
+}
+
+func (w *rNibDataService) SaveRsmRanInfo(rsmRanInfo *models.RsmRanInfo) error {
+       w.logger.Infof("#RnibDataService.SaveRsmRanInfo - RAN name: %s", rsmRanInfo.RanName)
+
+       err := w.retry("SaveRsmRanInfo", func() (err error) {
+               err = w.rsmWriter.SaveRsmRanInfo(rsmRanInfo)
+               return
+       })
+
+       return err
+}
+
 func (w *rNibDataService) GetNodeb(ranName string) (*entities.NodebInfo, error) {
        w.logger.Infof("#RnibDataService.GetNodeb - ranName: %s", ranName)
 
index 2dbea7c..dfc0e18 100644 (file)
@@ -46,12 +46,14 @@ func setupRnibDataServiceTestWithMaxAttempts(t *testing.T, maxAttempts int) (*rN
        }
        config.Rnib.MaxRnibConnectionAttempts = maxAttempts
 
-       readerMock := &mocks.RnibReaderMock{}
+       rnibReaderMock := &mocks.RnibReaderMock{}
+       rsmReaderMock := &mocks.RsmReaderMock{}
+       rsmWriterMock := &mocks.RsmWriterMock{}
 
-       rnibDataService := NewRnibDataService(logger, config, readerMock)
+       rnibDataService := NewRnibDataService(logger, config, rnibReaderMock, rsmReaderMock, rsmWriterMock)
        assert.NotNil(t, rnibDataService)
 
-       return rnibDataService, readerMock
+       return rnibDataService, rnibReaderMock
 }
 
 func TestSuccessfulGetNodeb(t *testing.T) {
@@ -77,7 +79,7 @@ func TestConnFailureGetNodeb(t *testing.T) {
 
        res, err := rnibDataService.GetNodeb(invName)
        readerMock.AssertNumberOfCalls(t, "GetNodeb", 3)
-       assert.True(t, strings.Contains(err.Error(), "connection error"))
+       assert.True(t, strings.Contains(err.Error(), "connection error"))
        assert.Equal(t, nodeb, res)
 }
 
@@ -102,7 +104,7 @@ func TestConnFailureGetNodebIdList(t *testing.T) {
 
        res, err := rnibDataService.GetListNodebIds()
        readerMock.AssertNumberOfCalls(t, "GetListNodebIds", 3)
-       assert.True(t, strings.Contains(err.Error(), "connection error"))
+       assert.True(t, strings.Contains(err.Error(), "connection error"))
        assert.Equal(t, nodeIds, res)
 }
 
@@ -118,12 +120,12 @@ func TestConnFailureTwiceGetNodebIdList(t *testing.T) {
 
        res, err := rnibDataService.GetListNodebIds()
        readerMock.AssertNumberOfCalls(t, "GetListNodebIds", 3)
-       assert.True(t, strings.Contains(err.Error(), "connection error"))
+       assert.True(t, strings.Contains(err.Error(), "connection error"))
        assert.Equal(t, nodeIds, res)
 
        res2, err := rnibDataService.GetNodeb(invName)
        readerMock.AssertNumberOfCalls(t, "GetNodeb", 3)
-       assert.True(t, strings.Contains(err.Error(), "connection error"))
+       assert.True(t, strings.Contains(err.Error(), "connection error"))
        assert.Equal(t, nodeb, res2)
 }
 
@@ -136,7 +138,7 @@ func TestConnFailureWithAnotherConfig(t *testing.T) {
 
        res, err := rnibDataService.GetListNodebIds()
        readerMock.AssertNumberOfCalls(t, "GetListNodebIds", 5)
-       assert.True(t, strings.Contains(err.Error(), "connection error"))
+       assert.True(t, strings.Contains(err.Error(), "connection error"))
        assert.Equal(t, nodeIds, res)
 }
 
index e4a6ae4..eceea09 100644 (file)
@@ -66,9 +66,10 @@ import (
        "fmt"
        "unsafe"
 )
+
 const PackedBufferSize = 4096
 
-func BuildPackedX2ResetResponse()([]byte, error){
+func BuildPackedX2ResetResponse() ([]byte, error) {
        payloadSize := C.ulong(PackedBufferSize)
        packedBuffer := [PackedBufferSize]C.uchar{}
        errorBuffer := [PackedBufferSize]C.char{}
index d14b389..fef6a37 100644 (file)
@@ -49,9 +49,12 @@ func InitTestCase(t *testing.T) (services.RNibDataService, *rmrsender.RmrSender,
                t.Errorf("#tests.InitTestCase - failed to parse configuration, error: %s", err)
        }
 
-       readerMock := &mocks.RnibReaderMock{}
+       rnibReaderMock := &mocks.RnibReaderMock{}
+
+       rsmReaderMock := &mocks.RsmReaderMock{}
+       rsmWriterMock := &mocks.RsmWriterMock{}
 
        rmrSender := InitRmrSender(&mocks.RmrMessengerMock{}, logger)
-       rnibDataService := services.NewRnibDataService(logger, config, readerMock)
+       rnibDataService := services.NewRnibDataService(logger, config, rnibReaderMock, rsmReaderMock, rsmWriterMock)
        return rnibDataService, rmrSender, logger
 }