[ovs-dev,v3,ovn,3/3] OVN: northd: add rate limiting support for SB controller events
diff mbox series

Message ID 77ceea354e1ab13b7679b479fcc4da5cc5e55ad9.1566222622.git.lorenzo.bianconi@redhat.com
State Superseded
Headers show
Series
  • add rate limiting support for controller_events
Related show

Commit Message

Lorenzo Bianconi Aug. 19, 2019, 2:37 p.m. UTC
Introduce the capability to associate a meter to each controller event
type in order to not overload the pinctrl thread under heavy load.
Each event type relies on a meter with a defined name:
- empty_lb_backends: event-elb

Acked-by: Mark Michelson <mmichels@redhat.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
 northd/ovn-northd.c | 44 +++++++++++++++++++++++++++++++++++---------
 ovn-nb.xml          |  8 ++++++++
 tests/ovn.at        |  1 +
 3 files changed, 44 insertions(+), 9 deletions(-)

Comments

Numan Siddique Aug. 21, 2019, 8:20 p.m. UTC | #1
On Mon, Aug 19, 2019 at 8:09 PM Lorenzo Bianconi <
lorenzo.bianconi@redhat.com> wrote:

> Introduce the capability to associate a meter to each controller event
> type in order to not overload the pinctrl thread under heavy load.
> Each event type relies on a meter with a defined name:
> - empty_lb_backends: event-elb
>
> Acked-by: Mark Michelson <mmichels@redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
>

Hi Lorenzo,

Looks like the patch [1] which added the trigger_event flow in ovn-northd
missed
out updating the ovn-northd.8.xml.

And since this patch updates the logical flow a bit, can you please update
this patch
with documentation in ovn-northd.8.xml ?

[1] -
https://github.com/ovn-org/ovn/commit/f49b17a6cbe30ee05dc9743554c8ece92b16db48#diff-cc9e65b93a60efcce2e845453dcb56d3

Thanks
Numan

