blob: b21eb3f2cc9fe392a59010616ea4141c38595905 [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/*
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020023#cgo LDFLAGS: -le2ap_wrapper -le2ap
Peter Szilagyifbc56f92019-07-23 19:29:46 +000024*/
25import "C"
26
kalnagy45114752019-06-18 14:40:39 +020027import (
Juha Hyttinen662f68d2020-01-15 14:49:18 +020028 "encoding/hex"
29 "fmt"
Anssi Mannila8046c702020-01-02 13:39:05 +020030 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
31 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
Juha Hyttinen63284a22020-01-15 10:45:11 +020032 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy45114752019-06-18 14:40:39 +020033)
34
Anssi Mannila8046c702020-01-02 13:39:05 +020035var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
36
kalnagy45114752019-06-18 14:40:39 +020037type E2ap struct {
38}
39
Juha Hyttinen86a46202020-01-14 12:49:09 +020040//-----------------------------------------------------------------------------
41//
42//-----------------------------------------------------------------------------
43func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
Anssi Mannila8046c702020-01-02 13:39:05 +020044 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020045 err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +020046 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020047 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Anssi Mannila8046c702020-01-02 13:39:05 +020048 }
Juha Hyttinen86a46202020-01-14 12:49:09 +020049 return subReq, nil
50}
Anssi Mannila8046c702020-01-02 13:39:05 +020051
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020052func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +020053 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020054 err, packedData := e2SubReq.Pack(req)
Anssi Mannila8046c702020-01-02 13:39:05 +020055 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020056 return 0, nil, err
Anssi Mannila8046c702020-01-02 13:39:05 +020057 }
Juha Hyttinen63284a22020-01-15 10:45:11 +020058 return xapp.RIC_SUB_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +020059}
60
61//-----------------------------------------------------------------------------
62//
63//-----------------------------------------------------------------------------
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020064func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
65 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020066 err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020067 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020068 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020069 }
70 return subResp, nil
71}
72
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020073func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020074 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020075 err, packedData := e2SubResp.Pack(req)
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020076 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020077 return 0, nil, err
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020078 }
Juha Hyttinen63284a22020-01-15 10:45:11 +020079 return xapp.RIC_SUB_RESP, packedData, nil
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020080}
81
82//-----------------------------------------------------------------------------
83//
84//-----------------------------------------------------------------------------
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020085func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
86 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020087 err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020088 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020089 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020090 }
91 return subFail, nil
92}
93
Juha Hyttinena9bf76c2020-02-05 14:06:57 +020094func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020095 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +020096 err, packedData := e2SubFail.Pack(req)
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020097 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020098 return 0, nil, err
Juha Hyttinen60bfcf92020-01-14 15:14:24 +020099 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200100 return xapp.RIC_SUB_FAILURE, packedData, nil
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200101}
102
103//-----------------------------------------------------------------------------
104//
105//-----------------------------------------------------------------------------
Juha Hyttinen86a46202020-01-14 12:49:09 +0200106func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
107 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200108 err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +0200109 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200110 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen86a46202020-01-14 12:49:09 +0200111 }
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200112 return subDelReq, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200113}
114
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200115func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200116 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200117 err, packedData := e2SubDelReq.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200118 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200119 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200120 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200121 return xapp.RIC_SUB_DEL_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200122}
123
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200124//-----------------------------------------------------------------------------
125//
126//-----------------------------------------------------------------------------
127func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
128 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200129 err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200130 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200131 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200132 }
133 return subDelResp, nil
134}
135
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200136func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200137 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200138 err, packedData := e2SubDelResp.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200139 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200140 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200141 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200142 return xapp.RIC_SUB_DEL_RESP, packedData, nil
Anssi Mannila8046c702020-01-02 13:39:05 +0200143}
Juha Hyttinen375c1412020-01-14 20:17:50 +0200144
145//-----------------------------------------------------------------------------
146//
147//-----------------------------------------------------------------------------
148func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
149 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200150 err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen375c1412020-01-14 20:17:50 +0200151 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200152 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen375c1412020-01-14 20:17:50 +0200153 }
154 return subDelFail, nil
155}
156
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200157func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen375c1412020-01-14 20:17:50 +0200158 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200159 err, packedData := e2SubDelFail.Pack(req)
Juha Hyttinen375c1412020-01-14 20:17:50 +0200160 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200161 return 0, nil, err
Juha Hyttinen375c1412020-01-14 20:17:50 +0200162 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200163 return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
Juha Hyttinen375c1412020-01-14 20:17:50 +0200164}