git://git.onelab.eu
/
sliver-openvswitch.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ofproto: Inline trivial functions.
[sliver-openvswitch.git]
/
tests
/
test-bundle.c
diff --git
a/tests/test-bundle.c
b/tests/test-bundle.c
index
fb15faf
..
9a65839
100644
(file)
--- a/
tests/test-bundle.c
+++ b/
tests/test-bundle.c
@@
-1,4
+1,4
@@
-/* Copyright (c) 2011
Nicira Networks
.
+/* Copyright (c) 2011
, 2012, 2013, 2014 Nicira, Inc
.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-21,16
+21,17
@@
#include <stdlib.h>
#include "flow.h"
#include <stdlib.h>
#include "flow.h"
+#include "ofp-actions.h"
#include "ofpbuf.h"
#include "ofpbuf.h"
-#include "random.h"
#include "util.h"
#include "util.h"
+#include "ovstest.h"
#define N_FLOWS 50000
#define MAX_SLAVES 8 /* Maximum supported by this test framework. */
struct slave {
#define N_FLOWS 50000
#define MAX_SLAVES 8 /* Maximum supported by this test framework. */
struct slave {
-
uint16
_t slave_id;
+
ofp_port
_t slave_id;
bool enabled;
size_t flow_count;
bool enabled;
size_t flow_count;
@@
-42,7
+43,7
@@
struct slave_group {
};
static struct slave *
};
static struct slave *
-slave_lookup(struct slave_group *sg,
uint16
_t slave_id)
+slave_lookup(struct slave_group *sg,
ofp_port
_t slave_id)
{
size_t i;
{
size_t i;
@@
-56,7
+57,7
@@
slave_lookup(struct slave_group *sg, uint16_t slave_id)
}
static bool
}
static bool
-slave_enabled_cb(
uint16
_t slave_id, void *aux)
+slave_enabled_cb(
ofp_port
_t slave_id, void *aux)
{
struct slave *slave;
{
struct slave *slave;
@@
-64,22
+65,29
@@
slave_enabled_cb(uint16_t slave_id, void *aux)
return slave ? slave->enabled : false;
}
return slave ? slave->enabled : false;
}
-static struct
nx_action
_bundle *
+static struct
ofpact
_bundle *
parse_bundle_actions(char *actions)
{
parse_bundle_actions(char *actions)
{
- struct nx_action_bundle *nab;
- struct ofpbuf b;
+ struct ofpact_bundle *bundle;
+ struct ofpbuf ofpacts;
+ struct ofpact *action;
+ char *error;
+
+ ofpbuf_init(&ofpacts, 0);
+ error = bundle_parse_load(actions, &ofpacts);
+ if (error) {
+ ovs_fatal(0, "%s", error);
+ }
- ofpbuf_init(&b, 0);
- bundle_parse(&b, actions);
- nab = ofpbuf_steal_data(&b);
- ofpbuf_uninit(&b);
+ action = ofpbuf_data(&ofpacts);
+ 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);
}
ovs_fatal(0, "At most %u slaves are supported", MAX_SLAVES);
}
- return
nab
;
+ return
bundle
;
}
static const char *
}
static const char *
@@
-97,29
+105,28
@@
mask_str(uint8_t mask, size_t n_bits)
return str;
}
return str;
}
-int
-main(int argc, char *argv[])
+static void
+
test_bundle_
main(int argc, char *argv[])
{
bool ok = true;
{
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]);
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();
if (argc != 2) {
ovs_fatal(0, "usage: %s bundle_action", program_name);
}
if (argc != 2) {
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;
/* 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++) {
+
ofp_port_t slave_id = bundle->slaves[i]
;
if (slave_lookup(&sg, slave_id)) {
ovs_fatal(0, "Redundant slaves are not supported. ");
if (slave_lookup(&sg, slave_id)) {
ovs_fatal(0, "Redundant slaves are not supported. ");
@@
-132,12
+139,8
@@
main(int argc, char *argv[])
/* Generate flows. */
flows = xmalloc(N_FLOWS * sizeof *flows);
for (i = 0; i < N_FLOWS; i++) {
/* Generate flows. */
flows = xmalloc(N_FLOWS * sizeof *flows);
for (i = 0; i < N_FLOWS; i++) {
- random_bytes(&flows[i], sizeof flows[i]);
- flows[i].regs[0] = OFPP_NONE;
- }
-
- if (bundle_check(nab, 1024)) {
- ovs_fatal(0, "Bundle action fails to check.");
+ flow_random_hash_fields(&flows[i]);
+ flows[i].regs[0] = ofp_to_u16(OFPP_NONE);
}
/* Cycles through each possible liveness permutation for the given
}
/* Cycles through each possible liveness permutation for the given
@@
-185,21
+188,24
@@
main(int argc, char *argv[])
changed = 0;
for (j = 0; j < N_FLOWS; j++) {
struct flow *flow = &flows[j];
changed = 0;
for (j = 0; j < N_FLOWS; j++) {
struct flow *flow = &flows[j];
- uint16_t old_slave_id;
+ ofp_port_t old_slave_id, ofp_port;
+ struct flow_wildcards wc;
- old_slave_id = flow->regs[0];
- flow->regs[0] = bundle_execute(nab, flow, slave_enabled_cb, &sg);
+ old_slave_id = u16_to_ofp(flow->regs[0]);
+ ofp_port = bundle_execute(bundle, flow, &wc, slave_enabled_cb,
+ &sg);
+ flow->regs[0] = ofp_to_u16(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++;
}
}
changed++;
}
}
- if (
nab->algorithm == htons(NX_BD_ALG_ACTIVE_BACKUP)
) {
+ if (
bundle->algorithm == NX_BD_ALG_ACTIVE_BACKUP
) {
perfect = active == old_active ? 0.0 : 1.0;
} else {
if (old_n_enabled || n_enabled) {
perfect = active == old_active ? 0.0 : 1.0;
} else {
if (old_n_enabled || n_enabled) {
@@
-224,7
+230,7
@@
main(int argc, char *argv[])
if (slave->enabled) {
double perfect_fp;
if (slave->enabled) {
double perfect_fp;
- if (
nab->algorithm == htons(NX_BD_ALG_ACTIVE_BACKUP)
) {
+ if (
bundle->algorithm == NX_BD_ALG_ACTIVE_BACKUP
) {
perfect_fp = j == active ? 1.0 : 0.0;
} else {
perfect_fp = 1.0 / n_enabled;
perfect_fp = j == active ? 1.0 : 0.0;
} else {
perfect_fp = 1.0 / n_enabled;
@@
-257,7
+263,9
@@
main(int argc, char *argv[])
old_n_enabled = n_enabled;
}
old_n_enabled = n_enabled;
}
- free(
nab
);
+ free(
bundle
);
free(flows);
free(flows);
-
return ok ? 0 : 1
;
+
exit(ok ? 0 : 1)
;
}
}
+
+OVSTEST_REGISTER("test-bundle", test_bundle_main);