---
>  northd/ovn-northd.c | 44 +++++++++++++++++++++++++++++++++++---------
>  ovn-nb.xml          |  8 ++++++++
>  tests/ovn.at        |  1 +
>  3 files changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index e29b0fff4..27395d6bd 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -4002,7 +4002,8 @@ ls_has_dns_records(const struct nbrec_logical_switch
> *nbs)
>  }
>
>  static void
> -build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
> +build_pre_lb(struct ovn_datapath *od, struct hmap *lflows,
> +             struct shash *meter_groups)
>  {
>      /* Do not send ND packets to conntrack */
>      ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 110,
> @@ -4040,7 +4041,11 @@ build_pre_lb(struct ovn_datapath *od, struct hmap
> *lflows)
>
>              if (controller_event_en && !node->value[0]) {
>                  struct ds match = DS_EMPTY_INITIALIZER;
> -                char *action;
> +                char *meter = "", *action;
> +
> +                if (shash_find(meter_groups, "event-elb")) {
> +                    meter = "event-elb";
> +                }
>
>                  if (addr_family == AF_INET) {
>                      ds_put_format(&match, "ip4.dst == %s && %s",
> @@ -4054,10 +4059,11 @@ build_pre_lb(struct ovn_datapath *od, struct hmap
> *lflows)
>                                    port);
>                  }
>                  action = xasprintf("trigger_event(event = \"%s\", "
> -                               "vip = \"%s\", protocol = \"%s\", "
> +                               "meter = \"%s\", vip = \"%s\", "
> +                               "protocol = \"%s\", "
>                                 "load_balancer = \"" UUID_FMT "\");",
>
> event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS),
> -                               node->key, lb->protocol,
> +                               meter, node->key, lb->protocol,
>                                 UUID_ARGS(&lb->header_.uuid));
>                  ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 120,
>                                ds_cstr(&match), action);
> @@ -4884,7 +4890,8 @@ build_lrouter_groups(struct hmap *ports, struct
> ovs_list *lr_list)
>  static void
>  build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
>                      struct hmap *port_groups, struct hmap *lflows,
> -                    struct hmap *mcgroups, struct hmap *igmp_groups)
> +                    struct hmap *mcgroups, struct hmap *igmp_groups,
> +                    struct shash *meter_groups)
>  {
>      /* This flow table structure is documented in ovn-northd(8), so please
>       * update ovn-northd.8.xml if you change anything. */
> @@ -4901,7 +4908,7 @@ build_lswitch_flows(struct hmap *datapaths, struct
> hmap *ports,
>          }
>
>          build_pre_acls(od, lflows);
> -        build_pre_lb(od, lflows);
> +        build_pre_lb(od, lflows, meter_groups);
>          build_pre_stateful(od, lflows);
>          build_acls(od, lflows, port_groups);
>          build_qos(od, lflows);
> @@ -8233,12 +8240,13 @@ build_lrouter_flows(struct hmap *datapaths, struct
> hmap *ports,
>  static void
>  build_lflows(struct northd_context *ctx, struct hmap *datapaths,
>               struct hmap *ports, struct hmap *port_groups,
> -             struct hmap *mcgroups, struct hmap *igmp_groups)
> +             struct hmap *mcgroups, struct hmap *igmp_groups,
> +             struct shash *meter_groups)
>  {
>      struct hmap lflows = HMAP_INITIALIZER(&lflows);
>
>      build_lswitch_flows(datapaths, ports, port_groups, &lflows, mcgroups,
> -                        igmp_groups);
> +                        igmp_groups, meter_groups);
>      build_lrouter_flows(datapaths, ports, &lflows);
>
>      /* Push changes to the Logical_Flow table to database. */
> @@ -8906,6 +8914,16 @@ build_mcast_groups(struct northd_context *ctx,
>      }
>  }
>
> +static void
> +build_meter_groups(struct northd_context *ctx,
> +                   struct shash *meter_groups)
> +{
> +    const struct nbrec_meter *nb_meter;
> +    NBREC_METER_FOR_EACH (nb_meter, ctx->ovnnb_idl) {
> +        shash_add(meter_groups, nb_meter->name, nb_meter);
> +    }
> +}
> +
>  static void
>  ovnnb_db_run(struct northd_context *ctx,
>               struct ovsdb_idl_index *sbrec_chassis_by_name,
> @@ -8919,6 +8937,7 @@ ovnnb_db_run(struct northd_context *ctx,
>      struct hmap port_groups;
>      struct hmap mcast_groups;
>      struct hmap igmp_groups;
> +    struct shash meter_groups = SHASH_INITIALIZER(&meter_groups);
>
>      build_datapaths(ctx, datapaths, lr_list);
>      build_ports(ctx, sbrec_chassis_by_name, datapaths, ports);
> @@ -8927,8 +8946,9 @@ ovnnb_db_run(struct northd_context *ctx,
>      build_lrouter_groups(ports, lr_list);
>      build_ip_mcast(ctx, datapaths);
>      build_mcast_groups(ctx, datapaths, ports, &mcast_groups,
> &igmp_groups);
> +    build_meter_groups(ctx, &meter_groups);
>      build_lflows(ctx, datapaths, ports, &port_groups, &mcast_groups,
> -                 &igmp_groups);
> +                 &igmp_groups, &meter_groups);
>
>      sync_address_sets(ctx);
>      sync_port_groups(ctx);
> @@ -8949,6 +8969,12 @@ ovnnb_db_run(struct northd_context *ctx,
>      hmap_destroy(&mcast_groups);
>      hmap_destroy(&port_groups);
>
> +    struct shash_node *node, *next;
> +    SHASH_FOR_EACH_SAFE (node, next, &meter_groups) {
> +        shash_delete(&meter_groups, node);
> +    }
> +    shash_destroy(&meter_groups);
> +
>      /* Sync ipsec configuration.
>       * Copy nb_cfg from northbound to southbound database.
>       * Also set up to update sb_cfg once our southbound transaction
> commits. */
> diff --git a/ovn-nb.xml b/ovn-nb.xml
> index 1f8d7518f..365704a8b 100644
> --- a/ovn-nb.xml
> +++ b/ovn-nb.xml
> @@ -117,6 +117,14 @@
>          <ref table="Controller_Event"/> table.
>          The intention is for a CMS to see the events and take some sort of
>          action. Please see the <ref table="Controller_Event"/> table in
> SBDB.
> +        It is possible to associate a meter to each controller event type
> +        in order to not overload the pinctrl thread under heavy load.
> +        Each event type relies on a meter with a defined name:
> +
> +        <ul>
> +          <li>empty_lb_backends: event-elb</li>
> +        </ul>
> +
>        </column>
>      </group>
>
> diff --git a/tests/ovn.at b/tests/ovn.at
> index 52c044c8d..009de59ce 100644
> --- a/tests/ovn.at
> +++ b/tests/ovn.at
> @@ -14689,6 +14689,7 @@ ovn-nbctl --wait=hv set NB_Global .
> options:controller_event=true
>  ovn-nbctl lb-add lb0 192.168.1.100:80 ""
>  ovn-nbctl ls-lb-add sw0 lb0
>  uuid_lb=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb0)
> +ovn-nbctl --wait=hv meter-add event-elb drop 100 pktps 10
>
>  OVN_POPULATE_ARP
>  ovn-nbctl --timeout=3 --wait=hv sync
> --
> 2.21.0
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

Patch
diff mbox series

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index e29b0fff4..27395d6bd 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -4002,7 +4002,8 @@  ls_has_dns_records(const struct nbrec_logical_switch *nbs)
 }
 
 static void
-build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
+build_pre_lb(struct ovn_datapath *od, struct hmap *lflows,
+             struct shash *meter_groups)
 {
     /* Do not send ND packets to conntrack */
     ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 110,
@@ -4040,7 +4041,11 @@  build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
 
             if (controller_event_en && !node->value[0]) {
                 struct ds match = DS_EMPTY_INITIALIZER;
-                char *action;
+                char *meter = "", *action;
+
+                if (shash_find(meter_groups, "event-elb")) {
+                    meter = "event-elb";
+                }
 
                 if (addr_family == AF_INET) {
                     ds_put_format(&match, "ip4.dst == %s && %s",
@@ -4054,10 +4059,11 @@  build_pre_lb(struct ovn_datapath *od, struct hmap *lflows)
                                   port);
                 }
                 action = xasprintf("trigger_event(event = \"%s\", "
-                               "vip = \"%s\", protocol = \"%s\", "
+                               "meter = \"%s\", vip = \"%s\", "
+                               "protocol = \"%s\", "
                                "load_balancer = \"" UUID_FMT "\");",
                                event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS),
-                               node->key, lb->protocol,
+                               meter, node->key, lb->protocol,
                                UUID_ARGS(&lb->header_.uuid));
                 ovn_lflow_add(lflows, od, S_SWITCH_IN_PRE_LB, 120,
                               ds_cstr(&match), action);
@@ -4884,7 +4890,8 @@  build_lrouter_groups(struct hmap *ports, struct ovs_list *lr_list)
 static void
 build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                     struct hmap *port_groups, struct hmap *lflows,
-                    struct hmap *mcgroups, struct hmap *igmp_groups)
+                    struct hmap *mcgroups, struct hmap *igmp_groups,
+                    struct shash *meter_groups)
 {
     /* This flow table structure is documented in ovn-northd(8), so please
      * update ovn-northd.8.xml if you change anything. */
@@ -4901,7 +4908,7 @@  build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
         }
 
         build_pre_acls(od, lflows);
