E2AP Wrapper Implementation
[ric-app/hw.git] / test / test_e2ap.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 AT&T Intellectual Property.
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  * test_e2ap.h
21  *
22  *  Created on: Oct 23, 2020
23  *  Author: Shraboni Jana
24  */
25
26 #ifndef TEST_TEST_E2AP_H_
27 #define TEST_TEST_E2AP_H_
28 #include<iostream>
29 #include<gtest/gtest.h>
30
31 #include "e2ap_control_failure.hpp"
32 #include "e2ap_control_ack.hpp"
33 #include "e2ap_subsdel_request.hpp"
34 #include "e2ap_subsdel_response.hpp"
35 #include "e2ap_subsdel_failure.hpp"
36 #include "e2ap_criticality_diagnostics.hpp"
37 #include "e2ap_subscription_response.hpp"
38 #include "e2ap_subscription_failure.hpp"
39
40
41 TEST(E2AP, ControlAcknowledgementEncode)
42 {
43
44         unsigned char buff[1024];
45         size_t buf_len = 1024;
46
47         E2APControlAcknowledge::ControlAcknowledgeIEs infoObj;
48         infoObj.set_ranFunctionID(1);
49         infoObj.set_ricRequestorID(1);
50         infoObj.set_ricInstanceID(1);
51         infoObj.set_ricControlStatus(1);
52         infoObj.set_ricCallProcessID("CallProcessID");
53         infoObj.set_ricControlOutcome("ControlOutcome");
54
55
56         E2APControlAcknowledge  cntrlObj(infoObj);
57
58         bool res = cntrlObj.encode(buff, &buf_len);
59         if(!res)
60         {
61                 std::cout << cntrlObj.get_error() << std::endl;
62         }
63         ASSERT_TRUE(res);
64         FILE * pFile;
65                 pFile = fopen ("controlack1.per","w");
66                 if (pFile!=NULL)
67                  {
68                           fwrite (buff , sizeof(char), buf_len, pFile);
69                       sleep(2);
70                           fclose (pFile);
71                   }
72
73 }
74 TEST(E2AP, ControlAcknowledgementDecode)
75 {
76        unsigned char e2ap_buff[4096];
77        char filename[100] = "controlack1.per";
78        FILE *fp;
79        fp = fopen(filename,"rb");
80        if(!fp) {
81                      perror(filename);
82                      exit(1); }
83
84            size_t e2ap_buff_size = fread(e2ap_buff, 1, 4096, fp);
85            fclose(fp);
86        if(!e2ap_buff_size){
87              fprintf(stderr, "%s: Empty or broken\n", filename);
88               exit(1);
89            } else {
90               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
91        }
92
93        bool decode_status = true;
94           try{
95                 E2APControlAcknowledge e2obj(&e2ap_buff[0],&e2ap_buff_size);
96
97
98           } catch(const char* e){
99                         decode_status = false;
100                         std::cout << "Error Message: " << e << std::endl;
101         }
102
103
104         ASSERT_TRUE(decode_status);
105
106 }
107 TEST(E2AP, ControlFailureEncode)
108 {
109
110         unsigned char buff[1024];
111         size_t buf_len = 1024;
112
113         E2APControlFailure::ControlFailureIEs infoObj;
114         infoObj.set_ranFunctionID(1);
115         infoObj.set_ricRequestorID(1);
116         infoObj.set_ricInstanceID(1);
117         infoObj.set_ricCause(1);
118         infoObj.set_ricSubCause(1);
119         infoObj.set_ricCallProcessID("CallProcessID");
120         infoObj.set_ricControlOutcome("ControlOutcome");
121
122
123         E2APControlFailure  cntrlObj(infoObj);
124
125         bool res = cntrlObj.encode(buff, &buf_len);
126         if(!res)
127         {
128                 std::cout << cntrlObj.get_error() << std::endl;
129         }
130         ASSERT_TRUE(res);
131         FILE * pFile;
132                 pFile = fopen ("controlfail1.per","w");
133                 if (pFile!=NULL)
134                  {
135                           fwrite (buff , sizeof(char), buf_len, pFile);
136                       sleep(2);
137                           fclose (pFile);
138                   }
139
140 }
141 TEST(E2AP, ControlFailureDecode)
142 {
143        unsigned char e2ap_buff[1024];
144        char filename[100] = "controlfail1.per";
145        FILE *fp;
146        fp = fopen(filename,"rb");
147        if(!fp) {
148                      perror(filename);
149                      exit(1); }
150
151            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
152            fclose(fp);
153        if(!e2ap_buff_size){
154              fprintf(stderr, "%s: Empty or broken\n", filename);
155               exit(1);
156            } else {
157               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
158        }
159
160        bool decode_status = true;
161           try{
162                 E2APControlFailure e2obj(&e2ap_buff[0],&e2ap_buff_size);
163
164
165           } catch(const char* e){
166                         decode_status = false;
167                         std::cout << "Error Message: " << e << std::endl;
168         }
169
170
171         ASSERT_TRUE(decode_status);
172
173 }
174
175 TEST(E2AP, SubscriptionDeleteRequest){
176
177         unsigned char buff[1024];
178         size_t buff_size = 1024;
179
180
181         E2APSubscriptionDeleteRequest::SubscriptionDeleteRequestIEs dataObj;
182
183         dataObj.set_ranFunctionID(1);
184         dataObj.set_ricInstanceID(1);
185         dataObj.set_ricRequestorID(3);
186
187         E2APSubscriptionDeleteRequest requestObj(dataObj);
188         bool res = requestObj.encode(buff, &buff_size);
189         if(!res)
190         {
191                 std::cout << requestObj.get_error() << std::endl;
192         }
193         ASSERT_TRUE(res);
194
195
196 }
197
198 TEST(E2AP, SubDelResponseEncode)
199 {
200
201         unsigned char buff[1024];
202         size_t buf_len = 1024;
203
204         E2APSubscriptionDeleteResponse::SubscriptionDeleteResponseIEs  infoObj;
205         infoObj.set_ranFunctionID(1);
206         infoObj.set_ricRequestorID(1);
207         infoObj.set_ricInstanceID(1);
208
209
210         E2APSubscriptionDeleteResponse  subdelObj(infoObj);
211
212         bool res = subdelObj.encode(buff, &buf_len);
213         if(!res)
214         {
215                 std::cout << subdelObj.get_error() << std::endl;
216         }
217         ASSERT_TRUE(res);
218         FILE * pFile;
219                 pFile = fopen ("subdelresponse1.per","w");
220                 if (pFile!=NULL)
221                  {
222                           fwrite (buff , sizeof(char), buf_len, pFile);
223                       sleep(2);
224                           fclose (pFile);
225                   }
226
227 }
228 TEST(E2AP, SubDelResponseDecode)
229 {
230        sleep(10);
231            unsigned char e2ap_buff[1024];
232        char filename[100] = "subdelresponse1.per";
233        FILE *fp;
234        fp = fopen(filename,"rb");
235        if(!fp) {
236                      perror(filename);
237                      exit(1); }
238
239            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
240            fclose(fp);
241        if(!e2ap_buff_size){
242              fprintf(stderr, "%s: Empty or broken\n", filename);
243               exit(1);
244            } else {
245               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
246        }
247
248        bool decode_status = true;
249           try{
250                   E2APSubscriptionDeleteResponse e2obj(&e2ap_buff[0],&e2ap_buff_size);
251
252
253           } catch(const char* e){
254                         decode_status = false;
255                         std::cout << "Error Message: " << e << std::endl;
256         }
257
258
259         ASSERT_TRUE(decode_status);
260
261 }
262
263 TEST(E2AP, SubDelFailureEncode){
264         unsigned char buff[1024];
265         size_t buf_len = 1024;
266
267         CriticalityDiagnosticsIEs crIEs1;
268         crIEs1.set_ieID(1);
269         crIEs1.set_typeOferror(1);
270         crIEs1.set_iEcriticality(2);
271
272         CriticalityDiagnosticsIEs crIEs2;
273         crIEs2.set_ieID(1);
274         crIEs2.set_typeOferror(1);
275         crIEs2.set_iEcriticality(1);
276
277
278
279         E2APCriticalityDiagnostics critObj;
280         critObj.set_procedureCode(10);
281         critObj.set_procedureCriticality(1);
282         critObj.set_ricInstanceID(101);
283         critObj.set_ricRequestorID(102);
284         critObj.set_triggeringMessage(1);
285         critObj.add(crIEs1);
286         critObj.add(crIEs2);
287
288         E2APSubscriptionDeleteFailure::SubscriptionDeleteFailureIEs  infoObj;
289         infoObj.set_ranFunctionID(1);
290         infoObj.set_ricRequestorID(1);
291         infoObj.set_ricInstanceID(1);
292         infoObj.set_ricCause(1);
293         infoObj.set_ricSubCause(2);
294         infoObj.set_critical_diagnostic(critObj);
295
296
297         E2APSubscriptionDeleteFailure  subdelObj(infoObj);
298
299         bool res = subdelObj.encode(buff, &buf_len);
300         if(!res)
301         {
302                 std::cout << "Subscribtion Delete Failure Error Message" << subdelObj.get_error() << std::endl;
303         }
304         ASSERT_TRUE(res);
305         FILE * pFile;
306         pFile = fopen ("subdelfailure2.per","w");
307         if (pFile!=NULL)
308         {
309                                   fwrite (buff , sizeof(char), buf_len, pFile);
310                               sleep(2);
311                                   fclose (pFile);
312          }
313
314 }
315
316 TEST(E2AP, SubDelFailureDecode)
317 {
318        sleep(10);
319            unsigned char e2ap_buff[1024];
320        char filename[100] = "subdelfailure2.per";
321        FILE *fp;
322        fp = fopen(filename,"rb");
323        if(!fp) {
324                      perror(filename);
325                      exit(1); }
326
327            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
328            fclose(fp);
329        if(!e2ap_buff_size){
330              fprintf(stderr, "%s: Empty or broken\n", filename);
331               exit(1);
332            } else {
333               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
334        }
335
336        bool decode_status = true;
337           try{
338                   E2APSubscriptionDeleteFailure e2obj(&e2ap_buff[0],&e2ap_buff_size);
339
340                   std::cout << "Procedure Code: " << e2obj.getIEs().get_critical_diagnostic()->get_procedureCode() << std::endl;
341                   std::cout << "Procedure Criticality: " << e2obj.getIEs().get_critical_diagnostic()->get_procedureCriticality() << std::endl;
342                   std::cout << "Size OF LIST :" << e2obj.getIEs().get_critical_diagnostic()->get_list_count() << std::endl;
343
344                   int count = e2obj.getIEs().get_critical_diagnostic()->get_list_count() ;
345                   std::vector<CriticalityDiagnosticsIEs> *lst = e2obj.getIEs().get_critical_diagnostic()->get_list();
346                   for(int i=0; i< count; i++){
347                           std::cout<< "Typ Error:::" << (*lst)[i].get_typeOferror() << std::endl;
348                           std::cout<< "iEcriticality:::" << (*lst)[i].get_iEcriticality() << std::endl;
349                           std::cout<< "ieID:::" << (*lst)[i].get_ieID() << std::endl;
350                   }
351
352           } catch(const char* e){
353                         decode_status = false;
354                         std::cout << "Error Message: " << e << std::endl;
355         }
356
357
358         ASSERT_TRUE(decode_status);
359
360 }
361
362 TEST(E2AP, SubResponseEncode){
363         unsigned char buff[512];
364         size_t buf_len = 512;
365
366         RICactionAdmittedList::RICactionAdmittedItemIEs tmp1;
367         tmp1.set_ricActionID(1);
368
369         RICactionAdmittedList admitlst;
370         admitlst.add(tmp1);
371         admitlst.add(RICactionAdmittedList::RICactionAdmittedItemIEs().set_ricActionID(2));
372
373         RICactionNotAdmittedList::RICactionNotAdmittedItemIEs tmp2;
374         tmp2.set_ricActionID(2);
375         tmp2.set_ricCause(1);
376         tmp2.set_ricSubCause(3);
377         RICactionNotAdmittedList notadmitlst;
378         notadmitlst.add(tmp2);
379         notadmitlst.add(RICactionNotAdmittedList::RICactionNotAdmittedItemIEs().set_ricActionID(2).set_ricCause(1).set_ricSubCause(1));
380
381         E2APSubscriptionResponse::SubscriptionResponseIEs  infoObj;
382         infoObj.set_ranFunctionID(1);
383         infoObj.set_ricRequestorID(1);
384         infoObj.set_ricInstanceID(1);
385         infoObj.set_actionsNotAdmitted_list(notadmitlst);
386         infoObj.set_actionsAdmitted_list(admitlst);
387
388         E2APSubscriptionResponse  subObj(infoObj);
389
390         bool res = subObj.encode(buff, &buf_len);
391         if(!res)
392         {
393                 std::cout << "Subscription Response Error Message" << subObj.get_error() << std::endl;
394         }
395         ASSERT_TRUE(res);
396         FILE * pFile;
397         pFile = fopen ("subresponse1.per","w");
398         if (pFile!=NULL)
399         {
400                                   fwrite (buff , sizeof(char), buf_len, pFile);
401                                   fclose (pFile);
402          }
403
404 }
405 TEST(E2AP, SubResponseDecode)
406 {
407        sleep(10);
408            unsigned char e2ap_buff[1024];
409        char filename[100] = "subresponse2.per";
410        FILE *fp;
411        fp = fopen(filename,"rb");
412        if(!fp) {
413                      perror(filename);
414                      exit(1); }
415
416            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
417            fclose(fp);
418        if(!e2ap_buff_size){
419              fprintf(stderr, "%s: Empty or broken\n", filename);
420               exit(1);
421            } else {
422               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
423        }
424
425        bool decode_status = true;
426           try{
427                   E2APSubscriptionResponse e2obj(&e2ap_buff[0],&e2ap_buff_size);
428
429                   std::cout << "RAN Function ID: " << e2obj.getIEs().get_ranFunctionID() << std::endl;
430                   std::cout << "Requestor ID: " << e2obj.getIEs().get_ricRequestorID() << std::endl;
431                   std::cout << "Instance ID :" << e2obj.getIEs().get_ricInstanceID() << std::endl;
432
433                   int count = e2obj.getIEs().get_actionsAdmitted_list().get_list_count() ;
434                   std::vector<RICactionAdmittedList::RICactionAdmittedItemIEs> *lst = e2obj.getIEs().get_actionsAdmitted_list().get_list();
435                   for(int i=0; i< count; i++){
436                           std::cout<< "Action ID:::" << (*lst)[i].get_ricActionID() << std::endl;
437
438                   }
439                   int count2 = e2obj.getIEs().get_actionsNotAdmitted_list().get_list_count() ;
440                   std::vector<RICactionNotAdmittedList::RICactionNotAdmittedItemIEs> *lst2 = e2obj.getIEs().get_actionsNotAdmitted_list().get_list();
441                   for(int i=0; i< count2; i++){
442                         std::cout<< "Action ID:::" << (*lst2)[i].get_ricActionID() << std::endl;
443                         std::cout<< "Cause:::" << (*lst2)[i].get_ricCause() << std::endl;
444                         std::cout<< "Sub Cause:::" << (*lst2)[i].get_ricSubCause() << std::endl;
445                    }
446
447           } catch(const char* e){
448                         decode_status = false;
449                         std::cout << "Error Message: " << e << std::endl;
450         }
451
452
453         ASSERT_TRUE(decode_status);
454
455 }
456
457 TEST(E2AP, SubFailureEncode){
458         unsigned char buff[512];
459         size_t buf_len = 512;
460
461         CriticalityDiagnosticsIEs crIEs1;
462         crIEs1.set_ieID(1);
463         crIEs1.set_typeOferror(1);
464         crIEs1.set_iEcriticality(2);
465
466         CriticalityDiagnosticsIEs crIEs2;
467         crIEs2.set_ieID(1);
468         crIEs2.set_typeOferror(1);
469         crIEs2.set_iEcriticality(1);
470
471
472
473         E2APCriticalityDiagnostics critObj;
474         critObj.set_procedureCode(10);
475         critObj.set_procedureCriticality(1);
476         critObj.set_ricInstanceID(101);
477         critObj.set_ricRequestorID(102);
478         critObj.set_triggeringMessage(1);
479         critObj.add(crIEs1);
480         critObj.add(crIEs2);
481
482         RICactionNotAdmittedList::RICactionNotAdmittedItemIEs tmp2;
483         tmp2.set_ricActionID(2);
484         tmp2.set_ricCause(1);
485         tmp2.set_ricSubCause(3);
486         RICactionNotAdmittedList notadmitlst;
487         notadmitlst.add(tmp2);
488         notadmitlst.add(RICactionNotAdmittedList::RICactionNotAdmittedItemIEs().set_ricActionID(2).set_ricCause(1).set_ricSubCause(1));
489
490         E2APSubscriptionFailure::SubscriptionFailureIEs  infoObj;
491         infoObj.set_ranFunctionID(1);
492         infoObj.set_ricRequestorID(1);
493         infoObj.set_ricInstanceID(1);
494         infoObj.set_actionsNotAdmitted_list(notadmitlst);
495         infoObj.set_critical_diagnostic(critObj);
496
497
498         E2APSubscriptionFailure  subObj(infoObj);
499
500         bool res = subObj.encode(buff, &buf_len);
501         if(!res)
502         {
503                 std::cout << "Subscription Failure Error Message" << subObj.get_error() << std::endl;
504         }
505         ASSERT_TRUE(res);
506         FILE * pFile;
507         pFile = fopen ("subfailure1.per","w");
508         if (pFile!=NULL)
509         {
510                                   fwrite (buff , sizeof(char), buf_len, pFile);
511                                   fclose (pFile);
512          }
513
514 }
515
516 TEST(E2AP, SubFailureDecode)
517 {
518        sleep(10);
519            unsigned char e2ap_buff[1024];
520        char filename[100] = "subfailure1.per";
521        FILE *fp;
522        fp = fopen(filename,"rb");
523        if(!fp) {
524                      perror(filename);
525                      exit(1); }
526
527            size_t e2ap_buff_size = fread(e2ap_buff, 1, 1024, fp);
528            fclose(fp);
529        if(!e2ap_buff_size){
530              fprintf(stderr, "%s: Empty or broken\n", filename);
531               exit(1);
532            } else {
533               fprintf(stderr, "e2ap buffer size: %ld \n", e2ap_buff_size);
534        }
535
536        bool decode_status = true;
537           try{
538                   E2APSubscriptionFailure e2obj(&e2ap_buff[0],&e2ap_buff_size);
539
540                   std::cout << "RAN Function ID: " << e2obj.getIEs().get_ranFunctionID() << std::endl;
541                   std::cout << "Requestor ID: " << e2obj.getIEs().get_ricRequestorID() << std::endl;
542                   std::cout << "Instance ID :" << e2obj.getIEs().get_ricInstanceID() << std::endl;
543                   int count = e2obj.getIEs().get_critical_diagnostic()->get_list_count() ;
544                   std::vector<CriticalityDiagnosticsIEs> *lst = e2obj.getIEs().get_critical_diagnostic()->get_list();
545                   for(int i=0; i< count; i++){
546                                   std::cout<< "Typ Error:::" << (*lst)[i].get_typeOferror() << std::endl;
547                           std::cout<< "iEcriticality:::" << (*lst)[i].get_iEcriticality() << std::endl;
548                           std::cout<< "ieID:::" << (*lst)[i].get_ieID() << std::endl;
549                    }
550
551                   int count2 = e2obj.getIEs().get_actionsNotAdmitted_list().get_list_count() ;
552                   std::vector<RICactionNotAdmittedList::RICactionNotAdmittedItemIEs> *lst2 = e2obj.getIEs().get_actionsNotAdmitted_list().get_list();
553                   for(int i=0; i< count2; i++){
554                         std::cout<< "Action ID:::" << (*lst2)[i].get_ricActionID() << std::endl;
555                         std::cout<< "Cause:::" << (*lst2)[i].get_ricCause() << std::endl;
556                         std::cout<< "Sub Cause:::" << (*lst2)[i].get_ricSubCause() << std::endl;
557                    }
558
559           } catch(const char* e){
560                         decode_status = false;
561                         std::cout << "Error Message: " << e << std::endl;
562         }
563
564
565         ASSERT_TRUE(decode_status);
566
567 }
568
569 #endif /* TEST_TEST_E2AP_H_ */