[ovs-dev,action,upcall,meters,5/5] ofproto: Meter slowpath action when action upcall meters are configured

Submitted by andy zhou on April 14, 2017, 7:46 p.m.

Details

Message ID 1492199182-4479-6-git-send-email-azhou@ovn.org
State Superseded
Headers show

Commit Message

andy zhou April 14, 2017, 7:46 p.m.
If a slow path action is a controller action, meter it when the
controller meter is configured.  For other kinds of slow path actions,
meter it when the slowpath meter is configured.

Note, this patch only considers the meters configuration of the
packet's input bridge, which may not be the same bridge that the
action is generated.

Signed-off-by: Andy Zhou <azhou@ovn.org>
---
 ofproto/ofproto-dpif-upcall.c | 34 +++++++++++++++++++++++++++++++---
 ofproto/ofproto-dpif-xlate.c  | 12 ++++++------
 tests/ofproto-dpif.at         | 31 +++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 9 deletions(-)

Comments

Jarno Rajahalme April 27, 2017, 10:49 p.m.
See comments below.

  Jarno

> On Apr 14, 2017, at 12:46 PM, Andy Zhou <azhou@ovn.org> wrote:
> 
> If a slow path action is a controller action, meter it when the
> controller meter is configured.  For other kinds of slow path actions,
> meter it when the slowpath meter is configured.
> 
> Note, this patch only considers the meters configuration of the
> packet's input bridge, which may not be the same bridge that the
> action is generated.
> 
> Signed-off-by: Andy Zhou <azhou@ovn.org>
> ---
> ofproto/ofproto-dpif-upcall.c | 34 +++++++++++++++++++++++++++++++---
> ofproto/ofproto-dpif-xlate.c  | 12 ++++++------
> tests/ofproto-dpif.at         | 31 +++++++++++++++++++++++++++++++
> 3 files changed, 68 insertions(+), 9 deletions(-)
> 
> diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
> index 3b28f9a22939..37f345b235b1 100644
> --- a/ofproto/ofproto-dpif-upcall.c
> +++ b/ofproto/ofproto-dpif-upcall.c
> @@ -1018,7 +1018,8 @@ classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata)
> static void
> compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
>                   const struct flow *flow, odp_port_t odp_in_port,
> -                  struct ofpbuf *buf)
> +                  struct ofpbuf *buf, uint32_t slowpath_meter_id,
> +                  uint32_t controller_meter_id)
> {
>     union user_action_cookie cookie;
>     odp_port_t port;
> @@ -1032,8 +1033,28 @@ compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
>         ? ODPP_NONE
>         : odp_in_port;
>     pid = dpif_port_get_pid(udpif->dpif, port, flow_hash_5tuple(flow, 0));
> +
> +    size_t offset;
> +    size_t ac_offset;
> +    uint32_t meter_id = xout->slow & SLOW_CONTROLLER ? controller_meter_id
> +                                                     : slowpath_meter_id;
> +
> +    if (meter_id != UINT32_MAX) {
> +        /* If slowpath meter is configured, generate clone(meter, userspace)
> +         * action.   */
> +        offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SAMPLE);
> +        nl_msg_put_u32(buf, OVS_SAMPLE_ATTR_PROBABILITY, UINT32_MAX);
> +        ac_offset = nl_msg_start_nested(buf, OVS_SAMPLE_ATTR_ACTIONS);
> +        nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id);
> +    }
> +
>     odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path,
>                              ODPP_NONE, false, buf);
> +
> +    if (meter_id != UINT32_MAX) {
> +        nl_msg_end_nested(buf, ac_offset);
> +        nl_msg_end_nested(buf, offset);
> +    }
> }
> 
> /* If there is no error, the upcall must be destroyed with upcall_uninit()
> @@ -1136,10 +1157,12 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall,
>         ofpbuf_use_const(&upcall->put_actions,
>                          odp_actions->data, odp_actions->size);
>     } else {
> +        uint32_t smid= upcall->ofproto->up.slowpath_meter_id;

white space error.

> +        uint32_t cmid = upcall->ofproto->up.controller_meter_id;
>         /* upcall->put_actions already initialized by upcall_receive(). */
>         compose_slow_path(udpif, &upcall->xout, upcall->flow,
>                           upcall->flow->in_port.odp_port,
> -                          &upcall->put_actions);
> +                          &upcall->put_actions, smid, cmid);
>     }
> 
>     /* This function is also called for slow-pathed flows.  As we are only
> @@ -1956,9 +1979,14 @@ revalidate_ukey__(struct udpif *udpif, const struct udpif_key *ukey,
>     }
> 
>     if (xoutp->slow) {
> +        struct ofproto_dpif *ofproto;
> +        ofproto = xlate_lookup_ofproto(udpif->backer, &ctx.flow, NULL);
> +        uint32_t smid= ofproto->up.slowpath_meter_id;
> +        uint32_t cmid= ofproto->up.controller_meter_id;
> +
>         ofpbuf_clear(odp_actions);
>         compose_slow_path(udpif, xoutp, &ctx.flow, ctx.flow.in_port.odp_port,
> -                          odp_actions);
> +                          odp_actions, smid, cmid);
>     }
> 
>     if (odp_flow_key_to_mask(ukey->mask, ukey->mask_len, &dp_mask, &ctx.flow)
> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
> index 52e0d3f1b0bb..416012ab6930 100644
> --- a/ofproto/ofproto-dpif-xlate.c
> +++ b/ofproto/ofproto-dpif-xlate.c
> @@ -2849,8 +2849,13 @@ compose_sample_action(struct xlate_ctx *ctx,
>         return 0;
>     }
> 
> +    /* If the slow path meter is configured by the controller,
> +     * Insert a meter action before the user space action.   */
> +    struct ofproto *ofproto = &ctx->xin->ofproto->up;
> +    uint32_t meter_id = ofproto->slowpath_meter_id;
> +
>     /* No need to generate sample action for 100% sampling rate. */
> -    bool is_sample = probability < UINT32_MAX;
> +    bool is_sample = probability < UINT32_MAX || meter_id != UINT32_MAX;

