Commit e272dd89 authored by Robert Schmidt's avatar Robert Schmidt

Merge remote-tracking branch 'origin/Fix_FAPI_PARAM_and_CONFIG_messages' into integration_2023_w37

parents 59ad0942 09d7487d
......@@ -185,9 +185,12 @@ rfsim4g_enb_nos1:
l2sim5g_ue:
Host: localhost
AttachScript: docker start l2sim-oai-nr-ue0
DetachScript: docker stop l2sim-oai-nr-ue0
NetworkScript: docker exec l2sim-oai-nr-ue0 ip a show dev oaitun_ue1
CmdPrefix: docker exec l2sim-oai-nr-ue0
IF: oaitun_ue1
MTU: 1500
l2sim5g_ext_dn:
Host: localhost
......@@ -196,9 +199,12 @@ l2sim5g_ext_dn:
l2sim4g_ue:
Host: localhost
AttachScript: docker start l2sim4g-oai-lte-ue1
DetachScript: docker stop l2sim4g-oai-lte-ue1
NetworkScript: docker exec l2sim4g-oai-lte-ue1 ip a show dev oaitun_ue1
CmdPrefix: docker exec l2sim4g-oai-lte-ue1
IF: oaitun_ue1
MTU: 1500
l2sim4g_ext_dn:
Host: localhost
......
......@@ -519,6 +519,7 @@ class OaiCiTest():
ping_cmd = f'{ue.getCmdPrefix()} ping {interface} {self.ping_args} 2>&1 | tee /tmp/{ping_log_file}'
cmd = cls_cmd.getConnection(ue.getHost())
response = cmd.run(ping_cmd, timeout=int(ping_time[0])*1.5)
ue_header = f'UE {ue.getName()} ({ueIP})'
if response.returncode != 0:
message = ue_header + ': ping crashed: TIMEOUT?'
logging.error('\u001B[1;37;41m ' + message + ' \u001B[0m')
......@@ -528,7 +529,6 @@ class OaiCiTest():
cmd.copyin(src=f'/tmp/{ping_log_file}', tgt=local_ping_log_file)
cmd.close()
ue_header = f'UE {ue.getName()} ({ueIP})'
with open(local_ping_log_file, 'r') as f:
ping_output = "".join(f.readlines())
result = re.search(', (?P<packetloss>[0-9\.]+)% packet loss, time [0-9\.]+ms', ping_output)
......
......@@ -36,7 +36,7 @@
<eNB_instance>1</eNB_instance>
<eNB_serverId>1</eNB_serverId>
<forced_workspace_cleanup>True</forced_workspace_cleanup>
<proxy_commit>a2fa216</proxy_commit>
<proxy_commit>f390610304baf6b66e4ec8cc00bf91398a651172</proxy_commit>
</testCase>
</testCaseList>
......@@ -32,7 +32,7 @@
000001
000002
000003
000011
000004
200000
020001
020002
......@@ -82,10 +82,10 @@
<nb_healthy>10</nb_healthy>
</testCase>
<testCase id="000011">
<class>IdleSleep</class>
<desc>Sleep</desc>
<idle_sleep_time_in_sec>10</idle_sleep_time_in_sec>
<testCase id="000004">
<class>Attach_UE</class>
<desc>Attach OAI UE</desc>
<id>l2sim4g_ue</id>
</testCase>
<testCase id="020001">
......
......@@ -32,7 +32,7 @@
000001
000002
000003
000011
000004
200000
020001
020002
......@@ -80,10 +80,10 @@
<nb_healthy>9</nb_healthy>
</testCase>
<testCase id="000011">
<class>IdleSleep</class>
<desc>Sleep</desc>
<idle_sleep_time_in_sec>10</idle_sleep_time_in_sec>
<testCase id="000004">
<class>Attach_UE</class>
<desc>Attach OAI UE</desc>
<id>l2sim5g_ue</id>
</testCase>
<testCase id="020001">
......
......@@ -36,7 +36,7 @@
<eNB_instance>1</eNB_instance>
<eNB_serverId>1</eNB_serverId>
<forced_workspace_cleanup>True</forced_workspace_cleanup>
<proxy_commit>a2fa216</proxy_commit>
<proxy_commit>f390610304baf6b66e4ec8cc00bf91398a651172</proxy_commit>
</testCase>
</testCaseList>
......@@ -250,7 +250,8 @@ void *pnf_nr_p7_thread_start(void *ptr) {
return 0;
}
int pnf_nr_param_request(nfapi_pnf_config_t *config, nfapi_nr_pnf_param_request_t *req) {
int pnf_nr_param_request(nfapi_pnf_config_t *config, nfapi_nr_pnf_param_request_t *req)
{
printf("[PNF] pnf param request\n");
nfapi_nr_pnf_param_response_t resp;
memset(&resp, 0, sizeof(resp));
......@@ -271,10 +272,11 @@ int pnf_nr_param_request(nfapi_pnf_config_t *config, nfapi_nr_pnf_param_request_
resp.pnf_param_general.shared_bands = pnf->shared_bands;
resp.pnf_param_general.shared_pa = pnf->shared_pa;
resp.pnf_param_general.maximum_total_power = pnf->max_total_power;
resp.num_tlvs = 1;
resp.pnf_phy.tl.tag = NFAPI_PNF_PHY_TAG;
resp.pnf_phy.number_of_phys = 1;
for(int i = 0; i < 1; ++i) {
for (int i = 0; i < 1; ++i) {
resp.pnf_phy.phy[i].phy_config_index = pnf->phys[i].index;
resp.pnf_phy.phy[i].downlink_channel_bandwidth_supported = pnf->phys[i].dl_channel_bw_support;
resp.pnf_phy.phy[i].uplink_channel_bandwidth_supported = pnf->phys[i].ul_channel_bw_support;
......@@ -284,21 +286,21 @@ int pnf_nr_param_request(nfapi_pnf_config_t *config, nfapi_nr_pnf_param_request_
resp.pnf_phy.phy[i].nmm_modes_supported = pnf->phys[i].nmm_modes_supported;
resp.pnf_phy.phy[i].number_of_rfs = 2;
for(int j = 0; j < 1; ++j) {
for (int j = 0; j < 1; ++j) {
resp.pnf_phy.phy[i].rf_config[j].rf_config_index = pnf->phys[i].rfs[j];
}
resp.pnf_phy.phy[i].number_of_rf_exclusions = 0;
for(int j = 0; j < 0; ++j) {
for (int j = 0; j < 0; ++j) {
resp.pnf_phy.phy[i].excluded_rf_config[j].rf_config_index = pnf->phys[i].excluded_rfs[j];
}
resp.num_tlvs++;
}
nfapi_nr_pnf_pnf_param_resp(config, &resp);
return 0;
}
int pnf_param_request(nfapi_pnf_config_t *config, nfapi_pnf_param_request_t *req) {
printf("[PNF] pnf param request\n");
nfapi_pnf_param_response_t resp;
......@@ -989,33 +991,35 @@ int config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfap
return 0;
}
int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi_nr_config_request_scf_t *req)
int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nfapi_nr_config_request_scf_t *req)
{
printf("[PNF] Received NFAPI_CONFIG_REQ phy_id:%d\n", req->header.phy_id);
pnf_info *pnf = (pnf_info *)(config->user_data);
uint8_t num_tlv = 0;
//struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
// In the case of nfapi_mode = 3 (UE = PNF) we should not have dependency on any eNB var. So we aim
// to keep only the necessary just to keep the nfapi FSM rolling by sending a dummy response.
// struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
// In the case of nfapi_mode = 3 (UE = PNF) we should not have dependency on any eNB var. So we aim
// to keep only the necessary just to keep the nfapi FSM rolling by sending a dummy response.
NR_DL_FRAME_PARMS *fp;
if (NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
if (NFAPI_MODE != NFAPI_UE_STUB_PNF) {
struct PHY_VARS_gNB_s *gNB = RC.gNB[0];
fp = &gNB->frame_parms;
} else {
fp = (NR_DL_FRAME_PARMS *) malloc(sizeof(NR_DL_FRAME_PARMS));
fp = (NR_DL_FRAME_PARMS *)malloc(sizeof(NR_DL_FRAME_PARMS));
}
phy_info *phy_info = pnf->phys;
printf("\nTiming window tag: %d\n",NFAPI_NR_NFAPI_TIMING_WINDOW_TAG);
if(req->nfapi_config.timing_window.tl.tag == NFAPI_NR_NFAPI_TIMING_WINDOW_TAG) {
printf("\nTiming window tag: %d\n", NFAPI_NR_NFAPI_TIMING_WINDOW_TAG);
if (req->nfapi_config.timing_window.tl.tag == NFAPI_NR_NFAPI_TIMING_WINDOW_TAG) {
phy_info->timing_window = req->nfapi_config.timing_window.value;
printf("Phy_info:Timing window:%u NFAPI_CONFIG:timing_window:%u\n", phy_info->timing_window, req->nfapi_config.timing_window.value);
printf("Phy_info:Timing window:%u NFAPI_CONFIG:timing_window:%u\n",
phy_info->timing_window,
req->nfapi_config.timing_window.value);
num_tlv++;
}
if(req->nfapi_config.timing_info_mode.tl.tag == NFAPI_NR_NFAPI_TIMING_INFO_MODE_TAG) {
if (req->nfapi_config.timing_info_mode.tl.tag == NFAPI_NR_NFAPI_TIMING_INFO_MODE_TAG) {
printf("timing info mode:%d\n", req->nfapi_config.timing_info_mode.value);
phy_info->timing_info_mode = req->nfapi_config.timing_info_mode.value;
num_tlv++;
......@@ -1023,8 +1027,8 @@ int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, n
phy_info->timing_info_mode = 0;
printf("NO timing info mode provided\n");
}
//TODO: Read the P7 message offset values
if(req->nfapi_config.timing_info_period.tl.tag == NFAPI_NR_NFAPI_TIMING_INFO_PERIOD_TAG) {
// TODO: Read the P7 message offset values
if (req->nfapi_config.timing_info_period.tl.tag == NFAPI_NR_NFAPI_TIMING_INFO_PERIOD_TAG) {
printf("timing info period provided value:%d\n", req->nfapi_config.timing_info_period.value);
phy_info->timing_info_period = req->nfapi_config.timing_info_period.value;
num_tlv++;
......@@ -1032,18 +1036,18 @@ int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, n
phy_info->timing_info_period = 0;
}
if(req->carrier_config.dl_bandwidth.tl.tag == NFAPI_NR_CONFIG_DL_BANDWIDTH_TAG) {
phy_info->dl_channel_bw_support = req->carrier_config.dl_bandwidth.value; //rf_config.dl_channel_bandwidth.value;
fp->N_RB_DL = req->carrier_config.dl_bandwidth.value; //rf_config.dl_channel_bandwidth.value;
if (req->carrier_config.dl_bandwidth.tl.tag == NFAPI_NR_CONFIG_DL_BANDWIDTH_TAG) {
phy_info->dl_channel_bw_support = req->carrier_config.dl_bandwidth.value; // rf_config.dl_channel_bandwidth.value;
fp->N_RB_DL = req->carrier_config.dl_bandwidth.value; // rf_config.dl_channel_bandwidth.value;
num_tlv++;
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() NFAPI_NR_CONFIG_DL_BANDWIDTH_TAG N_RB_DL:%u\n", __FUNCTION__, fp->N_RB_DL);
} else {
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() Missing NFAPI_NR_CONFIG_DL_BANDWIDTH_TAG\n", __FUNCTION__);
}
if(req->carrier_config.uplink_bandwidth.tl.tag == NFAPI_NR_CONFIG_UPLINK_BANDWIDTH_TAG) {
phy_info->ul_channel_bw_support = req->carrier_config.uplink_bandwidth.value; //req->rf_config.ul_channel_bandwidth.value;
fp->N_RB_UL = req->carrier_config.uplink_bandwidth.value; //req->rf_config.ul_channel_bandwidth.value;
if (req->carrier_config.uplink_bandwidth.tl.tag == NFAPI_NR_CONFIG_UPLINK_BANDWIDTH_TAG) {
phy_info->ul_channel_bw_support = req->carrier_config.uplink_bandwidth.value; // req->rf_config.ul_channel_bandwidth.value;
fp->N_RB_UL = req->carrier_config.uplink_bandwidth.value; // req->rf_config.ul_channel_bandwidth.value;
num_tlv++;
}
......@@ -1052,12 +1056,12 @@ int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, n
num_tlv++;
}
if(NFAPI_MODE!=NFAPI_UE_STUB_PNF) {
if (NFAPI_MODE != NFAPI_UE_STUB_PNF) {
printf("[PNF] CONFIG_REQUEST[num_tlv:%d] TLVs processed:%d\n", req->num_tlv, num_tlv);
printf("[PNF] Simulating PHY CONFIG\n");
NR_PHY_Config_t nr_phy_config;
nr_phy_config.Mod_id = 0;
nr_phy_config.CC_id=0;
nr_phy_config.CC_id = 0;
nr_phy_config.cfg = req;
nr_phy_config_request(&nr_phy_config);
nr_dump_frame_parms(fp);
......@@ -1066,19 +1070,28 @@ int nr_config_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, n
struct sockaddr_in vnf_p7_sockaddr;
memcpy(&vnf_p7_sockaddr.sin_addr.s_addr, &(req->nfapi_config.p7_vnf_address_ipv4.address[0]), 4);
phy_info->remote_addr = inet_ntoa(vnf_p7_sockaddr.sin_addr);
printf("[PNF] %d vnf p7 %s:%d timing %d %d %d\n", phy_info->id, phy_info->remote_addr, phy_info->remote_port,
phy_info->timing_window, phy_info->timing_info_mode, phy_info->timing_info_period);
printf("[PNF] %d vnf p7 %s:%d timing %d %d %d\n",
phy_info->id,
phy_info->remote_addr,
phy_info->remote_port,
phy_info->timing_window,
phy_info->timing_info_mode,
phy_info->timing_info_period);
nfapi_nr_config_response_scf_t nfapi_resp;
memset(&nfapi_resp, 0, sizeof(nfapi_resp));
nfapi_resp.header.message_id = NFAPI_NR_PHY_MSG_TYPE_CONFIG_RESPONSE;
nfapi_resp.header.phy_id = phy_info->id;
nfapi_resp.error_code = 0;
nfapi_resp.num_invalid_tlvs = 0;
nfapi_resp.num_invalid_tlvs_configured_in_idle = 0;
nfapi_resp.num_invalid_tlvs_configured_in_running = 0;
nfapi_resp.num_missing_tlvs = 0;
nfapi_nr_pnf_config_resp(config, &nfapi_resp);
printf("[PNF] Sent NFAPI_PNF_CONFIG_RESPONSE phy_id:%d\n", phy_info->id);
if(NFAPI_MODE==NFAPI_UE_STUB_PNF)
if (NFAPI_MODE == NFAPI_UE_STUB_PNF)
free(fp);
return 0;
}
......
/*
* Copyright 2017 Cisco Systems, Inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -14,7 +14,6 @@
* limitations under the License.
*/
#ifndef _NFAPI_H_
#define _NFAPI_H_
......@@ -40,7 +39,6 @@ uint8_t pulls16(uint8_t **in, int16_t *out, uint8_t *end);
uint8_t pull32(uint8_t **in, uint32_t *out, uint8_t *end);
uint8_t pulls32(uint8_t **in, int32_t *out, uint8_t *end);
uint32_t pullarray8(uint8_t **in, uint8_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pullarray16(uint8_t **in, uint16_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
uint32_t pullarrays16(uint8_t **in, int16_t out[], uint32_t max_len, uint32_t len, uint8_t *end);
......@@ -61,40 +59,79 @@ uint32_t pusharray32(const uint32_t *values_to_push,
uint8_t *out_end);
uint32_t pusharrays32(int32_t in[], uint32_t max_len, uint32_t len, uint8_t **out, uint8_t *end);
typedef uint8_t (*pack_array_elem_fn)(void* elem, uint8_t **ppWritePackedMsg, uint8_t *end);
uint8_t packarray(void* array, uint16_t elem_size, uint16_t max_count, uint16_t count, uint8_t **ppWritePackedMsg, uint8_t *end, pack_array_elem_fn fn);
typedef uint8_t (*unpack_array_elem_fn)(void* elem, uint8_t **ppReadPackedMsg, uint8_t *end);
uint8_t unpackarray(uint8_t **ppReadPackedMsg, void* array, uint16_t elem_size, uint16_t max_count, uint16_t count, uint8_t *end, unpack_array_elem_fn fn);
typedef uint8_t (*pack_array_elem_fn)(void *elem, uint8_t **ppWritePackedMsg, uint8_t *end);
uint8_t packarray(void *array,
uint16_t elem_size,
uint16_t max_count,
uint16_t count,
uint8_t **ppWritePackedMsg,
uint8_t *end,
pack_array_elem_fn fn);
typedef uint8_t (*unpack_array_elem_fn)(void *elem, uint8_t **ppReadPackedMsg, uint8_t *end);
uint8_t unpackarray(uint8_t **ppReadPackedMsg,
void *array,
uint16_t elem_size,
uint16_t max_count,
uint16_t count,
uint8_t *end,
unpack_array_elem_fn fn);
uint8_t pack_tl(nfapi_tl_t *tl, uint8_t **ppWritePackedMsg, uint8_t *end);
uint8_t unpack_tl(uint8_t **ppReadPackedMsg, nfapi_tl_t *tl, uint8_t *end);
typedef uint8_t (*pack_tlv_fn)(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end);
typedef uint8_t (*pack_tlv_fn)(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end);
uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn);
uint32_t pack_vendor_extension_tlv(nfapi_tl_t* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* config);
int unpack_vendor_extension(nfapi_tl_t* tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* config, nfapi_tl_t** ve_tlv);
typedef uint8_t (*unpack_tlv_fn)(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end);
typedef struct
{
uint16_t tag;
void* tlv;
unpack_tlv_fn unpack_func;
uint8_t pack_nr_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn);
uint32_t pack_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config);
int unpack_vendor_extension_tlv(nfapi_tl_t *tl,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p4_p5_codec_config_t *config,
nfapi_tl_t **ve_tlv);
uint8_t get_tlv_padding(uint16_t tlv_length);
typedef uint8_t (*unpack_tlv_fn)(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end);
typedef struct {
uint16_t tag;
void *tlv;
unpack_tlv_fn unpack_func;
} unpack_tlv_t;
int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t* packedMsgEnd, nfapi_p4_p5_codec_config_t* config, nfapi_tl_t** ve);
uint32_t pack_p7_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config);
typedef uint8_t (*unpack_p7_tlv_fn)(void* tlv, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t*);
typedef struct
{
uint16_t tag;
void* tlv;
unpack_p7_tlv_fn unpack_func;
int unpack_tlv_list(unpack_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *packedMsgEnd,
nfapi_p4_p5_codec_config_t *config,
nfapi_tl_t **ve);
int unpack_nr_tlv_list(unpack_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *packedMsgEnd,
nfapi_p4_p5_codec_config_t *config,
nfapi_tl_t **ve);
uint32_t pack_p7_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config);
typedef uint8_t (*unpack_p7_tlv_fn)(void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *);
typedef struct {
uint16_t tag;
void *tlv;
unpack_p7_tlv_fn unpack_func;
} unpack_p7_tlv_t;
int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t* packedMsgEnd, nfapi_p7_codec_config_t* config, nfapi_tl_t** ve);
int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *packedMsgEnd,
nfapi_p7_codec_config_t *config,
nfapi_tl_t **ve);
int unpack_nr_p7_tlv_list(unpack_p7_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *packedMsgEnd,
nfapi_p7_codec_config_t *config,
nfapi_tl_t **ve);
#if defined(__cplusplus)
}
......
......@@ -292,8 +292,8 @@ typedef enum {
} nfapi_nr_ssb_and_cset_mux_pattern_type_e;
typedef enum {
NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED=0,
NFAPI_NR_CCE_REG_MAPPING_NON_INTERLEAVED=1
NFAPI_NR_CCE_REG_MAPPING_INTERLEAVED=1,
NFAPI_NR_CCE_REG_MAPPING_NON_INTERLEAVED=0
} nfapi_nr_cce_reg_mapping_type_e;
typedef enum {
......
......@@ -474,7 +474,8 @@ typedef struct {
typedef struct {
nfapi_p4_p5_message_header_t header;
uint32_t error_code;
uint8_t error_code;
uint8_t num_tlvs;
nfapi_pnf_param_general_t pnf_param_general;
nfapi_pnf_phy_t pnf_phy;
nfapi_vendor_extension_tlv_t vendor_extension;
......@@ -489,7 +490,7 @@ typedef struct {
typedef struct {
nfapi_p4_p5_message_header_t header;
uint32_t error_code;
uint8_t error_code;
nfapi_vendor_extension_tlv_t vendor_extension;
} nfapi_nr_pnf_config_response_t;
......@@ -566,7 +567,10 @@ typedef struct {
typedef struct {
nfapi_p4_p5_message_header_t header;
uint8_t error_code;
//uint8_t num_invalid_tlvs;
uint8_t num_invalid_tlvs;
uint8_t num_invalid_tlvs_configured_in_idle;
uint8_t num_invalid_tlvs_configured_in_running;
uint8_t num_missing_tlvs;
// TODO: add list of invalid/unsupported TLVs (see Table 3.18)
nfapi_vendor_extension_tlv_t vendor_extension;
} nfapi_nr_config_response_scf_t;
......
......@@ -567,9 +567,14 @@ uint32_t pack_vendor_extension_tlv(nfapi_tl_t *ve, uint8_t **ppWritePackedMsg, u
return 1;
}
uint32_t unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config, nfapi_tl_t **ve_tlv) {
if(ve_tlv != 0 && config != 0) {
if(config->unpack_vendor_extension_tlv) {
int unpack_vendor_extension_tlv(nfapi_tl_t *tl,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p4_p5_codec_config_t *config,
nfapi_tl_t **ve_tlv)
{
if (ve_tlv != 0 && config != 0) {
if (config->unpack_vendor_extension_tlv) {
return (config->unpack_vendor_extension_tlv)(tl, ppReadPackedMsg, end, (void **)ve_tlv, config);
}
}
......@@ -702,6 +707,104 @@ int unpack_tlv_list(unpack_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPa
return 1;
}
int unpack_nr_tlv_list(unpack_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p4_p5_codec_config_t *config,
nfapi_tl_t **ve)
{
nfapi_tl_t generic_tl;
uint8_t numBadTags = 0;
uint16_t idx = 0;
while ((uint8_t *)(*ppReadPackedMsg) < end) {
// unpack the tl and process the values accordingly
if (unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
return 0;
uint8_t tagMatch = 0;
uint8_t *pStartOfValue = *ppReadPackedMsg;
for (idx = 0; idx < size; ++idx) {
if (unpack_fns[idx].tag == generic_tl.tag) { // match the extracted tag value with all the tags in unpack_fn list
tagMatch = 1;
nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
tl->tag = generic_tl.tag;
tl->length = generic_tl.length;
int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end);
if (result == 0) {
return 0;
}
// check if the length was right;
if (tl->length != (*ppReadPackedMsg - pStartOfValue)) {
NFAPI_TRACE(NFAPI_TRACE_ERROR,
"Warning tlv tag 0x%x length %d not equal to unpack %ld\n",
tl->tag,
tl->length,
(*ppReadPackedMsg - pStartOfValue));
on_error();
}
// Remove padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = get_tlv_padding(tl->length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
}
}
if (tagMatch == 0) {
if (generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE && generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
int result = unpack_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
if (result == 0) {
// got tot the end.
return 0;
} else if (result < 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown VE TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return 0;
}
if ((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// go to the end
return 0;
}
}
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return 0;
}
if ((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// go to the end
return 0;
}
}
}
}
return 1;
}
int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **ppReadPackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config, nfapi_tl_t **ve) {
nfapi_tl_t generic_tl;
uint8_t numBadTags = 0;
......@@ -785,6 +888,103 @@ int unpack_p7_tlv_list(unpack_p7_tlv_t unpack_fns[], uint16_t size, uint8_t **pp
return 1;
}
int unpack_nr_p7_tlv_list(unpack_p7_tlv_t unpack_fns[],
uint16_t size,
uint8_t **ppReadPackedMsg,
uint8_t *end,
nfapi_p7_codec_config_t *config,
nfapi_tl_t **ve)
{
nfapi_tl_t generic_tl;
uint8_t numBadTags = 0;
uint16_t idx = 0;
while ((uint8_t *)(*ppReadPackedMsg) < end) {
// unpack the tl and process the values accordingly
if (unpack_tl(ppReadPackedMsg, &generic_tl, end) == 0)
return 0;
uint8_t tagMatch = 0;
uint8_t *pStartOfValue = *ppReadPackedMsg;
for (idx = 0; idx < size; ++idx) {
if (unpack_fns[idx].tag == generic_tl.tag) {
tagMatch = 1;
nfapi_tl_t *tl = (nfapi_tl_t *)(unpack_fns[idx].tlv);
tl->tag = generic_tl.tag;
tl->length = generic_tl.length;
int result = (*unpack_fns[idx].unpack_func)(tl, ppReadPackedMsg, end, config);
if (result == 0) {
return 0;
}
// check if the length was right;
if (tl->length != (*ppReadPackedMsg - pStartOfValue)) {
NFAPI_TRACE(NFAPI_TRACE_ERROR,
"Warning tlv tag 0x%x length %d not equal to unpack %ld\n",
tl->tag,
tl->length,
(*ppReadPackedMsg - pStartOfValue));
on_error();
}
// Remove padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = get_tlv_padding(tl->length);
if (padding != 0) {
(*ppReadPackedMsg) += padding;
}
}
}
if (tagMatch == 0) {
if (generic_tl.tag >= NFAPI_VENDOR_EXTENSION_MIN_TAG_VALUE && generic_tl.tag <= NFAPI_VENDOR_EXTENSION_MAX_TAG_VALUE) {
int result = unpack_p7_vendor_extension_tlv(&generic_tl, ppReadPackedMsg, end, config, ve);
if (result == 0) {
// got to end
return 0;
} else if (result < 0) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return -1;
}
if ((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// got ot the dn
return 0;
}
}
} else {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unknown TAG value: 0x%04x\n", generic_tl.tag);
on_error();
if (++numBadTags > MAX_BAD_TAG) {
NFAPI_TRACE(NFAPI_TRACE_ERROR, "Supplied message has had too many bad tags\n");
on_error();
return -1;
}
if ((end - *ppReadPackedMsg) >= generic_tl.length) {
// Advance past the unknown TLV
(*ppReadPackedMsg) += generic_tl.length + get_tlv_padding(generic_tl.length);
} else {
// got ot the dn
return 0;
}
}
}
}
return 1;
}
// This intermediate function deals with calculating the length of the value
// and writing into the tlv header.
uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn) {
......@@ -820,6 +1020,47 @@ uint8_t pack_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *e
return 1;
}
uint8_t pack_nr_tlv(uint16_t tag, void *tlv, uint8_t **ppWritePackedMsg, uint8_t *end, pack_tlv_fn fn)
{
nfapi_tl_t *tl = (nfapi_tl_t *)tlv;
// If the tag is defined
if (tl->tag == tag) {
uint8_t *pStartOfTlv = *ppWritePackedMsg;
// write a dumy tlv header
if (pack_tl(tl, ppWritePackedMsg, end) == 0)
return 0;
// Record the start of the value
uint8_t *pStartOfValue = *ppWritePackedMsg;
// pack the tlv value
if (fn(tlv, ppWritePackedMsg, end) == 0)
return 0;
// calculate the length of the value and rewrite the tl header
tl->length = (*ppWritePackedMsg) - pStartOfValue;
// rewrite the header with the correct length
pack_tl(tl, &pStartOfTlv, end);
// Add padding that ensures multiple of 4 bytes (SCF 225 Section 2.3.2.1)
int padding = get_tlv_padding(tl->length);
NFAPI_TRACE(NFAPI_TRACE_DEBUG, "TLV 0x%x with padding of %d bytes\n", tl->tag, padding);
if (padding != 0) {
memset(*ppWritePackedMsg, 0, padding);
(*ppWritePackedMsg) += padding;
}
} else {
if (tl->tag != 0) {
NFAPI_TRACE(NFAPI_TRACE_WARN, "Warning pack_tlv tag 0x%x does not match expected 0x%x\n", tl->tag, tag);
} else {
// NFAPI_TRACE(NFAPI_TRACE_ERROR, "Warning pack_tlv tag 0x%x ZERO does not match expected 0x%x\n", tl->tag, tag);
}
}
return 1;
}
const char *nfapi_error_code_to_str(nfapi_error_code_e value) {
switch(value) {
case NFAPI_MSG_OK:
......@@ -853,3 +1094,8 @@ const char *nfapi_error_code_to_str(nfapi_error_code_e value) {
return "UNKNOWN";
}
}
uint8_t get_tlv_padding(uint16_t tlv_length)
{
return (4 - (tlv_length % 4)) % 4;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -2131,77 +2131,77 @@ int pnf_read_dispatch_message(pnf_t* pnf)
int pnf_nr_read_dispatch_message(pnf_t* pnf)
{
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*/ 0, 0, &sndrcvinfo, &flags);
if(message_size == -1)
{
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF 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, "PNF Failed to unpack p5 message header\n");
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, "PNF 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
{
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*/ 0,
0,
&sndrcvinfo,
&flags);
if (message_size == -1) {
NFAPI_TRACE(NFAPI_TRACE_INFO, "PNF 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, "PNF Failed to unpack p5 message header\n");
return 0;
}
message_size = header.message_length + header_buffer_size;
// 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, "PNF 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 0
// print the received message
printf("\n MESSAGE RECEIVED: \n");
......@@ -2211,56 +2211,44 @@ int pnf_nr_read_dispatch_message(pnf_t* pnf)
printf("\n");
#endif
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)
{
pnf_nr_handle_p5_message(pnf, read_buffer, message_size);
}
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;
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) {
pnf_nr_handle_p5_message(pnf, read_buffer, message_size);
} 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 pnf_message_pump(pnf_t* pnf)
{
uint8_t socketConnected = 1;
......
......@@ -1240,134 +1240,118 @@ 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;
}
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 + header_buffer_size;
// 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)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment