From 7cb279c20248abe8e1c3f0c3639c107acac40380 Mon Sep 17 00:00:00 2001 From: Simon Horman Date: Wed, 30 Oct 2013 18:17:20 +0900 Subject: [PATCH] ofproto-dpif: Support weight for select groups Signed-off-by: Simon Horman [blp@nicira.com adjusted this for highest random weight scoring and updated the test] Signed-off-by: Ben Pfaff --- ofproto/ofproto-dpif-xlate.c | 2 +- ofproto/ofproto.c | 3 ++- tests/ofproto-dpif.at | 24 ++++++++++++++++++++++-- tests/ofproto.at | 2 +- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 5c22db365..367dd88e9 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -811,7 +811,7 @@ group_best_live_bucket(const struct xlate_ctx *ctx, group_dpif_get_buckets(group, &buckets); LIST_FOR_EACH (bucket, list_node, buckets) { if (bucket_is_alive(ctx, bucket, 0)) { - uint32_t score = hash_int(i, basis); + uint32_t score = (hash_int(i, basis) & 0xffff) * bucket->weight; if (score >= best_score) { best_bucket = bucket; best_score = score; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 34b06425b..b88cd816d 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -531,7 +531,8 @@ ofproto_create(const char *datapath_name, const char *datapath_type, ovs_rwlock_init(&ofproto->groups_rwlock); hmap_init(&ofproto->groups); ovs_mutex_unlock(&ofproto_mutex); - ofproto->ogf.capabilities = OFPGFC_CHAINING | OFPGFC_SELECT_LIVENESS; + ofproto->ogf.capabilities = OFPGFC_CHAINING | OFPGFC_SELECT_LIVENESS | + OFPGFC_SELECT_WEIGHT; ofproto->ogf.max_groups[OFPGT11_ALL] = OFPG_MAX; ofproto->ogf.max_groups[OFPGT11_SELECT] = OFPG_MAX; ofproto->ogf.max_groups[OFPGT11_INDIRECT] = OFPG_MAX; diff --git a/tests/ofproto-dpif.at b/tests/ofproto-dpif.at index 643e072b5..2a2d32580 100644 --- a/tests/ofproto-dpif.at +++ b/tests/ofproto-dpif.at @@ -118,9 +118,17 @@ OVS_VSWITCHD_START ADD_OF_PORTS([br0], [1], [10], [11]) AT_CHECK([ovs-ofctl -O OpenFlow12 add-group br0 'group_id=1234,type=select,bucket=output:10,bucket=output:11']) AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 'ip actions=write_actions(group:1234)']) -AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:07,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=1,nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0'], [0], [stdout]) -AT_CHECK([tail -1 stdout], [0], + +# Try a bunch of different flows and make sure that they get distributed +# at least somewhat. +for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f; do + AT_CHECK([ovs-appctl ofproto/trace br0 "in_port=1,dl_src=50:54:00:00:00:07,dl_dst=50:54:00:00:00:0$d,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=1,nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0"], [0], [stdout]) + tail -1 stdout >> results +done +sort results | uniq -c +AT_CHECK([sort results | uniq], [0], [Datapath actions: 10 +Datapath actions: 11 ]) OVS_VSWITCHD_STOP AT_CLEANUP @@ -137,6 +145,18 @@ AT_CHECK([tail -1 stdout], [0], OVS_VSWITCHD_STOP AT_CLEANUP +AT_SETUP([ofproto-dpif - select group with weight]) +OVS_VSWITCHD_START +ADD_OF_PORTS([br0], [1], [10], [11], [12]) +AT_CHECK([ovs-ofctl -O OpenFlow12 add-group br0 'group_id=1234,type=select,bucket=output:10,bucket=output:11,weight=2,bucket=output:12,weight=0']) +AT_CHECK([ovs-ofctl -O OpenFlow12 add-flow br0 'ip actions=write_actions(group:1234)']) +AT_CHECK([ovs-appctl ofproto/trace br0 'in_port=1,dl_src=50:54:00:00:00:07,dl_dst=50:54:00:00:00:07,dl_type=0x0800,nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_proto=1,nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0'], [0], [stdout]) +AT_CHECK([tail -1 stdout], [0], + [Datapath actions: 11 +]) +OVS_VSWITCHD_STOP +AT_CLEANUP + AT_SETUP([ofproto-dpif - fast failover group]) OVS_VSWITCHD_START ADD_OF_PORTS([br0], [1], [10], [11]) diff --git a/tests/ofproto.at b/tests/ofproto.at index 9ba593422..27b6b34c4 100644 --- a/tests/ofproto.at +++ b/tests/ofproto.at @@ -306,7 +306,7 @@ AT_CHECK([STRIP_XIDS stdout], [0], [dnl OFPST_GROUP_FEATURES reply (OF1.2): Group table: Types: 0x0 - Capabilities: 0x6 + Capabilities: 0x7 ]) OVS_VSWITCHD_STOP AT_CLEANUP -- 2.43.0