This seems to fix the problem in the previous patch.

>     size_t sample_offset, actions_offset;
>     if (is_sample) {
>         sample_offset = nl_msg_start_nested(ctx->odp_actions,
> @@ -2861,11 +2866,6 @@ compose_sample_action(struct xlate_ctx *ctx,
>                                              OVS_SAMPLE_ATTR_ACTIONS);
>     }
> 
> -    /* If the slow path meter is configured by the controller,
> -     * Insert a meter action before the user space action.   */
> -    struct ofproto *ofproto = &ctx->xin->ofproto->up;
> -    uint32_t meter_id = ofproto->slowpath_meter_id;
> -
>     if (meter_id != UINT32_MAX) {
>         nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_METER, meter_id);
>     }
> diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
> index 3c3037b16548..8b097adec940 100644
> --- a/tests/ofproto-dpif.at
> +++ b/tests/ofproto-dpif.at
> @@ -1658,6 +1658,37 @@ NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len
> vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x1234
> ])
> 
> +AT_CHECK([ovs-appctl revalidator/purge])
> +AT_CHECK([ovs-ofctl monitor br0 65534 invalid_ttl -P nxt_packet_in --detach --no-chdir --pidfile 2> ofctl_monitor.log])
> +
> +dnl Add a controller meter.
> +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=controller pktps stats bands=type=drop rate=1'])
> +
> +dnl Advance time by 1 second.
> +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore])
> +
> +for i in `seq 1 8`; do
> +    AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x4321)'])
> +done
> +
> +AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/.*\(packets:\)/\1/' | sed 's/used:[[0-9]].[[0-9]]*s/used:0.001s/'], [0], [dnl
> +flow-dump from non-dpdk interfaces:
> +packets:7, bytes:98, used:0.001s, actions:sample(sample=100.0%,actions(meter(0),userspace(pid=0,slow_path(controller))))
> +])
> +

