]> git.proxmox.com Git - ovs.git/blame - lib/ovsdb-idl-provider.h
dpif-netdev: Add ovs-appctl dpif-netdev/pmd-rxq-rebalance.
[ovs.git] / lib / ovsdb-idl-provider.h
CommitLineData
239fa5bb 1/* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
93fe0264 2 * Copyright (C) 2016 Hewlett Packard Enterprise Development LP
c3bb4bd7
BP
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef OVSDB_IDL_PROVIDER_H
18#define OVSDB_IDL_PROVIDER_H 1
19
ee89ea7b 20#include "openvswitch/hmap.h"
b19bab5b 21#include "openvswitch/list.h"
c3bb4bd7 22#include "ovsdb-idl.h"
f199df26 23#include "ovsdb-map-op.h"
f1ab6e06 24#include "ovsdb-set-op.h"
c3bb4bd7 25#include "ovsdb-types.h"
ee89ea7b 26#include "openvswitch/shash.h"
c3bb4bd7
BP
27#include "uuid.h"
28
c1ac745c
BP
29/* A local copy of a row in an OVSDB table, replicated from an OVSDB server.
30 * This structure is used as a header for a larger structure that translates
31 * the "struct ovsdb_datum"s into easier-to-use forms, via the ->parse() and
32 * ->unparse functions in struct ovsdb_idl_column. (Those functions are
33 * generated automatically via ovsdb-idlc.)
34 *
35 * When no transaction is in progress:
36 *
4e0b4acc 37 * - 'old_datum' points to the data committed to the database and currently
c1ac745c
BP
38 * in the row.
39 *
4e0b4acc 40 * - 'new_datum == old_datum'.
c1ac745c
BP
41 *
42 * When a transaction is in progress, the situation is a little different. For
4e0b4acc
JS
43 * a row inserted in the transaction, 'old_datum' is NULL and 'new_datum'
44 * points to the row's initial contents. Otherwise:
c1ac745c 45 *
4e0b4acc
JS
46 * - 'old_datum' points to the data committed to the database and currently
47 * in the row. (This is the same as when no transaction is in progress.)
c1ac745c 48 *
4e0b4acc 49 * - If the transaction does not modify the row, 'new_datum == old_datum'.
c1ac745c 50 *
fa50ab0b
JS
51 * - If the transaction modifies the row, 'new_datum' points to the
52 * modified data.
c1ac745c 53 *
fa50ab0b 54 * - If the transaction deletes the row, 'new_datum' is NULL.
c1ac745c
BP
55 *
56 * Thus:
57 *
4e0b4acc
JS
58 * - 'old_datum' always points to committed data, except that it is NULL if
59 * the row is inserted within the current transaction.
c1ac745c 60 *
fa50ab0b
JS
61 * - 'new_datum' always points to the newest, possibly uncommitted version
62 * of the row's data, except that it is NULL if the row is deleted within
63 * the current transaction.
c1ac745c 64 */
c3bb4bd7
BP
65struct ovsdb_idl_row {
66 struct hmap_node hmap_node; /* In struct ovsdb_idl_table's 'rows'. */
67 struct uuid uuid; /* Row "_uuid" field. */
ca6ba700
TG
68 struct ovs_list src_arcs; /* Forward arcs (ovsdb_idl_arc.src_node). */
69 struct ovs_list dst_arcs; /* Backward arcs (ovsdb_idl_arc.dst_node). */
c3bb4bd7 70 struct ovsdb_idl_table *table; /* Containing table. */
4e0b4acc 71 struct ovsdb_datum *old_datum; /* Committed data (null if orphaned). */
475281c0
BP
72
73 /* Transactional data. */
fa50ab0b 74 struct ovsdb_datum *new_datum; /* Modified data (null to delete row). */
4e0b4acc 75 unsigned long int *prereqs; /* Bitmap of "old_datum" columns to verify. */
fa50ab0b 76 unsigned long int *written; /* Bitmap of "new_datum" columns to write. */
475281c0 77 struct hmap_node txn_node; /* Node in ovsdb_idl_txn's list. */
f199df26
EA
78 unsigned long int *map_op_written; /* Bitmap of columns pending map ops. */
79 struct map_op_list **map_op_lists; /* Per-column map operations. */
f1ab6e06
RM
80 unsigned long int *set_op_written; /* Bitmap of columns pending set ops. */
81 struct set_op_list **set_op_lists; /* Per-column set operations. */
932104f4 82
32d37ce8 83 /* Tracking data */
932104f4 84 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
32d37ce8
SA
85 struct ovs_list track_node; /* Rows modified/added/deleted by IDL */
86 unsigned long int *updated; /* Bitmap of columns updated by IDL */
c3bb4bd7
BP
87};
88
89struct ovsdb_idl_column {
90 char *name;
91 struct ovsdb_type type;
c6e5d064 92 bool is_mutable;
979821c0
BP
93 void (*parse)(struct ovsdb_idl_row *, const struct ovsdb_datum *);
94 void (*unparse)(struct ovsdb_idl_row *);
c3bb4bd7
BP
95};
96
97struct ovsdb_idl_table_class {
98 char *name;
c5f341ab 99 bool is_root;
c3bb4bd7
BP
100 const struct ovsdb_idl_column *columns;
101 size_t n_columns;
102 size_t allocation_size;
a699f614 103 void (*row_init)(struct ovsdb_idl_row *);
c3bb4bd7
BP
104};
105
106struct ovsdb_idl_table {
3eb14233 107 const struct ovsdb_idl_table_class *class_;
ef73f86c 108 unsigned char *modes; /* OVSDB_IDL_* bitmasks, indexed by column. */
cd26c1dc
AE
109 bool need_table; /* Monitor table even if no columns are selected
110 * for replication. */
c3bb4bd7
BP
111 struct shash columns; /* Contains "const struct ovsdb_idl_column *"s. */
112 struct hmap rows; /* Contains "struct ovsdb_idl_row"s. */
113 struct ovsdb_idl *idl; /* Containing idl. */
932104f4 114 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
93fe0264 115 struct shash indexes; /* Contains "struct ovsdb_idl_index"s */
932104f4 116 struct ovs_list track_list; /* Tracked rows (ovsdb_idl_row.track_node). */
16ebb90e
LS
117 struct ovsdb_idl_condition condition;
118 bool cond_changed;
c3bb4bd7
BP
119};
120
121struct ovsdb_idl_class {
9cb53f26 122 const char *database; /* <db-name> for this database. */
c3bb4bd7
BP
123 const struct ovsdb_idl_table_class *tables;
124 size_t n_tables;
125};
126
93fe0264
LR
127/*
128 * Structure containing the per-column configuration of the index.
129 */
130struct ovsdb_idl_index_column {
131 const struct ovsdb_idl_column *column; /* Column used for index key. */
132 column_comparator *comparer; /* Column comparison function. */
133 int sorting_order; /* Sorting order (ascending or descending). */
134};
135
136/*
137 * Defines a IDL compound index
138 */
139struct ovsdb_idl_index {
140 struct skiplist *skiplist; /* Skiplist with pointers to rows. */
141 struct ovsdb_idl_index_column *columns; /* Columns configuration */
142 size_t n_columns; /* Number of columns in index. */
143 size_t alloc_columns; /* Size allocated memory for columns,
144 comparers and sorting order. */
145 bool ins_del; /* True if a row in the index is being
146 inserted or deleted; if true, the
147 search key is augmented with the
148 UUID and address in order to discriminate
149 between entries with identical keys. */
150 const struct ovsdb_idl_table *table; /* Table that owns this index */
151 const char *index_name; /* The name of this index. */
152};
153
c3bb4bd7
BP
154struct ovsdb_idl_row *ovsdb_idl_get_row_arc(
155 struct ovsdb_idl_row *src,
012d3762 156 const struct ovsdb_idl_table_class *dst_table,
c3bb4bd7
BP
157 const struct uuid *dst_uuid);
158
475281c0
BP
159void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *,
160 const struct ovsdb_idl_column *);
475281c0 161
76c91af9
BP
162struct ovsdb_idl_txn *ovsdb_idl_txn_get(const struct ovsdb_idl_row *);
163
c3bb4bd7 164#endif /* ovsdb-idl-provider.h */