diff options
author | Ben Pfaff <blp@nicira.com> | 2015-04-15 16:46:38 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2015-04-16 08:36:19 -0700 |
commit | f386a8a7583f3ecc967dab124298fe4bc576324e (patch) | |
tree | c413a21878aefe68f87eaa29c7f13410e67f115c /tests | |
parent | c8cec9f3a921e44298cb1ce9ad4d55a04afb8f3e (diff) | |
download | openvswitch-f386a8a7583f3ecc967dab124298fe4bc576324e.tar.gz |
expr: Support string fields in expr_to_matches().
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ovn.at | 33 | ||||
-rw-r--r-- | tests/test-ovn.c | 67 |
2 files changed, 67 insertions, 33 deletions
diff --git a/tests/ovn.at b/tests/ovn.at index fa89cbe5d..24479eca5 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -346,3 +346,36 @@ AT_CHECK([ovstest test-ovn exhaustive --operation=flow --vars=3 --bits=3 --relop [Tested converting to flows 38394 expressions of 3 terminals with 3 vars each of 3 bits in terms of operators ==. ]) AT_CLEANUP + +AT_SETUP([ovn -- converting expressions to flows -- string fields]) +expr_to_flow () { + echo "$1" | ovstest test-ovn expr-to-flows | sort +} +AT_CHECK([expr_to_flow 'inport == "eth0"'], [0], [in_port=5 +]) +AT_CHECK([expr_to_flow 'inport == "eth1"'], [0], [in_port=6 +]) +AT_CHECK([expr_to_flow 'inport == "eth2"'], [0], [(no flows) +]) +AT_CHECK([expr_to_flow 'inport == "eth0" && ip'], [0], [dnl +ip,in_port=5 +ipv6,in_port=5 +]) +AT_CHECK([expr_to_flow 'inport == "eth1" && ip'], [0], [dnl +ip,in_port=6 +ipv6,in_port=6 +]) +AT_CHECK([expr_to_flow 'inport == "eth2" && ip'], [0], [(no flows) +]) +AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2", "LOCAL"}'], [0], +[in_port=5 +in_port=6 +in_port=LOCAL +]) +AT_CHECK([expr_to_flow 'inport == {"eth0", "eth1", "eth2"} && ip'], [0], [dnl +ip,in_port=5 +ip,in_port=6 +ipv6,in_port=5 +ipv6,in_port=6 +]) +AT_CLEANUP diff --git a/tests/test-ovn.c b/tests/test-ovn.c index a6d8b8000..67093d5b2 100644 --- a/tests/test-ovn.c +++ b/tests/test-ovn.c @@ -27,6 +27,7 @@ #include "ovs-thread.h" #include "ovstest.h" #include "shash.h" +#include "simap.h" #include "util.h" #include "openvswitch/vlog.h" @@ -131,8 +132,8 @@ create_symtab(struct shash *symtab) { shash_init(symtab); - expr_symtab_add_string(symtab, "inport", NULL); - expr_symtab_add_string(symtab, "outport", NULL); + expr_symtab_add_string(symtab, "inport", MFF_IN_PORT, NULL); + expr_symtab_add_string(symtab, "outport", MFF_ACTSET_OUTPUT, NULL); expr_symtab_add_field(symtab, "xreg0", MFF_XREG0, NULL, false); expr_symtab_add_field(symtab, "xreg1", MFF_XREG1, NULL, false); @@ -234,9 +235,16 @@ static void test_parse_expr__(int steps) { struct shash symtab; + struct simap ports; struct ds input; create_symtab(&symtab); + + simap_init(&ports); + simap_put(&ports, "eth0", 5); + simap_put(&ports, "eth1", 6); + simap_put(&ports, "LOCAL", ofp_to_u16(OFPP_LOCAL)); + ds_init(&input); while (!ds_get_test_line(&input, stdin)) { struct expr *expr; @@ -256,10 +264,18 @@ test_parse_expr__(int steps) } } if (!error) { - struct ds output = DS_EMPTY_INITIALIZER; - expr_format(expr, &output); - puts(ds_cstr(&output)); - ds_destroy(&output); + if (steps > 3) { + struct hmap matches; + + expr_to_matches(expr, &ports, &matches); + expr_matches_print(&matches, stdout); + expr_matches_destroy(&matches); + } else { + struct ds output = DS_EMPTY_INITIALIZER; + expr_format(expr, &output); + puts(ds_cstr(&output)); + ds_destroy(&output); + } } else { puts(error); free(error); @@ -268,6 +284,7 @@ test_parse_expr__(int steps) } ds_destroy(&input); + simap_destroy(&ports); expr_symtab_destroy(&symtab); shash_destroy(&symtab); } @@ -295,6 +312,12 @@ test_normalize_expr(struct ovs_cmdl_context *ctx OVS_UNUSED) { test_parse_expr__(3); } + +static void +test_expr_to_flows(struct ovs_cmdl_context *ctx OVS_UNUSED) +{ + test_parse_expr__(4); +} /* Evaluate an expression. */ @@ -859,7 +882,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab, struct test_rule *test_rule; uint32_t n_conjs; - n_conjs = expr_to_matches(modified, &matches); + n_conjs = expr_to_matches(modified, NULL, &matches); classifier_init(&cls, NULL); HMAP_FOR_EACH (m, hmap_node, &matches) { @@ -931,25 +954,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab, fputs(".\n", stderr); fprintf(stderr, "Converted to classifier:\n"); - - struct expr_match *m; - HMAP_FOR_EACH (m, hmap_node, &matches) { - char *s = match_to_string(&m->match, - OFP_DEFAULT_PRIORITY); - fputs(s, stderr); - if (m->n) { - for (int i = 0; i < m->n; i++) { - const struct cls_conjunction *c - = &m->conjunctions[i]; - fprintf(stderr, - "%c conjunction(%"PRIu32", %d/%d)", - i == 0 ? ':' : ',', - c->id, c->clause, c->n_clauses); - } - } - putc('\n', stderr); - } - + expr_matches_print(&matches, stderr); fprintf(stderr, "However, %s flow was found in the classifier.\n", found ? "a" : "no"); @@ -958,7 +963,6 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab, } } if (operation >= OP_FLOW) { - struct expr_match *m, *n; struct test_rule *test_rule; CLS_FOR_EACH (test_rule, cr, &cls) { @@ -968,12 +972,7 @@ test_tree_shape_exhaustively(struct expr *expr, struct shash *symtab, classifier_destroy(&cls); ovsrcu_quiesce(); - HMAP_FOR_EACH_SAFE (m, n, hmap_node, &matches) { - hmap_remove(&matches, &m->hmap_node); - free(m->conjunctions); - free(m); - } - hmap_destroy(&matches); + expr_matches_destroy(&matches); } expr_destroy(modified); } @@ -1160,6 +1159,7 @@ parse-expr\n\ annotate-expr\n\ simplify-expr\n\ normalize-expr\n\ +expr-to-flows\n\ Parses OVN expressions from stdin and print them back on stdout after\n\ differing degrees of analysis. Available fields are based on packet\n\ headers.\n\ @@ -1281,6 +1281,7 @@ test_ovn_main(int argc, char *argv[]) {"annotate-expr", NULL, 0, 0, test_annotate_expr}, {"simplify-expr", NULL, 0, 0, test_simplify_expr}, {"normalize-expr", NULL, 0, 0, test_normalize_expr}, + {"expr-to-flows", NULL, 0, 0, test_expr_to_flows}, {"evaluate-expr", NULL, 1, 1, test_evaluate_expr}, {"composition", NULL, 1, 1, test_composition}, {"tree-shape", NULL, 1, 1, test_tree_shape}, |