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