X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-bundle.c;h=aa8b6f0f47398ce98445a4d8ed7b147ebbf7a9a3;hb=7934111cdba68dd98c199b1ee23a55935d1572b7;hp=c6c9aec2ae5ec76fd87ca4fd8643bbbf1f927dd4;hpb=897b9afc123aec3b9e8950797b53909754e748bc;p=sliver-openvswitch.git diff --git a/tests/test-bundle.c b/tests/test-bundle.c index c6c9aec2a..aa8b6f0f4 100644 --- a/tests/test-bundle.c +++ b/tests/test-bundle.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 Nicira Networks. +/* Copyright (c) 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include #include "flow.h" +#include "ofp-actions.h" #include "ofpbuf.h" #include "random.h" @@ -64,22 +65,24 @@ slave_enabled_cb(uint16_t slave_id, void *aux) return slave ? slave->enabled : false; } -static struct nx_action_bundle * +static struct ofpact_bundle * parse_bundle_actions(char *actions) { - struct nx_action_bundle *nab; - struct ofpbuf b; + struct ofpact_bundle *bundle; + struct ofpbuf ofpacts; + struct ofpact *action; - ofpbuf_init(&b, 0); - bundle_parse(&b, actions); - nab = ofpbuf_steal_data(&b); - ofpbuf_uninit(&b); + ofpbuf_init(&ofpacts, 0); + bundle_parse_load(actions, &ofpacts); + action = ofpacts.data; + bundle = ofpact_get_BUNDLE(xmemdup(action, action->len)); + ofpbuf_uninit(&ofpacts); - if (ntohs(nab->n_slaves) > MAX_SLAVES) { + if (bundle->n_slaves > MAX_SLAVES) { ovs_fatal(0, "At most %u slaves are supported", MAX_SLAVES); } - return nab; + return bundle; } static const char * @@ -101,10 +104,11 @@ int main(int argc, char *argv[]) { bool ok = true; - struct nx_action_bundle *nab; + struct ofpact_bundle *bundle; struct flow *flows; size_t i, n_permute, old_n_enabled; struct slave_group sg; + int old_active; set_program_name(argv[0]); random_init(); @@ -113,12 +117,12 @@ main(int argc, char *argv[]) ovs_fatal(0, "usage: %s bundle_action", program_name); } - nab = parse_bundle_actions(argv[1]); + bundle = parse_bundle_actions(argv[1]); /* Generate 'slaves' array. */ sg.n_slaves = 0; - for (i = 0; i < ntohs(nab->n_slaves); i++) { - uint16_t slave_id = bundle_get_slave(nab, i); + for (i = 0; i < bundle->n_slaves; i++) { + uint16_t slave_id = bundle->slaves[i]; if (slave_lookup(&sg, slave_id)) { ovs_fatal(0, "Redundant slaves are not supported. "); @@ -132,24 +136,23 @@ main(int argc, char *argv[]) flows = xmalloc(N_FLOWS * sizeof *flows); for (i = 0; i < N_FLOWS; i++) { random_bytes(&flows[i], sizeof flows[i]); + memset(flows[i].zeros, 0, sizeof flows[i].zeros); flows[i].regs[0] = OFPP_NONE; } - if (bundle_check(nab, 1024)) { - ovs_fatal(0, "Bundle action fails to check."); - } - /* Cycles through each possible liveness permutation for the given * n_slaves. The initial state is equivalent to all slaves down, so we * skip it by starting at i = 1. We do one extra iteration to cover * transitioning from the final state back to the initial state. */ old_n_enabled = 0; + old_active = -1; n_permute = 1 << sg.n_slaves; for (i = 1; i <= n_permute + 1; i++) { struct slave *slave; size_t j, n_enabled, changed; double disruption, perfect; uint8_t mask; + int active; mask = i % n_permute; @@ -171,32 +174,45 @@ main(int argc, char *argv[]) } } + active = -1; + for (j = 0; j < sg.n_slaves; j++) { + if (sg.slaves[j].enabled) { + active = j; + break; + } + } + changed = 0; for (j = 0; j < N_FLOWS; j++) { struct flow *flow = &flows[j]; - uint16_t old_slave_id; + uint16_t old_slave_id, ofp_port; old_slave_id = flow->regs[0]; - flow->regs[0] = bundle_execute(nab, flow, slave_enabled_cb, &sg); + ofp_port = bundle_execute(bundle, flow, slave_enabled_cb, &sg); + flow->regs[0] = ofp_port; - if (flow->regs[0] != OFPP_NONE) { - slave_lookup(&sg, flow->regs[0])->flow_count++; + if (ofp_port != OFPP_NONE) { + slave_lookup(&sg, ofp_port)->flow_count++; } - if (old_slave_id != flow->regs[0]) { + if (old_slave_id != ofp_port) { changed++; } } - if (old_n_enabled || n_enabled) { - perfect = 1.0 / MAX(old_n_enabled, n_enabled); + if (bundle->algorithm == NX_BD_ALG_ACTIVE_BACKUP) { + perfect = active == old_active ? 0.0 : 1.0; } else { - /* This will happen when 'sg.n_slaves' is 0. */ - perfect = 0; + if (old_n_enabled || n_enabled) { + perfect = 1.0 / MAX(old_n_enabled, n_enabled); + } else { + /* This will happen when 'sg.n_slaves' is 0. */ + perfect = 0; + } } disruption = changed / (double)N_FLOWS; - printf("%s: disruption=%.2f (perfect=%.2f) ", + printf("%s: disruption=%.2f (perfect=%.2f)", mask_str(mask, sg.n_slaves), disruption, perfect); for (j = 0 ; j < sg.n_slaves; j++) { @@ -204,10 +220,16 @@ main(int argc, char *argv[]) double flow_percent; flow_percent = slave->flow_count / (double)N_FLOWS; - printf("%.2f ", flow_percent); + printf( " %.2f", flow_percent); if (slave->enabled) { - double perfect_fp = 1.0 / n_enabled; + double perfect_fp; + + if (bundle->algorithm == NX_BD_ALG_ACTIVE_BACKUP) { + perfect_fp = j == active ? 1.0 : 0.0; + } else { + perfect_fp = 1.0 / n_enabled; + } if (fabs(flow_percent - perfect_fp) >= .01) { fprintf(stderr, "%s: slave %d: flow_percentage=%.5f for" @@ -232,10 +254,11 @@ main(int argc, char *argv[]) ok = false; } + old_active = active; old_n_enabled = n_enabled; } - free(nab); + free(bundle); free(flows); return ok ? 0 : 1; }