GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError)
// GetCellById retrieves the cell entity from redis DB by cell type and cell Id
GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError)
+ // GetListNodebIds returns the full list of Nodeb identity entities
+ GetListNodebIds()([]*entities.NbIdentity, common.IRNibError)
}
+const(
+ EnbType = "ENB"
+ GnbType = "GNB"
+)
+
/*
Init initializes the infrastructure required for the RNibReader instance
*/
}
func (w *rNibReaderInstance) GetNodeb(inventoryName string) (*entities.NodebInfo, common.IRNibError) {
- name, rNibErr := common.ValidateAndBuildNodeBNameKey(inventoryName)
+ defer readerPool.Put(w)
+ key, rNibErr := common.ValidateAndBuildNodeBNameKey(inventoryName)
if rNibErr != nil {
return nil, rNibErr
}
- defer readerPool.Put(w)
- data, err := (*w.sdl).Get([]string{name})
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- nb := entities.NodebInfo{}
- if data != nil && data[name] != nil {
- err = proto.Unmarshal([]byte(data[name].(string)), &nb)
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- return &nb, nil
- }
- return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.GetNodeb - responding node %s not found", inventoryName))
+ return w.getNodeb(key)
}
func (w *rNibReaderInstance) GetNodebByGlobalNbId(nodeType entities.Node_Type, globalNbId *entities.GlobalNbId) (*entities.NodebInfo, common.IRNibError) {
+ defer readerPool.Put(w)
key, rNibErr := common.ValidateAndBuildNodeBIdKey(nodeType.String(), globalNbId.GetPlmnId(), globalNbId.GetNbId())
if rNibErr != nil {
return nil, rNibErr
}
- defer readerPool.Put(w)
- data, err := (*w.sdl).Get([]string{key})
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- nb := entities.NodebInfo{}
- if data != nil && data[key] != nil {
- err = proto.Unmarshal([]byte(data[key].(string)), &nb)
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- return &nb, nil
- }
- return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.GetNodebByGlobalNbId - responding node not found, global nodeb Id: %s", key))
+ return w.getNodeb(key)
}
func (w *rNibReaderInstance) GetCellList(inventoryName string) (*entities.Cells, common.IRNibError) {
func (w *rNibReaderInstance) GetListGnbIds() (*[]*entities.NbIdentity, common.IRNibError) {
defer readerPool.Put(w)
- data, err := (*w.sdl).GetMembers("GNB")
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- return unmarshalIdentityList(data)
+ return w.getListNodebIdsByType(GnbType)
}
func (w *rNibReaderInstance) GetListEnbIds() (*[]*entities.NbIdentity, common.IRNibError) {
defer readerPool.Put(w)
- data, err := (*w.sdl).GetMembers("ENB")
- if err != nil {
- return nil, common.NewInternalError(err)
- }
- return unmarshalIdentityList(data)
+ return w.getListNodebIdsByType(EnbType)
}
func (w *rNibReaderInstance) GetCountGnbList() (int, common.IRNibError) {
defer readerPool.Put(w)
- data, err := (*w.sdl).GetMembers("GNB")
+ size, err := (*w.sdl).GroupSize(GnbType)
if err != nil {
return 0, common.NewInternalError(err)
}
- return len(data), nil
+ return int(size), nil
}
func (w *rNibReaderInstance) GetCell(inventoryName string, pci uint32) (*entities.Cell, common.IRNibError) {
+ defer readerPool.Put(w)
key, rNibErr := common.ValidateAndBuildCellNamePciKey(inventoryName, pci)
if rNibErr != nil {
return nil, rNibErr
}
- return (*w).getCellByKey(key)
+ return w.getCellByKey(key)
}
func (w *rNibReaderInstance) GetCellById(cellType entities.Cell_Type, cellId string) (*entities.Cell, common.IRNibError) {
+ defer readerPool.Put(w)
var key string
var rNibErr common.IRNibError
if cellType == entities.Cell_LTE_CELL {
if rNibErr != nil {
return nil, rNibErr
}
- return (*w).getCellByKey(key)
+ return w.getCellByKey(key)
}
-func (w *rNibReaderInstance) getCellByKey(key string) (*entities.Cell, common.IRNibError) {
+func (w *rNibReaderInstance) GetListNodebIds()([]*entities.NbIdentity, common.IRNibError){
defer readerPool.Put(w)
+ dataEnb, err := (*w.sdl).GetMembers(EnbType)
+ if err != nil{
+ return nil, common.NewInternalError(err)
+ }
+ dataGnb, err := (*w.sdl).GetMembers(GnbType)
+ if err != nil{
+ return nil, common.NewInternalError(err)
+ }
+ data, rnibErr := unmarshalIdentityList(append(dataEnb, dataGnb...))
+ return *data, rnibErr
+}
+
+func (w *rNibReaderInstance) getNodeb(key string) (*entities.NodebInfo, common.IRNibError) {
+ data, err := (*w.sdl).Get([]string{key})
+ if err != nil {
+ return nil, common.NewInternalError(err)
+ }
+ nb := entities.NodebInfo{}
+ if data != nil && data[key] != nil {
+ err = proto.Unmarshal([]byte(data[key].(string)), &nb)
+ if err != nil {
+ return nil, common.NewInternalError(err)
+ }
+ return &nb, nil
+ }
+ return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.getNodeb - responding node not found. Key: %s", key))
+}
+
+func (w *rNibReaderInstance) getCellByKey(key string) (*entities.Cell, common.IRNibError) {
data, err := (*w.sdl).Get([]string{key})
if err != nil {
return nil, common.NewInternalError(err)
return nil, common.NewResourceNotFoundError(errors.Errorf("#rNibReader.getCellByKey - cell not found, key: %s", key))
}
+func (w *rNibReaderInstance) getListNodebIdsByType(nbType string) (*[]*entities.NbIdentity, common.IRNibError) {
+ data, err := (*w.sdl).GetMembers(nbType)
+ if err != nil {
+ return nil, common.NewInternalError(err)
+ }
+ return unmarshalIdentityList(data)
+}
+
func unmarshalIdentityList(data []string) (*[]*entities.NbIdentity, common.IRNibError) {
var members []*entities.NbIdentity
for _, d := range data {
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.Equal(t, 1, er.GetCode())
- assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetNodeb - responding node name not found", er.Error())
+ assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: RAN:name", er.Error())
}
func TestGetNodeBUnmarshalFailure(t *testing.T) {
assert.NotNil(t, er)
assert.Nil(t, cells)
assert.Equal(t, 1, er.GetCode())
- assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetNodeb - responding node name not found", er.Error())
+ assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: RAN:name", er.Error())
}
func TestGetNodeBCellsListNotFoundFailureEnb(t *testing.T) {
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
- sdlInstanceMock.On("GetMembers", "GNB").Return([]string{"data"}, e)
+ sdlInstanceMock.On("GetMembers", GnbType).Return([]string{"data"}, e)
ids, er := w.GetListGnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
w := GetRNibReader()
e := errors.New(errMsg)
var data []string
- sdlInstanceMock.On("GetMembers", "GNB").Return(data, e)
+ sdlInstanceMock.On("GetMembers", GnbType).Return(data, e)
ids, er := w.GetListGnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
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", EnbType).Return([]string{string(data)}, nilError)
+
+ errMsg := "expected Sdlgo error"
+ errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
+ expectedError := errors.New(errMsg)
+ var nilData []string
+ sdlInstanceMock.On("GetMembers", GnbType).Return(nilData, expectedError)
+
+ ids, er := w.GetListNodebIds()
+ assert.NotNil(t, er)
+ assert.Nil(t, ids)
+ assert.Equal(t, 2, er.GetCode())
+ 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", GnbType).Return([]string{string(data)}, nilError)
+
+ errMsg := "expected Sdlgo error"
+ errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
+ expectedError := errors.New(errMsg)
+ var nilData []string
+ sdlInstanceMock.On("GetMembers", EnbType).Return(nilData, expectedError)
+
+ ids, er := w.GetListNodebIds()
+ assert.NotNil(t, er)
+ assert.Nil(t, ids)
+ assert.Equal(t, 2, er.GetCode())
+ assert.EqualValues(t, errMsgExpected, er.Error())
+}
+
+func TestGetListNodesIdsEnbSdlgoSuccess(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", GnbType).Return([]string{string(data)}, nilError)
+ sdlInstanceMock.On("GetMembers", EnbType).Return([]string{string(data)}, nilError)
+
+ ids, er := w.GetListNodebIds()
+ assert.Nil(t, er)
+ assert.NotNil(t, ids)
+ assert.Len(t, ids, 2)
+}
+
func TestGetListEnbIdsUnmarshalFailure(t *testing.T) {
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
- sdlInstanceMock.On("GetMembers", "ENB").Return([]string{"data"}, e)
+ sdlInstanceMock.On("GetMembers", EnbType).Return([]string{"data"}, e)
ids, er := w.GetListEnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListEnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
- sdlInstanceMock.On("GetMembers", "ENB").Return([]string{string(data)}, e)
+ sdlInstanceMock.On("GetMembers", EnbType).Return([]string{string(data)}, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, 1)
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
- sdlInstanceMock.On("GetMembers", "ENB").Return([]string{}, e)
+ sdlInstanceMock.On("GetMembers", EnbType).Return([]string{}, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, 0)
idsEntities[i] = nbIdentity
}
var e error
- sdlInstanceMock.On("GetMembers", "ENB").Return(idsData, e)
+ sdlInstanceMock.On("GetMembers", EnbType).Return(idsData, e)
ids, er := w.GetListEnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, listSize)
if err != nil {
t.Errorf("#rNibReader_test.TestGetListGnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
}
- sdlInstanceMock.On("GetMembers", "GNB").Return([]string{string(data)}, e)
+ sdlInstanceMock.On("GetMembers", GnbType).Return([]string{string(data)}, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, 1)
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
- sdlInstanceMock.On("GetMembers", "GNB").Return([]string{}, e)
+ sdlInstanceMock.On("GetMembers", GnbType).Return([]string{}, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, 0)
idsEntities[i] = nbIdentity
}
var e error
- sdlInstanceMock.On("GetMembers", "GNB").Return(idsData, e)
+ sdlInstanceMock.On("GetMembers", GnbType).Return(idsData, e)
ids, er := w.GetListGnbIds()
assert.Nil(t, er)
assert.Len(t, *ids, listSize)
w := GetRNibReader()
e := errors.New(errMsg)
var data []string
- sdlInstanceMock.On("GetMembers", "ENB").Return(data, e)
+ sdlInstanceMock.On("GetMembers", EnbType).Return(data, e)
ids, er := w.GetListEnbIds()
assert.NotNil(t, er)
assert.Nil(t, ids)
}
func TestGetCountGnbListOneId(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.TestGetCountGnbList - Failed to marshal nodeb identity entity. Error: %v", err)
- }
- sdlInstanceMock.On("GetMembers", "GNB").Return([]string{string(data)}, e)
+ sdlInstanceMock.On("GroupSize", GnbType).Return(1, e)
count, er := w.GetCountGnbList()
assert.Nil(t, er)
assert.Equal(t, count, 1)
}
func TestGetCountGnbList(t *testing.T) {
- listSize := 3
- name := "name"
- plmnId := 0x02f823
- nbId := 0x4a952a1f
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
var e error
- 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
- }
- sdlInstanceMock.On("GetMembers", "GNB").Return(idsData, e)
+ sdlInstanceMock.On("GroupSize", GnbType).Return(3, e)
count, er := w.GetCountGnbList()
assert.Nil(t, er)
assert.Equal(t, count, 3)
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
e := errors.New(errMsg)
- var data []string
- sdlInstanceMock.On("GetMembers", "GNB").Return(data, e)
+ var count int
+ sdlInstanceMock.On("GroupSize", GnbType).Return(count, e)
count, er := w.GetCountGnbList()
assert.NotNil(t, er)
assert.Equal(t, 0, count)
func TestGetCell(t *testing.T) {
name := "name"
- var pci uint32
- pci = 10
+ var pci uint32 = 10
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.Equal(t, 1, er.GetCode())
- assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetNodebByGlobalNbId - responding node not found, global nodeb Id: ENB:02f829:4a952a0a", er.Error())
+ assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: ENB:02f829:4a952a0a", er.Error())
}
func TestGetNodebByIdNotFoundFailureGnb(t *testing.T) {
assert.NotNil(t, er)
assert.Nil(t, getNb)
assert.Equal(t, 1, er.GetCode())
- assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetNodebByGlobalNbId - responding node not found, global nodeb Id: GNB:02f829:4a952a0a", er.Error())
+ assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: GNB:02f829:4a952a0a", er.Error())
}
func TestGetNodeByIdUnmarshalFailure(t *testing.T) {
func TestGetCellById(t *testing.T) {
cellId := "aaaa"
- var pci uint32
- pci = 10
+ var pci uint32 = 10
readerPool = nil
sdlInstanceMock := initSdlInstanceMock(namespace, 1)
w := GetRNibReader()