negative case added
[ric-app/rc.git] / control / rcService.go
1 package control
2
3 import (
4         "log"
5         "runtime/debug"
6         _ "strings"
7         "time"
8
9         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
10         "gerrit.o-ran-sc.org/r/ric-app/rc/protocol/grpc/ricmsgcommrpc/rc"
11         "golang.org/x/net/context"
12 )
13
14 func (aPtrSendMsgSrv *RCControlServer) SendRICControlReqServiceGrpc(aCtx context.Context, aPtrRicControlGrpcReq *rc.RicControlGrpcReq) (*rc.RicControlGrpcRsp, error) {
15
16         xapp.Logger.Info("SendRICControlReqServiceGrpc Enter ")
17
18         defer func() {
19                 if r := recover(); r != nil {
20                         log.Println("Encountered panic:", r)
21                         xapp.Logger.Error("Encountered panic:", r)
22                         debug.SetTraceback("all")
23                         time.Sleep(100 * time.Millisecond)
24                         panic(r)
25                 }
26         }()
27
28         var lRicControlGrpcRsp rc.RicControlGrpcRsp
29         lRicControlGrpcRsp.RspCode = GRPC_ERROR 
30         lRicControlGrpcRsp.Description = "The client specified an invalid argument. or some parameters are missing "
31         if aPtrRicControlGrpcReq == nil {
32                 xapp.Logger.Error("Received nil data from Send error rsp")
33         } else {
34                 if len(aPtrRicControlGrpcReq.E2NodeID) == 0 || len(aPtrRicControlGrpcReq.RICControlMessageData.TargetCellID) == 0 || len(aPtrRicControlGrpcReq.RICControlHeaderData.UEID) == 0  || len(aPtrRicControlGrpcReq.RanName) == 0  || len(aPtrRicControlGrpcReq.PlmnID) == 0{
35                         xapp.Logger.Error("Mandatory parameters are not received send Error rsp to client,no control Request will be initiated ")
36                 } else {
37                         xapp.Logger.Info("GRPC Control request validated, initiate Control Request to RAN")
38                         gChan_RicControlReq_handle <- aPtrRicControlGrpcReq
39                         xapp.Logger.Debug("Received RIC Control Request with RicRequestorID: %d", aPtrRicControlGrpcReq.RICE2APHeaderData.RICRequestorID)
40                         xapp.Logger.Debug("Received RIC Control Request with RicActionId: %d", aPtrRicControlGrpcReq.RICE2APHeaderData.RanFuncId)
41
42                         xapp.Logger.Debug("Received RIC Control Request with UEID: %s", aPtrRicControlGrpcReq.RICControlHeaderData.UEID)
43                         xapp.Logger.Debug("Received RIC Control Request with ControlStyle: %d", aPtrRicControlGrpcReq.RICControlHeaderData.ControlStyle)
44                         xapp.Logger.Debug("Received RIC Control Request with ControlActionId: %d", aPtrRicControlGrpcReq.RICControlHeaderData.ControlActionId)
45
46                         xapp.Logger.Debug("Received RIC Control Request with CellType: %d", aPtrRicControlGrpcReq.RICControlMessageData.RICControlCellTypeVal)
47                         xapp.Logger.Debug("Received RIC Control Request with TargetCellID: %s", aPtrRicControlGrpcReq.RICControlMessageData.TargetCellID)
48                         xapp.Logger.Debug("Received RIC Control Request with RanName: %s", aPtrRicControlGrpcReq.RanName)
49                         lRicControlGrpcRsp.RspCode = GRPC_SUCCESS //int32(lGrpcRspStatusCode)
50                         lRicControlGrpcRsp.Description = "Success Response"
51                         xapp.Logger.Debug("RICHOCONTROL_EVENT: Success Response sent with  RspCode:%d, Description:%s", lRicControlGrpcRsp.RspCode, lRicControlGrpcRsp.Description)
52                 }
53         }
54
55         xapp.Logger.Info("RICHOCONTROL_EVENT: Response sent with  RspCode:%d, Description:%s", lRicControlGrpcRsp.RspCode, lRicControlGrpcRsp.Description)
56
57         log.Printf(" Response sent to , rsp: {Code: ", lRicControlGrpcRsp.RspCode, ", Description: ", lRicControlGrpcRsp.Description, "}")
58         return &lRicControlGrpcRsp, nil
59 }