blob: 2ee7584bb71bf2a76384dd4663a1f27250d3e25d [file] [log] [blame]
//
// 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 reader
import (
"encoding/json"
"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/golang/protobuf/proto"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
var namespace = "namespace"
func TestInit(t *testing.T) {
readerPool = nil
Init("", 1)
assert.NotNil(t, readerPool)
assert.NotNil(t, readerPool.New)
assert.NotNil(t, readerPool.Destroy)
available, created := readerPool.Stats()
assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
}
func TestInitPool(t *testing.T) {
readerPool = nil
sdlInstanceMock := new(MockSdlInstance)
initPool(1, func() interface{} {
sdlI := common.ISdlInstance(sdlInstanceMock)
return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
},
func(obj interface{}) {
},
)
assert.NotNil(t, readerPool)
assert.NotNil(t, readerPool.New)
assert.NotNil(t, readerPool.Destroy)
available, created := readerPool.Stats()
assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
}
func initSdlInstanceMock(namespace string, poolSize int) *MockSdlInstance {
sdlInstanceMock := new(MockSdlInstance)
initPool(poolSize, func() interface{} {
sdlI := common.ISdlInstance(sdlInstanceMock)
return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
},
func(obj interface{}) {
},
)
return sdlInstanceMock
}
func TestGetNodeB(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
enb := entities.Enb{}
cell := entities.ServedCellInfo{Tac: "tac"}
enb.ServedCells = []*entities.ServedCellInfo{&cell}
nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.TestGetNb - Failed to marshal ENB instance. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeB - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetNodeb(name)
assert.Nil(t, er)
assert.Equal(t, getNb.Ip, nb.Ip)
assert.Equal(t, getNb.Port, nb.Port)
assert.Equal(t, getNb.ConnectionStatus, nb.ConnectionStatus)
assert.Len(t, getNb.GetEnb().GetServedCells(), 1)
assert.Equal(t, getNb.GetEnb().GetServedCells()[0].Tac, nb.GetEnb().GetServedCells()[0].Tac)
}
func TestGetNodeBNotFoundFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetNodeb(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.NodebInfo not found. Key: RAN:name", er.Error())
}
func TestGetNodeBUnmarshalFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBUnmarshalFailure - failed to validate key parameter")
}
ret[redisKey] = "data"
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetNodeb(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetNodeBSdlgoFailure(t *testing.T) {
name := "name"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBSdlgoFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetNodeb(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetNodeBCellsListEnb(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
enb := entities.Enb{}
cell := entities.ServedCellInfo{Tac: "tac"}
enb.ServedCells = []*entities.ServedCellInfo{&cell}
nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.GetNodeBCellsList - Failed to marshal ENB instance. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListEnb - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
cells, er := w.GetCellList(name)
assert.Nil(t, er)
assert.NotNil(t, cells)
assert.Len(t, cells.GetServedCellInfos().GetServedCells(), 1)
retCell := cells.GetServedCellInfos().GetServedCells()[0]
assert.Equal(t, retCell.Tac, "tac")
}
func TestGetNodeBCellsListGnb(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
nb.NodeType = entities.Node_GNB
gnb := entities.Gnb{}
cell := entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{NrPci: 10}}
gnb.ServedNrCells = []*entities.ServedNRCell{&cell}
nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.GetNodeBCellsList - Failed to marshal GNB instance. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListGnb - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
cells, er := w.GetCellList(name)
assert.Nil(t, er)
assert.NotNil(t, cells)
assert.Len(t, cells.GetServedNrCells().GetServedCells(), 1)
retCell := cells.GetServedNrCells().GetServedCells()[0]
assert.Equal(t, retCell.GetServedNrCellInformation().GetNrPci(), uint32(10))
}
func TestGetNodeBCellsListNodeUnmarshalFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListNodeUnmarshalFailure - failed to validate key parameter")
}
ret[redisKey] = "data"
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
cells, er := w.GetCellList(name)
assert.NotNil(t, er)
assert.Nil(t, cells)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetNodeBCellsListNodeNotFoundFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListNodeNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
cells, er := w.GetCellList(name)
assert.NotNil(t, er)
assert.Nil(t, cells)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.NodebInfo not found. Key: RAN:name", er.Error())
}
func TestGetNodeBCellsListNotFoundFailureEnb(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
enb := entities.Enb{}
nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.TestGetNbCellsListNotFoundFailure - Failed to marshal ENB instance. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListNotFoundFailureEnb - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
_, er := w.GetCellList(name)
assert.NotNil(t, er)
assert.EqualValues(t, "#rNibReader.GetCellList - served cells not found. Responding node RAN name: name.", er.Error())
}
func TestGetNodeBCellsListNotFoundFailureGnb(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
gnb := entities.Gnb{}
nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListNotFoundFailureGnb - Failed to marshal ENB instance. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetNodeBCellsListNotFoundFailureGnb - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
_, er := w.GetCellList(name)
assert.NotNil(t, er)
assert.EqualValues(t, "#rNibReader.GetCellList - served cells not found. Responding node RAN name: name.", er.Error())
}
func TestCloseOnClosedPoolFailure(t *testing.T) {
readerPool = nil
instanceMock := initSdlInstanceMock(namespace, 1)
w1 := GetRNibReader()
_, err := w1.GetNodeb("")
if err == nil{
t.Errorf("#rNibReader_test.TestCloseOnClosedPoolFailure - failed to validate key parameter")
}
readerPool.Put(w1)
available, created := readerPool.Stats()
assert.Equal(t, 1, available, "number of available objects in the readerPool should be 1")
assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
var e error
instanceMock.On("Close").Return(e)
Close()
assert.Panics(t, func() { Close() })
}
func TestCloseFailure(t *testing.T) {
readerPool = nil
instanceMock := initSdlInstanceMock(namespace, 2)
w1 := GetRNibReader()
_, err := w1.GetNodeb("")
if err == nil{
t.Errorf("#rNibReader_test.TestCloseFailure - failed to validate key parameter")
}
available, created := readerPool.Stats()
assert.Equal(t, 1, available, "number of available objects in the readerPool should be 2")
assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
e := errors.New("expected error")
instanceMock.On("Close").Return(e)
Close()
available, created = readerPool.Stats()
assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
}
func TestGetListGnbIdsUnmarshalFailure(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{"data"}, e)
ids, er := w.GetListGnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.Equal(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetListGnbIdsSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var data []string
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return(data, e)
ids, er := w.GetListGnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetListNodesIdsGnbSdlgoFailure(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var nilError error
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListNodesIdsGnbSdlgoFailure - Failed to marshal nodeb identity entity. Error: %v", err)
}
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{string(data)}, nilError)
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
expectedError := errors.New(errMsg)
var nilData []string
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return(nilData, expectedError)
ids, er := w.GetListNodebIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetListNodesIdsEnbSdlgoFailure(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var nilError error
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListNodesIdsEnbSdlgoFailure - Failed to marshal nodeb identity entity. Error: %v", err)
}
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{string(data)}, nilError)
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
expectedError := errors.New(errMsg)
var nilData []string
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return(nilData, expectedError)
ids, er := w.GetListNodebIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetListNodesIdsSuccess(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var nilError error
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListNodesIdsSuccess - Failed to marshal nodeb identity entity. Error: %v", err)
}
name1 := "name1"
plmnId1 := "02f845"
nbId1 := "4a952a75"
nbIdentity1 := &entities.NbIdentity{InventoryName: name1, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId1, NbId: nbId1}}
data1, err := proto.Marshal(nbIdentity1)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListNodesIdsSuccess - Failed to marshal nodeb identity entity. Error: %v", err)
}
name2 := "name2"
nbIdentity2 := &entities.NbIdentity{InventoryName: name2}
data2, err := proto.Marshal(nbIdentity2)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListNodesIdsSuccess - Failed to marshal nodeb identity entity. Error: %v", err)
}
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{string(data)}, nilError)
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{string(data1)}, nilError)
sdlInstanceMock.On("GetMembers", entities.Node_UNKNOWN.String()).Return([]string{string(data2)}, nilError)
ids, er := w.GetListNodebIds()
assert.Nil(t, er)
assert.NotNil(t, ids)
assert.Len(t, ids, 3)
}
func TestGetListEnbIdsUnmarshalFailure(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{"data"}, e)
ids, er := w.GetListEnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.Equal(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetListEnbIdsOneId(t *testing.T) {
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var e error
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListEnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{string(data)}, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, ids, 1)
assert.Equal(t, (ids)[0].GetInventoryName(), name)
assert.Equal(t, (ids)[0].GetGlobalNbId().GetPlmnId(), nbIdentity.GetGlobalNbId().GetPlmnId())
assert.Equal(t, (ids)[0].GetGlobalNbId().GetNbId(), nbIdentity.GetGlobalNbId().GetNbId())
}
func TestGetListEnbIdsNoIds(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return([]string{}, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, ids, 0)
}
func TestGetListEnbIds(t *testing.T) {
name := "name"
plmnId := 0x02f829
nbId := 0x4a952a0a
listSize := 3
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
idsData := make([]string, listSize)
idsEntities := make([]*entities.NbIdentity, listSize)
for i := 0; i < listSize; i++ {
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: string(plmnId + i), NbId: string(nbId + i)}}
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListEnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
idsData[i] = string(data)
idsEntities[i] = nbIdentity
}
var e error
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return(idsData, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, ids, listSize)
for i, id := range ids {
assert.Equal(t, id.GetInventoryName(), name)
assert.Equal(t, id.GetGlobalNbId().GetPlmnId(), idsEntities[i].GetGlobalNbId().GetPlmnId())
assert.Equal(t, id.GetGlobalNbId().GetNbId(), idsEntities[i].GetGlobalNbId().GetNbId())
}
}
func TestGetListGnbIdsOneId(t *testing.T) {
name := "name"
plmnId := "02f829"
nbId := "4a952a0a"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
var e error
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListGnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{string(data)}, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, ids, 1)
assert.Equal(t, (ids)[0].GetInventoryName(), name)
assert.Equal(t, (ids)[0].GetGlobalNbId().GetPlmnId(), nbIdentity.GetGlobalNbId().GetPlmnId())
assert.Equal(t, (ids)[0].GetGlobalNbId().GetNbId(), nbIdentity.GetGlobalNbId().GetNbId())
}
func TestGetListGnbIdsNoIds(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return([]string{}, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, ids, 0)
}
func TestGetListGnbIds(t *testing.T) {
name := "name"
plmnId := 0x02f829
nbId := 0x4a952a0a
listSize := 3
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
idsData := make([]string, listSize)
idsEntities := make([]*entities.NbIdentity, listSize)
for i := 0; i < listSize; i++ {
nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: string(plmnId + i), NbId: string(nbId + i)}}
data, err := proto.Marshal(nbIdentity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListGnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
idsData[i] = string(data)
idsEntities[i] = nbIdentity
}
var e error
sdlInstanceMock.On("GetMembers", entities.Node_GNB.String()).Return(idsData, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, ids, listSize)
for i, id := range ids {
assert.Equal(t, id.GetInventoryName(), name)
assert.Equal(t, id.GetGlobalNbId().GetPlmnId(), idsEntities[i].GetGlobalNbId().GetPlmnId())
assert.Equal(t, id.GetGlobalNbId().GetNbId(), idsEntities[i].GetGlobalNbId().GetNbId())
}
}
func TestGetListEnbIdsSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var data []string
sdlInstanceMock.On("GetMembers", entities.Node_ENB.String()).Return(data, e)
ids, er := w.GetListEnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetCountGnbListOneId(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(1, e)
count, er := w.GetCountGnbList()
assert.Nil(t, er)
assert.Equal(t, count, 1)
}
func TestGetCountGnbList(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(3, e)
count, er := w.GetCountGnbList()
assert.Nil(t, er)
assert.Equal(t, count, 3)
}
func TestGetCountGnbListSdlgoFailure(t *testing.T) {
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var count int
sdlInstanceMock.On("GroupSize", entities.Node_GNB.String()).Return(count, e)
count, er := w.GetCountGnbList()
assert.NotNil(t, er)
assert.Equal(t, 0, count)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetCell(t *testing.T) {
name := "name"
var pci uint32 = 10
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
cellData, err := proto.Marshal(&cellEntity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetCell - Failed to marshal Cell entity. Error: %v", err)
}
var e error
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCell - failed to validate key parameter")
}
ret := map[string]interface{}{key: string(cellData)}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCell(name, pci)
assert.Nil(t, er)
assert.NotNil(t, cell)
assert.Equal(t, cell.Type, entities.Cell_LTE_CELL)
assert.NotNil(t, cell.GetServedCellInfo())
assert.Equal(t, cell.GetServedCellInfo().GetPci(), pci)
}
func TestGetCellNotFoundFailure(t *testing.T) {
name := "name"
var pci uint32
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCell(name, pci)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.Cell not found. Key: PCI:name:00", er.Error())
}
func TestGetCellUnmarshalFailure(t *testing.T) {
name := "name"
var pci uint32
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
ret := make(map[string]interface{}, 1)
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellUnmarshalFailure - failed to validate key parameter")
}
ret[key] = "data"
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCell(name, pci)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetCellSdlgoFailure(t *testing.T) {
name := "name"
var pci uint32
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellSdlgoFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCell(name, pci)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetNodebById(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
nb := entities.NodebInfo{NodeType: entities.Node_ENB}
nb.ConnectionStatus = 1
nb.Ip = "localhost"
nb.Port = 5656
enb := entities.Enb{}
cell := entities.ServedCellInfo{Tac: "tac"}
enb.ServedCells = []*entities.ServedCellInfo{&cell}
nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
var e error
data, err := proto.Marshal(&nb)
if err != nil {
t.Errorf("#rNibReader_test.TestGetNodebById - Failed to marshal ENB instance. Error: %v", err)
}
plmnId := "02f829"
nbId := "4a952a0a"
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
}
ret := map[string]interface{}{key: string(data)}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
assert.Nil(t, er)
assert.Equal(t, getNb.Ip, nb.Ip)
assert.Equal(t, getNb.Port, nb.Port)
assert.Equal(t, getNb.ConnectionStatus, nb.ConnectionStatus)
assert.Len(t, getNb.GetEnb().GetServedCells(), 1)
assert.Equal(t, getNb.GetEnb().GetServedCells()[0].Tac, nb.GetEnb().GetServedCells()[0].Tac)
}
func TestGetNodebByIdNotFoundFailureEnb(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
}
var ret map[string]interface{}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.NodebInfo not found. Key: ENB:02f829:4a952a0a", er.Error())
}
func TestGetNodebByIdNotFoundFailureGnb(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
}
var ret map[string]interface{}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
getNb, er := w.GetNodebByGlobalNbId(entities.Node_GNB, globalNbId)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.NodebInfo not found. Key: GNB:02f829:4a952a0a", er.Error())
}
func TestGetNodeByIdUnmarshalFailure(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
}
var e error
ret := make(map[string]interface{}, 1)
ret[key] = "data"
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetNodeByIdSdlgoFailure(t *testing.T) {
plmnId := "02f829"
nbId := "4a952a0a"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
if rNibErr != nil {
t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
}
e := errors.New(errMsg)
var ret map[string]interface{}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
getNb, er := w.GetNodebByGlobalNbId(entities.Node_GNB, globalNbId)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func TestGetCellById(t *testing.T) {
cellId := "aaaa"
var pci uint32 = 10
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
cellData, err := proto.Marshal(&cellEntity)
if err != nil {
t.Errorf("#rNibReader_test.TestGetCellById - Failed to marshal Cell entity. Error: %v", err)
}
var e error
key, rNibErr := common.ValidateAndBuildCellIdKey(cellId)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellById - failed to validate key parameter")
}
ret := map[string]interface{}{key: string(cellData)}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
assert.Nil(t, er)
assert.NotNil(t, cell)
assert.Equal(t, cell.Type, entities.Cell_LTE_CELL)
assert.NotNil(t, cell.GetServedCellInfo())
assert.Equal(t, cell.GetServedCellInfo().GetPci(), pci)
}
func TestGetCellByIdNotFoundFailureEnb(t *testing.T) {
cellId := "bbbb"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildCellIdKey(cellId)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellByIdNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.Cell not found. Key: CELL:bbbb", er.Error())
}
func TestGetCellByIdNotFoundFailureGnb(t *testing.T) {
cellId := "bbbb"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
key, rNibErr := common.ValidateAndBuildNrCellIdKey(cellId)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetCellByIdNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
cell, er := w.GetCellById(entities.Cell_NR_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.Cell not found. Key: NRCELL:bbbb", er.Error())
}
func TestGetCellByIdTypeValidationFailure(t *testing.T) {
cellId := "dddd"
readerPool = nil
initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
cell, er := w.GetCellById(5, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ValidationError{}, er)
assert.EqualValues(t, "#rNibReader.GetCellById - invalid cell type: 5", er.Error())
}
func TestGetCellByIdValidationFailureGnb(t *testing.T) {
cellId := ""
readerPool = nil
initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
cell, er := w.GetCellById(entities.Cell_NR_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ValidationError{}, er)
assert.EqualValues(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", er.Error())
}
func TestGetCellByIdValidationFailureEnb(t *testing.T) {
cellId := ""
readerPool = nil
initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
assert.NotNil(t, er)
assert.Nil(t, cell)
assert.IsType(t, &common.ValidationError{}, er)
assert.EqualValues(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", er.Error())
}
func TestGetRanLoadInformation(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
loadInfo := generateRanLoadInformation()
var e error
data, err := proto.Marshal(loadInfo)
if err != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
}
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformationNotFoundFailure - failed to validate key parameter")
}
ret := map[string]interface{}{redisKey: string(data)}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getLoadInfo, er := w.GetRanLoadInformation(name)
assert.Nil(t, er)
assert.NotNil(t, getLoadInfo)
expected, err := json.Marshal(loadInfo)
if err != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
}
actual, err := json.Marshal(getLoadInfo)
if err != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
}
assert.EqualValues(t, expected, actual)
}
func TestGetRanLoadInformationValidationFailure(t *testing.T) {
name := ""
readerPool = nil
initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
getNb, er := w.GetRanLoadInformation(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.ValidationError{}, er)
assert.EqualValues(t, "#utils.ValidateAndBuildRanLoadInformationKey - an empty inventory name received", er.Error())
}
func TestGetRanLoadInformationNotFoundFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformationNotFoundFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetRanLoadInformation(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.ResourceNotFoundError{}, er)
assert.EqualValues(t, "#rNibReader.getByKeyAndUnmarshal - entity of type *entities.RanLoadInformation not found. Key: LOAD:name", er.Error())
}
func TestGetRanLoadInformationUnmarshalFailure(t *testing.T) {
name := "name"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
ret := make(map[string]interface{}, 1)
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformationUnmarshalFailure - failed to validate key parameter")
}
ret[redisKey] = "data"
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetRanLoadInformation(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, "proto: can't skip unknown wire type 4", er.Error())
}
func TestGetRanLoadInformationSdlgoFailure(t *testing.T) {
name := "name"
errMsg := "expected Sdlgo error"
errMsgExpected := "expected Sdlgo error"
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
var ret map[string]interface{}
redisKey, rNibErr := common.ValidateAndBuildRanLoadInformationKey(name)
if rNibErr != nil {
t.Errorf("#rNibReader_test.TestGetRanLoadInformationSdlgoFailure - failed to validate key parameter")
}
sdlInstanceMock.On("Get", []string{redisKey}).Return(ret, e)
getNb, er := w.GetRanLoadInformation(name)
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.IsType(t, &common.InternalError{}, er)
assert.EqualValues(t, errMsgExpected, er.Error())
}
func generateCellLoadInformation() *entities.CellLoadInformation {
cellLoadInformation := entities.CellLoadInformation{}
cellLoadInformation.CellId = "123"
ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
TargetCellId:"456",
UlHighInterferenceIndication:"xxx",
}
cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation }
cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
RntpPerPrb:"xxx",
RntpThreshold:entities.RntpThreshold_NEG_4,
NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
PB: 1,
PdcchInterferenceImpact:2,
EnhancedRntp: &entities.EnhancedRntp{
EnhancedRntpBitmap:"xxx",
RntpHighPowerThreshold:entities.RntpThreshold_NEG_2,
EnhancedRntpStartTime: &entities.StartTime{StartSfn:500,StartSubframeNumber:5},
},
}
cellLoadInformation.AbsInformation = &entities.AbsInformation{
Mode: entities.AbsInformationMode_ABS_INFO_FDD,
AbsPatternInfo:"xxx",
NumberOfCellSpecificAntennaPorts:entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
MeasurementSubset:"xxx",
}
cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
AssociatedSubframes:"xxx",
ExtendedUlInterferenceOverloadIndications:cellLoadInformation.UlInterferenceOverloadIndications,
}
compInformationItem := &entities.CompInformationItem{
CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
BenefitMetric:50,
}
cellLoadInformation.CompInformation = &entities.CompInformation{
CompInformationItems:[]*entities.CompInformationItem{compInformationItem},
CompInformationStartTime:&entities.StartTime{StartSfn:123,StartSubframeNumber:456},
}
cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
State: entities.NaicsState_NAICS_ACTIVE,
TransmissionModes:"xxx",
PB: 2,
PAList:[]entities.PA{entities.PA_DB_NEG_3},
}
return &cellLoadInformation
}
func generateRanLoadInformation() *entities.RanLoadInformation {
ranLoadInformation := entities.RanLoadInformation{}
ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
cellLoadInformation := generateCellLoadInformation()
ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
return &ranLoadInformation
}
//integration tests
//
//func TestGetEnbInteg(t *testing.T){
// name := "nameEnb1"
// Init("namespace", 1)
// w := GetRNibReader()
// nb, err := w.GetNodeb(name)
// if err != nil{
// fmt.Println(err)
// } else {
// fmt.Printf("#TestGetEnbInteg - responding node type: %v\n", nb)
// }
//}
//
//func TestGetEnbCellsInteg(t *testing.T){
// name := "nameEnb1"
// Init("namespace", 1)
// w := GetRNibReader()
// cells, err := w.GetCellList(name)
// if err != nil{
// fmt.Println(err)
// } else if cells != nil{
// for _, cell := range cells.GetServedCellInfos().ServedCells{
// fmt.Printf("responding node type Cell: %v\n", *cell)
// }
// }
//}
//
//func TestGetGnbInteg(t *testing.T){
// name := "nameGnb1"
// Init("namespace", 1)
// w := GetRNibReader()
// nb, err := w.GetNodeb(name)
// if err != nil{
// fmt.Println(err)
// } else {
// fmt.Printf("#TestGetGnbInteg - responding node type: %v\n", nb)
// }
//}
//
//func TestGetGnbCellsInteg(t *testing.T){
// name := "nameGnb1"
// Init("namespace", 1)
// w := GetRNibReader()
// cells, err := w.GetCellList(name)
// if err != nil{
// fmt.Println(err)
// } else if cells != nil{
// for _, cell := range cells.GetServedNrCells().ServedCells{
// fmt.Printf("responding node type NR Cell: %v\n", *cell)
// }
// }
//}
//
//func TestGetListEnbIdsInteg(t *testing.T) {
// Init("namespace", 1)
// w := GetRNibReader()
// ids, err := w.GetListEnbIds()
// if err != nil{
// fmt.Println(err)
// } else {
// for _, id := range ids{
// fmt.Printf("#TestGetListEnbIdsInteg - ENB ID: %s\n", id)
// }
// }
//}
//
//func TestGetListGnbIdsInteg(t *testing.T) {
// Init("namespace", 1)
// w := GetRNibReader()
// ids, err := w.GetListGnbIds()
// if err != nil{
// fmt.Println(err)
// } else {
// for _, id := range ids{
// fmt.Printf("#TestGetListGnbIdsInteg - GNB ID: %s\n", id)
// }
// }
//}
//
//func TestGetCountGnbListInteg(t *testing.T) {
// Init("namespace", 1)
// w := GetRNibReader()
// count, err := w.GetCountGnbList()
// if err != nil{
// fmt.Println(err)
// } else {
// fmt.Printf("#TestGetCountGnbListInteg - count Gnb list: %d\n", count)
// }
//}
//
//func TestGetGnbCellInteg(t *testing.T){
// name := "nameGnb7"
// pci := 0x0a
// Init("namespace", 1)
// w := GetRNibReader()
// cell, err := w.GetCell(name, uint32(pci))
// if err != nil{
// fmt.Println(err)
// } else if cell != nil{
// fmt.Printf("responding node type NR Cell: %v\n", cell.GetServedNrCell())
// }
//}
//
//func TestGetEnbCellInteg(t *testing.T) {
// name := "nameEnb1"
// pci := 0x22
// Init("namespace", 1)
// w := GetRNibReader()
// cell, err := w.GetCell(name, uint32(pci))
// if err != nil {
// fmt.Println(err)
// } else if cell != nil {
// fmt.Printf("responding node type LTE Cell: %v\n", cell.GetServedCellInfo())
// }
//}
//
//func TestGetEnbCellByIdInteg(t *testing.T){
// Init("namespace", 1)
// w := GetRNibReader()
// cell, err := w.GetCellById(entities.Cell_NR_CELL, "45d")
// if err != nil{
// fmt.Println(err)
// } else if cell != nil{
// fmt.Printf("responding node type NR Cell: %v\n", cell.GetServedNrCell())
// }
//}
//
//func TestGetListNbIdsInteg(t *testing.T) {
// Init("e2Manager", 1)
// w := GetRNibReader()
// ids, err := w.GetListNodebIds()
// if err != nil{
// fmt.Println(err)
// } else {
// for _, id := range ids{
// fmt.Printf("#TestGetListGnbIdsInteg - NB ID: %s\n", id)
// }
// }
//}
//
//func TestGetRanLoadInformationInteg(t *testing.T){
// Init("e2Manager", 1)
// w := GetRNibReader()
// ranLoadInformation, err := w.GetRanLoadInformation("ran_integ")
// if err != nil{
// t.Errorf("#rNibReader_test.TestGetRanLoadInformationInteg - Failed to get RanLoadInformation entity. Error: %v", err)
// }
// assert.NotNil(t, ranLoadInformation)
// fmt.Printf("#rNibReader_test.TestGetRanLoadInformationInteg - GNB ID: %s\n", ranLoadInformation)
//}