Will be used in the next commit to optimize database conversion.

Signed-off-by: Ilya Maximets <[email protected]>
---
 lib/ovsdb-types.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/ovsdb-types.h |  3 +++
 2 files changed, 64 insertions(+)

diff --git a/lib/ovsdb-types.c b/lib/ovsdb-types.c
index 61efe59cf..197cee1c6 100644
--- a/lib/ovsdb-types.c
+++ b/lib/ovsdb-types.c
@@ -275,6 +275,58 @@ ovsdb_base_type_is_valid(const struct ovsdb_base_type 
*base)
     }
 }
 
+bool
+ovsdb_base_type_equals(const struct ovsdb_base_type *a,
+                       const struct ovsdb_base_type *b)
+{
+    if (a == b) {
+        return true;
+    }
+
+    if (a->type != b->type) {
+        return false;
+    }
+
+    if ((a->enum_ && !b->enum_) || (!a->enum_ && b->enum_)) {
+        return false;
+    } else if (a->enum_ &&
+               !ovsdb_datum_equals(a->enum_, b->enum_,
+                                   ovsdb_base_type_get_enum_type(a->type))) {
+        return false;
+    }
+
+    switch (a->type) {
+    case OVSDB_TYPE_VOID:
+        return true;
+
+    case OVSDB_TYPE_INTEGER:
+        return a->integer.min == b->integer.min
+               && a->integer.max == b->integer.max;
+
+    case OVSDB_TYPE_REAL:
+        return a->real.min == b->real.min && a->real.max == b->real.max;
+
+    case OVSDB_TYPE_BOOLEAN:
+        return true;
+
+    case OVSDB_TYPE_STRING:
+        return a->string.minLen == b->string.minLen
+               && a->string.maxLen == b->string.maxLen;
+
+    case OVSDB_TYPE_UUID:
+        /* Not comparing the table pointer here, only the table name, as this
+         * function can be used to compare types from different databases, so
+         * pointers will be different. */
+        return a->uuid.refType == b->uuid.refType
+               && nullable_string_is_equal(a->uuid.refTableName,
+                                           b->uuid.refTableName);
+
+    case OVSDB_N_TYPES:
+    default:
+        OVS_NOT_REACHED();
+    }
+}
+
 bool
 ovsdb_base_type_has_constraints(const struct ovsdb_base_type *base)
 {
@@ -568,6 +620,15 @@ ovsdb_type_is_valid(const struct ovsdb_type *type)
             && type->n_max >= 1);
 }
 
+bool
+ovsdb_type_equals(const struct ovsdb_type *a, const struct ovsdb_type *b)
+{
+    return ovsdb_base_type_equals(&a->key, &b->key)
+           && ovsdb_base_type_equals(&a->value, &b->value)
+           && a->n_min == b->n_min
+           && a->n_max == b->n_max;
+}
+
 static struct ovsdb_error *
 n_from_json(const struct json *json, unsigned int *n)
 {
diff --git a/lib/ovsdb-types.h b/lib/ovsdb-types.h
index b9eb0928d..9777efea3 100644
--- a/lib/ovsdb-types.h
+++ b/lib/ovsdb-types.h
@@ -107,6 +107,8 @@ void ovsdb_base_type_clone(struct ovsdb_base_type *,
 void ovsdb_base_type_destroy(struct ovsdb_base_type *);
 
 bool ovsdb_base_type_is_valid(const struct ovsdb_base_type *);
+bool ovsdb_base_type_equals(const struct ovsdb_base_type *,
+                            const struct ovsdb_base_type *);
 bool ovsdb_base_type_has_constraints(const struct ovsdb_base_type *);
 void ovsdb_base_type_clear_constraints(struct ovsdb_base_type *);
 const struct ovsdb_type *ovsdb_base_type_get_enum_type(enum ovsdb_atomic_type);
@@ -157,6 +159,7 @@ void ovsdb_type_clone(struct ovsdb_type *, const struct 
ovsdb_type *);
 void ovsdb_type_destroy(struct ovsdb_type *);
 
 bool ovsdb_type_is_valid(const struct ovsdb_type *);
+bool ovsdb_type_equals(const struct ovsdb_type *, const struct ovsdb_type *);
 
 static inline bool ovsdb_type_is_scalar(const struct ovsdb_type *);
 static inline bool ovsdb_type_is_optional(const struct ovsdb_type *);
-- 
2.38.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to