ea21995a3f2544e637559d5e8a92cb589b6da240
[ric-plt/submgr.git] / e2ap / pkg / e2ap_wrapper / ut_packer_e2ap.go
1 /*
2 ==================================================================================
3   Copyright (c) 2021 Nokia
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================================
17 */
18
19 package e2ap_wrapper
20
21 import (
22         "fmt"
23
24         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
25 )
26
27 const (
28         SUB_REQ         int = 1
29         SUB_RESP        int = 2
30         SUB_FAILURE     int = 3
31         SUB_DEL_REQ     int = 4
32         SUB_DEL_RESP    int = 5
33         SUB_DEL_FAILURE int = 6
34 )
35
36 //-----------------------------------------------------------------------------
37 //
38 //-----------------------------------------------------------------------------
39
40 var origPackerif e2ap.E2APPackerIf = NewAsn1E2Packer()
41
42 var allowAction = map[int]bool{
43         SUB_REQ:         true,
44         SUB_RESP:        true,
45         SUB_FAILURE:     true,
46         SUB_DEL_REQ:     true,
47         SUB_DEL_RESP:    true,
48         SUB_DEL_FAILURE: true,
49 }
50
51 func AllowE2apToProcess(mtype int, actionFail bool) {
52         allowAction[mtype] = actionFail
53 }
54
55 type utMsgPackerSubscriptionRequest struct {
56         e2apMsgPackerSubscriptionRequest
57 }
58
59 func (e2apMsg *utMsgPackerSubscriptionRequest) init() {
60 }
61
62 func (e2apMsg *utMsgPackerSubscriptionRequest) Pack(data *e2ap.E2APSubscriptionRequest) (error, *e2ap.PackedData) {
63         if allowAction[SUB_REQ] {
64                 e2sub := origPackerif.NewPackerSubscriptionRequest()
65                 return e2sub.Pack(data)
66         }
67         return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_REQ]), nil
68 }
69
70 func (e2apMsg *utMsgPackerSubscriptionRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionRequest) {
71         if allowAction[SUB_REQ] {
72                 e2sub := origPackerif.NewPackerSubscriptionRequest()
73                 return e2sub.UnPack(msg)
74         }
75         return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_REQ]), nil
76 }
77
78 func (e2apMsg *utMsgPackerSubscriptionRequest) String() string {
79         return "utMsgPackerSubscriptionRequest"
80 }
81
82 //-----------------------------------------------------------------------------
83 //
84 //-----------------------------------------------------------------------------
85 type utMsgPackerSubscriptionResponse struct {
86         e2apMsgPackerSubscriptionResponse
87 }
88
89 func (e2apMsg *utMsgPackerSubscriptionResponse) init() {
90 }
91
92 func (e2apMsg *utMsgPackerSubscriptionResponse) Pack(data *e2ap.E2APSubscriptionResponse) (error, *e2ap.PackedData) {
93         if allowAction[SUB_RESP] {
94                 e2sub := origPackerif.NewPackerSubscriptionResponse()
95                 return e2sub.Pack(data)
96         }
97         return fmt.Errorf("Error: Set to be fail by UT"), nil
98 }
99
100 func (e2apMsg *utMsgPackerSubscriptionResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionResponse) {
101         if allowAction[SUB_RESP] {
102                 e2sub := origPackerif.NewPackerSubscriptionResponse()
103                 return e2sub.UnPack(msg)
104         }
105         return fmt.Errorf("Error: Set to be fail by UT"), nil
106 }
107
108 func (e2apMsg *utMsgPackerSubscriptionResponse) String() string {
109         return "utMsgPackerSubscriptionResponse"
110 }
111
112 //-----------------------------------------------------------------------------
113 //
114 //-----------------------------------------------------------------------------
115 type utMsgPackerSubscriptionFailure struct {
116         e2apMsgPackerSubscriptionFailure
117 }
118
119 func (e2apMsg *utMsgPackerSubscriptionFailure) init() {
120 }
121
122 func (e2apMsg *utMsgPackerSubscriptionFailure) Pack(data *e2ap.E2APSubscriptionFailure) (error, *e2ap.PackedData) {
123         if allowAction[SUB_FAILURE] {
124                 e2sub := origPackerif.NewPackerSubscriptionFailure()
125                 return e2sub.Pack(data)
126         }
127         return fmt.Errorf("Error: Set to be fail by UT"), nil
128 }
129
130 func (e2apMsg *utMsgPackerSubscriptionFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionFailure) {
131         if allowAction[SUB_FAILURE] {
132                 e2sub := origPackerif.NewPackerSubscriptionFailure()
133                 return e2sub.UnPack(msg)
134         }
135         return fmt.Errorf("Error: Set to be fail by UT"), nil
136 }
137
138 func (e2apMsg *utMsgPackerSubscriptionFailure) String() string {
139         return "utMsgPackerSubscriptionFailure"
140 }
141
142 //-----------------------------------------------------------------------------
143 //
144 //-----------------------------------------------------------------------------
145 type utMsgPackerSubscriptionDeleteRequest struct {
146         e2apMsgPackerSubscriptionDeleteRequest
147 }
148
149 func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) init() {
150 }
151
152 func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) Pack(data *e2ap.E2APSubscriptionDeleteRequest) (error, *e2ap.PackedData) {
153         if allowAction[SUB_DEL_REQ] {
154                 e2sub := origPackerif.NewPackerSubscriptionDeleteRequest()
155                 return e2sub.Pack(data)
156         }
157         return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_DEL_REQ]), nil
158 }
159
160 func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteRequest) {
161         if allowAction[SUB_DEL_REQ] {
162                 e2sub := origPackerif.NewPackerSubscriptionDeleteRequest()
163                 return e2sub.UnPack(msg)
164         }
165         return fmt.Errorf("Error: Set to be fail by UT (%v)", allowAction[SUB_DEL_REQ]), nil
166 }
167
168 func (e2apMsg *utMsgPackerSubscriptionDeleteRequest) String() string {
169         return "utMsgPackerSubscriptionDeleteRequest"
170 }
171
172 //-----------------------------------------------------------------------------
173 //
174 //-----------------------------------------------------------------------------
175 type utMsgPackerSubscriptionDeleteResponse struct {
176         e2apMsgPackerSubscriptionDeleteResponse
177 }
178
179 func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) init() {
180
181 }
182
183 func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) Pack(data *e2ap.E2APSubscriptionDeleteResponse) (error, *e2ap.PackedData) {
184         if allowAction[SUB_DEL_RESP] {
185                 e2sub := origPackerif.NewPackerSubscriptionDeleteResponse()
186                 return e2sub.Pack(data)
187         }
188         return fmt.Errorf("Error: Set to be fail by UT"), nil
189 }
190
191 func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteResponse) {
192         if allowAction[SUB_DEL_RESP] {
193                 e2sub := origPackerif.NewPackerSubscriptionDeleteResponse()
194                 return e2sub.UnPack(msg)
195         }
196         return fmt.Errorf("Error: Set to be fail by UT"), nil
197 }
198
199 func (e2apMsg *utMsgPackerSubscriptionDeleteResponse) String() string {
200         return "utMsgPackerSubscriptionDeleteResponse"
201 }
202
203 //-----------------------------------------------------------------------------
204 //
205 //-----------------------------------------------------------------------------
206 type utMsgPackerSubscriptionDeleteFailure struct {
207         e2apMsgPackerSubscriptionDeleteFailure
208 }
209
210 func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) init() {
211 }
212
213 func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) Pack(data *e2ap.E2APSubscriptionDeleteFailure) (error, *e2ap.PackedData) {
214         if allowAction[SUB_DEL_FAILURE] {
215                 e2sub := origPackerif.NewPackerSubscriptionDeleteFailure()
216                 return e2sub.Pack(data)
217         }
218         return fmt.Errorf("Error: Set to be fail by UT"), nil
219 }
220
221 func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) UnPack(msg *e2ap.PackedData) (error, *e2ap.E2APSubscriptionDeleteFailure) {
222         if allowAction[SUB_DEL_FAILURE] {
223                 e2sub := origPackerif.NewPackerSubscriptionDeleteFailure()
224                 return e2sub.UnPack(msg)
225         }
226         return fmt.Errorf("Error: Set to be fail by UT"), nil
227 }
228
229 func (e2apMsg *utMsgPackerSubscriptionDeleteFailure) String() string {
230         return "utMsgPackerSubscriptionDeleteFailure"
231 }
232
233 //-----------------------------------------------------------------------------
234 // Public E2AP packer creators
235 //-----------------------------------------------------------------------------
236
237 type utAsn1E2APPacker struct{}
238
239 func (*utAsn1E2APPacker) NewPackerSubscriptionRequest() e2ap.E2APMsgPackerSubscriptionRequestIf {
240         return &utMsgPackerSubscriptionRequest{}
241 }
242
243 func (*utAsn1E2APPacker) NewPackerSubscriptionResponse() e2ap.E2APMsgPackerSubscriptionResponseIf {
244         return &utMsgPackerSubscriptionResponse{}
245 }
246
247 func (*utAsn1E2APPacker) NewPackerSubscriptionFailure() e2ap.E2APMsgPackerSubscriptionFailureIf {
248         return &utMsgPackerSubscriptionFailure{}
249 }
250
251 func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteRequest() e2ap.E2APMsgPackerSubscriptionDeleteRequestIf {
252         return &utMsgPackerSubscriptionDeleteRequest{}
253 }
254
255 func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteResponse() e2ap.E2APMsgPackerSubscriptionDeleteResponseIf {
256         return &utMsgPackerSubscriptionDeleteResponse{}
257 }
258
259 func (*utAsn1E2APPacker) NewPackerSubscriptionDeleteFailure() e2ap.E2APMsgPackerSubscriptionDeleteFailureIf {
260         return &utMsgPackerSubscriptionDeleteFailure{}
261 }
262
263 func NewUtAsn1E2APPacker() e2ap.E2APPackerIf {
264         return &utAsn1E2APPacker{}
265 }