Skip to content

Commit

Permalink
dpctl conntrack: Add get number of connections.
Browse files Browse the repository at this point in the history
A get command is added for number of conntrack connections.
This command is only supported in the userspace datapath
at this time.

Signed-off-by: Darrell Ball <[email protected]>
Signed-off-by: Antonio Fischetti <[email protected]>
Co-authored-by: Antonio Fischetti <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
2 people authored and blp committed Jan 9, 2018
1 parent c92339a commit 875075b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Post-v2.8.0
- ovs-dpctl and related ovs-appctl commands:
* "flush-conntrack" now accept a 5-tuple to delete a specific
connection tracking entry.
* New "ct-set-maxconns" and "ct-get-maxconns" for userspace datapath.
* New "ct-set-maxconns", "ct-get-maxconns", and "ct-get-nconns" commands
for userspace datapath.
- DPDK:
* Add support for DPDK v17.11
* Add support for vHost IOMMU
Expand Down
7 changes: 7 additions & 0 deletions lib/conntrack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,13 @@ conntrack_get_maxconns(struct conntrack *ct, uint32_t *maxconns)
return 0;
}

int
conntrack_get_nconns(struct conntrack *ct, uint32_t *nconns)
{
*nconns = atomic_count_get(&ct->n_conn);
return 0;
}

/* This function must be called with the ct->resources read lock taken. */
static struct alg_exp_node *
expectation_lookup(struct hmap *alg_expectations,
Expand Down
1 change: 1 addition & 0 deletions lib/conntrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int conntrack_dump_done(struct conntrack_dump *);
int conntrack_flush(struct conntrack *, const uint16_t *zone);
int conntrack_set_maxconns(struct conntrack *ct, uint32_t maxconns);
int conntrack_get_maxconns(struct conntrack *ct, uint32_t *maxconns);
int conntrack_get_nconns(struct conntrack *ct, uint32_t *nconns);

/* 'struct ct_lock' is a wrapper for an adaptive mutex. It's useful to try
* different types of locks (e.g. spinlocks) */
Expand Down
8 changes: 8 additions & 0 deletions lib/ct-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ ct_dpif_get_maxconns(struct dpif *dpif, uint32_t *maxconns)
: EOPNOTSUPP);
}

int
ct_dpif_get_nconns(struct dpif *dpif, uint32_t *nconns)
{
return (dpif->dpif_class->ct_get_nconns
? dpif->dpif_class->ct_get_nconns(dpif, nconns)
: EOPNOTSUPP);
}

void
ct_dpif_entry_uninit(struct ct_dpif_entry *entry)
{
Expand Down
1 change: 1 addition & 0 deletions lib/ct-dpif.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ int ct_dpif_flush(struct dpif *, const uint16_t *zone,
const struct ct_dpif_tuple *);
int ct_dpif_set_maxconns(struct dpif *dpif, uint32_t maxconns);
int ct_dpif_get_maxconns(struct dpif *dpif, uint32_t *maxconns);
int ct_dpif_get_nconns(struct dpif *dpif, uint32_t *nconns);
void ct_dpif_entry_uninit(struct ct_dpif_entry *);
void ct_dpif_format_entry(const struct ct_dpif_entry *, struct ds *,
bool verbose, bool print_stats);
Expand Down
22 changes: 22 additions & 0 deletions lib/dpctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,27 @@ dpctl_ct_get_maxconns(int argc, const char *argv[],
return error;
}

static int
dpctl_ct_get_nconns(int argc, const char *argv[],
struct dpctl_params *dpctl_p)
{
struct dpif *dpif;
int error = dpctl_ct_open_dp(argc, argv, dpctl_p, &dpif, 2);
if (!error) {
uint32_t nconns;
error = ct_dpif_get_nconns(dpif, &nconns);

if (!error) {
dpctl_print(dpctl_p, "%u\n", nconns);
} else {
dpctl_error(dpctl_p, error, "nconns could not be retrieved");
}
dpif_close(dpif);
}

return error;
}

/* Undocumented commands for unit testing. */

static int
Expand Down Expand Up @@ -2023,6 +2044,7 @@ static const struct dpctl_command all_commands[] = {
{ "ct-bkts", "[dp] [gt=N]", 0, 2, dpctl_ct_bkts, DP_RO },
{ "ct-set-maxconns", "[dp] maxconns", 1, 2, dpctl_ct_set_maxconns, DP_RW },
{ "ct-get-maxconns", "[dp]", 0, 1, dpctl_ct_get_maxconns, DP_RO },
{ "ct-get-nconns", "[dp]", 0, 1, dpctl_ct_get_nconns, DP_RO },
{ "help", "", 0, INT_MAX, dpctl_help, DP_RO },
{ "list-commands", "", 0, INT_MAX, dpctl_list_commands, DP_RO },

Expand Down
5 changes: 5 additions & 0 deletions lib/dpctl.man
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,8 @@ datapath.
\*(DX\fBct\-get\-maxconns\fR [\fIdp\fR]
Read the maximum limit of connection tracker connections.
Only supported for userspace datapath.
.
.TP
\*(DX\fBct\-get\-nconns\fR [\fIdp\fR]
Read the current number of connection tracker connections.
Only supported for userspace datapath.
9 changes: 9 additions & 0 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5862,6 +5862,14 @@ dpif_netdev_ct_get_maxconns(struct dpif *dpif, uint32_t *maxconns)
return conntrack_get_maxconns(&dp->conntrack, maxconns);
}

static int
dpif_netdev_ct_get_nconns(struct dpif *dpif, uint32_t *nconns)
{
struct dp_netdev *dp = get_dp_netdev(dpif);

return conntrack_get_nconns(&dp->conntrack, nconns);
}

const struct dpif_class dpif_netdev_class = {
"netdev",
dpif_netdev_init,
Expand Down Expand Up @@ -5909,6 +5917,7 @@ const struct dpif_class dpif_netdev_class = {
dpif_netdev_ct_flush,
dpif_netdev_ct_set_maxconns,
dpif_netdev_ct_get_maxconns,
dpif_netdev_ct_get_nconns,
dpif_netdev_meter_get_features,
dpif_netdev_meter_set,
dpif_netdev_meter_get,
Expand Down
1 change: 1 addition & 0 deletions lib/dpif-netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2991,6 +2991,7 @@ const struct dpif_class dpif_netlink_class = {
dpif_netlink_ct_flush,
NULL, /* ct_set_maxconns */
NULL, /* ct_get_maxconns */
NULL, /* ct_get_nconns */
dpif_netlink_meter_get_features,
dpif_netlink_meter_set,
dpif_netlink_meter_get,
Expand Down
2 changes: 2 additions & 0 deletions lib/dpif-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ struct dpif_class {
int (*ct_set_maxconns)(struct dpif *, uint32_t maxconns);
/* Get max connections allowed. */
int (*ct_get_maxconns)(struct dpif *, uint32_t *maxconns);
/* Get number of connections tracked. */
int (*ct_get_nconns)(struct dpif *, uint32_t *nconns);

/* Meters */

Expand Down

0 comments on commit 875075b

Please sign in to comment.