Useful in future patches.
Signed-off-by: Ethan Jackson <[email protected]>
---
ofproto/netflow.c | 17 ++++++++++++++++-
ofproto/netflow.h | 1 +
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/ofproto/netflow.c b/ofproto/netflow.c
index bf3501d..1206ae6 100644
--- a/ofproto/netflow.c
+++ b/ofproto/netflow.c
@@ -79,6 +79,7 @@ struct netflow_flow {
};
static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
+static atomic_uint netflow_count = ATOMIC_VAR_INIT(0);
static struct netflow_flow *netflow_flow_lookup(struct netflow *,
struct flow *)
@@ -386,6 +387,8 @@ struct netflow *
netflow_create(void)
{
struct netflow *nf = xzalloc(sizeof *nf);
+ int junk;
+
nf->engine_type = 0;
nf->engine_id = 0;
nf->boot_time = time_msec();
@@ -395,6 +398,7 @@ netflow_create(void)
hmap_init(&nf->flows);
atomic_init(&nf->ref_cnt, 1);
ofpbuf_init(&nf->packet, 1500);
+ atomic_add(&netflow_count, 1, &junk);
return nf;
}
@@ -422,11 +426,22 @@ netflow_unref(struct netflow *nf)
atomic_sub(&nf->ref_cnt, 1, &orig);
ovs_assert(orig > 0);
if (orig == 1) {
- ofpbuf_uninit(&nf->packet);
+ atomic_sub(&netflow_count, 1, &orig);
collectors_destroy(nf->collectors);
+ ofpbuf_uninit(&nf->packet);
free(nf);
}
}
+
+/* Returns true if there exist any netflow objects, false otherwise. */
+bool
+netflow_exists(void)
+{
+ int n;
+
+ atomic_read(&netflow_count, &n);
+ return n > 0;
+}
/* Helpers. */
diff --git a/ofproto/netflow.h b/ofproto/netflow.h
index f37cfa7..c7f2574 100644
--- a/ofproto/netflow.h
+++ b/ofproto/netflow.h
@@ -43,6 +43,7 @@ struct netflow_options {
struct netflow *netflow_create(void);
struct netflow *netflow_ref(const struct netflow *);
void netflow_unref(struct netflow *);
+bool netflow_exists(void);
int netflow_set_options(struct netflow *, const struct netflow_options *);
void netflow_expire(struct netflow *, struct flow *);
--
1.8.1.2
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev