1 /* Copyright (c) 2009, 2010 Nicira Networks.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
19 /* Open vSwitch Database Interface Definition Language (OVSDB IDL).
21 * The OVSDB IDL maintains an in-memory replica of a database. It issues RPC
22 * requests to an OVSDB database server and parses the responses, converting
23 * raw JSON into data structures that are easier for clients to digest. Most
24 * notably, references to rows via UUID become C pointers.
26 * The IDL also assists with issuing database transactions. The client creates
27 * a transaction, manipulates the IDL data structures, and commits or aborts
28 * the transaction. The IDL then composes and issues the necessary JSON-RPC
29 * requests and reports to the client whether the transaction completed
36 #include "ovsdb-types.h"
40 struct ovsdb_idl_class;
41 struct ovsdb_idl_column;
42 struct ovsdb_idl_table_class;
45 struct ovsdb_idl *ovsdb_idl_create(const char *remote,
46 const struct ovsdb_idl_class *,
47 bool monitor_everything_by_default);
48 void ovsdb_idl_destroy(struct ovsdb_idl *);
50 bool ovsdb_idl_run(struct ovsdb_idl *);
51 void ovsdb_idl_wait(struct ovsdb_idl *);
53 unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
54 bool ovsdb_idl_has_ever_connected(const struct ovsdb_idl *);
55 void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
57 /* Choosing columns and tables to replicate. */
59 /* Modes with which the IDL can monitor a column.
61 * If no bits are set, the column is not monitored at all. Its value will
62 * always appear to the client to be the default value for its type.
64 * If OVSDB_IDL_MONITOR is set, then the column is replicated. Its value will
65 * reflect the value in the database. If OVSDB_IDL_ALERT is also set, then
66 * ovsdb_idl_run() will return "true", and the value returned by
67 * ovsdb_idl_get_seqno() will change, when the column's value changes.
69 * The possible mode combinations are:
71 * - 0, for a column that a client doesn't care about.
73 * - (OVSDB_IDL_MONITOR | OVSDB_IDL_ALERT), for a column that a client wants
74 * to track and possibly update.
76 * - OVSDB_IDL_MONITOR, for columns that a client treats as "write-only",
77 * that is, it updates them but doesn't want to get alerted about its own
78 * updates. It also won't be alerted about other clients' updates, so this
79 * is suitable only for use by a client that "owns" a particular column.
81 * - OVDSB_IDL_ALERT without OVSDB_IDL_MONITOR is not valid.
83 #define OVSDB_IDL_MONITOR (1 << 0) /* Monitor this column? */
84 #define OVSDB_IDL_ALERT (1 << 1) /* Alert client when column updated? */
86 void ovsdb_idl_add_column(struct ovsdb_idl *, const struct ovsdb_idl_column *);
87 void ovsdb_idl_add_table(struct ovsdb_idl *,
88 const struct ovsdb_idl_table_class *);
90 void ovsdb_idl_omit(struct ovsdb_idl *, const struct ovsdb_idl_column *);
91 void ovsdb_idl_omit_alert(struct ovsdb_idl *, const struct ovsdb_idl_column *);
93 /* Reading the database replica. */
95 const struct ovsdb_idl_row *ovsdb_idl_get_row_for_uuid(
96 const struct ovsdb_idl *, const struct ovsdb_idl_table_class *,
98 const struct ovsdb_idl_row *ovsdb_idl_first_row(
99 const struct ovsdb_idl *, const struct ovsdb_idl_table_class *);
100 const struct ovsdb_idl_row *ovsdb_idl_next_row(const struct ovsdb_idl_row *);
102 const struct ovsdb_datum *ovsdb_idl_read(const struct ovsdb_idl_row *,
103 const struct ovsdb_idl_column *);
104 const struct ovsdb_datum *ovsdb_idl_get(const struct ovsdb_idl_row *,
105 const struct ovsdb_idl_column *,
106 enum ovsdb_atomic_type key_type,
107 enum ovsdb_atomic_type value_type);
111 enum ovsdb_idl_txn_status {
112 TXN_UNCHANGED, /* Transaction didn't include any changes. */
113 TXN_INCOMPLETE, /* Commit in progress, please wait. */
114 TXN_ABORTED, /* ovsdb_idl_txn_abort() called. */
115 TXN_SUCCESS, /* Commit successful. */
116 TXN_TRY_AGAIN, /* Commit failed because a "verify" operation
117 * reported an inconsistency, due to a network
118 * problem, or other transient failure. */
119 TXN_ERROR /* Commit failed due to a hard error. */
122 const char *ovsdb_idl_txn_status_to_string(enum ovsdb_idl_txn_status);
124 struct ovsdb_idl_txn *ovsdb_idl_txn_create(struct ovsdb_idl *);
125 void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *, ...)
126 PRINTF_FORMAT (2, 3);
127 void ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *);
128 void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *, const char *table,
129 const char *column, const struct json *where);
130 void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *);
131 void ovsdb_idl_txn_wait(const struct ovsdb_idl_txn *);
132 enum ovsdb_idl_txn_status ovsdb_idl_txn_commit(struct ovsdb_idl_txn *);
133 enum ovsdb_idl_txn_status ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *);
134 void ovsdb_idl_txn_abort(struct ovsdb_idl_txn *);
136 const char *ovsdb_idl_txn_get_error(const struct ovsdb_idl_txn *);
138 int64_t ovsdb_idl_txn_get_increment_new_value(const struct ovsdb_idl_txn *);
139 const struct uuid *ovsdb_idl_txn_get_insert_uuid(const struct ovsdb_idl_txn *,
140 const struct uuid *);
142 void ovsdb_idl_txn_write(const struct ovsdb_idl_row *,
143 const struct ovsdb_idl_column *,
144 struct ovsdb_datum *);
145 void ovsdb_idl_txn_delete(const struct ovsdb_idl_row *);
146 const struct ovsdb_idl_row *ovsdb_idl_txn_insert(
147 struct ovsdb_idl_txn *, const struct ovsdb_idl_table_class *,
148 const struct uuid *);
150 struct ovsdb_idl *ovsdb_idl_txn_get_idl (struct ovsdb_idl_txn *);
152 #endif /* ovsdb-idl.h */