Metrics for the Indication message 20/6620/2
authorsubhash kumar singh <subh.singh@samsung.com>
Wed, 25 Aug 2021 11:43:30 +0000 (11:43 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Wed, 25 Aug 2021 11:54:40 +0000 (17:24 +0530)
Metrics for the Indication message and code formatting.

Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I4d23aca9c2b9f258cfc39d69fc41eb125ae8c4fc

hwApp.go

index cd1d7b5..b368db9 100755 (executable)
--- a/hwApp.go
+++ b/hwApp.go
 package main
 
 import (
-       "encoding/json"
-       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
+       "encoding/json"
+
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
 )
 
 type HWApp struct {
+       stats map[string]xapp.Counter
 }
 
 var (
        A1_POLICY_QUERY      = 20013
        POLICY_QUERY_PAYLOAD = "{\"policy_type_id\":20000}"
-        reqId               = int64(1)
-        seqId               = int64(1)
-        funId               = int64(1)
-        actionId            = int64(1)
-        actionType          = "report"
-        subsequestActioType = "continue"
-        timeToWait          = "w10ms"
-        direction           = int64(0)
-        procedureCode       = int64(27)
-        typeOfMessage       = int64(1)
-        subscriptionId      = ""
-        hPort               = int64(8080)
-        rPort               = int64(4560)
-        clientEndpoint      = clientmodel.SubscriptionParamsClientEndpoint{Host: "service-ricxapp-hw-go-http.ricxapp", HTTPPort: &hPort, RMRPort: &rPort}
-
+       reqId                = int64(1)
+       seqId                = int64(1)
+       funId                = int64(1)
+       actionId             = int64(1)
+       actionType           = "report"
+       subsequestActioType  = "continue"
+       timeToWait           = "w10ms"
+       direction            = int64(0)
+       procedureCode        = int64(27)
+       typeOfMessage        = int64(1)
+       subscriptionId       = ""
+       hPort                = int64(8080)
+       rPort                = int64(4560)
+       clientEndpoint       = clientmodel.SubscriptionParamsClientEndpoint{Host: "service-ricxapp-hw-go-http.ricxapp", HTTPPort: &hPort, RMRPort: &rPort}
 )
 
 func (e *HWApp) sendPolicyQuery() {
@@ -71,109 +72,114 @@ func (e *HWApp) ConfigChangeHandler(f string) {
        xapp.Logger.Info("Config file changed")
 }
 
-func (e *HWApp) getEnbList() ([]*xapp.RNIBNbIdentity, error){
-       enbs, err := xapp.Rnib.GetListEnbIds()
+func (e *HWApp) getEnbList() ([]*xapp.RNIBNbIdentity, error) {
+       enbs, err := xapp.Rnib.GetListEnbIds()
 
-       if err != nil {
-               xapp.Logger.Error("err: %s", err)
-               return nil, err
-       }
+       if err != nil {
+               xapp.Logger.Error("err: %s", err)
+               return nil, err
+       }
 
-       xapp.Logger.Info("List for connected eNBs :")
-       for index, enb := range enbs {
-               xapp.Logger.Info("%d. enbid: %s", index+1, enb.InventoryName)
-       }
-       return enbs, nil
+       xapp.Logger.Info("List for connected eNBs :")
+       for index, enb := range enbs {
+               xapp.Logger.Info("%d. enbid: %s", index+1, enb.InventoryName)
+       }
+       return enbs, nil
 }
 
 func (e *HWApp) getGnbList() ([]*xapp.RNIBNbIdentity, error) {
-       gnbs, err := xapp.Rnib.GetListGnbIds()
-
-       if err != nil {
-               xapp.Logger.Error("err: %s", err)
-               return nil, err
-       }
-
-       xapp.Logger.Info("List of connected gNBs :")
-       for index, gnb := range gnbs {
-               xapp.Logger.Info("%d. gnbid : %s", index+1, gnb.InventoryName)
-       }
-       return gnbs, nil
+       gnbs, err := xapp.Rnib.GetListGnbIds()
+
+       if err != nil {
+               xapp.Logger.Error("err: %s", err)
+               return nil, err
+       }
+
+       xapp.Logger.Info("List of connected gNBs :")
+       for index, gnb := range gnbs {
+               xapp.Logger.Info("%d. gnbid : %s", index+1, gnb.InventoryName)
+       }
+       return gnbs, nil
 }
 
-func (e *HWApp) getnbList() ([]*xapp.RNIBNbIdentity) {
-       nbs := []*xapp.RNIBNbIdentity{}
+func (e *HWApp) getnbList() []*xapp.RNIBNbIdentity {
+       nbs := []*xapp.RNIBNbIdentity{}
 
-       if enbs , err := e.getEnbList(); err == nil {
-              nbs = append(nbs, enbs...)
-       }
+       if enbs, err := e.getEnbList(); err == nil {
+               nbs = append(nbs, enbs...)
+       }
 
-       if gnbs, err := e.getGnbList(); err == nil {
-              nbs = append(nbs, gnbs...)
-       }
-       return nbs
+       if gnbs, err := e.getGnbList(); err == nil {
+               nbs = append(nbs, gnbs...)
+       }
+       return nbs
 }
 
 func (e *HWApp) sendSubscription(meid string) {
 
-       xapp.Logger.Info("sending subscription request for meid : %s", meid)
-
-       subscriptionParams := clientmodel.SubscriptionParams{
-                ClientEndpoint: &clientEndpoint,
-                Meid:           &meid,
-                RANFunctionID:  &funId,
-                SubscriptionDetails: clientmodel.SubscriptionDetailsList{
-                        &clientmodel.SubscriptionDetail{
-                                RequestorID: &reqId,
-                                InstanceID:  &seqId,
-                                EventTriggers: &clientmodel.EventTriggerDefinition{
-                                        OctetString: "1234",
-                                },
-                                ActionToBeSetupList: clientmodel.ActionsToBeSetup{
-                                        &clientmodel.ActionToBeSetup{
-                                                ActionDefinition: &clientmodel.ActionDefinition{
-                                                        OctetString: "5678",
-                                                },
-                                                ActionID:   &actionId,
-                                                ActionType: &actionType,
-                                                SubsequentAction: &clientmodel.SubsequentAction{
-                                                        SubsequentActionType: &subsequestActioType,
-                                                        TimeToWait:           &timeToWait,
-                                                },
-                                        },
-                                },
-                        },
-                },
-        }
-
-        b, err := json.MarshalIndent(subscriptionParams, "", "  ")
-
-       if err != nil {
-               xapp.Logger.Error("Json marshaling failed : %s", err)
-               return
-       }
-
-        xapp.Logger.Info("*****body: %s ", string(b))
-
-       resp, err := xapp.Subscription.Subscribe(&subscriptionParams)
-
-       if err != nil {
-               xapp.Logger.Error("subscription failed (%s) with error: %s", meid, err)
-               return
-       }
-       xapp.Logger.Info("Successfully subcription done (%s), subscription id : %s", meid, *resp.SubscriptionID)
+       xapp.Logger.Info("sending subscription request for meid : %s", meid)
+
+       subscriptionParams := clientmodel.SubscriptionParams{
+               ClientEndpoint: &clientEndpoint,
+               Meid:           &meid,
+               RANFunctionID:  &funId,
+               SubscriptionDetails: clientmodel.SubscriptionDetailsList{
+                       &clientmodel.SubscriptionDetail{
+                               RequestorID: &reqId,
+                               InstanceID:  &seqId,
+                               EventTriggers: &clientmodel.EventTriggerDefinition{
+                                       OctetString: "1234",
+                               },
+                               ActionToBeSetupList: clientmodel.ActionsToBeSetup{
+                                       &clientmodel.ActionToBeSetup{
+                                               ActionDefinition: &clientmodel.ActionDefinition{
+                                                       OctetString: "5678",
+                                               },
+                                               ActionID:   &actionId,
+                                               ActionType: &actionType,
+                                               SubsequentAction: &clientmodel.SubsequentAction{
+                                                       SubsequentActionType: &subsequestActioType,
+                                                       TimeToWait:           &timeToWait,
+                                               },
+                                       },
+                               },
+                       },
+               },
+       }
+
+       b, err := json.MarshalIndent(subscriptionParams, "", "  ")
+
+       if err != nil {
+               xapp.Logger.Error("Json marshaling failed : %s", err)
+               return
+       }
+
+       xapp.Logger.Info("*****body: %s ", string(b))
+
+       resp, err := xapp.Subscription.Subscribe(&subscriptionParams)
+
+       if err != nil {
+               xapp.Logger.Error("subscription failed (%s) with error: %s", meid, err)
+               return
+       }
+       xapp.Logger.Info("Successfully subcription done (%s), subscription id : %s", meid, *resp.SubscriptionID)
 }
 
 func (e *HWApp) xAppStartCB(d interface{}) {
        xapp.Logger.Info("xApp ready call back received")
 
-       // get the list of all NBs
-       nbList := e.getnbList()
+       // get the list of all NBs
+       nbList := e.getnbList()
+
+       // send subscription request to each of the NBs
+       for _, nb := range nbList {
+               e.sendSubscription(nb.InventoryName)
+       }
+}
 
-       // send subscription request to each of the NBs
-       for _, nb := range nbList {
-       e.sendSubscription(nb.InventoryName)
-       }
+func (e *HWApp) handleRICIndication(ranName string, r *xapp.RMRParams) {
+       // update metrics for indication message
+       e.stats["RICIndicationRx"].Inc()
 }
 
 func (e *HWApp) Consume(msg *xapp.RMRParams) (err error) {
@@ -190,6 +196,11 @@ func (e *HWApp) Consume(msg *xapp.RMRParams) (err error) {
        case "RIC_HEALTH_CHECK_REQ":
                xapp.Logger.Info("Received health check request")
 
+       // RIC INDICATION message
+       case "RIC_INDICATION":
+               xapp.Logger.Info("Received RIC Indication message")
+               e.handleRICIndication(msg.Meid.RanName, msg)
+
        default:
                xapp.Logger.Info("Unknown message type '%d', discarding", msg.Mtype)
        }
@@ -221,6 +232,16 @@ func (e *HWApp) Run() {
 }
 
 func main() {
-       hw := HWApp{}
+       // Defind metrics counter that the xapp provides
+       metrics := []xapp.CounterOpts{
+               {
+                       Name: "RICIndicationRx",
+                       Help: "Total number of RIC Indication message received",
+               },
+       }
+
+       hw := HWApp{
+               stats: xapp.Metric.RegisterCounterGroup(metrics, "hw-go"), // register counter
+       }
        hw.Run()
 }