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