LTE and NR NFAPI integration
This commit is contained in:
+349
-20
@@ -102,7 +102,7 @@ nfapi_vnf_pnf_info_t* nfapi_vnf_pnf_list_find(nfapi_vnf_config_t* config, int p5
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
|
||||
void vnf_nr_handle_pnf_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -135,7 +135,7 @@ void vnf_nr_handle_pnf_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void vnf_handle_pnf_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -169,6 +169,40 @@ void vnf_handle_pnf_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_con
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void vnf_nr_handle_pnf_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || config == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received PNF_CONFIG_RESPONSE\n");
|
||||
|
||||
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)
|
||||
{
|
||||
// Invoke the call back
|
||||
if(config->pnf_nr_config_resp)
|
||||
{
|
||||
(config->pnf_nr_config_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// make sure to release any dyanmic part of the message
|
||||
if(msg.vendor_extension)
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_handle_pnf_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -202,6 +236,38 @@ void vnf_handle_pnf_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_co
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_nr_handle_pnf_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || config == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received PNF_START_RESPONSE\n");
|
||||
|
||||
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)
|
||||
{
|
||||
if(config->pnf_nr_start_resp)
|
||||
{
|
||||
(config->pnf_nr_start_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// make sure to release any dyanmic part of the message
|
||||
if(msg.vendor_extension)
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_handle_pnf_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
@@ -279,7 +345,7 @@ void vnf_handle_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received PARAM_RESPONSE\n");
|
||||
|
||||
nfapi_nr_param_response_scf_t msg;
|
||||
nfapi_param_response_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
@@ -333,6 +399,110 @@ void vnf_handle_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_nr_handle_param_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || config == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received PARAM_RESPONSE\n");
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
if (msg.error_code == NFAPI_MSG_OK)
|
||||
{
|
||||
nfapi_vnf_phy_info_t* phy_info = nfapi_vnf_phy_info_list_find(config, msg.header.phy_id);
|
||||
|
||||
if(msg.nfapi_config.p7_pnf_address_ipv4.tl.tag)
|
||||
{
|
||||
struct sockaddr_in sockAddr;
|
||||
|
||||
(void)memcpy(&sockAddr.sin_addr.s_addr, msg.nfapi_config.p7_pnf_address_ipv4.address, NFAPI_IPV4_ADDRESS_LENGTH);
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 IPv4 address: %s\n", inet_ntoa(sockAddr.sin_addr));
|
||||
|
||||
// store address
|
||||
phy_info->p7_pnf_address.sin_addr = sockAddr.sin_addr;
|
||||
}
|
||||
|
||||
if(msg.nfapi_config.p7_pnf_address_ipv6.tl.tag)
|
||||
{
|
||||
struct sockaddr_in6 sockAddr6;
|
||||
char addr6[64];
|
||||
(void)memcpy(&sockAddr6.sin6_addr, msg.nfapi_config.p7_pnf_address_ipv6.address, NFAPI_IPV6_ADDRESS_LENGTH);
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 IPv6 address: %s\n", inet_ntop(AF_INET6, &sockAddr6.sin6_addr, addr6, sizeof(addr6)));
|
||||
}
|
||||
|
||||
if (msg.nfapi_config.p7_pnf_port.tl.tag)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF P7 Port: %d\n", msg.nfapi_config.p7_pnf_port.value);
|
||||
|
||||
// store port
|
||||
phy_info->p7_pnf_address.sin_port = htons(msg.nfapi_config.p7_pnf_port.value);
|
||||
}
|
||||
}
|
||||
|
||||
if(config->nr_param_resp)
|
||||
{
|
||||
(config->nr_param_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// make sure to release any dyanmic part of the message
|
||||
if(msg.vendor_extension)
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void vnf_nr_handle_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || config == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received CONFIG_RESPONSE\n");
|
||||
|
||||
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 )
|
||||
{
|
||||
// check the error code:
|
||||
|
||||
if (msg.error_code == NFAPI_MSG_OK){
|
||||
if(config->nr_config_resp)
|
||||
{
|
||||
(config->nr_config_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// make sure to release any dyanmic part of the message
|
||||
if(msg.vendor_extension)
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_handle_config_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
|
||||
@@ -381,15 +551,47 @@ void vnf_handle_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received START_RESPONSE\n");
|
||||
|
||||
nfapi_nr_start_response_scf_t msg;
|
||||
nfapi_start_response_t msg;
|
||||
|
||||
// unpack the message
|
||||
if (nfapi_p5_message_unpack(pRecvMsg, recvMsgLen, &msg, sizeof(msg), &config->codec_config) >= 0)
|
||||
{
|
||||
if(config->start_resp)
|
||||
{
|
||||
(config->start_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: Unpack message failed, ignoring\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
// make sure to release any dyanmic part of the message
|
||||
if(msg.vendor_extension)
|
||||
config->codec_config.deallocate(msg.vendor_extension);
|
||||
}
|
||||
}
|
||||
|
||||
void vnf_nr_handle_start_response(void *pRecvMsg, int recvMsgLen, nfapi_vnf_config_t* config, int p5_idx)
|
||||
{
|
||||
// ensure it's valid
|
||||
if (pRecvMsg == NULL || config == NULL)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s: NULL parameters\n", __FUNCTION__);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received START_RESPONSE\n");
|
||||
|
||||
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)
|
||||
{ // check the error code
|
||||
if (msg.error_code == NFAPI_MSG_OK){
|
||||
if(config->start_resp)
|
||||
if(config->nr_start_resp)
|
||||
{
|
||||
(config->start_resp)(config, p5_idx, &msg);
|
||||
(config->nr_start_resp)(config, p5_idx, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -853,7 +1055,6 @@ void vnf_handle_vendor_extension(void* pRecvMsg, int recvMsgLen, nfapi_vnf_confi
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
void vnf_nr_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfapi_vnf_config_t* config)
|
||||
{
|
||||
nfapi_p4_p5_message_header_t messageHeader;
|
||||
@@ -874,32 +1075,32 @@ void vnf_nr_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfa
|
||||
|
||||
switch (messageHeader.message_id)
|
||||
{
|
||||
case NFAPI_PNF_PARAM_RESPONSE:
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_PARAM_RESPONSE:
|
||||
vnf_nr_handle_pnf_param_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_CONFIG_RESPONSE:
|
||||
vnf_handle_pnf_config_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_CONFIG_RESPONSE:
|
||||
vnf_nr_handle_pnf_config_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_START_RESPONSE:
|
||||
vnf_handle_pnf_start_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PNF_START_RESPONSE:
|
||||
vnf_nr_handle_pnf_start_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_PNF_STOP_RESPONSE:
|
||||
vnf_handle_pnf_stop_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_PARAM_RESPONSE:
|
||||
vnf_handle_param_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_PARAM_RESPONSE:
|
||||
vnf_nr_handle_param_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_CONFIG_RESPONSE:
|
||||
vnf_handle_config_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
case NFAPI_NR_PHY_MSG_TYPE_CONFIG_RESPONSE:
|
||||
vnf_nr_handle_config_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_START_RESPONSE:
|
||||
vnf_handle_start_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
vnf_nr_handle_start_response(pRecvMsg, recvMsgLen, config, p5_idx);
|
||||
break;
|
||||
|
||||
case NFAPI_STOP_RESPONSE:
|
||||
@@ -969,7 +1170,7 @@ void vnf_nr_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfa
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void vnf_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfapi_vnf_config_t* config)
|
||||
{
|
||||
nfapi_p4_p5_message_header_t messageHeader;
|
||||
@@ -1086,6 +1287,136 @@ void vnf_handle_p4_p5_message(void *pRecvMsg, int recvMsgLen, int p5_idx, nfapi_
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int vnf_nr_read_dispatch_message(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t* pnf)
|
||||
{
|
||||
if(1)
|
||||
{
|
||||
int socket_connected = 1;
|
||||
|
||||
// 1. Peek the message header
|
||||
// 2. If the message is larger than the stack buffer then create a dynamic buffer
|
||||
// 3. Read the buffer
|
||||
// 4. Handle the p5 message
|
||||
|
||||
uint32_t header_buffer_size = NFAPI_HEADER_LENGTH;
|
||||
uint8_t header_buffer[header_buffer_size];
|
||||
|
||||
uint32_t stack_buffer_size = 32; //should it be the size of then sctp_notificatoin structure
|
||||
uint8_t stack_buffer[stack_buffer_size];
|
||||
|
||||
uint8_t* dynamic_buffer = 0;
|
||||
|
||||
uint8_t* read_buffer = &stack_buffer[0];
|
||||
uint32_t message_size = 0;
|
||||
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addr_len = sizeof(addr);
|
||||
|
||||
struct sctp_sndrcvinfo sndrcvinfo;
|
||||
(void)memset(&sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
||||
|
||||
{
|
||||
int flags = MSG_PEEK;
|
||||
message_size = sctp_recvmsg(pnf->p5_sock, header_buffer, header_buffer_size, (struct sockaddr*)&addr, &addr_len, &sndrcvinfo, &flags);
|
||||
|
||||
if(message_size == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF Failed to peek sctp message size errno:%d\n", errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nfapi_p4_p5_message_header_t header;
|
||||
int unpack_result = nfapi_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);
|
||||
return 0;
|
||||
}
|
||||
message_size = header.message_length;
|
||||
|
||||
// now have the size of the mesage
|
||||
}
|
||||
|
||||
if(message_size > stack_buffer_size)
|
||||
{
|
||||
dynamic_buffer = (uint8_t*)malloc(message_size);
|
||||
|
||||
if(dynamic_buffer == NULL)
|
||||
{
|
||||
// todo : add error mesage
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "VNF Failed to allocate dynamic buffer for sctp_recvmsg size:%d\n", message_size);
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_buffer = dynamic_buffer;
|
||||
}
|
||||
|
||||
{
|
||||
int flags = 0;
|
||||
(void)memset(&sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo));
|
||||
|
||||
int recvmsg_result = sctp_recvmsg(pnf->p5_sock, read_buffer, message_size, (struct sockaddr*)&addr, &addr_len, &sndrcvinfo, &flags);
|
||||
if(recvmsg_result == -1)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Failed to read sctp message size errno:%d\n", errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (flags & MSG_NOTIFICATION)
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Notification received from %s:%u\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
|
||||
|
||||
// todo - handle the events
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
NFAPI_TRACE(NFAPI_TRACE_INFO, "Received message fd:%d from %s:%u assoc:%d on stream %d, PPID %d, length %d, flags 0x%x\n",
|
||||
pnf->p5_sock,
|
||||
inet_ntoa(addr.sin_addr),
|
||||
ntohs(addr.sin_port),
|
||||
sndrcvinfo.sinfo_assoc_id,
|
||||
sndrcvinfo.sinfo_stream,
|
||||
ntohl(sndrcvinfo.sinfo_ppid),
|
||||
message_size,
|
||||
flags);
|
||||
*/
|
||||
|
||||
// handle now if complete message in one or more segments
|
||||
if ((flags & 0x80) == 0x80)
|
||||
{
|
||||
printf("\nVNF RECEIVES:\n");
|
||||
for(int i=0; i<message_size; i++){
|
||||
printf("%d", read_buffer[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
vnf_nr_handle_p4_p5_message(read_buffer, message_size, pnf->p5_idx, config);
|
||||
}
|
||||
else
|
||||
{
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "sctp_recvmsg: unhandled mode with flags 0x%x\n", flags);
|
||||
|
||||
// assume socket disconnected
|
||||
NFAPI_TRACE(NFAPI_TRACE_WARN, "Disconnected socket\n");
|
||||
socket_connected = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(dynamic_buffer)
|
||||
{
|
||||
free(dynamic_buffer);
|
||||
}
|
||||
|
||||
return socket_connected;
|
||||
}
|
||||
}
|
||||
|
||||
int vnf_read_dispatch_message(nfapi_vnf_config_t* config, nfapi_vnf_pnf_info_t* pnf)
|
||||
{
|
||||
if(1)
|
||||
@@ -1243,7 +1574,6 @@ static int vnf_send_p5_msg(nfapi_vnf_pnf_info_t* pnf, const void *msg, int len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int vnf_nr_pack_and_send_p5_message(vnf_t* vnf, uint16_t p5_idx, nfapi_p4_p5_message_header_t* msg, uint16_t msg_len)
|
||||
{
|
||||
nfapi_vnf_pnf_info_t* pnf = nfapi_vnf_pnf_list_find(&(vnf->_public), p5_idx);
|
||||
@@ -1266,7 +1596,6 @@ int vnf_nr_pack_and_send_p5_message(vnf_t* vnf, uint16_t p5_idx, nfapi_p4_p5_mes
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
int vnf_pack_and_send_p5_message(vnf_t* vnf, uint16_t p5_idx, nfapi_p4_p5_message_header_t* msg, uint16_t msg_len)
|
||||
|
||||
Reference in New Issue
Block a user