How about dumping the meters too, for completeness?

> +AT_CHECK([ovs-appctl time/warp 1], [0], [ignore])
> +OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
> +
> +dnl Out of 8 packets we sent, one executes the controller action via
> +dnl miss upcall. Another one got passed the rate limiter.
> +dnl The rest of packets are blocked by the rate limiter.
> +AT_CHECK([cat ofctl_monitor.log], [0], [dnl
> +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
> +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
> +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
> +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
> +])
> +
> OVS_VSWITCHD_STOP
> AT_CLEANUP
> 
> -- 
> 1.8.3.1
> 
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
andy zhou April 28, 2017, 8:56 a.m.
On Thu, Apr 27, 2017 at 3:49 PM, Jarno Rajahalme <jarno@ovn.org> wrote:
> See comments below.
>
>   Jarno
>
>> On Apr 14, 2017, at 12:46 PM, Andy Zhou <azhou@ovn.org> wrote:
>>
>> If a slow path action is a controller action, meter it when the
>> controller meter is configured.  For other kinds of slow path actions,
>> meter it when the slowpath meter is configured.
>>
>> Note, this patch only considers the meters configuration of the
>> packet's input bridge, which may not be the same bridge that the
>> action is generated.
>>
>> Signed-off-by: Andy Zhou <azhou@ovn.org>
>> ---
>> ofproto/ofproto-dpif-upcall.c | 34 +++++++++++++++++++++++++++++++---
>> ofproto/ofproto-dpif-xlate.c  | 12 ++++++------
>> tests/ofproto-dpif.at         | 31 +++++++++++++++++++++++++++++++
>> 3 files changed, 68 insertions(+), 9 deletions(-)
>>
>> diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
>> index 3b28f9a22939..37f345b235b1 100644
>> --- a/ofproto/ofproto-dpif-upcall.c
>> +++ b/ofproto/ofproto-dpif-upcall.c
>> @@ -1018,7 +1018,8 @@ classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata)
>> static void
>> compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
>>                   const struct flow *flow, odp_port_t odp_in_port,
>> -                  struct ofpbuf *buf)
>> +                  struct ofpbuf *buf, uint32_t slowpath_meter_id,
>> +                  uint32_t controller_meter_id)
>> {
>>     union user_action_cookie cookie;
>>     odp_port_t port;
>> @@ -1032,8 +1033,28 @@ compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
>>         ? ODPP_NONE
>>         : odp_in_port;
>>     pid = dpif_port_get_pid(udpif->dpif, port, flow_hash_5tuple(flow, 0));
>> +
>> +    size_t offset;
>> +    size_t ac_offset;
>> +    uint32_t meter_id = xout->slow & SLOW_CONTROLLER ? controller_meter_id
>> +                                                     : slowpath_meter_id;
>> +
>> +    if (meter_id != UINT32_MAX) {
>> +        /* If slowpath meter is configured, generate clone(meter, userspace)
>> +         * action.   */
>> +        offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SAMPLE);
>> +        nl_msg_put_u32(buf, OVS_SAMPLE_ATTR_PROBABILITY, UINT32_MAX);
>> +        ac_offset = nl_msg_start_nested(buf, OVS_SAMPLE_ATTR_ACTIONS);
>> +        nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id);
>> +    }
>> +
>>     odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path,
>>                              ODPP_NONE, false, buf);
>> +
>> +    if (meter_id != UINT32_MAX) {
>> +        nl_msg_end_nested(buf, ac_offset);
>> +        nl_msg_end_nested(buf, offset);
>> +    }
>> }
>>
>> /* If there is no error, the upcall must be destroyed with upcall_uninit()
>> @@ -1136,10 +1157,12 @@ upcall_xlate(struct udpif *udpif, struct upcall *upcall,
>>         ofpbuf_use_const(&upcall->put_actions,
>>                          odp_actions->data, odp_actions->size);
>>     } else {
>> +        uint32_t smid= upcall->ofproto->up.slowpath_meter_id;
>
> white space error.
Thanks, will fix.
>
>> +        uint32_t cmid = upcall->ofproto->up.controller_meter_id;
>>         /* upcall->put_actions already initialized by upcall_receive(). */
>>         compose_slow_path(udpif, &upcall->xout, upcall->flow,
>>                           upcall->flow->in_port.odp_port,
>> -                          &upcall->put_actions);
>> +                          &upcall->put_actions, smid, cmid);
>>     }
>>
>>     /* This function is also called for slow-pathed flows.  As we are only
>> @@ -1956,9 +1979,14 @@ revalidate_ukey__(struct udpif *udpif, const struct udpif_key *ukey,
>>     }
>>
>>     if (xoutp->slow) {
>> +        struct ofproto_dpif *ofproto;
>> +        ofproto = xlate_lookup_ofproto(udpif->backer, &ctx.flow, NULL);
>> +        uint32_t smid= ofproto->up.slowpath_meter_id;
>> +        uint32_t cmid= ofproto->up.controller_meter_id;
>> +
>>         ofpbuf_clear(odp_actions);
>>         compose_slow_path(udpif, xoutp, &ctx.flow, ctx.flow.in_port.odp_port,
>> -                          odp_actions);
>> +                          odp_actions, smid, cmid);
>>     }
>>
>>     if (odp_flow_key_to_mask(ukey->mask, ukey->mask_len, &dp_mask, &ctx.flow)
>> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
>> index 52e0d3f1b0bb..416012ab6930 100644
>> --- a/ofproto/ofproto-dpif-xlate.c
>> +++ b/ofproto/ofproto-dpif-xlate.c
>> @@ -2849,8 +2849,13 @@ compose_sample_action(struct xlate_ctx *ctx,
>>         return 0;
>>     }
>>
>> +    /* If the slow path meter is configured by the controller,
>> +     * Insert a meter action before the user space action.   */
>> +    struct ofproto *ofproto = &ctx->xin->ofproto->up;
>> +    uint32_t meter_id = ofproto->slowpath_meter_id;
>> +
>>     /* No need to generate sample action for 100% sampling rate. */
>> -    bool is_sample = probability < UINT32_MAX;
>> +    bool is_sample = probability < UINT32_MAX || meter_id != UINT32_MAX;
>
> This seems to fix the problem in the previous patch.
Right. The comment above 'is_sample' is also wrong. Will fix that too.
>
>>     size_t sample_offset, actions_offset;
>>     if (is_sample) {
>>         sample_offset = nl_msg_start_nested(ctx->odp_actions,
>> @@ -2861,11 +2866,6 @@ compose_sample_action(struct xlate_ctx *ctx,
>>                                              OVS_SAMPLE_ATTR_ACTIONS);
>>     }
>>
>> -    /* If the slow path meter is configured by the controller,
>> -     * Insert a meter action before the user space action.   */
>> -    struct ofproto *ofproto = &ctx->xin->ofproto->up;
>> -    uint32_t meter_id = ofproto->slowpath_meter_id;
>> -
>>     if (meter_id != UINT32_MAX) {
>>         nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_METER, meter_id);
>>     }
>> diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
>> index 3c3037b16548..8b097adec940 100644
>> --- a/tests/ofproto-dpif.at
>> +++ b/tests/ofproto-dpif.at
>> @@ -1658,6 +1658,37 @@ NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len
>> vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x1234
>> ])
>>
>> +AT_CHECK([ovs-appctl revalidator/purge])
>> +AT_CHECK([ovs-ofctl monitor br0 65534 invalid_ttl -P nxt_packet_in --detach --no-chdir --pidfile 2> ofctl_monitor.log])
>> +
>> +dnl Add a controller meter.
>> +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=controller pktps stats bands=type=drop rate=1'])
>> +
>> +dnl Advance time by 1 second.
>> +AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore])
>> +
>> +for i in `seq 1 8`; do
>> +    AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x4321)'])
>> +done
>> +
>> +AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/.*\(packets:\)/\1/' | sed 's/used:[[0-9]].[[0-9]]*s/used:0.001s/'], [0], [dnl
>> +flow-dump from non-dpdk interfaces:
>> +packets:7, bytes:98, used:0.001s, actions:sample(sample=100.0%,actions(meter(0),userspace(pid=0,slow_path(controller))))
>> +])
>> +
>
> How about dumping the meters too, for completeness?
Good idea. Will add
>
>> +AT_CHECK([ovs-appctl time/warp 1], [0], [ignore])
>> +OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
>> +
>> +dnl Out of 8 packets we sent, one executes the controller action via
>> +dnl miss upcall. Another one got passed the rate limiter.
>> +dnl The rest of packets are blocked by the rate limiter.
>> +AT_CHECK([cat ofctl_monitor.log], [0], [dnl
>> +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
>> +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
>> +NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
>> +vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
>> +])
>> +
>> OVS_VSWITCHD_STOP
>> AT_CLEANUP
>>
>> --
>> 1.8.3.1
>>
>> _______________________________________________
>> dev mailing list
>> dev@openvswitch.org
>> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>

