From 138ddd6f66de28b9b3637629e0fa710356d531d7 Mon Sep 17 00:00:00 2001 From: sandeepindia Date: Wed, 29 Nov 2023 17:28:18 +0000 Subject: [PATCH] RICAPP-222 :- ASN decoders for kpm ran function description and asn encoders for action definition format1 and format3 Change-Id: Ic0e288d699ac1b88739ef21a194cd39a3b66d36b Signed-off-by: sandeepindia --- Dockerfile | 3 + control/control.go | 922 ++++++++++++++++++++++++++++------------------------- e2sm/wrapper.c | 753 +++++++++++++++++++++++++++++++++++++++++-- e2sm/wrapper.h | 20 ++ 4 files changed, 1235 insertions(+), 463 deletions(-) diff --git a/Dockerfile b/Dockerfile index 09ea30a..9a533c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,9 @@ FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu18-c-go:1.9.0 as build-kpimon 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 diff --git a/control/control.go b/control/control.go index acb8d59..3a17cd9 100644 --- a/control/control.go +++ b/control/control.go @@ -1,5 +1,4 @@ package control - /* #include #cgo LDFLAGS: -le2smwrapper -lm @@ -7,26 +6,26 @@ package control */ import "C" +import ( + "unsafe" +) + import ( "context" - "encoding/base64" "encoding/json" - "errors" - "fmt" "log" "net/http" - "reflect" + "time" +// "bytes" +// "encoding/binary" "strconv" + "encoding/base64" "strings" - "time" - "unsafe" - + "fmt" + "reflect" + "errors" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - - // "bytes" - // "encoding/binary" - influxdb2 "github.com/influxdata/influxdb-client-go" ) @@ -41,13 +40,12 @@ var ( actionType = "report" actionId = int64(1) seqId = int64(1) - funcId = int64(0) + funcId = int64(2) hPort = int64(8080) rPort = int64(4560) clientEndpoint = clientmodel.SubscriptionParamsClientEndpoint{Host: "service-ricxapp-kpimon-go-http.ricxapp", HTTPPort: &hPort, RMRPort: &rPort} ) var Glob_cell = make(map[string]bool) - func (c Control) Consume(msg *xapp.RMRParams) error { id := xapp.Rmr.GetRicMessageName(msg.Mtype) xapp.Logger.Info( @@ -88,9 +86,9 @@ func (c Control) getEnbList() ([]*xapp.RNIBNbIdentity, error) { return nil, err } - xapp.Logger.Info("There are %d connected eNBs", len(enbs)) + xapp.Logger.Info("List for connected eNBs :") for index, enb := range enbs { - xapp.Logger.Debug("%d. enbid: %s", index+1, enb.InventoryName) + xapp.Logger.Info("%d. enbid: %s", index+1, enb.InventoryName) } return enbs, nil } @@ -102,9 +100,9 @@ func (c *Control) getGnbList() ([]*xapp.RNIBNbIdentity, error) { xapp.Logger.Error("err: %s", err) return nil, err } - xapp.Logger.Info("There are %d connected gNBs", len(gnbs)) + xapp.Logger.Info("List of connected gNBs :") for index, gnb := range gnbs { - xapp.Logger.Debug("%d. gnbid : %s", index+1, gnb.InventoryName) + xapp.Logger.Info("%d. gnbid : %s", index+1, gnb.InventoryName) } return gnbs, nil } @@ -149,26 +147,55 @@ func plmnid_to_list_of_int(str string) []int64 { } return ans } -func encode_action_format1(plmn string, cellid string) clientmodel.ActionDefinition { +func encode_action_format1(plmn string, cellid string, meid string) clientmodel.ActionDefinition { lol1 := plmnid_to_list_of_int(plmn) lol2 := cellid_to_list_of_int(cellid) var format1 []int64 //format1=[]int64{0,1,1,8,0,19,32,0,3,1,32,0,0,32,0,4,1,32,0,0,32,0,78,1,32,0,0,32,0,79,1,32,0,0,32,0,8,1,32,0,0,32,0,7,1,32,0,0,32,0,11,1,32,0,0,32,0,12,1,32,0,0,32,0,80,1,32,0,0,32,0,81,1,32,0,0,32,0,13,1,32,0,0,32,0,14,1,32,0,0,32,0,40,1,32,0,0,32,0,41,1,32,0,0,32,0,42,1,32,0,0,32,0,82,1,32,0,0,32,0,83,1,32,0,0,32,0,84,1,32,0,0,32,0,85,1,32,0,0,32,0,86,1,32,0,0,64,39,15,0,0,31,1,18,52,92,0,16} //0(nr) 1(eutra) 0,31,1(plmn)18,52,92,0,16(cellid) + link:="http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/" + + link=link+meid + tmpr,err := http.Get(link) + if err != nil { + log.Fatalln(err) + l:=[]int64{0} + return l + } + defer tmpr.Body.Close() + var resp E2mgrResponse - //for simulation-by measID (not supported in viavi 1.4) - //format1=[]int64{0,1,1,8,0,22,32,0,3,1,32,0,0,32,0,4,1,32,0,0,32,0,78,1,32,0,0,32,0,79,1,32,0,0,32,0,80,1,32,0,0,32,0,81,1,32,0,0,32,0,8,1,32,0,0,32,0,7,1,32,0,0,32,0,11,1,32,0,0,32,0,12,1,32,0,0,32,0,82,1,32,0,0,32,0,83,1,32,0,0,32,0,13,1,32,0,0,32,0,14,1,32,0,0,32,0,40,1,32,0,0,32,0,41,1,32,0,0,32,0,42,1,32,0,0,32,0,84,1,32,0,0,32,0,85,1,32,0,0,32,0,86,1,32,0,0,32,0,87,1,32,0,0,32,0,88,1,32,0,0,32,0,89,1,32,0,0,64,39,15,0}//assuming nr cells - - //for simulation-by measName(supported in Viavi 1.4) - format1 = []int64{0, 1, 1, 8, 0, 22, 0, 160, 68, 82, 66, 46, 85, 69, 84, 104, 112, 68, 108, 1, 32, 0, 0, 0, 160, 68, 82, 66, 46, 85, 69, 84, 104, 112, 85, 108, 1, 32, 0, 0, 0, 176, 80, 69, 69, 46, 65, 118, 103, 80, 111, 119, 101, 114, 1, 32, 0, 0, 0, 144, 80, 69, 69, 46, 69, 110, 101, 114, 103, 121, 1, 32, 0, 0, 1, 144, 81, 111, 115, 70, 108, 111, 119, 46, 84, 111, 116, 80, 100, 99, 112, 80, 100, 117, 86, 111, 108, 117, 109, 101, 68, 108, 1, 32, 0, 0, 1, 144, 81, 111, 115, 70, 108, 111, 119, 46, 84, 111, 116, 80, 100, 99, 112, 80, 100, 117, 86, 111, 108, 117, 109, 101, 85, 108, 1, 32, 0, 0, 0, 160, 82, 82, 67, 46, 67, 111, 110, 110, 77, 97, 120, 1, 32, 0, 0, 0, 176, 82, 82, 67, 46, 67, 111, 110, 110, 77, 101, 97, 110, 1, 32, 0, 0, 0, 208, 82, 82, 85, 46, 80, 114, 98, 65, 118, 97, 105, 108, 68, 108, 1, 32, 0, 0, 0, 208, 82, 82, 85, 46, 80, 114, 98, 65, 118, 97, 105, 108, 85, 108, 1, 32, 0, 0, 0, 176, 82, 82, 85, 46, 80, 114, 98, 84, 111, 116, 68, 108, 1, 32, 0, 0, 0, 176, 82, 82, 85, 46, 80, 114, 98, 84, 111, 116, 85, 108, 1, 32, 0, 0, 0, 192, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 68, 108, 1, 32, 0, 0, 0, 192, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 85, 108, 1, 32, 0, 0, 0, 160, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 120, 1, 32, 0, 0, 0, 160, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 121, 1, 32, 0, 0, 0, 160, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 122, 1, 32, 0, 0, 0, 192, 86, 105, 97, 118, 105, 46, 71, 110, 98, 68, 117, 73, 100, 1, 32, 0, 0, 0, 160, 86, 105, 97, 118, 105, 46, 78, 114, 67, 103, 105, 1, 32, 0, 0, 0, 160, 86, 105, 97, 118, 105, 46, 78, 114, 80, 99, 105, 1, 32, 0, 0, 1, 96, 86, 105, 97, 118, 105, 46, 82, 97, 100, 105, 111, 46, 97, 110, 116, 101, 110, 110, 97, 84, 121, 112, 101, 1, 32, 0, 0, 1, 32, 86, 105, 97, 118, 105, 46, 82, 97, 100, 105, 111, 46, 97, 122, 105, 109, 117, 116, 104, 1, 32, 0, 0, 1, 0, 86, 105, 97, 118, 105, 46, 82, 97, 100, 105, 111, 46, 112, 111, 119, 101, 114, 1, 32, 0, 0, 64, 39, 15, 0} //assuming nr cells - //for e2test - // format1=[]int64{0,1,1,8,0,42,32,0,0,1,32,0,0,32,0,1,1,32,0,0,32,0,2,1,32,0,0,32,0,3,1,32,0,0,32,0,4,1,32,0,0,32,0,5,1,32,0,0,32,0,6,1,32,0,0,32,0,7,1,32,0,0,32,0,8,1,32,0,0,32,0,9,1,32,0,0,32,0,10,1,32,0,0,32,0,11,1,32,0,0,32,0,12,1,32,0,0,32,0,13,1,32,0,0,32,0,14,1,32,0,0,32,0,15,1,32,0,0,32,0,16,1,32,0,0,32,0,17,1,32,0,0,32,0,18,1,32,0,0,32,0,19,1,32,0,0,32,0,20,1,32,0,0,32,0,21,1,32,0,0,32,0,22,1,32,0,0,32,0,23,1,32,0,0,32,0,24,1,32,0,0,32,0,25,1,32,0,0,32,0,26,1,32,0,0,32,0,27,1,32,0,0,32,0,28,1,32,0,0,32,0,29,1,32,0,0,32,0,30,1,32,0,0,32,0,31,1,32,0,0,32,0,32,1,32,0,0,32,0,33,1,32,0,0,32,0,34,1,32,0,0,32,0,35,1,32,0,0,32,0,36,1,32,0,0,32,0,37,1,32,0,0,32,0,38,1,32,0,0,32,0,39,1,32,0,0,32,0,40,1,32,0,0,32,0,41,1,32,0,0,32,0,42,1,32,0,0,64,39,15,0} + err=json.NewDecoder(tmpr.Body).Decode(&resp) + if err != nil { + log.Fatalln(err) + l:=[]int64{0} + return l + + } + 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 + // Call the C function + determine := 2 //2 for format1 by name + result:=C.encode_action_Definition(cString, C.int(determine)) + + for i := 0; i < int(result.length); i++ { + value := int64(*(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(result.array)) + uintptr(i*8)))) + format1 = append(format1, value) + } format1 = append(format1, lol1...) //appending plmn - format1 = append(format1, lol2...) //appending cellid + format1 = append(format1, lol2...) //appending cellid return format1 } -func encode_action_format2() clientmodel.ActionDefinition { +func encode_action_format2() clientmodel.ActionDefinition{ var format2 []int64 format2 = []int64{0, 1, 0, 0, 0, 20, 0, 160, 68, 82, 66, 46, 85, 69, 84, 104, 112, 68, 108, 1, 0, 0, 0, 1, 64, 68, 82, 66, 46, 85, 69, 84, 104, 112, 85, 108, 1, 0, 0, 0, 1, 0, 71, 78, 66, 45, 68, 85, 45, 73, 68, 1, 0, 0, 0, 0, 160, 78, 82, 45, 67, 71, 73, 1, 0, 0, 0, 0, 160, 78, 82, 45, 80, 67, 73, 1, 0, 0, 0, 2, 192, 81, 111, 115, 70, 108, 111, 119, 46, 80, 100, 99, 112, 80, 100, 117, 86, 111, 108, 117, 109, 101, 68, 108, 1, 0, 0, 0, 2, 192, 81, 111, 115, 70, 108, 111, 119, 46, 80, 100, 99, 112, 80, 100, 117, 86, 111, 108, 117, 109, 101, 85, 108, 1, 0, 0, 0, 1, 64, 82, 82, 67, 46, 67, 111, 110, 110, 77, 97, 120, 1, 0, 0, 0, 1, 96, 82, 82, 67, 46, 67, 111, 110, 110, 77, 101, 97, 110, 1, 0, 0, 0, 1, 160, 82, 82, 85, 46, 80, 114, 98, 65, 118, 97, 105, 108, 68, 108, 1, 0, 0, 0, 1, 160, 82, 82, 85, 46, 80, 114, 98, 65, 118, 97, 105, 108, 85, 108, 1, 0, 0, 0, 1, 32, 82, 82, 85, 46, 80, 114, 98, 84, 111, 116, 1, 0, 0, 0, 1, 96, 82, 82, 85, 46, 80, 114, 98, 84, 111, 116, 68, 108, 1, 0, 0, 0, 1, 96, 82, 82, 85, 46, 80, 114, 98, 84, 111, 116, 85, 108, 1, 0, 0, 0, 1, 128, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 68, 108, 1, 0, 0, 0, 1, 128, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 85, 108, 1, 0, 0, 0, 1, 64, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 120, 1, 0, 0, 0, 1, 64, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 121, 1, 0, 0, 0, 1, 64, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 122, 1, 0, 0, 0, 2, 0, 86, 105, 97, 118, 105, 46, 82, 97, 100, 105, 111, 46, 112, 111, 119, 101, 114, 1, 0, 0, 0, 2, 64, 86, 105, 97, 118, 105, 46, 82, 97, 100, 105, 111, 46, 115, 101, 99, 116, 111, 114, 115, 1, 0, 0, 0, 0, 0} //encode the variable part and append it to our array. @@ -176,41 +203,75 @@ func encode_action_format2() clientmodel.ActionDefinition { return format2 } -func encode_action_format3() clientmodel.ActionDefinition { +func encode_action_format3(meid string) clientmodel.ActionDefinition { var format3 []int64 //for simulation-by measId(not supported in Viavi 1.4) //format3=[]int64{0,1,3,64,0,29,32,0,90,0,0,16,0,0,16,0,91,0,0,16,0,0,16,0,3,0,0,16,0,0,16,0,4,0,0,16,0,0,16,0,80,0,0,16,0,0,16,0,13,0,0,16,0,0,16,0,14,0,0,16,0,0,16,0,92,0,0,16,0,0,16,0,93,0,0,16,0,0,16,0,44,0,0,16,0,0,16,0,40,0,0,16,0,0,16,0,41,0,0,16,0,0,16,0,42,0,0,16,0,0,16,0,94,0,0,16,0,0,16,0,95,0,0,16,0,0,16,0,96,0,0,16,0,0,16,0,97,0,0,16,0,0,16,0,45,0,0,16,0,0,16,0,98,0,0,16,0,0,16,0,99,0,0,16,0,0,16,0,100,0,0,16,0,0,16,0,101,0,0,16,0,0,16,0,102,0,0,16,0,0,16,0,103,0,0,16,0,0,16,0,104,0,0,16,0,0,16,0,43,0,0,16,0,0,16,0,105,0,0,16,0,0,16,0,106,0,0,16,0,0,16,0,107,0,0,16,0,0,16,0,108,0,0,16,0,0,32,39,15} //variable part is not presetnt in action def format 3 + + link:="http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/" + link=link+meid + tmpr,err := http.Get(link) + if err != nil { + log.Fatalln(err) + l:=[]int64{0} + return l + + } + defer tmpr.Body.Close() + var resp E2mgrResponse + + err=json.NewDecoder(tmpr.Body).Decode(&resp) + if err != nil { + log.Fatalln(err) + l:=[]int64{0} + return l + + } + 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 + // Call the C function + determine := 4 //2 for format1 by name + + result:=C.encode_action_Definition(cString, C.int(determine)) + for i := 0; i < int(result.length); i++ { + value := int64(*(*int64)(unsafe.Pointer(uintptr(unsafe.Pointer(result.array)) + uintptr(i*8)))) + format3 = append(format3, value) + + } - //for simulation-by measName(supported in Viavi 1.4) - format3 = []int64{0, 1, 3, 64, 0, 29, 0, 160, 68, 82, 66, 46, 85, 69, 67, 113, 105, 68, 108, 0, 0, 16, 0, 0, 0, 80, 68, 82, 66, 46, 85, 69, 67, 113, 105, 85, 108, 0, 0, 16, 0, 0, 0, 80, 68, 82, 66, 46, 85, 69, 84, 104, 112, 68, 108, 0, 0, 16, 0, 0, 0, 80, 68, 82, 66, 46, 85, 69, 84, 104, 112, 85, 108, 0, 0, 16, 0, 0, 0, 200, 81, 111, 115, 70, 108, 111, 119, 46, 84, 111, 116, 80, 100, 99, 112, 80, 100, 117, 86, 111, 108, 117, 109, 101, 68, 108, 0, 0, 16, 0, 0, 0, 96, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 68, 108, 0, 0, 16, 0, 0, 0, 96, 82, 82, 85, 46, 80, 114, 98, 85, 115, 101, 100, 85, 108, 0, 0, 16, 0, 0, 0, 80, 84, 66, 46, 84, 111, 116, 78, 98, 114, 68, 108, 0, 0, 16, 0, 0, 0, 80, 84, 66, 46, 84, 111, 116, 78, 98, 114, 85, 108, 0, 0, 16, 0, 0, 0, 96, 86, 105, 97, 118, 105, 46, 67, 101, 108, 108, 46, 105, 100, 0, 0, 16, 0, 0, 0, 80, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 120, 0, 0, 16, 0, 0, 0, 80, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 121, 0, 0, 16, 0, 0, 0, 80, 86, 105, 97, 118, 105, 46, 71, 101, 111, 46, 122, 0, 0, 16, 0, 0, 0, 96, 86, 105, 97, 118, 105, 46, 81, 111, 83, 46, 53, 113, 105, 0, 0, 16, 0, 0, 0, 120, 86, 105, 97, 118, 105, 46, 81, 111, 83, 46, 67, 101, 108, 108, 73, 100, 0, 0, 16, 0, 0, 0, 112, 86, 105, 97, 118, 105, 46, 81, 111, 83, 46, 68, 114, 98, 73, 100, 0, 0, 16, 0, 0, 0, 104, 86, 105, 97, 118, 105, 46, 81, 111, 83, 46, 71, 102, 98, 114, 0, 0, 16, 0, 0, 0, 104, 86, 105, 97, 118, 105, 46, 83, 108, 105, 99, 101, 46, 105, 100, 0, 0, 16, 0, 0, 0, 112, 86, 105, 97, 118, 105, 46, 85, 69, 46, 66, 101, 97, 109, 73, 100, 0, 0, 16, 0, 0, 0, 128, 86, 105, 97, 118, 105, 46, 85, 69, 46, 70, 114, 97, 109, 101, 67, 110, 116, 0, 0, 16, 0, 0, 0, 112, 86, 105, 97, 118, 105, 46, 85, 69, 46, 82, 115, 83, 105, 110, 114, 0, 0, 16, 0, 0, 0, 96, 86, 105, 97, 118, 105, 46, 85, 69, 46, 82, 115, 114, 112, 0, 0, 16, 0, 0, 0, 96, 86, 105, 97, 118, 105, 46, 85, 69, 46, 82, 115, 114, 113, 0, 0, 16, 0, 0, 0, 112, 86, 105, 97, 118, 105, 46, 85, 69, 46, 84, 99, 82, 110, 116, 105, 0, 0, 16, 0, 0, 0, 136, 86, 105, 97, 118, 105, 46, 85, 69, 46, 97, 110, 111, 109, 97, 108, 105, 101, 115, 0, 0, 16, 0, 0, 0, 80, 86, 105, 97, 118, 105, 46, 85, 69, 46, 105, 100, 0, 0, 16, 0, 0, 0, 184, 86, 105, 97, 118, 105, 46, 85, 69, 46, 115, 101, 114, 118, 105, 110, 103, 68, 105, 115, 116, 97, 110, 99, 101, 0, 0, 16, 0, 0, 0, 104, 86, 105, 97, 118, 105, 46, 85, 69, 46, 115, 112, 101, 101, 100, 0, 0, 16, 0, 0, 0, 208, 86, 105, 97, 118, 105, 46, 85, 69, 46, 116, 97, 114, 103, 101, 116, 84, 104, 114, 111, 117, 103, 104, 112, 117, 116, 68, 108, 0, 0, 16, 0, 0, 0, 208, 86, 105, 97, 118, 105, 46, 85, 69, 46, 116, 97, 114, 103, 101, 116, 84, 104, 114, 111, 117, 103, 104, 112, 117, 116, 85, 108, 0, 0, 16, 0, 0, 32, 39, 15} - - //variable part is not presetnt in action def format 3 - //for e2test - //format3=[]int64{0,1,3,64,0,62,32,0,43,0,0,16,0,0,16,0,44,0,0,16,0,0,16,0,45,0,0,16,0,0,16,0,3,0,0,16,0,0,16,0,4,0,0,16,0,0,16,0,13,0,0,16,0,0,16,0,14,0,0,16,0,0,16,0,46,0,0,16,0,0,16,0,47,0,0,16,0,0,16,0,48,0,0,16,0,0,16,0,49,0,0,16,0,0,16,0,50,0,0,16,0,0,16,0,51,0,0,16,0,0,16,0,52,0,0,16,0,0,16,0,53,0,0,16,0,0,16,0,54,0,0,16,0,0,16,0,55,0,0,16,0,0,16,0,56,0,0,16,0,0,16,0,57,0,0,16,0,0,16,0,58,0,0,16,0,0,16,0,59,0,0,16,0,0,16,0,60,0,0,16,0,0,16,0,61,0,0,16,0,0,16,0,62,0,0,16,0,0,16,0,63,0,0,16,0,0,16,0,64,0,0,16,0,0,16,0,65,0,0,16,0,0,16,0,66,0,0,16,0,0,16,0,67,0,0,16,0,0,16,0,68,0,0,16,0,0,16,0,69,0,0,16,0,0,16,0,70,0,0,16,0,0,16,0,71,0,0,16,0,0,16,0,72,0,0,16,0,0,16,0,73,0,0,16,0,0,16,0,74,0,0,16,0,0,16,0,75,0,0,16,0,0,16,0,76,0,0,16,0,0,16,0,77,0,0,16,0,0,16,0,27,0,0,16,0,0,16,0,19,0,0,16,0,0,16,0,26,0,0,16,0,0,16,0,39,0,0,16,0,0,16,0,15,0,0,16,0,0,16,0,16,0,0,16,0,0,16,0,17,0,0,16,0,0,16,0,18,0,0,16,0,0,16,0,20,0,0,16,0,0,16,0,21,0,0,16,0,0,16,0,22,0,0,16,0,0,16,0,23,0,0,16,0,0,16,0,28,0,0,16,0,0,16,0,29,0,0,16,0,0,16,0,30,0,0,16,0,0,16,0,31,0,0,16,0,0,16,0,32,0,0,16,0,0,16,0,33,0,0,16,0,0,16,0,34,0,0,16,0,0,16,0,35,0,0,16,0,0,16,0,36,0,0,16,0,0,16,0,40,0,0,16,0,0,16,0,41,0,0,16,0,0,16,0,42,0,0,16,0,0,32,39,15} //variable part is not presetnt in action def format 3 return format3 } func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { var l clientmodel.ActionsToBeSetup - link := "http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/" - link = link + meid - tmpr, err := http.Get(link) + link:="http://service-ricplt-e2mgr-http.ricplt.svc.cluster.local:3800/v1/nodeb/" + link=link+meid + tmpr,err := http.Get(link) if err != nil { - log.Fatalln(err) - return l + log.Fatalln(err) + return l } defer tmpr.Body.Close() var resp E2mgrResponse - - err = json.NewDecoder(tmpr.Body).Decode(&resp) + + err=json.NewDecoder(tmpr.Body).Decode(&resp) if err != nil { - log.Fatalln(err) - return l - } + log.Fatalln(err) + return l + } + counter := 0 for i := 0; i < len(resp.Gnb.NodeConfigs); i++ { if resp.Gnb.NodeConfigs[i].E2nodeComponentInterfaceType == "f1" { @@ -222,7 +283,7 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { base64Text := make([]byte, base64.StdEncoding.DecodedLen(len(tm))) nl, _ := base64.StdEncoding.Decode(base64Text, []byte(tm)) message := string(base64Text[:nl]) - + counter = 0 for i := 0; i < len(meid); i++ { if meid[i] == '_' { @@ -233,14 +294,14 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { break } } - + ans := strings.ToUpper(meid[counter:len(meid)]) l1 := int64(len(message)) l2 := int64(len(ans)) var cells []string for i := int64(0); i <= l1-l2; i++ { if strings.Contains(message[i:i+l2], ans) { - Glob_cell[message[i:i+10]] = true + Glob_cell[message[i:i+10]]=true cells = append(cells, message[i:i+10]) fmt.Println(message[i : i+10]) } @@ -256,8 +317,8 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { s := clientmodel.ActionToBeSetup{ ActionID: lol, ActionType: &actionType, - ActionDefinition: encode_action_format1(resp.GlobalNbId.PlmnId, cells[n-1]), - SubsequentAction: &clientmodel.SubsequentAction{ + ActionDefinition: encode_action_format1(resp.GlobalNbId.PlmnId, cells[n-1],meid), + SubsequentAction: &clientmodel.SubsequentAction{ SubsequentActionType: &subsequentActionType, TimeToWait: &timeToWait, }, @@ -268,24 +329,24 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { } var tmp_act_id int64 = n /* - n = 1 - // for action def 2 - for n <= ue { - var tmp int64 = tmp_act_id - var lol *int64 = &tmp - s := clientmodel.ActionToBeSetup{ - ActionID: lol, - ActionType: &actionType, - ActionDefinition: encode_action_format2(), - SubsequentAction: &clientmodel.SubsequentAction{ - SubsequentActionType: &subsequentActionType, - TimeToWait: &timeToWait, - }, - } - l = append(l, &s) - tmp_act_id = tmp_act_id + 1 - n = n + 1 + n = 1 + // for action def 2 + for n <= ue { + var tmp int64 = tmp_act_id + var lol *int64 = &tmp + s := clientmodel.ActionToBeSetup{ + ActionID: lol, + ActionType: &actionType, + ActionDefinition: encode_action_format2(), + SubsequentAction: &clientmodel.SubsequentAction{ + SubsequentActionType: &subsequentActionType, + TimeToWait: &timeToWait, + }, } + l = append(l, &s) + tmp_act_id = tmp_act_id + 1 + n = n + 1 + } */ //for action def 3 @@ -294,8 +355,8 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { s := clientmodel.ActionToBeSetup{ ActionID: lol, ActionType: &actionType, - ActionDefinition: encode_action_format3(), - SubsequentAction: &clientmodel.SubsequentAction{ + ActionDefinition: encode_action_format3(meid), + SubsequentAction: &clientmodel.SubsequentAction{ SubsequentActionType: &subsequentActionType, TimeToWait: &timeToWait, }, @@ -308,35 +369,35 @@ func encode_actionsToBeSetup(meid string) clientmodel.ActionsToBeSetup { func (c Control) sendSubscription(meid string) { //Create Subscription message and send it to RIC platform xapp.Logger.Info("Sending subscription request for MEID: %v", meid) - /* - subscritionParams := clientmodel.SubscriptionParams{ - ClientEndpoint: &clientEndpoint, - Meid: &meid, - RANFunctionID: &funcId, - SubscriptionDetails: clientmodel.SubscriptionDetailsList{ - &clientmodel.SubscriptionDetail{ - EventTriggers: clientmodel.EventTriggerDefinition{ - 8,39,15, - }, - XappEventInstanceID: &seqId, - ActionToBeSetupList: clientmodel.ActionsToBeSetup{ - &clientmodel.ActionToBeSetup{ - ActionID: &actionId, - ActionType: &actionType, - ActionDefinition: clientmodel.ActionDefinition{ - 5678, - }, - SubsequentAction: &clientmodel.SubsequentAction{ - SubsequentActionType: &subsequentActionType, - TimeToWait: &timeToWait, - }, +/* + subscritionParams := clientmodel.SubscriptionParams{ + ClientEndpoint: &clientEndpoint, + Meid: &meid, + RANFunctionID: &funcId, + SubscriptionDetails: clientmodel.SubscriptionDetailsList{ + &clientmodel.SubscriptionDetail{ + EventTriggers: clientmodel.EventTriggerDefinition{ + 8,39,15, + }, + XappEventInstanceID: &seqId, + ActionToBeSetupList: clientmodel.ActionsToBeSetup{ + &clientmodel.ActionToBeSetup{ + ActionID: &actionId, + ActionType: &actionType, + ActionDefinition: clientmodel.ActionDefinition{ + 5678, + }, + SubsequentAction: &clientmodel.SubsequentAction{ + SubsequentActionType: &subsequentActionType, + TimeToWait: &timeToWait, }, }, }, }, - } + }, + } */ - + //8,39,15, for 10000 ms reporting period subscritionParams := clientmodel.SubscriptionParams{ ClientEndpoint: &clientEndpoint, @@ -345,7 +406,7 @@ func (c Control) sendSubscription(meid string) { SubscriptionDetails: clientmodel.SubscriptionDetailsList{ &clientmodel.SubscriptionDetail{ EventTriggers: clientmodel.EventTriggerDefinition{ - 8, 39, 15, + 8,39,15, }, XappEventInstanceID: &seqId, ActionToBeSetupList: encode_actionsToBeSetup(meid), @@ -368,188 +429,192 @@ func (c Control) sendSubscription(meid string) { } func Test() (err error) { - var e2ap *E2ap - //var e2sm *E2sm + var e2ap *E2ap + //var e2sm *E2sm - //indicationMsg, err := e2ap.GetIndicationMessage(params.Payload) + //indicationMsg, err := e2ap.GetIndicationMessage(params.Payload) indicationMsg, err := e2ap.GetIndicationM() - if err != nil { - xapp.Logger.Error("Failed to decode RIC Indication message: %v", err) - return - } - - //log.Printf("RIC Indication message from {%s} received", params.Meid.RanName) - /* - indicationHdr, err := e2sm.GetIndicationHeader(indicationMsg.IndHeader) - if err != nil { - xapp.Logger.Error("Failed to decode RIC Indication Header: %v", err) - return - } - */ - - //Decoding message and put information into log - log.Printf("-----------RIC Indication Header-----------") + if err != nil { + xapp.Logger.Error("Failed to decode RIC Indication message: %v", err) + return + } + + //log.Printf("RIC Indication message from {%s} received", params.Meid.RanName) + /* + indicationHdr, err := e2sm.GetIndicationHeader(indicationMsg.IndHeader) + if err != nil { + xapp.Logger.Error("Failed to decode RIC Indication Header: %v", err) + return + } + */ + + //Decoding message and put information into log + log.Printf("-----------RIC Indication Header-----------") log.Printf("indicationMsg.IndHeader= %x", indicationMsg.IndHeader) - /* - buf := new(bytes.Buffer) //create my buffer - binary.Write(buf, binary.LittleEndian, indicationMsg.IndHeader) - log.Printf("binary Write buf= %x",buf ) - b := buf.Bytes() - //str := buf.String() - //log.Printf(" buf Strin()= %s",str ) - //cptr1:= unsafe.Pointer(C.CString(str)) - cptr1:= unsafe.Pointer(&b[0]) - defer C.free(cptr1) - */ - cptr1 := unsafe.Pointer(&indicationMsg.IndHeader[0]) - decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(indicationMsg.IndHeader))) +/* + buf := new(bytes.Buffer) //create my buffer + binary.Write(buf, binary.LittleEndian, indicationMsg.IndHeader) + log.Printf("binary Write buf= %x",buf ) + b := buf.Bytes() + //str := buf.String() + //log.Printf(" buf Strin()= %s",str ) + //cptr1:= unsafe.Pointer(C.CString(str)) + cptr1:= unsafe.Pointer(&b[0]) + defer C.free(cptr1) +*/ + cptr1 := unsafe.Pointer(&indicationMsg.IndHeader[0]) + decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(indicationMsg.IndHeader))) //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(str))) //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(buf.Len())) - if decodedHdr == nil { - return errors.New("e2sm wrapper is unable to get IndicationHeader due to wrong or invalid input") - } - defer C.e2sm_free_ric_indication_header(decodedHdr) - IndHdrType := int32(decodedHdr.indicationHeader_formats.present) - if IndHdrType == 0 { - log.Printf("No Indication Header present") - } - if IndHdrType == 1 { - log.Printf("Indication Header format = %d", IndHdrType) - indHdrFormat1_C := *(**C.E2SM_KPM_IndicationHeader_Format1_t)(unsafe.Pointer(&decodedHdr.indicationHeader_formats.choice[0])) - //senderName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderName)) - senderName_C := indHdrFormat1_C.senderName - var senderName []byte - senderName = C.GoBytes(unsafe.Pointer(senderName_C.buf), C.int(senderName_C.size)) - log.Printf("Sender Name = %x", senderName) + if decodedHdr == nil { + return errors.New("e2sm wrapper is unable to get IndicationHeader due to wrong or invalid input") + } + defer C.e2sm_free_ric_indication_header(decodedHdr) + IndHdrType := int32(decodedHdr.indicationHeader_formats.present) + if IndHdrType==0{ + log.Printf("No Indication Header present") + } + if IndHdrType==1{ + log.Printf("Indication Header format = %d",IndHdrType) + indHdrFormat1_C := *(**C.E2SM_KPM_IndicationHeader_Format1_t)(unsafe.Pointer(&decodedHdr.indicationHeader_formats.choice[0])) + //senderName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderName)) + senderName_C:=indHdrFormat1_C.senderName + var senderName []byte + senderName = C.GoBytes(unsafe.Pointer(senderName_C.buf), C.int(senderName_C.size)) + log.Printf("Sender Name = %x",senderName) + + //senderType_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderType)) + senderType_C :=indHdrFormat1_C.senderType + //senderType []byte + senderType := C.GoBytes(unsafe.Pointer(senderType_C.buf), C.int(senderType_C.size)) + log.Printf("Sender Type = %x",senderType) + + //vendorName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.vendorName)) + vendorName_C :=indHdrFormat1_C.vendorName + //vendorName []byte + vendorName := C.GoBytes(unsafe.Pointer(vendorName_C.buf), C.int(vendorName_C.size)) + log.Printf("Vendor Name = %x",vendorName) + + + } + + /* + indMsg, err := e2sm.GetIndicationMessage(indicationMsg.IndMessage) + if err != nil { + xapp.Logger.Error("Failed to decode RIC Indication Message: %v", err) + return + } + */ + log.Printf("-----------RIC Indication Message-----------") + log.Printf("indicationMsg.IndMessage= %x",indicationMsg.IndMessage) + cptr2 := unsafe.Pointer(&indicationMsg.IndMessage[0]) + indicationmessage := C.e2sm_decode_ric_indication_message(cptr2, C.size_t(len(indicationMsg.IndMessage))) + if indicationmessage == nil { + return errors.New("e2sm wrapper is unable to get IndicationMessage due to wrong or invalid input") + } + defer C.e2sm_free_ric_indication_message(indicationmessage) + IndMsgType := int32(indicationmessage.indicationMessage_formats.present) + if IndMsgType==1 {//parsing cell metrics + fmt.Printf(" parsing for cell metrics\n" ) + indMsgFormat1_C := *(**C.E2SM_KPM_IndicationMessage_Format1_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) + no_of_cell:=int32(indMsgFormat1_C .measData.list.count) + fmt.Printf(" \n No of cell = %d\n",no_of_cell ) + //fmt.Println(no_of_cell) + for n := int32(0); n < no_of_cell; n++ { + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat1_C.measData.list.array)) + (uintptr)(int(n))*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + no_of_cell_metrics:=int32(MeasurementDataItem_C.measRecord.list.count) + var CellM CellMetricsEntry + v := reflect.ValueOf(CellM) + fmt.Printf(" \n No of cell metrics = %d\n",no_of_cell_metrics) + values := make(map[string]interface{}, v.NumField()) + //assert no_of_cell_metrics == v.NumField() they both should be equal. + for i := int32(0); i < no_of_cell_metrics; i++ { + //fmt.Println(i) + if v.Field(int(i)).CanInterface() { + var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t + MeasurementRecordItem_C:=*(**C. MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(int(i))*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) + type_var:=int(MeasurementRecordItem_C.present) + if type_var==1{ + var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=int32(*cast_integer) + }else if type_var==2{ + var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=float64(*cast_float) + }else{ + fmt.Printf("Wrong Data Type") + } + + }else { + fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + } + }//end of inner for loop + + + fmt.Println(values) + fmt.Printf("Parsing Cell Metric Done") + //c.writeCellMetrics_db(&values)//push cellmetrics map entry to database. + }//end of outer for loop + //end of if IndMsgType==1 , parsing cell metrics done + + } else if IndMsgType==2 { //parsing ue metrics + + fmt.Printf(" parsing for UE metrics" ) + indMsgFormat2_C := *(**C.E2SM_KPM_IndicationMessage_Format2_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) + no_of_ue_metrics:=int32(indMsgFormat2_C .measData.list.count) + fmt.Printf(" \n No of ue metrics = %d\n",no_of_ue_metrics) + + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(0)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + + no_of_ue:=int32(MeasurementDataItem_C.measRecord.list.count) + fmt.Printf(" \n No of ue= %d\n",no_of_ue) + for n := int32(0); n < no_of_ue; n++ { + var UeM UeMetricsEntry + v := reflect.ValueOf(UeM) + values := make(map[string]interface{}, v.NumField()) + //assert no_of_ue_metrics == v.NumField() they both should be equal. + for i := int32(0); i < no_of_ue_metrics; i++ { + //fmt.Println(i) + if v.Field(int(i)).CanInterface() { - //senderType_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderType)) - senderType_C := indHdrFormat1_C.senderType - //senderType []byte - senderType := C.GoBytes(unsafe.Pointer(senderType_C.buf), C.int(senderType_C.size)) - log.Printf("Sender Type = %x", senderType) + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(i)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t + MeasurementRecordItem_C:=*(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(n)*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - //vendorName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.vendorName)) - vendorName_C := indHdrFormat1_C.vendorName - //vendorName []byte - vendorName := C.GoBytes(unsafe.Pointer(vendorName_C.buf), C.int(vendorName_C.size)) - log.Printf("Vendor Name = %x", vendorName) + type_var:=int(MeasurementRecordItem_C.present) + if type_var==1{ + var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=int32(*cast_integer) + }else if type_var==2{ + var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=float64(*cast_float) - } + }else{ + fmt.Printf("Wrong Data Type") + } - /* - indMsg, err := e2sm.GetIndicationMessage(indicationMsg.IndMessage) - if err != nil { - xapp.Logger.Error("Failed to decode RIC Indication Message: %v", err) - return - } - */ - log.Printf("-----------RIC Indication Message-----------") - log.Printf("indicationMsg.IndMessage= %x", indicationMsg.IndMessage) - cptr2 := unsafe.Pointer(&indicationMsg.IndMessage[0]) - indicationmessage := C.e2sm_decode_ric_indication_message(cptr2, C.size_t(len(indicationMsg.IndMessage))) - if indicationmessage == nil { - return errors.New("e2sm wrapper is unable to get IndicationMessage due to wrong or invalid input") - } - defer C.e2sm_free_ric_indication_message(indicationmessage) - IndMsgType := int32(indicationmessage.indicationMessage_formats.present) - if IndMsgType == 1 { //parsing cell metrics - fmt.Printf(" parsing for cell metrics\n") - indMsgFormat1_C := *(**C.E2SM_KPM_IndicationMessage_Format1_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) - no_of_cell := int32(indMsgFormat1_C.measData.list.count) - fmt.Printf(" \n No of cell = %d\n", no_of_cell) - //fmt.Println(no_of_cell) - for n := int32(0); n < no_of_cell; n++ { - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat1_C.measData.list.array)) + (uintptr)(int(n))*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - no_of_cell_metrics := int32(MeasurementDataItem_C.measRecord.list.count) - var CellM CellMetricsEntry - v := reflect.ValueOf(CellM) - fmt.Printf(" \n No of cell metrics = %d\n", no_of_cell_metrics) - values := make(map[string]interface{}, v.NumField()) - //assert no_of_cell_metrics == v.NumField() they both should be equal. - for i := int32(0); i < no_of_cell_metrics; i++ { - //fmt.Println(i) - if v.Field(int(i)).CanInterface() { - var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t - MeasurementRecordItem_C := *(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(int(i))*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - type_var := int(MeasurementRecordItem_C.present) - if type_var == 1 { - var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = int32(*cast_integer) - } else if type_var == 2 { - var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = float64(*cast_float) - } else { - fmt.Printf("Wrong Data Type") - } - - } else { - fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) - } - } //end of inner for loop + }else { + fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + } - fmt.Println(values) - fmt.Printf("Parsing Cell Metric Done") - //c.writeCellMetrics_db(&values)//push cellmetrics map entry to database. - } //end of outer for loop - //end of if IndMsgType==1 , parsing cell metrics done - - } else if IndMsgType == 2 { //parsing ue metrics - - fmt.Printf(" parsing for UE metrics") - indMsgFormat2_C := *(**C.E2SM_KPM_IndicationMessage_Format2_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) - no_of_ue_metrics := int32(indMsgFormat2_C.measData.list.count) - fmt.Printf(" \n No of ue metrics = %d\n", no_of_ue_metrics) - - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(0)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - - no_of_ue := int32(MeasurementDataItem_C.measRecord.list.count) - fmt.Printf(" \n No of ue= %d\n", no_of_ue) - for n := int32(0); n < no_of_ue; n++ { - var UeM UeMetricsEntry - v := reflect.ValueOf(UeM) - values := make(map[string]interface{}, v.NumField()) - //assert no_of_ue_metrics == v.NumField() they both should be equal. - for i := int32(0); i < no_of_ue_metrics; i++ { - //fmt.Println(i) - if v.Field(int(i)).CanInterface() { - - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(i)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t - MeasurementRecordItem_C := *(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(n)*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - - type_var := int(MeasurementRecordItem_C.present) - if type_var == 1 { - var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = int32(*cast_integer) - } else if type_var == 2 { - var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = float64(*cast_float) - - } else { - fmt.Printf("Wrong Data Type") - } - - } else { - fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) - } - } //end of inner for loop + } //end of inner for loop fmt.Println(values) - fmt.Printf("Parsing UE Metric Done") - //c.writeUeMetrics_db(&values)//push UEmetrics map entry to database. + fmt.Printf("Parsing UE Metric Done") + //c.writeUeMetrics_db(&values)//push UEmetrics map entry to database. - } // end of outer for loop - //parsing ue metrics done - } else { - fmt.Printf(" Invalid Indication message format") + }// end of outer for loop + //parsing ue metrics done + }else{ + fmt.Printf(" Invalid Indication message format" ) - } + } - return nil + + return nil } func (c *Control) controlLoop() { @@ -586,176 +651,180 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { //Decoding message and put information into log //log.Printf("-----------RIC Indication Header-----------") - //log.Printf("indicationMsg.IndHeader= %x", indicationMsg.IndHeader) - /* - buf := new(bytes.Buffer) //create my buffer - binary.Write(buf, binary.LittleEndian, indicationMsg.IndHeader) - log.Printf("binary Write buf= %x",buf ) - b := buf.Bytes() - //str := buf.String() - //log.Printf(" buf Strin()= %s",str ) - //cptr1:= unsafe.Pointer(C.CString(str)) - cptr1:= unsafe.Pointer(&b[0]) - defer C.free(cptr1) - */ - cptr1 := unsafe.Pointer(&indicationMsg.IndHeader[0]) - decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(indicationMsg.IndHeader))) - //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(str))) - //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(buf.Len())) - if decodedHdr == nil { - return errors.New("e2sm wrapper is unable to get IndicationHeader due to wrong or invalid input") - } - defer C.e2sm_free_ric_indication_header(decodedHdr) - IndHdrType := int32(decodedHdr.indicationHeader_formats.present) - if IndHdrType == 0 { - log.Printf("No Indication Header present") - } - if IndHdrType == 1 { - log.Printf("Indication Header format = %d", IndHdrType) + //log.Printf("indicationMsg.IndHeader= %x", indicationMsg.IndHeader) +/* + buf := new(bytes.Buffer) //create my buffer + binary.Write(buf, binary.LittleEndian, indicationMsg.IndHeader) + log.Printf("binary Write buf= %x",buf ) + b := buf.Bytes() + //str := buf.String() + //log.Printf(" buf Strin()= %s",str ) + //cptr1:= unsafe.Pointer(C.CString(str)) + cptr1:= unsafe.Pointer(&b[0]) + defer C.free(cptr1) +*/ + cptr1 := unsafe.Pointer(&indicationMsg.IndHeader[0]) + decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(indicationMsg.IndHeader))) + //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(len(str))) + //decodedHdr := C.e2sm_decode_ric_indication_header(cptr1, C.size_t(buf.Len())) + if decodedHdr == nil { + return errors.New("e2sm wrapper is unable to get IndicationHeader due to wrong or invalid input") + } + defer C.e2sm_free_ric_indication_header(decodedHdr) + IndHdrType := int32(decodedHdr.indicationHeader_formats.present) + if IndHdrType==0{ + log.Printf("No Indication Header present") + } + if IndHdrType==1{ + log.Printf("Indication Header format = %d",IndHdrType) /* - indHdrFormat1_C := *(**C.E2SM_KPM_IndicationHeader_Format1_t)(unsafe.Pointer(&decodedHdr.indicationHeader_formats.choice[0])) - //senderName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderName)) - senderName_C:=indHdrFormat1_C.senderName - var senderName []byte - senderName = C.GoBytes(unsafe.Pointer(senderName_C.buf), C.int(senderName_C.size)) - //log.Printf("Sender Name = %x",senderName) - - //senderType_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderType)) - senderType_C :=indHdrFormat1_C.senderType - //senderType []byte - senderType := C.GoBytes(unsafe.Pointer(senderType_C.buf), C.int(senderType_C.size)) - //log.Printf("Sender Type = %x",senderType) - - //vendorName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.vendorName)) - vendorName_C :=indHdrFormat1_C.vendorName - //vendorName []byte - vendorName := C.GoBytes(unsafe.Pointer(vendorName_C.buf), C.int(vendorName_C.size)) - //log.Printf("Vendor Name = %x",vendorName) + indHdrFormat1_C := *(**C.E2SM_KPM_IndicationHeader_Format1_t)(unsafe.Pointer(&decodedHdr.indicationHeader_formats.choice[0])) + //senderName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderName)) + senderName_C:=indHdrFormat1_C.senderName + var senderName []byte + senderName = C.GoBytes(unsafe.Pointer(senderName_C.buf), C.int(senderName_C.size)) + //log.Printf("Sender Name = %x",senderName) + + //senderType_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.senderType)) + senderType_C :=indHdrFormat1_C.senderType + //senderType []byte + senderType := C.GoBytes(unsafe.Pointer(senderType_C.buf), C.int(senderType_C.size)) + //log.Printf("Sender Type = %x",senderType) + + //vendorName_C := (*C.PrintableString_t)(unsafe.Pointer(indHdrFormat1_C.vendorName)) + vendorName_C :=indHdrFormat1_C.vendorName + //vendorName []byte + vendorName := C.GoBytes(unsafe.Pointer(vendorName_C.buf), C.int(vendorName_C.size)) + //log.Printf("Vendor Name = %x",vendorName) */ - } - - /* - indMsg, err := e2sm.GetIndicationMessage(indicationMsg.IndMessage) - if err != nil { - xapp.Logger.Error("Failed to decode RIC Indication Message: %v", err) - return - } - */ - //log.Printf("-----------RIC Indication Message-----------") - //log.Printf("indicationMsg.IndMessage= %x",indicationMsg.IndMessage) - cptr2 := unsafe.Pointer(&indicationMsg.IndMessage[0]) - indicationmessage := C.e2sm_decode_ric_indication_message(cptr2, C.size_t(len(indicationMsg.IndMessage))) - if indicationmessage == nil { - return errors.New("e2sm wrapper is unable to get IndicationMessage due to wrong or invalid input") - } - defer C.e2sm_free_ric_indication_message(indicationmessage) - IndMsgType := int32(indicationmessage.indicationMessage_formats.present) - if IndMsgType == 1 { //parsing cell metrics - fmt.Printf(" parsing for cell metrics\n") - indMsgFormat1_C := *(**C.E2SM_KPM_IndicationMessage_Format1_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) - no_of_cell := int32(indMsgFormat1_C.measData.list.count) - fmt.Printf(" \n No of cell = %d\n", no_of_cell) - //fmt.Println(no_of_cell) - for n := int32(0); n < no_of_cell; n++ { - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat1_C.measData.list.array)) + (uintptr)(int(n))*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - no_of_cell_metrics := int32(MeasurementDataItem_C.measRecord.list.count) - var CellM CellMetricsEntry - v := reflect.ValueOf(CellM) - fmt.Printf(" \n No of cell metrics = %d\n", no_of_cell_metrics) - values := make(map[string]interface{}, v.NumField()) - //assert no_of_cell_metrics == v.NumField() they both should be equal. - if int(no_of_cell_metrics) != v.NumField() { - log.Printf("no_of_cell_metrics != v.NumField()") - return errors.New("no_of_cell_metrics != v.NumField()") - } - for i := int32(0); i < no_of_cell_metrics; i++ { - //fmt.Println(i) - if v.Field(int(i)).CanInterface() { - var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t - MeasurementRecordItem_C := *(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(int(i))*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - type_var := int(MeasurementRecordItem_C.present) - if type_var == 1 { - var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = int32(*cast_integer) - } else if type_var == 2 { - var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = float64(*cast_float) - } else { - fmt.Printf("Wrong Data Type") - } - - } else { - fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + } + + /* + indMsg, err := e2sm.GetIndicationMessage(indicationMsg.IndMessage) + if err != nil { + xapp.Logger.Error("Failed to decode RIC Indication Message: %v", err) + return + } + */ + //log.Printf("-----------RIC Indication Message-----------") + //log.Printf("indicationMsg.IndMessage= %x",indicationMsg.IndMessage) + cptr2 := unsafe.Pointer(&indicationMsg.IndMessage[0]) + indicationmessage := C.e2sm_decode_ric_indication_message(cptr2, C.size_t(len(indicationMsg.IndMessage))) + if indicationmessage == nil { + return errors.New("e2sm wrapper is unable to get IndicationMessage due to wrong or invalid input") + } + defer C.e2sm_free_ric_indication_message(indicationmessage) + IndMsgType := int32(indicationmessage.indicationMessage_formats.present) + if IndMsgType==1 {//parsing cell metrics + fmt.Printf(" parsing for cell metrics\n" ) + indMsgFormat1_C := *(**C.E2SM_KPM_IndicationMessage_Format1_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) + no_of_cell:=int32(indMsgFormat1_C .measData.list.count) + fmt.Printf(" \n No of cell = %d\n",no_of_cell ) + //fmt.Println(no_of_cell) + for n := int32(0); n < no_of_cell; n++ { + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat1_C.measData.list.array)) + (uintptr)(int(n))*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + no_of_cell_metrics:=int32(MeasurementDataItem_C.measRecord.list.count) + var CellM CellMetricsEntry + v := reflect.ValueOf(CellM) + fmt.Printf(" \n No of cell metrics = %d\n",no_of_cell_metrics) + values := make(map[string]interface{}, v.NumField()) + //assert no_of_cell_metrics == v.NumField() they both should be equal. + if (int(no_of_cell_metrics) != v.NumField()){ + log.Printf("no_of_cell_metrics != v.NumField()") + return errors.New("no_of_cell_metrics != v.NumField()") } - } //end of inner for loop - - fmt.Println(values) - fmt.Printf("Parsing Cell Metric Done") - c.writeCellMetrics_db(&values) //push cellmetrics map entry to database. - } //end of outer for loop - //end of if IndMsgType==1 , parsing cell metrics done - - } else if IndMsgType == 2 { //parsing ue metrics - - fmt.Printf(" parsing for UE metrics") - indMsgFormat2_C := *(**C.E2SM_KPM_IndicationMessage_Format2_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) - no_of_ue_metrics := int32(indMsgFormat2_C.measData.list.count) - fmt.Printf(" \n No of ue metrics = %d\n", no_of_ue_metrics) - - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(0)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - - no_of_ue := int32(MeasurementDataItem_C.measRecord.list.count) - fmt.Printf(" \n No of ue= %d\n", no_of_ue) - for n := int32(0); n < no_of_ue; n++ { - var UeM UeMetricsEntry - v := reflect.ValueOf(UeM) - values := make(map[string]interface{}, v.NumField()) - //assert no_of_ue_metrics == v.NumField() they both should be equal. - if int(no_of_ue_metrics) != v.NumField() { - log.Printf("no_of_ue_metrics != v.NumField()") - return errors.New("no_of_ue_metrics != v.NumField()") - } - for i := int32(0); i < no_of_ue_metrics; i++ { - //fmt.Println(i) - if v.Field(int(i)).CanInterface() { - - var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t - MeasurementDataItem_C := *(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(i)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) - var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t - MeasurementRecordItem_C := *(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(n)*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - - type_var := int(MeasurementRecordItem_C.present) - if type_var == 1 { - var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = int32(*cast_integer) - } else if type_var == 2 { - var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) - values[v.Type().Field(int(i)).Name] = float64(*cast_float) - - } else { - fmt.Printf("Wrong Data Type") - } - - } else { - fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + for i := int32(0); i < no_of_cell_metrics; i++ { + //fmt.Println(i) + if v.Field(int(i)).CanInterface() { + var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t + MeasurementRecordItem_C:=*(**C. MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(int(i))*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) + type_var:=int(MeasurementRecordItem_C.present) + if type_var==1{ + var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=int32(*cast_integer) + }else if type_var==2{ + var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=float64(*cast_float) + }else{ + fmt.Printf("Wrong Data Type") + } + + }else { + fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + } + }//end of inner for loop + + + fmt.Println(values) + fmt.Printf("Parsing Cell Metric Done") + c.writeCellMetrics_db(&values)//push cellmetrics map entry to database. + }//end of outer for loop + //end of if IndMsgType==1 , parsing cell metrics done + + } else if IndMsgType==2 { //parsing ue metrics + + fmt.Printf(" parsing for UE metrics" ) + indMsgFormat2_C := *(**C.E2SM_KPM_IndicationMessage_Format2_t)(unsafe.Pointer(&indicationmessage.indicationMessage_formats.choice[0])) + no_of_ue_metrics:=int32(indMsgFormat2_C .measData.list.count) + fmt.Printf(" \n No of ue metrics = %d\n",no_of_ue_metrics) + + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(0)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + + no_of_ue:=int32(MeasurementDataItem_C.measRecord.list.count) + fmt.Printf(" \n No of ue= %d\n",no_of_ue) + for n := int32(0); n < no_of_ue; n++ { + var UeM UeMetricsEntry + v := reflect.ValueOf(UeM) + values := make(map[string]interface{}, v.NumField()) + //assert no_of_ue_metrics == v.NumField() they both should be equal. + if (int(no_of_ue_metrics) != v.NumField()){ + log.Printf("no_of_ue_metrics != v.NumField()") + return errors.New("no_of_ue_metrics != v.NumField()") } + for i := int32(0); i < no_of_ue_metrics; i++ { + //fmt.Println(i) + if v.Field(int(i)).CanInterface() { - } //end of inner for loop - fmt.Println(values) - fmt.Printf("Parsing UE Metric Done") - c.writeUeMetrics_db(&values) //push UEmetrics map entry to database. + var sizeof_MeasurementDataItem_t *C.MeasurementDataItem_t + MeasurementDataItem_C:=*(**C.MeasurementDataItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(indMsgFormat2_C.measData.list.array)) + (uintptr)(i)*unsafe.Sizeof(sizeof_MeasurementDataItem_t))) + var sizeof_MeasurementRecordItem_t *C.MeasurementRecordItem_t + MeasurementRecordItem_C:=*(**C.MeasurementRecordItem_t)(unsafe.Pointer(uintptr(unsafe.Pointer(MeasurementDataItem_C.measRecord.list.array)) + (uintptr)(n)*unsafe.Sizeof(sizeof_MeasurementRecordItem_t))) - } // end of outer for loop - //parsing ue metrics done - } else { - fmt.Printf(" Invalid Indication message format") + type_var:=int(MeasurementRecordItem_C.present) + if type_var==1{ + var cast_integer *C.long = (*C.long)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=int32(*cast_integer) + }else if type_var==2{ + var cast_float *C.double = (*C.double)(unsafe.Pointer(&MeasurementRecordItem_C.choice[0])) + values[v.Type().Field(int(i)).Name]=float64(*cast_float) - } + }else{ + fmt.Printf("Wrong Data Type") + } + + }else { + fmt.Printf("sorry you have a unexported field (lower case) value you are trying to sneak past. Can not allow it: %v\n", v.Type().Field(int(i)).Name) + } + + + } //end of inner for loop + fmt.Println(values) + fmt.Printf("Parsing UE Metric Done") + c.writeUeMetrics_db(&values)//push UEmetrics map entry to database. + + }// end of outer for loop + //parsing ue metrics done + }else{ + fmt.Printf(" Invalid Indication message format" ) + + } + + + return nil - return nil } @@ -858,14 +927,6 @@ func (c Control) xAppStartCB(d interface{}) { // Get eNodeB list nbList := c.getnbList() - for { - time.Sleep(5 * time.Second) - if xapp.IsRegistered() { - xapp.Logger.Info("App registration is done, ready to send subscription request.") - break - } - xapp.Logger.Debug("App registration is not done yet, sleep 5s and check again") - } // Send subscription request to connected NodeB for _, nb := range nbList { if nb.ConnectionStatus == 1 { @@ -875,8 +936,7 @@ func (c Control) xAppStartCB(d interface{}) { } } - - fmt.Println("len of Glob_cell= ", len(Glob_cell)) + fmt.Println("len of Glob_cell= ",len(Glob_cell)) fmt.Println("Glob_cell map = ", Glob_cell) go c.controlLoop() diff --git a/e2sm/wrapper.c b/e2sm/wrapper.c index 61ec30f..b2be196 100644 --- a/e2sm/wrapper.c +++ b/e2sm/wrapper.c @@ -2,28 +2,519 @@ #include "wrapper.h" #include +/* +static int write_out(const void *buffer, size_t size, void *app_key) { + FILE *out_fp = app_key; + size_t wrote = fwrite(buffer, 1, size, out_fp); + return (wrote == size) ? 0 :-1; +} +*/ + +//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){ + + encode_act_Def_result_t res; + 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 + + 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); + + long *id_format1; + long *id_format3; + 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; + id_format1=(long *)calloc(sz1,sizeof(long)); + name_format1=(char **)malloc(sz1*sizeof(char *)); + for(int j=0;jric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measID); + 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; + id_format3=(long *)calloc(sz3,sizeof(long)); + name_format3=(char **)malloc(sz3*sizeof(char *)); + for(int j=0;jric_ReportStyle_List->list.array[i]->measInfo_Action_List.list.array[j]->measID); + 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; + + } + + } -// int main() { -// long id[] = {1,2,3,4}; -// void *buffer[8] = {} ; -// unsigned int sizeBuffer = 8; -// long actionDefCount = 8; -// long measId = 1; -// long ricStyleType = 1; -// long periods = 1; -// void *plm[8] = {} ; -// unsigned int sizePlm = 8; -// void *nRc[8] = {} ; -// unsigned int sizenRc = 8; + } + + + } + else + { + printf("[INFO] E2SM KPM RAN Function Description decode failed rval.code = %d \n", rval.code); + } + printf("\n"); + printf("measID format 1\n"); + for(int i=0;ibuf=(uint8_t *)calloc(3,sizeof(uint8_t)); + memcpy(PLM->buf,p, 3); + PLM->size=3; + + + NRCellIdentity_t *NRC=(NRCellIdentity_t *)calloc(1,sizeof(NRCellIdentity_t)); + NRC->buf=(uint8_t *)calloc(5,sizeof(uint8_t)); + memcpy(NRC->buf,nR, 5); + NRC->size=5; + NRC->bits_unused=4; + + nrCGIs->pLMNIdentity=*PLM; + nrCGIs->nRCellIdentity=*NRC; + + cellGlobal->present = CGI_PR_nR_CGI; + cellGlobal->choice.nR_CGI = nrCGIs; + + + + + MeasurementInfoItem_t **infoItem = (MeasurementInfoItem_t **)calloc(measIdcount, sizeof(MeasurementInfoItem_t *)); + int Label_Item_count=1; + + long *no_label=(long *) calloc(1,sizeof(long));//not giving label to the cell metrics/// don't know its bheaviour + *no_label=0; + int index = 0; + int c=0; + while (index < measIdcount) { + + infoItem[index] = (MeasurementInfoItem_t *)calloc(1, sizeof(MeasurementInfoItem_t )); + MeasurementType_t *Mtype=(MeasurementType_t *)calloc(1,sizeof(MeasurementType_t)); + Mtype->present=MeasurementType_PR_measName; + Mtype->choice.measName.buf=(uint8_t *)calloc(strlen(id_tmp[index]),sizeof(uint8_t)); + memcpy(Mtype->choice.measName.buf,id_tmp[index], strlen(id_tmp[index])); + Mtype->choice.measName.size=strlen(id_tmp[index]); + + + infoItem[index]->measType=*Mtype; + + + LabelInfoItem_t **L_Item = (LabelInfoItem_t **)calloc(Label_Item_count, sizeof(LabelInfoItem_t *)); + MeasurementLabel_t *M_Label=(MeasurementLabel_t *)calloc(1,sizeof(MeasurementLabel_t)); + M_Label->noLabel=no_label; + L_Item[0] = (LabelInfoItem_t *)calloc(1, sizeof(LabelInfoItem_t )); + L_Item[0]->measLabel=*M_Label; + int result1 = ASN_SEQUENCE_ADD(&infoItem[index]->labelInfoList, L_Item[0]); + if (result1==-1) + { + fprintf(stderr,"Unable to assign memory to add labelInfoList %s",strerror(errno)); + return -1; + } + + int result2 = ASN_SEQUENCE_ADD(&actionDefFor1->measInfoList, infoItem[index]); + if (result2==-1) + { + fprintf(stderr,"Unable to assign memory to add measInfoList %s",strerror(errno)); + return -1; + } + + + index++; + } -// printf("%d", a); -// return 0; -// } + actionDefFor1->granulPeriod = granulPeriod; + actionDefFor1->cellGlobalID = cellGlobal; + + + actionDef->ric_Style_Type = ric_style_type; + actionDef->actionDefinition_formats.present = E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1; + actionDef->actionDefinition_formats.choice.actionDefinition_Format1 = actionDefFor1; + + + char errbuf[128]; + size_t errbuf_len = 128; + + int ret_constr = asn_check_constraints(&asn_DEF_E2SM_KPM_ActionDefinition, (void *) actionDef, errbuf, &errbuf_len); + if(ret_constr){ + fprintf(stderr,"Constraints failed for encoding subscription request, %s", strerror(errno)); + return -1; + } + //ATS_ALIGNED_BASIC_PER + //ATS_ALIGNED_CANONICAL_PER + //ATS_DER + asn_enc_rval_t encode_result = asn_encode_to_buffer(0,ATS_ALIGNED_CANONICAL_PER,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef, buf, *buf_size); + //asn_enc_rval_t encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL,actionDef, buf, *buf_size); + if (encode_result.encoded == -1) { + fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); + return -1; + } + else { + fprintf(stderr, "successfully\n"); + xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + /* + FILE *fp = fopen("sandeep.bin", "wb"); + + asn_enc_rval_t ec =asn_encode(0, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef, write_out, fp); + fclose(fp); + if(ec.encoded ==-1) { + fprintf(stderr, "Could not encode action def (at %s)\n”,ec.failed_type ? ec.failed_type->name : ”unknown"); + // exit(1); + } else { + fprintf(stderr, "Created sandeep binary with ATS_ALIGNED_CANONICAL_PER encoded action def\n"); + } + FILE *fp2 = fopen("sandy.txt", "w"); + int r=asn_fprint(fp2,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef); + fclose(fp2); + if (r==-1) + fprintf(stderr, "failed asn_fprint\n"); + else + fprintf(stderr, "successfull asn_fprint\n"); + */ + + + + return encode_result.encoded; + } +} + +size_t e2sm_encode_ric_action_definition_format1_by_id(unsigned char *buf, size_t *buf_size, long *id , size_t measIdcount, long ric_style_type, unsigned long granulPeriod, unsigned char *p, unsigned char *nR) { + E2SM_KPM_ActionDefinition_t *actionDef = (E2SM_KPM_ActionDefinition_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_t)); + if (!actionDef) { + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + E2SM_KPM_ActionDefinition_Format1_t *actionDefFor1 = (E2SM_KPM_ActionDefinition_Format1_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_Format1_t)); + if (!actionDefFor1) { + ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + CGI_t *cellGlobal = (CGI_t *)calloc(1, sizeof(CGI_t)); + if (!cellGlobal) { + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + NR_CGI_t *nrCGIs = (NR_CGI_t *)calloc(1, sizeof(NR_CGI_t)); + if (!nrCGIs) { + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + + PLMNIdentity_t *PLM=(PLMNIdentity_t *)calloc(1,sizeof(PLMNIdentity_t)); + PLM->buf=(uint8_t *)calloc(3,sizeof(uint8_t)); + memcpy(PLM->buf,p, 3); + PLM->size=3; + + + NRCellIdentity_t *NRC=(NRCellIdentity_t *)calloc(1,sizeof(NRCellIdentity_t)); + NRC->buf=(uint8_t *)calloc(5,sizeof(uint8_t)); + memcpy(NRC->buf,nR, 5); + NRC->size=5; + NRC->bits_unused=4; + + nrCGIs->pLMNIdentity=*PLM; + nrCGIs->nRCellIdentity=*NRC; + + cellGlobal->present = CGI_PR_nR_CGI; + cellGlobal->choice.nR_CGI = nrCGIs; + + + + + MeasurementInfoItem_t **infoItem = (MeasurementInfoItem_t **)calloc(measIdcount, sizeof(MeasurementInfoItem_t *)); + int Label_Item_count=1; + + long *no_label=(long *) calloc(1,sizeof(long));//not giving label to the cell metrics/// don't know its bheaviour + *no_label=0; + int index = 0; + while (index < measIdcount) { + + infoItem[index] = (MeasurementInfoItem_t *)calloc(1, sizeof(MeasurementInfoItem_t )); + MeasurementType_t *Mtype=(MeasurementType_t *)calloc(1,sizeof(MeasurementType_t)); + Mtype->present=MeasurementType_PR_measID; + Mtype->choice.measID = id[index]; + infoItem[index]->measType=*Mtype; + + + LabelInfoItem_t **L_Item = (LabelInfoItem_t **)calloc(Label_Item_count, sizeof(LabelInfoItem_t *)); + MeasurementLabel_t *M_Label=(MeasurementLabel_t *)calloc(1,sizeof(MeasurementLabel_t)); + M_Label->noLabel=no_label; + L_Item[0] = (LabelInfoItem_t *)calloc(1, sizeof(LabelInfoItem_t )); + L_Item[0]->measLabel=*M_Label; + int result1 = ASN_SEQUENCE_ADD(&infoItem[index]->labelInfoList, L_Item[0]); + if (result1==-1) + { + fprintf(stderr,"Unable to assign memory to add labelInfoList %s",strerror(errno)); + return -1; + } + + int result2 = ASN_SEQUENCE_ADD(&actionDefFor1->measInfoList, infoItem[index]); + if (result2==-1) + { + fprintf(stderr,"Unable to assign memory to add measInfoList %s",strerror(errno)); + return -1; + } + + + index++; + } + + + actionDefFor1->granulPeriod = granulPeriod; + actionDefFor1->cellGlobalID = cellGlobal; + + + actionDef->ric_Style_Type = ric_style_type; + actionDef->actionDefinition_formats.present = E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1; + actionDef->actionDefinition_formats.choice.actionDefinition_Format1 = actionDefFor1; + + + char errbuf[128]; + size_t errbuf_len = 128; + + int ret_constr = asn_check_constraints(&asn_DEF_E2SM_KPM_ActionDefinition, (void *) actionDef, errbuf, &errbuf_len); + if(ret_constr){ + fprintf(stderr,"Constraints failed for encoding subscription request, %s", strerror(errno)); + return -1; + } + //ATS_ALIGNED_BASIC_PER + //ATS_ALIGNED_CANONICAL_PER + //ATS_DER + asn_enc_rval_t encode_result = asn_encode_to_buffer(0,ATS_ALIGNED_CANONICAL_PER,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef, buf, *buf_size); + //asn_enc_rval_t encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL,actionDef, buf, *buf_size); + if (encode_result.encoded == -1) { + fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); + return -1; + } + else { + fprintf(stderr, "successfully\n"); + xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + /* + FILE *fp = fopen("sandeep.bin", "wb"); + + asn_enc_rval_t ec =asn_encode(0, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef, write_out, fp); + fclose(fp); + if(ec.encoded ==-1) { + fprintf(stderr, "Could not encode action def (at %s)\n”,ec.failed_type ? ec.failed_type->name : ”unknown"); + exit(1); + } else { + fprintf(stderr, "Created sandeep binary with ATS_ALIGNED_CANONICAL_PER encoded action def\n"); + } + FILE *fp2 = fopen("sandy.txt", "w"); + int r=asn_fprint(fp2,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef); + fclose(fp2); + if (r==-1) + fprintf(stderr, "failed asn_fprint\n"); + else + fprintf(stderr, "successfull asn_fprint\n"); + */ + + return encode_result.encoded; + } +} ssize_t e2sm_encode_ric_event_trigger_definition(void *buffer, size_t buf_size, size_t event_trigger_count, long *RT_periods) { E2SM_KPM_EventTriggerDefinition_t *eventTriggerDef = (E2SM_KPM_EventTriggerDefinition_t *)calloc(1, sizeof(E2SM_KPM_EventTriggerDefinition_t)); @@ -64,27 +555,225 @@ ssize_t e2sm_encode_ric_event_trigger_definition(void *buffer, size_t buf_size, return encode_result.encoded; } } -// int main() { +size_t e2sm_encode_ric_action_definition_format3_by_name(unsigned char *buf, size_t *buf_size, char **id_tmp , size_t measIdcount, long ric_style_type, unsigned long granulPeriod) { + E2SM_KPM_ActionDefinition_t *actionDef = (E2SM_KPM_ActionDefinition_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_t)); + if (!actionDef) { + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + E2SM_KPM_ActionDefinition_Format3_t *actionDefFor3 = (E2SM_KPM_ActionDefinition_Format3_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_Format3_t)); + if (!actionDefFor3) { + ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + + + MeasurementCondItem_t **CondItem = (MeasurementCondItem_t **)calloc(measIdcount, sizeof(MeasurementCondItem_t *)); + int Label_Item_count=1; + + long *no_label=(long *) calloc(1,sizeof(long));//not giving label to the cell metrics/// don't know its bheaviour + *no_label=0; + int index = 0; + while (index < measIdcount) { + + CondItem[index] = (MeasurementCondItem_t *)calloc(1, sizeof(MeasurementCondItem_t )); + MeasurementType_t *Mtype=(MeasurementType_t *)calloc(1,sizeof(MeasurementType_t)); + Mtype->present=MeasurementType_PR_measName; + Mtype->choice.measName.buf=(uint8_t *)calloc(strlen(id_tmp[index]),sizeof(uint8_t)); + memcpy(Mtype->choice.measName.buf,id_tmp[index], strlen(id_tmp[index])); + Mtype->choice.measName.size=strlen(id_tmp[index]); + CondItem[index]->measType=*Mtype; + + + + MatchingCondItem_t **M_Item = (MatchingCondItem_t **)calloc(Label_Item_count, sizeof(MatchingCondItem_t *)); + MeasurementLabel_t *M_Label=(MeasurementLabel_t *)calloc(1,sizeof(MeasurementLabel_t)); + M_Label->noLabel=no_label; + M_Item[0] = (MatchingCondItem_t *)calloc(1, sizeof(MatchingCondItem_t )); + M_Item[0]->present=MatchingCondItem_PR_measLabel; + M_Item[0]->choice.measLabel=M_Label; + int result1 = ASN_SEQUENCE_ADD(&CondItem[index]->matchingCond, M_Item[0]); + if (result1==-1) + { + fprintf(stderr,"Unable to assign memory for matchingCond to add matchingCondItem_t %s",strerror(errno)); + return -1; + } + + int result2 = ASN_SEQUENCE_ADD(&actionDefFor3->measCondList, CondItem[index]); + if (result2==-1) + { + fprintf(stderr,"Unable to assign memory for measCondList to add MeasurementCondItem_t %s",strerror(errno)); + return -1; + } + + + index++; + } + + + actionDefFor3->granulPeriod = granulPeriod; + + + actionDef->ric_Style_Type = ric_style_type; + actionDef->actionDefinition_formats.present = E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3; + actionDef->actionDefinition_formats.choice.actionDefinition_Format3 = actionDefFor3; + + + char errbuf[128]; + size_t errbuf_len = 128; + + int ret_constr = asn_check_constraints(&asn_DEF_E2SM_KPM_ActionDefinition, (void *) actionDef, errbuf, &errbuf_len); + if(ret_constr){ + fprintf(stderr,"Constraints failed for encoding subscription request, %s", strerror(errno)); + return -1; + } + //ATS_ALIGNED_BASIC_PER + //ATS_ALIGNED_CANONICAL_PER + //ATS_DER + asn_enc_rval_t encode_result = asn_encode_to_buffer(0,ATS_ALIGNED_CANONICAL_PER,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef, buf, *buf_size); + //asn_enc_rval_t encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL,actionDef, buf, *buf_size); + if (encode_result.encoded == -1) { + fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); + return -1; + } + else { + fprintf(stderr, "successfully\n"); + + xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + /* + FILE *fp = fopen("sandeep.bin", "wb"); + + asn_enc_rval_t ec =asn_encode(0, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef, write_out, fp); + fclose(fp); + if(ec.encoded ==-1) { + fprintf(stderr, "Could not encode action def (at %s)\n”,ec.failed_type ? ec.failed_type->name : ”unknown"); + exit(1); + } else { + fprintf(stderr, "Created sandeep binary with ATS_ALIGNED_CANONICAL_PER encoded action def\n"); + } + FILE *fp2 = fopen("sandy.txt", "w"); + int r=asn_fprint(fp2,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef); + fclose(fp2); + if (r==-1) + fprintf(stderr, "failed asn_fprint\n"); + else + fprintf(stderr, "successfull asn_fprint\n"); + */ + return encode_result.encoded; + } +} +size_t e2sm_encode_ric_action_definition_format3_by_id(unsigned char *buf, size_t *buf_size, long *id , size_t measIdcount, long ric_style_type, unsigned long granulPeriod) { + E2SM_KPM_ActionDefinition_t *actionDef = (E2SM_KPM_ActionDefinition_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_t)); + if (!actionDef) { + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + + E2SM_KPM_ActionDefinition_Format3_t *actionDefFor3 = (E2SM_KPM_ActionDefinition_Format3_t *)calloc(1, sizeof(E2SM_KPM_ActionDefinition_Format3_t)); + if (!actionDefFor3) { + ASN_STRUCT_FREE(asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + fprintf(stderr, "alloc RIC ActionDefinition failed\n"); + return -1; + } + -// long id[] = {1,2,3,4}; -// void *buffer[8] = {} ; -// unsigned int sizeBuffer = 8; -// long actionDefCount = 8; -// long measId = 1; -// long ricStyleType = 1; -// long periods = 1; -// void *plm[8] = {} ; -// unsigned int sizePlm = 8; -// void *nRc[8] = {} ; -// unsigned int sizenRc = 8; + MeasurementCondItem_t **CondItem = (MeasurementCondItem_t **)calloc(measIdcount, sizeof(MeasurementCondItem_t *)); + int Label_Item_count=1; -// int a = e2sm_encode_ric_action_definition(buffer, sizeBuffer, actionDefCount, measId, ricStyleType, periods, plm, nRc); + long *no_label=(long *) calloc(1,sizeof(long));//not giving label to the cell metrics/// don't know its bheaviour + *no_label=0; + int index = 0; + while (index < measIdcount) { -// printf("%d", a); + CondItem[index] = (MeasurementCondItem_t *)calloc(1, sizeof(MeasurementCondItem_t )); + MeasurementType_t *Mtype=(MeasurementType_t *)calloc(1,sizeof(MeasurementType_t)); + Mtype->present=MeasurementType_PR_measID; + Mtype->choice.measID = id[index]; + CondItem[index]->measType=*Mtype; + + + //LabelInfoList_t *L_List=(LabelInfoList_t *)calloc(1,sizeof(LabelInfoList_t )); + MatchingCondItem_t **M_Item = (MatchingCondItem_t **)calloc(Label_Item_count, sizeof(MatchingCondItem_t *)); + MeasurementLabel_t *M_Label=(MeasurementLabel_t *)calloc(1,sizeof(MeasurementLabel_t)); + M_Label->noLabel=no_label; + M_Item[0] = (MatchingCondItem_t *)calloc(1, sizeof(MatchingCondItem_t )); + M_Item[0]->present=MatchingCondItem_PR_measLabel; + M_Item[0]->choice.measLabel=M_Label; + int result1 = ASN_SEQUENCE_ADD(&CondItem[index]->matchingCond, M_Item[0]); + if (result1==-1) + { + fprintf(stderr,"Unable to assign memory for matchingCond to add matchingCondItem_t %s",strerror(errno)); + return -1; + } + + int result2 = ASN_SEQUENCE_ADD(&actionDefFor3->measCondList, CondItem[index]); + if (result2==-1) + { + fprintf(stderr,"Unable to assign memory for measCondList to add MeasurementCondItem_t %s",strerror(errno)); + return -1; + } + + + index++; + } + + + actionDefFor3->granulPeriod = granulPeriod; + //actionDefFor3->cellGlobalID = cellGlobal; //optional + + + actionDef->ric_Style_Type = ric_style_type; + actionDef->actionDefinition_formats.present = E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3; + actionDef->actionDefinition_formats.choice.actionDefinition_Format3 = actionDefFor3; + + + char errbuf[128]; + size_t errbuf_len = 128; + + int ret_constr = asn_check_constraints(&asn_DEF_E2SM_KPM_ActionDefinition, (void *) actionDef, errbuf, &errbuf_len); + if(ret_constr){ + fprintf(stderr,"Constraints failed for encoding subscription request, %s", strerror(errno)); + return -1; + } + //ATS_ALIGNED_BASIC_PER + //ATS_ALIGNED_CANONICAL_PER + //ATS_DER + asn_enc_rval_t encode_result = asn_encode_to_buffer(0,ATS_ALIGNED_CANONICAL_PER,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef, buf, *buf_size); + //asn_enc_rval_t encode_result = uper_encode_to_buffer(&asn_DEF_E2SM_KPM_ActionDefinition, NULL,actionDef, buf, *buf_size); + if (encode_result.encoded == -1) { + fprintf(stderr, "Cannot encode %s: %s\n", encode_result.failed_type->name, strerror(errno)); + return -1; + } + else { + fprintf(stderr, "successfully\n"); + xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef); + /* + FILE *fp = fopen("sandeep.bin", "wb"); + + asn_enc_rval_t ec =asn_encode(0, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_E2SM_KPM_ActionDefinition, actionDef, write_out, fp); + fclose(fp); + if(ec.encoded ==-1) { + fprintf(stderr, "Could not encode action def (at %s)\n”,ec.failed_type ? ec.failed_type->name : ”unknown"); + exit(1); + } else { + fprintf(stderr, "Created sandeep binary with ATS_ALIGNED_CANONICAL_PER encoded action def\n"); + } + FILE *fp2 = fopen("sandy.txt", "w"); + int r=asn_fprint(fp2,&asn_DEF_E2SM_KPM_ActionDefinition,actionDef); + fclose(fp2); + if (r==-1) + fprintf(stderr, "failed asn_fprint\n"); + else + fprintf(stderr, "successfull asn_fprint\n"); + */ + return encode_result.encoded; + } +} -// return 0; -// } /* 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) { diff --git a/e2sm/wrapper.h b/e2sm/wrapper.h index a3bb5f3..fb2a636 100644 --- a/e2sm/wrapper.h +++ b/e2sm/wrapper.h @@ -52,6 +52,9 @@ #include #include #include +#include +#include +#include #include #include @@ -93,9 +96,26 @@ typedef struct Nrc { int size; int bits_unused; } Nrc; + */ +typedef struct encode_act_Def_result{ + int * array; + int length; +} encode_act_Def_result_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); +// + +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); + +size_t e2sm_encode_ric_action_definition_format1_by_id(unsigned char *buf, size_t *buf_size, long *id , size_t measIdcount, long ric_style_type, unsigned long granulPeriod, unsigned char *p, unsigned char *nR); + +size_t e2sm_encode_ric_action_definition_format3_by_name(unsigned char *buf, size_t *buf_size, char **id_tmp , size_t measIdcount, long ric_style_type, unsigned long granulPeriod); + +size_t e2sm_encode_ric_action_definition_format3_by_id(unsigned char *buf, size_t *buf_size, long *id , size_t measIdcount, long ric_style_type, unsigned long granulPeriod); + E2SM_KPM_IndicationHeader_t* e2sm_decode_ric_indication_header(void *buffer, size_t buf_size); void e2sm_free_ric_indication_header(E2SM_KPM_IndicationHeader_t* indHdr); E2SM_KPM_IndicationMessage_t* e2sm_decode_ric_indication_message(void *buffer, size_t buf_size); -- 2.16.6