Change VNF to use functions pointers to pack/unpack messages.
Adds 3 new function pointers to the P5 and P7 VNF structures, allowing to configure which function to use to pack/unpack the messages, as well as unpack the message header, being then used seamlessly regardless of using the FAPI or nFAPI functions.
This commit is contained in:
@@ -1445,6 +1445,9 @@ void *vnf_nr_p7_thread_start(void *ptr)
|
||||
p7_vnf->config->codec_config.deallocate = &vnf_deallocate;
|
||||
p7_vnf->config->allocate_p7_vendor_ext = &phy_nr_allocate_p7_vendor_ext;
|
||||
p7_vnf->config->deallocate_p7_vendor_ext = &phy_nr_deallocate_p7_vendor_ext;
|
||||
p7_vnf->config->unpack_func = &nfapi_nr_p7_message_unpack;
|
||||
p7_vnf->config->hdr_unpack_func = &nfapi_nr_p7_message_header_unpack;
|
||||
p7_vnf->config->pack_func = &nfapi_nr_p7_message_pack;
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI P7 start thread %s\n", __FUNCTION__);
|
||||
pthread_create(&vnf_p7_start_pthread, NULL, &vnf_nr_p7_start_thread, p7_vnf->config);
|
||||
return 0;
|
||||
@@ -1862,6 +1865,9 @@ void configure_nr_nfapi_vnf(char *vnf_addr, int vnf_p5_port, char *pnf_ip_addr,
|
||||
config->codec_config.allocate = &vnf_nr_allocate;
|
||||
config->codec_config.deallocate = &vnf_nr_deallocate;
|
||||
memset(&UL_RCC_INFO, 0, sizeof(UL_RCC_IND_t));
|
||||
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;
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__);
|
||||
pthread_create(&vnf_start_pthread, NULL, (void *)&vnf_nr_start_thread, config);
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Created VNF NFAPI start thread %s\n", __FUNCTION__);
|
||||
|
||||
@@ -449,7 +449,47 @@ typedef struct nfapi_vnf_config
|
||||
*/
|
||||
void (*deallocate_p4_p5_vendor_ext)(void* header);
|
||||
|
||||
/*! \brief Encodes a (n)FAPI P5 message to a buffer
|
||||
* \param pMessageBuf A pointer to a (n)fapi 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
|
||||
* \param packedBufLen The size of the buffer
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return != 0 means success, -1 means failure.
|
||||
*/
|
||||
int (*pack_func)(void* pMessageBuf,
|
||||
uint32_t messageBufLen,
|
||||
void* pPackedBuf,
|
||||
uint32_t packedBufLen,
|
||||
nfapi_p4_p5_codec_config_t* config);
|
||||
|
||||
/*! \brief Decodes an (n)FAPI P5 message
|
||||
* \param pMessageBuf A pointer to an encoded P5 message
|
||||
* \param messageBufLen The size of the encoded P5 message
|
||||
* \param pUnpackedBuf A pointer to the nfapi_message_header
|
||||
* \param unpackedBufLen The size of nfapi_message_header structure.
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return true on success, false on failure
|
||||
*/
|
||||
bool (*unpack_func)(void* pMessageBuf,
|
||||
uint32_t messageBufLen,
|
||||
void* pUnpackedBuf,
|
||||
uint32_t unpackedBufLen,
|
||||
nfapi_p4_p5_codec_config_t* config);
|
||||
|
||||
/*! \brief Decodes an (n)FAPI P5 message header
|
||||
* \param pMessageBuf A pointer to an encoded P5 message header
|
||||
* \param messageBufLen The size of the encoded P5 message header
|
||||
* \param pUnpackedBuf A pointer to the nfapi_message_header
|
||||
* \param unpackedBufLen The size of nfapi_message_header structure.
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return true on success, false on failure
|
||||
*/
|
||||
bool (*hdr_unpack_func)(void* pMessageBuf,
|
||||
uint32_t messageBufLen,
|
||||
void* pUnpackedBuf,
|
||||
uint32_t unpackedBufLen,
|
||||
nfapi_p4_p5_codec_config_t* config);
|
||||
|
||||
|
||||
|
||||
@@ -878,7 +918,42 @@ typedef struct nfapi_vnf_p7_config
|
||||
*/
|
||||
void (*deallocate_p7_vendor_ext)(void* header);
|
||||
|
||||
/*! A callback to pack a P7 message
|
||||
* \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
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return != -1 means success, -1 means failure.
|
||||
*/
|
||||
int (*pack_func)(void* pMessageBuf, void* pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t* config);
|
||||
|
||||
/*! A callback to unpack a P7 message
|
||||
* \param pMessageBuf A pointer to an encoded P7 message header
|
||||
* \param messageBufLen The size of the encoded P7 message header
|
||||
* \param pUnpackedBuf A pointer to the nfapi_message_header
|
||||
* \param unpackedBufLen The size of nfapi_message_header structure.
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return true on success, false on failure
|
||||
*/
|
||||
bool (*unpack_func)(void* pMessageBuf,
|
||||
uint32_t messageBufLen,
|
||||
void* pUnpackedBuf,
|
||||
uint32_t unpackedBufLen,
|
||||
nfapi_p7_codec_config_t* config);
|
||||
|
||||
/*! \brief Decodes an NFAPI P7 message header
|
||||
* \param pMessageBuf A pointer to an encoded P5 message header
|
||||
* \param messageBufLen The size of the encoded P5 message header
|
||||
* \param pUnpackedBuf A pointer to the nfapi_message_header
|
||||
* \param unpackedBufLen The size of nfapi_message_header structure.
|
||||
* \param config A pointer to the nfapi configuration structure
|
||||
* \return true on success, false on failure
|
||||
*/
|
||||
bool (*hdr_unpack_func)(void* pMessageBuf,
|
||||
uint32_t messageBufLen,
|
||||
void* pUnpackedBuf,
|
||||
uint32_t unpackedBufLen,
|
||||
nfapi_p7_codec_config_t* config);
|
||||
} nfapi_vnf_p7_config_t;
|
||||
|
||||
/*! Creates and initializes the nfapi_vnf_p7_config structure before use
|
||||
|
||||
@@ -117,7 +117,8 @@ void vnf_nr_handle_pnf_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_
|
||||
nfapi_nr_pnf_param_response_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{
|
||||
// Invoke the call back
|
||||
if(config->pnf_nr_param_resp)
|
||||
@@ -188,7 +189,8 @@ void vnf_nr_handle_pnf_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf
|
||||
nfapi_nr_pnf_config_response_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{
|
||||
// Invoke the call back
|
||||
if(config->pnf_nr_config_resp)
|
||||
@@ -258,7 +260,8 @@ void vnf_nr_handle_pnf_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_
|
||||
nfapi_nr_pnf_start_response_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{
|
||||
if(config->pnf_nr_start_resp)
|
||||
{
|
||||
@@ -428,7 +431,8 @@ void vnf_nr_handle_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_conf
|
||||
nfapi_nr_param_response_scf_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{
|
||||
|
||||
if (msg.error_code == NFAPI_NR_PARAM_MSG_OK)
|
||||
@@ -495,7 +499,8 @@ void vnf_nr_handle_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_con
|
||||
nfapi_nr_config_response_scf_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >=0 )
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{
|
||||
// check the error code:
|
||||
|
||||
@@ -602,7 +607,8 @@ void vnf_nr_handle_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_conf
|
||||
nfapi_nr_start_response_scf_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_nr_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
const bool result = config->unpack_func(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config);
|
||||
if (result)
|
||||
{ // check the error code
|
||||
if (msg.error_code == NFAPI_NR_START_MSG_OK){
|
||||
if(config->nr_start_resp)
|
||||
@@ -1085,7 +1091,8 @@ void vnf_nr_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfa
|
||||
}
|
||||
|
||||
// unpack the message header
|
||||
if (nfapi_nr_p5_message_header_unpack(pRecvMsg, recvMsgLen, &messageHeader, sizeof(nfapi_nr_p4_p5_message_header_t), &config->codec_config) < 0)
|
||||
const bool result = config->hdr_unpack_func(pRecvMsg, recvMsgLen, &messageHeader, sizeof(nfapi_nr_p4_p5_message_header_t), &config->codec_config);
|
||||
if (!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return;
|
||||
@@ -1295,9 +1302,9 @@ int vnf_nr_read_dispatch_message(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_
|
||||
}
|
||||
|
||||
nfapi_nr_p4_p5_message_header_t header;
|
||||
int unpack_result = nfapi_nr_p5_message_header_unpack(header_buffer, header_buffer_size, &header, sizeof(header), 0);
|
||||
if (unpack_result < 0) {
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF Failed to decode message header %d\n", unpack_result);
|
||||
const bool result = config->hdr_unpack_func(header_buffer, header_buffer_size, &header, sizeof(header), 0);
|
||||
if (!result) {
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF Failed to decode message header\n");
|
||||
return 0;
|
||||
}
|
||||
message_size = header.message_length + header_buffer_size;
|
||||
|
||||
@@ -1098,10 +1098,8 @@ void vnf_nr_handle_p7_vendor_extension(void *pRecvMsg, int recvMsgLen, vnf_p7_t*
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "%s failed to allocate vendor extention structure\n", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
int unpack_result = nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, msg, msg_size, &vnf_p7->_public.codec_config);
|
||||
|
||||
if(unpack_result == 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, msg, msg_size, &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
if(vnf_p7->_public.vendor_ext)
|
||||
vnf_p7->_public.vendor_ext(&(vnf_p7->_public), msg);
|
||||
@@ -1497,8 +1495,8 @@ void vnf_handle_nr_slot_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf
|
||||
else
|
||||
{
|
||||
nfapi_nr_slot_indication_scf_t ind = {0};
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1524,8 +1522,8 @@ void vnf_handle_nr_rx_data_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t*
|
||||
else
|
||||
{
|
||||
nfapi_nr_rx_data_indication_t ind;
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1551,8 +1549,8 @@ void vnf_handle_nr_crc_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_
|
||||
else
|
||||
{
|
||||
nfapi_nr_crc_indication_t ind;
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1578,8 +1576,8 @@ void vnf_handle_nr_srs_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_
|
||||
else
|
||||
{
|
||||
nfapi_nr_srs_indication_t ind;
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1604,8 +1602,8 @@ void vnf_handle_nr_uci_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_
|
||||
else
|
||||
{
|
||||
nfapi_nr_uci_indication_t ind;
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1631,8 +1629,8 @@ void vnf_handle_nr_rach_indication(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf
|
||||
else
|
||||
{
|
||||
nfapi_nr_rach_indication_t ind;
|
||||
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(ind), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Failed to unpack message\n", __FUNCTION__);
|
||||
}
|
||||
@@ -1661,7 +1659,8 @@ void vnf_nr_handle_ul_node_sync(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7
|
||||
}
|
||||
|
||||
nfapi_nr_ul_node_sync_t ind;
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(nfapi_nr_ul_node_sync_t), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(nfapi_nr_ul_node_sync_t), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Failed to unpack ul_node_sync\n");
|
||||
return;
|
||||
@@ -2096,7 +2095,8 @@ void vnf_nr_handle_timing_info(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
|
||||
}
|
||||
|
||||
nfapi_nr_timing_info_t ind;
|
||||
if(nfapi_nr_p7_message_unpack(pRecvMsg, recvMsgLen, &ind, sizeof(nfapi_timing_info_t), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.unpack_func(pRecvMsg, recvMsgLen, &ind, sizeof(nfapi_timing_info_t), &vnf_p7->_public.codec_config);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Failed to unpack timing_info\n");
|
||||
return;
|
||||
@@ -2232,7 +2232,8 @@ void vnf_nr_dispatch_p7_message(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7
|
||||
}
|
||||
|
||||
// unpack the message header
|
||||
if (nfapi_nr_p7_message_header_unpack(pRecvMsg, recvMsgLen, &header, sizeof(header), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.hdr_unpack_func(pRecvMsg, recvMsgLen, &header, sizeof(header), &vnf_p7->_public.codec_config);
|
||||
if (!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return;
|
||||
@@ -2429,7 +2430,8 @@ void vnf_nr_handle_p7_message(void *pRecvMsg, int recvMsgLen, vnf_p7_t* vnf_p7)
|
||||
}
|
||||
|
||||
// unpack the message header
|
||||
if (nfapi_nr_p7_message_header_unpack(pRecvMsg, recvMsgLen, &messageHeader, sizeof(nfapi_nr_p7_message_header_t), &vnf_p7->_public.codec_config) < 0)
|
||||
const bool result = vnf_p7->_public.hdr_unpack_func(pRecvMsg, recvMsgLen, &messageHeader, sizeof(nfapi_nr_p7_message_header_t), &vnf_p7->_public.codec_config);
|
||||
if (!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return;
|
||||
@@ -2552,7 +2554,8 @@ int vnf_nr_p7_read_dispatch_message(vnf_p7_t* vnf_p7)
|
||||
{
|
||||
// get the segment size
|
||||
nfapi_nr_p7_message_header_t header;
|
||||
if(nfapi_nr_p7_message_header_unpack(header_buffer, NFAPI_NR_P7_HEADER_LENGTH, &header, sizeof(header), 0) < 0)
|
||||
const bool result = vnf_p7->_public.hdr_unpack_func(header_buffer, NFAPI_NR_P7_HEADER_LENGTH, &header, sizeof(header), 0);
|
||||
if(!result)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unpack message header failed, ignoring\n");
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user