From: Ben Pfaff Date: Wed, 26 Jan 2011 15:12:24 +0000 (-0800) Subject: dpif: Eliminate ODPPF_* constants from client-visible interface. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba25b8f41f4db5ed5c91f53b9b83b57f242a82d6;p=openvswitch dpif: Eliminate ODPPF_* constants from client-visible interface. 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. Reviewed by Justin Pettit. --- diff --git a/lib/dpif-linux.c b/lib/dpif-linux.c index 98acebed..8d5c4896 100644 --- a/lib/dpif-linux.c +++ b/lib/dpif-linux.c @@ -506,7 +506,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) @@ -520,7 +520,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 9272ef7a..7284e2f1 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -797,7 +797,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) @@ -814,7 +814,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); @@ -827,13 +827,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 639d8d56..0ab3c1f2 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -231,21 +231,21 @@ struct dpif_class { * with 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 *dpif, int flags, + int (*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); diff --git a/lib/dpif.c b/lib/dpif.c index c225e2bc..b7e2b389 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -772,22 +772,22 @@ dpif_flow_get(const struct dpif *dpif, int flags, * 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 + * 'flags' includes DPIF_FP_CREATE. Otherwise the operation will fail with * ENOENT. * * If the operation succeeds, then 'stats', if nonnull, will 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, will 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) @@ -795,6 +795,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); @@ -802,23 +803,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 390cf671..20fe0f77 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 edd1cc2e..a0dca356 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(). @@ -2306,7 +2307,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; @@ -2326,9 +2328,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; @@ -2507,7 +2509,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);