Patch hide | download patch | download mbox

diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c
index 3b28f9a22939..37f345b235b1 100644
--- a/ofproto/ofproto-dpif-upcall.c
+++ b/ofproto/ofproto-dpif-upcall.c
@@ -1018,7 +1018,8 @@  classify_upcall(enum dpif_upcall_type type, const struct nlattr *userdata)
 static void
 compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
                   const struct flow *flow, odp_port_t odp_in_port,
-                  struct ofpbuf *buf)
+                  struct ofpbuf *buf, uint32_t slowpath_meter_id,
+                  uint32_t controller_meter_id)
 {
     union user_action_cookie cookie;
     odp_port_t port;
@@ -1032,8 +1033,28 @@  compose_slow_path(struct udpif *udpif, struct xlate_out *xout,
         ? ODPP_NONE
         : odp_in_port;
     pid = dpif_port_get_pid(udpif->dpif, port, flow_hash_5tuple(flow, 0));
+
+    size_t offset;
+    size_t ac_offset;
+    uint32_t meter_id = xout->slow & SLOW_CONTROLLER ? controller_meter_id
+                                                     : slowpath_meter_id;
+
+    if (meter_id != UINT32_MAX) {
+        /* If slowpath meter is configured, generate clone(meter, userspace)
+         * action.   */
+        offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SAMPLE);
+        nl_msg_put_u32(buf, OVS_SAMPLE_ATTR_PROBABILITY, UINT32_MAX);
+        ac_offset = nl_msg_start_nested(buf, OVS_SAMPLE_ATTR_ACTIONS);
+        nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id);
+    }
+
     odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path,
                              ODPP_NONE, false, buf);
