[ovs-dev] [PATCH v2 01/26] lib: Separate versioning to its own module.
Jarno Rajahalme
jarno at ovn.org
Fri Jul 29 00:55:53 UTC 2016
Separate rule versioning to lib/versions.h to make it easier to use
versioning for other data types.
Signed-off-by: Jarno Rajahalme <jarno at ovn.org>
---
lib/automake.mk | 1 +
lib/classifier-private.h | 31 +++++--------------
lib/classifier.c | 45 +++++++++++++--------------
lib/classifier.h | 29 +++++++----------
lib/ovs-router.c | 6 ++--
lib/tnl-ports.c | 8 ++---
lib/versions.h | 74 ++++++++++++++++++++++++++++++++++++++++++++
ofproto/ofproto-dpif-xlate.c | 4 +--
ofproto/ofproto-dpif.c | 14 ++++-----
ofproto/ofproto-dpif.h | 4 +--
ofproto/ofproto-provider.h | 6 ++--
ofproto/ofproto.c | 44 +++++++++++++-------------
tests/test-classifier.c | 46 +++++++++++++--------------
tests/test-ovn.c | 4 +--
utilities/ovs-ofctl.c | 2 +-
15 files changed, 185 insertions(+), 133 deletions(-)
create mode 100644 lib/versions.h
diff --git a/lib/automake.mk b/lib/automake.mk
index 4110e5f..f420a9c 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -279,6 +279,7 @@ lib_libopenvswitch_la_SOURCES = \
lib/vconn-provider.h \
lib/vconn-stream.c \
lib/vconn.c \
+ lib/versions.h \
lib/vlan-bitmap.c \
lib/vlan-bitmap.h \
lib/vlog.c \
diff --git a/lib/classifier-private.h b/lib/classifier-private.h
index eb47a4c..1d5ee00 100644
--- a/lib/classifier-private.h
+++ b/lib/classifier-private.h
@@ -72,13 +72,8 @@ struct cls_match {
/* Accessed by all readers. */
struct cmap_node cmap_node; /* Within struct cls_subtable 'rules'. */
- /* Rule versioning.
- *
- * CLS_NOT_REMOVED_VERSION has a special meaning for 'remove_version',
- * meaning that the rule has been added but not yet removed.
- */
- const cls_version_t add_version; /* Version rule was added in. */
- ATOMIC(cls_version_t) remove_version; /* Version rule is removed in. */
+ /* Rule versioning. */
+ struct versions versions;
const struct cls_rule *cls_rule;
const struct miniflow flow; /* Matching rule. Mask is in the subtable. */
@@ -102,34 +97,22 @@ get_cls_match(const struct cls_rule *rule)
void cls_match_free_cb(struct cls_match *);
static inline void
-cls_match_set_remove_version(struct cls_match *rule, cls_version_t version)
+cls_match_set_remove_version(struct cls_match *rule, ovs_version_t version)
{
- atomic_store_relaxed(&rule->remove_version, version);
+ versions_set_remove_version(&rule->versions, version);
}
static inline bool
cls_match_visible_in_version(const struct cls_match *rule,
- cls_version_t version)
+ ovs_version_t version)
{
- cls_version_t remove_version;
-
- /* C11 does not want to access an atomic via a const object pointer. */
- atomic_read_relaxed(&CONST_CAST(struct cls_match *, rule)->remove_version,
- &remove_version);
-
- return rule->add_version <= version && version < remove_version;
+ return versions_visible_in_version(&rule->versions, version);
}
static inline bool
cls_match_is_eventually_invisible(const struct cls_match *rule)
{
- cls_version_t remove_version;
-
- /* C11 does not want to access an atomic via a const object pointer. */
- atomic_read_relaxed(&CONST_CAST(struct cls_match *, rule)->remove_version,
- &remove_version);
-
- return remove_version <= CLS_MAX_VERSION;
+ return versions_is_eventually_invisible(&rule->versions);
}
diff --git a/lib/classifier.c b/lib/classifier.c
index 2b24724..d5fd759 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -84,7 +84,7 @@ cls_conjunction_set_alloc(struct cls_match *match,
}
static struct cls_match *
-cls_match_alloc(const struct cls_rule *rule, cls_version_t version,
+cls_match_alloc(const struct cls_rule *rule, ovs_version_t version,
const struct cls_conjunction conj[], size_t n)
{
size_t count = miniflow_n_values(rule->match.flow);
@@ -95,9 +95,8 @@ cls_match_alloc(const struct cls_rule *rule, cls_version_t version,
ovsrcu_init(&cls_match->next, NULL);
*CONST_CAST(const struct cls_rule **, &cls_match->cls_rule) = rule;
*CONST_CAST(int *, &cls_match->priority) = rule->priority;
- *CONST_CAST(cls_version_t *, &cls_match->add_version) = version;
- atomic_init(&cls_match->remove_version, version); /* Initially
- * invisible. */
+ /* Make rule initially invisible. */
+ cls_match->versions = VERSIONS_INITIALIZER(version, version);
miniflow_clone(CONST_CAST(struct miniflow *, &cls_match->flow),
rule->match.flow, count);
ovsrcu_set_hidden(&cls_match->conj_set,
@@ -113,7 +112,7 @@ static struct cls_subtable *insert_subtable(struct classifier *cls,
static void destroy_subtable(struct classifier *cls, struct cls_subtable *);
static const struct cls_match *find_match_wc(const struct cls_subtable *,
- cls_version_t version,
+ ovs_version_t version,
const struct flow *,
struct trie_ctx *,
unsigned int n_tries,
@@ -126,7 +125,7 @@ static struct cls_match *find_equal(const struct cls_subtable *,
* versioning is used at most one of them is ever visible for lookups on any
* given 'version'. */
static inline const struct cls_match *
-next_visible_rule_in_list(const struct cls_match *rule, cls_version_t version)
+next_visible_rule_in_list(const struct cls_match *rule, ovs_version_t version)
{
do {
rule = cls_match_next(rule);
@@ -288,11 +287,11 @@ cls_rule_is_catchall(const struct cls_rule *rule)
* This may only be called by the exclusive writer. */
void
cls_rule_make_invisible_in_version(const struct cls_rule *rule,
- cls_version_t remove_version)
+ ovs_version_t remove_version)
{
struct cls_match *cls_match = get_cls_match_protected(rule);
- ovs_assert(remove_version >= cls_match->add_version);
+ ovs_assert(remove_version >= cls_match->versions.add_version);
cls_match_set_remove_version(cls_match, remove_version);
}
@@ -305,14 +304,14 @@ void
cls_rule_restore_visibility(const struct cls_rule *rule)
{
cls_match_set_remove_version(get_cls_match_protected(rule),
- CLS_NOT_REMOVED_VERSION);
+ OVS_VERSION_NOT_REMOVED);
}
/* Return true if 'rule' is visible in 'version'.
*
* 'rule' must be in a classifier. */
bool
-cls_rule_visible_in_version(const struct cls_rule *rule, cls_version_t version)
+cls_rule_visible_in_version(const struct cls_rule *rule, ovs_version_t version)
{
struct cls_match *cls_match = get_cls_match(rule);
@@ -516,7 +515,7 @@ static inline ovs_be32 minimatch_get_ports(const struct minimatch *match)
*/
const struct cls_rule *
classifier_replace(struct classifier *cls, const struct cls_rule *rule,
- cls_version_t version,
+ ovs_version_t version,
const struct cls_conjunction *conjs, size_t n_conjs)
{
struct cls_match *new;
@@ -627,7 +626,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule,
/* No change in subtable's max priority or max count. */
/* Make 'new' visible to lookups in the appropriate version. */
- cls_match_set_remove_version(new, CLS_NOT_REMOVED_VERSION);
+ cls_match_set_remove_version(new, OVS_VERSION_NOT_REMOVED);
/* Make rule visible to iterators (immediately). */
rculist_replace(CONST_CAST(struct rculist *, &rule->node),
@@ -644,7 +643,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule,
}
/* Make 'new' visible to lookups in the appropriate version. */
- cls_match_set_remove_version(new, CLS_NOT_REMOVED_VERSION);
+ cls_match_set_remove_version(new, OVS_VERSION_NOT_REMOVED);
/* Make rule visible to iterators (immediately). */
rculist_push_back(&subtable->rules_list,
@@ -686,7 +685,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule,
* such a rule. */
void
classifier_insert(struct classifier *cls, const struct cls_rule *rule,
- cls_version_t version, const struct cls_conjunction conj[],
+ ovs_version_t version, const struct cls_conjunction conj[],
size_t n_conj)
{
const struct cls_rule *displaced_rule
@@ -929,7 +928,7 @@ free_conjunctive_matches(struct hmap *matches,
* 'flow' is non-const to allow for temporary modifications during the lookup.
* Any changes are restored before returning. */
static const struct cls_rule *
-classifier_lookup__(const struct classifier *cls, cls_version_t version,
+classifier_lookup__(const struct classifier *cls, ovs_version_t version,
struct flow *flow, struct flow_wildcards *wc,
bool allow_conjunctive_matches)
{
@@ -1157,7 +1156,7 @@ classifier_lookup__(const struct classifier *cls, cls_version_t version,
* 'flow' is non-const to allow for temporary modifications during the lookup.
* Any changes are restored before returning. */
const struct cls_rule *
-classifier_lookup(const struct classifier *cls, cls_version_t version,
+classifier_lookup(const struct classifier *cls, ovs_version_t version,
struct flow *flow, struct flow_wildcards *wc)
{
return classifier_lookup__(cls, version, flow, wc, true);
@@ -1170,7 +1169,7 @@ classifier_lookup(const struct classifier *cls, cls_version_t version,
const struct cls_rule *
classifier_find_rule_exactly(const struct classifier *cls,
const struct cls_rule *target,
- cls_version_t version)
+ ovs_version_t version)
{
const struct cls_match *head, *rule;
const struct cls_subtable *subtable;
@@ -1205,7 +1204,7 @@ classifier_find_rule_exactly(const struct classifier *cls,
const struct cls_rule *
classifier_find_match_exactly(const struct classifier *cls,
const struct match *target, int priority,
- cls_version_t version)
+ ovs_version_t version)
{
const struct cls_rule *retval;
struct cls_rule cr;
@@ -1227,7 +1226,7 @@ classifier_find_match_exactly(const struct classifier *cls,
* dl_type could match both, if the rules also have the same priority. */
bool
classifier_rule_overlaps(const struct classifier *cls,
- const struct cls_rule *target, cls_version_t version)
+ const struct cls_rule *target, ovs_version_t version)
{
struct cls_subtable *subtable;
@@ -1301,7 +1300,7 @@ cls_rule_is_loose_match(const struct cls_rule *rule,
static bool
rule_matches(const struct cls_rule *rule, const struct cls_rule *target,
- cls_version_t version)
+ ovs_version_t version)
{
/* Rule may only match a target if it is visible in target's version. */
return cls_rule_visible_in_version(rule, version)
@@ -1340,7 +1339,7 @@ search_subtable(const struct cls_subtable *subtable,
* Ignores target->priority. */
struct cls_cursor
cls_cursor_start(const struct classifier *cls, const struct cls_rule *target,
- cls_version_t version)
+ ovs_version_t version)
{
struct cls_cursor cursor;
struct cls_subtable *subtable;
@@ -1617,7 +1616,7 @@ miniflow_and_mask_matches_flow(const struct miniflow *flow,
}
static inline const struct cls_match *
-find_match(const struct cls_subtable *subtable, cls_version_t version,
+find_match(const struct cls_subtable *subtable, ovs_version_t version,
const struct flow *flow, uint32_t hash)
{
const struct cls_match *head, *rule;
@@ -1639,7 +1638,7 @@ find_match(const struct cls_subtable *subtable, cls_version_t version,
}
static const struct cls_match *
-find_match_wc(const struct cls_subtable *subtable, cls_version_t version,
+find_match_wc(const struct cls_subtable *subtable, ovs_version_t version,
const struct flow *flow, struct trie_ctx trie_ctx[CLS_MAX_TRIES],
unsigned int n_tries, struct flow_wildcards *wc)
{
diff --git a/lib/classifier.h b/lib/classifier.h
index 6247350..44185a3 100644
--- a/lib/classifier.h
+++ b/lib/classifier.h
@@ -304,6 +304,7 @@
#include "pvector.h"
#include "rculist.h"
#include "openvswitch/type-props.h"
+#include "versions.h"
#ifdef __cplusplus
extern "C" {
@@ -322,12 +323,6 @@ struct cls_trie {
rcu_trie_ptr root; /* NULL if none. */
};
-typedef uint64_t cls_version_t;
-
-#define CLS_MIN_VERSION 0 /* Default version number to use. */
-#define CLS_MAX_VERSION (TYPE_MAXIMUM(cls_version_t) - 1)
-#define CLS_NOT_REMOVED_VERSION TYPE_MAXIMUM(cls_version_t)
-
enum {
CLS_MAX_INDICES = 3, /* Maximum number of lookup indices per subtable. */
CLS_MAX_TRIES = 3 /* Maximum number of prefix trees per classifier. */
@@ -381,15 +376,15 @@ void cls_rule_destroy(struct cls_rule *);
void cls_rule_set_conjunctions(struct cls_rule *,
const struct cls_conjunction *, size_t n);
void cls_rule_make_invisible_in_version(const struct cls_rule *,
- cls_version_t);
+ ovs_version_t);
void cls_rule_restore_visibility(const struct cls_rule *);
void classifier_insert(struct classifier *, const struct cls_rule *,
- cls_version_t, const struct cls_conjunction *,
+ ovs_version_t, const struct cls_conjunction *,
size_t n_conjunctions);
const struct cls_rule *classifier_replace(struct classifier *,
const struct cls_rule *,
- cls_version_t,
+ ovs_version_t,
const struct cls_conjunction *,
size_t n_conjunctions);
const struct cls_rule *classifier_remove(struct classifier *,
@@ -400,17 +395,17 @@ static inline void classifier_publish(struct classifier *);
/* Lookups. These are RCU protected and may run concurrently with modifiers
* and each other. */
const struct cls_rule *classifier_lookup(const struct classifier *,
- cls_version_t, struct flow *,
+ ovs_version_t, struct flow *,
struct flow_wildcards *);
bool classifier_rule_overlaps(const struct classifier *,
- const struct cls_rule *, cls_version_t);
+ const struct cls_rule *, ovs_version_t);
const struct cls_rule *classifier_find_rule_exactly(const struct classifier *,
const struct cls_rule *,
- cls_version_t);
+ ovs_version_t);
const struct cls_rule *classifier_find_match_exactly(const struct classifier *,
const struct match *,
int priority,
- cls_version_t);
+ ovs_version_t);
bool classifier_is_empty(const struct classifier *);
int classifier_count(const struct classifier *);
@@ -421,7 +416,7 @@ void cls_rule_format(const struct cls_rule *, struct ds *);
bool cls_rule_is_catchall(const struct cls_rule *);
bool cls_rule_is_loose_match(const struct cls_rule *rule,
const struct minimatch *criteria);
-bool cls_rule_visible_in_version(const struct cls_rule *, cls_version_t);
+bool cls_rule_visible_in_version(const struct cls_rule *, ovs_version_t);
/* Iteration.
*
@@ -439,18 +434,18 @@ struct cls_cursor {
const struct classifier *cls;
const struct cls_subtable *subtable;
const struct cls_rule *target;
- cls_version_t version; /* Version to iterate. */
+ ovs_version_t version; /* Version to iterate. */
struct pvector_cursor subtables;
const struct cls_rule *rule;
};
struct cls_cursor cls_cursor_start(const struct classifier *,
const struct cls_rule *target,
- cls_version_t);
+ ovs_version_t);
void cls_cursor_advance(struct cls_cursor *);
#define CLS_FOR_EACH(RULE, MEMBER, CLS) \
- CLS_FOR_EACH_TARGET(RULE, MEMBER, CLS, NULL, CLS_MAX_VERSION)
+ CLS_FOR_EACH_TARGET(RULE, MEMBER, CLS, NULL, OVS_VERSION_MAX)
#define CLS_FOR_EACH_TARGET(RULE, MEMBER, CLS, TARGET, VERSION) \
for (struct cls_cursor cursor__ = cls_cursor_start(CLS, TARGET, VERSION); \
(cursor__.rule \
diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index 685e1ad..e27514a 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -94,7 +94,7 @@ ovs_router_lookup(const struct in6_addr *ip6_dst, char output_bridge[],
const struct cls_rule *cr;
struct flow flow = {.ipv6_dst = *ip6_dst};
- cr = classifier_lookup(&cls, CLS_MAX_VERSION, &flow, NULL);
+ cr = classifier_lookup(&cls, OVS_VERSION_MAX, &flow, NULL);
if (cr) {
struct ovs_router_entry *p = ovs_router_entry_cast(cr);
@@ -206,7 +206,7 @@ ovs_router_insert__(uint8_t priority, const struct in6_addr *ip6_dst,
cls_rule_init(&p->cr, &match, priority);
ovs_mutex_lock(&mutex);
- cr = classifier_replace(&cls, &p->cr, CLS_MIN_VERSION, NULL, 0);
+ cr = classifier_replace(&cls, &p->cr, OVS_VERSION_MIN, NULL, 0);
ovs_mutex_unlock(&mutex);
if (cr) {
@@ -254,7 +254,7 @@ rt_entry_delete(uint8_t priority, const struct in6_addr *ip6_dst, uint8_t plen)
cls_rule_init(&rule, &match, priority);
/* Find the exact rule. */
- cr = classifier_find_rule_exactly(&cls, &rule, CLS_MAX_VERSION);
+ cr = classifier_find_rule_exactly(&cls, &rule, OVS_VERSION_MAX);
if (cr) {
ovs_mutex_lock(&mutex);
res = __rt_entry_delete(cr);
diff --git a/lib/tnl-ports.c b/lib/tnl-ports.c
index e945eae..ffa1389 100644
--- a/lib/tnl-ports.c
+++ b/lib/tnl-ports.c
@@ -112,7 +112,7 @@ map_insert(odp_port_t port, struct eth_addr mac, struct in6_addr *addr,
tnl_port_init_flow(&match.flow, mac, addr, nw_proto, tp_port);
do {
- cr = classifier_lookup(&cls, CLS_MAX_VERSION, &match.flow, NULL);
+ cr = classifier_lookup(&cls, OVS_VERSION_MAX, &match.flow, NULL);
p = tnl_port_cast(cr);
/* Try again if the rule was released before we get the reference. */
} while (p && !ovs_refcount_try_ref_rcu(&p->ref_cnt));
@@ -143,7 +143,7 @@ map_insert(odp_port_t port, struct eth_addr mac, struct in6_addr *addr,
ovs_refcount_init(&p->ref_cnt);
ovs_strlcpy(p->dev_name, dev_name, sizeof p->dev_name);
- classifier_insert(&cls, &p->cr, CLS_MIN_VERSION, NULL, 0);
+ classifier_insert(&cls, &p->cr, OVS_VERSION_MIN, NULL, 0);
}
}
@@ -235,7 +235,7 @@ map_delete(struct eth_addr mac, struct in6_addr *addr,
tnl_port_init_flow(&flow, mac, addr, nw_proto, tp_port);
- cr = classifier_lookup(&cls, CLS_MAX_VERSION, &flow, NULL);
+ cr = classifier_lookup(&cls, OVS_VERSION_MAX, &flow, NULL);
tnl_port_unref(cr);
}
@@ -287,7 +287,7 @@ out:
odp_port_t
tnl_port_map_lookup(struct flow *flow, struct flow_wildcards *wc)
{
- const struct cls_rule *cr = classifier_lookup(&cls, CLS_MAX_VERSION, flow,
+ const struct cls_rule *cr = classifier_lookup(&cls, OVS_VERSION_MAX, flow,
wc);
return (cr) ? tnl_port_cast(cr)->portno : ODPP_NONE;
diff --git a/lib/versions.h b/lib/versions.h
new file mode 100644
index 0000000..d92f0a3
--- /dev/null
+++ b/lib/versions.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VERSIONS_H
+#define VERSIONS_H 1
+
+#include "ovs-atomic.h"
+#include "openvswitch/type-props.h"
+
+typedef uint64_t ovs_version_t;
+
+#define OVS_VERSION_MIN 0 /* Default version number to use. */
+#define OVS_VERSION_MAX (TYPE_MAXIMUM(ovs_version_t) - 1)
+#define OVS_VERSION_NOT_REMOVED TYPE_MAXIMUM(ovs_version_t)
+
+/*
+ * OVS_VERSION_NOT_REMOVED has a special meaning for 'remove_version',
+ * meaning that the rule has been added but not yet removed.
+ */
+struct versions {
+ ovs_version_t add_version; /* Version object was added in. */
+ ATOMIC(ovs_version_t) remove_version; /* Version object is removed in. */
+};
+
+#define VERSIONS_INITIALIZER(ADD, REMOVE) \
+ (struct versions){ ADD, ATOMIC_VAR_INIT(REMOVE) }
+
+static inline void
+versions_set_remove_version(struct versions *versions, ovs_version_t version)
+{
+ atomic_store_relaxed(&versions->remove_version, version);
+}
+
+static inline bool
+versions_visible_in_version(const struct versions *versions,
+ ovs_version_t version)
+{
+ ovs_version_t remove_version;
+
+ /* C11 does not want to access an atomic via a const object pointer. */
+ atomic_read_relaxed(&CONST_CAST(struct versions *,
+ versions)->remove_version,
+ &remove_version);
+
+ return versions->add_version <= version && version < remove_version;
+}
+
+static inline bool
+versions_is_eventually_invisible(const struct versions *versions)
+{
+ ovs_version_t remove_version;
+
+ /* C11 does not want to access an atomic via a const object pointer. */
+ atomic_read_relaxed(&CONST_CAST(struct versions *,
+ versions)->remove_version,
+ &remove_version);
+
+ return remove_version < OVS_VERSION_NOT_REMOVED;
+}
+
+#endif /* VERSIONS_H */
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 160da5b..3565c70 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -170,7 +170,7 @@ struct xlate_ctx {
const struct xbridge *xbridge;
/* Flow tables version at the beginning of the translation. */
- cls_version_t tables_version;
+ ovs_version_t tables_version;
/* Flow at the last commit. */
struct flow base_flow;
@@ -3050,7 +3050,7 @@ compose_output_action__(struct xlate_ctx *ctx, ofp_port_t ofp_port,
struct flow old_flow = ctx->xin->flow;
bool old_conntrack = ctx->conntracked;
bool old_was_mpls = ctx->was_mpls;
- cls_version_t old_version = ctx->tables_version;
+ ovs_version_t old_version = ctx->tables_version;
struct ofpbuf old_stack = ctx->stack;
union mf_subvalue new_stack[1024 / sizeof(union mf_subvalue)];
struct ofpbuf old_action_set = ctx->action_set;
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index 79f2aa0..fa16af2 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -273,7 +273,7 @@ struct ofproto_dpif {
* process. */
struct uuid uuid;
- ATOMIC(cls_version_t) tables_version; /* For classifier lookups. */
+ ATOMIC(ovs_version_t) tables_version; /* For classifier lookups. */
uint64_t dump_seq; /* Last read of udpif_dump_seq(). */
@@ -1349,7 +1349,7 @@ construct(struct ofproto *ofproto_)
}
uuid_generate(&ofproto->uuid);
- atomic_init(&ofproto->tables_version, CLS_MIN_VERSION);
+ atomic_init(&ofproto->tables_version, OVS_VERSION_MIN);
ofproto->netflow = NULL;
ofproto->sflow = NULL;
ofproto->ipfix = NULL;
@@ -1717,7 +1717,7 @@ query_tables(struct ofproto *ofproto,
}
static void
-set_tables_version(struct ofproto *ofproto_, cls_version_t version)
+set_tables_version(struct ofproto *ofproto_, ovs_version_t version)
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
@@ -3894,10 +3894,10 @@ rule_set_recirc_id(struct rule *rule_, uint32_t id)
ovs_mutex_unlock(&rule->up.mutex);
}
-cls_version_t
+ovs_version_t
ofproto_dpif_get_tables_version(struct ofproto_dpif *ofproto OVS_UNUSED)
{
- cls_version_t version;
+ ovs_version_t version;
atomic_read_relaxed(&ofproto->tables_version, &version);
@@ -3911,7 +3911,7 @@ ofproto_dpif_get_tables_version(struct ofproto_dpif *ofproto OVS_UNUSED)
* 'flow' is non-const to allow for temporary modifications during the lookup.
* Any changes are restored before returning. */
static struct rule_dpif *
-rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, cls_version_t version,
+rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, ovs_version_t version,
uint8_t table_id, struct flow *flow,
struct flow_wildcards *wc)
{
@@ -3947,7 +3947,7 @@ rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto, cls_version_t version,
* Any changes are restored before returning. */
struct rule_dpif *
rule_dpif_lookup_from_table(struct ofproto_dpif *ofproto,
- cls_version_t version, struct flow *flow,
+ ovs_version_t version, struct flow *flow,
struct flow_wildcards *wc,
const struct dpif_flow_stats *stats,
uint8_t *table_id, ofp_port_t in_port,
diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h
index a3c2ac5..ff07ba7 100644
--- a/ofproto/ofproto-dpif.h
+++ b/ofproto/ofproto-dpif.h
@@ -100,10 +100,10 @@ struct dpif_backer_support {
bool ofproto_dpif_get_enable_ufid(const struct dpif_backer *backer);
struct dpif_backer_support *ofproto_dpif_get_support(const struct ofproto_dpif *);
-cls_version_t ofproto_dpif_get_tables_version(struct ofproto_dpif *);
+ovs_version_t ofproto_dpif_get_tables_version(struct ofproto_dpif *);
struct rule_dpif *rule_dpif_lookup_from_table(struct ofproto_dpif *,
- cls_version_t, struct flow *,
+ ovs_version_t, struct flow *,
struct flow_wildcards *,
const struct dpif_flow_stats *,
uint8_t *table_id,
diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h
index 7156814..cfc5fa0 100644
--- a/ofproto/ofproto-provider.h
+++ b/ofproto/ofproto-provider.h
@@ -93,7 +93,7 @@ struct ofproto {
long long int eviction_group_timer; /* For rate limited reheapification. */
struct oftable *tables;
int n_tables;
- cls_version_t tables_version; /* Controls which rules are visible to
+ ovs_version_t tables_version; /* Controls which rules are visible to
* table lookups. */
/* Rules indexed on their cookie values, in all flow tables. */
@@ -861,7 +861,7 @@ struct ofproto_class {
* lookups. This must be called with a new version number after each set
* of flow table changes has been completed, so that datapath revalidation
* can be triggered. */
- void (*set_tables_version)(struct ofproto *ofproto, cls_version_t version);
+ void (*set_tables_version)(struct ofproto *ofproto, ovs_version_t version);
/* ## ---------------- ## */
/* ## ofport Functions ## */
@@ -1793,7 +1793,7 @@ int ofproto_class_unregister(const struct ofproto_class *);
struct ofproto_flow_mod {
struct ofputil_flow_mod fm;
- cls_version_t version; /* Version in which changes take
+ ovs_version_t version; /* Version in which changes take
* effect. */
struct rule_collection old_rules; /* Affected rules. */
struct rule_collection new_rules; /* Replacement rules. */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 6cd2600..18d170e 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -139,7 +139,7 @@ struct rule_criteria {
* collect_rules_loose() and "strict" way by collect_rules_strict(), as
* defined in the OpenFlow spec. */
struct cls_rule cr;
- cls_version_t version;
+ ovs_version_t version;
/* Matching criteria for the OpenFlow cookie. Consider a bit B in a rule's
* cookie and the corresponding bits C in 'cookie' and M in 'cookie_mask'.
@@ -161,7 +161,7 @@ struct rule_criteria {
static void rule_criteria_init(struct rule_criteria *, uint8_t table_id,
const struct match *match, int priority,
- cls_version_t version,
+ ovs_version_t version,
ovs_be64 cookie, ovs_be64 cookie_mask,
ofp_port_t out_port, uint32_t out_group);
static void rule_criteria_require_rw(struct rule_criteria *,
@@ -271,7 +271,7 @@ static enum ofperr replace_rule_create(struct ofproto *,
struct rule **new_rule)
OVS_REQUIRES(ofproto_mutex);
-static void replace_rule_start(struct ofproto *, cls_version_t version,
+static void replace_rule_start(struct ofproto *, ovs_version_t version,
struct rule *old_rule, struct rule *new_rule,
struct cls_conjunction *, size_t n_conjs)
OVS_REQUIRES(ofproto_mutex);
@@ -557,7 +557,7 @@ ofproto_create(const char *datapath_name, const char *datapath_type,
ofproto->eviction_group_timer = LLONG_MIN;
ofproto->tables = NULL;
ofproto->n_tables = 0;
- ofproto->tables_version = CLS_MIN_VERSION;
+ ofproto->tables_version = OVS_VERSION_MIN;
hindex_init(&ofproto->cookies);
hmap_init(&ofproto->learned_cookies);
ovs_list_init(&ofproto->expirable);
@@ -1526,7 +1526,7 @@ ofproto_rule_delete(struct ofproto *ofproto, struct rule *rule)
if (!rule->removed) {
/* Make sure there is no postponed removal of the rule. */
- ovs_assert(cls_rule_visible_in_version(&rule->cr, CLS_MAX_VERSION));
+ ovs_assert(cls_rule_visible_in_version(&rule->cr, OVS_VERSION_MAX));
if (!classifier_remove(&rule->ofproto->tables[rule->table_id].cls,
&rule->cr)) {
@@ -2165,7 +2165,7 @@ ofproto_add_flow(struct ofproto *ofproto, const struct match *match,
* with the actions that we want. If it does, then we're done. */
rule = rule_from_cls_rule(classifier_find_match_exactly(
&ofproto->tables[0].cls, match, priority,
- CLS_MAX_VERSION));
+ OVS_VERSION_MAX));
if (rule) {
const struct rule_actions *actions = rule_get_actions(rule);
must_add = !ofpacts_equal(actions->ofpacts, actions->ofpacts_len,
@@ -2206,7 +2206,7 @@ ofproto_flow_mod(struct ofproto *ofproto, struct ofproto_flow_mod *ofm)
rule = rule_from_cls_rule(classifier_find_match_exactly(
&table->cls, &fm->match, fm->priority,
- CLS_MAX_VERSION));
+ OVS_VERSION_MAX));
if (rule) {
/* Reading many of the rule fields and writing on 'modified'
* requires the rule->mutex. Also, rule->actions may change
@@ -2253,7 +2253,7 @@ ofproto_delete_flow(struct ofproto *ofproto,
/* First do a cheap check whether the rule we're looking for has already
* been deleted. If so, then we're done. */
rule = rule_from_cls_rule(classifier_find_match_exactly(
- cls, target, priority, CLS_MAX_VERSION));
+ cls, target, priority, OVS_VERSION_MAX));
if (!rule) {
return;
}
@@ -2910,7 +2910,7 @@ remove_rule_rcu__(struct rule *rule)
struct ofproto *ofproto = rule->ofproto;
struct oftable *table = &ofproto->tables[rule->table_id];
- ovs_assert(!cls_rule_visible_in_version(&rule->cr, CLS_MAX_VERSION));
+ ovs_assert(!cls_rule_visible_in_version(&rule->cr, OVS_VERSION_MAX));
if (!classifier_remove(&table->cls, &rule->cr)) {
OVS_NOT_REACHED();
}
@@ -3200,7 +3200,7 @@ learned_cookies_flush(struct ofproto *ofproto, struct ovs_list *dead_cookies)
struct match match;
match_init_catchall(&match);
- rule_criteria_init(&criteria, c->table_id, &match, 0, CLS_MAX_VERSION,
+ rule_criteria_init(&criteria, c->table_id, &match, 0, OVS_VERSION_MAX,
c->cookie, OVS_BE64_MAX, OFPP_ANY, OFPG_ANY);
rule_criteria_require_rw(&criteria, false);
collect_rules_loose(ofproto, &criteria, &rules);
@@ -3983,7 +3983,7 @@ next_matching_table(const struct ofproto *ofproto,
static void
rule_criteria_init(struct rule_criteria *criteria, uint8_t table_id,
const struct match *match, int priority,
- cls_version_t version, ovs_be64 cookie,
+ ovs_version_t version, ovs_be64 cookie,
ovs_be64 cookie_mask, ofp_port_t out_port,
uint32_t out_group)
{
@@ -4294,7 +4294,7 @@ handle_flow_stats_request(struct ofconn *ofconn,
return error;
}
- rule_criteria_init(&criteria, fsr.table_id, &fsr.match, 0, CLS_MAX_VERSION,
+ rule_criteria_init(&criteria, fsr.table_id, &fsr.match, 0, OVS_VERSION_MAX,
fsr.cookie, fsr.cookie_mask, fsr.out_port,
fsr.out_group);
@@ -4459,7 +4459,7 @@ handle_aggregate_stats_request(struct ofconn *ofconn,
}
rule_criteria_init(&criteria, request.table_id, &request.match, 0,
- CLS_MAX_VERSION, request.cookie, request.cookie_mask,
+ OVS_VERSION_MAX, request.cookie, request.cookie_mask,
request.out_port, request.out_group);
ovs_mutex_lock(&ofproto_mutex);
@@ -4913,7 +4913,7 @@ replace_rule_create(struct ofproto *ofproto, struct ofputil_flow_mod *fm,
}
static void
-replace_rule_start(struct ofproto *ofproto, cls_version_t version,
+replace_rule_start(struct ofproto *ofproto, ovs_version_t version,
struct rule *old_rule, struct rule *new_rule,
struct cls_conjunction *conjs, size_t n_conjs)
{
@@ -5091,7 +5091,7 @@ modify_flows_start_loose(struct ofproto *ofproto, struct ofproto_flow_mod *ofm)
struct rule_criteria criteria;
enum ofperr error;
- rule_criteria_init(&criteria, fm->table_id, &fm->match, 0, CLS_MAX_VERSION,
+ rule_criteria_init(&criteria, fm->table_id, &fm->match, 0, OVS_VERSION_MAX,
fm->cookie, fm->cookie_mask, OFPP_ANY, OFPG_ANY);
rule_criteria_require_rw(&criteria,
(fm->flags & OFPUTIL_FF_NO_READONLY) != 0);
@@ -5168,7 +5168,7 @@ modify_flow_start_strict(struct ofproto *ofproto, struct ofproto_flow_mod *ofm)
enum ofperr error;
rule_criteria_init(&criteria, fm->table_id, &fm->match, fm->priority,
- CLS_MAX_VERSION, fm->cookie, fm->cookie_mask, OFPP_ANY,
+ OVS_VERSION_MAX, fm->cookie, fm->cookie_mask, OFPP_ANY,
OFPG_ANY);
rule_criteria_require_rw(&criteria,
(fm->flags & OFPUTIL_FF_NO_READONLY) != 0);
@@ -5189,7 +5189,7 @@ modify_flow_start_strict(struct ofproto *ofproto, struct ofproto_flow_mod *ofm)
/* OFPFC_DELETE implementation. */
static void
-delete_flows_start__(struct ofproto *ofproto, cls_version_t version,
+delete_flows_start__(struct ofproto *ofproto, ovs_version_t version,
const struct rule_collection *rules)
OVS_REQUIRES(ofproto_mutex)
{
@@ -5265,7 +5265,7 @@ delete_flows_start_loose(struct ofproto *ofproto, struct ofproto_flow_mod *ofm)
struct rule_criteria criteria;
enum ofperr error;
- rule_criteria_init(&criteria, fm->table_id, &fm->match, 0, CLS_MAX_VERSION,
+ rule_criteria_init(&criteria, fm->table_id, &fm->match, 0, OVS_VERSION_MAX,
fm->cookie, fm->cookie_mask, fm->out_port,
fm->out_group);
rule_criteria_require_rw(&criteria,
@@ -5321,7 +5321,7 @@ delete_flow_start_strict(struct ofproto *ofproto,
enum ofperr error;
rule_criteria_init(&criteria, fm->table_id, &fm->match, fm->priority,
- CLS_MAX_VERSION, fm->cookie, fm->cookie_mask,
+ OVS_VERSION_MAX, fm->cookie, fm->cookie_mask,
fm->out_port, fm->out_group);
rule_criteria_require_rw(&criteria,
(fm->flags & OFPUTIL_FF_NO_READONLY) != 0);
@@ -5718,7 +5718,7 @@ ofproto_collect_ofmonitor_refresh_rules(const struct ofmonitor *m,
FOR_EACH_MATCHING_TABLE (table, m->table_id, ofproto) {
struct rule *rule;
- CLS_FOR_EACH_TARGET (rule, cr, &table->cls, &target, CLS_MAX_VERSION) {
+ CLS_FOR_EACH_TARGET (rule, cr, &table->cls, &target, OVS_VERSION_MAX) {
ofproto_collect_ofmonitor_refresh_rule(m, rule, seqno, rules);
}
}
@@ -6257,7 +6257,7 @@ group_get_ref_count(struct ofgroup *group)
uint32_t count;
match_init_catchall(&match);
- rule_criteria_init(&criteria, 0xff, &match, 0, CLS_MAX_VERSION, htonll(0),
+ rule_criteria_init(&criteria, 0xff, &match, 0, OVS_VERSION_MAX, htonll(0),
htonll(0), OFPP_ANY, group->group_id);
ovs_mutex_lock(&ofproto_mutex);
error = collect_rules_loose(ofproto, &criteria, &rules);
@@ -7073,7 +7073,7 @@ static enum ofperr
do_bundle_commit(struct ofconn *ofconn, uint32_t id, uint16_t flags)
{
struct ofproto *ofproto = ofconn_get_ofproto(ofconn);
- cls_version_t version = ofproto->tables_version + 1;
+ ovs_version_t version = ofproto->tables_version + 1;
struct ofp_bundle *bundle;
struct ofp_bundle_entry *be;
enum ofperr error;
diff --git a/tests/test-classifier.c b/tests/test-classifier.c
index c74c440..3a275b4 100644
--- a/tests/test-classifier.c
+++ b/tests/test-classifier.c
@@ -406,7 +406,7 @@ get_value(unsigned int *x, unsigned n_values)
static void
compare_classifiers(struct classifier *cls, size_t n_invisible_rules,
- cls_version_t version, struct tcls *tcls)
+ ovs_version_t version, struct tcls *tcls)
{
static const int confidence = 500;
unsigned int i;
@@ -520,7 +520,7 @@ verify_tries(struct classifier *cls)
static void
check_tables(const struct classifier *cls, int n_tables, int n_rules,
- int n_dups, int n_invisible, cls_version_t version)
+ int n_dups, int n_invisible, ovs_version_t version)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
const struct cls_subtable *table;
@@ -564,7 +564,7 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
CMAP_FOR_EACH (head, cmap_node, &table->rules) {
int prev_priority = INT_MAX;
- cls_version_t prev_version = 0;
+ ovs_version_t prev_version = 0;
const struct cls_match *rule, *prev;
bool found_visible_rules_in_list = false;
@@ -576,7 +576,7 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
}
FOR_EACH_RULE_IN_LIST_PROTECTED(rule, prev, head) {
- cls_version_t rule_version;
+ ovs_version_t rule_version;
const struct cls_rule *found_rule;
/* Priority may not increase. */
@@ -601,7 +601,7 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
}
/* Rule must be visible in the version it was inserted. */
- rule_version = rule->add_version;
+ rule_version = rule->versions.add_version;
assert(cls_match_visible_in_version(rule, rule_version));
/* We should always find the latest version of the rule,
@@ -616,12 +616,12 @@ check_tables(const struct classifier *cls, int n_tables, int n_rules,
assert(found_rule->priority == rule->priority);
/* Found rule may not have a lower version. */
- assert(cls_match->add_version >= rule_version);
+ assert(cls_match->versions.add_version >= rule_version);
/* This rule must not be visible in the found rule's
* version. */
assert(!cls_match_visible_in_version(
- rule, cls_match->add_version));
+ rule, cls_match->versions.add_version));
}
if (rule->priority == prev_priority) {
@@ -780,7 +780,7 @@ test_empty(struct ovs_cmdl_context *ctx OVS_UNUSED)
tcls_init(&tcls);
assert(classifier_is_empty(&cls));
assert(tcls_is_empty(&tcls));
- compare_classifiers(&cls, 0, CLS_MIN_VERSION, &tcls);
+ compare_classifiers(&cls, 0, OVS_VERSION_MIN, &tcls);
classifier_destroy(&cls);
tcls_destroy(&tcls);
}
@@ -810,15 +810,15 @@ test_single_rule(struct ovs_cmdl_context *ctx OVS_UNUSED)
tcls_init(&tcls);
tcls_rule = tcls_insert(&tcls, rule);
- classifier_insert(&cls, &rule->cls_rule, CLS_MIN_VERSION, NULL, 0);
- compare_classifiers(&cls, 0, CLS_MIN_VERSION, &tcls);
- check_tables(&cls, 1, 1, 0, 0, CLS_MIN_VERSION);
+ classifier_insert(&cls, &rule->cls_rule, OVS_VERSION_MIN, NULL, 0);
+ compare_classifiers(&cls, 0, OVS_VERSION_MIN, &tcls);
+ check_tables(&cls, 1, 1, 0, 0, OVS_VERSION_MIN);
classifier_remove(&cls, &rule->cls_rule);
tcls_remove(&tcls, tcls_rule);
assert(classifier_is_empty(&cls));
assert(tcls_is_empty(&tcls));
- compare_classifiers(&cls, 0, CLS_MIN_VERSION, &tcls);
+ compare_classifiers(&cls, 0, OVS_VERSION_MIN, &tcls);
ovsrcu_postpone(free_rule, rule);
classifier_destroy(&cls);
@@ -847,20 +847,20 @@ test_rule_replacement(struct ovs_cmdl_context *ctx OVS_UNUSED)
set_prefix_fields(&cls);
tcls_init(&tcls);
tcls_insert(&tcls, rule1);
- classifier_insert(&cls, &rule1->cls_rule, CLS_MIN_VERSION, NULL, 0);
- compare_classifiers(&cls, 0, CLS_MIN_VERSION, &tcls);
- check_tables(&cls, 1, 1, 0, 0, CLS_MIN_VERSION);
+ classifier_insert(&cls, &rule1->cls_rule, OVS_VERSION_MIN, NULL, 0);
+ compare_classifiers(&cls, 0, OVS_VERSION_MIN, &tcls);
+ check_tables(&cls, 1, 1, 0, 0, OVS_VERSION_MIN);
tcls_destroy(&tcls);
tcls_init(&tcls);
tcls_insert(&tcls, rule2);
assert(test_rule_from_cls_rule(
- classifier_replace(&cls, &rule2->cls_rule, CLS_MIN_VERSION,
+ classifier_replace(&cls, &rule2->cls_rule, OVS_VERSION_MIN,
NULL, 0)) == rule1);
ovsrcu_postpone(free_rule, rule1);
- compare_classifiers(&cls, 0, CLS_MIN_VERSION, &tcls);
- check_tables(&cls, 1, 1, 0, 0, CLS_MIN_VERSION);
+ compare_classifiers(&cls, 0, OVS_VERSION_MIN, &tcls);
+ check_tables(&cls, 1, 1, 0, 0, OVS_VERSION_MIN);
classifier_defer(&cls);
classifier_remove(&cls, &rule2->cls_rule);
@@ -950,7 +950,7 @@ test_many_rules_in_one_list (struct ovs_cmdl_context *ctx OVS_UNUSED)
int pri_rules[N_RULES];
struct classifier cls;
struct tcls tcls;
- cls_version_t version = CLS_MIN_VERSION;
+ ovs_version_t version = OVS_VERSION_MIN;
size_t n_invisible_rules = 0;
n_permutations++;
@@ -1095,7 +1095,7 @@ test_many_rules_in_one_table(struct ovs_cmdl_context *ctx OVS_UNUSED)
struct test_rule *tcls_rules[N_RULES];
struct classifier cls;
struct tcls tcls;
- cls_version_t version = CLS_MIN_VERSION;
+ ovs_version_t version = OVS_VERSION_MIN;
size_t n_invisible_rules = 0;
int value_pats[N_RULES];
int value_mask;
@@ -1184,7 +1184,7 @@ test_many_rules_in_n_tables(int n_tables)
int priorities[MAX_RULES];
struct classifier cls;
struct tcls tcls;
- cls_version_t version = CLS_MIN_VERSION;
+ ovs_version_t version = OVS_VERSION_MIN;
size_t n_invisible_rules = 0;
struct ovs_list list = OVS_LIST_INITIALIZER(&list);
@@ -1351,7 +1351,7 @@ static void *
lookup_classifier(void *aux_)
{
struct cls_aux *aux = aux_;
- cls_version_t version = CLS_MIN_VERSION;
+ ovs_version_t version = OVS_VERSION_MIN;
int hits = 0, old_hits;
int misses = 0, old_misses;
size_t i;
@@ -1389,7 +1389,7 @@ static void
benchmark(bool use_wc)
{
struct classifier cls;
- cls_version_t version = CLS_MIN_VERSION;
+ ovs_version_t version = OVS_VERSION_MIN;
struct cls_aux aux;
int *wcfs = xmalloc(n_tables * sizeof *wcfs);
int *priorities = xmalloc(n_priorities * sizeof *priorities);
diff --git a/tests/test-ovn.c b/tests/test-ovn.c
index ffb4e50..707b326 100644
--- a/tests/test-ovn.c
+++ b/tests/test-ovn.c
@@ -1009,7 +1009,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab,
HMAP_FOR_EACH (m, hmap_node, &matches) {
test_rule = xmalloc(sizeof *test_rule);
cls_rule_init(&test_rule->cr, &m->match, 0);
- classifier_insert(&cls, &test_rule->cr, CLS_MIN_VERSION,
+ classifier_insert(&cls, &test_rule->cr, OVS_VERSION_MIN,
m->conjunctions, m->n);
}
}
@@ -1053,7 +1053,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab,
f.regs[n_nvars + i] = ((subst >> (n_nvars * n_bits + i))
& 1);
}
- bool found = classifier_lookup(&cls, CLS_MIN_VERSION,
+ bool found = classifier_lookup(&cls, OVS_VERSION_MIN,
&f, NULL) != NULL;
if (expected != found) {
struct ds expr_s, modified_s;
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 8b02722..e373aa4 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -2867,7 +2867,7 @@ fte_insert(struct flow_tables *tables, const struct match *match,
fte->versions[index] = version;
old = fte_from_cls_rule(classifier_replace(cls, &fte->rule,
- CLS_MIN_VERSION, NULL, 0));
+ OVS_VERSION_MIN, NULL, 0));
if (old) {
fte->versions[!index] = old->versions[!index];
old->versions[!index] = NULL;
--
2.1.4
More information about the dev
mailing list