blob: ed2f6901c03c08450a18ef7173425e2c3c2b140b [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
Peter Szilagyifbc56f92019-07-23 19:29:46 +000022/*
23#include <wrapper.h>
24
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020025#cgo LDFLAGS: -le2ap_wrapper -le2ap
Peter Szilagyifbc56f92019-07-23 19:29:46 +000026*/
27import "C"
28
kalnagy45114752019-06-18 14:40:39 +020029import (
Juha Hyttinen662f68d2020-01-15 14:49:18 +020030 "encoding/hex"
31 "fmt"
Anssi Mannila8046c702020-01-02 13:39:05 +020032 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
33 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
Juha Hyttinen63284a22020-01-15 10:45:11 +020034 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy45114752019-06-18 14:40:39 +020035)
36
Anssi Mannila8046c702020-01-02 13:39:05 +020037var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
38
kalnagy45114752019-06-18 14:40:39 +020039type E2ap struct {
40}
41
Juha Hyttinen86a46202020-01-14 12:49:09 +020042//-----------------------------------------------------------------------------
43//
44//-----------------------------------------------------------------------------
45func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
Anssi Mannila8046c702020-01-02 13:39:05 +020046 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020047 err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +020048 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020049 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Anssi Mannila8046c702020-01-02 13:39:05 +020050 }
Juha Hyttinen86a46202020-01-14 12:49:09 +020051 return subReq, nil
52}
Anssi Mannila8046c702020-01-02 13:39:05 +020053
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020054func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +020055 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020056 err, packedData := e2SubReq.Pack(req)
Anssi Mannila8046c702020-01-02 13:39:05 +020057 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020058 return 0, nil, err
Anssi Mannila8046c702020-01-02 13:39:05 +020059 }
Juha Hyttinen63284a22020-01-15 10:45:11 +020060 return xapp.RIC_SUB_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +020061}
62
63//-----------------------------------------------------------------------------
64//
65//-----------------------------------------------------------------------------
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020066func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
67 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020068 err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020069 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020070 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020071 }
72 return subResp, nil
73}
74
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020075func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020076 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020077 err, packedData := e2SubResp.Pack(req)
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020078 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020079 return 0, nil, err
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020080 }
Juha Hyttinen63284a22020-01-15 10:45:11 +020081 return xapp.RIC_SUB_RESP, packedData, nil
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020082}
83
84//-----------------------------------------------------------------------------
85//
86//-----------------------------------------------------------------------------
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020087func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
88 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020089 err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020090 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020091 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020092 }
93 return subFail, nil
94}
95
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020096func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020097 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020098 err, packedData := e2SubFail.Pack(req)
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020099 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200100 return 0, nil, err
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200101 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200102 return xapp.RIC_SUB_FAILURE, packedData, nil
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200103}
104
105//-----------------------------------------------------------------------------
106//
107//-----------------------------------------------------------------------------
Juha Hyttinen86a46202020-01-14 12:49:09 +0200108func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
109 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200110 err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +0200111 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200112 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen86a46202020-01-14 12:49:09 +0200113 }
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200114 return subDelReq, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200115}
116
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200117func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200118 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200119 err, packedData := e2SubDelReq.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200120 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200121 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200122 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200123 return xapp.RIC_SUB_DEL_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200124}
125
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200126//-----------------------------------------------------------------------------
127//
128//-----------------------------------------------------------------------------
129func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
130 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200131 err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200132 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200133 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200134 }
135 return subDelResp, nil
136}
137
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200138func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200139 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200140 err, packedData := e2SubDelResp.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200141 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200142 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200143 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200144 return xapp.RIC_SUB_DEL_RESP, packedData, nil
Anssi Mannila8046c702020-01-02 13:39:05 +0200145}
Juha Hyttinen375c1412020-01-14 20:17:50 +0200146
147//-----------------------------------------------------------------------------
148//
149//-----------------------------------------------------------------------------
150func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
151 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200152 err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen375c1412020-01-14 20:17:50 +0200153 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200154 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen375c1412020-01-14 20:17:50 +0200155 }
156 return subDelFail, nil
157}
158
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200159func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen375c1412020-01-14 20:17:50 +0200160 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200161 err, packedData := e2SubDelFail.Pack(req)
Juha Hyttinen375c1412020-01-14 20:17:50 +0200162 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200163 return 0, nil, err
Juha Hyttinen375c1412020-01-14 20:17:50 +0200164 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200165 return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
Juha Hyttinen375c1412020-01-14 20:17:50 +0200166}