+
+    if (meter_id != UINT32_MAX) {
+        nl_msg_end_nested(buf, ac_offset);
+        nl_msg_end_nested(buf, offset);
+    }
 }
 
 /* If there is no error, the upcall must be destroyed with upcall_uninit()
@@ -1136,10 +1157,12 @@  upcall_xlate(struct udpif *udpif, struct upcall *upcall,
         ofpbuf_use_const(&upcall->put_actions,
                          odp_actions->data, odp_actions->size);
     } else {
+        uint32_t smid= upcall->ofproto->up.slowpath_meter_id;
+        uint32_t cmid = upcall->ofproto->up.controller_meter_id;
         /* upcall->put_actions already initialized by upcall_receive(). */
         compose_slow_path(udpif, &upcall->xout, upcall->flow,
                           upcall->flow->in_port.odp_port,
-                          &upcall->put_actions);
+                          &upcall->put_actions, smid, cmid);
     }
 
     /* This function is also called for slow-pathed flows.  As we are only
@@ -1956,9 +1979,14 @@  revalidate_ukey__(struct udpif *udpif, const struct udpif_key *ukey,
     }
 
     if (xoutp->slow) {
+        struct ofproto_dpif *ofproto;
+        ofproto = xlate_lookup_ofproto(udpif->backer, &ctx.flow, NULL);
+        uint32_t smid= ofproto->up.slowpath_meter_id;
+        uint32_t cmid= ofproto->up.controller_meter_id;
+
         ofpbuf_clear(odp_actions);
         compose_slow_path(udpif, xoutp, &ctx.flow, ctx.flow.in_port.odp_port,
-                          odp_actions);
+                          odp_actions, smid, cmid);
     }
 
     if (odp_flow_key_to_mask(ukey->mask, ukey->mask_len, &dp_mask, &ctx.flow)
diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index 52e0d3f1b0bb..416012ab6930 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -2849,8 +2849,13 @@  compose_sample_action(struct xlate_ctx *ctx,
         return 0;
     }
 
+    /* If the slow path meter is configured by the controller,
+     * Insert a meter action before the user space action.   */
+    struct ofproto *ofproto = &ctx->xin->ofproto->up;
+    uint32_t meter_id = ofproto->slowpath_meter_id;
+
     /* No need to generate sample action for 100% sampling rate. */
