From 471b563ac7511d9ce9bb25e823a1055e5cdb43fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAben=20Soares=20Silva?= Date: Wed, 2 Apr 2025 17:50:58 +0100 Subject: [PATCH] Add send function pointers to PNF --- nfapi/oai_integration/nfapi_pnf.c | 3 ++ nfapi/open-nFAPI/pnf/inc/pnf.h | 6 ++-- nfapi/open-nFAPI/pnf/inc/pnf_p7.h | 8 ++---- .../pnf/public_inc/nfapi_pnf_interface.h | 28 +++++++++++++++++-- nfapi/open-nFAPI/pnf/src/pnf.c | 6 ++-- nfapi/open-nFAPI/pnf/src/pnf_interface.c | 24 ++++++++-------- nfapi/open-nFAPI/pnf/src/pnf_p7.c | 21 +++++++------- nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c | 19 ++++++++----- 8 files changed, 72 insertions(+), 43 deletions(-) diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c index b58463a7de..f1010bde1a 100644 --- a/nfapi/oai_integration/nfapi_pnf.c +++ b/nfapi/oai_integration/nfapi_pnf.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include "fapi_stub.h" @@ -1750,6 +1751,7 @@ int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nf p7_config->unpack_func = &nfapi_nr_p7_message_unpack; p7_config->hdr_unpack_func = &nfapi_nr_p7_message_header_unpack; p7_config->pack_func = &nfapi_nr_p7_message_pack; + p7_config->send_p7_msg = &pnf_nr_send_p7_message; NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating P7 thread %s\n", __FUNCTION__); pthread_t p7_thread; threadCreate(&p7_thread, &pnf_nr_p7_thread_start, p7_config, "pnf_p7_thread", -1, OAI_PRIORITY_RT); @@ -2194,6 +2196,7 @@ void configure_nr_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_add config->unpack_func = &nfapi_nr_p5_message_unpack; config->hdr_unpack_func = &nfapi_nr_p5_message_header_unpack; config->pack_func = &nfapi_nr_p5_message_pack; + config->send_p5_msg = &pnf_nr_send_p5_message; NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating PNF NFAPI start thread %s\n", __FUNCTION__); pthread_create(&pnf_start_pthread, NULL, &pnf_nr_start_thread, config); pthread_setname_np(pnf_start_pthread, "NFAPI_PNF"); diff --git a/nfapi/open-nFAPI/pnf/inc/pnf.h b/nfapi/open-nFAPI/pnf/inc/pnf.h index 7275db76e1..386cb3cf6a 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf.h @@ -22,7 +22,7 @@ #define NFAPI_MAX_PACKED_MESSAGE_SIZE 32768 -typedef struct { +struct pnf_t { nfapi_pnf_config_t _public; @@ -33,14 +33,14 @@ typedef struct { uint8_t terminate; -} pnf_t; +}; int pnf_connect(pnf_t *pnf); int pnf_message_pump(pnf_t *pnf); int pnf_nr_message_pump(pnf_t *pnf); -int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len); +bool pnf_nr_send_p5_message(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len); int pnf_pack_and_send_p5_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len); int pnf_pack_and_send_p4_message(pnf_t* pnf, nfapi_p4_p5_message_header_t* msg, uint32_t msg_len); int pnf_send_message(pnf_t* pnf, uint8_t* msg, uint32_t msg_len, uint16_t stream_id); diff --git a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h index 0325c8c242..8a603ecdb3 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h @@ -82,7 +82,7 @@ typedef struct { } pnf_p7_rx_reassembly_queue_t; -typedef struct { +struct pnf_p7_t { nfapi_pnf_p7_config_t _public; @@ -139,12 +139,12 @@ typedef struct { pnf_p7_stats_t stats; pnf_p7_nr_stats_t nr_stats; -} pnf_p7_t; +}; int pnf_p7_message_pump(pnf_p7_t* pnf_p7); int pnf_nr_p7_message_pump(pnf_p7_t* pnf_p7); int pnf_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* msg, uint32_t msg_len); -int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len); +bool pnf_nr_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len); int pnf_p7_send_message(pnf_p7_t* pnf_p7, uint8_t* msg, uint32_t msg_len); @@ -160,7 +160,5 @@ pnf_p7_rx_message_t* pnf_p7_rx_reassembly_queue_add_segment(pnf_p7_t* pnf_p7, pn void pnf_p7_rx_reassembly_queue_remove_msg(pnf_p7_t* pnf_p7, pnf_p7_rx_reassembly_queue_t* queue, pnf_p7_rx_message_t* msg); void pnf_p7_rx_reassembly_queue_remove_old_msgs(pnf_p7_t* pnf_p7, pnf_p7_rx_reassembly_queue_t* queue, uint32_t rx_hr_time, uint32_t delta); -int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len); - #endif /* _PNF_P7_H_ */ diff --git a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h index 2e4cb8812c..04abf6309d 100644 --- a/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h +++ b/nfapi/open-nFAPI/pnf/public_inc/nfapi_pnf_interface.h @@ -31,8 +31,8 @@ extern "C" { #include #include "openair1/PHY/defs_gNB.h" - - +typedef struct pnf_t pnf_t; +typedef struct pnf_p7_t pnf_p7_t; /*! This enum is used to describe the states of the pnf */ @@ -320,6 +320,8 @@ typedef struct nfapi_pnf_config void (*deallocate_p4_p5_vendor_ext)(void* header); /*! \brief Encodes an (n)FAPI P5 message to a buffer + * + * This function is called internally in send_p5_msg() * \param pMessageBuf A pointer to a nfapi p5 message structure * \param messageBufLen The size of the p5 message structure * \param pPackedBuf A pointer to the buffer that the p5 message will be packed into @@ -361,6 +363,16 @@ typedef struct nfapi_pnf_config uint32_t unpackedBufLen, nfapi_p4_p5_codec_config_t* config); + /*! \brief Sends a (N)FAPI P5 message + * + * This function internally packs the given message into a buffer by calling the previously defined pack_func() function pointer + * Then, having the message buffer populated, sends it to the VNF + * \param pnf A pointer to a pnf_t* + * \param msg A pointer to the P5 message + * \param msg_len The size of the encoded P5 message + * \return true on success, false on failure. + */ + bool (*send_p5_msg)(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len); } nfapi_pnf_config_t; /*! Create a pnf configuration @@ -767,6 +779,8 @@ typedef struct nfapi_pnf_p7_config void (*deallocate_p7_vendor_ext)(void* header); /*! A callback to pack a P7 message + * + * This function is called internally in send_p7_msg() * \param pMessageBuf A pointer to a nfapi p7 message structure * \param pPackedBuf A pointer to the buffer that the p7 message will be packed into * \param packedBufLen The size of the buffer @@ -803,6 +817,16 @@ typedef struct nfapi_pnf_p7_config uint32_t unpackedBufLen, nfapi_p7_codec_config_t* config); + /*! \brief Sends a (N)FAPI P7 message + * + * This function internally packs the given message into a buffer by calling the previously defined pack_func() function pointer + * Then, having the message buffer populated, sends it to the VNF + * \param pnf_p7 A pointer to a pnf_p7_t struct + * \param header A pointer to the P7 message to pack & send + * \param msg_len The P7 message length + * \return true on success, false on failure. + */ + bool (*send_p7_msg)(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len); } nfapi_pnf_p7_config_t; /*! Create and initialise a nfapi_pnf_p7_config structure diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c index e4438eded7..7ed881f7e3 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf.c +++ b/nfapi/open-nFAPI/pnf/src/pnf.c @@ -1705,17 +1705,17 @@ void pnf_handle_p5_message(pnf_t* pnf, void *pRecvMsg, int recvMsgLen) } } -int pnf_nr_pack_and_send_p5_message(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len) +bool pnf_nr_send_p5_message(pnf_t* pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len) { int packed_len = pnf->_public.pack_func(msg, msg_len, pnf->tx_message_buffer, sizeof(pnf->tx_message_buffer), &pnf->_public.codec_config); if (packed_len < 0) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_nr_p5_message_pack failed (%d)\n", packed_len); - return -1; + return false; } - return pnf_send_message(pnf, pnf->tx_message_buffer, packed_len, 0 /*msg->stream_id*/); + return pnf_send_message(pnf, pnf->tx_message_buffer, packed_len, 0 /*msg->stream_id*/) == 0; } diff --git a/nfapi/open-nFAPI/pnf/src/pnf_interface.c b/nfapi/open-nFAPI/pnf/src/pnf_interface.c index a53604640c..78ea46bbf6 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_interface.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_interface.c @@ -135,8 +135,8 @@ int nfapi_nr_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_param_r } pnf_t* _this = (pnf_t*)(config); - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_param_response_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured!"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_pnf_param_response_t)); } int nfapi_pnf_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_pnf_param_response_t* resp) @@ -188,8 +188,8 @@ int nfapi_nr_pnf_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_config } pnf_t* _this = (pnf_t*)(config); - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_config_response_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured|"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_pnf_config_response_t)); } @@ -227,8 +227,8 @@ int nfapi_nr_pnf_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_pnf_start_r } pnf_t* _this = (pnf_t*)(config); - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_pnf_start_response_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured|"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_pnf_start_response_t)); } @@ -273,8 +273,8 @@ int nfapi_nr_pnf_param_resp(nfapi_pnf_config_t* config, nfapi_nr_param_response_ } pnf_t* _this = (pnf_t*)(config); - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_param_response_scf_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured|"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_param_response_scf_t)); } int nfapi_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_config_response_t* resp) @@ -329,8 +329,8 @@ int nfapi_nr_pnf_config_resp(nfapi_pnf_config_t* config, nfapi_nr_config_respons NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknow phy id %d\n", __FUNCTION__, resp->header.phy_id); return -1; } - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_config_response_scf_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured|"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_config_response_scf_t)); } @@ -384,8 +384,8 @@ int nfapi_nr_pnf_start_resp(nfapi_pnf_config_t* config, nfapi_nr_start_response_ NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: unknown phy id %d\n", __FUNCTION__, resp->header.phy_id); return -1; } - - return pnf_nr_pack_and_send_p5_message(_this, &(resp->header), sizeof(nfapi_nr_start_response_scf_t)); + AssertFatal(config->send_p5_msg, "Function pointer must be configured|"); + return config->send_p5_msg(_this, &(resp->header), sizeof(nfapi_nr_start_response_scf_t)); } diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7.c b/nfapi/open-nFAPI/pnf/src/pnf_p7.c index 2235a7c153..95fff37bc9 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_p7.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_p7.c @@ -569,14 +569,14 @@ int pnf_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_p7_message_header_t* return 0; } -int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len) +bool pnf_nr_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_header_t* header, uint32_t msg_len) { header->m_segment_sequence = NFAPI_P7_SET_MSS(0, 0, pnf_p7->sequence_number); // Need to guard against different threads calling the encode function at the same time if (pthread_mutex_lock(&(pnf_p7->pack_mutex)) != 0) { NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to lock mutex\n"); - return -1; + return false; } uint8_t tx_buf[131072]; // four times NFAPI_MAX_PACKED_MESSAGE_SIZE as of this commit @@ -585,11 +585,11 @@ int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_hea if (len < 0) { if (pthread_mutex_unlock(&(pnf_p7->pack_mutex)) != 0) { NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n"); - return -1; + return false; } NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p7_message_pack failed with return %d\n", len); - return -1; + return false; } if (len > pnf_p7->_public.segment_size) { @@ -644,10 +644,10 @@ int pnf_nr_p7_pack_and_send_p7_message(pnf_p7_t* pnf_p7, nfapi_nr_p7_message_hea if (pthread_mutex_unlock(&(pnf_p7->pack_mutex)) != 0) { NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n"); - return -1; + return false; } - return 0; + return true; } void pnf_pack_and_send_timing_info(pnf_p7_t* pnf_p7) @@ -707,9 +707,8 @@ void pnf_nr_pack_and_send_timing_info(pnf_p7_t* pnf_p7) timing_info.tx_data_request_earliest_arrival = 0; timing_info.ul_tti_earliest_arrival = 0; timing_info.ul_dci_earliest_arrival = 0; - - - pnf_nr_p7_pack_and_send_p7_message(pnf_p7, &(timing_info.header), sizeof(timing_info)); + AssertFatal(pnf_p7->_public.send_p7_msg, "The function pointer to pack and send P7 messages must be set"); + pnf_p7->_public.send_p7_msg(pnf_p7, &(timing_info.header), sizeof(timing_info)); pnf_p7->timing_info_ms_counter = 0; } @@ -2097,8 +2096,8 @@ void pnf_nr_handle_dl_node_sync(void *pRecvMsg, int recvMsgLen, pnf_p7_t* pnf_p7 NFAPI_TRACE(NFAPI_TRACE_INFO, "failed to unlock mutex\n"); return; } - - pnf_nr_p7_pack_and_send_p7_message(pnf_p7, &(ul_node_sync.header), sizeof(ul_node_sync)); + AssertFatal(pnf_p7->_public.send_p7_msg, "Function pointer must be configured|"); + pnf_p7->_public.send_p7_msg(pnf_p7, &(ul_node_sync.header), sizeof(ul_node_sync)); //printf("\nSSent UL Node Sync sfn:%d,slot:%d\n",pnf_p7->sfn,pnf_p7->slot); } diff --git a/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c b/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c index 6e5569d972..06d268a875 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c +++ b/nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c @@ -260,7 +260,8 @@ int nfapi_pnf_p7_nr_slot_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_slot_indica } pnf_p7_t* _this = (pnf_p7_t*)(config); - return pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_slot_indication_scf_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + return _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_slot_indication_scf_t)); } int nfapi_pnf_p7_nr_rx_data_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rx_data_indication_t* ind) @@ -272,8 +273,8 @@ int nfapi_pnf_p7_nr_rx_data_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rx_data_ } pnf_p7_t* _this = (pnf_p7_t*)(config); - - int ret = pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_rx_data_indication_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + int ret = _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_rx_data_indication_t)); if (ret == 0) { for (int i = 0; i < ind->number_of_pdus; ++i) _this->nr_stats.ul.bytes += ind->pdu_list[i].pdu_length; @@ -290,7 +291,8 @@ int nfapi_pnf_p7_nr_crc_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_crc_indicati } pnf_p7_t* _this = (pnf_p7_t*)(config); - return pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_crc_indication_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + return _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_crc_indication_t)); } int nfapi_pnf_p7_nr_srs_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_srs_indication_t* ind) @@ -302,7 +304,8 @@ int nfapi_pnf_p7_nr_srs_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_srs_indicati } pnf_p7_t* _this = (pnf_p7_t*)(config); - return pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_srs_indication_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + return _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_srs_indication_t)); } int nfapi_pnf_p7_nr_uci_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_uci_indication_t* ind) @@ -314,7 +317,8 @@ int nfapi_pnf_p7_nr_uci_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_uci_indicati } pnf_p7_t* _this = (pnf_p7_t*)(config); - return pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_uci_indication_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + return _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_uci_indication_t)); } int nfapi_pnf_p7_nr_rach_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rach_indication_t* ind) @@ -326,5 +330,6 @@ int nfapi_pnf_p7_nr_rach_ind(nfapi_pnf_p7_config_t* config, nfapi_nr_rach_indica } pnf_p7_t* _this = (pnf_p7_t*)(config); - return pnf_nr_p7_pack_and_send_p7_message(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_rach_indication_t)); + AssertFatal(_this->_public.send_p7_msg, "Function pointer must be configured|"); + return _this->_public.send_p7_msg(_this, (nfapi_nr_p7_message_header_t*)ind, sizeof(nfapi_nr_rach_indication_t)); }