Skip to content

Commit

Permalink
Better dp_get_vnf_entry() handling
Browse files Browse the repository at this point in the history
Signed-off-by: Guvenc Gulce <[email protected]>
  • Loading branch information
guvenc committed Aug 1, 2023
1 parent 8f042c3 commit 39976c9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
6 changes: 3 additions & 3 deletions include/dp_vnf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ extern "C" {
#endif

#define DP_VNF_MAX_TABLE_SIZE 1000
#define DP_VNF_MATCH_ALL_PORT_ID 0xFFFF
#define DP_VNF_MATCH_ALL_PORT_ID_VALUE 0xFFFF
#define DP_VNF_MATCH_ALL_PORT_ID true

enum vnf_type {
DP_VNF_TYPE_UNDEFINED,
Expand Down Expand Up @@ -43,8 +44,7 @@ int dp_get_portid_with_vnf_key(void *key, enum vnf_type v_type);
int dp_del_vnf_with_vnf_key(void *key);
int dp_del_vnf_with_value(struct dp_vnf_value *val);
int dp_find_vnf_with_value(struct dp_vnf_value *val);
int dp_get_vnf_entry(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid);
int dp_get_vnf_entry_match_all_port_ids(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid);
int dp_get_vnf_entry(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid, bool match_all);
int dp_list_vnf_alias_routes(uint16_t portid, enum vnf_type v_type, struct dp_grpc_responder *responder);

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/dp_cntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static __rte_always_inline struct flow_value *flow_table_insert_entry(struct flo
/* This will be an uni-directional traffic. So prepare the flag to offload immediately */
if (dp_conf_is_offload_enabled()
&& (df->flags.flow_type != DP_FLOW_TYPE_INCOMING)
&& !DP_FAILED(dp_get_vnf_entry_match_all_port_ids(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, m->port))
&& !DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, m->port, DP_VNF_MATCH_ALL_PORT_ID))
)
flow_val->nf_info.nat_type = DP_FLOW_LB_TYPE_LOCAL_NEIGH_TRAFFIC;
else
Expand Down
5 changes: 3 additions & 2 deletions src/dp_flow.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static __rte_always_inline void dp_mark_vnf_type(struct dp_flow *df, struct flow
s_data = dp_get_vm_snat_data(key->ip_src, key->vni);
if (s_data && s_data->network_nat_ip != 0)
key->vnf = (uint8_t)DP_VNF_TYPE_NAT;
else if (!DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, port)))
else if (!DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, port, !DP_VNF_MATCH_ALL_PORT_ID)))
key->vnf = (uint8_t)DP_VNF_TYPE_LB_ALIAS_PFX;
else
key->vnf = (uint8_t)DP_VNF_TYPE_UNDEFINED;
Expand Down Expand Up @@ -222,11 +222,12 @@ int dp_get_flow_data(struct flow_key *key, void **data)
if (DP_FAILED(result))
*data = NULL;

#ifdef ENABLE_PYTEST
if (*data != NULL)
DPS_LOG_DEBUG("Successfully found data in flow table", DP_LOG_FLOW_KEY(key));
else
DPS_LOG_DEBUG("Cannot find data in flow table", DP_LOG_FLOW_KEY(key));

#endif
return result;
}

Expand Down
14 changes: 3 additions & 11 deletions src/dp_vnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,10 @@ int dp_set_vnf_value(void *key, struct dp_vnf_value *val)
return DP_ERROR;
}

int dp_get_vnf_entry_match_all_port_ids(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid)
int dp_get_vnf_entry(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid, bool match_all)
{
val->v_type = v_type;
val->portid = DP_VNF_MATCH_ALL_PORT_ID;
val->vni = dp_get_vm_vni(portid);
return dp_find_vnf_with_value(val);
}

int dp_get_vnf_entry(struct dp_vnf_value *val, enum vnf_type v_type, uint16_t portid)
{
val->v_type = v_type;
val->portid = portid;
val->portid = match_all ? DP_VNF_MATCH_ALL_PORT_ID_VALUE : portid;
val->vni = dp_get_vm_vni(portid);
return dp_find_vnf_with_value(val);
}
Expand Down Expand Up @@ -116,7 +108,7 @@ int dp_del_vnf_with_vnf_key(void *key)

static __rte_always_inline bool dp_vnf_equal(struct dp_vnf_value *val1, struct dp_vnf_value *val2)
{
return ((val1->portid == DP_VNF_MATCH_ALL_PORT_ID) || (val1->portid == val2->portid))
return ((val1->portid == DP_VNF_MATCH_ALL_PORT_ID_VALUE) || (val1->portid == val2->portid))
&& val1->alias_pfx.ip == val2->alias_pfx.ip
&& val1->alias_pfx.length == val2->alias_pfx.length
&& val1->v_type == val2->v_type;
Expand Down
2 changes: 1 addition & 1 deletion src/grpc/dp_grpc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ static int dp_process_add_lbprefix(struct dp_grpc_responder *responder)
if (DP_FAILED(port_id))
return DP_GRPC_ERR_NO_VM;

if (!DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, port_id)))
if (!DP_FAILED(dp_get_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, port_id, !DP_VNF_MATCH_ALL_PORT_ID)))
return DP_GRPC_ERR_ALREADY_EXISTS;

if (DP_FAILED(dp_insert_vnf_entry(&vnf_val, DP_VNF_TYPE_LB_ALIAS_PFX, dp_get_vm_vni(port_id), port_id, ul_addr6)))
Expand Down

0 comments on commit 39976c9

Please sign in to comment.