-        build_pre_lb(od, lflows);
+        build_pre_lb(od, lflows, meter_groups);
         build_pre_stateful(od, lflows);
         build_acls(od, lflows, port_groups);
         build_qos(od, lflows);
@@ -8233,12 +8240,13 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
 static void
 build_lflows(struct northd_context *ctx, struct hmap *datapaths,
              struct hmap *ports, struct hmap *port_groups,
-             struct hmap *mcgroups, struct hmap *igmp_groups)
+             struct hmap *mcgroups, struct hmap *igmp_groups,
+             struct shash *meter_groups)
 {
     struct hmap lflows = HMAP_INITIALIZER(&lflows);
 
     build_lswitch_flows(datapaths, ports, port_groups, &lflows, mcgroups,
-                        igmp_groups);
+                        igmp_groups, meter_groups);
     build_lrouter_flows(datapaths, ports, &lflows);
 
     /* Push changes to the Logical_Flow table to database. */
@@ -8906,6 +8914,16 @@  build_mcast_groups(struct northd_context *ctx,
     }
 }
 
+static void
+build_meter_groups(struct northd_context *ctx,
+                   struct shash *meter_groups)
+{
+    const struct nbrec_meter *nb_meter;
+    NBREC_METER_FOR_EACH (nb_meter, ctx->ovnnb_idl) {
+        shash_add(meter_groups, nb_meter->name, nb_meter);
+    }
+}
+
 static void
 ovnnb_db_run(struct northd_context *ctx,
              struct ovsdb_idl_index *sbrec_chassis_by_name,
@@ -8919,6 +8937,7 @@  ovnnb_db_run(struct northd_context *ctx,
     struct hmap port_groups;
     struct hmap mcast_groups;
     struct hmap igmp_groups;
+    struct shash meter_groups = SHASH_INITIALIZER(&meter_groups);
 
     build_datapaths(ctx, datapaths, lr_list);
     build_ports(ctx, sbrec_chassis_by_name, datapaths, ports);
@@ -8927,8 +8946,9 @@  ovnnb_db_run(struct northd_context *ctx,
     build_lrouter_groups(ports, lr_list);
     build_ip_mcast(ctx, datapaths);
     build_mcast_groups(ctx, datapaths, ports, &mcast_groups, &igmp_groups);
+    build_meter_groups(ctx, &meter_groups);
     build_lflows(ctx, datapaths, ports, &port_groups, &mcast_groups,
-                 &igmp_groups);
+                 &igmp_groups, &meter_groups);
 
     sync_address_sets(ctx);
     sync_port_groups(ctx);
@@ -8949,6 +8969,12 @@  ovnnb_db_run(struct northd_context *ctx,
     hmap_destroy(&mcast_groups);
     hmap_destroy(&port_groups);
 
+    struct shash_node *node, *next;
+    SHASH_FOR_EACH_SAFE (node, next, &meter_groups) {
+        shash_delete(&meter_groups, node);
+    }
+    shash_destroy(&meter_groups);
+
     /* Sync ipsec configuration.
      * Copy nb_cfg from northbound to southbound database.
      * Also set up to update sb_cfg once our southbound transaction commits. */
diff --git a/ovn-nb.xml b/ovn-nb.xml
index 1f8d7518f..365704a8b 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -117,6 +117,14 @@ 
         <ref table="Controller_Event"/> table.
         The intention is for a CMS to see the events and take some sort of
         action. Please see the <ref table="Controller_Event"/> table in SBDB.
+        It is possible to associate a meter to each controller event type
+        in order to not overload the pinctrl thread under heavy load.
+        Each event type relies on a meter with a defined name:
+
+        <ul>
+          <li>empty_lb_backends: event-elb</li>
+        </ul>
+
       </column>
     </group>
 
diff --git a/tests/ovn.at b/tests/ovn.at
index 52c044c8d..009de59ce 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -14689,6 +14689,7 @@  ovn-nbctl --wait=hv set NB_Global . options:controller_event=true
 ovn-nbctl lb-add lb0 192.168.1.100:80 ""
 ovn-nbctl ls-lb-add sw0 lb0
 uuid_lb=$(ovn-nbctl --bare --columns=_uuid find load_balancer name=lb0)
+ovn-nbctl --wait=hv meter-add event-elb drop 100 pktps 10
 
 OVN_POPULATE_ARP
 ovn-nbctl --timeout=3 --wait=hv sync