Skip to content

Commit

Permalink
dpctl: Implement dpctl/flow-get for dpif-netdev.
Browse files Browse the repository at this point in the history
Currently 'dpctl/flow-get' doesn't work for flows installed by
PMD threads.

Fix that by implementing search across all PMD threads. Will be returned
flow from first PMD thread with match.

Signed-off-by: Ilya Maximets <[email protected]>
Signed-off-by: Daniele Di Proietto <[email protected]>
  • Loading branch information
igsilya authored and ddiproietto committed Jun 7, 2016
1 parent f9176a3 commit c673049
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
3 changes: 1 addition & 2 deletions lib/dpctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,7 @@ dpctl_get_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p)
goto out;
}

/* Does not work for DPDK, since do not know which 'pmd' to apply the
* operation. So, just uses PMD_ID_NULL. */
/* In case of PMD will be returned flow from first PMD thread with match. */
error = dpif_flow_get(dpif, NULL, 0, &ufid, PMD_ID_NULL, &buf, &flow);
if (error) {
dpctl_error(dpctl_p, error, "getting flow");
Expand Down
50 changes: 36 additions & 14 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2045,26 +2045,48 @@ dpif_netdev_flow_get(const struct dpif *dpif, const struct dpif_flow_get *get)
struct dp_netdev *dp = get_dp_netdev(dpif);
struct dp_netdev_flow *netdev_flow;
struct dp_netdev_pmd_thread *pmd;
unsigned pmd_id = get->pmd_id == PMD_ID_NULL
? NON_PMD_CORE_ID : get->pmd_id;
int error = 0;
struct hmapx to_find = HMAPX_INITIALIZER(&to_find);
struct hmapx_node *node;
int error = EINVAL;

pmd = dp_netdev_get_pmd(dp, pmd_id);
if (!pmd) {
return EINVAL;
if (get->pmd_id == PMD_ID_NULL) {
CMAP_FOR_EACH (pmd, node, &dp->poll_threads) {
if (dp_netdev_pmd_try_ref(pmd) && !hmapx_add(&to_find, pmd)) {
dp_netdev_pmd_unref(pmd);
}
}
} else {
pmd = dp_netdev_get_pmd(dp, get->pmd_id);
if (!pmd) {
goto out;
}
hmapx_add(&to_find, pmd);
}

netdev_flow = dp_netdev_pmd_find_flow(pmd, get->ufid, get->key,
get->key_len);
if (netdev_flow) {
dp_netdev_flow_to_dpif_flow(netdev_flow, get->buffer, get->buffer,
get->flow, false);
} else {
error = ENOENT;
if (!hmapx_count(&to_find)) {
goto out;
}
dp_netdev_pmd_unref(pmd);

HMAPX_FOR_EACH (node, &to_find) {
pmd = (struct dp_netdev_pmd_thread *) node->data;
netdev_flow = dp_netdev_pmd_find_flow(pmd, get->ufid, get->key,
get->key_len);
if (netdev_flow) {
dp_netdev_flow_to_dpif_flow(netdev_flow, get->buffer, get->buffer,
get->flow, false);
error = 0;
break;
} else {
error = ENOENT;
}
}

HMAPX_FOR_EACH (node, &to_find) {
pmd = (struct dp_netdev_pmd_thread *) node->data;
dp_netdev_pmd_unref(pmd);
}
out:
hmapx_destroy(&to_find);
return error;
}

Expand Down

0 comments on commit c673049

Please sign in to comment.