[ovs-dev] [classifier-opt 13/28] flow: Use bit-mask for TTL match, instead of FWW_* flag.
Ben Pfaff
blp at nicira.com
Fri Jul 20 23:25:10 UTC 2012
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
lib/classifier.c | 10 +++++-----
lib/flow.c | 41 ++++++++++++++++++++++++-----------------
lib/flow.h | 13 +++++++------
lib/meta-flow.c | 11 +++++++----
lib/nx-match.c | 4 ++--
lib/ofp-util.c | 12 +++++-------
6 files changed, 50 insertions(+), 41 deletions(-)
diff --git a/lib/classifier.c b/lib/classifier.c
index 446ca4e..a8fd0fd 100644
--- a/lib/classifier.c
+++ b/lib/classifier.c
@@ -378,7 +378,7 @@ cls_rule_set_nw_ecn(struct cls_rule *rule, uint8_t nw_ecn)
void
cls_rule_set_nw_ttl(struct cls_rule *rule, uint8_t nw_ttl)
{
- rule->wc.wildcards &= ~FWW_NW_TTL;
+ rule->wc.nw_ttl_mask = UINT8_MAX;
rule->flow.nw_ttl = nw_ttl;
}
@@ -582,7 +582,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s)
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
if (rule->priority != OFP_DEFAULT_PRIORITY) {
ds_put_format(s, "priority=%d,", rule->priority);
@@ -729,7 +729,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s)
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)) {
+ if (wc->nw_ttl_mask) {
ds_put_format(s, "nw_ttl=%"PRIu8",", f->nw_ttl);
}
switch (wc->nw_frag_mask) {
@@ -1266,7 +1266,7 @@ flow_equal_except(const struct flow *a, const struct flow *b,
const flow_wildcards_t wc = wildcards->wildcards;
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
for (i = 0; i < FLOW_N_REGS; i++) {
if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) {
@@ -1288,7 +1288,7 @@ flow_equal_except(const struct flow *a, const struct flow *b,
&& eth_addr_equal_except(a->dl_dst, b->dl_dst,
wildcards->dl_dst_mask)
&& (wc & FWW_NW_PROTO || a->nw_proto == b->nw_proto)
- && (wc & FWW_NW_TTL || a->nw_ttl == b->nw_ttl)
+ && !((a->nw_ttl ^ b->nw_ttl) & wildcards->nw_ttl_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,
diff --git a/lib/flow.c b/lib/flow.c
index c0d5a47..ab1711e 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -444,7 +444,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
const flow_wildcards_t wc = wildcards->wildcards;
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
for (i = 0; i < FLOW_N_REGS; i++) {
flow->regs[i] &= wildcards->reg_masks[i];
@@ -469,9 +469,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
}
flow->ipv6_label &= wildcards->ipv6_label_mask;
flow->nw_tos &= wildcards->nw_tos_mask;
- if (wc & FWW_NW_TTL) {
- flow->nw_ttl = 0;
- }
+ flow->nw_ttl &= wildcards->nw_ttl_mask;
flow->nw_frag &= wildcards->nw_frag_mask;
eth_addr_bitand(flow->arp_sha, wildcards->arp_sha_mask, flow->arp_sha);
eth_addr_bitand(flow->arp_tha, wildcards->arp_tha_mask, flow->arp_tha);
@@ -488,7 +486,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards)
void
flow_get_metadata(const struct flow *flow, struct flow_metadata *fmd)
{
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
fmd->tun_id = flow->tun_id;
fmd->tun_id_mask = htonll(UINT64_MAX);
@@ -582,7 +580,7 @@ flow_print(FILE *stream, const struct flow *flow)
void
flow_wildcards_init_catchall(struct flow_wildcards *wc)
{
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
wc->wildcards = FWW_ALL;
wc->tun_id_mask = htonll(0);
@@ -603,6 +601,8 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc)
memset(wc->arp_sha_mask, 0, ETH_ADDR_LEN);
memset(wc->arp_tha_mask, 0, ETH_ADDR_LEN);
wc->nw_tos_mask = 0;
+ wc->nw_ttl_mask = 0;
+ memset(wc->zeros, 0, sizeof wc->zeros);
}
/* Initializes 'wc' as an exact-match set of wildcards; that is, 'wc' does not
@@ -610,7 +610,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc)
void
flow_wildcards_init_exact(struct flow_wildcards *wc)
{
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
wc->wildcards = 0;
wc->tun_id_mask = htonll(UINT64_MAX);
@@ -631,6 +631,8 @@ flow_wildcards_init_exact(struct flow_wildcards *wc)
memset(wc->arp_sha_mask, 0xff, ETH_ADDR_LEN);
memset(wc->arp_tha_mask, 0xff, ETH_ADDR_LEN);
wc->nw_tos_mask = UINT8_MAX;
+ wc->nw_ttl_mask = UINT8_MAX;
+ memset(wc->zeros, 0, sizeof wc->zeros);
}
/* Returns true if 'wc' is exact-match, false if 'wc' wildcards any bits or
@@ -640,7 +642,7 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc)
{
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
if (wc->wildcards
|| wc->tun_id_mask != htonll(UINT64_MAX)
@@ -659,7 +661,8 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc)
|| wc->ipv6_label_mask != htonl(UINT32_MAX)
|| !ipv6_mask_is_exact(&wc->nd_target_mask)
|| wc->nw_frag_mask != UINT8_MAX
- || wc->nw_tos_mask != UINT8_MAX) {
+ || wc->nw_tos_mask != UINT8_MAX
+ || wc->nw_ttl_mask != UINT8_MAX) {
return false;
}
@@ -679,7 +682,7 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc)
{
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
if (wc->wildcards != FWW_ALL
|| wc->tun_id_mask != htonll(0)
@@ -698,7 +701,8 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc)
|| wc->ipv6_label_mask != htonl(0)
|| !ipv6_mask_is_any(&wc->nd_target_mask)
|| wc->nw_frag_mask != 0
- || wc->nw_tos_mask != 0) {
+ || wc->nw_tos_mask != 0
+ || wc->nw_ttl_mask != 0) {
return false;
}
@@ -721,7 +725,7 @@ flow_wildcards_combine(struct flow_wildcards *dst,
{
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
dst->wildcards = src1->wildcards | src2->wildcards;
dst->tun_id_mask = src1->tun_id_mask & src2->tun_id_mask;
@@ -747,6 +751,7 @@ flow_wildcards_combine(struct flow_wildcards *dst,
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;
+ dst->nw_ttl_mask = src1->nw_ttl_mask & src2->nw_ttl_mask;
}
/* Returns a hash of the wildcards in 'wc'. */
@@ -756,7 +761,7 @@ flow_wildcards_hash(const struct flow_wildcards *wc, uint32_t basis)
/* If you change struct flow_wildcards and thereby trigger this
* assertion, please check that the new struct flow_wildcards has no holes
* in it before you update the assertion. */
- BUILD_ASSERT_DECL(sizeof *wc == 112 + FLOW_N_REGS * 4);
+ BUILD_ASSERT_DECL(sizeof *wc == 120 + FLOW_N_REGS * 4);
return hash_bytes(wc, sizeof *wc, basis);
}
@@ -768,7 +773,7 @@ flow_wildcards_equal(const struct flow_wildcards *a,
{
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
if (a->wildcards != b->wildcards
|| a->tun_id_mask != b->tun_id_mask
@@ -787,7 +792,8 @@ flow_wildcards_equal(const struct flow_wildcards *a,
|| !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)
- || a->nw_tos_mask != b->nw_tos_mask) {
+ || a->nw_tos_mask != b->nw_tos_mask
+ || a->nw_ttl_mask != b->nw_ttl_mask) {
return false;
}
@@ -810,7 +816,7 @@ flow_wildcards_has_extra(const struct flow_wildcards *a,
uint8_t eth_masked[ETH_ADDR_LEN];
struct in6_addr ipv6_masked;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
for (i = 0; i < FLOW_N_REGS; i++) {
if ((a->reg_masks[i] & b->reg_masks[i]) != b->reg_masks[i]) {
@@ -863,7 +869,8 @@ flow_wildcards_has_extra(const struct flow_wildcards *a,
|| (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_tos_mask & b->nw_tos_mask) != b->nw_tos_mask);
+ || (a->nw_tos_mask & b->nw_tos_mask) != b->nw_tos_mask
+ || (a->nw_ttl_mask & b->nw_ttl_mask) != b->nw_ttl_mask);
}
/* Sets the wildcard mask for register 'idx' in 'wc' to 'mask'.
diff --git a/lib/flow.h b/lib/flow.h
index cc4c98d..bf65e27 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -34,7 +34,7 @@ struct ofpbuf;
/* This sequence number should be incremented whenever anything involving flows
* or the wildcarding of flows changes. This will cause build assertion
* failures in places which likely need to be updated. */
-#define FLOW_WC_SEQ 14
+#define FLOW_WC_SEQ 15
#define FLOW_N_REGS 8
BUILD_ASSERT_DECL(FLOW_N_REGS <= NXM_NX_MAX_REGS);
@@ -103,7 +103,7 @@ BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->nw_frag) == 1);
BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE);
/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
-BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 14);
+BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 150 && FLOW_WC_SEQ == 15);
void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id,
uint16_t in_port, struct flow *);
@@ -151,11 +151,10 @@ 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_TTL ((OVS_FORCE flow_wildcards_t) (1 << 3))
-#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 4)) - 1))
+#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 3)) - 1))
/* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */
-BUILD_ASSERT_DECL(FWW_ALL == ((1 << 4) - 1) && FLOW_WC_SEQ == 14);
+BUILD_ASSERT_DECL(FWW_ALL == ((1 << 3) - 1) && FLOW_WC_SEQ == 15);
/* Information on wildcards for a flow, as a supplement to "struct flow".
*
@@ -182,10 +181,12 @@ struct flow_wildcards {
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 nw_tos_mask; /* 1-bit in each significant nw_tos bit. */
+ uint8_t nw_ttl_mask; /* 1-bit in each significant nw_ttl bit. */
+ uint8_t zeros[7]; /* Padding field set to zero. */
};
/* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */
-BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 144 && FLOW_WC_SEQ == 14);
+BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 152 && FLOW_WC_SEQ == 15);
void flow_wildcards_init_catchall(struct flow_wildcards *);
void flow_wildcards_init_exact(struct flow_wildcards *);
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index 49d4bed..1497401 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_TTL, "nw_ttl", NULL,
MF_FIELD_SIZES(u8),
- MFM_NONE, FWW_NW_TTL,
+ MFM_NONE, 0,
MFS_DECIMAL,
MFP_IP_ANY,
true,
@@ -558,7 +558,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_TTL:
case MFF_ARP_OP:
assert(mf->fww_bit != 0);
return (wc->wildcards & mf->fww_bit) != 0;
@@ -608,6 +607,8 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc)
return !(wc->nw_tos_mask & IP_DSCP_MASK);
case MFF_IP_ECN:
return !(wc->nw_tos_mask & IP_ECN_MASK);
+ case MFF_IP_TTL:
+ return !wc->nw_ttl_mask;
case MFF_ND_TARGET:
return ipv6_mask_is_any(&wc->nd_target_mask);
@@ -651,7 +652,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_TTL:
case MFF_ARP_OP:
assert(mf->fww_bit != 0);
memset(mask, wc->wildcards & mf->fww_bit ? 0x00 : 0xff, mf->n_bytes);
@@ -714,6 +714,9 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc,
mask->ipv6 = wc->nd_target_mask;
break;
+ case MFF_IP_TTL:
+ mask->u8 = wc->nw_ttl_mask;
+ break;
case MFF_IP_FRAG:
mask->u8 = wc->nw_frag_mask & FLOW_NW_FRAG_MASK;
break;
@@ -1431,7 +1434,7 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule)
break;
case MFF_IP_TTL:
- rule->wc.wildcards |= FWW_NW_TTL;
+ rule->wc.nw_ttl_mask = 0;
rule->flow.nw_ttl = 0;
break;
diff --git a/lib/nx-match.c b/lib/nx-match.c
index d9ebe1e..2dfb351 100644
--- a/lib/nx-match.c
+++ b/lib/nx-match.c
@@ -443,7 +443,7 @@ nxm_put_ip(struct ofpbuf *b, const struct cls_rule *cr,
flow->nw_tos & IP_ECN_MASK);
}
- if (!oxm && !(wc & FWW_NW_TTL)) {
+ if (!oxm && cr->wc.nw_ttl_mask) {
nxm_put_8(b, NXM_NX_IP_TTL, flow->nw_ttl);
}
@@ -493,7 +493,7 @@ nx_put_match(struct ofpbuf *b, bool oxm, const struct cls_rule *cr,
int match_len;
int i;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
/* Metadata. */
if (!(wc & FWW_IN_PORT)) {
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index d7ec9da..d82ab2a 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -83,14 +83,12 @@ ofputil_netmask_to_wcbits(ovs_be32 netmask)
void
ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *wc)
{
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
/* Initialize most of rule->wc. */
flow_wildcards_init_catchall(wc);
- /* Start with wildcard fields that aren't defined by ofp10_match. */
- wc->wildcards = FWW_NW_TTL;
-
+ wc->wildcards = 0;
if (ofpfw & OFPFW10_IN_PORT) {
wc->wildcards |= FWW_IN_PORT;
}
@@ -1457,7 +1455,7 @@ ofputil_usable_protocols(const struct cls_rule *rule)
{
const struct flow_wildcards *wc = &rule->wc;
- BUILD_ASSERT_DECL(FLOW_WC_SEQ == 14);
+ BUILD_ASSERT_DECL(FLOW_WC_SEQ == 15);
/* NXM and OF1.1+ supports bitwise matching on ethernet addresses. */
if (!eth_mask_is_exact(wc->dl_src_mask)
@@ -1512,7 +1510,7 @@ ofputil_usable_protocols(const struct cls_rule *rule)
}
/* Only NXM supports matching IP TTL/hop limit. */
- if (!(wc->wildcards & FWW_NW_TTL)) {
+ if (wc->nw_ttl_mask) {
return OFPUTIL_P_NXM_ANY;
}
@@ -4100,7 +4098,7 @@ ofputil_normalize_rule(struct cls_rule *rule)
}
if (!(may_match & MAY_IPVx)) {
wc.nw_tos_mask = 0;
- wc.wildcards |= FWW_NW_TTL;
+ wc.nw_ttl_mask = 0;
}
if (!(may_match & MAY_ARP_SHA)) {
memset(wc.arp_sha_mask, 0, ETH_ADDR_LEN);
--
1.7.2.5
More information about the dev
mailing list