Enhanced SIM for E2AP v1 for TS UC
[sim/e2-interface.git] / e2sim / e2apv1sim / test / X2 / x2termination_test.cpp
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 # Copyright 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 #include <stdio.h>
21 #include <string>
22 #include <iostream>
23
24 #include "e2sim_defs.h"
25 #include "asn_x2ap.hpp"
26 #include "e2sim_sctp.hpp"
27 #include "x2ap_message_handler.hpp"
28 #include "x2ap_asn_codec.hpp"
29
30 using namespace std;
31
32 void test_X2Setup(int &client_fd)
33 {
34   //Create X2SetupRequest message
35   x2ap_pdu_t* pdu = new_x2ap_pdu();
36   eNB_config cfg;
37
38   x2ap_create_X2SetupRequest(pdu, cfg);
39   x2ap_print_pdu(pdu);
40
41   //Encode into buffer
42   sctp_buffer_t data;
43   x2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
44
45   //Send to sctp
46   sctp_send_data(client_fd, data);
47   LOG_I("[SCTP] Sent X2 SETUP REQUEST");
48
49   //expect X2 SETUP RESPONSE
50   sctp_buffer_t recv_buf;
51   if(sctp_receive_data(client_fd, recv_buf) > 0)
52   {
53     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
54     x2ap_handle_sctp_data(client_fd, recv_buf);
55   }
56
57   //Send again, expect X2 SETUP FAILURE
58   sctp_send_data(client_fd, data);
59   LOG_I("[SCTP] Sent X2 SETUP REQUEST");
60
61   if(sctp_receive_data(client_fd, recv_buf) > 0)
62   {
63     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
64     x2ap_handle_sctp_data(client_fd, recv_buf);
65   }
66
67 }
68
69 void test_ENDCX2Setup(int &client_fd)
70 {
71   //Create ENDCX2SetupRequest message
72   x2ap_pdu_t* pdu = new_x2ap_pdu();
73   eNB_config cfg;
74
75   x2ap_create_ENDCX2SetupRequest(pdu, cfg);
76   x2ap_print_pdu(pdu);
77
78   //Encode into buffer
79   sctp_buffer_t data;
80   x2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
81
82   //Send to sctp
83   sctp_send_data(client_fd, data);
84   LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
85
86   //expect ENDC X2 SETUP RESPONSE
87   sctp_buffer_t recv_buf;
88   if(sctp_receive_data(client_fd, recv_buf) > 0)
89   {
90     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
91     x2ap_handle_sctp_data(client_fd, recv_buf);
92   }
93
94   //Send again, expect ENDC X2 SETUP FAILURE
95   sctp_send_data(client_fd, data);
96   LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
97
98   if(sctp_receive_data(client_fd, recv_buf) > 0)
99   {
100     LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
101     x2ap_handle_sctp_data(client_fd, recv_buf);
102   }
103
104 }
105
106 int main(int argc, char* argv[]){
107
108   LOG_I("X2 Termination Test");
109
110   options_t ops = read_input_options(argc, argv);
111
112   int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
113
114   test_X2Setup(client_fd);
115   // test_ENDCX2Setup(client_fd);
116
117
118   return 0;
119 }