f0b33812316854a4696f796647232be618dbf3c7
[ric-plt/submgr.git] / pkg / control / e2ap.go
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 <wrapper.h>
24
25 #cgo LDFLAGS: -le2ap_wrapper -le2ap
26 */
27 import "C"
28
29 import (
30         "encoding/hex"
31         "fmt"
32         "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"
35         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
36 )
37
38 var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
39
40 type E2ap struct {
41 }
42
43 //-----------------------------------------------------------------------------
44 //
45 //-----------------------------------------------------------------------------
46 func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
47         e2SubReq := packerif.NewPackerSubscriptionRequest()
48         packedData := &packer.PackedData{}
49         packedData.Buf = payload
50         err, subReq := e2SubReq.UnPack(packedData)
51         if err != nil {
52                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
53         }
54         return subReq, nil
55 }
56
57 func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *packer.PackedData, error) {
58         e2SubReq := packerif.NewPackerSubscriptionRequest()
59         err, packedData := e2SubReq.Pack(req)
60         if err != nil {
61                 return 0, nil, err
62         }
63         return xapp.RIC_SUB_REQ, packedData, nil
64 }
65
66 //-----------------------------------------------------------------------------
67 //
68 //-----------------------------------------------------------------------------
69 func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
70         e2SubResp := packerif.NewPackerSubscriptionResponse()
71         packedData := &packer.PackedData{}
72         packedData.Buf = payload
73         err, subResp := e2SubResp.UnPack(packedData)
74         if err != nil {
75                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
76         }
77         return subResp, nil
78 }
79
80 func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *packer.PackedData, error) {
81         e2SubResp := packerif.NewPackerSubscriptionResponse()
82         err, packedData := e2SubResp.Pack(req)
83         if err != nil {
84                 return 0, nil, err
85         }
86         return xapp.RIC_SUB_RESP, packedData, nil
87 }
88
89 //-----------------------------------------------------------------------------
90 //
91 //-----------------------------------------------------------------------------
92 func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
93         e2SubFail := packerif.NewPackerSubscriptionFailure()
94         packedData := &packer.PackedData{}
95         packedData.Buf = payload
96         err, subFail := e2SubFail.UnPack(packedData)
97         if err != nil {
98                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
99         }
100         return subFail, nil
101 }
102
103 func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *packer.PackedData, error) {
104         e2SubFail := packerif.NewPackerSubscriptionFailure()
105         err, packedData := e2SubFail.Pack(req)
106         if err != nil {
107                 return 0, nil, err
108         }
109         return xapp.RIC_SUB_FAILURE, packedData, nil
110 }
111
112 //-----------------------------------------------------------------------------
113 //
114 //-----------------------------------------------------------------------------
115 func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
116         e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
117         packedData := &packer.PackedData{}
118         packedData.Buf = payload
119         err, subDelReq := e2SubDelReq.UnPack(packedData)
120         if err != nil {
121                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
122         }
123         return subDelReq, nil
124 }
125
126 func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *packer.PackedData, error) {
127         e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
128         err, packedData := e2SubDelReq.Pack(req)
129         if err != nil {
130                 return 0, nil, err
131         }
132         return xapp.RIC_SUB_DEL_REQ, packedData, nil
133 }
134
135 //-----------------------------------------------------------------------------
136 //
137 //-----------------------------------------------------------------------------
138 func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
139         e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
140         packedData := &packer.PackedData{}
141         packedData.Buf = payload
142         err, subDelResp := e2SubDelResp.UnPack(packedData)
143         if err != nil {
144                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
145         }
146         return subDelResp, nil
147 }
148
149 func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *packer.PackedData, error) {
150         e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
151         err, packedData := e2SubDelResp.Pack(req)
152         if err != nil {
153                 return 0, nil, err
154         }
155         return xapp.RIC_SUB_DEL_RESP, packedData, nil
156 }
157
158 //-----------------------------------------------------------------------------
159 //
160 //-----------------------------------------------------------------------------
161 func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
162         e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
163         packedData := &packer.PackedData{}
164         packedData.Buf = payload
165         err, subDelFail := e2SubDelFail.UnPack(packedData)
166         if err != nil {
167                 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
168         }
169         return subDelFail, nil
170 }
171
172 func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *packer.PackedData, error) {
173         e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
174         err, packedData := e2SubDelFail.Pack(req)
175         if err != nil {
176                 return 0, nil, err
177         }
178         return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
179 }