1 /* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
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.
16 #ifndef OVSDB_IDL_PROVIDER_H
17 #define OVSDB_IDL_PROVIDER_H 1
19 #include "openvswitch/hmap.h"
20 #include "openvswitch/list.h"
21 #include "ovsdb-idl.h"
22 #include "ovsdb-map-op.h"
23 #include "ovsdb-set-op.h"
24 #include "ovsdb-types.h"
25 #include "openvswitch/shash.h"
28 /* A local copy of a row in an OVSDB table, replicated from an OVSDB server.
29 * This structure is used as a header for a larger structure that translates
30 * the "struct ovsdb_datum"s into easier-to-use forms, via the ->parse() and
31 * ->unparse functions in struct ovsdb_idl_column. (Those functions are
32 * generated automatically via ovsdb-idlc.)
34 * When no transaction is in progress:
36 * - 'old' points to the data committed to the database and currently
41 * When a transaction is in progress, the situation is a little different. For
42 * a row inserted in the transaction, 'old' is NULL and 'new' points to the
43 * row's initial contents. Otherwise:
45 * - 'old' points to the data committed to the database and currently in
46 * the row. (This is the same as when no transaction is in progress.)
48 * - If the transaction does not modify the row, 'new == old'.
50 * - If the transaction modifies the row, 'new' points to the modified
53 * - If the transaction deletes the row, 'new' is NULL.
57 * - 'old' always points to committed data, except that it is NULL if the
58 * row is inserted within the current transaction.
60 * - 'new' always points to the newest, possibly uncommitted version of the
61 * row's data, except that it is NULL if the row is deleted within the
62 * current transaction.
64 struct ovsdb_idl_row
{
65 struct hmap_node hmap_node
; /* In struct ovsdb_idl_table's 'rows'. */
66 struct uuid uuid
; /* Row "_uuid" field. */
67 struct ovs_list src_arcs
; /* Forward arcs (ovsdb_idl_arc.src_node). */
68 struct ovs_list dst_arcs
; /* Backward arcs (ovsdb_idl_arc.dst_node). */
69 struct ovsdb_idl_table
*table
; /* Containing table. */
70 struct ovsdb_datum
*old
; /* Committed data (null if orphaned). */
72 /* Transactional data. */
73 struct ovsdb_datum
*new; /* Modified data (null to delete row). */
74 unsigned long int *prereqs
; /* Bitmap of columns to verify in "old". */
75 unsigned long int *written
; /* Bitmap of columns from "new" to write. */
76 struct hmap_node txn_node
; /* Node in ovsdb_idl_txn's list. */
77 unsigned long int *map_op_written
; /* Bitmap of columns pending map ops. */
78 struct map_op_list
**map_op_lists
; /* Per-column map operations. */
79 unsigned long int *set_op_written
; /* Bitmap of columns pending set ops. */
80 struct set_op_list
**set_op_lists
; /* Per-column set operations. */
83 unsigned int change_seqno
[OVSDB_IDL_CHANGE_MAX
];
84 struct ovs_list track_node
; /* Rows modified/added/deleted by IDL */
85 unsigned long int *updated
; /* Bitmap of columns updated by IDL */
88 struct ovsdb_idl_column
{
90 struct ovsdb_type type
;
92 void (*parse
)(struct ovsdb_idl_row
*, const struct ovsdb_datum
*);
93 void (*unparse
)(struct ovsdb_idl_row
*);
96 struct ovsdb_idl_table_class
{
99 const struct ovsdb_idl_column
*columns
;
101 size_t allocation_size
;
102 void (*row_init
)(struct ovsdb_idl_row
*);
105 struct ovsdb_idl_table
{
106 const struct ovsdb_idl_table_class
*class;
107 unsigned char *modes
; /* OVSDB_IDL_* bitmasks, indexed by column. */
108 bool need_table
; /* Monitor table even if no columns are selected
109 * for replication. */
110 struct shash columns
; /* Contains "const struct ovsdb_idl_column *"s. */
111 struct hmap rows
; /* Contains "struct ovsdb_idl_row"s. */
112 struct ovsdb_idl
*idl
; /* Containing idl. */
113 unsigned int change_seqno
[OVSDB_IDL_CHANGE_MAX
];
114 struct ovs_list track_list
; /* Tracked rows (ovsdb_idl_row.track_node). */
115 struct ovsdb_idl_condition condition
;
119 struct ovsdb_idl_class
{
120 const char *database
; /* <db-name> for this database. */
121 const struct ovsdb_idl_table_class
*tables
;
125 struct ovsdb_idl_row
*ovsdb_idl_get_row_arc(
126 struct ovsdb_idl_row
*src
,
127 const struct ovsdb_idl_table_class
*dst_table
,
128 const struct uuid
*dst_uuid
);
130 void ovsdb_idl_txn_verify(const struct ovsdb_idl_row
*,
131 const struct ovsdb_idl_column
*);
133 struct ovsdb_idl_txn
*ovsdb_idl_txn_get(const struct ovsdb_idl_row
*);
135 #endif /* ovsdb-idl-provider.h */