-/* Copyright (c) 2009, 2010 Nicira Networks
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return json_array_create(clauses, cnd->n_clauses);
}
+static bool
+ovsdb_clause_evaluate(const struct ovsdb_row *row,
+ const struct ovsdb_clause *c)
+{
+ const struct ovsdb_datum *field = &row->fields[c->column->index];
+ const struct ovsdb_datum *arg = &c->arg;
+ const struct ovsdb_type *type = &c->column->type;
+
+ if (ovsdb_type_is_scalar(type)) {
+ int cmp = ovsdb_atom_compare_3way(&field->keys[0], &arg->keys[0],
+ type->key.type);
+ switch (c->function) {
+ case OVSDB_F_LT:
+ return cmp < 0;
+ case OVSDB_F_LE:
+ return cmp <= 0;
+ case OVSDB_F_EQ:
+ case OVSDB_F_INCLUDES:
+ return cmp == 0;
+ case OVSDB_F_NE:
+ case OVSDB_F_EXCLUDES:
+ return cmp != 0;
+ case OVSDB_F_GE:
+ return cmp >= 0;
+ case OVSDB_F_GT:
+ return cmp > 0;
+ }
+ } else {
+ switch (c->function) {
+ case OVSDB_F_EQ:
+ return ovsdb_datum_equals(field, arg, type);
+ case OVSDB_F_NE:
+ return !ovsdb_datum_equals(field, arg, type);
+ case OVSDB_F_INCLUDES:
+ return ovsdb_datum_includes_all(arg, field, type);
+ case OVSDB_F_EXCLUDES:
+ return ovsdb_datum_excludes_all(arg, field, type);
+ case OVSDB_F_LT:
+ case OVSDB_F_LE:
+ case OVSDB_F_GE:
+ case OVSDB_F_GT:
+ NOT_REACHED();
+ }
+ }
+
+ NOT_REACHED();
+}
+
bool
ovsdb_condition_evaluate(const struct ovsdb_row *row,
const struct ovsdb_condition *cnd)
size_t i;
for (i = 0; i < cnd->n_clauses; i++) {
- const struct ovsdb_clause *c = &cnd->clauses[i];
- const struct ovsdb_datum *field = &row->fields[c->column->index];
- const struct ovsdb_datum *arg = &cnd->clauses[i].arg;
- const struct ovsdb_type *type = &c->column->type;
-
- if (ovsdb_type_is_scalar(type)) {
- int cmp = ovsdb_atom_compare_3way(&field->keys[0], &arg->keys[0],
- type->key.type);
- switch (c->function) {
- case OVSDB_F_LT:
- return cmp < 0;
- case OVSDB_F_LE:
- return cmp <= 0;
- case OVSDB_F_EQ:
- case OVSDB_F_INCLUDES:
- return cmp == 0;
- case OVSDB_F_NE:
- case OVSDB_F_EXCLUDES:
- return cmp != 0;
- case OVSDB_F_GE:
- return cmp >= 0;
- case OVSDB_F_GT:
- return cmp > 0;
- }
- } else {
- switch (c->function) {
- case OVSDB_F_EQ:
- return ovsdb_datum_equals(field, arg, type);
- case OVSDB_F_NE:
- return !ovsdb_datum_equals(field, arg, type);
- case OVSDB_F_INCLUDES:
- return ovsdb_datum_includes_all(arg, field, type);
- case OVSDB_F_EXCLUDES:
- return ovsdb_datum_excludes_all(arg, field, type);
- case OVSDB_F_LT:
- case OVSDB_F_LE:
- case OVSDB_F_GE:
- case OVSDB_F_GT:
- NOT_REACHED();
- }
+ if (!ovsdb_clause_evaluate(row, &cnd->clauses[i])) {
+ return false;
}
- NOT_REACHED();
}
return true;
[["i", ">=", 1]],
[["i", ">", 1]],
[["i", "includes", 1]],
- [["i", "excludes", 1]]]' \
+ [["i", "excludes", 1]],
+ [["i", ">", 0], ["i", "<", 2]]]' \
'[{"i": 0},
{"i": 1},
{"i": 2}']]],
condition 4: -TT
condition 5: --T
condition 6: -T-
-condition 7: T-T], [condition])
+condition 7: T-T
+condition 8: -T-], [condition])
OVSDB_CHECK_POSITIVE([evaluating conditions on reals],
[[evaluate-conditions \
[["r", ">=", 5.0]],
[["r", ">", 5.0]],
[["r", "includes", 5.0]],
- [["r", "excludes", 5.0]]]' \
+ [["r", "excludes", 5.0]],
+ [["r", "!=", 0], ["r", "!=", 5.1]]]' \
'[{"r": 0},
{"r": 5.0},
{"r": 5.1}']]],
condition 4: -TT
condition 5: --T
condition 6: -T-
-condition 7: T-T], [condition])
+condition 7: T-T
+condition 8: -T-], [condition])
OVSDB_CHECK_POSITIVE([evaluating conditions on booleans],
[[evaluate-conditions \
[["b", "==", false]],
[["b", "!=", false]],
[["b", "includes", false]],
- [["b", "excludes", false]]]' \
+ [["b", "excludes", false]],
+ [["b", "==", true], ["b", "==", false]]]' \
'[{"b": true},
{"b": false}']]],
[condition 0: T-
condition 4: -T
condition 5: T-
condition 6: -T
-condition 7: T-], [condition])
+condition 7: T-
+condition 8: --], [condition])
OVSDB_CHECK_POSITIVE([evaluating conditions on strings],
[[evaluate-conditions \
[["s", "==", "foo"]],
[["s", "!=", "foo"]],
[["s", "includes", "foo"]],
- [["s", "excludes", "foo"]]]' \
+ [["s", "excludes", "foo"]],
+ [["s", "!=", "foo"], ["s", "!=", ""]]]' \
'[{"s": ""},
{"s": "foo"},
{"s": "xxx"}']]],
condition 4: -T-
condition 5: T-T
condition 6: -T-
-condition 7: T-T], [condition])
+condition 7: T-T
+condition 8: --T], [condition])
OVSDB_CHECK_POSITIVE([evaluating conditions on UUIDs],
[[evaluate-conditions \
[["u", "==", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]]],
[["u", "!=", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]]],
[["u", "includes", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]]],
- [["u", "excludes", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]]]]' \
+ [["u", "excludes", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]]],
+ [["u", "!=", ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]],
+ ["u", "!=", ["uuid", "cb160ed6-92a6-4503-a6aa-a09a09e01f0d"]]]]' \
'[{"u": ["uuid", "8a1dbdb8-416f-4ce9-affa-3332691714b6"]},
{"u": ["uuid", "06151f9d-62d6-4f59-8504-e9765107faa9"]},
{"u": ["uuid", "00000000-0000-0000-0000-000000000000"]}']]],
condition 4: -T-
condition 5: T-T
condition 6: -T-
-condition 7: T-T], [condition])
+condition 7: T-T
+condition 8: T-T], [condition])
OVSDB_CHECK_POSITIVE([evaluating conditions on sets],
[[evaluate-conditions \
[["i", "excludes", ["set", [2]]]],
[["i", "excludes", ["set", [2, 0]]]],
[["i", "excludes", ["set", [2, 1]]]],
- [["i", "excludes", ["set", [2, 1, 0]]]]]' \
+ [["i", "excludes", ["set", [2, 1, 0]]]],
+ [["i", "includes", ["set", [0]]],
+ ["i", "includes", ["set", [1]]]]]' \
'[{"i": ["set", []]},
{"i": ["set", [0]]},
{"i": ["set", [1]]},
condition 28: TTTT- ---
condition 29: T-T-- ---
condition 30: TT--- ---
-condition 31: T---- ---], [condition])
+condition 31: T---- ---
+condition 32: ---T- --T], [condition])
# This is the same as the "set" test except that it adds values,
# all of which always match.
[["i", "excludes", ["map", [[2, true]]]]],
[["i", "excludes", ["map", [[2, true], [0, true]]]]],
[["i", "excludes", ["map", [[2, true], [1, false]]]]],
- [["i", "excludes", ["map", [[2, true], [1, false], [0, true]]]]]]' \
+ [["i", "excludes", ["map", [[2, true], [1, false], [0, true]]]]],
+ [["i", "includes", ["map", [[0, true]]]],
+ ["i", "includes", ["map", [[1, false]]]]]]' \
'[{"i": ["map", []]},
{"i": ["map", [[0, true]]]},
{"i": ["map", [[1, false]]]},
condition 28: TTTT- ---
condition 29: T-T-- ---
condition 30: TT--- ---
-condition 31: T---- ---], [condition])
+condition 31: T---- ---
+condition 32: ---T- --T], [condition])
# This is the same as the "set" test except that it adds values,
# and those values don't always match.
[["i", "excludes", ["map", [[2, true]]]]],
[["i", "excludes", ["map", [[2, true], [0, true]]]]],
[["i", "excludes", ["map", [[2, true], [1, false]]]]],
- [["i", "excludes", ["map", [[2, true], [1, false], [0, true]]]]]]' \
+ [["i", "excludes", ["map", [[2, true], [1, false], [0, true]]]]],
+ [["i", "includes", ["map", [[0, true]]]],
+ ["i", "includes", ["map", [[1, false]]]]]]' \
'[{"i": ["map", []]},
{"i": ["map", [[0, true]]]},
{"i": ["map", [[0, false]]]},
condition 28: TTTTT TT-T- T----
condition 29: T-TTT ---T- -----
condition 30: TTT-T -T-T- T----
-condition 31: T-T-T ---T- -----], [condition])
+condition 31: T-T-T ---T- -----
+condition 32: ----- T---- ---T-], [condition])