From 5d9499c4dc43bb40f49bf7a819821750a43039d2 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 18 Jun 2012 14:11:13 -0700 Subject: [PATCH] flow: Use bit-mask for DSCP and ECN bits, instead of FWW_* flags. Signed-off-by: Ben Pfaff --- lib/classifier.c | 11 +++++------ lib/flow.c | 24 ++++++++++++------------ lib/flow.h | 10 ++++------ lib/meta-flow.c | 24 ++++++++++++++++-------- lib/nx-match.c | 4 ++-- lib/ofp-util.c | 16 ++++++++-------- tests/test-classifier.c | 7 +++++-- 7 files changed, 52 insertions(+), 44 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index 38f1a4fe..79ba657e 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -387,7 +387,7 @@ cls_rule_set_nw_dst_masked(struct cls_rule *rule, ovs_be32 ip, ovs_be32 mask) void cls_rule_set_nw_dscp(struct cls_rule *rule, uint8_t nw_dscp) { - rule->wc.wildcards &= ~FWW_NW_DSCP; + rule->wc.nw_tos_mask |= IP_DSCP_MASK; rule->flow.nw_tos &= ~IP_DSCP_MASK; rule->flow.nw_tos |= nw_dscp & IP_DSCP_MASK; } @@ -395,7 +395,7 @@ cls_rule_set_nw_dscp(struct cls_rule *rule, uint8_t nw_dscp) void cls_rule_set_nw_ecn(struct cls_rule *rule, uint8_t nw_ecn) { - rule->wc.wildcards &= ~FWW_NW_ECN; + rule->wc.nw_tos_mask |= IP_ECN_MASK; rule->flow.nw_tos &= ~IP_ECN_MASK; rule->flow.nw_tos |= nw_ecn & IP_ECN_MASK; } @@ -748,10 +748,10 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) format_eth_masked(s, "arp_sha", f->arp_sha, wc->arp_sha_mask); format_eth_masked(s, "arp_tha", f->arp_tha, wc->arp_tha_mask); } - if (!(w & FWW_NW_DSCP)) { + if (wc->nw_tos_mask & IP_DSCP_MASK) { ds_put_format(s, "nw_tos=%"PRIu8",", f->nw_tos & IP_DSCP_MASK); } - if (!(w & FWW_NW_ECN)) { + if (wc->nw_tos_mask & IP_ECN_MASK) { ds_put_format(s, "nw_ecn=%"PRIu8",", f->nw_tos & IP_ECN_MASK); } if (!(w & FWW_NW_TTL)) { @@ -1314,8 +1314,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, wildcards->dl_dst_mask) && (wc & FWW_NW_PROTO || a->nw_proto == b->nw_proto) && (wc & FWW_NW_TTL || a->nw_ttl == b->nw_ttl) - && (wc & FWW_NW_DSCP || !((a->nw_tos ^ b->nw_tos) & IP_DSCP_MASK)) - && (wc & FWW_NW_ECN || !((a->nw_tos ^ b->nw_tos) & IP_ECN_MASK)) + && !((a->nw_tos ^ b->nw_tos) & wildcards->nw_tos_mask) && !((a->nw_frag ^ b->nw_frag) & wildcards->nw_frag_mask) && eth_addr_equal_except(a->arp_sha, b->arp_sha, wildcards->arp_sha_mask) diff --git a/lib/flow.c b/lib/flow.c index f4446c93..0b0bc445 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -469,12 +469,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) flow->nw_proto = 0; } flow->ipv6_label &= wildcards->ipv6_label_mask; - if (wc & FWW_NW_DSCP) { - flow->nw_tos &= ~IP_DSCP_MASK; - } - if (wc & FWW_NW_ECN) { - flow->nw_tos &= ~IP_ECN_MASK; - } + flow->nw_tos &= wildcards->nw_tos_mask; if (wc & FWW_NW_TTL) { flow->nw_ttl = 0; } @@ -602,7 +597,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) memset(wc->dl_dst_mask, 0, ETH_ADDR_LEN); memset(wc->arp_sha_mask, 0, ETH_ADDR_LEN); memset(wc->arp_tha_mask, 0, ETH_ADDR_LEN); - memset(wc->zeros, 0, sizeof wc->zeros); + wc->nw_tos_mask = 0; } /* Initializes 'wc' as an exact-match set of wildcards; that is, 'wc' does not @@ -630,7 +625,7 @@ flow_wildcards_init_exact(struct flow_wildcards *wc) memset(wc->dl_dst_mask, 0xff, ETH_ADDR_LEN); memset(wc->arp_sha_mask, 0xff, ETH_ADDR_LEN); memset(wc->arp_tha_mask, 0xff, ETH_ADDR_LEN); - memset(wc->zeros, 0, sizeof wc->zeros); + wc->nw_tos_mask = UINT8_MAX; } /* Returns true if 'wc' is exact-match, false if 'wc' wildcards any bits or @@ -658,7 +653,8 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) || !ipv6_mask_is_exact(&wc->ipv6_dst_mask) || wc->ipv6_label_mask != htonl(UINT32_MAX) || !ipv6_mask_is_exact(&wc->nd_target_mask) - || wc->nw_frag_mask != UINT8_MAX) { + || wc->nw_frag_mask != UINT8_MAX + || wc->nw_tos_mask != UINT8_MAX) { return false; } @@ -696,7 +692,8 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) || !ipv6_mask_is_any(&wc->ipv6_dst_mask) || wc->ipv6_label_mask != htonl(0) || !ipv6_mask_is_any(&wc->nd_target_mask) - || wc->nw_frag_mask != 0) { + || wc->nw_frag_mask != 0 + || wc->nw_tos_mask != 0) { return false; } @@ -744,6 +741,7 @@ flow_wildcards_combine(struct flow_wildcards *dst, eth_addr_bitand(src1->dl_dst_mask, src2->dl_dst_mask, dst->dl_dst_mask); eth_addr_bitand(src1->arp_sha_mask, src2->arp_sha_mask, dst->arp_sha_mask); eth_addr_bitand(src1->arp_tha_mask, src2->arp_tha_mask, dst->arp_tha_mask); + dst->nw_tos_mask = src1->nw_tos_mask & src2->nw_tos_mask; } /* Returns a hash of the wildcards in 'wc'. */ @@ -783,7 +781,8 @@ flow_wildcards_equal(const struct flow_wildcards *a, || !eth_addr_equals(a->dl_src_mask, b->dl_src_mask) || !eth_addr_equals(a->dl_dst_mask, b->dl_dst_mask) || !eth_addr_equals(a->arp_sha_mask, b->arp_sha_mask) - || !eth_addr_equals(a->arp_tha_mask, b->arp_tha_mask)) { + || !eth_addr_equals(a->arp_tha_mask, b->arp_tha_mask) + || a->nw_tos_mask != b->nw_tos_mask) { return false; } @@ -858,7 +857,8 @@ flow_wildcards_has_extra(const struct flow_wildcards *a, || (a->metadata_mask & b->metadata_mask) != b->metadata_mask || (a->tp_src_mask & b->tp_src_mask) != b->tp_src_mask || (a->tp_dst_mask & b->tp_dst_mask) != b->tp_dst_mask - || (a->nw_frag_mask & b->nw_frag_mask) != b->nw_frag_mask); + || (a->nw_frag_mask & b->nw_frag_mask) != b->nw_frag_mask + || (a->nw_tos_mask & b->nw_tos_mask) != b->nw_tos_mask); } /* Sets the wildcard mask for register 'idx' in 'wc' to 'mask'. diff --git a/lib/flow.h b/lib/flow.h index dac65e56..53960004 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -144,13 +144,11 @@ typedef unsigned int OVS_BITWISE flow_wildcards_t; #define FWW_IN_PORT ((OVS_FORCE flow_wildcards_t) (1 << 0)) #define FWW_DL_TYPE ((OVS_FORCE flow_wildcards_t) (1 << 1)) #define FWW_NW_PROTO ((OVS_FORCE flow_wildcards_t) (1 << 2)) -#define FWW_NW_DSCP ((OVS_FORCE flow_wildcards_t) (1 << 3)) -#define FWW_NW_ECN ((OVS_FORCE flow_wildcards_t) (1 << 4)) -#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 5)) -#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 6)) - 1)) +#define FWW_NW_TTL ((OVS_FORCE flow_wildcards_t) (1 << 3)) +#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 4)) - 1)) /* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */ -BUILD_ASSERT_DECL(FWW_ALL == ((1 << 6) - 1) && FLOW_WC_SEQ == 14); +BUILD_ASSERT_DECL(FWW_ALL == ((1 << 4) - 1) && FLOW_WC_SEQ == 14); /* Information on wildcards for a flow, as a supplement to "struct flow". * @@ -176,7 +174,7 @@ struct flow_wildcards { uint8_t dl_dst_mask[6]; /* 1-bit in each significant dl_dst bit. */ uint8_t arp_sha_mask[6]; /* 1-bit in each significant dl_dst bit. */ uint8_t arp_tha_mask[6]; /* 1-bit in each significant dl_dst bit. */ - uint8_t zeros[1]; /* Padding field set to zero. */ + uint8_t nw_tos_mask; /* 1-bit in each significant nw_tos bit. */ }; /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 3713ca4e..70c97ef0 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -260,7 +260,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_IP_DSCP, "nw_tos", NULL, MF_FIELD_SIZES(u8), - MFM_NONE, FWW_NW_DSCP, + MFM_NONE, 0, MFS_DECIMAL, MFP_IP_ANY, true, @@ -269,7 +269,7 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { }, { MFF_IP_ECN, "nw_ecn", NULL, 1, 2, - MFM_NONE, FWW_NW_ECN, + MFM_NONE, 0, MFS_DECIMAL, MFP_IP_ANY, true, @@ -576,8 +576,6 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IN_PORT: case MFF_ETH_TYPE: case MFF_IP_PROTO: - case MFF_IP_DSCP: - case MFF_IP_ECN: case MFF_IP_TTL: case MFF_ARP_OP: assert(mf->fww_bit != 0); @@ -627,6 +625,11 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_IPV6_LABEL: return !wc->ipv6_label_mask; + case MFF_IP_DSCP: + return !(wc->nw_tos_mask & IP_DSCP_MASK); + case MFF_IP_ECN: + return !(wc->nw_tos_mask & IP_ECN_MASK); + case MFF_ND_TARGET: return ipv6_mask_is_any(&wc->nd_target_mask); @@ -669,8 +672,6 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, case MFF_IN_PORT: case MFF_ETH_TYPE: case MFF_IP_PROTO: - case MFF_IP_DSCP: - case MFF_IP_ECN: case MFF_IP_TTL: case MFF_ARP_OP: assert(mf->fww_bit != 0); @@ -727,6 +728,13 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, mask->be32 = wc->ipv6_label_mask; break; + case MFF_IP_DSCP: + mask->u8 = wc->nw_tos_mask & IP_DSCP_MASK; + break; + case MFF_IP_ECN: + mask->u8 = wc->nw_tos_mask & IP_ECN_MASK; + break; + case MFF_ND_TARGET: mask->ipv6 = wc->nd_target_mask; break; @@ -1457,12 +1465,12 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule) break; case MFF_IP_DSCP: - rule->wc.wildcards |= FWW_NW_DSCP; + rule->wc.nw_tos_mask &= ~IP_DSCP_MASK; rule->flow.nw_tos &= ~IP_DSCP_MASK; break; case MFF_IP_ECN: - rule->wc.wildcards |= FWW_NW_ECN; + rule->wc.nw_tos_mask &= ~IP_ECN_MASK; rule->flow.nw_tos &= ~IP_ECN_MASK; break; diff --git a/lib/nx-match.c b/lib/nx-match.c index 16c1674a..c92f8cc8 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -500,12 +500,12 @@ nxm_put_ip(struct ofpbuf *b, const struct cls_rule *cr, nxm_put_frag(b, cr); - if (!(wc & FWW_NW_DSCP)) { + if (cr->wc.nw_tos_mask & IP_DSCP_MASK) { nxm_put_8(b, oxm ? OXM_OF_IP_DSCP : NXM_OF_IP_TOS, flow->nw_tos & IP_DSCP_MASK); } - if (!(wc & FWW_NW_ECN)) { + if (cr->wc.nw_tos_mask & IP_ECN_MASK) { nxm_put_8(b, oxm ? OXM_OF_IP_ECN : NXM_NX_IP_ECN, flow->nw_tos & IP_ECN_MASK); } diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 4cacadfa..6723d4a5 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -90,7 +90,7 @@ ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc) flow_wildcards_init_catchall(wc); /* Start with wildcard fields that aren't defined by ofp10_match. */ - wc->wildcards = FWW_NW_ECN | FWW_NW_TTL; + wc->wildcards = FWW_NW_TTL; if (ofpfw & OFPFW10_IN_PORT) { wc->wildcards |= FWW_IN_PORT; @@ -101,8 +101,9 @@ ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc) if (ofpfw & OFPFW10_NW_PROTO) { wc->wildcards |= FWW_NW_PROTO; } - if (ofpfw & OFPFW10_NW_TOS) { - wc->wildcards |= FWW_NW_DSCP; + + if (!(ofpfw & OFPFW10_NW_TOS)) { + wc->nw_tos_mask |= IP_DSCP_MASK; } wc->nw_src_mask = ofputil_wcbits_to_netmask(ofpfw >> OFPFW10_NW_SRC_SHIFT); @@ -204,7 +205,7 @@ ofputil_cls_rule_to_ofp10_match(const struct cls_rule *rule, << OFPFW10_NW_SRC_SHIFT); ofpfw |= (ofputil_netmask_to_wcbits(wc->nw_dst_mask) << OFPFW10_NW_DST_SHIFT); - if (wc->wildcards & FWW_NW_DSCP) { + if (!(wc->nw_tos_mask & IP_DSCP_MASK)) { ofpfw |= OFPFW10_NW_TOS; } if (!wc->tp_src_mask) { @@ -512,7 +513,7 @@ ofputil_cls_rule_to_ofp11_match(const struct cls_rule *rule, match->dl_type = ofputil_dl_type_to_openflow(rule->flow.dl_type); } - if (rule->wc.wildcards & FWW_NW_DSCP) { + if (!(rule->wc.nw_tos_mask & IP_DSCP_MASK)) { wc |= OFPFW11_NW_TOS; } else { match->nw_tos = rule->flow.nw_tos & IP_DSCP_MASK; @@ -954,7 +955,7 @@ ofputil_usable_protocols(const struct cls_rule *rule) } /* Only NXM supports matching IP ECN bits. */ - if (!(wc->wildcards & FWW_NW_ECN)) { + if (wc->nw_tos_mask & IP_ECN_MASK) { return OFPUTIL_P_NXM_ANY; } @@ -3636,8 +3637,7 @@ ofputil_normalize_rule__(struct cls_rule *rule, bool may_log) wc.wildcards |= FWW_NW_PROTO; } if (!(may_match & MAY_IPVx)) { - wc.wildcards |= FWW_NW_DSCP; - wc.wildcards |= FWW_NW_ECN; + wc.nw_tos_mask = 0; wc.wildcards |= FWW_NW_TTL; } if (!(may_match & MAY_ARP_SHA)) { diff --git a/tests/test-classifier.c b/tests/test-classifier.c index e7cf734a..a978afb0 100644 --- a/tests/test-classifier.c +++ b/tests/test-classifier.c @@ -56,7 +56,7 @@ CLS_FIELD(0, dl_src, DL_SRC) \ CLS_FIELD(0, dl_dst, DL_DST) \ CLS_FIELD(FWW_NW_PROTO, nw_proto, NW_PROTO) \ - CLS_FIELD(FWW_NW_DSCP, nw_tos, NW_DSCP) + CLS_FIELD(0, nw_tos, NW_DSCP) /* Field indexes. * @@ -218,7 +218,8 @@ match(const struct cls_rule *wild, const struct flow *fixed) eq = !((fixed->metadata ^ wild->flow.metadata) & wild->wc.metadata_mask); } else if (f_idx == CLS_F_IDX_NW_DSCP) { - eq = !((fixed->nw_tos ^ wild->flow.nw_tos) & IP_DSCP_MASK); + eq = !((fixed->nw_tos ^ wild->flow.nw_tos) & + (wild->wc.nw_tos_mask & IP_DSCP_MASK)); } else { NOT_REACHED(); } @@ -499,6 +500,8 @@ make_rule(int wc_fields, unsigned int priority, int value_pat) rule->cls_rule.wc.tun_id_mask = htonll(UINT64_MAX); } else if (f_idx == CLS_F_IDX_METADATA) { rule->cls_rule.wc.metadata_mask = htonll(UINT64_MAX); + } else if (f_idx == CLS_F_IDX_NW_DSCP) { + rule->cls_rule.wc.nw_tos_mask |= IP_DSCP_MASK; } else { NOT_REACHED(); } -- 2.30.2