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 ******************************************************************************/
26 #include "e2sim_defs.h"
27 #include "asn_e2ap.hpp"
28 #include "e2sim_sctp.hpp"
29 #include "e2ap_message_handler.hpp"
30 #include "e2ap_asn_codec.hpp"
34 void test_send_X2Setup(int &client_fd)
36 //Create X2SetupRequest message
37 e2ap_pdu_t* pdu = new_e2ap_pdu();
40 e2ap_create_X2SetupRequest(pdu, cfg);
45 e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
48 sctp_send_data(client_fd, data);
49 LOG_I("[SCTP] Sent X2 SETUP REQUEST");
51 //wait to receive response
52 sctp_buffer_t recv_buf;
53 if(sctp_receive_data(client_fd, recv_buf) > 0)
55 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
56 e2ap_handle_sctp_data(client_fd, recv_buf);
61 void test_send_ENDCX2Setup(int &client_fd)
63 //Create ENDCX2SetupRequest message
64 e2ap_pdu_t* pdu = new_e2ap_pdu();
67 e2ap_create_ENDCX2SetupRequest(pdu, cfg);
72 e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
75 sctp_send_data(client_fd, data);
76 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
78 //wait to receive response
79 sctp_buffer_t recv_buf;
80 if(sctp_receive_data(client_fd, recv_buf) > 0)
82 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
83 e2ap_handle_sctp_data(client_fd, recv_buf);
88 void test_send_RICSubscriptionRequest(int &client_fd)
90 LOG_I("Test RIC SUBSCRIPTION");
92 /* Create RIC SUBSCRITION REQUEST */
93 e2ap_pdu_t* pdu = new_e2ap_pdu();
95 RICsubscription_params_t params;
96 params.request_id = 2;
97 params.seq_number = 200;
98 params.ran_func_id = 0;
99 params.event_trigger_def = "hello world";
101 RIC_action_t action1(1, RICactionType_report);
102 // RIC_action_t action2(3, RICactionType_insert);
103 // RIC_action_t action3(5, RICactionType_insert);
104 // RIC_action_t action4(7, RICactionType_insert);
105 params.actionList.push_back(action1);
106 // params.actionList.push_back(action2);
107 // params.actionList.push_back(action3);
108 // params.actionList.push_back(action4);
110 e2ap_create_RICsubscriptionRequest(pdu, params);
115 e2ap_encode_pdu(pdu, data.buffer, sizeof(data.buffer), data.len);
118 sctp_send_data(client_fd, data);
119 LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST");
121 //wait to receive response and indication (if any)
122 sctp_buffer_t recv_buf;
123 LOG_I("[SCTP] Waiting for SCTP data");
126 if(sctp_receive_data(client_fd, recv_buf) > 0)
128 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
129 e2ap_handle_sctp_data(client_fd, recv_buf);
138 //==========================================================================
141 e2ap_pdu_t* pdu2 = new_e2ap_pdu();
143 e2ap_decode_pdu(pdu2, data.buffer, data.len);
145 RICsubscription_params_t params2;
146 e2ap_parse_RICsubscriptionRequest(pdu2, params2);
147 printf("request_id = %d\n", params2.request_id);
148 printf("seq_number = %d\n", params2.seq_number);
149 printf("ran_func_id = %d\n", params2.ran_func_id);
150 printf("event = %s\n", ¶ms2.event_trigger_def[0]);
152 for( auto const &a : params.actionList)
154 printf("action id = %d, action type = %d\n", (int)a.action_id, (int)a.action_type);
158 LOG_I("================= RESPONSE ===========================");
159 for(size_t i = 0; i < params2.actionList.size(); i++)
161 //example logic: admit every other action
163 params2.actionList[i].isAdmitted = true;
165 params2.actionList[i].isAdmitted = false;
166 params2.actionList[i].notAdmitted_cause = RICcause_radioNetwork;
167 params2.actionList[i].notAdmitted_subCause = 5;
171 e2ap_pdu_t* res_pdu = new_e2ap_pdu();
172 e2ap_create_RICsubscriptionResponse(res_pdu, params2);
174 e2ap_print_pdu(res_pdu);
177 sctp_buffer_t data_resp;
178 e2ap_encode_pdu(res_pdu, data_resp.buffer, sizeof(data_resp.buffer), data_resp.len);
180 LOG_I("================= FAILURE ===========================");
181 e2ap_pdu_t* fail_pdu = new_e2ap_pdu();
183 RICsubscription_params_t params3;
184 e2ap_parse_RICsubscriptionRequest(pdu2, params3);
186 for(size_t i = 0; i < params3.actionList.size(); i++)
188 params3.actionList[i].isAdmitted = false;
189 params3.actionList[i].notAdmitted_cause = RICcause_radioNetwork;
190 params3.actionList[i].notAdmitted_subCause = 5;
193 e2ap_create_RICsubscriptionFailure(fail_pdu, params3);
194 e2ap_print_pdu(fail_pdu);
197 sctp_buffer_t data_fail;
198 e2ap_encode_pdu(fail_pdu, data_fail.buffer, sizeof(data_fail.buffer), data_fail.len);
202 int main(int argc, char* argv[]){
204 LOG_I("E2 Termination Test");
206 // test_send_RICSubscriptionRequest();
209 options_t ops = read_input_options(argc, argv);
210 int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
212 //---------------------------------------------------
213 // test_send_X2Setup(client_fd);
214 test_send_ENDCX2Setup(client_fd);
215 test_send_RICSubscriptionRequest(client_fd);
217 //---------------------------------------------------
220 LOG_I("[SCTP] Connection closed.");