diff options
author | Ben Pfaff <blp@nicira.com> | 2011-10-11 11:07:14 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-10-11 11:07:14 -0700 |
commit | 26c6b6cd2b2ead7ea8be58481bd6a4d10dc96897 (patch) | |
tree | b3b08c55b9780a5dc83a9f447e83266c6b834f3c /lib | |
parent | 109ee2810ddf3c26d4c32e64208ca2033965d6db (diff) |
dpif-netdev: Implement OVS_ACTION_ATTR_SAMPLE action.
OVS_ACTION_ATTR_SAMPLE has never been implemented in dpif-netdev. This
commit implements it and adds a cast to enum ovs_action_type in the switch
statement that checks the action type, so that GCC complains if we forget
to add a case for a new action type.
I had to assign the return value of nl_attr_type() to a temporary variable,
because "switch ((enum ovs_action_type) nl_attr_type(a))" provoked a GCC
warning that I've never seen before:
../lib/dpif-netdev.c:1260: warning: cast from function call of type 'int'
to non-matching type 'enum ovs_action_type'
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpif-netdev.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 43f6c43c..c1c339e9 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -47,6 +47,7 @@ #include "ofpbuf.h" #include "packets.h" #include "poll-loop.h" +#include "random.h" #include "shash.h" #include "timeval.h" #include "util.h" @@ -1209,6 +1210,40 @@ dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet, return 0; } +static void +dp_netdev_sample(struct dp_netdev *dp, + struct ofpbuf *packet, struct flow *key, + const struct nlattr *action) +{ + const struct nlattr *subactions = NULL; + const struct nlattr *a; + size_t left; + + NL_NESTED_FOR_EACH_UNSAFE (a, left, action) { + int type = nl_attr_type(a); + + switch ((enum ovs_sample_attr) type) { + case OVS_SAMPLE_ATTR_PROBABILITY: + if (random_uint32() >= nl_attr_get_u32(a)) { + return; + } + break; + + case OVS_SAMPLE_ATTR_ACTIONS: + subactions = a; + break; + + case OVS_SAMPLE_ATTR_UNSPEC: + case __OVS_SAMPLE_ATTR_MAX: + default: + NOT_REACHED(); + } + } + + dp_netdev_execute_actions(dp, packet, key, nl_attr_get(subactions), + nl_attr_get_size(subactions)); +} + static int dp_netdev_execute_actions(struct dp_netdev *dp, struct ofpbuf *packet, struct flow *key, @@ -1219,7 +1254,9 @@ dp_netdev_execute_actions(struct dp_netdev *dp, unsigned int left; NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) { - switch (nl_attr_type(a)) { + int type = nl_attr_type(a); + + switch ((enum ovs_action_type) type) { case OVS_ACTION_ATTR_OUTPUT: dp_netdev_output_port(dp, packet, nl_attr_get_u32(a)); break; @@ -1258,6 +1295,20 @@ dp_netdev_execute_actions(struct dp_netdev *dp, case OVS_ACTION_ATTR_SET_TP_DST: dp_netdev_set_tp_port(packet, key, a); break; + + case OVS_ACTION_ATTR_SAMPLE: + dp_netdev_sample(dp, packet, key, a); + break; + + case OVS_ACTION_ATTR_SET_TUNNEL: + case OVS_ACTION_ATTR_SET_PRIORITY: + case OVS_ACTION_ATTR_POP_PRIORITY: + /* not implemented */ + break; + + case OVS_ACTION_ATTR_UNSPEC: + case __OVS_ACTION_ATTR_MAX: + NOT_REACHED(); } } return 0; |