X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=control%2Fcontrol.go;h=45acb6bbf271afceb1b88d76ca9699011fed088e;hb=35bea97552450f45d4b1b9ed0375b059440989ce;hp=a4c10f28c146bfb4accf6161c3d04fd88772314d;hpb=4a8b4de538cb766095326da4a628b5cc01b8c8e7;p=scp%2Fric-app%2Fkpimon.git diff --git a/control/control.go b/control/control.go index a4c10f2..45acb6b 100644 --- a/control/control.go +++ b/control/control.go @@ -3,26 +3,28 @@ package control import ( "encoding/json" "errors" - "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - "github.com/go-redis/redis" "log" "os" "strconv" "strings" "sync" "time" + "gerrit.o-ran-sc.org/r/ric-plt/sdlgo" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + //"github.com/go-redis/redis" ) type Control struct { - ranList []string //nodeB list - eventCreateExpired int32 //maximum time for the RIC Subscription Request event creation procedure in the E2 Node - eventDeleteExpired int32 //maximum time for the RIC Subscription Request event deletion procedure in the E2 Node + ranList []string //nodeB list + eventCreateExpired int32 //maximum time for the RIC Subscription Request event creation procedure in the E2 Node + eventDeleteExpired int32 //maximum time for the RIC Subscription Request event deletion procedure in the E2 Node rcChan chan *xapp.RMRParams //channel for receiving rmr message - client *redis.Client //redis client + //client *redis.Client //redis client eventCreateExpiredMap map[string]bool //map for recording the RIC Subscription Request event creation procedure is expired or not eventDeleteExpiredMap map[string]bool //map for recording the RIC Subscription Request event deletion procedure is expired or not eventCreateExpiredMu *sync.Mutex //mutex for eventCreateExpiredMap eventDeleteExpiredMu *sync.Mutex //mutex for eventDeleteExpiredMap + sdl *sdlgo.SdlInstance } func init() { @@ -42,15 +44,16 @@ func NewControl() Control { return Control{strings.Split(str, ","), 5, 5, make(chan *xapp.RMRParams), - redis.NewClient(&redis.Options{ - Addr: os.Getenv("redisAddr"), //"localhost:6379" - Password: "", - DB: 0, - }), + //redis.NewClient(&redis.Options{ + // Addr: os.Getenv("DBAAS_SERVICE_HOST") + ":" + os.Getenv("DBAAS_SERVICE_PORT"), //"localhost:6379" + // Password: "", + // DB: 0, + //}), make(map[string]bool), make(map[string]bool), &sync.Mutex{}, - &sync.Mutex{}} + &sync.Mutex{}, + sdlgo.NewSdlInstance("kpimon", sdlgo.NewDatabase())} } func ReadyCB(i interface{}) { @@ -61,11 +64,11 @@ func ReadyCB(i interface{}) { } func (c *Control) Run() { - _, err := c.client.Ping().Result() - if err != nil { - xapp.Logger.Error("Failed to connect to Redis DB with %v", err) - log.Printf("Failed to connect to Redis DB with %v", err) - } + //_, err := c.client.Ping().Result() + //if err != nil { + // xapp.Logger.Error("Failed to connect to Redis DB with %v", err) + // log.Printf("Failed to connect to Redis DB with %v", err) + //} if len(c.ranList) > 0 { xapp.SetReadyCB(ReadyCB, c) xapp.Run(c) @@ -181,19 +184,19 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { log.Printf("-----------RIC Indication Header-----------") if indicationHdr.IndHdrType == 1 { log.Printf("RIC Indication Header Format: %d", indicationHdr.IndHdrType) - indHdrFormat1 := indicationHdr.IndHdr.(IndicationHeaderFormat1) + indHdrFormat1 := indicationHdr.IndHdr.(*IndicationHeaderFormat1) log.Printf("GlobalKPMnodeIDType: %d", indHdrFormat1.GlobalKPMnodeIDType) if indHdrFormat1.GlobalKPMnodeIDType == 1 { - globalKPMnodegNBID := indHdrFormat1.GlobalKPMnodeID.(GlobalKPMnodegNBIDType) + globalKPMnodegNBID := indHdrFormat1.GlobalKPMnodeID.(*GlobalKPMnodegNBIDType) globalgNBID := globalKPMnodegNBID.GlobalgNBID log.Printf("PlmnID: %x", globalgNBID.PlmnID.Buf) log.Printf("gNB ID Type: %d", globalgNBID.GnbIDType) if globalgNBID.GnbIDType == 1 { - gNBID := globalgNBID.GnbID.(GNBID) + gNBID := globalgNBID.GnbID.(*GNBID) log.Printf("gNB ID ID: %x, Unused: %d", gNBID.Buf, gNBID.BitsUnused) } @@ -205,45 +208,45 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { log.Printf("gNB-DU ID: %x", globalKPMnodegNBID.GnbDUID.Buf) } } else if indHdrFormat1.GlobalKPMnodeIDType == 2 { - globalKPMnodeengNBID := indHdrFormat1.GlobalKPMnodeID.(GlobalKPMnodeengNBIDType) + globalKPMnodeengNBID := indHdrFormat1.GlobalKPMnodeID.(*GlobalKPMnodeengNBIDType) log.Printf("PlmnID: %x", globalKPMnodeengNBID.PlmnID.Buf) log.Printf("en-gNB ID Type: %d", globalKPMnodeengNBID.GnbIDType) if globalKPMnodeengNBID.GnbIDType == 1 { - engNBID := globalKPMnodeengNBID.GnbID.(ENGNBID) + engNBID := globalKPMnodeengNBID.GnbID.(*ENGNBID) log.Printf("en-gNB ID ID: %x, Unused: %d", engNBID.Buf, engNBID.BitsUnused) } } else if indHdrFormat1.GlobalKPMnodeIDType == 3 { - globalKPMnodengeNBID := indHdrFormat1.GlobalKPMnodeID.(GlobalKPMnodengeNBIDType) + globalKPMnodengeNBID := indHdrFormat1.GlobalKPMnodeID.(*GlobalKPMnodengeNBIDType) log.Printf("PlmnID: %x", globalKPMnodengeNBID.PlmnID.Buf) log.Printf("ng-eNB ID Type: %d", globalKPMnodengeNBID.EnbIDType) if globalKPMnodengeNBID.EnbIDType == 1 { - ngeNBID := globalKPMnodengeNBID.EnbID.(NGENBID_Macro) + ngeNBID := globalKPMnodengeNBID.EnbID.(*NGENBID_Macro) log.Printf("ng-eNB ID ID: %x, Unused: %d", ngeNBID.Buf, ngeNBID.BitsUnused) } else if globalKPMnodengeNBID.EnbIDType == 2 { - ngeNBID := globalKPMnodengeNBID.EnbID.(NGENBID_ShortMacro) + ngeNBID := globalKPMnodengeNBID.EnbID.(*NGENBID_ShortMacro) log.Printf("ng-eNB ID ID: %x, Unused: %d", ngeNBID.Buf, ngeNBID.BitsUnused) } else if globalKPMnodengeNBID.EnbIDType == 3 { - ngeNBID := globalKPMnodengeNBID.EnbID.(NGENBID_LongMacro) + ngeNBID := globalKPMnodengeNBID.EnbID.(*NGENBID_LongMacro) log.Printf("ng-eNB ID ID: %x, Unused: %d", ngeNBID.Buf, ngeNBID.BitsUnused) } } else if indHdrFormat1.GlobalKPMnodeIDType == 4 { - globalKPMnodeeNBID := indHdrFormat1.GlobalKPMnodeID.(GlobalKPMnodeeNBIDType) + globalKPMnodeeNBID := indHdrFormat1.GlobalKPMnodeID.(*GlobalKPMnodeeNBIDType) log.Printf("PlmnID: %x", globalKPMnodeeNBID.PlmnID.Buf) log.Printf("eNB ID Type: %d", globalKPMnodeeNBID.EnbIDType) if globalKPMnodeeNBID.EnbIDType == 1 { - eNBID := globalKPMnodeeNBID.EnbID.(ENBID_Macro) + eNBID := globalKPMnodeeNBID.EnbID.(*ENBID_Macro) log.Printf("eNB ID ID: %x, Unused: %d", eNBID.Buf, eNBID.BitsUnused) } else if globalKPMnodeeNBID.EnbIDType == 2 { - eNBID := globalKPMnodeeNBID.EnbID.(ENBID_Home) + eNBID := globalKPMnodeeNBID.EnbID.(*ENBID_Home) log.Printf("eNB ID ID: %x, Unused: %d", eNBID.Buf, eNBID.BitsUnused) } else if globalKPMnodeeNBID.EnbIDType == 3 { - eNBID := globalKPMnodeeNBID.EnbID.(ENBID_ShortMacro) + eNBID := globalKPMnodeeNBID.EnbID.(*ENBID_ShortMacro) log.Printf("eNB ID ID: %x, Unused: %d", eNBID.Buf, eNBID.BitsUnused) } else if globalKPMnodeeNBID.EnbIDType == 4 { - eNBID := globalKPMnodeeNBID.EnbID.(ENBID_LongMacro) + eNBID := globalKPMnodeeNBID.EnbID.(*ENBID_LongMacro) log.Printf("eNB ID ID: %x, Unused: %d", eNBID.Buf, eNBID.BitsUnused) } @@ -312,18 +315,18 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { } if indHdrFormat1.GnbNameType == 1 { - log.Printf("gNB-DU-Name: %x", (indHdrFormat1.GnbName.(GNB_DU_Name)).Buf) + log.Printf("gNB-DU-Name: %x", (indHdrFormat1.GnbName.(*GNB_DU_Name)).Buf) } else if indHdrFormat1.GnbNameType == 2 { - log.Printf("gNB-CU-CP-Name: %x", (indHdrFormat1.GnbName.(GNB_CU_CP_Name)).Buf) + log.Printf("gNB-CU-CP-Name: %x", (indHdrFormat1.GnbName.(*GNB_CU_CP_Name)).Buf) } else if indHdrFormat1.GnbNameType == 3 { - log.Printf("gNB-CU-UP-Name: %x", (indHdrFormat1.GnbName.(GNB_CU_UP_Name)).Buf) + log.Printf("gNB-CU-UP-Name: %x", (indHdrFormat1.GnbName.(*GNB_CU_UP_Name)).Buf) } if indHdrFormat1.GlobalgNBID != nil { log.Printf("PlmnID: %x", indHdrFormat1.GlobalgNBID.PlmnID.Buf) log.Printf("gNB ID Type: %d", indHdrFormat1.GlobalgNBID.GnbIDType) if indHdrFormat1.GlobalgNBID.GnbIDType == 1 { - gNBID := indHdrFormat1.GlobalgNBID.GnbID.(GNBID) + gNBID := indHdrFormat1.GlobalgNBID.GnbID.(*GNBID) log.Printf("gNB ID ID: %x, Unused: %d", gNBID.Buf, gNBID.BitsUnused) } } @@ -355,7 +358,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if indMsg.IndMsgType == 1 { log.Printf("RIC Indication Message Format: %d", indMsg.IndMsgType) - indMsgFormat1 := indMsg.IndMsg.(IndicationMessageFormat1) + indMsgFormat1 := indMsg.IndMsg.(*IndicationMessageFormat1) log.Printf("PMContainerCount: %d", indMsgFormat1.PMContainerCount) @@ -380,7 +383,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if containerType == 1 { log.Printf("oDU PF Container: ") - oDU := pmContainer.PFContainer.Container.(ODUPFContainerType) + oDU := pmContainer.PFContainer.Container.(*ODUPFContainerType) cellResourceReportCount := oDU.CellResourceReportCount log.Printf("CellResourceReportCount: %d", cellResourceReportCount) @@ -469,7 +472,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { } else if containerType == 2 { log.Printf("oCU-CP PF Container: ") - oCUCP := pmContainer.PFContainer.Container.(OCUCPPFContainerType) + oCUCP := pmContainer.PFContainer.Container.(*OCUCPPFContainerType) if oCUCP.GNBCUCPName != nil { log.Printf("gNB-CU-CP Name: %x", oCUCP.GNBCUCPName.Buf) @@ -479,7 +482,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { } else if containerType == 3 { log.Printf("oCU-UP PF Container: ") - oCUUP := pmContainer.PFContainer.Container.(OCUUPPFContainerType) + oCUUP := pmContainer.PFContainer.Container.(*OCUUPPFContainerType) if oCUUP.GNBCUUPName != nil { log.Printf("gNB-CU-UP Name: %x", oCUUP.GNBCUUPName.Buf) @@ -499,7 +502,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { log.Printf("CU-UP Plmn Count: %d", cuUPPlmnCount) for k := 0; k < cuUPPlmnCount; k++ { - log.Printf("CU-UP Plmn [%d]: ") + log.Printf("CU-UP Plmn [%d]: ", k) cuUPPlmn := cuUPPFContainerItem.OCUUPPMContainer.CUUPPlmns[k] @@ -582,7 +585,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { log.Printf("PerQCIReportCount: %d", cuUPPMEPCPerQCIReportCount) for l := 0; l < cuUPPMEPCPerQCIReportCount; l++ { - log.Printf("PerQCIReport[%d]: ") + log.Printf("PerQCIReport[%d]: ", l) cuUPPMEPCPerQCIReport := cuUPPlmn.CUUPPMEPC.CUUPPMEPCPerQCIReports[l] @@ -615,7 +618,7 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if containerType == 1 { log.Printf("DU Usage Report: ") - oDUUE := pmContainer.RANContainer.Container.(DUUsageReportType) + oDUUE := pmContainer.RANContainer.Container.(*DUUsageReportType) for j := 0; j < oDUUE.CellResourceReportItemCount; j++ { cellResourceReportItem := oDUUE.CellResourceReportItems[j] @@ -642,15 +645,30 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { continue } - var ueMetrics *UeMetricsEntry - if isUeExist, _ := c.client.Exists(strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { - ueJsonStr, _ := c.client.Get(strconv.FormatInt(ueID, 10)).Result() - json.Unmarshal([]byte(ueJsonStr), ueMetrics) + var ueMetrics UeMetricsEntry + + retStr, err := c.sdl.Get([]string{"{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)}) + if err != nil { + panic(err) + xapp.Logger.Error("Failed to get ueMetrics from Redis!") + log.Printf("Failed to get ueMetrics from Redis!") } else { - ueMetrics = &UeMetricsEntry{} + if retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)] != nil { + ueJsonStr := retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)].(string) + json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + } } - ueMetrics.ServingCellID = servingCellID + //if isUeExist, _ := c.client.Exists("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { + // ueJsonStr, _ := c.client.Get("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result() + // json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + //} + + ueMetrics.UeID = ueID + log.Printf("UeID: %d", ueMetrics.UeID) + ueMetrics.ServingCellID = servingCellID + log.Printf("ServingCellID: %s", ueMetrics.ServingCellID) + ueMetrics.MeasPeriodRF = 20 if flag { timestampPRB = timestamp @@ -661,30 +679,40 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if ueResourceReportItem.PRBUsageDL != -1 { ueMetrics.PRBUsageDL = ueResourceReportItem.PRBUsageDL + log.Printf("PRBUsageDL: %d", ueMetrics.PRBUsageDL) } if ueResourceReportItem.PRBUsageUL != -1 { ueMetrics.PRBUsageUL = ueResourceReportItem.PRBUsageUL + log.Printf("PRBUsageUL: %d", ueMetrics.PRBUsageUL) } - newUeJsonStr, err := json.Marshal(ueMetrics) + newUeJsonStr, err := json.Marshal(&ueMetrics) if err != nil { - xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) continue } - err = c.client.Set(strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + + err = c.sdl.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr) if err != nil { - xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) continue } + + //err = c.client.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + //if err != nil { + // xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // continue + //} } } } else if containerType == 2 { log.Printf("CU-CP Usage Report: ") - oCUCPUE := pmContainer.RANContainer.Container.(CUCPUsageReportType) + oCUCPUE := pmContainer.RANContainer.Container.(*CUCPUsageReportType) for j := 0; j < oCUCPUE.CellResourceReportItemCount; j++ { cellResourceReportItem := oCUCPUE.CellResourceReportItems[j] @@ -711,55 +739,84 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { continue } - var ueMetrics *UeMetricsEntry - if isUeExist, _ := c.client.Exists(strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { - ueJsonStr, _ := c.client.Get(strconv.FormatInt(ueID, 10)).Result() - json.Unmarshal([]byte(ueJsonStr), ueMetrics) + var ueMetrics UeMetricsEntry + + retStr, err := c.sdl.Get([]string{"{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)}) + if err != nil { + panic(err) + xapp.Logger.Error("Failed to get ueMetrics from Redis!") + log.Printf("Failed to get ueMetrics from Redis!") } else { - ueMetrics = &UeMetricsEntry{} + if retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)] != nil { + ueJsonStr := retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)].(string) + json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + } } + //if isUeExist, _ := c.client.Exists("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { + // ueJsonStr, _ := c.client.Get("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result() + // json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + //} + + ueMetrics.UeID = ueID + log.Printf("UeID: %d", ueMetrics.UeID) ueMetrics.ServingCellID = servingCellID + log.Printf("ServingCellID: %s", ueMetrics.ServingCellID) ueMetrics.MeasTimeRF.TVsec = timestamp.TVsec ueMetrics.MeasTimeRF.TVnsec = timestamp.TVnsec + ueMetrics.MeasPeriodPDCP = 20 + ueMetrics.MeasPeriodPRB = 20 + if ueResourceReportItem.ServingCellRF != nil { err = json.Unmarshal(ueResourceReportItem.ServingCellRF.Buf, &ueMetrics.ServingCellRF) + log.Printf("ueMetrics.ServingCellRF: %+v", ueMetrics.ServingCellRF) if err != nil { - xapp.Logger.Error("Failed to Unmarshal ServingCellRF in CU-CP Usage Report with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to Unmarshal ServingCellRF in CU-CP Usage Report with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to Unmarshal ServingCellRF in CU-CP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to Unmarshal ServingCellRF in CU-CP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("ServingCellRF raw data: %x", ueResourceReportItem.ServingCellRF.Buf) continue } } if ueResourceReportItem.NeighborCellRF != nil { err = json.Unmarshal(ueResourceReportItem.NeighborCellRF.Buf, &ueMetrics.NeighborCellsRF) + log.Printf("ueMetrics.NeighborCellsRF: %+v", ueMetrics.NeighborCellsRF) if err != nil { - xapp.Logger.Error("Failed to Unmarshal NeighborCellRF in CU-CP Usage Report with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to Unmarshal NeighborCellRF in CU-CP Usage Report with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to Unmarshal NeighborCellRF in CU-CP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to Unmarshal NeighborCellRF in CU-CP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("NeighborCellRF raw data: %x", ueResourceReportItem.NeighborCellRF.Buf) continue } } - newUeJsonStr, err := json.Marshal(ueMetrics) + newUeJsonStr, err := json.Marshal(&ueMetrics) if err != nil { - xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) continue } - err = c.client.Set(strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + + err = c.sdl.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr) if err != nil { - xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) continue } + + //err = c.client.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + //if err != nil { + // xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // continue + //} } } - } else if containerType == 6 { + } else if containerType == 3 { log.Printf("CU-UP Usage Report: ") - oCUUPUE := pmContainer.RANContainer.Container.(CUUPUsageReportType) + oCUUPUE := pmContainer.RANContainer.Container.(*CUUPUsageReportType) for j := 0; j < oCUUPUE.CellResourceReportItemCount; j++ { cellResourceReportItem := oCUUPUE.CellResourceReportItems[j] @@ -786,15 +843,29 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { continue } - var ueMetrics *UeMetricsEntry - if isUeExist, _ := c.client.Exists(strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { - ueJsonStr, _ := c.client.Get(strconv.FormatInt(ueID, 10)).Result() - json.Unmarshal([]byte(ueJsonStr), ueMetrics) + var ueMetrics UeMetricsEntry + + retStr, err := c.sdl.Get([]string{"{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)}) + if err != nil { + panic(err) + xapp.Logger.Error("Failed to get ueMetrics from Redis!") + log.Printf("Failed to get ueMetrics from Redis!") } else { - ueMetrics = &UeMetricsEntry{} + if retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)] != nil { + ueJsonStr := retStr["{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)].(string) + json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + } } + //if isUeExist, _ := c.client.Exists("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result(); isUeExist == 1 { + // ueJsonStr, _ := c.client.Get("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10)).Result() + // json.Unmarshal([]byte(ueJsonStr), &ueMetrics) + //} + + ueMetrics.UeID = ueID + log.Printf("UeID: %d", ueMetrics.UeID) ueMetrics.ServingCellID = servingCellID + log.Printf("ServingCellID: %s", ueMetrics.ServingCellID) if flag { timestampPDCPBytes = timestamp @@ -806,8 +877,8 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if ueResourceReportItem.PDCPBytesDL != nil { ueMetrics.PDCPBytesDL, err = e2sm.ParseInteger(ueResourceReportItem.PDCPBytesDL.Buf, ueResourceReportItem.PDCPBytesDL.Size) if err != nil { - xapp.Logger.Error("Failed to parse PDCPBytesDL in CU-UP Usage Report with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to parse PDCPBytesDL in CU-UP Usage Report with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to parse PDCPBytesDL in CU-UP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to parse PDCPBytesDL in CU-UP Usage Report with UE ID [%d]: %v", ueID, err) continue } } @@ -815,24 +886,32 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { if ueResourceReportItem.PDCPBytesUL != nil { ueMetrics.PDCPBytesUL, err = e2sm.ParseInteger(ueResourceReportItem.PDCPBytesUL.Buf, ueResourceReportItem.PDCPBytesUL.Size) if err != nil { - xapp.Logger.Error("Failed to parse PDCPBytesUL in CU-UP Usage Report with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to parse PDCPBytesUL in CU-UP Usage Report with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to parse PDCPBytesUL in CU-UP Usage Report with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to parse PDCPBytesUL in CU-UP Usage Report with UE ID [%d]: %v", ueID, err) continue } } - newUeJsonStr, err := json.Marshal(ueMetrics) + newUeJsonStr, err := json.Marshal(&ueMetrics) if err != nil { - xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to marshal UeMetrics with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to marshal UeMetrics with UE ID [%d]: %v", ueID, err) continue } - err = c.client.Set(strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + + err = c.sdl.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr) if err != nil { - xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) - log.Printf("Failed to set UeMetrics into redis with UE ID [%s]: %v", ueID, err) + xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) continue } + + //err = c.client.Set("{TS-UE-metrics}," + strconv.FormatInt(ueID, 10), newUeJsonStr, 0).Err() + //if err != nil { + // xapp.Logger.Error("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // log.Printf("Failed to set UeMetrics into redis with UE ID [%d]: %v", ueID, err) + // continue + //} } } } else { @@ -843,14 +922,29 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { } if flag { - var cellMetrics *CellMetricsEntry - if isCellExist, _ := c.client.Exists(cellIDHdr).Result(); isCellExist == 1 { - cellJsonStr, _ := c.client.Get(cellIDHdr).Result() - json.Unmarshal([]byte(cellJsonStr), cellMetrics) + var cellMetrics CellMetricsEntry + + retStr, err := c.sdl.Get([]string{"{TS-cell-metrics}," + cellIDHdr}) + if err != nil { + panic(err) + xapp.Logger.Error("Failed to get cellMetrics from Redis!") + log.Printf("Failed to get cellMetrics from Redis!") } else { - cellMetrics = &CellMetricsEntry{} + if retStr["{TS-cell-metrics}," + cellIDHdr] != nil { + cellJsonStr := retStr["{TS-cell-metrics}," + cellIDHdr].(string) + json.Unmarshal([]byte(cellJsonStr), &cellMetrics) + } } + //if isCellExist, _ := c.client.Exists("{TS-cell-metrics}," + cellIDHdr).Result(); isCellExist == 1 { + // cellJsonStr, _ := c.client.Get("{TS-cell-metrics}," + cellIDHdr).Result() + // json.Unmarshal([]byte(cellJsonStr), &cellMetrics) + //} + + cellMetrics.MeasPeriodPDCP = 20 + cellMetrics.MeasPeriodPRB = 20 + cellMetrics.CellID = cellIDHdr + if timestampPDCPBytes != nil { cellMetrics.MeasTimestampPDCPBytes.TVsec = timestampPDCPBytes.TVsec cellMetrics.MeasTimestampPDCPBytes.TVnsec = timestampPDCPBytes.TVnsec @@ -872,18 +966,27 @@ func (c *Control) handleIndication(params *xapp.RMRParams) (err error) { cellMetrics.AvailPRBUL = availPRBUL } - newCellJsonStr, err := json.Marshal(cellMetrics) + newCellJsonStr, err := json.Marshal(&cellMetrics) if err != nil { xapp.Logger.Error("Failed to marshal CellMetrics with CellID [%s]: %v", cellIDHdr, err) log.Printf("Failed to marshal CellMetrics with CellID [%s]: %v", cellIDHdr, err) continue } - err = c.client.Set(cellIDHdr, newCellJsonStr, 0).Err() + + err = c.sdl.Set("{TS-cell-metrics}," + cellIDHdr, newCellJsonStr) if err != nil { xapp.Logger.Error("Failed to set CellMetrics into redis with CellID [%s]: %v", cellIDHdr, err) log.Printf("Failed to set CellMetrics into redis with CellID [%s]: %v", cellIDHdr, err) continue } + + + //err = c.client.Set("{TS-cell-metrics}," + cellIDHdr, newCellJsonStr, 0).Err() + //if err != nil { + // xapp.Logger.Error("Failed to set CellMetrics into redis with CellID [%s]: %v", cellIDHdr, err) + // log.Printf("Failed to set CellMetrics into redis with CellID [%s]: %v", cellIDHdr, err) + // continue + //} } } } else { @@ -1094,7 +1197,6 @@ func (c *Control) sendRicSubRequest(subID int, requestSN int, funcID int) (err e log.Printf("Failed to send RIC_SUB_REQ: %v", err) return err } - log.Printf("Set EventTriggerDefinition: %x", eventTriggerDefinition) var actionCount int = 1 @@ -1122,13 +1224,13 @@ func (c *Control) sendRicSubRequest(subID int, requestSN int, funcID int) (err e } } - for index := 0; index < len(c.ranList); index++ { + for index := 0; index < 1; index++ { //len(c.ranList) params := &xapp.RMRParams{} params.Mtype = 12010 params.SubId = subID - xapp.Logger.Debug("Send RIC_SUB_REQ to {%s}", c.ranList[index]) - log.Printf("Send RIC_SUB_REQ to {%s}", c.ranList[index]) + //xapp.Logger.Debug("Send RIC_SUB_REQ to {%s}", c.ranList[index]) + //log.Printf("Send RIC_SUB_REQ to {%s}", c.ranList[index]) params.Payload = make([]byte, 1024) params.Payload, err = e2ap.SetSubscriptionRequestPayload(params.Payload, 1001, uint16(requestSN), uint16(funcID), eventTriggerDefinition, len(eventTriggerDefinition), actionCount, actionIds, actionTypes, actionDefinitions, subsequentActions) @@ -1140,7 +1242,8 @@ func (c *Control) sendRicSubRequest(subID int, requestSN int, funcID int) (err e log.Printf("Set Payload: %x", params.Payload) - params.Meid = &xapp.RMRMeid{RanName: c.ranList[index]} + //params.Meid = &xapp.RMRMeid{RanName: c.ranList[index]} + params.Meid = &xapp.RMRMeid{PlmnID: "373437", EnbID: "10110101110001100111011110001", RanName: "gnb_734_733_b5c67788"} xapp.Logger.Debug("The RMR message to be sent is %d with SubId=%d", params.Mtype, params.SubId) log.Printf("The RMR message to be sent is %d with SubId=%d", params.Mtype, params.SubId) @@ -1152,8 +1255,8 @@ func (c *Control) sendRicSubRequest(subID int, requestSN int, funcID int) (err e } c.setEventCreateExpiredTimer(params.Meid.RanName) - c.ranList = append(c.ranList[:index], c.ranList[index+1:]...) - index-- + //c.ranList = append(c.ranList[:index], c.ranList[index+1:]...) + //index-- } return nil @@ -1175,9 +1278,11 @@ func (c *Control) sendRicSubDelRequest(subID int, requestSN int, funcID int) (er log.Printf("Set Payload: %x", params.Payload) if funcID == 0 { - params.Meid = &xapp.RMRMeid{PlmnID: "::", EnbID: "::", RanName: "0"} + //params.Meid = &xapp.RMRMeid{PlmnID: "::", EnbID: "::", RanName: "0"} + params.Meid = &xapp.RMRMeid{PlmnID: "373437", EnbID: "10110101110001100111011110001", RanName: "gnb_734_733_b5c67788"} } else { - params.Meid = &xapp.RMRMeid{PlmnID: "::", EnbID: "::", RanName: "3"} + //params.Meid = &xapp.RMRMeid{PlmnID: "::", EnbID: "::", RanName: "3"} + params.Meid = &xapp.RMRMeid{PlmnID: "373437", EnbID: "10110101110001100111011110001", RanName: "gnb_734_733_b5c67788"} } xapp.Logger.Debug("The RMR message to be sent is %d with SubId=%d", params.Mtype, params.SubId) @@ -1194,3 +1299,4 @@ func (c *Control) sendRicSubDelRequest(subID int, requestSN int, funcID int) (er return nil } +