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 ******************************************************************************/
27 #include "e2sim_defs.h"
28 #include "e2sim_sctp.hpp"
29 #include "e2ap_message_handler.hpp"
30 #include "encode_e2apv1.hpp"
36 void encode_and_send_sctp_data(E2AP_PDU_t* pdu)
41 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
42 memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
44 sctp_send_data(client_fd, data);
47 void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
52 printf("Calling encode_and_send_sctp_data\n");
54 printf("client_fd is %d\n", client_fd);
56 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
58 printf("after encoding pdu\n");
60 memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
62 printf("calling sctp_send_data\n");
64 sctp_send_data(client_fd, data);
67 void wait_for_sctp_data()
69 sctp_buffer_t recv_buf;
70 if(sctp_receive_data(client_fd, recv_buf) > 0)
72 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
73 e2ap_handle_sctp_data(client_fd, recv_buf, false);
78 int main(int argc, char* argv[]){
80 printf("Start E2 Agent (E2 Simulator\n");
85 simfile.open("simulation.txt", ios::in);
87 if (simfile.is_open()) {
89 while (getline(simfile, line)) {
98 printf("encoding now the user level - DU\n");
100 E2SM_KPM_IndicationMessage_t *indMsg =
101 (E2SM_KPM_IndicationMessage_t*)calloc(1,sizeof(E2SM_KPM_IndicationMessage_t));
103 //encode_kpm_report_rancontainer_du(indMsg);
104 encode_kpm_report_style1(indMsg);
110 options_t ops = read_input_options(argc, argv);
112 printf("After reading input options\n");
114 //E2 Agent will automatically restart upon sctp disconnection
115 // int server_fd = sctp_start_server(ops.server_ip, ops.server_port);
117 client_fd = sctp_start_client(ops.server_ip, ops.server_port);
118 E2AP_PDU_t* pdu_setup = (E2AP_PDU_t*)calloc(1,sizeof(E2AP_PDU));
120 printf("After starting client\n");
121 printf("client_fd value is %d\n", client_fd);
123 // generate_e2apv1_subscription_request(pdu_setup);
124 generate_e2apv1_setup_request(pdu_setup);
126 printf("After generating e2setup req\n");
128 xer_fprint(stderr, &asn_DEF_E2AP_PDU, pdu_setup);
130 printf("After XER Encoding\n");
132 auto buffer_size = MAX_SCTP_BUFFER;
133 unsigned char buffer[MAX_SCTP_BUFFER];
137 char *error_buf = (char*)calloc(300, sizeof(char));
140 asn_check_constraints(&asn_DEF_E2AP_PDU, pdu_setup, error_buf, &errlen);
141 printf("error length %d\n", errlen);
142 printf("error buf %s\n", error_buf);
144 auto er = asn_encode_to_buffer(nullptr, ATS_ALIGNED_BASIC_PER, &asn_DEF_E2AP_PDU, pdu_setup, buffer, buffer_size);
145 //auto er = asn_encode_to_buffer(nullptr, ATS_BASIC_XER, &asn_DEF_E2AP_PDU, pdu_setup, buffer, buffer_size);
146 data.len = er.encoded;
148 fprintf(stderr, "er encded is %d\n", er.encoded);
150 memcpy(data.buffer, buffer, er.encoded);
152 if(sctp_send_data(client_fd, data) > 0) {
153 LOG_I("[SCTP] Sent E2-SETUP-REQUEST");
155 LOG_E("[SCTP] Unable to send E2-SETUP-REQUEST to peer");
158 sctp_buffer_t recv_buf;
160 LOG_I("[SCTP] Waiting for SCTP data");
162 while(1) //constantly looking for data on SCTP interface
164 if(sctp_receive_data(client_fd, recv_buf) <= 0)
167 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
169 e2ap_handle_sctp_data(client_fd, recv_buf, xmlenc);
170 if (xmlenc) xmlenc = false;