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"
28 #include "e2sim_defs.h"
30 #include "e2ap_asn1c_codec.h"
31 #include "GlobalE2node-ID.h"
32 #include "GlobalE2node-gNB-ID.h"
33 #include "GlobalgNB-ID.h"
34 #include "OCTET_STRING.h"
35 #include "asn_application.h"
36 #include "GNB-ID-Choice.h"
37 #include "ProtocolIE-Field.h"
38 #include "E2setupRequest.h"
48 void (*free)(decltype(*array));
52 void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
57 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
58 memcpy(data.buffer, buf, min(data.len, MAX_SCTP_BUFFER));
60 sctp_send_data(client_fd, data);
63 void wait_for_sctp_data(int client_fd)
65 sctp_buffer_t recv_buf;
66 if(sctp_receive_data(client_fd, recv_buf) > 0)
68 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
69 e2ap_handle_sctp_data(client_fd, recv_buf);
73 int main(int argc, char* argv[]){
74 LOG_I("Start RIC Simulator");
76 options_t ops = read_input_options(argc, argv);
77 int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
80 // E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml");
84 uint8_t *buf = (uint8_t *)"gnb1";
86 BIT_STRING_t gnb_bstring;
87 gnb_bstring.buf = buf;
89 gnb_bstring.bits_unused = 0;
94 uint8_t *buf2 = (uint8_t *)"plmn3";
99 GNB_ID_Choice_t gnbchoice;
100 GNB_ID_Choice_PR pres2 = GNB_ID_Choice_PR_gnb_ID;
101 gnbchoice.present = pres2;
102 gnbchoice.choice.gnb_ID = gnb_bstring;
106 gnb.gnb_id = gnbchoice;
110 GlobalE2node_gNB_ID_t *e2gnb = (GlobalE2node_gNB_ID_t*)calloc(1, sizeof(GlobalE2node_gNB_ID_t));
111 e2gnb->global_gNB_ID = gnb;
114 GlobalE2node_ID_t *globale2nodeid = (GlobalE2node_ID_t*)calloc(1, sizeof(GlobalE2node_ID_t));
115 GlobalE2node_ID_PR pres;
116 pres = GlobalE2node_ID_PR_gNB;
117 globale2nodeid->present = pres;
118 globale2nodeid->choice.gNB = e2gnb;
121 GlobalE2node_ID_t globale2nodeid;
122 GlobalE2node_ID_PR pres;
123 pres = GlobalE2node_ID_PR_gNB;
124 globale2nodeid.present = pres;
125 globale2nodeid.choice.gNB = e2gnb;
127 E2setupRequestIEs_t *e2setuprid = (E2setupRequestIEs_t*)calloc(1, sizeof(E2setupRequest_t));;
128 E2setupRequestIEs__value_PR pres3;
129 pres3 = E2setupRequestIEs__value_PR_GlobalE2node_ID;
131 e2setuprid->criticality = 0;
132 e2setuprid->value.choice.GlobalE2node_ID = globale2nodeid;
133 e2setuprid->value.present = pres3;
136 E2setupRequest_t e2setupreq;
137 e2setupreq.protocolIEs.list.size = sizeof(E2setupRequestIEs);
138 e2setupreq.protocolIEs.list.count = 1;
139 e2setupreq.protocolIEs.list.array = &e2setuprid;
141 InitiatingMessage__value_PR pres4;
142 pres4 = InitiatingMessage__value_PR_E2setupRequest;
143 InitiatingMessage_t *initmsg = (InitiatingMessage_t*)calloc(1, sizeof(InitiatingMessage_t));
144 initmsg->procedureCode = 1;
145 initmsg->criticality = 0;
146 initmsg->value.present = pres4;
147 initmsg->value.choice.E2setupRequest = e2setupreq;
150 pres5 = E2AP_PDU_PR_initiatingMessage;
152 E2AP_PDU_t *e2ap_pdu = (E2AP_PDU_t*)calloc(1, sizeof(E2AP_PDU_t));
153 e2ap_pdu->present = pres5;
154 e2ap_pdu->choice.initiatingMessage = initmsg;
156 printf("over here\n");
158 asn_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu);
161 printf("over here 2\n");
163 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2ap_pdu);
165 printf("over here 55\n");
167 E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_SetupRequest2.xml");
168 e2ap_asn1c_print_pdu(pdu_setup);
169 encode_and_send_sctp_data(pdu_setup, client_fd);
170 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
173 // E2setupRequest_t* pdu_setup = smaller_e2ap_xml_to_pdu("E2AP_PartSetupRequest.xml");
174 // e2ap_asn1c_print_pdu(pdu_setup);
175 // encode_and_send_sctp_data(pdu_setup, client_fd);
176 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
179 GlobalE2node_ID_t* pdu_setup = smaller_e2ap_xml_to_pdu("GlobalE2node-ID.xml");
181 asn_fprint(stdout, &asn_DEF_GlobalE2node_ID, pdu_setup);
183 printf("over here 2\n");
185 xer_fprint(stdout, &asn_DEF_GlobalE2node_ID, pdu_setup);
188 e2ap_asn1c_print_pdu(pdu_setup);
189 encode_and_send_sctp_data(pdu_setup, client_fd);
191 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
194 //2. Receive ENDCX2SetupResponse
195 wait_for_sctp_data(client_fd);
197 //3. Send RICSubscriptionRequest
199 E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml");
200 e2ap_asn1c_print_pdu(pdu_sub);
201 encode_and_send_sctp_data(pdu_sub, client_fd);
202 LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST");
204 //4. Receive RICSubscriptionResponse
206 wait_for_sctp_data(client_fd);
210 //---------------------------------------
212 LOG_I("[SCTP] Connection closed.");