" parse each CONDITION on TABLE, and re-serialize\n"
" evaluate-conditions TABLE [CONDITION,...] [ROW,...]\n"
" test CONDITIONS on TABLE against each ROW, print results\n"
+ " evaluate-conditions-any TABLE [CONDITION,...] [ROW,...]\n"
+ " test CONDITIONS to match any of the CONDITONS on TABLE\n"
+ " against each ROW, print results\n"
+ " compare-conditions TABLE [CONDITION,...]\n"
+ " mutually compare all of the CONDITION, print results for\n"
+ " each pair\n"
" parse-mutations TABLE MUTATION...\n"
" parse each MUTATION on TABLE, and re-serialize\n"
" execute-mutations TABLE [MUTATION,...] [ROW,...]\n"
exit(exit_code);
}
+#define OVSDB_CONDITION_EVERY 0
+#define OVSDB_CONDITION_ANY 1
+
static void
-do_evaluate_conditions(struct ovs_cmdl_context *ctx)
+do_evaluate_condition__(struct ovs_cmdl_context *ctx, int mode)
{
struct ovsdb_table_schema *ts;
struct ovsdb_table *table;
for (i = 0; i < n_conditions; i++) {
printf("condition %2"PRIuSIZE":", i);
for (j = 0; j < n_rows; j++) {
- bool result = ovsdb_condition_evaluate(rows[j], &conditions[i]);
+ bool result;
+ if (mode == OVSDB_CONDITION_EVERY) {
+ result = ovsdb_condition_match_every_clause(rows[j],
+ &conditions[i]);
+ } else {
+ result = ovsdb_condition_match_any_clause(rows[j]->fields,
+ &conditions[i],
+ NULL);
+ }
if (j % 5 == 0) {
putchar(' ');
}
ovsdb_table_destroy(table); /* Also destroys 'ts'. */
}
+static void
+do_evaluate_conditions(struct ovs_cmdl_context *ctx)
+{
+ do_evaluate_condition__(ctx, OVSDB_CONDITION_EVERY);
+}
+
+static void
+do_evaluate_conditions_any(struct ovs_cmdl_context *ctx)
+{
+ do_evaluate_condition__(ctx, OVSDB_CONDITION_ANY);
+}
+
+static void
+do_compare_conditions(struct ovs_cmdl_context *ctx)
+{
+ struct ovsdb_table_schema *ts;
+ struct ovsdb_table *table;
+ struct ovsdb_condition *conditions;
+ size_t n_conditions;
+ struct json *json;
+ size_t i;
+
+ /* Parse table schema, create table. */
+ json = unbox_json(parse_json(ctx->argv[1]));
+ check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
+ json_destroy(json);
+
+ table = ovsdb_table_create(ts);
+
+ /* Parse conditions. */
+ json = parse_json(ctx->argv[2]);
+ if (json->type != JSON_ARRAY) {
+ ovs_fatal(0, "CONDITION argument is not JSON array");
+ }
+ n_conditions = json->u.array.n;
+ conditions = xmalloc(n_conditions * sizeof *conditions);
+
+ for (i = 0; i < n_conditions; i++) {
+ check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
+ NULL, &conditions[i]));
+ }
+ json_destroy(json);
+
+ for (i = 0; i < n_conditions - 1; i++) {
+ int res = ovsdb_condition_cmp_3way(&conditions[i], &conditions[i + 1]);
+ printf("condition %"PRIuSIZE"-%"PRIuSIZE": %d\n", i, i + 1, res);
+ }
+
+ for (i = 0; i < n_conditions; i++) {
+ ovsdb_condition_destroy(&conditions[i]);
+ }
+ free(conditions);
+ ovsdb_table_destroy(table); /* Also destroys 'ts'. */
+}
+
static void
do_parse_mutations(struct ovs_cmdl_context *ctx)
{
/* Insert new elements in different map columns */
myRow = idltest_simple2_first(idl);
myTxn = ovsdb_idl_txn_create(idl);
- smap = idltest_simple2_get_smap(myRow, OVSDB_TYPE_STRING,
+ idltest_simple2_get_smap(myRow, OVSDB_TYPE_STRING,
OVSDB_TYPE_STRING);
idltest_simple2_update_smap_setkey(myRow, "key1", "myList1");
imap = idltest_simple2_get_imap(myRow, OVSDB_TYPE_INTEGER,
{ "compare-rows", NULL, 2, INT_MAX, do_compare_rows },
{ "parse-conditions", NULL, 2, INT_MAX, do_parse_conditions },
{ "evaluate-conditions", NULL, 3, 3, do_evaluate_conditions },
+ { "evaluate-conditions-any", NULL, 3, 3, do_evaluate_conditions_any },
+ { "compare-conditions", NULL, 2, 2, do_compare_conditions },
{ "parse-mutations", NULL, 2, INT_MAX, do_parse_mutations },
{ "execute-mutations", NULL, 3, 3, do_execute_mutations },
{ "query", NULL, 3, 3, do_query },