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