[ovs-dev,RFC,14/14] ovn-controller: Incremental processing for port-group changes.

Message ID 1532480380-97578-15-git-send-email-hzhou8@ebay.com
State RFC
Headers show
Series
  • ovn-controller incremental processing.
Related show

Commit Message

Han Zhou July 25, 2018, 12:59 a.m.
Signed-off-by: Han Zhou <hzhou8@ebay.com>
---
 ovn/controller/lflow.h          |   3 +-
 ovn/controller/ovn-controller.c | 110 ++++++++++++++++++++++++++++++++++------
 2 files changed, 97 insertions(+), 16 deletions(-)

Patch

diff --git a/ovn/controller/lflow.h b/ovn/controller/lflow.h
index 01dda1d..b90f971 100644
--- a/ovn/controller/lflow.h
+++ b/ovn/controller/lflow.h
@@ -70,7 +70,8 @@  struct uuid;
 #define LOG_PIPELINE_LEN 24
 
 enum ref_type {
-    REF_TYPE_ADDRSET
+    REF_TYPE_ADDRSET,
+    REF_TYPE_PORTGROUP
 };
 
 /* Maintains the relationship for a pair of named resource and
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 13bc333..1f95acb 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -330,6 +330,29 @@  port_groups_init(const struct sbrec_port_group_table *port_group_table,
 }
 
 static void
+port_groups_update(const struct sbrec_port_group_table *port_group_table,
+                   struct shash *port_groups, struct sset *new,
+                   struct sset *deleted, struct sset *updated)
+{
+    const struct sbrec_port_group *pg;
+    SBREC_PORT_GROUP_TABLE_FOR_EACH_TRACKED (pg, port_group_table) {
+        if (sbrec_port_group_is_deleted(pg)) {
+            expr_const_sets_remove(port_groups, pg->name);
+            sset_add(deleted, pg->name);
+        } else {
+            expr_const_sets_add(port_groups, pg->name,
+                                (const char *const *) pg->ports,
+                                pg->n_ports, false);
+            if (sbrec_port_group_is_new(pg)) {
+                sset_add(new, pg->name);
+            } else {
+                sset_add(updated, pg->name);
+            }
+        }
+    }
+}
+
+static void
 update_ssl_config(const struct ovsrec_ssl_table *ssl_table)
 {
     const struct ovsrec_ssl *ssl = ovsrec_ssl_table_first(ssl_table);
@@ -748,6 +771,30 @@  en_port_groups_run(struct engine_node *node)
     node->changed = true;
 }
 
+static bool
+port_groups_sb_port_group_handler(struct engine_node *node)
+{
+    struct ed_type_port_groups *pg = (struct ed_type_port_groups *)node->data;
+
+    sset_clear(&pg->new);
+    sset_clear(&pg->deleted);
+    sset_clear(&pg->updated);
+
+    struct sbrec_port_group_table *pg_table =
+        (struct sbrec_port_group_table *)EN_OVSDB_GET(
+            engine_get_input("SB_port_group", node));
+
+    port_groups_update(pg_table, &pg->port_groups, &pg->new,
+                     &pg->deleted, &pg->updated);
+
+    node->changed = !sset_is_empty(&pg->new) || !sset_is_empty(&pg->deleted)
+                    || !sset_is_empty(&pg->updated);
+
+    pg->change_tracked = true;
+    node->changed = true;
+    return true;
+}
+
 struct ed_type_runtime_data {
     /* Contains "struct local_datapath" nodes. */
     struct hmap local_datapaths;
@@ -1338,7 +1385,8 @@  flow_output_sb_multicast_group_handler(struct engine_node *node)
 }
 
 static bool
