2 * Copyright (c) 2009 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"
127 " parse JSON as OVSDB type, and re-serialize\n"
128 " parse-atoms TYPE ATOM...\n"
129 " parse JSON ATOMs as atoms of TYPE, and re-serialize\n"
130 " parse-atom-strings TYPE ATOM...\n"
131 " parse string ATOMs as atoms of given TYPE, and re-serialize\n"
132 " sort-atoms TYPE ATOM...\n"
133 " print JSON ATOMs in sorted order\n"
134 " parse-data TYPE DATUM...\n"
135 " parse JSON DATUMs as data of given TYPE, and re-serialize\n"
136 " parse-data-strings TYPE DATUM...\n"
137 " parse string DATUMs as data of given TYPE, and re-serialize\n"
138 " parse-column NAME OBJECT\n"
139 " parse column NAME with info OBJECT, and re-serialize\n"
140 " parse-table NAME OBJECT\n"
141 " parse table NAME with info OBJECT\n"
142 " parse-row TABLE ROW..., and re-serialize\n"
143 " parse each ROW of defined TABLE\n"
144 " compare-row TABLE ROW...\n"
145 " mutually compare all of the ROWs, print those that are equal\n"
146 " parse-conditions TABLE CONDITION...\n"
147 " parse each CONDITION on TABLE, and re-serialize\n"
148 " evaluate-conditions TABLE [CONDITION,...] [ROW,...]\n"
149 " test CONDITIONS on TABLE against each ROW, print results\n"
150 " parse-mutations TABLE MUTATION...\n"
151 " parse each MUTATION on TABLE, and re-serialize\n"
152 " execute-mutations TABLE [MUTATION,...] [ROW,...]\n"
153 " execute MUTATIONS on TABLE on each ROW, print results\n"
154 " query TABLE [ROW,...] [CONDITION,...]\n"
155 " add each ROW to TABLE, then query and print the rows that\n"
156 " satisfy each CONDITION.\n"
157 " query-distinct TABLE [ROW,...] [CONDITION,...] COLUMNS\n"
158 " add each ROW to TABLE, then query and print the rows that\n"
159 " satisfy each CONDITION and have distinct COLUMNS.\n"
160 " transact COMMAND\n"
161 " execute each specified transactional COMMAND:\n"
168 " execute SCHEMA TRANSACTION...\n"
169 " executes each TRANSACTION on an initially empty database\n"
170 " the specified SCHEMA\n"
171 " trigger SCHEMA TRANSACTION...\n"
172 " executes each TRANSACTION on an initially empty database\n"
173 " the specified SCHEMA. A TRANSACTION of the form\n"
174 " [\"advance\", NUMBER] advances NUMBER milliseconds in\n"
175 " simulated time, for causing triggers to time out.\n"
176 " idl SERVER [TRANSACTION...]\n"
177 " connect to SERVER and dump the contents of the database\n"
178 " as seen initially by the IDL implementation and after\n"
179 " executing each TRANSACTION. (Each TRANSACTION must modify\n"
180 " the database or this command will hang.)\n",
181 program_name, program_name);
183 printf("\nOther options:\n"
184 " -t, --timeout=SECS give up after SECS seconds\n"
185 " -h, --help display this help message\n");
189 /* Command helper functions. */
192 parse_json(const char *s)
194 struct json *json = json_from_string(s);
195 if (json->type == JSON_STRING) {
196 ovs_fatal(0, "\"%s\": %s", s, json->u.string);
202 unbox_json(struct json *json)
204 if (json->type == JSON_ARRAY && json->u.array.n == 1) {
205 struct json *inner = json->u.array.elems[0];
206 json->u.array.elems[0] = NULL;
215 print_and_free_json(struct json *json)
217 char *string = json_to_string(json, JSSF_SORT);
224 print_and_free_ovsdb_error(struct ovsdb_error *error)
226 char *string = ovsdb_error_to_string(error);
227 ovsdb_error_destroy(error);
233 check_ovsdb_error(struct ovsdb_error *error)
236 ovs_fatal(0, "%s", ovsdb_error_to_string(error));
241 die_if_error(char *error)
244 ovs_fatal(0, "%s", error);
248 /* Command implementations. */
251 do_log_io(int argc, char *argv[])
253 const char *name = argv[1];
254 char *mode = argv[2];
256 struct ovsdb_error *error;
257 struct ovsdb_log *log;
258 char *save_ptr = NULL;
263 for (flags = 0, token = strtok_r(mode, " |", &save_ptr); token != NULL;
264 token = strtok_r(NULL, " |", &save_ptr))
266 if (!strcmp(token, "O_RDONLY")) {
268 } else if (!strcmp(token, "O_RDWR")) {
270 } else if (!strcmp(token, "O_TRUNC")) {
272 } else if (!strcmp(token, "O_CREAT")) {
274 } else if (!strcmp(token, "O_EXCL")) {
276 } else if (!strcmp(token, "O_TRUNC")) {
281 check_ovsdb_error(ovsdb_log_open(name, flags, &log));
282 printf("%s: open successful\n", name);
284 for (i = 3; i < argc; i++) {
285 const char *command = argv[i];
286 if (!strcmp(command, "read")) {
289 error = ovsdb_log_read(log, &json);
291 printf("%s: read: ", name);
293 print_and_free_json(json);
295 printf("end of log\n");
299 } else if (!strncmp(command, "write:", 6)) {
300 struct json *json = parse_json(command + 6);
301 error = ovsdb_log_write(log, json);
303 } else if (!strcmp(command, "commit")) {
304 error = ovsdb_log_commit(log);
306 ovs_fatal(0, "unknown log-io command \"%s\"", command);
309 char *s = ovsdb_error_to_string(error);
310 printf("%s: %s failed: %s\n", name, command, s);
313 printf("%s: %s successful\n", name, command);
317 ovsdb_log_close(log);
321 do_parse_atomic_type(int argc UNUSED, char *argv[])
323 enum ovsdb_atomic_type type;
326 json = unbox_json(parse_json(argv[1]));
327 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
329 print_and_free_json(ovsdb_atomic_type_to_json(type));
333 do_parse_type(int argc UNUSED, char *argv[])
335 struct ovsdb_type type;
338 json = unbox_json(parse_json(argv[1]));
339 check_ovsdb_error(ovsdb_type_from_json(&type, json));
341 print_and_free_json(ovsdb_type_to_json(&type));
345 do_parse_atoms(int argc, char *argv[])
347 enum ovsdb_atomic_type type;
351 json = unbox_json(parse_json(argv[1]));
352 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
355 for (i = 2; i < argc; i++) {
356 union ovsdb_atom atom;
358 json = unbox_json(parse_json(argv[i]));
359 check_ovsdb_error(ovsdb_atom_from_json(&atom, type, json, NULL));
362 print_and_free_json(ovsdb_atom_to_json(&atom, type));
364 ovsdb_atom_destroy(&atom, type);
369 do_parse_atom_strings(int argc, char *argv[])
371 enum ovsdb_atomic_type type;
375 json = unbox_json(parse_json(argv[1]));
376 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
379 for (i = 2; i < argc; i++) {
380 union ovsdb_atom atom;
383 die_if_error(ovsdb_atom_from_string(&atom, type, argv[i]));
386 ovsdb_atom_to_string(&atom, type, &out);
390 ovsdb_atom_destroy(&atom, type);
395 do_parse_data(int argc, char *argv[])
397 struct ovsdb_type type;
401 json = unbox_json(parse_json(argv[1]));
402 check_ovsdb_error(ovsdb_type_from_json(&type, json));
405 for (i = 2; i < argc; i++) {
406 struct ovsdb_datum datum;
408 json = unbox_json(parse_json(argv[i]));
409 check_ovsdb_error(ovsdb_datum_from_json(&datum, &type, json, NULL));
412 print_and_free_json(ovsdb_datum_to_json(&datum, &type));
414 ovsdb_datum_destroy(&datum, &type);
419 do_parse_data_strings(int argc, char *argv[])
421 struct ovsdb_type type;
425 json = unbox_json(parse_json(argv[1]));
426 check_ovsdb_error(ovsdb_type_from_json(&type, json));
429 for (i = 2; i < argc; i++) {
430 struct ovsdb_datum datum;
433 die_if_error(ovsdb_datum_from_string(&datum, &type, argv[i]));
436 ovsdb_datum_to_string(&datum, &type, &out);
440 ovsdb_datum_destroy(&datum, &type);
444 static enum ovsdb_atomic_type compare_atoms_atomic_type;
447 compare_atoms(const void *a_, const void *b_)
449 const union ovsdb_atom *a = a_;
450 const union ovsdb_atom *b = b_;
452 return ovsdb_atom_compare_3way(a, b, compare_atoms_atomic_type);
456 do_sort_atoms(int argc UNUSED, char *argv[])
458 enum ovsdb_atomic_type type;
459 union ovsdb_atom *atoms;
460 struct json *json, **json_atoms;
464 json = unbox_json(parse_json(argv[1]));
465 check_ovsdb_error(ovsdb_atomic_type_from_json(&type, json));
468 json = unbox_json(parse_json(argv[2]));
469 if (json->type != JSON_ARRAY) {
470 ovs_fatal(0, "second argument must be array");
473 /* Convert JSON atoms to internal representation. */
474 n_atoms = json->u.array.n;
475 atoms = xmalloc(n_atoms * sizeof *atoms);
476 for (i = 0; i < n_atoms; i++) {
477 check_ovsdb_error(ovsdb_atom_from_json(&atoms[i], type,
478 json->u.array.elems[i], NULL));
483 compare_atoms_atomic_type = type;
484 qsort(atoms, n_atoms, sizeof *atoms, compare_atoms);
486 /* Convert internal representation back to JSON. */
487 json_atoms = xmalloc(n_atoms * sizeof *json_atoms);
488 for (i = 0; i < n_atoms; i++) {
489 json_atoms[i] = ovsdb_atom_to_json(&atoms[i], type);
490 ovsdb_atom_destroy(&atoms[i], type);
492 print_and_free_json(json_array_create(json_atoms, n_atoms));
496 do_parse_column(int argc UNUSED, char *argv[])
498 struct ovsdb_column *column;
501 json = parse_json(argv[2]);
502 check_ovsdb_error(ovsdb_column_from_json(json, argv[1], &column));
504 print_and_free_json(ovsdb_column_to_json(column));
505 ovsdb_column_destroy(column);
509 do_parse_table(int argc UNUSED, char *argv[])
511 struct ovsdb_table_schema *ts;
514 json = parse_json(argv[2]);
515 check_ovsdb_error(ovsdb_table_schema_from_json(json, argv[1], &ts));
517 print_and_free_json(ovsdb_table_schema_to_json(ts));
518 ovsdb_table_schema_destroy(ts);
522 do_parse_rows(int argc, char *argv[])
524 struct ovsdb_column_set all_columns;
525 struct ovsdb_table_schema *ts;
526 struct ovsdb_table *table;
530 json = unbox_json(parse_json(argv[1]));
531 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
534 table = ovsdb_table_create(ts);
535 ovsdb_column_set_init(&all_columns);
536 ovsdb_column_set_add_all(&all_columns, table);
538 for (i = 2; i < argc; i++) {
539 struct ovsdb_column_set columns;
540 struct ovsdb_row *row;
542 ovsdb_column_set_init(&columns);
543 row = ovsdb_row_create(table);
545 json = unbox_json(parse_json(argv[i]));
546 check_ovsdb_error(ovsdb_row_from_json(row, json, NULL, &columns));
549 print_and_free_json(ovsdb_row_to_json(row, &all_columns));
551 if (columns.n_columns) {
557 for (j = 0; j < columns.n_columns; j++) {
558 svec_add(&names, columns.columns[j]->name);
561 s = svec_join(&names, ", ", "");
564 svec_destroy(&names);
569 ovsdb_column_set_destroy(&columns);
570 ovsdb_row_destroy(row);
573 ovsdb_column_set_destroy(&all_columns);
574 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
578 do_compare_rows(int argc, char *argv[])
580 struct ovsdb_column_set all_columns;
581 struct ovsdb_table_schema *ts;
582 struct ovsdb_table *table;
583 struct ovsdb_row **rows;
589 json = unbox_json(parse_json(argv[1]));
590 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
593 table = ovsdb_table_create(ts);
594 ovsdb_column_set_init(&all_columns);
595 ovsdb_column_set_add_all(&all_columns, table);
598 rows = xmalloc(sizeof *rows * n_rows);
599 names = xmalloc(sizeof *names * n_rows);
600 for (i = 0; i < n_rows; i++) {
601 rows[i] = ovsdb_row_create(table);
603 json = parse_json(argv[i + 2]);
604 if (json->type != JSON_ARRAY || json->u.array.n != 2
605 || json->u.array.elems[0]->type != JSON_STRING) {
606 ovs_fatal(0, "\"%s\" does not have expected form "
607 "[\"name\", {data}]", argv[i]);
609 names[i] = xstrdup(json->u.array.elems[0]->u.string);
610 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[1],
614 for (i = 0; i < n_rows; i++) {
615 uint32_t i_hash = ovsdb_row_hash_columns(rows[i], &all_columns, 0);
616 for (j = i + 1; j < n_rows; j++) {
617 uint32_t j_hash = ovsdb_row_hash_columns(rows[j], &all_columns, 0);
618 if (ovsdb_row_equal_columns(rows[i], rows[j], &all_columns)) {
619 printf("%s == %s\n", names[i], names[j]);
620 if (i_hash != j_hash) {
621 printf("but hash(%s) != hash(%s)\n", names[i], names[j]);
624 } else if (i_hash == j_hash) {
625 printf("hash(%s) == hash(%s)\n", names[i], names[j]);
632 ovsdb_column_set_destroy(&all_columns);
633 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
637 do_parse_conditions(int argc, char *argv[])
639 struct ovsdb_table_schema *ts;
644 json = unbox_json(parse_json(argv[1]));
645 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
648 for (i = 2; i < argc; i++) {
649 struct ovsdb_condition cnd;
650 struct ovsdb_error *error;
652 json = parse_json(argv[i]);
653 error = ovsdb_condition_from_json(ts, json, NULL, &cnd);
655 print_and_free_json(ovsdb_condition_to_json(&cnd));
657 char *s = ovsdb_error_to_string(error);
658 ovs_error(0, "%s", s);
660 ovsdb_error_destroy(error);
665 ovsdb_condition_destroy(&cnd);
667 ovsdb_table_schema_destroy(ts);
673 do_evaluate_conditions(int argc UNUSED, char *argv[])
675 struct ovsdb_table_schema *ts;
676 struct ovsdb_table *table;
677 struct ovsdb_condition *conditions;
679 struct ovsdb_row **rows;
684 /* Parse table schema, create table. */
685 json = unbox_json(parse_json(argv[1]));
686 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
689 table = ovsdb_table_create(ts);
691 /* Parse conditions. */
692 json = parse_json(argv[2]);
693 if (json->type != JSON_ARRAY) {
694 ovs_fatal(0, "CONDITION argument is not JSON array");
696 n_conditions = json->u.array.n;
697 conditions = xmalloc(n_conditions * sizeof *conditions);
698 for (i = 0; i < n_conditions; i++) {
699 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
700 NULL, &conditions[i]));
705 json = parse_json(argv[3]);
706 if (json->type != JSON_ARRAY) {
707 ovs_fatal(0, "ROW argument is not JSON array");
709 n_rows = json->u.array.n;
710 rows = xmalloc(n_rows * sizeof *rows);
711 for (i = 0; i < n_rows; i++) {
712 rows[i] = ovsdb_row_create(table);
713 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
718 for (i = 0; i < n_conditions; i++) {
719 printf("condition %2d:", i);
720 for (j = 0; j < n_rows; j++) {
721 bool result = ovsdb_condition_evaluate(rows[j], &conditions[i]);
725 putchar(result ? 'T' : '-');
730 for (i = 0; i < n_conditions; i++) {
731 ovsdb_condition_destroy(&conditions[i]);
733 for (i = 0; i < n_rows; i++) {
734 ovsdb_row_destroy(rows[i]);
736 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
740 do_parse_mutations(int argc, char *argv[])
742 struct ovsdb_table_schema *ts;
747 json = unbox_json(parse_json(argv[1]));
748 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
751 for (i = 2; i < argc; i++) {
752 struct ovsdb_mutation_set set;
753 struct ovsdb_error *error;
755 json = parse_json(argv[i]);
756 error = ovsdb_mutation_set_from_json(ts, json, NULL, &set);
758 print_and_free_json(ovsdb_mutation_set_to_json(&set));
760 char *s = ovsdb_error_to_string(error);
761 ovs_error(0, "%s", s);
763 ovsdb_error_destroy(error);
768 ovsdb_mutation_set_destroy(&set);
770 ovsdb_table_schema_destroy(ts);
776 do_execute_mutations(int argc UNUSED, char *argv[])
778 struct ovsdb_table_schema *ts;
779 struct ovsdb_table *table;
780 struct ovsdb_mutation_set *sets;
782 struct ovsdb_row **rows;
787 /* Parse table schema, create table. */
788 json = unbox_json(parse_json(argv[1]));
789 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
792 table = ovsdb_table_create(ts);
794 /* Parse mutations. */
795 json = parse_json(argv[2]);
796 if (json->type != JSON_ARRAY) {
797 ovs_fatal(0, "MUTATION argument is not JSON array");
799 n_sets = json->u.array.n;
800 sets = xmalloc(n_sets * sizeof *sets);
801 for (i = 0; i < n_sets; i++) {
802 check_ovsdb_error(ovsdb_mutation_set_from_json(ts,
803 json->u.array.elems[i],
809 json = parse_json(argv[3]);
810 if (json->type != JSON_ARRAY) {
811 ovs_fatal(0, "ROW argument is not JSON array");
813 n_rows = json->u.array.n;
814 rows = xmalloc(n_rows * sizeof *rows);
815 for (i = 0; i < n_rows; i++) {
816 rows[i] = ovsdb_row_create(table);
817 check_ovsdb_error(ovsdb_row_from_json(rows[i], json->u.array.elems[i],
822 for (i = 0; i < n_sets; i++) {
823 printf("mutation %2d:\n", i);
824 for (j = 0; j < n_rows; j++) {
825 struct ovsdb_error *error;
826 struct ovsdb_row *row;
828 row = ovsdb_row_clone(rows[j]);
829 error = ovsdb_mutation_set_execute(row, &sets[i]);
831 printf("row %zu: ", j);
833 print_and_free_ovsdb_error(error);
835 struct ovsdb_column_set columns;
836 struct shash_node *node;
838 ovsdb_column_set_init(&columns);
839 SHASH_FOR_EACH (node, &ts->columns) {
840 struct ovsdb_column *c = node->data;
841 if (!ovsdb_datum_equals(&row->fields[c->index],
842 &rows[j]->fields[c->index],
844 ovsdb_column_set_add(&columns, c);
847 if (columns.n_columns) {
848 print_and_free_json(ovsdb_row_to_json(row, &columns));
850 printf("no change\n");
852 ovsdb_column_set_destroy(&columns);
854 ovsdb_row_destroy(row);
859 for (i = 0; i < n_sets; i++) {
860 ovsdb_mutation_set_destroy(&sets[i]);
862 for (i = 0; i < n_rows; i++) {
863 ovsdb_row_destroy(rows[i]);
865 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
868 struct do_query_cbdata {
869 struct uuid *row_uuids;
875 do_query_cb(const struct ovsdb_row *row, void *cbdata_)
877 struct do_query_cbdata *cbdata = cbdata_;
880 for (i = 0; i < cbdata->n_rows; i++) {
881 if (uuid_equals(ovsdb_row_get_uuid(row), &cbdata->row_uuids[i])) {
890 do_query(int argc UNUSED, char *argv[])
892 struct do_query_cbdata cbdata;
893 struct ovsdb_table_schema *ts;
894 struct ovsdb_table *table;
899 /* Parse table schema, create table. */
900 json = unbox_json(parse_json(argv[1]));
901 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
904 table = ovsdb_table_create(ts);
906 /* Parse rows, add to table. */
907 json = parse_json(argv[2]);
908 if (json->type != JSON_ARRAY) {
909 ovs_fatal(0, "ROW argument is not JSON array");
911 cbdata.n_rows = json->u.array.n;
912 cbdata.row_uuids = xmalloc(cbdata.n_rows * sizeof *cbdata.row_uuids);
913 cbdata.counts = xmalloc(cbdata.n_rows * sizeof *cbdata.counts);
914 for (i = 0; i < cbdata.n_rows; i++) {
915 struct ovsdb_row *row = ovsdb_row_create(table);
916 uuid_generate(ovsdb_row_get_uuid_rw(row));
917 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
919 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
920 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
921 UUID_ARGS(ovsdb_row_get_uuid(row)));
923 cbdata.row_uuids[i] = *ovsdb_row_get_uuid(row);
924 ovsdb_table_put_row(table, row);
928 /* Parse conditions and execute queries. */
929 json = parse_json(argv[3]);
930 if (json->type != JSON_ARRAY) {
931 ovs_fatal(0, "CONDITION argument is not JSON array");
933 for (i = 0; i < json->u.array.n; i++) {
934 struct ovsdb_condition cnd;
937 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
940 memset(cbdata.counts, 0, cbdata.n_rows * sizeof *cbdata.counts);
941 ovsdb_query(table, &cnd, do_query_cb, &cbdata);
943 printf("query %2d:", i);
944 for (j = 0; j < cbdata.n_rows; j++) {
948 if (cbdata.counts[j]) {
949 printf("%d", cbdata.counts[j]);
950 if (cbdata.counts[j] > 1) {
960 ovsdb_condition_destroy(&cnd);
964 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
969 struct do_query_distinct_class {
970 struct ovsdb_row *example;
974 struct do_query_distinct_row {
976 struct do_query_distinct_class *class;
980 do_query_distinct(int argc UNUSED, char *argv[])
982 struct ovsdb_column_set columns;
983 struct ovsdb_table_schema *ts;
984 struct ovsdb_table *table;
985 struct do_query_distinct_row *rows;
987 struct do_query_distinct_class *classes;
993 /* Parse table schema, create table. */
994 json = unbox_json(parse_json(argv[1]));
995 check_ovsdb_error(ovsdb_table_schema_from_json(json, "mytable", &ts));
998 table = ovsdb_table_create(ts);
1000 /* Parse column set. */
1001 json = parse_json(argv[4]);
1002 check_ovsdb_error(ovsdb_column_set_from_json(json, table, &columns));
1005 /* Parse rows, add to table. */
1006 json = parse_json(argv[2]);
1007 if (json->type != JSON_ARRAY) {
1008 ovs_fatal(0, "ROW argument is not JSON array");
1010 n_rows = json->u.array.n;
1011 rows = xmalloc(n_rows * sizeof *rows);
1012 classes = xmalloc(n_rows * sizeof *classes);
1014 for (i = 0; i < n_rows; i++) {
1015 struct ovsdb_row *row;
1019 row = ovsdb_row_create(table);
1020 uuid_generate(ovsdb_row_get_uuid_rw(row));
1021 check_ovsdb_error(ovsdb_row_from_json(row, json->u.array.elems[i],
1024 /* Initialize row and find equivalence class. */
1025 rows[i].uuid = *ovsdb_row_get_uuid(row);
1026 rows[i].class = NULL;
1027 for (j = 0; j < n_classes; j++) {
1028 if (ovsdb_row_equal_columns(row, classes[j].example, &columns)) {
1029 rows[i].class = &classes[j];
1033 if (!rows[i].class) {
1034 rows[i].class = &classes[n_classes];
1035 classes[n_classes].example = ovsdb_row_clone(row);
1039 /* Add row to table. */
1040 if (ovsdb_table_get_row(table, ovsdb_row_get_uuid(row))) {
1041 ovs_fatal(0, "duplicate UUID "UUID_FMT" in table",
1042 UUID_ARGS(ovsdb_row_get_uuid(row)));
1044 ovsdb_table_put_row(table, row);
1049 /* Parse conditions and execute queries. */
1050 json = parse_json(argv[3]);
1051 if (json->type != JSON_ARRAY) {
1052 ovs_fatal(0, "CONDITION argument is not JSON array");
1054 for (i = 0; i < json->u.array.n; i++) {
1055 struct ovsdb_row_set results;
1056 struct ovsdb_condition cnd;
1058 check_ovsdb_error(ovsdb_condition_from_json(ts, json->u.array.elems[i],
1061 for (j = 0; j < n_classes; j++) {
1062 classes[j].count = 0;
1064 ovsdb_row_set_init(&results);
1065 ovsdb_query_distinct(table, &cnd, &columns, &results);
1066 for (j = 0; j < results.n_rows; j++) {
1067 for (k = 0; k < n_rows; k++) {
1068 if (uuid_equals(ovsdb_row_get_uuid(results.rows[j]),
1070 rows[k].class->count++;
1074 ovsdb_row_set_destroy(&results);
1076 printf("query %2d:", i);
1077 for (j = 0; j < n_rows; j++) {
1078 int count = rows[j].class->count;
1085 printf("%d", count);
1087 } else if (count == 1) {
1088 putchar("abcdefghijklmnopqrstuvwxyz"[rows[j].class - classes]);
1095 ovsdb_condition_destroy(&cnd);
1099 ovsdb_table_destroy(table); /* Also destroys 'ts'. */
1105 do_execute(int argc UNUSED, char *argv[])
1107 struct ovsdb_schema *schema;
1112 /* Create database. */
1113 json = parse_json(argv[1]);
1114 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1116 db = ovsdb_create(schema);
1118 for (i = 2; i < argc; i++) {
1119 struct json *params, *result;
1122 params = parse_json(argv[i]);
1123 result = ovsdb_execute(db, params, 0, NULL);
1124 s = json_to_string(result, JSSF_SORT);
1126 json_destroy(params);
1127 json_destroy(result);
1133 struct test_trigger {
1134 struct ovsdb_trigger trigger;
1139 do_trigger_dump(struct test_trigger *t, long long int now, const char *title)
1141 struct json *result;
1144 result = ovsdb_trigger_steal_result(&t->trigger);
1145 s = json_to_string(result, JSSF_SORT);
1146 printf("t=%lld: trigger %d (%s): %s\n", now, t->number, title, s);
1147 json_destroy(result);
1148 ovsdb_trigger_destroy(&t->trigger);
1153 do_trigger(int argc UNUSED, char *argv[])
1155 struct ovsdb_schema *schema;
1156 struct list completions;
1163 /* Create database. */
1164 json = parse_json(argv[1]);
1165 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1167 db = ovsdb_create(schema);
1169 list_init(&completions);
1172 for (i = 2; i < argc; i++) {
1173 struct json *params = parse_json(argv[i]);
1174 if (params->type == JSON_ARRAY
1175 && json_array(params)->n == 2
1176 && json_array(params)->elems[0]->type == JSON_STRING
1177 && !strcmp(json_string(json_array(params)->elems[0]), "advance")
1178 && json_array(params)->elems[1]->type == JSON_INTEGER) {
1179 now += json_integer(json_array(params)->elems[1]);
1180 json_destroy(params);
1182 struct test_trigger *t = xmalloc(sizeof *t);
1183 ovsdb_trigger_init(db, &t->trigger, params, &completions, now);
1184 t->number = number++;
1185 if (ovsdb_trigger_is_complete(&t->trigger)) {
1186 do_trigger_dump(t, now, "immediate");
1188 printf("t=%lld: new trigger %d\n", now, t->number);
1192 ovsdb_trigger_run(db, now);
1193 while (!list_is_empty(&completions)) {
1194 do_trigger_dump(CONTAINER_OF(list_pop_front(&completions),
1195 struct test_trigger, trigger.node),
1199 ovsdb_trigger_wait(db, now);
1200 poll_immediate_wake();
1208 do_help(int argc UNUSED, char *argv[] UNUSED)
1213 /* "transact" command. */
1215 static struct ovsdb *do_transact_db;
1216 static struct ovsdb_txn *do_transact_txn;
1217 static struct ovsdb_table *do_transact_table;
1220 do_transact_commit(int argc UNUSED, char *argv[] UNUSED)
1222 ovsdb_txn_commit(do_transact_txn, false);
1223 do_transact_txn = NULL;
1227 do_transact_abort(int argc UNUSED, char *argv[] UNUSED)
1229 ovsdb_txn_abort(do_transact_txn);
1230 do_transact_txn = NULL;
1234 uuid_from_integer(int integer, struct uuid *uuid)
1237 uuid->parts[3] = integer;
1240 static const struct ovsdb_row *
1241 do_transact_find_row(const char *uuid_string)
1243 const struct ovsdb_row *row;
1246 uuid_from_integer(atoi(uuid_string), &uuid);
1247 row = ovsdb_table_get_row(do_transact_table, &uuid);
1249 ovs_fatal(0, "table does not contain row with UUID "UUID_FMT,
1256 do_transact_set_integer(struct ovsdb_row *row, const char *column_name,
1259 if (integer != -1) {
1260 const struct ovsdb_column *column;
1262 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1264 row->fields[column->index].keys[0].integer = integer;
1269 do_transact_get_integer(const struct ovsdb_row *row, const char *column_name)
1271 const struct ovsdb_column *column;
1273 column = ovsdb_table_schema_get_column(do_transact_table->schema,
1275 return row->fields[column->index].keys[0].integer;
1279 do_transact_set_i_j(struct ovsdb_row *row,
1280 const char *i_string, const char *j_string)
1282 do_transact_set_integer(row, "i", atoi(i_string));
1283 do_transact_set_integer(row, "j", atoi(j_string));
1287 do_transact_insert(int argc UNUSED, char *argv[] UNUSED)
1289 struct ovsdb_row *row;
1292 row = ovsdb_row_create(do_transact_table);
1295 uuid = ovsdb_row_get_uuid_rw(row);
1296 uuid_from_integer(atoi(argv[1]), uuid);
1297 if (ovsdb_table_get_row(do_transact_table, uuid)) {
1298 ovs_fatal(0, "table already contains row with UUID "UUID_FMT,
1302 do_transact_set_i_j(row, argv[2], argv[3]);
1305 ovsdb_txn_row_insert(do_transact_txn, row);
1309 do_transact_delete(int argc UNUSED, char *argv[] UNUSED)
1311 const struct ovsdb_row *row = do_transact_find_row(argv[1]);
1312 ovsdb_txn_row_delete(do_transact_txn, row);
1316 do_transact_modify(int argc UNUSED, char *argv[] UNUSED)
1318 const struct ovsdb_row *row_ro;
1319 struct ovsdb_row *row_rw;
1321 row_ro = do_transact_find_row(argv[1]);
1322 row_rw = ovsdb_txn_row_modify(do_transact_txn, row_ro);
1323 do_transact_set_i_j(row_rw, argv[2], argv[3]);
1327 compare_rows_by_uuid(const void *a_, const void *b_)
1329 struct ovsdb_row *const *ap = a_;
1330 struct ovsdb_row *const *bp = b_;
1332 return uuid_compare_3way(ovsdb_row_get_uuid(*ap), ovsdb_row_get_uuid(*bp));
1336 do_transact_print(int argc UNUSED, char *argv[] UNUSED)
1338 const struct ovsdb_row **rows;
1339 const struct ovsdb_row *row;
1343 n_rows = hmap_count(&do_transact_table->rows);
1344 rows = xmalloc(n_rows * sizeof *rows);
1346 HMAP_FOR_EACH (row, struct ovsdb_row, hmap_node,
1347 &do_transact_table->rows) {
1350 assert(i == n_rows);
1352 qsort(rows, n_rows, sizeof *rows, compare_rows_by_uuid);
1354 for (i = 0; i < n_rows; i++) {
1355 printf("\n%"PRId32": i=%d, j=%d",
1356 ovsdb_row_get_uuid(rows[i])->parts[3],
1357 do_transact_get_integer(rows[i], "i"),
1358 do_transact_get_integer(rows[i], "j"));
1365 do_transact(int argc, char *argv[])
1367 static const struct command do_transact_commands[] = {
1368 { "commit", 0, 0, do_transact_commit },
1369 { "abort", 0, 0, do_transact_abort },
1370 { "insert", 2, 3, do_transact_insert },
1371 { "delete", 1, 1, do_transact_delete },
1372 { "modify", 2, 3, do_transact_modify },
1373 { "print", 0, 0, do_transact_print },
1374 { NULL, 0, 0, NULL },
1377 struct ovsdb_schema *schema;
1382 json = parse_json("{\"name\": \"testdb\", "
1386 " {\"i\": {\"type\": \"integer\"}, "
1387 " \"j\": {\"type\": \"integer\"}}}}}");
1388 check_ovsdb_error(ovsdb_schema_from_json(json, &schema));
1390 do_transact_db = ovsdb_create(schema);
1391 do_transact_table = ovsdb_get_table(do_transact_db, "mytable");
1392 assert(do_transact_table != NULL);
1394 for (i = 1; i < argc; i++) {
1395 struct json *command;
1400 command = parse_json(argv[i]);
1401 if (command->type != JSON_ARRAY) {
1402 ovs_fatal(0, "transaction %d must be JSON array "
1403 "with at least 1 element", i);
1406 n_args = command->u.array.n;
1407 args = xmalloc((n_args + 1) * sizeof *args);
1408 for (j = 0; j < n_args; j++) {
1409 struct json *s = command->u.array.elems[j];
1410 if (s->type != JSON_STRING) {
1411 ovs_fatal(0, "transaction %d argument %d must be JSON string",
1414 args[j] = xstrdup(json_string(s));
1416 args[n_args] = NULL;
1418 if (!do_transact_txn) {
1419 do_transact_txn = ovsdb_txn_create(do_transact_db);
1422 for (j = 0; j < n_args; j++) {
1426 fputs(args[j], stdout);
1429 run_command(n_args, args, do_transact_commands);
1432 for (j = 0; j < n_args; j++) {
1436 json_destroy(command);
1438 ovsdb_txn_abort(do_transact_txn);
1439 ovsdb_destroy(do_transact_db); /* Also destroys 'schema'. */
1443 compare_link1(const void *a_, const void *b_)
1445 const struct idltest_link1 *const *ap = a_;
1446 const struct idltest_link1 *const *bp = b_;
1447 const struct idltest_link1 *a = *ap;
1448 const struct idltest_link1 *b = *bp;
1450 return a->i < b->i ? -1 : a->i > b->i;
1454 print_idl(struct ovsdb_idl *idl, int step)
1456 const struct idltest_simple *s;
1457 const struct idltest_link1 *l1;
1458 const struct idltest_link2 *l2;
1461 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1464 printf("%03d: i=%"PRId64" r=%g b=%s s=%s u="UUID_FMT" ia=[",
1465 step, s->i, s->r, s->b ? "true" : "false",
1466 s->s, UUID_ARGS(&s->u));
1467 for (i = 0; i < s->n_ia; i++) {
1468 printf("%s%"PRId64, i ? " " : "", s->ia[i]);
1471 for (i = 0; i < s->n_ra; i++) {
1472 printf("%s%g", i ? " " : "", s->ra[i]);
1475 for (i = 0; i < s->n_ba; i++) {
1476 printf("%s%s", i ? " " : "", s->ba[i] ? "true" : "false");
1479 for (i = 0; i < s->n_sa; i++) {
1480 printf("%s%s", i ? " " : "", s->sa[i]);
1483 for (i = 0; i < s->n_ua; i++) {
1484 printf("%s"UUID_FMT, i ? " " : "", UUID_ARGS(&s->ua[i]));
1486 printf("] uuid="UUID_FMT"\n", UUID_ARGS(&s->header_.uuid));
1489 IDLTEST_LINK1_FOR_EACH (l1, idl) {
1490 struct idltest_link1 **links;
1493 printf("%03d: i=%"PRId64" k=", step, l1->i);
1495 printf("%"PRId64, l1->k->i);
1498 links = xmemdup(l1->ka, l1->n_ka * sizeof *l1->ka);
1499 qsort(links, l1->n_ka, sizeof *links, compare_link1);
1500 for (i = 0; i < l1->n_ka; i++) {
1501 printf("%s%"PRId64, i ? " " : "", links[i]->i);
1506 printf("%"PRId64, l1->l2->i);
1508 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l1->header_.uuid));
1511 IDLTEST_LINK2_FOR_EACH (l2, idl) {
1512 printf("%03d: i=%"PRId64" l1=", step, l2->i);
1514 printf("%"PRId64, l2->l1->i);
1516 printf(" uuid="UUID_FMT"\n", UUID_ARGS(&l2->header_.uuid));
1520 printf("%03d: empty\n", step);
1525 print_updated_idl(struct ovsdb_idl *idl, struct jsonrpc *rpc,
1526 int step, unsigned int seqno)
1529 unsigned int new_seqno;
1535 new_seqno = ovsdb_idl_get_seqno(idl);
1536 if (new_seqno != seqno) {
1537 print_idl(idl, step);
1544 ovsdb_idl_wait(idl);
1550 parse_uuids(const struct json *json, struct ovsdb_symbol_table *symtab,
1555 if (json->type == JSON_STRING && uuid_from_string(&uuid, json->u.string)) {
1556 char *name = xasprintf("#%d#", *n);
1557 fprintf(stderr, "%s = "UUID_FMT"\n", name, UUID_ARGS(&uuid));
1558 ovsdb_symbol_table_put(symtab, name, &uuid, false);
1561 } else if (json->type == JSON_ARRAY) {
1564 for (i = 0; i < json->u.array.n; i++) {
1565 parse_uuids(json->u.array.elems[i], symtab, n);
1567 } else if (json->type == JSON_OBJECT) {
1568 const struct shash_node *node;
1570 SHASH_FOR_EACH (node, json_object(json)) {
1571 parse_uuids(node->data, symtab, n);
1577 substitute_uuids(struct json *json, const struct ovsdb_symbol_table *symtab)
1579 if (json->type == JSON_STRING) {
1580 const struct ovsdb_symbol *symbol;
1582 symbol = ovsdb_symbol_table_get(symtab, json->u.string);
1584 free(json->u.string);
1585 json->u.string = xasprintf(UUID_FMT, UUID_ARGS(&symbol->uuid));
1587 } else if (json->type == JSON_ARRAY) {
1590 for (i = 0; i < json->u.array.n; i++) {
1591 substitute_uuids(json->u.array.elems[i], symtab);
1593 } else if (json->type == JSON_OBJECT) {
1594 const struct shash_node *node;
1596 SHASH_FOR_EACH (node, json_object(json)) {
1597 substitute_uuids(node->data, symtab);
1602 static const struct idltest_simple *
1603 idltest_find_simple(struct ovsdb_idl *idl, int i)
1605 const struct idltest_simple *s;
1607 IDLTEST_SIMPLE_FOR_EACH (s, idl) {
1616 idl_set(struct ovsdb_idl *idl, char *commands, int step)
1618 char *cmd, *save_ptr1 = NULL;
1619 struct ovsdb_idl_txn *txn;
1620 enum ovsdb_idl_txn_status status;
1621 bool increment = false;
1623 txn = ovsdb_idl_txn_create(idl);
1624 for (cmd = strtok_r(commands, ",", &save_ptr1); cmd;
1625 cmd = strtok_r(NULL, ",", &save_ptr1)) {
1626 char *save_ptr2 = NULL;
1627 char *name, *arg1, *arg2, *arg3;
1629 name = strtok_r(cmd, " ", &save_ptr2);
1630 arg1 = strtok_r(NULL, " ", &save_ptr2);
1631 arg2 = strtok_r(NULL, " ", &save_ptr2);
1632 arg3 = strtok_r(NULL, " ", &save_ptr2);
1634 if (!strcmp(name, "set")) {
1635 const struct idltest_simple *s;
1638 ovs_fatal(0, "\"set\" command requires 3 arguments");
1641 s = idltest_find_simple(idl, atoi(arg1));
1643 ovs_fatal(0, "\"set\" command asks for nonexistent "
1644 "i=%d", atoi(arg1));
1647 if (!strcmp(arg2, "b")) {
1648 idltest_simple_set_b(s, atoi(arg3));
1649 } else if (!strcmp(arg2, "s")) {
1650 idltest_simple_set_s(s, arg3);
1651 } else if (!strcmp(arg2, "u")) {
1653 uuid_from_string(&uuid, arg3);
1654 idltest_simple_set_u(s, uuid);
1655 } else if (!strcmp(arg2, "r")) {
1656 idltest_simple_set_r(s, atof(arg3));
1658 ovs_fatal(0, "\"set\" command asks for unknown column %s",
1661 } else if (!strcmp(name, "insert")) {
1662 struct idltest_simple *s;
1664 if (!arg1 || arg2) {
1665 ovs_fatal(0, "\"set\" command requires 1 argument");
1668 s = idltest_simple_insert(txn);
1669 idltest_simple_set_i(s, atoi(arg1));
1670 } else if (!strcmp(name, "delete")) {
1671 const struct idltest_simple *s;
1673 if (!arg1 || arg2) {
1674 ovs_fatal(0, "\"set\" command requires 1 argument");
1677 s = idltest_find_simple(idl, atoi(arg1));
1679 ovs_fatal(0, "\"set\" command asks for nonexistent "
1680 "i=%d", atoi(arg1));
1682 idltest_simple_delete(s);
1683 } else if (!strcmp(name, "increment")) {
1684 if (!arg2 || arg3) {
1685 ovs_fatal(0, "\"set\" command requires 2 arguments");
1687 ovsdb_idl_txn_increment(txn, arg1, arg2, NULL);
1690 ovs_fatal(0, "unknown command %s", name);
1694 while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
1696 ovsdb_idl_wait(idl);
1697 ovsdb_idl_txn_wait(txn);
1700 printf("%03d: commit, status=%s",
1701 step, ovsdb_idl_txn_status_to_string(status));
1703 printf(", increment=%"PRId64,
1704 ovsdb_idl_txn_get_increment_new_value(txn));
1707 ovsdb_idl_txn_destroy(txn);
1711 do_idl(int argc, char *argv[])
1713 struct jsonrpc *rpc;
1714 struct ovsdb_idl *idl;
1715 unsigned int seqno = 0;
1716 struct ovsdb_symbol_table *symtab;
1722 idl = ovsdb_idl_create(argv[1], &idltest_idl_class);
1724 struct stream *stream;
1726 error = stream_open_block(argv[1], &stream);
1728 ovs_fatal(error, "failed to connect to \"%s\"", argv[1]);
1730 rpc = jsonrpc_open(stream);
1735 symtab = ovsdb_symbol_table_create();
1736 for (i = 2; i < argc; i++) {
1737 struct jsonrpc_msg *request, *reply;
1740 seqno = print_updated_idl(idl, rpc, step++, seqno);
1742 if (!strcmp(argv[i], "reconnect")) {
1743 printf("%03d: reconnect\n", step++);
1744 ovsdb_idl_force_reconnect(idl);
1745 } else if (argv[i][0] != '[') {
1746 idl_set(idl, argv[i], step++);
1748 struct json *json = parse_json(argv[i]);
1749 substitute_uuids(json, symtab);
1750 request = jsonrpc_create_request("transact", json, NULL);
1751 error = jsonrpc_transact_block(rpc, request, &reply);
1753 ovs_fatal(error, "jsonrpc transaction failed");
1755 printf("%03d: ", step++);
1756 if (reply->result) {
1757 parse_uuids(reply->result, symtab, &n_uuids);
1759 json_destroy(reply->id);
1761 print_and_free_json(jsonrpc_msg_to_json(reply));
1764 ovsdb_symbol_table_destroy(symtab);
1769 print_updated_idl(idl, NULL, step++, seqno);
1770 ovsdb_idl_destroy(idl);
1771 printf("%03d: done\n", step);
1774 static struct command all_commands[] = {
1775 { "log-io", 2, INT_MAX, do_log_io },
1776 { "parse-atomic-type", 1, 1, do_parse_atomic_type },
1777 { "parse-type", 1, 1, do_parse_type },
1778 { "parse-atoms", 2, INT_MAX, do_parse_atoms },
1779 { "parse-atom-strings", 2, INT_MAX, do_parse_atom_strings },
1780 { "parse-data", 2, INT_MAX, do_parse_data },
1781 { "parse-data-strings", 2, INT_MAX, do_parse_data_strings },
1782 { "sort-atoms", 2, 2, do_sort_atoms },
1783 { "parse-column", 2, 2, do_parse_column },
1784 { "parse-table", 2, 2, do_parse_table },
1785 { "parse-rows", 2, INT_MAX, do_parse_rows },
1786 { "compare-rows", 2, INT_MAX, do_compare_rows },
1787 { "parse-conditions", 2, INT_MAX, do_parse_conditions },
1788 { "evaluate-conditions", 3, 3, do_evaluate_conditions },
1789 { "parse-mutations", 2, INT_MAX, do_parse_mutations },
1790 { "execute-mutations", 3, 3, do_execute_mutations },
1791 { "query", 3, 3, do_query },
1792 { "query-distinct", 4, 4, do_query_distinct },
1793 { "transact", 1, INT_MAX, do_transact },
1794 { "execute", 2, INT_MAX, do_execute },
1795 { "trigger", 2, INT_MAX, do_trigger },
1796 { "idl", 1, INT_MAX, do_idl },
1797 { "help", 0, INT_MAX, do_help },
1798 { NULL, 0, 0, NULL },