.vscode/launch.json
*.o
*.a
+RSM/RSM
+coverage.txt
RSM/asn1codec/e2ap_engine/converter-example
RSM/asn1codec/tests/
RSM/cp.out
"rsm/e2pdus"
"rsm/httpserver"
"rsm/logger"
- "rsm/managers"
"rsm/managers/rmrmanagers"
"rsm/rmrcgo"
+ "rsm/rsmdb"
"rsm/services"
"rsm/services/rmrreceiver"
"rsm/services/rmrsender"
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()
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()
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()
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()
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)
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)
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)
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)
type IController interface {
}
+
/*
import (
"encoding/json"
requestPrettyPrint := strings.Replace(string(dump), "\r\n", " ", -1)
return strings.Replace(requestPrettyPrint, "\n", "", -1)
}
-*/
\ No newline at end of file
+*/
controller.handleErrorResponse(fmt.Errorf("ErrorError"), writer)
assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
}
-*/
\ No newline at end of file
+*/
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) {
maxFailedMeasObjects = 32
)
-type IResourceStatusResponseConverter interface {
+type IResourceStatusResponseConverter interface {
Convert(packedBuf []byte) (*models.ResourceStatusResponse, error)
UnpackX2apPduAsString(packedBuf []byte, maxMessageBufferSize int) (string, error)
}
X2apPduUnpacker
}
-
func NewResourceStatusResponseConverter(unpacker X2apPduUnpacker) ResourceStatusResponseConverter {
return ResourceStatusResponseConverter{unpacker}
}
return fmt.Sprintf("%x:%x", plmnId, eutranCellIdentifier)
}
-
-
func convertMeasurementFailureCauses(measurementFailureCause_List *C.MeasurementFailureCause_List_t, measurementInitiationResult *models.MeasurementInitiationResult) error {
var MeasurementFailureCauses []*models.MeasurementFailureCause
return nil
}
-
func convertMeasurementInitiationResult(measurementInitiationResult_List *C.MeasurementInitiationResult_List_t) ([]*models.MeasurementInitiationResult, error) {
var measurementInitiationResults []*models.MeasurementInitiationResult
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"
)
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{logger: logger, maxMessageBufferSize: maxMessageBufferSize}
}
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
C.asn1_pdu_printer(pdu, C.size_t(len(buf)), &buf[0])
return C.GoString(&buf[0]), nil
}
-
-
-
* limitations under the License.
*
*******************************************************************************/
+
package e2pdus
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 {
}
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",
--- /dev/null
+//
+// 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
+//
+// 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 (
_, ok := messageDirectionEnumName[int32(md)]
if !ok {
- return nil,&json.UnsupportedValueError{}
+ return nil, &json.UnsupportedValueError{}
}
- v:= int32(md)
+ v := int32(md)
return json.Marshal(v)
}
+//
+// 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
+//
+// 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 (
return keys
}
-
+//
+// 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"
+//
+// 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 (
}
return keys
-}
\ No newline at end of file
+}
--- /dev/null
+//
+// 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"
+)
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
+ }
}
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)
}
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 {
}
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
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)
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)
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)
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)
type RmrMessageHandler interface {
Handle(*models.RmrRequest)
-}
\ No newline at end of file
+}
t.Fatalf("failed to perform GET to http://localhost:11223/v1/health")
}
assert.Equal(t, 200, resp.StatusCode)
-}
\ No newline at end of file
+}
)
type Logger struct {
- Logger *zap.Logger
+ Logger *zap.Logger
}
// Copied from zap logger
_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) {
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()))
}
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()))
}
millis := int64(nanos) / int64(time.Millisecond)
enc.AppendInt64(millis)
}
-
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
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
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)
}
-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) {
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 {
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)
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
+}
+++ /dev/null
-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)
- }
-}
+++ /dev/null
-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
-}
"rsm/configuration"
"rsm/converters"
"rsm/logger"
- "rsm/managers"
"rsm/models"
"rsm/providers/rmrmsghandlerprovider"
"rsm/rmrcgo"
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,
}
}
"rsm/configuration"
"rsm/converters"
"rsm/e2pdus"
- "rsm/managers"
"rsm/rmrcgo"
+ "rsm/services"
"rsm/tests/testhelper"
"testing"
)
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")
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")
+//
+// 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 (
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)
}
-
+//
+// 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 (
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)
}
-
--- /dev/null
+//
+// 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)
+}
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()
+}
+//
+// 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 (
--- /dev/null
+//
+// 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)
+}
--- /dev/null
+//
+// 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)
+}
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)
}
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)
}
package models
type Request interface {
-
}
+//
+// 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 {
+//
+// 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 (
MeasurementFailureCauses []*MeasurementFailureCause
}
-func (r MeasurementInitiationResult)String() string {
+func (r MeasurementInitiationResult) String() string {
var strBuilder strings.Builder
strBuilder.WriteString("[ ")
for _, cause := range r.MeasurementFailureCauses {
MeasurementInitiationResults []*MeasurementInitiationResult
}
-func (r ResourceStatusResponse)String() string{
+func (r ResourceStatusResponse) String() string {
var strBuilder strings.Builder
strBuilder.WriteString("[ ")
for _, result := range r.MeasurementInitiationResults {
}
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
+}
type IResponse interface {
Marshal() (string, error)
-}
\ No newline at end of file
+}
func (response RmrMessage) GetMessageAsBytes(logger *logger.Logger) []byte {
return response.Payload
-}
\ No newline at end of file
+}
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 {
payload,
startTime,
}
-}
\ No newline at end of file
+}
--- /dev/null
+//
+// 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"`
+}
--- /dev/null
+//
+// 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,
+ }
+}
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) {
if reflect.TypeOf(actual) != reflect.TypeOf(expected) {
t.Errorf("Error actual = %v, and Expected = %v.", actual, expected)
}
-}
\ No newline at end of file
+}
"rsm/converters"
"rsm/handlers/rmrmsghandlers"
"rsm/logger"
- "rsm/managers"
"rsm/rmrcgo"
"rsm/services"
"rsm/services/rmrsender"
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),
}
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)
}
"rsm/converters"
"rsm/e2pdus"
"rsm/handlers/rmrmsghandlers"
- "rsm/managers"
+ "rsm/services"
"rsm/tests/testhelper"
"strings"
"testing"
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 {
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 {
{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 {
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")
}
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")
}
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")
}
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)
}
t.Errorf("#rmr_c_go_api_test.initLog - failed to initialize logger, error: %s", err)
}
return log
-}
\ No newline at end of file
+}
)
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
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)
//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
}
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")
--- /dev/null
+//
+// 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)
+}
--- /dev/null
+//
+// 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
+}
package rsmerrors
type BaseError struct {
- Code int
+ Code int
Message string
}
}
func NewHeaderValidationError() *HeaderValidationError {
- return &HeaderValidationError {
+ return &HeaderValidationError{
&BaseError{
- Code: 415,
+ Code: 415,
Message: "Header validation error",
},
}
}
func NewInternalError() *InternalError {
- return &InternalError {
+ return &InternalError{
&BaseError{
- Code: 501,
+ Code: 501,
Message: "Internal Server Error. Please try again later",
},
}
package rsmerrors
-
type InvalidJsonError struct {
*BaseError
}
func (e *InvalidJsonError) Error() string {
return e.Message
}
-
}
func NewRnibDbError() *RnibDbError {
- return &RnibDbError {
+ return &RnibDbError{
&BaseError{
- Code: 500,
+ Code: 500,
Message: "RNIB error",
},
}
func (e *RnibDbError) Error() string {
return e.Message
-}
\ No newline at end of file
+}
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),
},
}
}
--- /dev/null
+//
+// 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,
+ }
+}
--- /dev/null
+//
+// 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)
+}
// TODO: go routine?
r.nManager.HandleMessage(mbuf)
}
-}
\ No newline at end of file
+}
"rsm/converters"
"rsm/e2pdus"
"rsm/logger"
- "rsm/managers"
"rsm/managers/rmrmanagers"
"rsm/mocks"
"rsm/rmrcgo"
+ "rsm/services"
"rsm/tests"
"rsm/tests/testhelper"
"testing"
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)
}
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
+}
t.Errorf("#tests.initLog - failed to initialize logger, error: %s", err)
}
return log
-}
\ No newline at end of file
+}
"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)
}
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) {
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)
}
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)
}
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)
}
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)
}
"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{}
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
}