-flow_output_addr_sets_handler(struct engine_node *node)
+_flow_output_resource_ref_handler(struct engine_node *node,
+                                 enum ref_type ref_type)
 {
     struct ed_type_runtime_data *data =
         (struct ed_type_runtime_data *)engine_get_input(
@@ -1349,11 +1397,6 @@  flow_output_addr_sets_handler(struct engine_node *node)
 
     struct ed_type_addr_sets *as_data =
         (struct ed_type_addr_sets *)engine_get_input("addr_sets", node)->data;
-
-    /* XXX: The change_tracked check may be added to inc-proc framework. */
-    if (!as_data->change_tracked) {
-        return false;
-    }
     struct shash *addr_sets = &as_data->addr_sets;
 
     struct ed_type_port_groups *pg_data =
@@ -1412,10 +1455,35 @@  flow_output_addr_sets_handler(struct engine_node *node)
             engine_get_input("SB_logical_flow", node));
 
     bool changed;
-    const char *as;
+    const char *ref_name;
+    struct sset *new, *updated, *deleted;
+
+    switch (ref_type) {
+        case REF_TYPE_ADDRSET:
+            /* XXX: The change_tracked check may be added to inc-proc
+             * framework. */
+            if (!as_data->change_tracked) {
+                return false;
+            }
+            new = &as_data->new;
+            updated = &as_data->updated;
+            deleted = &as_data->deleted;
+            break;
+        case REF_TYPE_PORTGROUP:
+            if (!pg_data->change_tracked) {
+                return false;
+            }
+            new = &pg_data->new;
+            updated = &pg_data->updated;
+            deleted = &pg_data->deleted;
+            break;
+        default:
+            OVS_NOT_REACHED();
+    }
+
 
-    SSET_FOR_EACH (as, &as_data->deleted) {
-        if (!lflow_handle_changed_ref(REF_TYPE_ADDRSET, as,
+    SSET_FOR_EACH (ref_name, deleted) {
+        if (!lflow_handle_changed_ref(ref_type, ref_name,
                     sbrec_chassis_by_name,
                     sbrec_multicast_group_by_name_datapath,
                     sbrec_port_binding_by_name,dhcp_table,
@@ -1428,8 +1496,8 @@  flow_output_addr_sets_handler(struct engine_node *node)
         }
         node->changed = changed || node->changed;
     }
-    SSET_FOR_EACH (as, &as_data->updated) {
-        if (!lflow_handle_changed_ref(REF_TYPE_ADDRSET, as,
+    SSET_FOR_EACH (ref_name, updated) {
+        if (!lflow_handle_changed_ref(ref_type, ref_name,
                     sbrec_chassis_by_name,
                     sbrec_multicast_group_by_name_datapath,
                     sbrec_port_binding_by_name,dhcp_table,
@@ -1442,8 +1510,8 @@  flow_output_addr_sets_handler(struct engine_node *node)
         }
         node->changed = changed || node->changed;
     }
-    SSET_FOR_EACH (as, &as_data->new) {
-        if (!lflow_handle_changed_ref(REF_TYPE_ADDRSET, as,
+    SSET_FOR_EACH (ref_name, new) {
+        if (!lflow_handle_changed_ref(ref_type, ref_name,
                     sbrec_chassis_by_name,
                     sbrec_multicast_group_by_name_datapath,
                     sbrec_port_binding_by_name,dhcp_table,
@@ -1460,6 +1528,18 @@  flow_output_addr_sets_handler(struct engine_node *node)
     return true;
 }
 
+static bool
+flow_output_addr_sets_handler(struct engine_node *node)
+{
+    return _flow_output_resource_ref_handler(node, REF_TYPE_ADDRSET);
+}
+
+static bool
+flow_output_port_groups_handler(struct engine_node *node)
+{
+    return _flow_output_resource_ref_handler(node, REF_TYPE_PORTGROUP);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -1552,10 +1632,10 @@  main(int argc, char *argv[])
     ENGINE_NODE(port_groups, "port_groups");
 
     engine_add_input(&en_addr_sets, &en_sb_address_set, addr_sets_sb_address_set_handler);
-    engine_add_input(&en_port_groups, &en_sb_port_group, NULL);
+    engine_add_input(&en_port_groups, &en_sb_port_group, port_groups_sb_port_group_handler);
 
     engine_add_input(&en_flow_output, &en_addr_sets, flow_output_addr_sets_handler);
-    engine_add_input(&en_flow_output, &en_port_groups, NULL);
+    engine_add_input(&en_flow_output, &en_port_groups, flow_output_port_groups_handler);
     engine_add_input(&en_flow_output, &en_runtime_data, NULL);
 
     engine_add_input(&en_flow_output, &en_ovs_open_vswitch, NULL);