2 * Copyright (c) 2010 Nicira Networks.
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"
32 main(int argc, char *argv[])
34 enum { MP_MAX_LINKS = 63 };
35 struct nx_action_multipath mp;
39 set_program_name(argv[0]);
43 ovs_fatal(0, "usage: %s multipath_action", program_name);
46 multipath_parse(&mp, argv[1]);
47 for (n = 1; n <= MP_MAX_LINKS; n++) {
48 enum { N_FLOWS = 65536 };
49 double disruption, perfect, distribution;
50 int histogram[MP_MAX_LINKS];
51 double sum_dev2, stddev;
56 memset(histogram, 0, sizeof histogram);
57 for (i = 0; i < N_FLOWS; i++) {
58 int old_link, new_link;
61 random_bytes(&flow, sizeof flow);
63 mp.max_link = htons(n - 1);
64 multipath_execute(&mp, &flow);
65 old_link = flow.regs[0];
67 mp.max_link = htons(n);
68 multipath_execute(&mp, &flow);
69 new_link = flow.regs[0];
71 assert(old_link >= 0 && old_link < n);
72 assert(new_link >= 0 && new_link < n + 1);
74 histogram[old_link]++;
75 changed += old_link != new_link;
79 for (i = 0; i < n; i++) {
80 double mean = (double) N_FLOWS / n;
81 double deviation = histogram[i] - mean;
83 sum_dev2 += deviation * deviation;
85 stddev = sqrt(sum_dev2 / n);
87 disruption = (double) changed / N_FLOWS;
88 perfect = 1.0 / (n + 1);
89 distribution = stddev / ((double) N_FLOWS / n);
90 printf("%2d -> %2d: disruption=%.2f (perfect=%.2f); "
91 "stddev/expected=%.4f\n",
92 n, n + 1, disruption, perfect, distribution);
94 switch (ntohs(mp.algorithm)) {
95 case NX_MP_ALG_MODULO_N:
96 if (disruption < (n < 2 ? .25 : .5)) {
97 fprintf(stderr, "%d -> %d: disruption=%.2f < .5\n",
98 n, n + 1, disruption);
103 case NX_MP_ALG_HASH_THRESHOLD:
104 if (disruption < .48 || disruption > .52) {
105 fprintf(stderr, "%d -> %d: disruption=%.2f not approximately "
106 ".5\n", n, n + 1, disruption);
111 case NX_MP_ALG_ITER_HASH:
112 if (!(n & (n - 1))) {
117 if (fabs(disruption - perfect) >= .01) {
118 fprintf(stderr, "%d -> %d: disruption=%.5f differs from "
119 "perfect=%.5f by more than .01\n",
120 n, n + 1, disruption, perfect);