]> git.proxmox.com Git - ovs.git/blame - lib/ovsdb-data.h
ovsdb: Add tests for OVSDB protocol over SSL.
[ovs.git] / lib / ovsdb-data.h
CommitLineData
f85f8ebb
BP
1/* Copyright (c) 2009 Nicira Networks
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_DATA_H
17#define OVSDB_DATA_H 1
18
19#include <stdlib.h>
20#include "compiler.h"
21#include "ovsdb-types.h"
22
23struct ovsdb_symbol_table;
24
25/* One value of an atomic type (given by enum ovs_atomic_type). */
26union ovsdb_atom {
27 int64_t integer;
28 double real;
29 bool boolean;
30 char *string;
31 struct uuid uuid;
32};
33
34void ovsdb_atom_init_default(union ovsdb_atom *, enum ovsdb_atomic_type);
35void ovsdb_atom_clone(union ovsdb_atom *, const union ovsdb_atom *,
36 enum ovsdb_atomic_type);
37void ovsdb_atom_swap(union ovsdb_atom *, union ovsdb_atom *);
38
39static inline bool
40ovsdb_atom_needs_destruction(enum ovsdb_atomic_type type)
41{
42 return type == OVSDB_TYPE_STRING;
43}
44
45static inline void
46ovsdb_atom_destroy(union ovsdb_atom *atom, enum ovsdb_atomic_type type)
47{
48 if (type == OVSDB_TYPE_STRING) {
49 free(atom->string);
50 }
51}
52
53uint32_t ovsdb_atom_hash(const union ovsdb_atom *, enum ovsdb_atomic_type,
54 uint32_t basis);
55
56int ovsdb_atom_compare_3way(const union ovsdb_atom *,
57 const union ovsdb_atom *,
58 enum ovsdb_atomic_type);
59
60static inline bool ovsdb_atom_equals(const union ovsdb_atom *a,
61 const union ovsdb_atom *b,
62 enum ovsdb_atomic_type type)
63{
64 return !ovsdb_atom_compare_3way(a, b, type);
65}
66
67struct ovsdb_error *ovsdb_atom_from_json(union ovsdb_atom *,
68 enum ovsdb_atomic_type,
69 const struct json *,
70 const struct ovsdb_symbol_table *)
71 WARN_UNUSED_RESULT;
72struct json *ovsdb_atom_to_json(const union ovsdb_atom *,
73 enum ovsdb_atomic_type);
74\f
75/* One value of an OVSDB type (given by struct ovsdb_type). */
76struct ovsdb_datum {
77 unsigned int n; /* Number of 'keys' and 'values'. */
78 union ovsdb_atom *keys; /* Each of the ovsdb_type's 'key_type'. */
79 union ovsdb_atom *values; /* Each of the ovsdb_type's 'value_type'. */
80};
81
82void ovsdb_datum_init_default(struct ovsdb_datum *, const struct ovsdb_type *);
83void ovsdb_datum_clone(struct ovsdb_datum *, const struct ovsdb_datum *,
84 const struct ovsdb_type *);
85void ovsdb_datum_destroy(struct ovsdb_datum *, const struct ovsdb_type *);
86void ovsdb_datum_swap(struct ovsdb_datum *, struct ovsdb_datum *);
e9f8f936
BP
87struct ovsdb_error *ovsdb_datum_sort(struct ovsdb_datum *,
88 const struct ovsdb_type *);
f85f8ebb
BP
89
90struct ovsdb_error *ovsdb_datum_from_json(struct ovsdb_datum *,
91 const struct ovsdb_type *,
92 const struct json *,
93 const struct ovsdb_symbol_table *)
94 WARN_UNUSED_RESULT;
95struct json *ovsdb_datum_to_json(const struct ovsdb_datum *,
96 const struct ovsdb_type *);
97
98uint32_t ovsdb_datum_hash(const struct ovsdb_datum *,
99 const struct ovsdb_type *, uint32_t basis);
100int ovsdb_datum_compare_3way(const struct ovsdb_datum *,
101 const struct ovsdb_datum *,
102 const struct ovsdb_type *);
103bool ovsdb_datum_equals(const struct ovsdb_datum *,
104 const struct ovsdb_datum *,
105 const struct ovsdb_type *);
106bool ovsdb_datum_includes_all(const struct ovsdb_datum *,
107 const struct ovsdb_datum *,
108 const struct ovsdb_type *);
109bool ovsdb_datum_excludes_all(const struct ovsdb_datum *,
110 const struct ovsdb_datum *,
111 const struct ovsdb_type *);
112
e9f8f936
BP
113void ovsdb_datum_union(struct ovsdb_datum *,
114 const struct ovsdb_datum *,
115 const struct ovsdb_type *);
116void ovsdb_datum_subtract(struct ovsdb_datum *a,
117 const struct ovsdb_type *a_type,
118 const struct ovsdb_datum *b,
119 const struct ovsdb_type *b_type);
120
f85f8ebb
BP
121static inline bool
122ovsdb_datum_conforms_to_type(const struct ovsdb_datum *datum,
123 const struct ovsdb_type *type)
124{
125 return datum->n >= type->n_min && datum->n <= type->n_max;
126}
127\f
128/* A table mapping from names to data items. Currently the data items are
129 * always UUIDs; perhaps this will be expanded in the future. */
130
2d2d6d4a
BP
131struct ovsdb_symbol {
132 struct uuid uuid; /* The UUID that the symbol represents. */
133 bool used; /* Already used as row UUID? */
134};
135
f85f8ebb
BP
136struct ovsdb_symbol_table *ovsdb_symbol_table_create(void);
137void ovsdb_symbol_table_destroy(struct ovsdb_symbol_table *);
2d2d6d4a
BP
138struct ovsdb_symbol *ovsdb_symbol_table_get(const struct ovsdb_symbol_table *,
139 const char *name);
f85f8ebb 140void ovsdb_symbol_table_put(struct ovsdb_symbol_table *, const char *name,
2d2d6d4a 141 const struct uuid *, bool used);
f85f8ebb
BP
142
143#endif /* ovsdb-data.h */