/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (C) 2016 Hewlett Packard Enterprise Development LP
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "ovsdb-data.h"
#include "openvswitch/list.h"
#include "ovsdb-condition.h"
+#include "skiplist.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
struct json;
struct ovsdb_datum;
struct ovsdb_idl_row;
struct ovsdb_idl_column;
struct ovsdb_idl_table_class;
-struct ovsdb_idl_condition;
struct uuid;
struct ovsdb_idl *ovsdb_idl_create(const char *remote,
int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int probe_interval);
+
+void ovsdb_idl_check_consistency(const struct ovsdb_idl *);
+
+const struct ovsdb_idl_class *ovsdb_idl_get_class(const struct ovsdb_idl *);
+const struct ovsdb_idl_table_class *ovsdb_idl_table_class_from_column(
+ const struct ovsdb_idl_class *, const struct ovsdb_idl_column *);
\f
/* Choosing columns and tables to replicate. */
void ovsdb_idl_loop_destroy(struct ovsdb_idl_loop *);
struct ovsdb_idl_txn *ovsdb_idl_loop_run(struct ovsdb_idl_loop *);
-void ovsdb_idl_loop_commit_and_wait(struct ovsdb_idl_loop *);
+int ovsdb_idl_loop_commit_and_wait(struct ovsdb_idl_loop *);
+\f
+/* Conditional Replication
+ * =======================
+ *
+ * By default, when the IDL replicates a particular table in the database, it
+ * replicates every row in the table. These functions allow the client to
+ * specify that only selected rows should be replicated, by constructing a
+ * per-table condition that specifies the rows to replicate.
+ *
+ * A condition is a disjunction of clauses. The condition is true, and thus a
+ * row is replicated, if any of the clauses evaluates to true for a given row.
+ * (Thus, a condition with no clauses is always false.)
+ */
struct ovsdb_idl_condition {
- const struct ovsdb_idl_table_class *tc;
- struct ovs_list clauses;
+ struct hmap clauses; /* Contains "struct ovsdb_idl_clause"s. */
+ bool is_true; /* Is the condition unconditionally true? */
};
+#define OVSDB_IDL_CONDITION_INIT(CONDITION) \
+ { HMAP_INITIALIZER(&(CONDITION)->clauses), false }
-struct ovsdb_idl_clause {
- struct ovs_list node;
- enum ovsdb_function function;
- const struct ovsdb_idl_column *column;
- struct ovsdb_datum arg;
-};
-
-void ovsdb_idl_condition_reset(struct ovsdb_idl *idl,
- const struct ovsdb_idl_table_class *tc);
-void ovsdb_idl_condition_add_clause(struct ovsdb_idl *idl,
- const struct ovsdb_idl_table_class *tc,
+void ovsdb_idl_condition_init(struct ovsdb_idl_condition *);
+void ovsdb_idl_condition_clear(struct ovsdb_idl_condition *);
+void ovsdb_idl_condition_destroy(struct ovsdb_idl_condition *);
+void ovsdb_idl_condition_add_clause(struct ovsdb_idl_condition *,
enum ovsdb_function function,
const struct ovsdb_idl_column *column,
- struct ovsdb_datum *arg);
-void ovsdb_idl_condition_remove_clause(struct ovsdb_idl *idl,
- const struct ovsdb_idl_table_class *tc,
- enum ovsdb_function function,
- const struct ovsdb_idl_column *column,
- struct ovsdb_datum *arg);
+ const struct ovsdb_datum *arg);
+void ovsdb_idl_condition_add_clause_true(struct ovsdb_idl_condition *);
+bool ovsdb_idl_condition_is_true(const struct ovsdb_idl_condition *);
+
+unsigned int ovsdb_idl_set_condition(struct ovsdb_idl *,
+ const struct ovsdb_idl_table_class *,
+ const struct ovsdb_idl_condition *);
+
+unsigned int ovsdb_idl_get_condition_seqno(const struct ovsdb_idl *);
+
+/* The OVSDB-IDL Compound Indexes feature allows for the creation of custom
+ * table indexes over one or more columns in the IDL. These indexes provide
+ * the ability to retrieve rows matching a particular search criteria and to
+ * iterate over a subset of rows in a defined order.
+ */
+
+#define OVSDB_INDEX_DESC -1
+#define OVSDB_INDEX_ASC 1
+
+/*
+ * Skiplist comparison function. Allows to store sorted data.
+ */
+typedef int (column_comparator)(const void *a, const void *b);
+
+struct ovsdb_idl_index_cursor {
+ struct ovsdb_idl_index *index; /* Index used by this cursor */
+ struct skiplist_node *position; /* Current position in the index */
+};
+
+struct ovsdb_idl_index *ovsdb_idl_create_index(struct ovsdb_idl *idl,
+ const struct ovsdb_idl_table_class *tc,
+ const char *index_name);
+void ovsdb_idl_index_add_column(struct ovsdb_idl_index *,
+ const struct ovsdb_idl_column *,
+ int order,
+ column_comparator *custom_comparer);
+bool ovsdb_idl_initialize_cursor(struct ovsdb_idl *,
+ const struct ovsdb_idl_table_class *tc,
+ const char *index_name,
+ struct ovsdb_idl_index_cursor *cursor);
+void ovsdb_idl_index_write_(struct ovsdb_idl_row *,
+ const struct ovsdb_idl_column *,
+ struct ovsdb_datum *,
+ const struct ovsdb_idl_table_class *);
+struct ovsdb_idl_row *ovsdb_idl_index_init_row(struct ovsdb_idl *,
+ const struct ovsdb_idl_table_class *);
+void ovsdb_idl_index_destroy_row__(const struct ovsdb_idl_row *);
+struct ovsdb_idl_row *ovsdb_idl_index_first(struct ovsdb_idl_index_cursor *);
+struct ovsdb_idl_row *ovsdb_idl_index_next(struct ovsdb_idl_index_cursor *);
+struct ovsdb_idl_row *ovsdb_idl_index_data(struct ovsdb_idl_index_cursor *);
+struct ovsdb_idl_row *ovsdb_idl_index_find(struct ovsdb_idl_index_cursor *,
+ struct ovsdb_idl_row *);
+struct ovsdb_idl_row *ovsdb_idl_index_forward_to(
+ struct ovsdb_idl_index_cursor *,
+ struct ovsdb_idl_row *);
+int ovsdb_idl_index_compare(struct ovsdb_idl_index_cursor *,
+ struct ovsdb_idl_row *a,
+ struct ovsdb_idl_row *b);
+
+#ifdef __cplusplus
+}
+#endif
#endif /* ovsdb-idl.h */