-    bool is_sample = probability < UINT32_MAX;
+    bool is_sample = probability < UINT32_MAX || meter_id != UINT32_MAX;
     size_t sample_offset, actions_offset;
     if (is_sample) {
         sample_offset = nl_msg_start_nested(ctx->odp_actions,
@@ -2861,11 +2866,6 @@  compose_sample_action(struct xlate_ctx *ctx,
                                              OVS_SAMPLE_ATTR_ACTIONS);
     }
 
-    /* If the slow path meter is configured by the controller,
-     * Insert a meter action before the user space action.   */
-    struct ofproto *ofproto = &ctx->xin->ofproto->up;
-    uint32_t meter_id = ofproto->slowpath_meter_id;
-
     if (meter_id != UINT32_MAX) {
         nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_METER, meter_id);
     }
diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at
index 3c3037b16548..8b097adec940 100644
--- a/tests/ofproto-dpif.at
+++ b/tests/ofproto-dpif.at
@@ -1658,6 +1658,37 @@  NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len
 vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x1234
 ])
 
+AT_CHECK([ovs-appctl revalidator/purge])
+AT_CHECK([ovs-ofctl monitor br0 65534 invalid_ttl -P nxt_packet_in --detach --no-chdir --pidfile 2> ofctl_monitor.log])
+
+dnl Add a controller meter.
+AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=controller pktps stats bands=type=drop rate=1'])
+
+dnl Advance time by 1 second.
+AT_CHECK([ovs-appctl time/warp 1000], [0], [ignore])
+
+for i in `seq 1 8`; do
+    AT_CHECK([ovs-appctl netdev-dummy/receive p1 'in_port(1),eth(src=50:54:00:00:00:09,dst=50:54:00:00:00:0a),eth_type(0x4321)'])
+done
+
+AT_CHECK([ovs-appctl dpctl/dump-flows | sed 's/.*\(packets:\)/\1/' | sed 's/used:[[0-9]].[[0-9]]*s/used:0.001s/'], [0], [dnl
+flow-dump from non-dpdk interfaces:
+packets:7, bytes:98, used:0.001s, actions:sample(sample=100.0%,actions(meter(0),userspace(pid=0,slow_path(controller))))
+])
+
+AT_CHECK([ovs-appctl time/warp 1], [0], [ignore])
+OVS_WAIT_UNTIL([ovs-appctl -t ovs-ofctl exit])
+
+dnl Out of 8 packets we sent, one executes the controller action via
+dnl miss upcall. Another one got passed the rate limiter.
+dnl The rest of packets are blocked by the rate limiter.
+AT_CHECK([cat ofctl_monitor.log], [0], [dnl
+NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
+NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via action) data_len=14 (unbuffered)
+vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x4321
+])
+
 OVS_VSWITCHD_STOP
 AT_CLEANUP