2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
25 submgr "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/control"
26 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
27 "github.com/spf13/viper"
37 var c = make(chan submgr.RmrDatagram, 1)
38 var params xapp.RMRParams
40 var requestRawData string
41 var deleteRawData string
43 var deleteSeedSN uint16
47 viper.SetEnvPrefix("rco")
48 viper.AllowEmptyEnv(true)
49 requestRawData = viper.GetString("rawdata")
50 if requestRawData == "" {
51 requestRawData = "00c90020000003ea7e00050000010002ea6300020003ea81000a000000ea6b4003000440"
53 deleteRawData = viper.GetString("deleterawdata")
54 if deleteRawData == "" {
55 deleteRawData = "00ca0012000002ea7e00050000010002ea6300020003"
57 xapp.Logger.Info("Initial RAW DATA: %v", requestRawData)
58 xapp.Logger.Info("Initial DELETE RAW DATA: %v", deleteRawData)
59 seedSN = uint16(viper.GetInt("seed_sn"))
60 if seedSN == 0 || seedSN > 65535 {
63 deleteSeedSN = uint16(viper.GetInt("delete_seed_sn"))
64 if deleteSeedSN == 0 || deleteSeedSN > 65535 {
68 xapp.Logger.Info("Initial SEQUENCE NUMBER: %v", seedSN)
71 func (r *Rco) GeneratePayload(subId uint16) (payload []byte, err error) {
72 skeleton, err := hex.DecodeString(requestRawData)
74 return make([]byte, 0), errors.New("nable to decode data provided in \"RCO_RAWDATA\" environment variable")
76 payload, err = r.SetSubscriptionRequestSequenceNumber(skeleton, subId)
80 func (r *Rco) GenerateDeletePayload(subId uint16) (payload []byte, err error) {
81 skeleton, err := hex.DecodeString(deleteRawData)
83 return make([]byte, 0), errors.New("unable to decode data provided in \"RCO_DELETERAWDATA\" environment variable")
85 payload, err = r.SetSubscriptionDeleteRequestSequenceNumber(skeleton, subId)
89 func (r Rco) Consume(params *xapp.RMRParams) (err error) {
91 case xapp.RICMessageTypes["RIC_SUB_RESP"]:
92 payloadSeqNum, err := r.GetSubscriptionResponseSequenceNumber(params.Payload)
94 xapp.Logger.Error("SUBRESP: Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
96 xapp.Logger.Info("Subscription Response Message Received: RMR SUBSCRIPTION_ID: %v | PAYLOAD SEQUENCE_NUMBER: %v", params.SubId, payloadSeqNum)
98 case xapp.RICMessageTypes["RIC_SUB_DEL_RESP"]:
99 payloadSeqNum, err := r.GetSubscriptionDeleteResponseSequenceNumber(params.Payload)
101 xapp.Logger.Error("DELRESP: Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
103 xapp.Logger.Info("Subscription Delete Response Message Received: RMR SUBSCRIPTION_ID: %v | PAYLOAD SEQUENCE_NUMBER: %v", params.SubId, payloadSeqNum)
106 err = errors.New("Message Type " + strconv.Itoa(params.Mtype) + " is discarded")
107 xapp.Logger.Error("Unknown message type: %v", err)
112 func (r *Rco) SendRequests() (err error) {
113 message, err := r.GeneratePayload(seedSN)
115 xapp.Logger.Debug(err.Error())
118 deletemessage, err := r.GenerateDeletePayload(deleteSeedSN)
120 xapp.Logger.Debug(err.Error())
124 time.Sleep(5 * time.Second)
125 c <- submgr.RmrDatagram{MessageType: 12010, SubscriptionId: seedSN, Payload: message}
127 time.Sleep(5 * time.Second)
128 c <- submgr.RmrDatagram{MessageType: 12020, SubscriptionId: deleteSeedSN, Payload: deletemessage}
133 func (r *Rco) Run() {
136 payloadSeqNum, err := r.GetSubscriptionRequestSequenceNumber(message.Payload)
138 xapp.Logger.Debug("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
140 params.SubId = int(message.SubscriptionId)
141 params.Mtype = message.MessageType
142 params.PayloadLen = len(message.Payload)
143 params.Payload = message.Payload
144 xapp.Logger.Info("Sending Message: TYPE: %v | RMR SUBSCRIPTION_ID: %v | PAYLOAD SEQUENCE_NUMBER: %v)", message.MessageType, message.SubscriptionId, payloadSeqNum)
145 xapp.Rmr.Send(¶ms, false)
149 func (r *Rco) sendInvalidTestMessages() {
151 time.Sleep(7 * time.Second)
152 c <- submgr.RmrDatagram{MessageType: 10000, SubscriptionId: 0, Payload: make([]byte, 1)}
153 time.Sleep(7 * time.Second)
154 c <- submgr.RmrDatagram{MessageType: 12010, SubscriptionId: 0, Payload: make([]byte, 1)}
160 go xapp.Rmr.Start(rco)
162 go rco.sendInvalidTestMessages()
163 err := rco.SendRequests()
165 xapp.Logger.Info("Error: %v", err)