#include "command-line.h"
#include "flow.h"
#include "packets.h"
+#include "unaligned.h"
#undef NDEBUG
#include <assert.h>
CLS_FIELD(OFPFW_TP_SRC, tp_src, TP_SRC) \
CLS_FIELD(OFPFW_TP_DST, tp_dst, TP_DST) \
CLS_FIELD(OFPFW_DL_SRC, dl_src, DL_SRC) \
- CLS_FIELD(OFPFW_DL_DST, dl_dst, DL_DST) \
+ CLS_FIELD(OFPFW_DL_DST | FWW_ETH_MCAST, \
+ dl_dst, DL_DST) \
CLS_FIELD(OFPFW_NW_PROTO, nw_proto, NW_PROTO) \
CLS_FIELD(OFPFW_DL_VLAN_PCP, dl_vlan_pcp, DL_VLAN_PCP) \
CLS_FIELD(OFPFW_NW_TOS, nw_tos, NW_TOS)
}
}
-static int
-tcls_count_exact(const struct tcls *tcls)
-{
- int n_exact;
- size_t i;
-
- n_exact = 0;
- for (i = 0; i < tcls->n_rules; i++) {
- n_exact += tcls->rules[i]->cls_rule.wc.wildcards == 0;
- }
- return n_exact;
-}
-
static bool
tcls_is_empty(const struct tcls *tcls)
{
NOT_REACHED();
}
-static uint32_t
-read_uint32(const void *p)
-{
- uint32_t x;
- memcpy(&x, p, sizeof x);
- return x;
-}
-
static bool
match(const struct cls_rule *wild, const struct flow *fixed)
{
}
if (wild->wc.wildcards & f->wildcards) {
- uint32_t test = read_uint32(wild_field);
- uint32_t ip = read_uint32(fixed_field);
+ uint32_t test = get_unaligned_u32(wild_field);
+ uint32_t ip = get_unaligned_u32(fixed_field);
int shift = (f_idx == CLS_F_IDX_NW_SRC
? OFPFW_NW_SRC_SHIFT : OFPFW_NW_DST_SHIFT);
uint32_t mask = flow_nw_bits_to_mask(wild->wc.wildcards, shift);
}
static struct cls_rule *
-tcls_lookup(const struct tcls *cls, const struct flow *flow, int include)
+tcls_lookup(const struct tcls *cls, const struct flow *flow)
{
size_t i;
for (i = 0; i < cls->n_rules; i++) {
struct test_rule *pos = cls->rules[i];
- uint32_t wildcards = pos->cls_rule.wc.wildcards;
- if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT)
- && match(&pos->cls_rule, flow)) {
+ if (match(&pos->cls_rule, flow)) {
return &pos->cls_rule;
}
}
}
static void
-tcls_delete_matches(struct tcls *cls,
- const struct cls_rule *target,
- int include)
+tcls_delete_matches(struct tcls *cls, const struct cls_rule *target)
{
size_t i;
for (i = 0; i < cls->n_rules; ) {
struct test_rule *pos = cls->rules[i];
- uint32_t wildcards = pos->cls_rule.wc.wildcards;
- if (include & (wildcards ? CLS_INC_WILD : CLS_INC_EXACT)
- && !flow_wildcards_has_extra(&pos->cls_rule.wc, &target->wc)
+ if (!flow_wildcards_has_extra(&pos->cls_rule.wc, &target->wc)
&& match(target, &pos->cls_rule.flow)) {
tcls_remove(cls, pos);
} else {
}
}
\f
-static uint32_t nw_src_values[] = { CONSTANT_HTONL(0xc0a80001),
+static ovs_be32 nw_src_values[] = { CONSTANT_HTONL(0xc0a80001),
CONSTANT_HTONL(0xc0a04455) };
-static uint32_t nw_dst_values[] = { CONSTANT_HTONL(0xc0a80002),
+static ovs_be32 nw_dst_values[] = { CONSTANT_HTONL(0xc0a80002),
CONSTANT_HTONL(0xc0a04455) };
-static uint32_t tun_id_values[] = { 0, 0xffff0000 };
-static uint16_t in_port_values[] = { CONSTANT_HTONS(1),
- CONSTANT_HTONS(OFPP_LOCAL) };
-static uint16_t dl_vlan_values[] = { CONSTANT_HTONS(101), CONSTANT_HTONS(0) };
+static ovs_be32 tun_id_values[] = { 0, 0xffff0000 };
+static uint16_t in_port_values[] = { 1, ODPP_LOCAL };
+static ovs_be16 dl_vlan_values[] = { CONSTANT_HTONS(101), CONSTANT_HTONS(0) };
static uint8_t dl_vlan_pcp_values[] = { 7, 0 };
-static uint16_t dl_type_values[]
+static ovs_be16 dl_type_values[]
= { CONSTANT_HTONS(ETH_TYPE_IP), CONSTANT_HTONS(ETH_TYPE_ARP) };
-static uint16_t tp_src_values[] = { CONSTANT_HTONS(49362),
+static ovs_be16 tp_src_values[] = { CONSTANT_HTONS(49362),
CONSTANT_HTONS(80) };
-static uint16_t tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) };
+static ovs_be16 tp_dst_values[] = { CONSTANT_HTONS(6667), CONSTANT_HTONS(22) };
static uint8_t dl_src_values[][6] = { { 0x00, 0x02, 0xe3, 0x0f, 0x80, 0xa4 },
{ 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } };
static uint8_t dl_dst_values[][6] = { { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 },
unsigned int i;
assert(classifier_count(cls) == tcls->n_rules);
- assert(classifier_count_exact(cls) == tcls_count_exact(tcls));
for (i = 0; i < confidence; i++) {
struct cls_rule *cr0, *cr1;
struct flow flow;
unsigned int x;
- int include;
x = rand () % N_FLOW_VALUES;
flow.nw_src = nw_src_values[get_value(&x, N_NW_SRC_VALUES)];
flow.nw_proto = nw_proto_values[get_value(&x, N_NW_PROTO_VALUES)];
flow.nw_tos = nw_tos_values[get_value(&x, N_NW_TOS_VALUES)];
- for (include = 1; include <= 3; include++) {
- cr0 = classifier_lookup(cls, &flow, include);
- cr1 = tcls_lookup(tcls, &flow, include);
- assert((cr0 == NULL) == (cr1 == NULL));
- if (cr0 != NULL) {
- const struct test_rule *tr0 = test_rule_from_cls_rule(cr0);
- const struct test_rule *tr1 = test_rule_from_cls_rule(cr1);
-
- assert(flow_equal(&cr0->flow, &cr1->flow));
- assert(cr0->wc.wildcards == cr1->wc.wildcards);
- assert(cr0->priority == cr1->priority);
- /* Skip nw_src_mask and nw_dst_mask, because they are derived
- * members whose values are used only for optimization. */
- assert(tr0->aux == tr1->aux);
- }
+ cr0 = classifier_lookup(cls, &flow);
+ cr1 = tcls_lookup(tcls, &flow);
+ assert((cr0 == NULL) == (cr1 == NULL));
+ if (cr0 != NULL) {
+ const struct test_rule *tr0 = test_rule_from_cls_rule(cr0);
+ const struct test_rule *tr1 = test_rule_from_cls_rule(cr1);
+
+ assert(flow_equal(&cr0->flow, &cr1->flow));
+ assert(cr0->wc.wildcards == cr1->wc.wildcards);
+ assert(cr0->priority == cr1->priority);
+ /* Skip nw_src_mask and nw_dst_mask, because they are derived
+ * members whose values are used only for optimization. */
+ assert(tr0->aux == tr1->aux);
}
}
}
static void
destroy_classifier(struct classifier *cls)
{
- classifier_for_each(cls, CLS_INC_ALL, free_rule, cls);
+ classifier_for_each(cls, free_rule, cls);
classifier_destroy(cls);
}
int n_tables, int n_rules, int n_dups)
{
const struct cls_table *table;
- const struct test_rule *test_rule;
struct flow_wildcards exact_wc;
int found_tables = 0;
int found_rules = 0;
int found_dups = 0;
- int n_exact1 = 0;
- int n_exact2 = 0;
flow_wildcards_init_exact(&exact_wc);
HMAP_FOR_EACH (table, hmap_node, &cls->tables) {
- bool is_exact = flow_wildcards_equal(&table->wc, &exact_wc);
const struct cls_rule *head;
assert(!hmap_is_empty(&table->rules));
const struct cls_rule *rule;
found_rules++;
- if (is_exact) {
- n_exact1++;
- }
LIST_FOR_EACH (rule, list, &head->list) {
assert(rule->priority < prev_priority);
prev_priority = rule->priority;
found_rules++;
found_dups++;
- if (is_exact) {
- n_exact1++;
- }
assert(classifier_find_rule_exactly(cls, rule) == rule);
}
}
}
- CLASSIFIER_FOR_EACH_EXACT_RULE (test_rule, cls_rule, cls) {
- n_exact2++;
- }
-
assert(found_tables == hmap_count(&cls->tables));
assert(n_tables == -1 || n_tables == hmap_count(&cls->tables));
assert(n_rules == -1 || found_rules == n_rules);
assert(n_dups == -1 || found_dups == n_dups);
- assert(n_exact1 == n_exact2);
}
static struct test_rule *
while (!classifier_is_empty(&cls)) {
struct test_rule *rule = xmemdup(tcls.rules[rand() % tcls.n_rules],
sizeof(struct test_rule));
- int include = rand() % 2 ? CLS_INC_WILD : CLS_INC_EXACT;
- include |= (rule->cls_rule.wc.wildcards
- ? CLS_INC_WILD : CLS_INC_EXACT);
- classifier_for_each_match(&cls, &rule->cls_rule, include,
- free_rule, &cls);
- tcls_delete_matches(&tcls, &rule->cls_rule, include);
+ classifier_for_each_match(&cls, &rule->cls_rule, free_rule, &cls);
+ tcls_delete_matches(&tcls, &rule->cls_rule);
compare_classifiers(&cls, &tcls);
check_tables(&cls, -1, -1, -1);
free(rule);