From 233e697c71b9074ca84674db52154baf8d2a25f7 Mon Sep 17 00:00:00 2001 From: sandeepindia Date: Wed, 29 Nov 2023 17:47:44 +0000 Subject: [PATCH] RICAPP-223:- Creating UE/CELL metrics hashmap based upon the KPIS supported by each E2 node Change-Id: I07401d83866580a8b27b2e83aad26bd15f1141fc Signed-off-by: sandeepindia --- Dockerfile | 2 + control/control.go | 65 +++++++++++++++++++++++++++++--- e2sm/wrapper.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++ e2sm/wrapper.h | 11 ++++++ 4 files changed, 181 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a533c2..5af9b09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,14 @@ WORKDIR /opt # Install RMR client #COPY bin/rmr* ./ #RUN dpkg -i rmr_4.8.0_amd64.deb; dpkg -i rmr-dev_4.8.0_amd64.deb; rm rmr* + # Install RMR client ARG RMRVERSION=4.9.0 RUN wget --content-disposition https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr_${RMRVERSION}_amd64.deb RUN wget --content-disposition https://packagecloud.io/o-ran-sc/release/packages/debian/stretch/rmr-dev_${RMRVERSION}_amd64.deb/download.deb && dpkg -i rmr-dev_${RMRVERSION}_amd64.deb RUN rm -f rmr_${RMRVERSION}_amd64.deb rmr-dev_${RMRVERSION}_amd64.deb + RUN apt-get update && \ apt-get -y install gcc COPY e2ap/ e2ap/ diff --git a/control/control.go b/control/control.go index 3a17cd9..e101eaf 100644 --- a/control/control.go +++ b/control/control.go @@ -5,11 +5,9 @@ package control #cgo CFLAGS: -I/usr/local/include/e2sm */ import "C" - import ( "unsafe" ) - import ( "context" "encoding/json" @@ -46,6 +44,8 @@ var ( clientEndpoint = clientmodel.SubscriptionParamsClientEndpoint{Host: "service-ricxapp-kpimon-go-http.ricxapp", HTTPPort: &hPort, RMRPort: &rPort} ) var Glob_cell = make(map[string]bool) +var ranUeKpi = make(map[string][]string) +var ranCellKpi = make(map[string][]string) func (c Control) Consume(msg *xapp.RMRParams) error { id := xapp.Rmr.GetRicMessageName(msg.Mtype) xapp.Logger.Info( @@ -922,10 +922,65 @@ func (c *Control) writeCellMetrics_db(cellMetrics *map[string]interface{}) { } func (c Control) xAppStartCB(d interface{}) { - xapp.Logger.Info("In callback KPI monitor xApp ...") + xapp.Logger.Info("In callback KPI monitor xApp ...") + + //ranUeKpi ranCellKpi + // Get eNodeB list + nbList := c.getnbList() + + for _, nb := range nbList { + if nb.ConnectionStatus == 1 { + xapp.Logger.Info("Building ranCellKp for %v", nb.InventoryName) + link:="http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/" + link=link+nb.InventoryName + tmpr,err := http.Get(link) + if err != nil { + log.Fatalln(err) + panic("Unable to build ranCellKpi") + } + defer tmpr.Body.Close() + var resp E2mgrResponse + + err=json.NewDecoder(tmpr.Body).Decode(&resp) + if err != nil { + log.Fatalln(err) + panic("Unable to build ranCellKpi") + + } + counter:=0 + //RanFunctionId=2 for kpm in viavi + for i := 0; i < len(resp.Gnb.RanFunctions); i++ { + if resp.Gnb.RanFunctions[i].RanFunctionId == 2 { + counter = i + break + } + } + cString := C.CString(resp.Gnb.RanFunctions[counter].RanFunctionDefinition) + defer C.free(unsafe.Pointer(cString)) // Free the allocated C string when done + result:=C.buildRanCellUeKpi(cString) + + ueSlice := make([]string, result.ueKpiSize) + + for _, v := range unsafe.Slice(result.ueKpi, result.ueKpiSize) { + ueSlice = append(ueSlice, C.GoString(v)) + } + ranUeKpi[nb.InventoryName]=ueSlice + + cellSlice := make([]string, result.cellKpiSize) + + for _, v := range unsafe.Slice(result.cellKpi, result.cellKpiSize) { + cellSlice = append(cellSlice, C.GoString(v)) + } + ranCellKpi[nb.InventoryName]=cellSlice + + + //C.freeMemorydRanCellUeKpi(result) + + + } + + } - // Get eNodeB list - nbList := c.getnbList() // Send subscription request to connected NodeB for _, nb := range nbList { diff --git a/e2sm/wrapper.c b/e2sm/wrapper.c index b2be196..2cb785d 100644 --- a/e2sm/wrapper.c +++ b/e2sm/wrapper.c @@ -9,7 +9,115 @@ static int write_out(const void *buffer, size_t size, void *app_key) { return (wrote == size) ? 0 :-1; } */ +ranCellUeKpi_t buildRanCellUeKpi(const char *hex_values){ + int BUFFER_SIZE=10240; + // Calculate the length of the hex string + size_t hex_len = strlen(hex_values); + + // Allocate memory for a char array to store the hex values + char *hex_buffer = (char *)malloc(hex_len / 2 + 1); // Each byte is represented by 2 characters, +1 for null terminator + ranCellUeKpi_t res; + if (hex_buffer == NULL) { + fprintf(stderr, "Memory allocation failed\n"); + return res; + } + + // Convert the hex string to binary data + for (size_t i = 0; i < hex_len; i += 2) { + char byte[3] = {hex_values[i], hex_values[i + 1], '\0'}; + hex_buffer[i / 2] = (char)strtol(byte, NULL, 16); + } + + // Null-terminate the char array + hex_buffer[hex_len / 2] = '\0'; + + // Now hex_buffer contains the binary data corresponding to the hex values + + // Print the result + printf("Hex values as a string: %s\n", hex_buffer); + char **name_format1; + char **name_format3; + int sz1=0; + int sz3=0; + + E2SM_KPM_RANfunction_Description_t * e2smKpmRanFunctDescrip=(E2SM_KPM_RANfunction_Description_t * )calloc(1,sizeof(E2SM_KPM_RANfunction_Description_t )); + + enum asn_transfer_syntax syntax; + + syntax = ATS_ALIGNED_BASIC_PER; + + asn_dec_rval_t rval = asn_decode(NULL, syntax, &asn_DEF_E2SM_KPM_RANfunction_Description, (void**)&e2smKpmRanFunctDescrip, hex_buffer, hex_len); + + if(rval.code == RC_OK) + { + printf( "[INFO] E2SM KPM RAN Function Description decode successfull rval.code = %d \n",rval.code); + + asn_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, e2smKpmRanFunctDescrip); + + for(int i=0; i< e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.count; i++){ + + if(e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->ric_ActionFormat_Type==1){ + sz1=e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.count; + name_format1=(char **)malloc(sz1*sizeof(char *)); + for(int j=0;jric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measName.size; + name_format1[j]=(char*)malloc(bufsize); + name_format1[j]=e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measName.buf; + + } + + } + + if(e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->ric_ActionFormat_Type==3){ + sz3=e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.count; + name_format3=(char **)malloc(sz3*sizeof(char *)); + for(int j=0;jric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measName.size; + name_format3[j]=(char*)malloc(bufsize); + name_format3[j]=e2smKpmRanFunctDescrip->ric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measName.buf; + + } + + } + + + + } + + + } + else + { + printf("[INFO] E2SM KPM RAN Function Description decode failed rval.code = %d \n", rval.code); + } + + res.ueKpi=name_format3; + res.cellKpi=name_format1; + res.ueKpiSize= sz3; + res.cellKpiSize= sz1 ; + return res; +} +void freeMemorydRanCellUeKpi(ranCellUeKpi_t res){ + if (res.cellKpi !=NULL ){ + + for(int i=0; i