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"
32 #include "ProtocolIE-Field.h"
37 void encode_and_send_sctp_data(E2AP_PDU_t* pdu, int client_fd)
42 data.len = e2ap_asn1c_encode_pdu(pdu, &buf);
43 memcpy(data.buffer, buf, data.len);
45 sctp_send_data(client_fd, data);
48 void wait_for_sctp_data(int client_fd)
50 sctp_buffer_t recv_buf;
51 if(sctp_receive_data(client_fd, recv_buf) > 0)
53 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
54 e2ap_handle_sctp_data(client_fd, recv_buf);
58 void set_seqnum(E2AP_PDU_t* pdu)
60 InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
61 // xer_fprint(stdout, &asn_DEF_InitiatingMessage, (void *)initiatingMessage);
63 RICsubscriptionRequest_t *request = &initiatingMessage->value.choice.RICsubscriptionRequest;
64 xer_fprint(stdout, &asn_DEF_RICsubscriptionRequest, (void *)request);
66 LOG_I("num of IEs = %d", request->protocolIEs.list.count);
68 RICsubscriptionRequest_IEs_t *ie;
70 ie = request->protocolIEs.list.array[2];
72 xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ie);
74 // e2ap_asn1c_print_pdu(pdu);
77 int subresponse_get_sequenceNum(E2AP_PDU_t* pdu)
79 SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome;
81 RICrequestID_t *requestid;
83 int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count;
85 for(int edx = 0; edx < num_IEs; edx++)
87 RICsubscriptionResponse_IEs_t *memb_ptr =
88 responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx];
92 case (ProtocolIE_ID_id_RICrequestID):
93 requestid = &memb_ptr->value.choice.RICrequestID;
94 // xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
95 return requestid->ricRequestSequenceNumber;
101 void subrequest_set_sequenceNum(E2AP_PDU_t* pdu, int seq)
103 InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
105 RICrequestID_t *requestid;
107 int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count;
109 for(int edx = 0; edx < num_IEs; edx++)
111 RICsubscriptionRequest_IEs_t *memb_ptr =
112 initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx];
116 case (ProtocolIE_ID_id_RICrequestID):
117 requestid = &memb_ptr->value.choice.RICrequestID;
118 requestid->ricRequestSequenceNumber = seq;
125 void subscription_response_get_field(E2AP_PDU_t* pdu)
127 SuccessfulOutcome_t *responseMsg = pdu->choice.successfulOutcome;
129 RICrequestID_t *requestid;
130 RANfunctionID_t * ranfunctionid;
131 RICsubscription_t * ricsubscription;
133 int requestID_val, sequenceNum;
135 int num_IEs = responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.count;
137 LOG_I("num of IEs = %d", num_IEs);
139 for(int edx = 0; edx < num_IEs; edx++)
141 RICsubscriptionResponse_IEs_t *memb_ptr =
142 responseMsg->value.choice.RICsubscriptionResponse.protocolIEs.list.array[edx];
146 case (ProtocolIE_ID_id_RICrequestID):
147 requestid = &memb_ptr->value.choice.RICrequestID;
148 xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
149 requestID_val = requestid->ricRequestorID;
150 sequenceNum = requestid->ricRequestSequenceNumber;
151 requestid->ricRequestSequenceNumber = 202;
154 case (ProtocolIE_ID_id_RANfunctionID):
155 ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
156 xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid);
159 // case (ProtocolIE_ID_id_RICsubscription):
160 // ricsubscription = &memb_ptr->value.choice.RICsubscription;
161 // xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription);
166 LOG_I("Request ID = %d, seq = %d", requestID_val, sequenceNum);
169 void subscription_request_get_field(E2AP_PDU_t* pdu)
171 InitiatingMessage_t *initiatingMessage = pdu->choice.initiatingMessage;
173 RICrequestID_t *requestid;
174 RANfunctionID_t * ranfunctionid;
175 RICsubscription_t * ricsubscription;
177 int num_IEs = initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.count;
179 LOG_I("num of IEs = %d", num_IEs);
181 for(int edx = 0; edx < num_IEs; edx++)
183 RICsubscriptionRequest_IEs_t *memb_ptr =
184 initiatingMessage->value.choice.RICsubscriptionRequest.protocolIEs.list.array[edx];
188 case (ProtocolIE_ID_id_RICrequestID):
189 requestid = &memb_ptr->value.choice.RICrequestID;
190 xer_fprint(stdout, &asn_DEF_RICrequestID, (void *)requestid);
193 case (ProtocolIE_ID_id_RANfunctionID):
194 ranfunctionid = &memb_ptr->value.choice.RANfunctionID;
195 xer_fprint(stdout, &asn_DEF_RANfunctionID, (void *)ranfunctionid);
198 case (ProtocolIE_ID_id_RICsubscription):
199 ricsubscription = &memb_ptr->value.choice.RICsubscription;
200 xer_fprint(stdout, &asn_DEF_RICsubscription, (void *)ricsubscription);
206 int main(int argc, char* argv[]){
207 LOG_I("Start RIC Simulator - Performance Test");
209 options_t ops = read_input_options(argc, argv);
210 int client_fd = sctp_start_client(ops.server_ip, ops.server_port);
212 //1. Send ENDCX2Setup
213 E2AP_PDU_t* pdu_setup = e2ap_xml_to_pdu("E2AP_ENDCX2SetupRequest.xml");
214 // e2ap_asn1c_print_pdu(pdu_setup);
215 encode_and_send_sctp_data(pdu_setup, client_fd);
216 LOG_I("[SCTP] Sent ENDC X2 SETUP REQUEST");
218 //2. Receive ENDCX2SetupResponse
219 wait_for_sctp_data(client_fd);
221 //3. Send RICSubscriptionRequest
222 E2AP_PDU_t* pdu_sub = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest_Ashwin.xml");
223 e2ap_asn1c_print_pdu(pdu_sub);
224 encode_and_send_sctp_data(pdu_sub, client_fd);
225 LOG_I("[SCTP] Sent RIC SUBSCRIPTION REQUEST");
228 //4. Receive RIC SUBSCRIPT RESPONSE
233 usleep(1000); //sleep for one ms
235 sctp_buffer_t recv_buf;
239 if(sctp_receive_data(client_fd, recv_buf) > 0)
241 LOG_I("[SCTP] Received new data of size %d", recv_buf.len);
242 // e2ap_handle_sctp_data(client_fd, recv_buf);
244 E2AP_PDU_t* res_pdu = new E2AP_PDU_t();
246 e2ap_asn1c_decode_pdu(res_pdu, recv_buf.buffer, recv_buf.len);
248 int procedureCode = e2ap_asn1c_get_procedureCode(res_pdu);
249 int index = (int)res_pdu->present;
251 if(index == E2AP_PDU_PR_successfulOutcome && \
252 procedureCode == ProcedureCode_id_ricSubscription)
254 res_seq =subresponse_get_sequenceNum(res_pdu);
257 LOG_I("Received RIC SUBSCRIPTION RESPONSE, seq = %d, totalCount = %d",\
260 //Put res_seq in new subscription request
261 E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
262 subrequest_set_sequenceNum(req_pdu, res_seq);
263 // e2ap_asn1c_print_pdu(req_pdu);
265 encode_and_send_sctp_data(req_pdu, client_fd);
266 LOG_I("Send new SUBSCRIPT REQUEST, seq = %d", res_seq);
273 // E2AP_PDU_t* res_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionResponse.xml");
275 // //Extract subscription response sequence number
276 // int res_seq = subresponse_get_sequenceNum(res_pdu);
277 // LOG_I("Subscription Response SeqNo = %d", res_seq);
279 // //Put responseSeq in new subscription request
280 // E2AP_PDU_t* req_pdu = e2ap_xml_to_pdu("E2AP_RICsubscriptionRequest.xml");
282 // subrequest_set_sequenceNum(req_pdu, res_seq);
284 // e2ap_asn1c_print_pdu(req_pdu);