]> git.proxmox.com Git - ovs.git/blame - lib/ovsdb-idl.h
datapath-windows: Stateless TCP Tunnelling protocol - Initial implementation
[ovs.git] / lib / ovsdb-idl.h
CommitLineData
ff495b63 1/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
c3bb4bd7
BP
2 *
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef OVSDB_IDL_H
17#define OVSDB_IDL_H 1
18
2ce42c88
BP
19/* Open vSwitch Database Interface Definition Language (OVSDB IDL).
20 *
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.
25 *
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
30 * successfully.
31 */
32
f3d64521 33#include <stdbool.h>
b54e22e9 34#include <stdint.h>
e1c0e2d1 35#include "compiler.h"
8c3c2f30 36#include "ovsdb-types.h"
b54e22e9
BP
37
38struct json;
979821c0 39struct ovsdb_datum;
c3bb4bd7 40struct ovsdb_idl_class;
979821c0
BP
41struct ovsdb_idl_column;
42struct ovsdb_idl_table_class;
43struct uuid;
c3bb4bd7
BP
44
45struct ovsdb_idl *ovsdb_idl_create(const char *remote,
ef73f86c 46 const struct ovsdb_idl_class *,
fba6bd1d
BP
47 bool monitor_everything_by_default,
48 bool retry);
c3bb4bd7
BP
49void ovsdb_idl_destroy(struct ovsdb_idl *);
50
854a94d9 51void ovsdb_idl_run(struct ovsdb_idl *);
c3bb4bd7
BP
52void ovsdb_idl_wait(struct ovsdb_idl *);
53
06b6d651
BP
54void ovsdb_idl_set_lock(struct ovsdb_idl *, const char *lock_name);
55bool ovsdb_idl_has_lock(const struct ovsdb_idl *);
56bool ovsdb_idl_is_lock_contended(const struct ovsdb_idl *);
57
c3bb4bd7 58unsigned int ovsdb_idl_get_seqno(const struct ovsdb_idl *);
f3d64521 59bool ovsdb_idl_has_ever_connected(const struct ovsdb_idl *);
705d7a39 60void ovsdb_idl_enable_reconnect(struct ovsdb_idl *);
c3bb4bd7 61void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
8cdec725 62void ovsdb_idl_verify_write_only(struct ovsdb_idl *);
fba6bd1d
BP
63
64bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
65int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
ef73f86c
BP
66\f
67/* Choosing columns and tables to replicate. */
68
69/* Modes with which the IDL can monitor a column.
70 *
71 * If no bits are set, the column is not monitored at all. Its value will
72 * always appear to the client to be the default value for its type.
73 *
74 * If OVSDB_IDL_MONITOR is set, then the column is replicated. Its value will
854a94d9
BP
75 * reflect the value in the database. If OVSDB_IDL_ALERT is also set, then the
76 * value returned by ovsdb_idl_get_seqno() will change when the column's value
77 * changes.
ef73f86c
BP
78 *
79 * The possible mode combinations are:
80 *
81 * - 0, for a column that a client doesn't care about.
82 *
83 * - (OVSDB_IDL_MONITOR | OVSDB_IDL_ALERT), for a column that a client wants
84 * to track and possibly update.
85 *
86 * - OVSDB_IDL_MONITOR, for columns that a client treats as "write-only",
87 * that is, it updates them but doesn't want to get alerted about its own
88 * updates. It also won't be alerted about other clients' updates, so this
89 * is suitable only for use by a client that "owns" a particular column.
90 *
91 * - OVDSB_IDL_ALERT without OVSDB_IDL_MONITOR is not valid.
92 */
93#define OVSDB_IDL_MONITOR (1 << 0) /* Monitor this column? */
94#define OVSDB_IDL_ALERT (1 << 1) /* Alert client when column updated? */
95
96void ovsdb_idl_add_column(struct ovsdb_idl *, const struct ovsdb_idl_column *);
97void ovsdb_idl_add_table(struct ovsdb_idl *,
98 const struct ovsdb_idl_table_class *);
c3bb4bd7 99
c547535a 100void ovsdb_idl_omit(struct ovsdb_idl *, const struct ovsdb_idl_column *);
ef73f86c
BP
101void ovsdb_idl_omit_alert(struct ovsdb_idl *, const struct ovsdb_idl_column *);
102\f
103/* Reading the database replica. */
c547535a 104
979821c0
BP
105const struct ovsdb_idl_row *ovsdb_idl_get_row_for_uuid(
106 const struct ovsdb_idl *, const struct ovsdb_idl_table_class *,
107 const struct uuid *);
108const struct ovsdb_idl_row *ovsdb_idl_first_row(
109 const struct ovsdb_idl *, const struct ovsdb_idl_table_class *);
110const struct ovsdb_idl_row *ovsdb_idl_next_row(const struct ovsdb_idl_row *);
111
8c3c2f30
BP
112const struct ovsdb_datum *ovsdb_idl_read(const struct ovsdb_idl_row *,
113 const struct ovsdb_idl_column *);
114const struct ovsdb_datum *ovsdb_idl_get(const struct ovsdb_idl_row *,
115 const struct ovsdb_idl_column *,
116 enum ovsdb_atomic_type key_type,
117 enum ovsdb_atomic_type value_type);
ff495b63
BP
118bool ovsdb_idl_is_mutable(const struct ovsdb_idl_row *,
119 const struct ovsdb_idl_column *);
cfea354b
BP
120
121bool ovsdb_idl_row_is_synthetic(const struct ovsdb_idl_row *);
ef73f86c 122\f
2f926787
BP
123/* Transactions.
124 *
125 * A transaction may modify the contents of a database by modifying the values
126 * of columns, deleting rows, inserting rows, or adding checks that columns in
127 * the database have not changed ("verify" operations), through
128 * ovsdb_idl_txn_*() functions. (The OVSDB IDL code generator produces helper
129 * functions that internally call the ovsdb_idl_txn_*() functions. These are
130 * likely to be more convenient.)
131 *
132 * Reading and writing columns and inserting and deleting rows are all
133 * straightforward. The reasons to verify columns are less obvious.
134 * Verification is the key to maintaining transactional integrity. Because
135 * OVSDB handles multiple clients, it can happen that between the time that
136 * OVSDB client A reads a column and writes a new value, OVSDB client B has
137 * written that column. Client A's write should not ordinarily overwrite
138 * client B's, especially if the column in question is a "map" column that
139 * contains several more or less independent data items. If client A adds a
140 * "verify" operation before it writes the column, then the transaction fails
141 * in case client B modifies it first. Client A will then see the new value of
142 * the column and compose a new transaction based on the new contents written
143 * by client B.
144 *
145 * When a transaction is complete, which must be before the next call to
146 * ovsdb_idl_run() on 'idl', call ovsdb_idl_txn_commit() or
147 * ovsdb_idl_txn_abort().
148 *
149 * The life-cycle of a transaction looks like this:
150 *
151 * 1. Create the transaction and record the initial sequence number:
152 *
153 * seqno = ovsdb_idl_get_seqno(idl);
154 * txn = ovsdb_idl_txn_create(idl);
155 *
156 * 2. Modify the database with ovsdb_idl_txn_*() functions directly or
157 * indirectly.
158 *
159 * 3. Commit the transaction by calling ovsdb_idl_txn_commit(). The first call
160 * to this function probably returns TXN_INCOMPLETE. The client must keep
161 * calling again along as this remains true, calling ovsdb_idl_run() in
162 * between to let the IDL do protocol processing. (If the client doesn't
163 * have anything else to do in the meantime, it can use
164 * ovsdb_idl_txn_commit_block() to avoid having to loop itself.)
165 *
166 * 4. If the final status is TXN_TRY_AGAIN, wait for ovsdb_idl_get_seqno() to
167 * change from the saved 'seqno' (it's possible that it's already changed,
168 * in which case the client should not wait at all), then start over from
169 * step 1. Only a call to ovsdb_idl_run() will change the return value of
170 * ovsdb_idl_get_seqno(). (ovsdb_idl_txn_commit_block() calls
171 * ovsdb_idl_run().)
172 */
8c3c2f30 173
475281c0 174enum ovsdb_idl_txn_status {
2096903b 175 TXN_UNCOMMITTED, /* Not yet committed or aborted. */
b54e22e9 176 TXN_UNCHANGED, /* Transaction didn't include any changes. */
475281c0
BP
177 TXN_INCOMPLETE, /* Commit in progress, please wait. */
178 TXN_ABORTED, /* ovsdb_idl_txn_abort() called. */
179 TXN_SUCCESS, /* Commit successful. */
854a94d9 180 TXN_TRY_AGAIN, /* Commit failed because a "verify" operation
475281c0 181 * reported an inconsistency, due to a network
4fdfe5cc
BP
182 * problem, or other transient failure. Wait
183 * for a change, then try again. */
06b6d651 184 TXN_NOT_LOCKED, /* Server hasn't given us the lock yet. */
475281c0
BP
185 TXN_ERROR /* Commit failed due to a hard error. */
186};
187
188const char *ovsdb_idl_txn_status_to_string(enum ovsdb_idl_txn_status);
189
190struct ovsdb_idl_txn *ovsdb_idl_txn_create(struct ovsdb_idl *);
e1c0e2d1 191void ovsdb_idl_txn_add_comment(struct ovsdb_idl_txn *, const char *, ...)
cab50449 192 OVS_PRINTF_FORMAT (2, 3);
577aebdf 193void ovsdb_idl_txn_set_dry_run(struct ovsdb_idl_txn *);
94fbe1aa
BP
194void ovsdb_idl_txn_increment(struct ovsdb_idl_txn *,
195 const struct ovsdb_idl_row *,
196 const struct ovsdb_idl_column *);
475281c0 197void ovsdb_idl_txn_destroy(struct ovsdb_idl_txn *);
586bb84a 198void ovsdb_idl_txn_wait(const struct ovsdb_idl_txn *);
475281c0 199enum ovsdb_idl_txn_status ovsdb_idl_txn_commit(struct ovsdb_idl_txn *);
af96ccd2 200enum ovsdb_idl_txn_status ovsdb_idl_txn_commit_block(struct ovsdb_idl_txn *);
475281c0
BP
201void ovsdb_idl_txn_abort(struct ovsdb_idl_txn *);
202
91e310a5
BP
203const char *ovsdb_idl_txn_get_error(const struct ovsdb_idl_txn *);
204
69490970
BP
205int64_t ovsdb_idl_txn_get_increment_new_value(const struct ovsdb_idl_txn *);
206const struct uuid *ovsdb_idl_txn_get_insert_uuid(const struct ovsdb_idl_txn *,
207 const struct uuid *);
208
979821c0
BP
209void ovsdb_idl_txn_write(const struct ovsdb_idl_row *,
210 const struct ovsdb_idl_column *,
211 struct ovsdb_datum *);
fe19569a
BP
212void ovsdb_idl_txn_write_clone(const struct ovsdb_idl_row *,
213 const struct ovsdb_idl_column *,
214 const struct ovsdb_datum *);
9e336f49
BP
215void ovsdb_idl_txn_delete(const struct ovsdb_idl_row *);
216const struct ovsdb_idl_row *ovsdb_idl_txn_insert(
ce5a3e38
BP
217 struct ovsdb_idl_txn *, const struct ovsdb_idl_table_class *,
218 const struct uuid *);
979821c0 219
1e86ae6f
BP
220struct ovsdb_idl *ovsdb_idl_txn_get_idl (struct ovsdb_idl_txn *);
221
c3bb4bd7 222#endif /* ovsdb-idl.h */