RIC-867: Submgr adaptations to E2APv2.0
[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.Cause.Content = e2ap.E2AP_CauseContent_RICrequest
160         afailenc.Cause.Value = e2ap.E2AP_CauseValue_RICrequest_control_message_invalid
161
162         // NOT SUPPORTED CURRENTLY
163         afailenc.CriticalityDiagnostics.Present = false
164         //      afailenc.CriticalityDiagnostics.ProcCodePresent = true
165         //      afailenc.CriticalityDiagnostics.ProcCode = 1
166         //      afailenc.CriticalityDiagnostics.TrigMsgPresent = true
167         //      afailenc.CriticalityDiagnostics.TrigMsg = 2
168         //      afailenc.CriticalityDiagnostics.ProcCritPresent = true
169         //      afailenc.CriticalityDiagnostics.ProcCrit = e2ap.E2AP_CriticalityReject
170         //      for index := uint32(0); index < 256; index++ {
171         //              ieitem := e2ap.CriticalityDiagnosticsIEListItem{}
172         //              ieitem.IeCriticality = e2ap.E2AP_CriticalityReject
173         //              ieitem.IeID = index
174         //              ieitem.TypeOfError = 1
175         //              afailenc.CriticalityDiagnostics.CriticalityDiagnosticsIEList.Items = append(afailenc.CriticalityDiagnostics.CriticalityDiagnosticsIEList.Items, ieitem)
176         //      }
177
178         testCtxt.testPrint("pack")
179         err, packedMsg := e2SubsFail.Pack(&afailenc)
180         if err != nil {
181                 testCtxt.testError(t, "Pack failed: %s", err.Error())
182                 return
183         }
184         testCtxt.testPrint("print:\n%s", e2SubsFail.String())
185         testCtxt.testPrint("unpack")
186         err, afaildec := e2SubsFail.UnPack(packedMsg)
187         if err != nil {
188                 testCtxt.testError(t, "UnPack failed: %s", err.Error())
189                 return
190         }
191         testCtxt.testPrint("print:\n%s", e2SubsFail.String())
192         testCtxt.testValueEquality(t, "msg", &afailenc, afaildec)
193 }
194
195 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionRequestBuffers(t *testing.T) {
196
197         testfunc := func(buffer string) {
198                 packedData := testCtxt.toPackedData(t, buffer)
199                 if packedData == nil {
200                         return
201                 }
202                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionRequest()
203                 err, _ := e2SubResp.UnPack(packedData)
204                 if err != nil {
205                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
206                         return
207                 }
208                 testCtxt.testPrint("OK [%s]", buffer)
209         }
210
211         testCtxt.SetDesc("SubReqBuffer")
212         testfunc("00c9402c000003ea7e00050000010000ea6300020001ea810016000b00130051407b000000054000ea6b000420000000")
213 }
214
215 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionResponseBuffers(t *testing.T) {
216
217         testfunc := func(buffer string) {
218                 packedData := testCtxt.toPackedData(t, buffer)
219                 if packedData == nil {
220                         return
221                 }
222                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionResponse()
223                 err, _ := e2SubResp.UnPack(packedData)
224                 if err != nil {
225                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
226                         return
227                 }
228                 testCtxt.testPrint("OK [%s]", buffer)
229         }
230
231         testCtxt.SetDesc("SubRespBuffer")
232         testfunc("20c9402a000004ea7e00050000018009ea6300020001ea6c000700ea6d00020000ea6e000908ea6f000400000040")
233         testfunc("20c9401d000003ea7e0005004eec0004ea6300020001ea6c000700ea6d40020000")
234
235 }
236
237 func (testCtxt *E2ApTests) E2ApTestMsgSubscriptionFailureBuffers(t *testing.T) {
238
239         testfunc := func(buffer string) {
240                 packedData := testCtxt.toPackedData(t, buffer)
241                 if packedData == nil {
242                         return
243                 }
244                 e2SubResp := testCtxt.packerif.NewPackerSubscriptionFailure()
245                 err, _ := e2SubResp.UnPack(packedData)
246                 if err != nil {
247                         testCtxt.testError(t, "UnPack() Failed: %s [%s]", err.Error(), buffer)
248                         return
249                 }
250                 testCtxt.testPrint("OK [%s]", buffer)
251         }
252
253         testCtxt.SetDesc("SubFailBuffer")
254         testfunc("40c94017000003ea7e000500000106f3ea6300020001ea6e000100")
255 }