[ovs-dev] [netlink v4 35/52] dpif: Eliminate ODPPF_* constants from client-visible interface.
Ben Pfaff
blp at nicira.com
Wed Jan 12 05:49:47 UTC 2011
Following this commit, the ODPPF_* constants are only used in
Linux-specific parts of OVS userspace code. This allows the actual Linux
datapath interface to evolve more freely.
---
lib/dpif-linux.c | 13 +++++++++++--
lib/dpif-netdev.c | 8 ++++----
lib/dpif-provider.h | 14 +++++++-------
lib/dpif.c | 19 ++++++++-----------
lib/dpif.h | 8 +++++++-
ofproto/ofproto.c | 12 +++++++-----
6 files changed, 44 insertions(+), 30 deletions(-)
diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c
index 6be463d..ba35991 100644
--- a/lib/dpif-linux.c
+++ b/lib/dpif-linux.c
@@ -505,7 +505,7 @@ dpif_linux_flow_get(const struct dpif *dpif_, int flags,
}
static int
-dpif_linux_flow_put(struct dpif *dpif_, int flags,
+dpif_linux_flow_put(struct dpif *dpif_, enum dpif_flow_put_flags flags,
const struct nlattr *key, size_t key_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *stats)
@@ -519,7 +519,16 @@ dpif_linux_flow_put(struct dpif *dpif_, int flags,
put.flow.actions = (struct nlattr *) actions;
put.flow.actions_len = actions_len;
put.flow.flags = 0;
- put.flags = flags;
+ put.flags = 0;
+ if (flags & DPIF_FP_CREATE) {
+ put.flags |= ODPPF_CREATE;
+ }
+ if (flags & DPIF_FP_MODIFY) {
+ put.flags |= ODPPF_MODIFY;
+ }
+ if (flags & DPIF_FP_ZERO_STATS) {
+ put.flags |= ODPPF_ZERO_STATS;
+ }
error = do_ioctl(dpif_, ODP_FLOW_PUT, &put);
if (!error && stats) {
odp_flow_stats_to_dpif_flow_stats(&put.flow.stats, stats);
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 8988214..8e0404c 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -796,7 +796,7 @@ clear_stats(struct dp_netdev_flow *flow)
}
static int
-dpif_netdev_flow_put(struct dpif *dpif, int flags,
+dpif_netdev_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
const struct nlattr *nl_key, size_t nl_key_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *stats)
@@ -813,7 +813,7 @@ dpif_netdev_flow_put(struct dpif *dpif, int flags,
flow = dp_netdev_lookup_flow(dp, &key);
if (!flow) {
- if (flags & ODPPF_CREATE) {
+ if (flags & DPIF_FP_CREATE) {
if (hmap_count(&dp->flow_table) < MAX_FLOWS) {
if (stats) {
memset(stats, 0, sizeof *stats);
@@ -826,13 +826,13 @@ dpif_netdev_flow_put(struct dpif *dpif, int flags,
return ENOENT;
}
} else {
- if (flags & ODPPF_MODIFY) {
+ if (flags & DPIF_FP_MODIFY) {
int error = set_flow_actions(flow, actions, actions_len);
if (!error) {
if (stats) {
get_dpif_flow_stats(flow, stats);
}
- if (flags & ODPPF_ZERO_STATS) {
+ if (flags & DPIF_FP_ZERO_STATS) {
clear_stats(flow);
}
}
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index 83b881d..1f9adf7 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -230,21 +230,21 @@ struct dpif_class {
* types ODPAT_* in the 'actions_len' bytes starting at 'actions'.
*
* - If the flow's key does not exist in 'dpif', then the flow will be
- * added if 'flags' includes ODPPF_CREATE. Otherwise the operation will
- * fail with ENOENT.
+ * added if 'flags' includes DPIF_FP_CREATE. Otherwise the operation
+ * will fail with ENOENT.
*
* If the operation succeeds, then 'stats', if nonnull, must be zeroed.
*
* - If the flow's key does exist in 'dpif', then the flow's actions will
- * be updated if 'flags' includes ODPPF_MODIFY. Otherwise the operation
- * will fail with EEXIST. If the flow's actions are updated, then its
- * statistics will be zeroed if 'flags' includes ODPPF_ZERO_STATS, and
- * left as-is otherwise.
+ * be updated if 'flags' includes DPIF_FP_MODIFY. Otherwise the
+ * operation will fail with EEXIST. If the flow's actions are updated,
+ * then its statistics will be zeroed if 'flags' includes
+ * DPIF_FP_ZERO_STATS, and left as-is otherwise.
*
* If the operation succeeds, then 'stats', if nonnull, must be set to
* the flow's statistics before the update.
*/
- int (*flow_put)(struct dpif *, int flags,
+ int (*flow_put)(struct dpif *, enum dpif_flow_put_flags flags,
const struct nlattr *key, size_t key_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *stats);
diff --git a/lib/dpif.c b/lib/dpif.c
index e7151d7..b5a990a 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -771,22 +771,22 @@ dpif_flow_get(const struct dpif *dpif, int flags,
* ODPAT_* in the 'actions_len' bytes starting at 'actions'.
*
* - If the flow's key does not exist in 'dpif', then the flow will be added if
- * 'flags' includes ODPPF_CREATE. Otherwise the operation will fail with
+ * 'flags' includes DPIF_FP_CREATE. Otherwise the operation will fail with
* ENOENT.
*
* If the operation succeeds, then 'stats', if nonnull, must be zeroed.
*
* - If the flow's key does exist in 'dpif', then the flow's actions will be
- * updated if 'flags' includes ODPPF_MODIFY. Otherwise the operation will
+ * updated if 'flags' includes DPIF_FP_MODIFY. Otherwise the operation will
* fail with EEXIST. If the flow's actions are updated, then its statistics
- * will be zeroed if 'flags' includes ODPPF_ZERO_STATS, and left as-is
+ * will be zeroed if 'flags' includes DPIF_FP_ZERO_STATS, and left as-is
* otherwise.
*
* If the operation succeeds, then 'stats', if nonnull, must be set to the
* flow's statistics before the update.
*/
int
-dpif_flow_put(struct dpif *dpif, int flags,
+dpif_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
const struct nlattr *key, size_t key_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *stats)
@@ -794,6 +794,7 @@ dpif_flow_put(struct dpif *dpif, int flags,
int error;
COVERAGE_INC(dpif_flow_put);
+ assert(!(flags & ~(DPIF_FP_CREATE | DPIF_FP_MODIFY | DPIF_FP_ZERO_STATS)));
error = dpif->dpif_class->flow_put(dpif, flags, key, key_len,
actions, actions_len, stats);
@@ -801,23 +802,19 @@ dpif_flow_put(struct dpif *dpif, int flags,
memset(stats, 0, sizeof *stats);
}
if (should_log_flow_message(error)) {
- enum { ODPPF_ALL = ODPPF_CREATE | ODPPF_MODIFY | ODPPF_ZERO_STATS };
struct ds s;
ds_init(&s);
ds_put_cstr(&s, "put");
- if (flags & ODPPF_CREATE) {
+ if (flags & DPIF_FP_CREATE) {
ds_put_cstr(&s, "[create]");
}
- if (flags & ODPPF_MODIFY) {
+ if (flags & DPIF_FP_MODIFY) {
ds_put_cstr(&s, "[modify]");
}
- if (flags & ODPPF_ZERO_STATS) {
+ if (flags & DPIF_FP_ZERO_STATS) {
ds_put_cstr(&s, "[zero]");
}
- if (flags & ~ODPPF_ALL) {
- ds_put_format(&s, "[%x]", flags & ~ODPPF_ALL);
- }
log_flow_message(dpif, error, ds_cstr(&s), key, key_len, stats,
actions, actions_len);
ds_destroy(&s);
diff --git a/lib/dpif.h b/lib/dpif.h
index 390cf67..20fe0f7 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -117,8 +117,14 @@ struct dpif_flow_stats {
void dpif_flow_stats_format(const struct dpif_flow_stats *, struct ds *);
+enum dpif_flow_put_flags {
+ DPIF_FP_CREATE = 1 << 0, /* Allow creating a new flow. */
+ DPIF_FP_MODIFY = 1 << 1, /* Allow modifying an existing flow. */
+ DPIF_FP_ZERO_STATS = 1 << 2 /* Zero the stats of an existing flow. */
+};
+
int dpif_flow_flush(struct dpif *);
-int dpif_flow_put(struct dpif *, int flags,
+int dpif_flow_put(struct dpif *, enum dpif_flow_put_flags,
const struct nlattr *key, size_t key_len,
const struct nlattr *actions, size_t actions_len,
struct dpif_flow_stats *);
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 0922662..58f476f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -206,7 +206,8 @@ struct facet {
*
* - Do include packets and bytes that were obtained from the datapath
* when a flow was deleted (e.g. dpif_flow_del()) or when its
- * statistics were reset (e.g. dpif_flow_put() with ODPPF_ZERO_STATS).
+ * statistics were reset (e.g. dpif_flow_put() with
+ * DPIF_FP_ZERO_STATS).
*
* - Do not include any packets or bytes that can currently be obtained
* from the datapath by, e.g., dpif_flow_get().
@@ -2260,7 +2261,8 @@ facet_make_actions(struct ofproto *p, struct facet *facet,
}
static int
-facet_put__(struct ofproto *ofproto, struct facet *facet, int flags)
+facet_put__(struct ofproto *ofproto, struct facet *facet,
+ enum dpif_flow_put_flags flags)
{
uint32_t keybuf[ODPUTIL_FLOW_KEY_U32S];
struct ofpbuf key;
@@ -2280,9 +2282,9 @@ static void
facet_install(struct ofproto *p, struct facet *facet, bool zero_stats)
{
if (facet->may_install) {
- int flags = ODPPF_CREATE | ODPPF_MODIFY;
+ enum dpif_flow_put_flags flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
if (zero_stats) {
- flags |= ODPPF_ZERO_STATS;
+ flags |= DPIF_FP_ZERO_STATS;
}
if (!facet_put__(p, facet, flags)) {
facet->installed = true;
@@ -2461,7 +2463,7 @@ facet_revalidate(struct ofproto *ofproto, struct facet *facet)
odp_flow_key_from_flow(&key, &facet->flow);
dpif_flow_put(ofproto->dpif,
- ODPPF_CREATE | ODPPF_MODIFY | ODPPF_ZERO_STATS,
+ DPIF_FP_CREATE | DPIF_FP_MODIFY | DPIF_FP_ZERO_STATS,
key.data, key.size,
odp_actions->data, odp_actions->size, &stats);
--
1.7.1
More information about the dev
mailing list