Ron Shacham | 0eba05c | 2020-05-08 15:13:19 -0400 | [diff] [blame] | 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 <unistd.h> |
| 22 | #include <assert.h> |
| 23 | |
| 24 | #include "e2sim_sctp.hpp" |
| 25 | #include "e2ap_message_handler.hpp" |
| 26 | |
| 27 | extern "C" { |
| 28 | #include "e2sim_defs.h" |
| 29 | #include "E2AP-PDU.h" |
| 30 | #include "e2ap_asn1c_codec.h" |
| 31 | } |
| 32 | |
| 33 | using namespace std; |
| 34 | |
| 35 | void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd) |
| 36 | { |
| 37 | uint8_t *buf; |
| 38 | sctp_buffer_t data; |
| 39 | |
| 40 | data.len = e2ap_asn1c_encode_pdu(pdu, &buf); |
| 41 | memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER)); |
| 42 | |
| 43 | // sctp_send_data(client_fd, data); |
| 44 | sctp_send_data_X2AP(client_fd, data); |
| 45 | } |
| 46 | |
| 47 | void wait_for_sctp_data(int client_fd) |
| 48 | { |
| 49 | sctp_buffer_t recv_buf; |
| 50 | if(sctp_receive_data(client_fd, recv_buf) > 0) |
| 51 | { |
| 52 | LOG_I("[SCTP] Received new data of size %d", recv_buf.len); |
| 53 | e2ap_handle_sctp_data(client_fd, recv_buf); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | int main(int argc, char* argv[]){ |
| 59 | LOG_I("Start RIC Simulator"); |
| 60 | |
| 61 | options_t ops = read_input_options(argc, argv); |
| 62 | int client_fd = sctp_start_client(ops.server_ip, ops.server_port); |
| 63 | |
| 64 | //Send X2 Setup Request |
| 65 | E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_X2SetupRequest.xml"); |
| 66 | e2ap_asn1c_print_pdu(pdu_setup); |
| 67 | encode_and_send_sctp_data(pdu_setup, client_fd); |
| 68 | |
| 69 | //wait to receive X2SetupResponse |
| 70 | while(1){ |
| 71 | wait_for_sctp_data(client_fd); |
| 72 | } |
| 73 | } |