[ovs-dev,RFC,v2,ovn,4/5] ovn-northd: Extend metering to Controller-Events
diff mbox series

Message ID 20191105125349.4760.36202.stgit@dceara.remote.csb
State New
Headers show
Series
  • Add CoPP (Control Plane Protection).
Related show

Commit Message

Dumitru Ceara Nov. 5, 2019, 12:53 p.m. UTC
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
---
 include/ovn/actions.h |    1 -
 lib/actions.c         |   50 +++++++++----------------------------------------
 northd/ovn-northd.c   |   15 +++++++--------
 tests/ovn.at          |    3 +--
 4 files changed, 17 insertions(+), 52 deletions(-)

Patch
diff mbox series

diff --git a/include/ovn/actions.h b/include/ovn/actions.h
index 8fc7727..9371e32 100644
--- a/include/ovn/actions.h
+++ b/include/ovn/actions.h
@@ -342,7 +342,6 @@  struct ovnact_controller_event {
     int event_type;   /* controller event type */
     struct ovnact_gen_option *options;
     size_t n_options;
-    char *meter;
 };
 
 /* OVNACT_BIND_VPORT. */
diff --git a/lib/actions.c b/lib/actions.c
index 32bc4d5..7708712 100644
--- a/lib/actions.c
+++ b/lib/actions.c
@@ -1292,9 +1292,6 @@  format_TRIGGER_EVENT(const struct ovnact_controller_event *event,
 {
     ds_put_format(s, "trigger_event(event = \"%s\"",
                   event_to_string(event->event_type));
-    if (event->meter) {
-        ds_put_format(s, ", meter = \"%s\"", event->meter);
-    }
     for (const struct ovnact_gen_option *o = event->options;
          o < &event->options[event->n_options]; o++) {
         ds_put_cstr(s, ", ");
@@ -1439,24 +1436,11 @@  encode_event_empty_lb_backends_opts(struct ofpbuf *ofpacts,
 
 static void
 encode_TRIGGER_EVENT(const struct ovnact_controller_event *event,
-                     const struct ovnact_encode_params *ep OVS_UNUSED,
+                     const struct ovnact_encode_params *ep,
                      struct ofpbuf *ofpacts)
 {
-    uint32_t meter_id = NX_CTLR_NO_METER;
-    size_t oc_offset;
-
-    if (event->meter) {
-        meter_id = ovn_extend_table_assign_id(ep->meter_table, event->meter,
-                                              ep->lflow_uuid);
-        if (meter_id == EXT_TABLE_ID_INVALID) {
-            VLOG_WARN("Unable to assign id for trigger meter: %s",
-                      event->meter);
-            return;
-        }
-    }
-
-    oc_offset = encode_start_controller_op(ACTION_OPCODE_EVENT, false,
-                                           meter_id, ofpacts);
+    size_t oc_offset = encode_start_controller_op(ACTION_OPCODE_EVENT, false,
+                                                  ep->ctrl_meter_id, ofpacts);
     ovs_be32 ofs = htonl(event->event_type);
     ofpbuf_put(ofpacts, &ofs, sizeof ofs);
 
@@ -1878,27 +1862,12 @@  parse_trigger_event(struct action_context *ctx,
                                      sizeof *event->options);
         }
 
-        if (lexer_match_id(ctx->lexer, "meter")) {
-            if (!lexer_force_match(ctx->lexer, LEX_T_EQUALS)) {
-                return;
-            }
-            /* If multiple meters are given, use the most recent. */
-            if (ctx->lexer->token.type == LEX_T_STRING &&
-                strlen(ctx->lexer->token.s)) {
-                free(event->meter);
-                event->meter = xstrdup(ctx->lexer->token.s);
-            } else if (ctx->lexer->token.type != LEX_T_STRING) {
-                lexer_syntax_error(ctx->lexer, "expecting string");
-                return;
-            }
-            lexer_get(ctx->lexer);
-        } else {
-            struct ovnact_gen_option *o = &event->options[event->n_options++];
-            memset(o, 0, sizeof *o);
-            parse_gen_opt(ctx, o,
-                    &ctx->pp->controller_event_opts->event_opts[event_type],
-                    event_to_string(event_type));
-            }
+        struct ovnact_gen_option *o = &event->options[event->n_options++];
+        memset(o, 0, sizeof *o);
+        parse_gen_opt(ctx, o,
+                      &ctx->pp->controller_event_opts->event_opts[event_type],
+                      event_to_string(event_type));
+
         if (ctx->lexer->error) {
             return;
         }
@@ -1919,7 +1888,6 @@  static void
 ovnact_controller_event_free(struct ovnact_controller_event *event)
 {
     free_gen_options(event->options, event->n_options);
-    free(event->meter);
 }
 
 static void
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index ec45021..4e53690 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -4288,11 +4288,7 @@  build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows,
     }
 
     struct ds match = DS_EMPTY_INITIALIZER;
-    char *meter = "", *action;
-
-    if (meter_groups && shash_find(meter_groups, "event-elb")) {
-        meter = "event-elb";
-    }
+    char *action;
 
     if (addr_family == AF_INET) {
         ds_put_format(&match, "ip4.dst == %s && %s",
@@ -4306,13 +4302,16 @@  build_empty_lb_event_flow(struct ovn_datapath *od, struct hmap *lflows,
                       port);
     }
     action = xasprintf("trigger_event(event = \"%s\", "
-                       "meter = \"%s\", vip = \"%s\", "
+                       "vip = \"%s\", "
                        "protocol = \"%s\", "
                        "load_balancer = \"" UUID_FMT "\");",
                        event_to_string(OVN_EVENT_EMPTY_LB_BACKENDS),
-                       meter, node->key, lb->protocol,
+                       node->key, lb->protocol,
                        UUID_ARGS(&lb->header_.uuid));
-    ovn_lflow_add(lflows, od, pl, 130, ds_cstr(&match), action);
+
+    const struct nbrec_copp *copp = (od->nbr ? od->nbr->copp : od->nbs->copp);
+    ovn_lflow_add_ctrl(lflows, od, pl, 130, ds_cstr(&match), action,
+                       copp_meter_get(COPP_EVENT_ELB, copp, meter_groups));
     ds_destroy(&match);
     free(action);
 }
diff --git a/tests/ovn.at b/tests/ovn.at
index 410f4b5..8d66753 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -1416,8 +1416,7 @@  trigger_event(event = "empty_lb_backends", vip = "10.0.0.1:80", protocol = "tcp"
     encodes as controller(userdata=00.00.00.0f.00.00.00.00.00.00.00.00.00.01.00.0b.31.30.2e.30.2e.30.2e.31.3a.38.30.00.02.00.03.74.63.70.00.03.00.24.31.32.33.34.35.36.37.38.2d.61.62.63.64.2d.39.38.37.36.2d.66.65.64.63.2d.31.31.31.31.39.66.38.65.37.64.36.63)
 
 trigger_event(event = "empty_lb_backends", meter="event-elb" vip = "10.0.0.1:80", protocol = "tcp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c");
-    formats as trigger_event(event = "empty_lb_backends", meter = "event-elb", vip = "10.0.0.1:80", protocol = "tcp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c");
-    encodes as controller(userdata=00.00.00.0f.00.00.00.00.00.00.00.00.00.01.00.0b.31.30.2e.30.2e.30.2e.31.3a.38.30.00.02.00.03.74.63.70.00.03.00.24.31.32.33.34.35.36.37.38.2d.61.62.63.64.2d.39.38.37.36.2d.66.65.64.63.2d.31.31.31.31.39.66.38.65.37.64.36.63,meter_id=5)
+    Syntax error at `meter' expecting empty_lb_backends option name.
 
 # Testing invalid vip results in extra error messages from socket-util.c
 trigger_event(event = "empty_lb_backends", vip = "10.0.0.1:80", protocol = "sctp", load_balancer = "12345678-abcd-9876-fedc-11119f8e7d6c");