RICAPP-223:- Creating UE/CELL metrics hashmap based upon the KPIS supported by each... 39/12139/1
authorsandeepindia <kumar.sandeep3@hcl.com>
Wed, 29 Nov 2023 17:47:44 +0000 (17:47 +0000)
committersandeepindia <kumar.sandeep3@hcl.com>
Wed, 29 Nov 2023 17:47:44 +0000 (17:47 +0000)
Change-Id: I07401d83866580a8b27b2e83aad26bd15f1141fc
Signed-off-by: sandeepindia <kumar.sandeep3@hcl.com>
Dockerfile
control/control.go
e2sm/wrapper.c
e2sm/wrapper.h

index 9a533c2..5af9b09 100644 (file)
@@ -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/
index 3a17cd9..e101eaf 100644 (file)
@@ -5,11 +5,9 @@ package control
 #cgo CFLAGS: -I/usr/local/include/e2sm\r
 */\r
 import "C"\r
-\r
 import (\r
        "unsafe"\r
 )\r
-\r
 import (\r
        "context"\r
        "encoding/json"\r
@@ -46,6 +44,8 @@ var (
        clientEndpoint       = clientmodel.SubscriptionParamsClientEndpoint{Host: "service-ricxapp-kpimon-go-http.ricxapp", HTTPPort: &hPort, RMRPort: &rPort}\r
 )\r
 var Glob_cell = make(map[string]bool)\r
+var ranUeKpi = make(map[string][]string)\r
+var ranCellKpi =  make(map[string][]string)\r
 func (c Control) Consume(msg *xapp.RMRParams) error {\r
        id := xapp.Rmr.GetRicMessageName(msg.Mtype)\r
        xapp.Logger.Info(\r
@@ -922,10 +922,65 @@ func (c *Control) writeCellMetrics_db(cellMetrics *map[string]interface{}) {
 }\r
 \r
 func (c Control) xAppStartCB(d interface{}) {\r
-       xapp.Logger.Info("In callback KPI monitor xApp ...")\r
+               xapp.Logger.Info("In callback KPI monitor xApp ...")\r
+\r
+               //ranUeKpi ranCellKpi   \r
+               // Get eNodeB list\r
+               nbList := c.getnbList()\r
+\r
+               for _, nb := range nbList {\r
+                if nb.ConnectionStatus == 1 {\r
+                        xapp.Logger.Info("Building ranCellKp for %v", nb.InventoryName)\r
+                        link:="http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/"\r
+                       link=link+nb.InventoryName\r
+                       tmpr,err := http.Get(link)\r
+                       if err != nil {\r
+                               log.Fatalln(err)\r
+                               panic("Unable to build ranCellKpi")\r
+                       }\r
+                       defer tmpr.Body.Close()\r
+                       var resp E2mgrResponse\r
+\r
+                       err=json.NewDecoder(tmpr.Body).Decode(&resp)\r
+                       if err != nil {\r
+                               log.Fatalln(err)\r
+                               panic("Unable to build ranCellKpi")\r
+\r
+                       }\r
+                       counter:=0\r
+                       //RanFunctionId=2 for kpm in viavi\r
+                       for i := 0; i < len(resp.Gnb.RanFunctions); i++ {\r
+                               if resp.Gnb.RanFunctions[i].RanFunctionId  == 2 {\r
+                                       counter = i\r
+                                       break\r
+                               }\r
+                       }\r
+                       cString := C.CString(resp.Gnb.RanFunctions[counter].RanFunctionDefinition)\r
+                       defer C.free(unsafe.Pointer(cString)) // Free the allocated C string when done\r
+                       result:=C.buildRanCellUeKpi(cString)\r
+                       \r
+                       ueSlice := make([]string, result.ueKpiSize)\r
+                       \r
+                       for _, v := range unsafe.Slice(result.ueKpi, result.ueKpiSize) {\r
+                               ueSlice = append(ueSlice, C.GoString(v))\r
+                       }\r
+                       ranUeKpi[nb.InventoryName]=ueSlice\r
+\r
+                       cellSlice := make([]string, result.cellKpiSize)\r
+\r
+                        for _, v := range unsafe.Slice(result.cellKpi, result.cellKpiSize) {\r
+                                cellSlice = append(cellSlice, C.GoString(v))\r
+                        }\r
+                        ranCellKpi[nb.InventoryName]=cellSlice\r
+\r
+\r
+                       //C.freeMemorydRanCellUeKpi(result)\r
+\r
+\r
+                }\r
+\r
+        }\r
 \r
-       // Get eNodeB list\r
-       nbList := c.getnbList()\r
 \r
        // Send subscription request to connected NodeB\r
        for _, nb := range nbList {\r
index b2be196..2cb785d 100644 (file)
@@ -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;j<sz1;j++){
+                                        size_t bufsize=e2smKpmRanFunctDescrip->ric_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;j<sz3;j++){
+                                        size_t bufsize=e2smKpmRanFunctDescrip->ric_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<res.cellKpiSize;i++){
+                       free(res.cellKpi[i]);
+               }
+               
+               free(res.cellKpi);
+       }
+       
+       if(res.ueKpi!=NULL){
+               for(int i=0; i<res.ueKpiSize;i++){
+                       free(res.ueKpi[i]);
+               }
+               free(res.ueKpi);
+       }
+
+
+
+}
 //determine 
 //1 for format1 by id, 2 for format1 by name , 3 for format3 by id, 4 for format3 by name
 struct encode_act_Def_result encode_action_Definition(const char *hex_values, int determine){
index fb2a636..56bd638 100644 (file)
@@ -102,10 +102,21 @@ typedef struct encode_act_Def_result{
        int * array;
        int length;
 } encode_act_Def_result_t;
+
+typedef struct ranCellUeKpi{
+        char ** ueKpi;
+        char ** cellKpi;
+       int ueKpiSize;
+       int cellKpiSize;
+} ranCellUeKpi_t;
+
 ssize_t e2sm_encode_ric_event_trigger_definition(void *buffer, size_t buf_size, size_t event_trigger_count, long *RT_periods);
+
 //ssize_t e2sm_encode_ric_action_definition(void *buffer, size_t buf_size, long action_Def_count, long meas_ID, long ric_style_type, long GR_periods, Plm plm, Nrc nRc);
 //
 
+ranCellUeKpi_t buildRanCellUeKpi(const char *hex_values);
+
 struct encode_act_Def_result encode_action_Definition(const char *hex_values, int determine);
 
 size_t e2sm_encode_ric_action_definition_format1_by_name(unsigned char *buf, size_t *buf_size, const char **id_tmp , size_t measIdcount, long ric_style_type, unsigned long granulPeriod, unsigned char  *p, unsigned char *nR);