2009-07-08 13:19:16 -07:00
|
|
|
|
/*
|
2012-05-02 15:21:36 -07:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*/
|
|
|
|
|
#ifndef FLOW_H
|
|
|
|
|
#define FLOW_H 1
|
|
|
|
|
|
2010-02-12 12:51:36 -08:00
|
|
|
|
#include <sys/types.h>
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string.h>
|
2010-04-12 11:49:16 -04:00
|
|
|
|
#include "openflow/nicira-ext.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "openflow/openflow.h"
|
|
|
|
|
#include "hash.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
2011-01-26 07:11:50 -08:00
|
|
|
|
struct dpif_flow_stats;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct ds;
|
2010-11-08 10:37:35 -08:00
|
|
|
|
struct flow_wildcards;
|
2012-09-04 12:43:53 -07:00
|
|
|
|
struct miniflow;
|
|
|
|
|
struct minimask;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct ofpbuf;
|
|
|
|
|
|
2011-07-29 13:15:09 -07:00
|
|
|
|
/* 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. */
|
2012-06-18 13:33:13 -07:00
|
|
|
|
#define FLOW_WC_SEQ 17
|
2011-07-29 13:15:09 -07:00
|
|
|
|
|
2012-03-08 14:44:54 -08:00
|
|
|
|
#define FLOW_N_REGS 8
|
2010-11-11 10:41:33 -08:00
|
|
|
|
BUILD_ASSERT_DECL(FLOW_N_REGS <= NXM_NX_MAX_REGS);
|
|
|
|
|
|
2011-01-23 18:44:44 -08:00
|
|
|
|
/* Used for struct flow's dl_type member for frames that have no Ethernet
|
|
|
|
|
* type, that is, pure 802.2 frames. */
|
|
|
|
|
#define FLOW_DL_TYPE_NONE 0x5ff
|
|
|
|
|
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
|
/* Fragment bits, used for IPv4 and IPv6, always zero for non-IP flows. */
|
2011-11-09 17:10:27 -08:00
|
|
|
|
#define FLOW_NW_FRAG_ANY (1 << 0) /* Set for any IP frag. */
|
|
|
|
|
#define FLOW_NW_FRAG_LATER (1 << 1) /* Set for IP frag with nonzero offset. */
|
|
|
|
|
#define FLOW_NW_FRAG_MASK (FLOW_NW_FRAG_ANY | FLOW_NW_FRAG_LATER)
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
|
|
2011-11-09 17:10:27 -08:00
|
|
|
|
BUILD_ASSERT_DECL(FLOW_NW_FRAG_ANY == NX_IP_FRAG_ANY);
|
|
|
|
|
BUILD_ASSERT_DECL(FLOW_NW_FRAG_LATER == NX_IP_FRAG_LATER);
|
Implement new fragment handling policy.
Until now, OVS has handled IP fragments more awkwardly than necessary. It
has not been possible to match on L4 headers, even in fragments with offset
0 where they are actually present. This means that there was no way to
implement ACLs that treat, say, different TCP ports differently, on
fragmented traffic; instead, all decisions for fragment forwarding had to
be made on the basis of L2 and L3 headers alone.
This commit improves the situation significantly. It is still not possible
to match on L4 headers in fragments with nonzero offset, because that
information is simply not present in such fragments, but this commit adds
the ability to match on L4 headers for fragments with zero offset. This
means that it becomes possible to implement ACLs that drop such "first
fragments" on the basis of L4 headers. In practice, that effectively
blocks even fragmented traffic on an L4 basis, because the receiving IP
stack cannot reassemble a full packet when the first fragment is missing.
This commit works by adding a new "fragment type" to the kernel flow match
and making it available through OpenFlow as a new NXM field named
NXM_NX_IP_FRAG. Because OpenFlow 1.0 explicitly says that the L4 fields
are always 0 for IP fragments, it adds a new OpenFlow fragment handling
mode that fills in the L4 fields for "first fragments". It also enhances
ovs-ofctl to allow users to configure this new fragment handling mode and
to parse the new field.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Bug #7557.
2011-10-19 21:33:44 -07:00
|
|
|
|
|
2012-09-13 20:11:08 -07:00
|
|
|
|
#define FLOW_TNL_F_DONT_FRAGMENT (1 << 0)
|
|
|
|
|
#define FLOW_TNL_F_CSUM (1 << 1)
|
|
|
|
|
#define FLOW_TNL_F_KEY (1 << 2)
|
|
|
|
|
struct flow_tnl {
|
|
|
|
|
ovs_be64 tun_id;
|
|
|
|
|
ovs_be32 ip_src;
|
|
|
|
|
ovs_be32 ip_dst;
|
|
|
|
|
uint16_t flags;
|
|
|
|
|
uint8_t ip_tos;
|
|
|
|
|
uint8_t ip_ttl;
|
|
|
|
|
};
|
|
|
|
|
|
2012-09-25 15:25:51 -07:00
|
|
|
|
/*
|
|
|
|
|
* A flow in the network.
|
|
|
|
|
*
|
|
|
|
|
* The meaning of 'in_port' is context-dependent. In most cases, it is a
|
|
|
|
|
* 16-bit OpenFlow 1.0 port number. In the software datapath interface (dpif)
|
|
|
|
|
* layer and its implementations (e.g. dpif-linux, dpif-netdev), it is instead
|
|
|
|
|
* a 32-bit datapath port number.
|
|
|
|
|
*/
|
2010-10-11 13:31:35 -07:00
|
|
|
|
struct flow {
|
2012-09-13 20:11:08 -07:00
|
|
|
|
struct flow_tnl tunnel; /* Encapsulating tunnel parameters. */
|
2012-06-27 01:09:44 +12:00
|
|
|
|
ovs_be64 metadata; /* OpenFlow Metadata. */
|
2011-11-02 18:22:22 -07:00
|
|
|
|
struct in6_addr ipv6_src; /* IPv6 source address. */
|
|
|
|
|
struct in6_addr ipv6_dst; /* IPv6 destination address. */
|
|
|
|
|
struct in6_addr nd_target; /* IPv6 neighbor discovery (ND) target. */
|
2011-12-21 15:52:23 -08:00
|
|
|
|
uint32_t skb_priority; /* Packet priority for QoS. */
|
2010-11-11 10:41:33 -08:00
|
|
|
|
uint32_t regs[FLOW_N_REGS]; /* Registers. */
|
2010-12-29 19:03:46 -08:00
|
|
|
|
ovs_be32 nw_src; /* IPv4 source address. */
|
|
|
|
|
ovs_be32 nw_dst; /* IPv4 destination address. */
|
2011-11-01 15:57:56 -07:00
|
|
|
|
ovs_be32 ipv6_label; /* IPv6 flow label. */
|
2012-09-25 15:25:51 -07:00
|
|
|
|
uint32_t in_port; /* Input port. OpenFlow port number
|
|
|
|
|
unless in DPIF code, in which case it
|
|
|
|
|
is the datapath port number. */
|
2010-11-23 10:06:28 -08:00
|
|
|
|
ovs_be16 vlan_tci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */
|
2010-10-26 15:24:26 -07:00
|
|
|
|
ovs_be16 dl_type; /* Ethernet frame type. */
|
|
|
|
|
ovs_be16 tp_src; /* TCP/UDP source port. */
|
|
|
|
|
ovs_be16 tp_dst; /* TCP/UDP destination port. */
|
2010-10-11 13:31:35 -07:00
|
|
|
|
uint8_t dl_src[6]; /* Ethernet source address. */
|
|
|
|
|
uint8_t dl_dst[6]; /* Ethernet destination address. */
|
|
|
|
|
uint8_t nw_proto; /* IP protocol or low 8 bits of ARP opcode. */
|
2011-11-09 17:10:27 -08:00
|
|
|
|
uint8_t nw_tos; /* IP ToS (including DSCP and ECN). */
|
2011-02-01 22:54:11 -08:00
|
|
|
|
uint8_t arp_sha[6]; /* ARP/ND source hardware address. */
|
|
|
|
|
uint8_t arp_tha[6]; /* ARP/ND target hardware address. */
|
2011-11-05 15:48:12 -07:00
|
|
|
|
uint8_t nw_ttl; /* IP TTL/Hop Limit. */
|
2011-11-09 17:10:27 -08:00
|
|
|
|
uint8_t nw_frag; /* FLOW_FRAG_* flags. */
|
2010-10-11 13:31:35 -07:00
|
|
|
|
};
|
2012-09-13 20:11:08 -07:00
|
|
|
|
BUILD_ASSERT_DECL(sizeof(struct flow) % 4 == 0);
|
2012-06-18 15:12:57 -07:00
|
|
|
|
|
2012-08-07 13:43:18 -07:00
|
|
|
|
#define FLOW_U32S (sizeof(struct flow) / 4)
|
|
|
|
|
|
2012-06-18 15:12:57 -07:00
|
|
|
|
/* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */
|
2012-10-03 11:29:05 -07:00
|
|
|
|
BUILD_ASSERT_DECL(sizeof(struct flow) == sizeof(struct flow_tnl) + 144 &&
|
|
|
|
|
FLOW_WC_SEQ == 17);
|
2010-10-11 13:31:35 -07:00
|
|
|
|
|
Do not include zeroed metadata fields in NXM/OXM packet-in messages.
NXM and OpenFlow 1.2+ allow including the values of arbitrary flow metadata
in "packet-in" messages. Open vSwitch has until now always included all
the values of the metadata fields that it implements in NXT_PACKET_IN
messages.
However, this has at least two disadvantages:
- Most of the metadata fields tend to be zero most of the time, which
wastes space in the message.
- It means that controllers must be very liberal about accepting
fields that they know nothing about in packet-in messages, since any
switch upgrade could cause new fields to appear even if the
controller does nothing to give them nonzero values. (Controllers
have to be prepared to tolerate unknown fields in any case, but this
property makes unknown fields more likely to appear than otherwise.)
This commit changes Open vSwitch so that metadata fields whose values are
zero are not reported in packet-ins, fixing both problems. (This is
explicitly allowed by OpenFlow 1.2+.)
This commit mainly fixes a sort of internal conceptual dissonance centering
around struct flow_metadata. This structure is supposed to report the
metadata for a given flow. If you look at a flow, it has particular
metadata values; it doesn't have masks, and the idea of a mask for a
particular flow doesn't really make sense. However, struct flow_metadata
did have masks. This led to internal confusion; one can see this in, for
example, the following code removed by this commit in ofproto-dpif.c to
handle misses in the OpenFlow flow table:
/* Registers aren't meaningful on a miss. */
memset(pin.fmd.reg_masks, 0, sizeof pin.fmd.reg_masks);
What this code was really trying to say is that on a flow miss, the
registers are zero, so they shouldn't be included in the packet-in message.
It did manage to omit the registers, by marking them as "wild", but it is
conceptually more correct to simply omit them because they are zero (and
that's one effect of this commit).
Bug #12968.
Reported-by: Igor Ganichev <iganichev@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-15 10:16:49 -07:00
|
|
|
|
/* Represents the metadata fields of struct flow. */
|
2012-01-04 16:40:13 -08:00
|
|
|
|
struct flow_metadata {
|
|
|
|
|
ovs_be64 tun_id; /* Encapsulating tunnel ID. */
|
Do not include zeroed metadata fields in NXM/OXM packet-in messages.
NXM and OpenFlow 1.2+ allow including the values of arbitrary flow metadata
in "packet-in" messages. Open vSwitch has until now always included all
the values of the metadata fields that it implements in NXT_PACKET_IN
messages.
However, this has at least two disadvantages:
- Most of the metadata fields tend to be zero most of the time, which
wastes space in the message.
- It means that controllers must be very liberal about accepting
fields that they know nothing about in packet-in messages, since any
switch upgrade could cause new fields to appear even if the
controller does nothing to give them nonzero values. (Controllers
have to be prepared to tolerate unknown fields in any case, but this
property makes unknown fields more likely to appear than otherwise.)
This commit changes Open vSwitch so that metadata fields whose values are
zero are not reported in packet-ins, fixing both problems. (This is
explicitly allowed by OpenFlow 1.2+.)
This commit mainly fixes a sort of internal conceptual dissonance centering
around struct flow_metadata. This structure is supposed to report the
metadata for a given flow. If you look at a flow, it has particular
metadata values; it doesn't have masks, and the idea of a mask for a
particular flow doesn't really make sense. However, struct flow_metadata
did have masks. This led to internal confusion; one can see this in, for
example, the following code removed by this commit in ofproto-dpif.c to
handle misses in the OpenFlow flow table:
/* Registers aren't meaningful on a miss. */
memset(pin.fmd.reg_masks, 0, sizeof pin.fmd.reg_masks);
What this code was really trying to say is that on a flow miss, the
registers are zero, so they shouldn't be included in the packet-in message.
It did manage to omit the registers, by marking them as "wild", but it is
conceptually more correct to simply omit them because they are zero (and
that's one effect of this commit).
Bug #12968.
Reported-by: Igor Ganichev <iganichev@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-15 10:16:49 -07:00
|
|
|
|
ovs_be64 metadata; /* OpenFlow 1.1+ metadata field. */
|
2012-01-04 16:40:13 -08:00
|
|
|
|
uint32_t regs[FLOW_N_REGS]; /* Registers. */
|
|
|
|
|
uint16_t in_port; /* OpenFlow port or zero. */
|
|
|
|
|
};
|
|
|
|
|
|
2012-09-13 20:11:08 -07:00
|
|
|
|
void flow_extract(struct ofpbuf *, uint32_t priority, const struct flow_tnl *,
|
2011-11-01 10:13:16 -07:00
|
|
|
|
uint16_t in_port, struct flow *);
|
2011-08-19 09:39:16 -07:00
|
|
|
|
void flow_zero_wildcards(struct flow *, const struct flow_wildcards *);
|
2012-01-04 16:40:13 -08:00
|
|
|
|
void flow_get_metadata(const struct flow *, struct flow_metadata *);
|
2011-08-19 09:39:16 -07:00
|
|
|
|
|
2010-09-03 11:30:02 -07:00
|
|
|
|
char *flow_to_string(const struct flow *);
|
|
|
|
|
void flow_format(struct ds *, const struct flow *);
|
|
|
|
|
void flow_print(FILE *, const struct flow *);
|
2011-10-25 16:33:38 -07:00
|
|
|
|
static inline int flow_compare_3way(const struct flow *, const struct flow *);
|
2010-09-03 11:30:02 -07:00
|
|
|
|
static inline bool flow_equal(const struct flow *, const struct flow *);
|
|
|
|
|
static inline size_t flow_hash(const struct flow *, uint32_t basis);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2012-07-22 22:42:55 -07:00
|
|
|
|
void flow_set_dl_vlan(struct flow *, ovs_be16 vid);
|
2012-07-22 23:20:22 -07:00
|
|
|
|
void flow_set_vlan_vid(struct flow *, ovs_be16 vid);
|
2011-11-21 14:14:02 -08:00
|
|
|
|
void flow_set_vlan_pcp(struct flow *, uint8_t pcp);
|
|
|
|
|
|
2011-09-08 14:32:13 -07:00
|
|
|
|
void flow_compose(struct ofpbuf *, const struct flow *);
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
static inline int
|
2011-10-25 16:33:38 -07:00
|
|
|
|
flow_compare_3way(const struct flow *a, const struct flow *b)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2012-06-18 15:12:57 -07:00
|
|
|
|
return memcmp(a, b, sizeof *a);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool
|
2010-09-03 11:30:02 -07:00
|
|
|
|
flow_equal(const struct flow *a, const struct flow *b)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2011-10-25 16:33:38 -07:00
|
|
|
|
return !flow_compare_3way(a, b);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline size_t
|
2010-09-03 11:30:02 -07:00
|
|
|
|
flow_hash(const struct flow *flow, uint32_t basis)
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{
|
2012-06-18 15:12:57 -07:00
|
|
|
|
return hash_words((const uint32_t *) flow, sizeof *flow / 4, basis);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
2012-09-04 12:43:53 -07:00
|
|
|
|
|
|
|
|
|
uint32_t flow_hash_in_minimask(const struct flow *, const struct minimask *,
|
|
|
|
|
uint32_t basis);
|
2012-08-07 13:43:18 -07:00
|
|
|
|
|
2012-08-07 13:38:38 -07:00
|
|
|
|
/* Wildcards for a flow.
|
|
|
|
|
*
|
|
|
|
|
* A 1-bit in each bit in 'masks' indicates that the corresponding bit of
|
|
|
|
|
* the flow is significant (must match). A 0-bit indicates that the
|
|
|
|
|
* corresponding bit of the flow is wildcarded (need not match). */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
struct flow_wildcards {
|
2012-08-07 13:38:38 -07:00
|
|
|
|
struct flow masks;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
};
|
2011-07-29 13:15:09 -07:00
|
|
|
|
|
2010-11-10 14:39:54 -08:00
|
|
|
|
void flow_wildcards_init_catchall(struct flow_wildcards *);
|
2010-10-27 20:15:56 -07:00
|
|
|
|
void flow_wildcards_init_exact(struct flow_wildcards *);
|
|
|
|
|
|
2011-09-12 16:38:52 -07:00
|
|
|
|
bool flow_wildcards_is_catchall(const struct flow_wildcards *);
|
2010-11-08 16:45:00 -08:00
|
|
|
|
|
2010-11-11 10:41:33 -08:00
|
|
|
|
void flow_wildcards_set_reg_mask(struct flow_wildcards *,
|
|
|
|
|
int idx, uint32_t mask);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2010-11-03 11:00:58 -07:00
|
|
|
|
void flow_wildcards_combine(struct flow_wildcards *dst,
|
|
|
|
|
const struct flow_wildcards *src1,
|
|
|
|
|
const struct flow_wildcards *src2);
|
|
|
|
|
bool flow_wildcards_has_extra(const struct flow_wildcards *,
|
|
|
|
|
const struct flow_wildcards *);
|
|
|
|
|
|
2011-05-26 16:23:21 -07:00
|
|
|
|
uint32_t flow_wildcards_hash(const struct flow_wildcards *, uint32_t basis);
|
2010-11-03 11:00:58 -07:00
|
|
|
|
bool flow_wildcards_equal(const struct flow_wildcards *,
|
|
|
|
|
const struct flow_wildcards *);
|
2011-02-01 18:50:25 -08:00
|
|
|
|
uint32_t flow_hash_symmetric_l4(const struct flow *flow, uint32_t basis);
|
2010-11-03 11:00:58 -07:00
|
|
|
|
|
2011-07-13 16:20:24 -07:00
|
|
|
|
uint32_t flow_hash_fields(const struct flow *, enum nx_hash_fields,
|
|
|
|
|
uint16_t basis);
|
|
|
|
|
const char *flow_hash_fields_to_str(enum nx_hash_fields);
|
|
|
|
|
bool flow_hash_fields_valid(enum nx_hash_fields);
|
2011-06-06 14:21:40 -07:00
|
|
|
|
|
2012-08-07 13:43:18 -07:00
|
|
|
|
bool flow_equal_except(const struct flow *a, const struct flow *b,
|
|
|
|
|
const struct flow_wildcards *);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
|
|
|
|
|
/* Compressed flow. */
|
|
|
|
|
|
|
|
|
|
#define MINI_N_INLINE (sizeof(void *) == 4 ? 7 : 8)
|
|
|
|
|
#define MINI_N_MAPS DIV_ROUND_UP(FLOW_U32S, 32)
|
|
|
|
|
|
|
|
|
|
/* A sparse representation of a "struct flow".
|
|
|
|
|
*
|
|
|
|
|
* A "struct flow" is fairly large and tends to be mostly zeros. Sparse
|
|
|
|
|
* representation has two advantages. First, it saves memory. Second, it
|
|
|
|
|
* saves time when the goal is to iterate over only the nonzero parts of the
|
|
|
|
|
* struct.
|
|
|
|
|
*
|
|
|
|
|
* The 'map' member holds one bit for each uint32_t in a "struct flow". Each
|
|
|
|
|
* 0-bit indicates that the corresponding uint32_t is zero, each 1-bit that it
|
|
|
|
|
* is nonzero.
|
|
|
|
|
*
|
|
|
|
|
* 'values' points to the start of an array that has one element for each 1-bit
|
|
|
|
|
* in 'map'. The least-numbered 1-bit is in values[0], the next 1-bit is in
|
|
|
|
|
* values[1], and so on.
|
|
|
|
|
*
|
|
|
|
|
* 'values' may point to a few different locations:
|
|
|
|
|
*
|
|
|
|
|
* - If 'map' has MINI_N_INLINE or fewer 1-bits, it may point to
|
|
|
|
|
* 'inline_values'. One hopes that this is the common case.
|
|
|
|
|
*
|
|
|
|
|
* - If 'map' has more than MINI_N_INLINE 1-bits, it may point to memory
|
|
|
|
|
* allocated with malloc().
|
|
|
|
|
*
|
|
|
|
|
* - The caller could provide storage on the stack for situations where
|
|
|
|
|
* that makes sense. So far that's only proved useful for
|
|
|
|
|
* minimask_combine(), but the principle works elsewhere.
|
|
|
|
|
*
|
|
|
|
|
* The implementation maintains and depends on the invariant that every element
|
|
|
|
|
* in 'values' is nonzero; that is, wherever a 1-bit appears in 'map', the
|
|
|
|
|
* corresponding element of 'values' must be nonzero.
|
|
|
|
|
*/
|
|
|
|
|
struct miniflow {
|
|
|
|
|
uint32_t *values;
|
|
|
|
|
uint32_t inline_values[MINI_N_INLINE];
|
|
|
|
|
uint32_t map[MINI_N_MAPS];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void miniflow_init(struct miniflow *, const struct flow *);
|
|
|
|
|
void miniflow_clone(struct miniflow *, const struct miniflow *);
|
|
|
|
|
void miniflow_destroy(struct miniflow *);
|
|
|
|
|
|
|
|
|
|
void miniflow_expand(const struct miniflow *, struct flow *);
|
|
|
|
|
|
|
|
|
|
uint32_t miniflow_get(const struct miniflow *, unsigned int u32_ofs);
|
|
|
|
|
uint16_t miniflow_get_vid(const struct miniflow *);
|
|
|
|
|
|
|
|
|
|
bool miniflow_equal(const struct miniflow *a, const struct miniflow *b);
|
|
|
|
|
bool miniflow_equal_in_minimask(const struct miniflow *a,
|
|
|
|
|
const struct miniflow *b,
|
|
|
|
|
const struct minimask *);
|
|
|
|
|
bool miniflow_equal_flow_in_minimask(const struct miniflow *a,
|
|
|
|
|
const struct flow *b,
|
|
|
|
|
const struct minimask *);
|
|
|
|
|
uint32_t miniflow_hash(const struct miniflow *, uint32_t basis);
|
|
|
|
|
uint32_t miniflow_hash_in_minimask(const struct miniflow *,
|
|
|
|
|
const struct minimask *, uint32_t basis);
|
|
|
|
|
|
|
|
|
|
/* Compressed flow wildcards. */
|
|
|
|
|
|
|
|
|
|
/* A sparse representation of a "struct flow_wildcards".
|
|
|
|
|
*
|
|
|
|
|
* See the large comment on struct miniflow for details. */
|
|
|
|
|
struct minimask {
|
|
|
|
|
struct miniflow masks;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void minimask_init(struct minimask *, const struct flow_wildcards *);
|
|
|
|
|
void minimask_clone(struct minimask *, const struct minimask *);
|
|
|
|
|
void minimask_combine(struct minimask *dst,
|
|
|
|
|
const struct minimask *a, const struct minimask *b,
|
|
|
|
|
uint32_t storage[FLOW_U32S]);
|
|
|
|
|
void minimask_destroy(struct minimask *);
|
|
|
|
|
|
|
|
|
|
void minimask_expand(const struct minimask *, struct flow_wildcards *);
|
|
|
|
|
|
|
|
|
|
uint32_t minimask_get(const struct minimask *, unsigned int u32_ofs);
|
|
|
|
|
uint16_t minimask_get_vid_mask(const struct minimask *);
|
|
|
|
|
|
|
|
|
|
bool minimask_equal(const struct minimask *a, const struct minimask *b);
|
|
|
|
|
uint32_t minimask_hash(const struct minimask *, uint32_t basis);
|
|
|
|
|
|
|
|
|
|
bool minimask_has_extra(const struct minimask *, const struct minimask *);
|
|
|
|
|
bool minimask_is_catchall(const struct minimask *);
|
2012-08-07 13:43:18 -07:00
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#endif /* flow.h */
|