kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package control |
| 21 | |
| 22 | /* |
| 23 | #include <rmr/RIC_message_types.h> |
| 24 | |
| 25 | #cgo CFLAGS: -I../ |
| 26 | #cgo LDFLAGS: -lrmr_nng -lnng |
| 27 | */ |
| 28 | import "C" |
| 29 | |
| 30 | |
| 31 | import ( |
| 32 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 33 | "errors" |
| 34 | "strconv" |
| 35 | ) |
| 36 | |
| 37 | type Control struct { |
| 38 | e2ap *E2ap |
| 39 | registry *Registry |
| 40 | } |
| 41 | |
| 42 | func NewControl() Control { |
| 43 | return Control{new(E2ap),new(Registry)} |
| 44 | } |
| 45 | |
| 46 | func (c *Control) Run() { |
| 47 | xapp.Run(c) |
| 48 | } |
| 49 | |
| 50 | func (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 | |
| 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") |
| 65 | } |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | func (c *Control) handleSubscriptionRequest(datagram *RmrDatagram) ( err error) { |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 70 | /* TODO: removed to being able to integrate with UEMGR |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 71 | content, err := c.e2ap.GetPayloadContent(datagram.Payload) |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 72 | */ |
| 73 | xapp.Logger.Info("Subscription Request Message received with ID: %v", datagram.SubscriptionId) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 74 | new_sub_id := c.registry.GetSubscriptionId() |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 75 | /* TODO: removed to being able to integrate with UEMGR |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 76 | 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 | } |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 81 | */ |
| 82 | xapp.Logger.Info("New Subscription Registered, forwarding to E2T") |
| 83 | c.rmrSend(&RmrDatagram{C.RIC_SUB_REQ , new_sub_id, datagram.Payload}) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 84 | return |
| 85 | } |
| 86 | |
| 87 | func (c *Control) handleSubscriptionResponse(datagram *RmrDatagram) ( err error) { |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 88 | /* TODO: removed to being able to integrate with UEMGR |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 89 | content, err := c.e2ap.GetPayloadContent(datagram.Payload) |
kalnagy | e6e9432 | 2019-06-21 10:19:12 +0200 | [diff] [blame] | 90 | */ |
| 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}) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 94 | return |
| 95 | } |