diff --git a/srsgnb/hdr/stack/ric/e2ap.h b/srsgnb/hdr/stack/ric/e2ap.h index 5e2d97194..406f70059 100644 --- a/srsgnb/hdr/stack/ric/e2ap.h +++ b/srsgnb/hdr/stack/ric/e2ap.h @@ -23,14 +23,16 @@ class e2ap { public: e2_ap_pdu_c generate_setup_request(); - int process_setup_response(); + int process_setup_response(e2setup_resp_s setup_response); int process_setup_failure(); int process_subscription_request(); int generate_subscription_response(); int generate_subscription_failure(); int generate_indication(); + bool has_setup_response() { return setup_response_received; } private: + bool setup_response_received = false; }; #endif /* RIC_E2AP_H */ diff --git a/srsgnb/src/stack/ric/e2ap.cc b/srsgnb/src/stack/ric/e2ap.cc index 1252f71aa..76ccfbc7a 100644 --- a/srsgnb/src/stack/ric/e2ap.cc +++ b/srsgnb/src/stack/ric/e2ap.cc @@ -51,3 +51,10 @@ e2_ap_pdu_c e2ap::generate_setup_request() item1.e2node_component_cfg.e2node_component_resp_part.from_string("72657370617274"); return pdu; } + +int e2ap::process_setup_response(e2setup_resp_s setup_response) +{ + setup_response_received = true; + // TODO process setup response + return 0; +} \ No newline at end of file diff --git a/srsgnb/src/stack/ric/ric_client.cc b/srsgnb/src/stack/ric/ric_client.cc index dce625f41..591875c91 100644 --- a/srsgnb/src/stack/ric/ric_client.cc +++ b/srsgnb/src/stack/ric/ric_client.cc @@ -66,8 +66,12 @@ void ric_client::stop() void ric_client::run_thread() { while (running) { - send_e2_setup_request(); - printf("e2 setup request sent\n"); + if (!e2ap_.has_setup_response()) { + send_e2_setup_request(); + printf("e2 setup request sent\n"); + } + sleep(1); + task_sched.run_next_task(); sleep(5); } } @@ -103,14 +107,97 @@ bool ric_client::send_e2_setup_request() asn1::bit_ref bref(buf->msg, buf->get_tailroom()); if (setup_req_pdu.pack(bref) != asn1::SRSASN_SUCCESS) { - printf("Failed to pack TX E2 PDU\n"); + logger.error("Failed to pack TX E2 PDU"); return false; } buf->N_bytes = bref.distance_bytes(); printf("try to send %d bytes to addr %s \n", buf->N_bytes, inet_ntoa(ric_addr.sin_addr)); if (!send_sctp(buf)) { - printf("failed to send e2 setup request\n"); + logger.error("failed to send e2 setup request"); return false; } return true; } + +bool ric_client::handle_e2_rx_msg(srsran::unique_byte_buffer_t pdu, + const sockaddr_in& from, + const sctp_sndrcvinfo& sri, + int flags) +{ + printf("RIC_CLIENT: Received %d bytes from %s\n", pdu->N_bytes, inet_ntoa(from.sin_addr)); + e2_ap_pdu_c pdu_c; + asn1::cbit_ref bref(pdu->msg, pdu->N_bytes); + if (pdu_c.unpack(bref) != asn1::SRSASN_SUCCESS) { + logger.error("Failed to unpack RX E2 PDU"); + return false; + } + if (pdu_c.type().value == e2_ap_pdu_c::types_opts::init_msg) { + logger.info("Received E2AP Init Message"); + handle_e2_init_msg(pdu_c.init_msg()); + } else if (pdu_c.type().value == e2_ap_pdu_c::types_opts::successful_outcome) { + logger.info("Received E2AP Successful Outcome"); + // handle_e2_successful_outcome(pdu_c.successful_outcome()); + } else if (pdu_c.type().value == e2_ap_pdu_c::types_opts::unsuccessful_outcome) { + logger.info("Received E2AP Unsuccessful Outcome "); + // handle_e2_unsuccessful_outcome(pdu_c.unsuccessful_outcome()); + } else { + logger.warning("Received E2AP Unknown Message "); + } + return true; +} + +bool ric_client::handle_e2_init_msg(asn1::e2ap::init_msg_s& init_msg) +{ + using namespace asn1::e2ap; + // TODO check for different type of RIC generated init messages + // eg. RIC subscription request, RIC Reset request, RIC control request, RIC subscription delete request + return true; +} + +bool ric_client::handle_e2_successful_outcome(asn1::e2ap::successful_outcome_s& successful_outcome) +{ + using namespace asn1::e2ap; + if (successful_outcome.value.type() == e2_ap_elem_procs_o::successful_outcome_c::types_opts::e2setup_resp) { + logger.info("Received E2AP E2 Setup Successful Outcome"); + handle_e2_setup_response(successful_outcome.value.e2setup_resp()); + } else if (successful_outcome.value.type() == + e2_ap_elem_procs_o::successful_outcome_c::types_opts::ricsubscription_resp) { + logger.info("Received E2AP RIC Subscription Response"); + // handle_ric_subscription_response(successful_outcome.value.ric_subscription()); + } else if (successful_outcome.value.type() == e2_ap_elem_procs_o::successful_outcome_c::types_opts::ri_cctrl_ack) { + logger.info("Received E2AP RIC Control acknowlegement \n"); + // handle_ric_control_response(successful_outcome.value.ric_control()); + } else if (successful_outcome.value.type() == + e2_ap_elem_procs_o::successful_outcome_c::types_opts::ricservice_upd_ack) { + logger.info("Received E2AP RIC Service Update acknowlegement \n"); + // handle_ric_service_update_ack(successful_outcome.value.ric_service_update()); + } else if (successful_outcome.value.type() == + e2_ap_elem_procs_o::successful_outcome_c::types_opts::ricsubscription_delete_resp) { + logger.info("Received E2AP RIC Subscription Delete Response \n"); + // handle_ric_subscription_delete_response(successful_outcome.value.ric_subscription_delete()); + } else if (successful_outcome.value.type() == e2_ap_elem_procs_o::successful_outcome_c::types_opts::e2_removal_resp) { + logger.info("Received E2AP RIC Service Status Successful Outcome \n"); + // handle_e2_removal_response(successful_outcome.value.e2_removal()); + } else { + logger.info("Received E2AP Unknown Successful Outcome \n"); + } + return true; +} + +bool ric_client::handle_e2_setup_response(e2setup_resp_s setup_response) +{ + printf("Received E2AP E2 Setup Response \n"); + if (e2ap_.process_setup_response(setup_response)) { + logger.error("Failed to process E2 Setup Response"); + return false; + } + return true; +} + +bool ric_client::handle_e2_unsuccessful_outcome(asn1::e2ap::unsuccessful_outcome_s& unsuccessful_outcome) +{ + using namespace asn1::e2ap; + // TODO check for different type of RIC generated unsuccessful outcomes + // eg. RIC subscription failure, RIC Reset failure, RIC control failure, RIC subscription delete failure + return true; +}