2 * Copyright (c) 2010, 2012 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "multipath.h"
28 #include "ofp-actions.h"
33 main(int argc, char *argv[])
35 enum { MP_MAX_LINKS = 63 };
36 struct ofpact_multipath mp;
40 set_program_name(argv[0]);
44 ovs_fatal(0, "usage: %s multipath_action", program_name);
47 multipath_parse(&mp, argv[1]);
48 for (n = 1; n <= MP_MAX_LINKS; n++) {
49 enum { N_FLOWS = 65536 };
50 double disruption, perfect, distribution;
51 int histogram[MP_MAX_LINKS];
52 double sum_dev2, stddev;
57 memset(histogram, 0, sizeof histogram);
58 for (i = 0; i < N_FLOWS; i++) {
59 int old_link, new_link;
62 random_bytes(&flow, sizeof flow);
63 memset(flow.zeros, 0, sizeof flow.zeros);
67 multipath_execute(&mp, &flow);
68 old_link = flow.regs[0];
71 multipath_execute(&mp, &flow);
72 new_link = flow.regs[0];
74 assert(old_link >= 0 && old_link < n);
75 assert(new_link >= 0 && new_link < n + 1);
77 histogram[old_link]++;
78 changed += old_link != new_link;
82 for (i = 0; i < n; i++) {
83 double mean = (double) N_FLOWS / n;
84 double deviation = histogram[i] - mean;
86 sum_dev2 += deviation * deviation;
88 stddev = sqrt(sum_dev2 / n);
90 disruption = (double) changed / N_FLOWS;
91 perfect = 1.0 / (n + 1);
92 distribution = stddev / ((double) N_FLOWS / n);
93 printf("%2d -> %2d: disruption=%.2f (perfect=%.2f); "
94 "stddev/expected=%.4f\n",
95 n, n + 1, disruption, perfect, distribution);
97 switch (mp.algorithm) {
98 case NX_MP_ALG_MODULO_N:
99 if (disruption < (n < 2 ? .25 : .5)) {
100 fprintf(stderr, "%d -> %d: disruption=%.2f < .5\n",
101 n, n + 1, disruption);
106 case NX_MP_ALG_HASH_THRESHOLD:
107 if (disruption < .48 || disruption > .52) {
108 fprintf(stderr, "%d -> %d: disruption=%.2f not approximately "
109 ".5\n", n, n + 1, disruption);
114 case NX_MP_ALG_ITER_HASH:
115 if (!(n & (n - 1))) {
120 if (fabs(disruption - perfect) >= .01) {
121 fprintf(stderr, "%d -> %d: disruption=%.5f differs from "
122 "perfect=%.5f by more than .01\n",
123 n, n + 1, disruption, perfect);