1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
4 # Copyright 2019 Nokia *
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 *
10 # http://www.apache.org/licenses/LICENSE-2.0 *
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. *
18 ******************************************************************************/
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"
32 void test_X2Setup(int &client_fd)
34 //Create X2SetupRequest message
35 x2ap_pdu_t* pdu = new_x2ap_pdu();
38 x2ap_create_X2SetupRequest(pdu, cfg);
43 x2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
46 sctp_send_data(client_fd, data);
47 LOG_I("[SCTP] Sent X2 SETUP REQUEST");
49 //expect X2 SETUP RESPONSE
50 sctp_buffer_t recv_buf;
51 if(sctp_receive_data(client_fd, recv_buf) > 0)
53 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
54 x2ap_handle_sctp_data(client_fd, recv_buf);
57 //Send again, expect X2 SETUP FAILURE
58 sctp_send_data(client_fd, data);
59 LOG_I("[SCTP] Sent X2 SETUP REQUEST");
61 if(sctp_receive_data(client_fd, recv_buf) > 0)
63 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
64 x2ap_handle_sctp_data(client_fd, recv_buf);
69 void test_ENDCX2Setup(int &client_fd)
71 //Create ENDCX2SetupRequest message
72 x2ap_pdu_t* pdu = new_x2ap_pdu();
75 x2ap_create_ENDCX2SetupRequest(pdu, cfg);
80 x2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
83 sctp_send_data(client_fd, data);
84 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
86 //expect ENDC X2 SETUP RESPONSE
87 sctp_buffer_t recv_buf;
88 if(sctp_receive_data(client_fd, recv_buf) > 0)
90 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
91 x2ap_handle_sctp_data(client_fd, recv_buf);
94 //Send again, expect ENDC X2 SETUP FAILURE
95 sctp_send_data(client_fd, data);
96 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
98 if(sctp_receive_data(client_fd, recv_buf) > 0)
100 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
101 x2ap_handle_sctp_data(client_fd, recv_buf);
106 int main(int argc, char* argv[]){
108 LOG_I("X2 Termination Test");
110 options_t ops = read_input_options(argc, argv);
112 int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
114 test_X2Setup(client_fd);
115 // test_ENDCX2Setup(client_fd);