67a5858a817c5f24670db57f237c9e7fb1cb0a2e
[ric-plt/submgr.git] / e2ap / pkg / e2ap / e2ap_tests / msg_e2ap_subscription.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 e2ap_tests
21
22 import (
23         "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
24         "testing"
25 )
26
27 //-----------------------------------------------------------------------------
28 //
29 //-----------------------------------------------------------------------------
30
31 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionRequestWithData(t *testing.T, areqenc *e2ap.E2APSubscriptionRequest) {
32
33         e2SubsReq := testCtxt.packerif.NewPackerSubscriptionRequest()
34
35         testCtxt.testPrint("########## ##########")
36         testCtxt.testPrint("init")
37         testCtxt.testPrint("pack")
38
39         err, packedMsg := e2SubsReq.Pack(areqenc)
40         if err != nil {
41                 testCtxt.testError(t, "Pack failed: %s", err.Error())
42                 return
43         }
44         testCtxt.testPrint("print:\n%s", e2SubsReq.String())
45         testCtxt.testPrint("unpack")
46
47         err, areqdec := e2SubsReq.UnPack(packedMsg)
48         if err != nil {
49                 testCtxt.testError(t, "UnPack failed: %s", err.Error())
50                 return
51         }
52         testCtxt.testPrint("print:\n%s", e2SubsReq.String())
53
54         testCtxt.testValueEquality(t, "msg", areqenc, areqdec)
55         testCtxt.testValueEquality(t, "EventTriggerDefinition", &areqenc.EventTriggerDefinition, &areqdec.EventTriggerDefinition)
56 }
57 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionRequest(t *testing.T, msgContent *SubscriptionTestMsgContent) {
58
59         areqenc := e2ap.E2APSubscriptionRequest{}
60         areqenc.RequestId.Id = 1
61         areqenc.RequestId.InstanceId = 22
62         areqenc.FunctionId = 33
63
64         if msgContent.NBX2EventTriggerDefinitionPresent {
65                 areqenc.EventTriggerDefinition.Data.Length = 1
66                 areqenc.EventTriggerDefinition.Data.Data = make([]uint8, areqenc.EventTriggerDefinition.Data.Length)
67                 areqenc.EventTriggerDefinition.Data.Data[0] = 1
68         } else if msgContent.NBNRTEventTriggerDefinitionPresent {
69                 areqenc.EventTriggerDefinition.Data.Length = 1
70                 areqenc.EventTriggerDefinition.Data.Data = make([]uint8, areqenc.EventTriggerDefinition.Data.Length)
71                 areqenc.EventTriggerDefinition.Data.Data[0] = 100
72         }
73
74         for index := 0; index < 1; /*16*/ index++ {
75                 item := e2ap.ActionToBeSetupItem{}
76                 item.ActionId = uint64(index)
77                 item.ActionType = e2ap.E2AP_ActionTypeInsert
78
79                 item.RicActionDefinitionPresent = true
80
81                 if item.RicActionDefinitionPresent {
82                         if msgContent.ActionDefinitionX2Format1Present {
83                                 item.ActionDefinitionChoice.Data.Length = 1
84                                 item.ActionDefinitionChoice.Data.Data = make([]uint8, item.ActionDefinitionChoice.Data.Length)
85                                 item.ActionDefinitionChoice.Data.Data[0] = 1
86                         } else if msgContent.ActionDefinitionX2Format2Present {
87                                 item.ActionDefinitionChoice.Data.Length = 1
88                                 item.ActionDefinitionChoice.Data.Data = make([]uint8, item.ActionDefinitionChoice.Data.Length)
89                                 item.ActionDefinitionChoice.Data.Data[0] = 2
90                         } else if msgContent.ActionDefinitionNRTFormat1Present {
91                                 item.ActionDefinitionChoice.Data.Length = 1
92                                 item.ActionDefinitionChoice.Data.Data = make([]uint8, item.ActionDefinitionChoice.Data.Length)
93                                 item.ActionDefinitionChoice.Data.Data[0] = 3
94                         }
95                 }
96                 item.SubsequentAction.Present = true
97                 item.SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
98                 item.SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitW100ms
99                 areqenc.ActionSetups = append(areqenc.ActionSetups, item)
100         }
101         testCtxt.E2ApTestMsgSubscriptionRequestWithData(t, &areqenc)
102 }
103
104 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionResponse(t *testing.T) {
105
106         testCtxt.SetDesc("SubsResp")
107
108         e2SubsResp := testCtxt.packerif.NewPackerSubscriptionResponse()
109
110         testCtxt.testPrint("########## ##########")
111         testCtxt.testPrint("init")
112
113         arespenc := e2ap.E2APSubscriptionResponse{}
114         arespenc.RequestId.Id = 1
115         arespenc.RequestId.InstanceId = 22
116         arespenc.FunctionId = 33
117         for index := uint64(0); index < 16; index++ {
118                 item := e2ap.ActionAdmittedItem{}
119                 item.ActionId = index
120                 arespenc.ActionAdmittedList.Items = append(arespenc.ActionAdmittedList.Items, item)
121         }
122         for index := uint64(0); index < 16; index++ {
123                 item := e2ap.ActionNotAdmittedItem{}
124                 item.ActionId = index
125                 item.Cause.Content = 1
126                 item.Cause.Value = 1
127                 arespenc.ActionNotAdmittedList.Items = append(arespenc.ActionNotAdmittedList.Items, item)
128         }
129
130         testCtxt.testPrint("pack")
131         err, packedMsg := e2SubsResp.Pack(&arespenc)
132         if err != nil {
133                 testCtxt.testError(t, "Pack failed: %s", err.Error())
134                 return
135         }
136         testCtxt.testPrint("print:\n%s", e2SubsResp.String())
137         testCtxt.testPrint("unpack")
138         err, arespdec := e2SubsResp.UnPack(packedMsg)
139         if err != nil {
140                 testCtxt.testError(t, "UnPack failed: %s", err.Error())
141                 return
142         }
143         testCtxt.testPrint("print:\n%s", e2SubsResp.String())
144         testCtxt.testValueEquality(t, "msg", &arespenc, arespdec)
145 }
146
147 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionFailure(t *testing.T) {
148
149         testCtxt.SetDesc("SubsFail")
150
151         e2SubsFail := testCtxt.packerif.NewPackerSubscriptionFailure()
152
153         testCtxt.testPrint("########## ##########")
154         testCtxt.testPrint("init")
155
156         afailenc := e2ap.E2APSubscriptionFailure{}
157         afailenc.RequestId.Id = 1
158         afailenc.RequestId.InstanceId = 22
159         afailenc.FunctionId = 33
160         for index := uint64(0); index < 16; index++ {
161                 item := e2ap.ActionNotAdmittedItem{}
162                 item.ActionId = index
163                 item.Cause.Content = 1
164                 item.Cause.Value = 1
165                 afailenc.ActionNotAdmittedList.Items = append(afailenc.ActionNotAdmittedList.Items, item)
166         }
167         // NOT SUPPORTED CURRENTLY
168         afailenc.CriticalityDiagnostics.Present = false
169         //      afailenc.CriticalityDiagnostics.ProcCodePresent = true
170         //      afailenc.CriticalityDiagnostics.ProcCode = 1
171         //      afailenc.CriticalityDiagnostics.TrigMsgPresent = true
172         //      afailenc.CriticalityDiagnostics.TrigMsg = 2
173         //      afailenc.CriticalityDiagnostics.ProcCritPresent = true
174         //      afailenc.CriticalityDiagnostics.ProcCrit = e2ap.E2AP_CriticalityReject
175         //      for index := uint32(0); index < 256; index++ {
176         //              ieitem := e2ap.CriticalityDiagnosticsIEListItem{}
177         //              ieitem.IeCriticality = e2ap.E2AP_CriticalityReject
178         //              ieitem.IeID = index
179         //              ieitem.TypeOfError = 1
180         //              afailenc.CriticalityDiagnostics.CriticalityDiagnosticsIEList.Items = append(afailenc.CriticalityDiagnostics.CriticalityDiagnosticsIEList.Items, ieitem)
181         //      }
182
183         testCtxt.testPrint("pack")
184         err, packedMsg := e2SubsFail.Pack(&afailenc)
185         if err != nil {
186                 testCtxt.testError(t, "Pack failed: %s", err.Error())
187                 return
188         }
189         testCtxt.testPrint("print:\n%s", e2SubsFail.String())
190         testCtxt.testPrint("unpack")
191         err, afaildec := e2SubsFail.UnPack(packedMsg)
192         if err != nil {
193                 testCtxt.testError(t, "UnPack failed: %s", err.Error())
194                 return
195         }
196         testCtxt.testPrint("print:\n%s", e2SubsFail.String())
197         testCtxt.testValueEquality(t, "msg", &afailenc, afaildec)
198 }
199
200 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionRequestBuffers(t *testing.T) {
201
202         testfunc := func(buffer string) {
203                 packedData := testCtxt.toPackedData(t, buffer)
204                 if packedData == nil {
205                         return
206                 }
207                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionRequest()
208                 err, _ := e2SubResp.UnPack(packedData)
209                 if err != nil {
210                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
211                         return
212                 }
213                 testCtxt.testPrint("OK [%s]", buffer)
214         }
215
216         testCtxt.SetDesc("SubReqBuffer")
217         testfunc("00c9402c000003ea7e00050000010000ea6300020001ea810016000b00130051407b000000054000ea6b000420000000")
218 }
219
220 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionResponseBuffers(t *testing.T) {
221
222         testfunc := func(buffer string) {
223                 packedData := testCtxt.toPackedData(t, buffer)
224                 if packedData == nil {
225                         return
226                 }
227                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionResponse()
228                 err, _ := e2SubResp.UnPack(packedData)
229                 if err != nil {
230                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
231                         return
232                 }
233                 testCtxt.testPrint("OK [%s]", buffer)
234         }
235
236         testCtxt.SetDesc("SubRespBuffer")
237         testfunc("20c9402a000004ea7e00050000018009ea6300020001ea6c000700ea6d00020000ea6e000908ea6f000400000040")
238         testfunc("20c9401d000003ea7e0005004eec0004ea6300020001ea6c000700ea6d40020000")
239
240 }
241
242 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionFailureBuffers(t *testing.T) {
243
244         testfunc := func(buffer string) {
245                 packedData := testCtxt.toPackedData(t, buffer)
246                 if packedData == nil {
247                         return
248                 }
249                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionFailure()
250                 err, _ := e2SubResp.UnPack(packedData)
251                 if err != nil {
252                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
253                         return
254                 }
255                 testCtxt.testPrint("OK [%s]", buffer)
256         }
257
258         testCtxt.SetDesc("SubFailBuffer")
259         testfunc("40c94017000003ea7e000500000106f3ea6300020001ea6e000100")
260 }