blob: d213c65e1c1179a8261bb4abf43f924e4f9c7cf3 [file] [log] [blame]
kalnagy45114752019-06-18 14:40:39 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
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==================================================================================
18*/
19
20package control
21
22/*
23#include <rmr/RIC_message_types.h>
24
25#cgo CFLAGS: -I../
26#cgo LDFLAGS: -lrmr_nng -lnng
27*/
28import "C"
29
30
31import (
32 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
33 "errors"
34 "strconv"
35)
36
37type Control struct {
38 e2ap *E2ap
39 registry *Registry
40}
41
42func NewControl() Control {
43 return Control{new(E2ap),new(Registry)}
44}
45
46func (c *Control) Run() {
47 xapp.Run(c)
48}
49
50func (c *Control) Consume(mtype, sub_id int, len int, payload []byte) (err error) {
51 switch mtype {
52 case C.RIC_SUB_REQ:
53 err = c.handleSubscriptionRequest(&RmrDatagram{mtype, sub_id, payload})
54 case C.RIC_SUB_RESP:
55 err = c.handleSubscriptionResponse(&RmrDatagram{mtype, sub_id, payload})
56 default:
57 err = errors.New("Message Type "+strconv.Itoa(mtype)+" discarded")
58 }
59 return
60}
61
62func (c *Control) rmrSend(datagram *RmrDatagram) (err error) {
63 if !xapp.Rmr.Send(datagram.MessageType, datagram.SubscriptionId, len(datagram.Payload), datagram.Payload) {
64 err = errors.New("rmr.Send() failed")
65 }
66 return
67}
68
69func (c *Control) handleSubscriptionRequest(datagram *RmrDatagram) ( err error) {
kalnagye6e94322019-06-21 10:19:12 +020070 /* TODO: removed to being able to integrate with UEMGR
kalnagy45114752019-06-18 14:40:39 +020071 content, err := c.e2ap.GetPayloadContent(datagram.Payload)
kalnagye6e94322019-06-21 10:19:12 +020072 */
73 xapp.Logger.Info("Subscription Request Message received with ID: %v", datagram.SubscriptionId)
kalnagy45114752019-06-18 14:40:39 +020074 new_sub_id := c.registry.GetSubscriptionId()
kalnagye6e94322019-06-21 10:19:12 +020075 /* TODO: removed to being able to integrate with UEMGR
kalnagy45114752019-06-18 14:40:39 +020076 payload, err := c.e2ap.SetSubscriptionSequenceNumber(datagram.Payload, new_sub_id)
77 if err != nil {
78 xapp.Logger.Error("Unable to set Subscription Sequence Number in Payload due to: "+ err.Error())
79 return
80 }
kalnagye6e94322019-06-21 10:19:12 +020081 */
82 xapp.Logger.Info("New Subscription Registered, forwarding to E2T")
83 c.rmrSend(&RmrDatagram{C.RIC_SUB_REQ , new_sub_id, datagram.Payload})
kalnagy45114752019-06-18 14:40:39 +020084 return
85}
86
87func (c *Control) handleSubscriptionResponse(datagram *RmrDatagram) ( err error) {
kalnagye6e94322019-06-21 10:19:12 +020088 /* TODO: removed to being able to integrate with UEMGR
kalnagy45114752019-06-18 14:40:39 +020089 content, err := c.e2ap.GetPayloadContent(datagram.Payload)
kalnagye6e94322019-06-21 10:19:12 +020090 */
91 xapp.Logger.Info("Subscription Response Message received with ID: %v", datagram.SubscriptionId)
92 xapp.Logger.Info("Subscription Response Registered, forwarding to Requestor")
93 c.rmrSend(&RmrDatagram{C.RIC_SUB_RESP , datagram.SubscriptionId, datagram.Payload})
kalnagy45114752019-06-18 14:40:39 +020094 return
95}