Skip to content

Commit

Permalink
ofproto: Meter sample action when configured.
Browse files Browse the repository at this point in the history
When slowpath meter is configured, add meter action when translate
sample action.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
azhou-nicira committed Apr 28, 2017
1 parent 9e638f2 commit 31b29c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ofproto/ofproto-dpif-xlate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2850,8 +2850,14 @@ compose_sample_action(struct xlate_ctx *ctx,
return 0;
}

/* No need to generate sample action for 100% sampling rate. */
bool is_sample = probability < UINT32_MAX;
/* 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;

/* When meter action is not required, avoid generate sample action
* for 100% sampling rate. */
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,
Expand All @@ -2862,6 +2868,10 @@ compose_sample_action(struct xlate_ctx *ctx,
OVS_SAMPLE_ATTR_ACTIONS);
}

if (meter_id != UINT32_MAX) {
nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_METER, meter_id);
}

odp_port_t odp_port = ofp_port_to_odp_port(
ctx->xbridge, ctx->xin->flow.in_port.ofp_port);
uint32_t pid = dpif_port_get_pid(ctx->xbridge->dpif, odp_port,
Expand Down
14 changes: 14 additions & 0 deletions tests/ofproto-dpif.at
Original file line number Diff line number Diff line change
Expand Up @@ -6490,6 +6490,20 @@ flow-dump from non-dpdk interfaces:
packets:2, bytes:68, used:0.001s, actions:userspace(pid=0,ipfix(output_port=4294967295))
])

AT_CHECK([ovs-appctl revalidator/purge])
dnl
dnl Add a slowpath meter. The userspace action should be metered.
AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=slowpath pktps burst stats bands=type=drop rate=3 burst_size=1'])

dnl Send some packets that should be sampled and metered.
for i in `seq 1 3`; 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(0x0800)'])
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:2, bytes:68, used:0.001s, actions:sample(sample=100.0%,actions(meter(0),userspace(pid=0,ipfix(output_port=4294967295))))
])

dnl Remove the IPFIX configuration.
AT_CHECK([ovs-vsctl clear bridge br0 ipfix])
AT_CHECK([ovs-appctl revalidator/purge])
Expand Down

0 comments on commit 31b29c2

Please sign in to comment.