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 ==================================================================================
23 #include <rmr/RIC_message_types.h>
26 #cgo LDFLAGS: -lrmr_nng -lnng
32 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
42 func NewControl() Control {
43 return Control{new(E2ap),new(Registry)}
46 func (c *Control) Run() {
50 func (c *Control) Consume(mtype, sub_id int, len int, payload []byte) (err error) {
53 err = c.handleSubscriptionRequest(&RmrDatagram{mtype, sub_id, payload})
55 err = c.handleSubscriptionResponse(&RmrDatagram{mtype, sub_id, payload})
57 err = errors.New("Message Type "+strconv.Itoa(mtype)+" discarded")
62 func (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")
69 func (c *Control) handleSubscriptionRequest(datagram *RmrDatagram) ( err error) {
70 /* TODO: removed to being able to integrate with UEMGR
71 content, err := c.e2ap.GetPayloadContent(datagram.Payload)
73 xapp.Logger.Info("Subscription Request Message received with ID: %v", datagram.SubscriptionId)
74 new_sub_id := c.registry.GetSubscriptionId()
75 /* TODO: removed to being able to integrate with UEMGR
76 payload, err := c.e2ap.SetSubscriptionSequenceNumber(datagram.Payload, new_sub_id)
78 xapp.Logger.Error("Unable to set Subscription Sequence Number in Payload due to: "+ err.Error())
82 xapp.Logger.Info("New Subscription Registered, forwarding to E2T")
83 c.rmrSend(&RmrDatagram{C.RIC_SUB_REQ , new_sub_id, datagram.Payload})
87 func (c *Control) handleSubscriptionResponse(datagram *RmrDatagram) ( err error) {
88 /* TODO: removed to being able to integrate with UEMGR
89 content, err := c.e2ap.GetPayloadContent(datagram.Payload)
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})