blob: f564c484a24ec9b810fc5838113ec7beb021814a [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"
34 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer"
Juha Hyttinen63284a22020-01-15 10:45:11 +020035 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy45114752019-06-18 14:40:39 +020036)
37
Anssi Mannila8046c702020-01-02 13:39:05 +020038var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
39
kalnagy45114752019-06-18 14:40:39 +020040type E2ap struct {
41}
42
Juha Hyttinen86a46202020-01-14 12:49:09 +020043//-----------------------------------------------------------------------------
44//
45//-----------------------------------------------------------------------------
46func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
Anssi Mannila8046c702020-01-02 13:39:05 +020047 e2SubReq := packerif.NewPackerSubscriptionRequest()
48 packedData := &packer.PackedData{}
49 packedData.Buf = payload
Juha Hyttinen86a46202020-01-14 12:49:09 +020050 err := e2SubReq.UnPack(packedData)
Anssi Mannila8046c702020-01-02 13:39:05 +020051 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020052 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Anssi Mannila8046c702020-01-02 13:39:05 +020053 }
Juha Hyttinen86a46202020-01-14 12:49:09 +020054 err, subReq := e2SubReq.Get()
55 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020056 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Anssi Mannila8046c702020-01-02 13:39:05 +020057 }
Juha Hyttinen86a46202020-01-14 12:49:09 +020058 return subReq, nil
59}
Anssi Mannila8046c702020-01-02 13:39:05 +020060
Juha Hyttinen63284a22020-01-15 10:45:11 +020061func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *packer.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +020062 e2SubReq := packerif.NewPackerSubscriptionRequest()
63 err := e2SubReq.Set(req)
Anssi Mannila8046c702020-01-02 13:39:05 +020064 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020065 return 0, nil, err
Anssi Mannila8046c702020-01-02 13:39:05 +020066 }
Juha Hyttinen86a46202020-01-14 12:49:09 +020067 err, packedData := e2SubReq.Pack(nil)
Anssi Mannila8046c702020-01-02 13:39:05 +020068 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020069 return 0, nil, err
Anssi Mannila8046c702020-01-02 13:39:05 +020070 }
Juha Hyttinen63284a22020-01-15 10:45:11 +020071 return xapp.RIC_SUB_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +020072}
73
74//-----------------------------------------------------------------------------
75//
76//-----------------------------------------------------------------------------
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020077func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
78 e2SubResp := packerif.NewPackerSubscriptionResponse()
79 packedData := &packer.PackedData{}
80 packedData.Buf = payload
81 err := e2SubResp.UnPack(packedData)
82 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020083 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020084 }
85 err, subResp := e2SubResp.Get()
86 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +020087 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020088 }
89 return subResp, nil
90}
91
Juha Hyttinen63284a22020-01-15 10:45:11 +020092func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *packer.PackedData, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020093 e2SubResp := packerif.NewPackerSubscriptionResponse()
94 err := e2SubResp.Set(req)
95 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +020096 return 0, nil, err
Juha Hyttinenaafee7f2020-01-14 14:54:51 +020097 }
98 err, packedData := e2SubResp.Pack(nil)
99 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200100 return 0, nil, err
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200101 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200102 return xapp.RIC_SUB_RESP, packedData, nil
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200103}
104
105//-----------------------------------------------------------------------------
106//
107//-----------------------------------------------------------------------------
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200108func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
109 e2SubFail := packerif.NewPackerSubscriptionFailure()
110 packedData := &packer.PackedData{}
111 packedData.Buf = payload
112 err := e2SubFail.UnPack(packedData)
113 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200114 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200115 }
116 err, subFail := e2SubFail.Get()
117 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200118 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200119 }
120 return subFail, nil
121}
122
Juha Hyttinen63284a22020-01-15 10:45:11 +0200123func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *packer.PackedData, error) {
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200124 e2SubFail := packerif.NewPackerSubscriptionFailure()
125 err := e2SubFail.Set(req)
126 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200127 return 0, nil, err
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200128 }
129 err, packedData := e2SubFail.Pack(nil)
130 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200131 return 0, nil, err
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200132 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200133 return xapp.RIC_SUB_FAILURE, packedData, nil
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200134}
135
136//-----------------------------------------------------------------------------
137//
138//-----------------------------------------------------------------------------
Juha Hyttinen86a46202020-01-14 12:49:09 +0200139func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
140 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
141 packedData := &packer.PackedData{}
142 packedData.Buf = payload
143 err := e2SubDelReq.UnPack(packedData)
144 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200145 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen86a46202020-01-14 12:49:09 +0200146 }
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200147 err, subDelReq := e2SubDelReq.Get()
Juha Hyttinen86a46202020-01-14 12:49:09 +0200148 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200149 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen86a46202020-01-14 12:49:09 +0200150 }
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200151 return subDelReq, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200152}
153
Juha Hyttinen63284a22020-01-15 10:45:11 +0200154func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *packer.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200155 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
156 err := e2SubDelReq.Set(req)
157 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200158 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200159 }
160 err, packedData := e2SubDelReq.Pack(nil)
161 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200162 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200163 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200164 return xapp.RIC_SUB_DEL_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200165}
166
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200167//-----------------------------------------------------------------------------
168//
169//-----------------------------------------------------------------------------
170func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
171 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
172 packedData := &packer.PackedData{}
173 packedData.Buf = payload
174 err := e2SubDelResp.UnPack(packedData)
175 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200176 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200177 }
178 err, subDelResp := e2SubDelResp.Get()
179 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200180 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200181 }
182 return subDelResp, nil
183}
184
Juha Hyttinen63284a22020-01-15 10:45:11 +0200185func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *packer.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200186 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
187 err := e2SubDelResp.Set(req)
188 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200189 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200190 }
191 err, packedData := e2SubDelResp.Pack(nil)
192 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200193 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200194 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200195 return xapp.RIC_SUB_DEL_RESP, packedData, nil
Anssi Mannila8046c702020-01-02 13:39:05 +0200196}
Juha Hyttinen375c1412020-01-14 20:17:50 +0200197
198//-----------------------------------------------------------------------------
199//
200//-----------------------------------------------------------------------------
201func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
202 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
203 packedData := &packer.PackedData{}
204 packedData.Buf = payload
205 err := e2SubDelFail.UnPack(packedData)
206 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200207 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen375c1412020-01-14 20:17:50 +0200208 }
209 err, subDelFail := e2SubDelFail.Get()
210 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200211 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen375c1412020-01-14 20:17:50 +0200212 }
213 return subDelFail, nil
214}
215
Juha Hyttinen63284a22020-01-15 10:45:11 +0200216func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *packer.PackedData, error) {
Juha Hyttinen375c1412020-01-14 20:17:50 +0200217 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
218 err := e2SubDelFail.Set(req)
219 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200220 return 0, nil, err
Juha Hyttinen375c1412020-01-14 20:17:50 +0200221 }
222 err, packedData := e2SubDelFail.Pack(nil)
223 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200224 return 0, nil, err
Juha Hyttinen375c1412020-01-14 20:17:50 +0200225 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200226 return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
Juha Hyttinen375c1412020-01-14 20:17:50 +0200227}