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_sctp.hpp"
25 #include "e2ap_message_handler.hpp"
27 #include "encode_e2apv1.hpp"
28 #include "encode_kpm.hpp"
31 #include "e2sim_defs.h"
33 #include "e2ap_asn1c_codec.h"
34 #include "GlobalE2node-ID.h"
35 #include "GlobalE2node-gNB-ID.h"
36 #include "GlobalgNB-ID.h"
37 #include "OCTET_STRING.h"
38 #include "asn_application.h"
39 #include "GNB-ID-Choice.h"
40 #include "ProtocolIE-Field.h"
41 #include "E2setupRequest.h"
42 #include "RICaction-ToBeSetup-Item.h"
43 #include "RICactions-ToBeSetup-List.h"
44 #include "RICeventTriggerDefinition.h"
45 #include "RICsubscriptionRequest.h"
46 #include "ProtocolIE-SingleContainer.h"
47 #include "RANfunctions-List.h"
48 #include "RICindication.h"
49 #include "RICsubsequentActionType.h"
50 #include "RICsubsequentAction.h"
51 #include "RICtimeToWait.h"
61 void (*free)(decltype(*array));
67 void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
72 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
73 memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
75 sctp_send_data(client_fd, data);
79 void encode_and_send_sctp_data(E2AP_PDU_t* pdu)
84 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
85 memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
87 sctp_send_data(client_fd, data);
90 void wait_for_sctp_data(int client_fd)
92 sctp_buffer_t recv_buf;
93 if(sctp_receive_data(client_fd, recv_buf) > 0)
95 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
96 e2ap_handle_sctp_data(client_fd, recv_buf, false);
102 int main(int argc, char* argv[]){
103 LOG_I("Start RIC Simulator");
107 options_t ops = read_input_options(argc, argv);
109 int server_fd = sctp_start_server(ops.server_ip, ops.server_port);
110 client_fd = sctp_accept_connection(ops.server_ip, server_fd);
112 sctp_buffer_t recv_buf;
114 LOG_I("[SCTP] Waiting for SCTP data");
116 while(1) //constantly looking for data on SCTP interface
118 LOG_I("in while loop");
119 if(sctp_receive_data(client_fd, recv_buf) <= 0)
122 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
124 e2ap_handle_sctp_data(client_fd, recv_buf, xmlenc);