Global replace of Nicira Networks.
[sliver-openvswitch.git] / ovsdb / ovsdb.h
1 /* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
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_OVSDB_H
17 #define OVSDB_OVSDB_H 1
18
19 #include "compiler.h"
20 #include "hmap.h"
21 #include "list.h"
22 #include "shash.h"
23
24 struct json;
25 struct ovsdb_log;
26 struct ovsdb_session;
27 struct ovsdb_txn;
28 struct uuid;
29
30 /* Database schema. */
31 struct ovsdb_schema {
32     char *name;
33     char *version;
34     char *cksum;
35     struct shash tables;        /* Contains "struct ovsdb_table_schema *"s. */
36 };
37
38 struct ovsdb_schema *ovsdb_schema_create(const char *name,
39                                          const char *version,
40                                          const char *cksum);
41 struct ovsdb_schema *ovsdb_schema_clone(const struct ovsdb_schema *);
42 void ovsdb_schema_destroy(struct ovsdb_schema *);
43
44 struct ovsdb_error *ovsdb_schema_from_file(const char *file_name,
45                                            struct ovsdb_schema **)
46     WARN_UNUSED_RESULT;
47 struct ovsdb_error *ovsdb_schema_from_json(struct json *,
48                                            struct ovsdb_schema **)
49     WARN_UNUSED_RESULT;
50 struct json *ovsdb_schema_to_json(const struct ovsdb_schema *);
51
52 bool ovsdb_schema_equal(const struct ovsdb_schema *,
53                         const struct ovsdb_schema *);
54 \f
55 /* Database. */
56 struct ovsdb {
57     struct ovsdb_schema *schema;
58     struct list replicas;       /* Contains "struct ovsdb_replica"s. */
59     struct shash tables;        /* Contains "struct ovsdb_table *"s. */
60
61     /* Triggers. */
62     struct list triggers;       /* Contains "struct ovsdb_trigger"s. */
63     bool run_triggers;
64 };
65
66 struct ovsdb *ovsdb_create(struct ovsdb_schema *);
67 void ovsdb_destroy(struct ovsdb *);
68
69 struct ovsdb_error *ovsdb_from_json(const struct json *, struct ovsdb **)
70     WARN_UNUSED_RESULT;
71 struct json *ovsdb_to_json(const struct ovsdb *);
72
73 struct ovsdb_table *ovsdb_get_table(const struct ovsdb *, const char *);
74
75 struct json *ovsdb_execute(struct ovsdb *, const struct ovsdb_session *,
76                            const struct json *params,
77                            long long int elapsed_msec,
78                            long long int *timeout_msec);
79 \f
80 /* Database replication. */
81
82 struct ovsdb_replica {
83     struct list node;           /* Element in "struct ovsdb" replicas list. */
84     const struct ovsdb_replica_class *class;
85 };
86
87 struct ovsdb_replica_class {
88     struct ovsdb_error *(*commit)(struct ovsdb_replica *,
89                                   const struct ovsdb_txn *, bool durable);
90     void (*destroy)(struct ovsdb_replica *);
91 };
92
93 void ovsdb_replica_init(struct ovsdb_replica *,
94                         const struct ovsdb_replica_class *);
95
96 void ovsdb_add_replica(struct ovsdb *, struct ovsdb_replica *);
97 void ovsdb_remove_replica(struct ovsdb *, struct ovsdb_replica *);
98
99 #endif /* ovsdb/ovsdb.h */