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