+static const struct idltest_simple *
+idltest_find_simple(struct ovsdb_idl *idl, int i)
+{
+ const struct idltest_simple *s;
+
+ IDLTEST_SIMPLE_FOR_EACH (s, idl) {
+ if (s->i == i) {
+ return s;
+ }
+ }
+ return NULL;
+}
+
+static void
+idl_set(struct ovsdb_idl *idl, char *commands, int step)
+{
+ char *cmd, *save_ptr1 = NULL;
+ struct ovsdb_idl_txn *txn;
+ enum ovsdb_idl_txn_status status;
+ bool increment = false;
+
+ txn = ovsdb_idl_txn_create(idl);
+ for (cmd = strtok_r(commands, ",", &save_ptr1); cmd;
+ cmd = strtok_r(NULL, ",", &save_ptr1)) {
+ char *save_ptr2 = NULL;
+ char *name, *arg1, *arg2, *arg3;
+
+ name = strtok_r(cmd, " ", &save_ptr2);
+ arg1 = strtok_r(NULL, " ", &save_ptr2);
+ arg2 = strtok_r(NULL, " ", &save_ptr2);
+ arg3 = strtok_r(NULL, " ", &save_ptr2);
+
+ if (!strcmp(name, "set")) {
+ const struct idltest_simple *s;
+
+ if (!arg3) {
+ ovs_fatal(0, "\"set\" command requires 3 arguments");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"set\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+
+ if (!strcmp(arg2, "b")) {
+ idltest_simple_set_b(s, atoi(arg3));
+ } else if (!strcmp(arg2, "s")) {
+ idltest_simple_set_s(s, arg3);
+ } else if (!strcmp(arg2, "u")) {
+ struct uuid uuid;
+ if (!uuid_from_string(&uuid, arg3)) {
+ ovs_fatal(0, "\"%s\" is not a valid UUID", arg3);
+ }
+ idltest_simple_set_u(s, uuid);
+ } else if (!strcmp(arg2, "r")) {
+ idltest_simple_set_r(s, atof(arg3));
+ } else {
+ ovs_fatal(0, "\"set\" command asks for unknown column %s",
+ arg2);
+ }
+ } else if (!strcmp(name, "insert")) {
+ struct idltest_simple *s;
+
+ if (!arg1 || arg2) {
+ ovs_fatal(0, "\"insert\" command requires 1 argument");
+ }
+
+ s = idltest_simple_insert(txn);
+ idltest_simple_set_i(s, atoi(arg1));
+ } else if (!strcmp(name, "delete")) {
+ const struct idltest_simple *s;
+
+ if (!arg1 || arg2) {
+ ovs_fatal(0, "\"delete\" command requires 1 argument");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"delete\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+ idltest_simple_delete(s);
+ } else if (!strcmp(name, "verify")) {
+ const struct idltest_simple *s;
+
+ if (!arg2 || arg3) {
+ ovs_fatal(0, "\"verify\" command requires 2 arguments");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"verify\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+
+ if (!strcmp(arg2, "i")) {
+ idltest_simple_verify_i(s);
+ } else if (!strcmp(arg2, "b")) {
+ idltest_simple_verify_b(s);
+ } else if (!strcmp(arg2, "s")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "u")) {
+ idltest_simple_verify_s(s);
+ } else if (!strcmp(arg2, "r")) {
+ idltest_simple_verify_r(s);
+ } else {
+ ovs_fatal(0, "\"verify\" command asks for unknown column %s",
+ arg2);
+ }
+ } else if (!strcmp(name, "increment")) {
+ const struct idltest_simple *s;
+
+ if (!arg1 || arg2) {
+ ovs_fatal(0, "\"increment\" command requires 1 argument");
+ }
+
+ s = idltest_find_simple(idl, atoi(arg1));
+ if (!s) {
+ ovs_fatal(0, "\"set\" command asks for nonexistent "
+ "i=%d", atoi(arg1));
+ }
+
+ ovsdb_idl_txn_increment(txn, &s->header_, &idltest_simple_col_i);
+ increment = true;
+ } else if (!strcmp(name, "abort")) {
+ ovsdb_idl_txn_abort(txn);
+ break;
+ } else if (!strcmp(name, "destroy")) {
+ printf("%03d: destroy\n", step);
+ ovsdb_idl_txn_destroy(txn);
+ return;
+ } else {
+ ovs_fatal(0, "unknown command %s", name);
+ }
+ }
+
+ status = ovsdb_idl_txn_commit_block(txn);
+ printf("%03d: commit, status=%s",
+ step, ovsdb_idl_txn_status_to_string(status));
+ if (increment) {
+ printf(", increment=%"PRId64,
+ ovsdb_idl_txn_get_increment_new_value(txn));
+ }
+ putchar('\n');
+ ovsdb_idl_txn_destroy(txn);
+}
+