2 * Copyright (c) 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
26 #include "command-line.h"
27 #include "dynamic-string.h"
30 #include "ovsdb-data.h"
31 #include "ovsdb-error.h"
32 #include "ovsdb-idl.h"
33 #include "ovsdb-types.h"
34 #include "ovsdb/column.h"
35 #include "ovsdb/condition.h"
36 #include "ovsdb/file.h"
37 #include "ovsdb/log.h"
38 #include "ovsdb/mutation.h"
39 #include "ovsdb/ovsdb.h"
40 #include "ovsdb/query.h"
41 #include "ovsdb/row.h"
42 #include "ovsdb/table.h"
43 #include "ovsdb/transaction.h"
44 #include "ovsdb/trigger.h"
45 #include "poll-loop.h"
48 #include "tests/idltest.h"
53 static struct command all_commands[];
55 static void usage(void) NO_RETURN;
56 static void parse_options(int argc, char *argv[]);
59 main(int argc, char *argv[])
61 set_program_name(argv[0]);
64 parse_options(argc, argv);
65 run_command(argc - optind, argv + optind, all_commands);
70 parse_options(int argc, char *argv[])
72 static struct option long_options[] = {
73 {"timeout", required_argument, 0, 't'},
74 {"verbose", optional_argument, 0, 'v'},
75 {"help", no_argument, 0, 'h'},
78 char *short_options = long_options_to_short_options(long_options);
81 unsigned long int timeout;
84 c = getopt_long(argc, argv, short_options, long_options, NULL);
91 timeout = strtoul(optarg, NULL, 10);
93 ovs_fatal(0, "value %s on -t or --timeout is not at least 1",
104 vlog_set_verbosity(optarg);
120 printf("%s: Open vSwitch database test utility\n"
121 "usage: %s [OPTIONS] COMMAND [ARG...]\n\n"
122 " log-io FILE FLAGS COMMAND...\n"
123 " open FILE with FLAGS, run COMMANDs\n"
124 " parse-atomic-type TYPE\n"
125 " parse TYPE as OVSDB atomic type, and re-serialize\n"
126 " parse-base-type TYPE\n"
127 " parse TYPE as OVSDB base type, and re-serialize\n"
129 " parse JSON as OVSDB type, and re-serialize\n"
130 " parse-atoms TYPE ATOM...\n"
131 " parse JSON ATOMs as atoms of TYPE, and re-serialize\n"
132 " parse-atom-strings TYPE ATOM...\n"
133 " parse string ATOMs as atoms of given TYPE, and re-serialize\n"
134 " sort-atoms TYPE ATOM...\n"
135 " print JSON ATOMs in sorted order\n"
136 " parse-data TYPE DATUM...\n"
137 " parse JSON DATUMs as data of given TYPE, and re-serialize\n"
138 " parse-data-strings TYPE DATUM...\n"
139 " parse string DATUMs as data of given TYPE, and re-serialize\n"
140 " parse-column NAME OBJECT\n"
141 " parse column NAME with info OBJECT, and re-serialize\n"
142 " parse-table NAME OBJECT\n"
143 " parse table NAME with info OBJECT\n"
144 " parse-row TABLE ROW..., and re-serialize\n"
145 " parse each ROW of defined TABLE\n"
146 " compare-row TABLE ROW...\n"
147 " mutually compare all of the ROWs, print those that are equal\n"
148 " parse-conditions TABLE CONDITION...\n"
149 " parse each CONDITION on TABLE, and re-serialize\n"
150 " evaluate-conditions TABLE [CONDITION,...] [ROW,...]\n"
151 " test CONDITIONS on TABLE against each ROW, print results\n"
152 " parse-mutations TABLE MUTATION...\n"
153 " parse each MUTATION on TABLE, and re-serialize\n"
154 " execute-mutations TABLE [MUTATION,...] [ROW,...]\n"
155 " execute MUTATIONS on TABLE on each ROW, print results\n"
156 " query TABLE [ROW,...] [CONDITION,...]\n"
157 " add each ROW to TABLE, then query and print the rows that\n"
158 " satisfy each CONDITION.\n"
159 " query-distinct TABLE [ROW,...] [CONDITION,...] COLUMNS\n"
160 " add each ROW to TABLE, then query and print the rows that\n"
161 " satisfy each CONDITION and have distinct COLUMNS.\n"
162 " parse-schema JSON\n"
163 " parse JSON as an OVSDB schema, and re-serialize\n"
164 " transact COMMAND\n"
165 " execute each specified transactional COMMAND:\n"
172 " execute SCHEMA TRANSACTION...\n"
173 " executes each TRANSACTION on an initially empty database\n"
174 " the specified SCHEMA\n"
175 " trigger SCHEMA TRANSACTION...\n"
176 " executes each TRANSACTION on an initially empty database\n"
177 " the specified SCHEMA. A TRANSACTION of the form\n"
178 " [\"advance\", NUMBER] advances NUMBER milliseconds in\n"
179 " simulated time, for causing triggers to time out.\n"
180 " idl SERVER [TRANSACTION...]\n"
181 " connect to SERVER and dump the contents of the database\n"
182 " as seen initially by the IDL implementation and after\n"
183 " executing each TRANSACTION. (Each TRANSACTION must modify\n"
184 " the database or this command will hang.)\n",
185 program_name, program_name);
187 printf("\nOther options:\n"
188 " -t, --timeout=SECS give up after SECS seconds\n"
189 " -h, --help display this help message\n");
193 /* Command helper functions. */
196 parse_json(const char *s)
198 struct json *json = json_from_string(s);
199 if (json->type == JSON_STRING) {
200 ovs_fatal(0, "\"%s\": %s", s, json->u.string);
206 unbox_json(struct json *json)
208 if (json->type == JSON_ARRAY && json->u.array.n == 1) {
209 struct json *inner = json->u.array.elems[0];
210 json->u.array.elems[0] = NULL;
219 print_and_free_json(struct json *json)
221 char *string = json_to_string(json, JSSF_SORT);
228 print_and_free_ovsdb_error(struct ovsdb_error *error)
230 char *string = ovsdb_error_to_string(error);
231 ovsdb_error_destroy(error);
237 check_ovsdb_error(struct ovsdb_error *error)
240 char *s = ovsdb_error_to_string(error);
241 ovsdb_error_destroy(error);
242 ovs_fatal(0, "%s", s);
247 die_if_error(char *error)
250 ovs_fatal(0, "%s", error);
254 /* Command implementations. */
257 do_log_io(int argc, char *argv[])
259 const char *name = argv[1];
260 char *mode_string = argv[2];
262 struct ovsdb_error *error;
263 enum ovsdb_log_open_mode mode;
264 struct ovsdb_log *log;
267 if (!strcmp(mode_string, "read-only")) {
268 mode = OVSDB_LOG_READ_ONLY;
269 } else if (!strcmp(mode_string, "read/write")) {
270 mode = OVSDB_LOG_READ_WRITE;
271 } else if (!strcmp(mode_string, "create")) {
272 mode = OVSDB_LOG_CREATE;
274 ovs_fatal(0, "unknown log-io open mode \"%s\"", mode_string);
277 check_ovsdb_error(ovsdb_log_open(name, mode, -1, &log));
278 printf("%s: open successful\n", name);
280 for (i = 3; i < argc; i++) {
281 const char *command = argv[i];
282 if (!strcmp(command, "read")) {
285 error = ovsdb_log_read(log, &json);
287 printf("%s: read: ", name);
289 print_and_free_json(json);
291 printf("end of log\n");
295 } else if (!strncmp(command, "write:", 6)) {
296 struct json *json = parse_json(command + 6);
297 error = ovsdb_log_write(log, json);
299 } else if (!strcmp(command, "commit")) {
300 error = ovsdb_log_commit(log);
302 ovs_fatal(0, "unknown log-io command \"%s\"", command);
305 char *s = ovsdb_error_to_string(error);
306 printf("%s: %s failed: %s\n", name, command, s);
308 ovsdb_error_destroy(error);
310 printf("%s: %s successful\n", name, command);
314 ovsdb_log_close(log);
318 do_parse_atomic_type(int argc OVS_UNUSED, char *argv[])
320 enum ovsdb_atomic_type type;
323 json = unbox_json(parse_json(argv[1]));
324 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
326 print_and_free_json(ovsdb_atomic_type_to_json(type));
330 do_parse_base_type(int argc OVS_UNUSED, char *argv[])
332 struct ovsdb_base_type base;
335 json = unbox_json(parse_json(argv[1]));
336 check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
338 print_and_free_json(ovsdb_base_type_to_json(&base));
339 ovsdb_base_type_destroy(&base);
343 do_parse_type(int argc OVS_UNUSED, char *argv[])
345 struct ovsdb_type type;
348 json = unbox_json(parse_json(argv[1]));
349 check_ovsdb_error(ovsdb_type_from_json(&type, json));
351 print_and_free_json(ovsdb_type_to_json(&type));
352 ovsdb_type_destroy(&type);
356 do_parse_atoms(int argc, char *argv[])
358 struct ovsdb_base_type base;
362 json = unbox_json(parse_json(argv[1]));
363 check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
366 for (i = 2; i < argc; i++) {
367 struct ovsdb_error *error;
368 union ovsdb_atom atom;
370 json = unbox_json(parse_json(argv[i]));
371 error = ovsdb_atom_from_json(&atom, &base, json, NULL);
375 print_and_free_ovsdb_error(error);
377 print_and_free_json(ovsdb_atom_to_json(&atom, base.type));
378 ovsdb_atom_destroy(&atom, base.type);
381 ovsdb_base_type_destroy(&base);
385 do_parse_atom_strings(int argc, char *argv[])
387 struct ovsdb_base_type base;
391 json = unbox_json(parse_json(argv[1]));
392 check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
395 for (i = 2; i < argc; i++) {
396 union ovsdb_atom atom;
399 die_if_error(ovsdb_atom_from_string(&atom, &base, argv[i], NULL));
402 ovsdb_atom_to_string(&atom, base.type, &out);
406 ovsdb_atom_destroy(&atom, base.type);
408 ovsdb_base_type_destroy(&base);
412 do_parse_data(int argc, char *argv[])
414 struct ovsdb_type type;
418 json = unbox_json(parse_json(argv[1]));
419 check_ovsdb_error(ovsdb_type_from_json(&type, json));
422 for (i = 2; i < argc; i++) {
423 struct ovsdb_datum datum;
425 json = unbox_json(parse_json(argv[i]));
426 check_ovsdb_error(ovsdb_datum_from_json(&datum, &type, json, NULL));
429 print_and_free_json(ovsdb_datum_to_json(&datum, &type));
431 ovsdb_datum_destroy(&datum, &type);
433 ovsdb_type_destroy(&type);
437 do_parse_data_strings(int argc, char *argv[])
439 struct ovsdb_type type;
443 json = unbox_json(parse_json(argv[1]));
444 check_ovsdb_error(ovsdb_type_from_json(&type, json));
447 for (i = 2; i < argc; i++) {
448 struct ovsdb_datum datum;
451 die_if_error(ovsdb_datum_from_string(&datum, &type, argv[i], NULL));
454 ovsdb_datum_to_string(&datum, &type, &out);
458 ovsdb_datum_destroy(&datum, &type);
460 ovsdb_type_destroy(&type);
463 static enum ovsdb_atomic_type compare_atoms_atomic_type;
466 compare_atoms(const void *a_, const void *b_)
468 const union ovsdb_atom *a = a_;
469 const union ovsdb_atom *b = b_;
471 return ovsdb_atom_compare_3way(a, b, compare_atoms_atomic_type);
475 do_sort_atoms(int argc OVS_UNUSED, char *argv[])
477 struct ovsdb_base_type base;
478 union ovsdb_atom *atoms;
479 struct json *json, **json_atoms;
483 json = unbox_json(parse_json(argv[1]));
484 check_ovsdb_error(ovsdb_base_type_from_json(&base, json));
487 json = unbox_json(parse_json(argv[2]));
488 if (json->type != JSON_ARRAY) {
489 ovs_fatal(0, "second argument must be array");
492 /* Convert JSON atoms to internal representation. */
493 n_atoms = json->u.array.n;
494 atoms = xmalloc(n_atoms * sizeof *atoms);
495 for (i = 0; i < n_atoms; i++) {
496 check_ovsdb_error(ovsdb_atom_from_json(&atoms[i], &base,
497 json->u.array.elems[i], NULL));
502 compare_atoms_atomic_type = base.type;
503 qsort(atoms, n_atoms, sizeof *atoms, compare_atoms);
505 /* Convert internal representation back to JSON. */
506 json_atoms = xmalloc(n_atoms * sizeof *json_atoms);
507 for (i = 0; i < n_atoms; i++) {
508 json_atoms[i] = ovsdb_atom_to_json(&atoms[i], base.type);
509 ovsdb_atom_destroy(&atoms[i], base.type);
511 print_and_free_json(json_array_create(json_atoms, n_atoms));
513 ovsdb_base_type_destroy(&base);
517 do_parse_column(int argc OVS_UNUSED, char *argv[])
519 struct ovsdb_column *column;
522 json = parse_json(argv[2]);
523 check_ovsdb_error(ovsdb_column_from_json(json, argv[1], &column));
525 print_and_free_json(ovsdb_column_to_json(column));
526 ovsdb_column_destroy(column);
530 do_parse_table(int argc OVS_UNUSED, char *argv[])
532 struct ovsdb_table_schema *ts;
535 json = parse_json(argv[2]);
536 check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
538 print_and_free_json(ovsdb_table_schema_to_json(ts));
539 ovsdb_table_schema_destroy(ts);
543 do_parse_rows(int argc, char *argv[])
545 struct ovsdb_column_set all_columns;
546 struct ovsdb_table_schema *ts;
547 struct ovsdb_table *table;
551 json = unbox_json(parse_json(argv[1]));
552 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
555 table = ovsdb_table_create(ts);
556 ovsdb_column_set_init(&all_columns);
557 ovsdb_column_set_add_all(&all_columns, table);
559 for (i = 2; i < argc; i++) {
560 struct ovsdb_column_set columns;
561 struct ovsdb_row *row;
563 ovsdb_column_set_init(&columns);
564 row = ovsdb_row_create(table);
566 json = unbox_json(parse_json(argv[i]));
567 check_ovsdb_error(ovsdb_row_from_json(row, json, NULL, &columns));
570 print_and_free_json(ovsdb_row_to_json(row, &all_columns));
572 if (columns.n_columns) {
578 for (j = 0; j < columns.n_columns; j++) {
579 svec_add(&names, columns.columns[j]->name);
582 s = svec_join(&names, ", ", "");
585 svec_destroy(&names);
590 ovsdb_column_set_destroy(&columns);
591 ovsdb_row_destroy(row);
594 ovsdb_column_set_destroy(&all_columns);
595 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
599 do_compare_rows(int argc, char *argv[])
601 struct ovsdb_column_set all_columns;
602 struct ovsdb_table_schema *ts;
603 struct ovsdb_table *table;
604 struct ovsdb_row **rows;
610 json = unbox_json(parse_json(argv[1]));
611 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
614 table = ovsdb_table_create(ts);
615 ovsdb_column_set_init(&all_columns);
616 ovsdb_column_set_add_all(&all_columns, table);
619 rows = xmalloc(sizeof *rows * n_rows);
620 names = xmalloc(sizeof *names * n_rows);
621 for (i = 0; i < n_rows; i++) {
622 rows[i] = ovsdb_row_create(table);
624 json = parse_json(argv[i + 2]);
625 if (json->type != JSON_ARRAY || json->u.array.n != 2
626 || json->u.array.elems[0]->type != JSON_STRING) {
627 ovs_fatal(0, "\"%s\" does not have expected form "
628 "[\"name\", {data}]", argv[i]);
630 names[i] = xstrdup(json->u.array.elems[0]->u.string);
631 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[1],
635 for (i = 0; i < n_rows; i++) {
636 uint32_t i_hash = ovsdb_row_hash_columns(rows[i], &all_columns, 0);
637 for (j = i + 1; j < n_rows; j++) {
638 uint32_t j_hash = ovsdb_row_hash_columns(rows[j], &all_columns, 0);
639 if (ovsdb_row_equal_columns(rows[i], rows[j], &all_columns)) {
640 printf("%s == %s\n", names[i], names[j]);
641 if (i_hash != j_hash) {
642 printf("but hash(%s) != hash(%s)\n", names[i], names[j]);
645 } else if (i_hash == j_hash) {
646 printf("hash(%s) == hash(%s)\n", names[i], names[j]);
650 for (i = 0; i < n_rows; i++) {
651 ovsdb_row_destroy(rows[i]);
657 ovsdb_column_set_destroy(&all_columns);
658 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
662 do_parse_conditions(int argc, char *argv[])
664 struct ovsdb_table_schema *ts;
669 json = unbox_json(parse_json(argv[1]));
670 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
673 for (i = 2; i < argc; i++) {
674 struct ovsdb_condition cnd;
675 struct ovsdb_error *error;
677 json = parse_json(argv[i]);
678 error = ovsdb_condition_from_json(ts, json, NULL, &cnd);
680 print_and_free_json(ovsdb_condition_to_json(&cnd));
682 char *s = ovsdb_error_to_string(error);
683 ovs_error(0, "%s", s);
685 ovsdb_error_destroy(error);
690 ovsdb_condition_destroy(&cnd);
692 ovsdb_table_schema_destroy(ts);
698 do_evaluate_conditions(int argc OVS_UNUSED, char *argv[])
700 struct ovsdb_table_schema *ts;
701 struct ovsdb_table *table;
702 struct ovsdb_condition *conditions;
704 struct ovsdb_row **rows;
709 /* Parse table schema, create table. */
710 json = unbox_json(parse_json(argv[1]));
711 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
714 table = ovsdb_table_create(ts);
716 /* Parse conditions. */
717 json = parse_json(argv[2]);
718 if (json->type != JSON_ARRAY) {
719 ovs_fatal(0, "CONDITION argument is not JSON array");
721 n_conditions = json->u.array.n;
722 conditions = xmalloc(n_conditions * sizeof *conditions);
723 for (i = 0; i < n_conditions; i++) {
724 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
725 NULL, &conditions[i]));
730 json = parse_json(argv[3]);
731 if (json->type != JSON_ARRAY) {
732 ovs_fatal(0, "ROW argument is not JSON array");
734 n_rows = json->u.array.n;
735 rows = xmalloc(n_rows * sizeof *rows);
736 for (i = 0; i < n_rows; i++) {
737 rows[i] = ovsdb_row_create(table);
738 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
743 for (i = 0; i < n_conditions; i++) {
744 printf("condition %2zu:", i);
745 for (j = 0; j < n_rows; j++) {
746 bool result = ovsdb_condition_evaluate(rows[j], &conditions[i]);
750 putchar(result ? 'T' : '-');
755 for (i = 0; i < n_conditions; i++) {
756 ovsdb_condition_destroy(&conditions[i]);
759 for (i = 0; i < n_rows; i++) {
760 ovsdb_row_destroy(rows[i]);
763 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
767 do_parse_mutations(int argc, char *argv[])
769 struct ovsdb_table_schema *ts;
774 json = unbox_json(parse_json(argv[1]));
775 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
778 for (i = 2; i < argc; i++) {
779 struct ovsdb_mutation_set set;
780 struct ovsdb_error *error;
782 json = parse_json(argv[i]);
783 error = ovsdb_mutation_set_from_json(ts, json, NULL, &set);
785 print_and_free_json(ovsdb_mutation_set_to_json(&set));
787 char *s = ovsdb_error_to_string(error);
788 ovs_error(0, "%s", s);
790 ovsdb_error_destroy(error);
795 ovsdb_mutation_set_destroy(&set);
797 ovsdb_table_schema_destroy(ts);
803 do_execute_mutations(int argc OVS_UNUSED, char *argv[])
805 struct ovsdb_table_schema *ts;
806 struct ovsdb_table *table;
807 struct ovsdb_mutation_set *sets;
809 struct ovsdb_row **rows;
814 /* Parse table schema, create table. */
815 json = unbox_json(parse_json(argv[1]));
816 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
819 table = ovsdb_table_create(ts);
821 /* Parse mutations. */
822 json = parse_json(argv[2]);
823 if (json->type != JSON_ARRAY) {
824 ovs_fatal(0, "MUTATION argument is not JSON array");
826 n_sets = json->u.array.n;
827 sets = xmalloc(n_sets * sizeof *sets);
828 for (i = 0; i < n_sets; i++) {
829 check_ovsdb_error(ovsdb_mutation_set_from_json(ts,
830 json->u.array.elems[i],
836 json = parse_json(argv[3]);
837 if (json->type != JSON_ARRAY) {
838 ovs_fatal(0, "ROW argument is not JSON array");
840 n_rows = json->u.array.n;
841 rows = xmalloc(n_rows * sizeof *rows);
842 for (i = 0; i < n_rows; i++) {
843 rows[i] = ovsdb_row_create(table);
844 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
849 for (i = 0; i < n_sets; i++) {
850 printf("mutation %2zu:\n", i);
851 for (j = 0; j < n_rows; j++) {
852 struct ovsdb_error *error;
853 struct ovsdb_row *row;
855 row = ovsdb_row_clone(rows[j]);
856 error = ovsdb_mutation_set_execute(row, &sets[i]);
858 printf("row %zu: ", j);
860 print_and_free_ovsdb_error(error);
862 struct ovsdb_column_set columns;
863 struct shash_node *node;
865 ovsdb_column_set_init(&columns);
866 SHASH_FOR_EACH (node, &ts->columns) {
867 struct ovsdb_column *c = node->data;
868 if (!ovsdb_datum_equals(&row->fields[c->index],
869 &rows[j]->fields[c->index],
871 ovsdb_column_set_add(&columns, c);
874 if (columns.n_columns) {
875 print_and_free_json(ovsdb_row_to_json(row, &columns));
877 printf("no change\n");
879 ovsdb_column_set_destroy(&columns);
881 ovsdb_row_destroy(row);
886 for (i = 0; i < n_sets; i++) {
887 ovsdb_mutation_set_destroy(&sets[i]);
890 for (i = 0; i < n_rows; i++) {
891 ovsdb_row_destroy(rows[i]);
894 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
897 struct do_query_cbdata {
898 struct uuid *row_uuids;
904 do_query_cb(const struct ovsdb_row *row, void *cbdata_)
906 struct do_query_cbdata *cbdata = cbdata_;
909 for (i = 0; i < cbdata->n_rows; i++) {
910 if (uuid_equals(ovsdb_row_get_uuid(row), &cbdata->row_uuids[i])) {
919 do_query(int argc OVS_UNUSED, char *argv[])
921 struct do_query_cbdata cbdata;
922 struct ovsdb_table_schema *ts;
923 struct ovsdb_table *table;
928 /* Parse table schema, create table. */
929 json = unbox_json(parse_json(argv[1]));
930 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
933 table = ovsdb_table_create(ts);
935 /* Parse rows, add to table. */
936 json = parse_json(argv[2]);
937 if (json->type != JSON_ARRAY) {
938 ovs_fatal(0, "ROW argument is not JSON array");
940 cbdata.n_rows = json->u.array.n;
941 cbdata.row_uuids = xmalloc(cbdata.n_rows * sizeof *cbdata.row_uuids);
942 cbdata.counts = xmalloc(cbdata.n_rows * sizeof *cbdata.counts);
943 for (i = 0; i < cbdata.n_rows; i++) {
944 struct ovsdb_row *row = ovsdb_row_create(table);
945 uuid_generate(ovsdb_row_get_uuid_rw(row));
946 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
948 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
949 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
950 UUID_ARGS(ovsdb_row_get_uuid(row)));
952 cbdata.row_uuids[i] = *ovsdb_row_get_uuid(row);
953 ovsdb_table_put_row(table, row);
957 /* Parse conditions and execute queries. */
958 json = parse_json(argv[3]);
959 if (json->type != JSON_ARRAY) {
960 ovs_fatal(0, "CONDITION argument is not JSON array");
962 for (i = 0; i < json->u.array.n; i++) {
963 struct ovsdb_condition cnd;
966 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
969 memset(cbdata.counts, 0, cbdata.n_rows * sizeof *cbdata.counts);
970 ovsdb_query(table, &cnd, do_query_cb, &cbdata);
972 printf("query %2zu:", i);
973 for (j = 0; j < cbdata.n_rows; j++) {
977 if (cbdata.counts[j]) {
978 printf("%d", cbdata.counts[j]);
979 if (cbdata.counts[j] > 1) {
989 ovsdb_condition_destroy(&cnd);
993 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
998 struct do_query_distinct_class {
999 struct ovsdb_row *example;
1003 struct do_query_distinct_row {
1005 struct do_query_distinct_class *class;
1009 do_query_distinct(int argc OVS_UNUSED, char *argv[])
1011 struct ovsdb_column_set columns;
1012 struct ovsdb_table_schema *ts;
1013 struct ovsdb_table *table;
1014 struct do_query_distinct_row *rows;
1016 struct do_query_distinct_class *classes;
1022 /* Parse table schema, create table. */
1023 json = unbox_json(parse_json(argv[1]));
1024 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
1027 table = ovsdb_table_create(ts);
1029 /* Parse column set. */
1030 json = parse_json(argv[4]);
1031 check_ovsdb_error(ovsdb_column_set_from_json(json, table, &columns));
1034 /* Parse rows, add to table. */
1035 json = parse_json(argv[2]);
1036 if (json->type != JSON_ARRAY) {
1037 ovs_fatal(0, "ROW argument is not JSON array");
1039 n_rows = json->u.array.n;
1040 rows = xmalloc(n_rows * sizeof *rows);
1041 classes = xmalloc(n_rows * sizeof *classes);
1043 for (i = 0; i < n_rows; i++) {
1044 struct ovsdb_row *row;
1048 row = ovsdb_row_create(table);
1049 uuid_generate(ovsdb_row_get_uuid_rw(row));
1050 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
1053 /* Initialize row and find equivalence class. */
1054 rows[i].uuid = *ovsdb_row_get_uuid(row);
1055 rows[i].class = NULL;
1056 for (j = 0; j < n_classes; j++) {
1057 if (ovsdb_row_equal_columns(row, classes[j].example, &columns)) {
1058 rows[i].class = &classes[j];
1062 if (!rows[i].class) {
1063 rows[i].class = &classes[n_classes];
1064 classes[n_classes].example = ovsdb_row_clone(row);
1068 /* Add row to table. */
1069 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
1070 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
1071 UUID_ARGS(ovsdb_row_get_uuid(row)));
1073 ovsdb_table_put_row(table, row);
1078 /* Parse conditions and execute queries. */
1079 json = parse_json(argv[3]);
1080 if (json->type != JSON_ARRAY) {
1081 ovs_fatal(0, "CONDITION argument is not JSON array");
1083 for (i = 0; i < json->u.array.n; i++) {
1084 struct ovsdb_row_set results;
1085 struct ovsdb_condition cnd;
1087 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
1090 for (j = 0; j < n_classes; j++) {
1091 classes[j].count = 0;
1093 ovsdb_row_set_init(&results);
1094 ovsdb_query_distinct(table, &cnd, &columns, &results);
1095 for (j = 0; j < results.n_rows; j++) {
1096 for (k = 0; k < n_rows; k++) {
1097 if (uuid_equals(ovsdb_row_get_uuid(results.rows[j]),
1099 rows[k].class->count++;
1103 ovsdb_row_set_destroy(&results);
1105 printf("query %2zu:", i);
1106 for (j = 0; j < n_rows; j++) {
1107 int count = rows[j].class->count;
1114 printf("%d", count);
1116 } else if (count == 1) {
1117 putchar("abcdefghijklmnopqrstuvwxyz"[rows[j].class - classes]);
1124 ovsdb_condition_destroy(&cnd);
1128 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
1134 do_parse_schema(int argc OVS_UNUSED, char *argv[])
1136 struct ovsdb_schema *schema;
1139 json = parse_json(argv[1]);
1140 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1142 print_and_free_json(ovsdb_schema_to_json(schema));
1143 ovsdb_schema_destroy(schema);
1147 do_execute(int argc OVS_UNUSED, char *argv[])
1149 struct ovsdb_schema *schema;
1154 /* Create database. */
1155 json = parse_json(argv[1]);
1156 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1158 db = ovsdb_create(schema);
1160 for (i = 2; i < argc; i++) {
1161 struct json *params, *result;
1164 params = parse_json(argv[i]);
1165 result = ovsdb_execute(db, params, 0, NULL);
1166 s = json_to_string(result, JSSF_SORT);
1169 json_destroy(params);
1170 json_destroy(result);
1176 struct test_trigger {
1177 struct ovsdb_trigger trigger;
1182 do_trigger_dump(struct test_trigger *t, long long int now, const char *title)
1184 struct json *result;
1187 result = ovsdb_trigger_steal_result(&t->trigger);
1188 s = json_to_string(result, JSSF_SORT);
1189 printf("t=%lld: trigger %d (%s): %s\n", now, t->number, title, s);
1191 json_destroy(result);
1192 ovsdb_trigger_destroy(&t->trigger);
1197 do_trigger(int argc OVS_UNUSED, char *argv[])
1199 struct ovsdb_schema *schema;
1200 struct list completions;
1207 /* Create database. */
1208 json = parse_json(argv[1]);
1209 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1211 db = ovsdb_create(schema);
1213 list_init(&completions);
1216 for (i = 2; i < argc; i++) {
1217 struct json *params = parse_json(argv[i]);
1218 if (params->type == JSON_ARRAY
1219 && json_array(params)->n == 2
1220 && json_array(params)->elems[0]->type == JSON_STRING
1221 && !strcmp(json_string(json_array(params)->elems[0]), "advance")
1222 && json_array(params)->elems[1]->type == JSON_INTEGER) {
1223 now += json_integer(json_array(params)->elems[1]);
1224 json_destroy(params);
1226 struct test_trigger *t = xmalloc(sizeof *t);
1227 ovsdb_trigger_init(db, &t->trigger, params, &completions, now);
1228 t->number = number++;
1229 if (ovsdb_trigger_is_complete(&t->trigger)) {
1230 do_trigger_dump(t, now, "immediate");
1232 printf("t=%lld: new trigger %d\n", now, t->number);
1236 ovsdb_trigger_run(db, now);
1237 while (!list_is_empty(&completions)) {
1238 do_trigger_dump(CONTAINER_OF(list_pop_front(&completions),
1239 struct test_trigger, trigger.node),
1243 ovsdb_trigger_wait(db, now);
1244 poll_immediate_wake();
1252 do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1257 /* "transact" command. */
1259 static struct ovsdb *do_transact_db;
1260 static struct ovsdb_txn *do_transact_txn;
1261 static struct ovsdb_table *do_transact_table;
1264 do_transact_commit(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1266 ovsdb_txn_commit(do_transact_txn, false);
1267 do_transact_txn = NULL;
1271 do_transact_abort(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1273 ovsdb_txn_abort(do_transact_txn);
1274 do_transact_txn = NULL;
1278 uuid_from_integer(int integer, struct uuid *uuid)
1281 uuid->parts[3] = integer;
1284 static const struct ovsdb_row *
1285 do_transact_find_row(const char *uuid_string)
1287 const struct ovsdb_row *row;
1290 uuid_from_integer(atoi(uuid_string), &uuid);
1291 row = ovsdb_table_get_row(do_transact_table, &uuid);
1293 ovs_fatal(0, "table does not contain row with UUID "UUID_FMT,
1300 do_transact_set_integer(struct ovsdb_row *row, const char *column_name,
1303 if (integer != -1) {
1304 const struct ovsdb_column *column;
1306 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1308 row->fields[column->index].keys[0].integer = integer;
1313 do_transact_get_integer(const struct ovsdb_row *row, const char *column_name)
1315 const struct ovsdb_column *column;
1317 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1319 return row->fields[column->index].keys[0].integer;
1323 do_transact_set_i_j(struct ovsdb_row *row,
1324 const char *i_string, const char *j_string)
1326 do_transact_set_integer(row, "i", atoi(i_string));
1327 do_transact_set_integer(row, "j", atoi(j_string));
1331 do_transact_insert(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1333 struct ovsdb_row *row;
1336 row = ovsdb_row_create(do_transact_table);
1339 uuid = ovsdb_row_get_uuid_rw(row);
1340 uuid_from_integer(atoi(argv[1]), uuid);
1341 if (ovsdb_table_get_row(do_transact_table, uuid)) {
1342 ovs_fatal(0, "table already contains row with UUID "UUID_FMT,
1346 do_transact_set_i_j(row, argv[2], argv[3]);
1349 ovsdb_txn_row_insert(do_transact_txn, row);
1353 do_transact_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1355 const struct ovsdb_row *row = do_transact_find_row(argv[1]);
1356 ovsdb_txn_row_delete(do_transact_txn, row);
1360 do_transact_modify(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1362 const struct ovsdb_row *row_ro;
1363 struct ovsdb_row *row_rw;
1365 row_ro = do_transact_find_row(argv[1]);
1366 row_rw = ovsdb_txn_row_modify(do_transact_txn, row_ro);
1367 do_transact_set_i_j(row_rw, argv[2], argv[3]);
1371 compare_rows_by_uuid(const void *a_, const void *b_)
1373 struct ovsdb_row *const *ap = a_;
1374 struct ovsdb_row *const *bp = b_;
1376 return uuid_compare_3way(ovsdb_row_get_uuid(*ap), ovsdb_row_get_uuid(*bp));
1380 do_transact_print(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
1382 const struct ovsdb_row **rows;
1383 const struct ovsdb_row *row;
1387 n_rows = hmap_count(&do_transact_table->rows);
1388 rows = xmalloc(n_rows * sizeof *rows);
1390 HMAP_FOR_EACH (row, struct ovsdb_row, hmap_node,
1391 &do_transact_table->rows) {
1394 assert(i == n_rows);
1396 qsort(rows, n_rows, sizeof *rows, compare_rows_by_uuid);
1398 for (i = 0; i < n_rows; i++) {
1399 printf("\n%"PRId32": i=%d, j=%d",
1400 ovsdb_row_get_uuid(rows[i])->parts[3],
1401 do_transact_get_integer(rows[i], "i"),
1402 do_transact_get_integer(rows[i], "j"));
1409 do_transact(int argc, char *argv[])
1411 static const struct command do_transact_commands[] = {
1412 { "commit", 0, 0, do_transact_commit },
1413 { "abort", 0, 0, do_transact_abort },
1414 { "insert", 2, 3, do_transact_insert },
1415 { "delete", 1, 1, do_transact_delete },
1416 { "modify", 2, 3, do_transact_modify },
1417 { "print", 0, 0, do_transact_print },
1418 { NULL, 0, 0, NULL },
1421 struct ovsdb_schema *schema;
1426 json = parse_json("{\"name\": \"testdb\", "
1430 " {\"i\": {\"type\": \"integer\"}, "
1431 " \"j\": {\"type\": \"integer\"}}}}}");
1432 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1434 do_transact_db = ovsdb_create(schema);
1435 do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
1436 assert(do_transact_table != NULL);
1438 for (i = 1; i < argc; i++) {
1439 struct json *command;
1444 command = parse_json(argv[i]);
1445 if (command->type != JSON_ARRAY) {
1446 ovs_fatal(0, "transaction %d must be JSON array "
1447 "with at least 1 element", i);
1450 n_args = command->u.array.n;
1451 args = xmalloc((n_args + 1) * sizeof *args);
1452 for (j = 0; j < n_args; j++) {
1453 struct json *s = command->u.array.elems[j];
1454 if (s->type != JSON_STRING) {
1455 ovs_fatal(0, "transaction %d argument %d must be JSON string",
1458 args[j] = xstrdup(json_string(s));
1460 args[n_args] = NULL;
1462 if (!do_transact_txn) {
1463 do_transact_txn = ovsdb_txn_create(do_transact_db);
1466 for (j = 0; j < n_args; j++) {
1470 fputs(args[j], stdout);
1473 run_command(n_args, args, do_transact_commands);
1476 for (j = 0; j < n_args; j++) {
1480 json_destroy(command);
1482 ovsdb_txn_abort(do_transact_txn);
1483 ovsdb_destroy(do_transact_db); /* Also destroys 'schema'. */
1487 compare_link1(const void *a_, const void *b_)
1489 const struct idltest_link1 *const *ap = a_;
1490 const struct idltest_link1 *const *bp = b_;
1491 const struct idltest_link1 *a = *ap;
1492 const struct idltest_link1 *b = *bp;
1494 return a->i < b->i ? -1 : a->i > b->i;
1498 print_idl(struct ovsdb_idl *idl, int step)
1500 const struct idltest_simple *s;
1501 const struct idltest_link1 *l1;
1502 const struct idltest_link2 *l2;
1505 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1508 printf("%03d: i=%"PRId64" r=%g b=%s s=%s u="UUID_FMT" ia=[",
1509 step, s->i, s->r, s->b ? "true" : "false",
1510 s->s, UUID_ARGS(&s->u));
1511 for (i = 0; i < s->n_ia; i++) {
1512 printf("%s%"PRId64, i ? " " : "", s->ia[i]);
1515 for (i = 0; i < s->n_ra; i++) {
1516 printf("%s%g", i ? " " : "", s->ra[i]);
1519 for (i = 0; i < s->n_ba; i++) {
1520 printf("%s%s", i ? " " : "", s->ba[i] ? "true" : "false");
1523 for (i = 0; i < s->n_sa; i++) {
1524 printf("%s%s", i ? " " : "", s->sa[i]);
1527 for (i = 0; i < s->n_ua; i++) {
1528 printf("%s"UUID_FMT, i ? " " : "", UUID_ARGS(&s->ua[i]));
1530 printf("] uuid="UUID_FMT"\n", UUID_ARGS(&s->header_.uuid));
1533 IDLTEST_LINK1_FOR_EACH (l1, idl) {
1534 struct idltest_link1 **links;
1537 printf("%03d: i=%"PRId64" k=", step, l1->i);
1539 printf("%"PRId64, l1->k->i);
1542 links = xmemdup(l1->ka, l1->n_ka * sizeof *l1->ka);
1543 qsort(links, l1->n_ka, sizeof *links, compare_link1);
1544 for (i = 0; i < l1->n_ka; i++) {
1545 printf("%s%"PRId64, i ? " " : "", links[i]->i);
1550 printf("%"PRId64, l1->l2->i);
1552 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l1->header_.uuid));
1555 IDLTEST_LINK2_FOR_EACH (l2, idl) {
1556 printf("%03d: i=%"PRId64" l1=", step, l2->i);
1558 printf("%"PRId64, l2->l1->i);
1560 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l2->header_.uuid));
1564 printf("%03d: empty\n", step);
1569 parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
1574 if (json->type == JSON_STRING && uuid_from_string(&uuid, json->u.string)) {
1575 char *name = xasprintf("#%zu#", *n);
1576 fprintf(stderr, "%s = "UUID_FMT"\n", name, UUID_ARGS(&uuid));
1577 ovsdb_symbol_table_put(symtab, name, &uuid, false);
1580 } else if (json->type == JSON_ARRAY) {
1583 for (i = 0; i < json->u.array.n; i++) {
1584 parse_uuids(json->u.array.elems[i], symtab, n);
1586 } else if (json->type == JSON_OBJECT) {
1587 const struct shash_node *node;
1589 SHASH_FOR_EACH (node, json_object(json)) {
1590 parse_uuids(node->data, symtab, n);
1596 substitute_uuids(struct json *json, const struct ovsdb_symbol_table *symtab)
1598 if (json->type == JSON_STRING) {
1599 const struct ovsdb_symbol *symbol;
1601 symbol = ovsdb_symbol_table_get(symtab, json->u.string);
1603 free(json->u.string);
1604 json->u.string = xasprintf(UUID_FMT, UUID_ARGS(&symbol->uuid));
1606 } else if (json->type == JSON_ARRAY) {
1609 for (i = 0; i < json->u.array.n; i++) {
1610 substitute_uuids(json->u.array.elems[i], symtab);
1612 } else if (json->type == JSON_OBJECT) {
1613 const struct shash_node *node;
1615 SHASH_FOR_EACH (node, json_object(json)) {
1616 substitute_uuids(node->data, symtab);
1621 static const struct idltest_simple *
1622 idltest_find_simple(struct ovsdb_idl *idl, int i)
1624 const struct idltest_simple *s;
1626 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1635 idl_set(struct ovsdb_idl *idl, char *commands, int step)
1637 char *cmd, *save_ptr1 = NULL;
1638 struct ovsdb_idl_txn *txn;
1639 enum ovsdb_idl_txn_status status;
1640 bool increment = false;
1642 txn = ovsdb_idl_txn_create(idl);
1643 for (cmd = strtok_r(commands, ",", &save_ptr1); cmd;
1644 cmd = strtok_r(NULL, ",", &save_ptr1)) {
1645 char *save_ptr2 = NULL;
1646 char *name, *arg1, *arg2, *arg3;
1648 name = strtok_r(cmd, " ", &save_ptr2);
1649 arg1 = strtok_r(NULL, " ", &save_ptr2);
1650 arg2 = strtok_r(NULL, " ", &save_ptr2);
1651 arg3 = strtok_r(NULL, " ", &save_ptr2);
1653 if (!strcmp(name, "set")) {
1654 const struct idltest_simple *s;
1657 ovs_fatal(0, "\"set\" command requires 3 arguments");
1660 s = idltest_find_simple(idl, atoi(arg1));
1662 ovs_fatal(0, "\"set\" command asks for nonexistent "
1663 "i=%d", atoi(arg1));
1666 if (!strcmp(arg2, "b")) {
1667 idltest_simple_set_b(s, atoi(arg3));
1668 } else if (!strcmp(arg2, "s")) {
1669 idltest_simple_set_s(s, arg3);
1670 } else if (!strcmp(arg2, "u")) {
1672 uuid_from_string(&uuid, arg3);
1673 idltest_simple_set_u(s, uuid);
1674 } else if (!strcmp(arg2, "r")) {
1675 idltest_simple_set_r(s, atof(arg3));
1677 ovs_fatal(0, "\"set\" command asks for unknown column %s",
1680 } else if (!strcmp(name, "insert")) {
1681 struct idltest_simple *s;
1683 if (!arg1 || arg2) {
1684 ovs_fatal(0, "\"set\" command requires 1 argument");
1687 s = idltest_simple_insert(txn);
1688 idltest_simple_set_i(s, atoi(arg1));
1689 } else if (!strcmp(name, "delete")) {
1690 const struct idltest_simple *s;
1692 if (!arg1 || arg2) {
1693 ovs_fatal(0, "\"set\" command requires 1 argument");
1696 s = idltest_find_simple(idl, atoi(arg1));
1698 ovs_fatal(0, "\"set\" command asks for nonexistent "
1699 "i=%d", atoi(arg1));
1701 idltest_simple_delete(s);
1702 } else if (!strcmp(name, "increment")) {
1703 if (!arg2 || arg3) {
1704 ovs_fatal(0, "\"set\" command requires 2 arguments");
1706 ovsdb_idl_txn_increment(txn, arg1, arg2, NULL);
1709 ovs_fatal(0, "unknown command %s", name);
1713 status = ovsdb_idl_txn_commit_block(txn);
1714 printf("%03d: commit, status=%s",
1715 step, ovsdb_idl_txn_status_to_string(status));
1717 printf(", increment=%"PRId64,
1718 ovsdb_idl_txn_get_increment_new_value(txn));
1721 ovsdb_idl_txn_destroy(txn);
1725 do_idl(int argc, char *argv[])
1727 struct jsonrpc *rpc;
1728 struct ovsdb_idl *idl;
1729 unsigned int seqno = 0;
1730 struct ovsdb_symbol_table *symtab;
1738 idl = ovsdb_idl_create(argv[1], &idltest_idl_class);
1740 struct stream *stream;
1742 error = stream_open_block(jsonrpc_stream_open(argv[1], &stream),
1745 ovs_fatal(error, "failed to connect to \"%s\"", argv[1]);
1747 rpc = jsonrpc_open(stream);
1752 setvbuf(stdout, NULL, _IOLBF, 0);
1754 symtab = ovsdb_symbol_table_create();
1755 for (i = 2; i < argc; i++) {
1756 char *arg = argv[i];
1757 struct jsonrpc_msg *request, *reply;
1761 /* The previous transaction didn't change anything. */
1764 /* Wait for update. */
1765 while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
1768 ovsdb_idl_wait(idl);
1774 print_idl(idl, step++);
1776 seqno = ovsdb_idl_get_seqno(idl);
1778 if (!strcmp(arg, "reconnect")) {
1779 printf("%03d: reconnect\n", step++);
1780 ovsdb_idl_force_reconnect(idl);
1781 } else if (arg[0] != '[') {
1782 idl_set(idl, arg, step++);
1784 struct json *json = parse_json(arg);
1785 substitute_uuids(json, symtab);
1786 request = jsonrpc_create_request("transact", json, NULL);
1787 error = jsonrpc_transact_block(rpc, request, &reply);
1789 ovs_fatal(error, "jsonrpc transaction failed");
1791 printf("%03d: ", step++);
1792 if (reply->result) {
1793 parse_uuids(reply->result, symtab, &n_uuids);
1795 json_destroy(reply->id);
1797 print_and_free_json(jsonrpc_msg_to_json(reply));
1800 ovsdb_symbol_table_destroy(symtab);
1805 while (ovsdb_idl_get_seqno(idl) == seqno && !ovsdb_idl_run(idl)) {
1806 ovsdb_idl_wait(idl);
1809 print_idl(idl, step++);
1810 ovsdb_idl_destroy(idl);
1811 printf("%03d: done\n", step);
1814 static struct command all_commands[] = {
1815 { "log-io", 2, INT_MAX, do_log_io },
1816 { "parse-atomic-type", 1, 1, do_parse_atomic_type },
1817 { "parse-base-type", 1, 1, do_parse_base_type },
1818 { "parse-type", 1, 1, do_parse_type },
1819 { "parse-atoms", 2, INT_MAX, do_parse_atoms },
1820 { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings },
1821 { "parse-data", 2, INT_MAX, do_parse_data },
1822 { "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
1823 { "sort-atoms", 2, 2, do_sort_atoms },
1824 { "parse-column", 2, 2, do_parse_column },
1825 { "parse-table", 2, 2, do_parse_table },
1826 { "parse-rows", 2, INT_MAX, do_parse_rows },
1827 { "compare-rows", 2, INT_MAX, do_compare_rows },
1828 { "parse-conditions", 2, INT_MAX, do_parse_conditions },
1829 { "evaluate-conditions", 3, 3, do_evaluate_conditions },
1830 { "parse-mutations", 2, INT_MAX, do_parse_mutations },
1831 { "execute-mutations", 3, 3, do_execute_mutations },
1832 { "query", 3, 3, do_query },
1833 { "query-distinct", 4, 4, do_query_distinct },
1834 { "transact", 1, INT_MAX, do_transact },
1835 { "parse-schema", 1, 1, do_parse_schema },
1836 { "execute", 2, INT_MAX, do_execute },
1837 { "trigger", 2, INT_MAX, do_trigger },
1838 { "idl", 1, INT_MAX, do_idl },
1839 { "help", 0, INT_MAX, do_help },
1840 { NULL, 0, 0, NULL },