2009-07-08 13:19:16 -07:00
|
|
|
|
/*
|
2013-01-25 16:22:07 +09:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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>
|
2013-09-25 15:07:21 -07:00
|
|
|
|
#include "byte-order.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. */
|
2013-10-28 13:54:40 -07:00
|
|
|
|
#define FLOW_WC_SEQ 22
|
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)
|
2012-11-21 18:51:36 -08:00
|
|
|
|
|
|
|
|
|
const char *flow_tun_flag_to_string(uint32_t flags);
|
|
|
|
|
|
2012-09-13 20:11:08 -07:00
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-19 16:58:44 -07:00
|
|
|
|
/* Unfortunately, a "struct flow" sometimes has to handle OpenFlow port
|
|
|
|
|
* numbers and other times datapath (dpif) port numbers. This union allows
|
|
|
|
|
* access to both. */
|
|
|
|
|
union flow_in_port {
|
|
|
|
|
ofp_port_t ofp_port;
|
|
|
|
|
odp_port_t odp_port;
|
|
|
|
|
};
|
|
|
|
|
|
2012-09-25 15:25:51 -07:00
|
|
|
|
/*
|
2013-10-17 14:28:20 -07:00
|
|
|
|
* A flow in the network.
|
|
|
|
|
*
|
|
|
|
|
* Must be initialized to all zeros to make any compiler-induced padding
|
|
|
|
|
* zeroed. Helps also in keeping unused fields (such as mutually exclusive
|
|
|
|
|
* IPv4 and IPv6 addresses) zeroed out.
|
|
|
|
|
*
|
|
|
|
|
* 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. */
|
2013-06-19 16:58:44 -07:00
|
|
|
|
union flow_in_port in_port; /* Input port.*/
|
2013-08-06 12:57:13 -07:00
|
|
|
|
uint32_t pkt_mark; /* Packet mark. */
|
2013-01-25 16:22:07 +09:00
|
|
|
|
ovs_be32 mpls_lse; /* MPLS label stack entry. */
|
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. */
|
2013-08-22 20:24:44 +12:00
|
|
|
|
ovs_be16 tp_src; /* TCP/UDP/SCTP source port. */
|
|
|
|
|
ovs_be16 tp_dst; /* TCP/UDP/SCTP destination port. */
|
2013-10-28 13:54:40 -07:00
|
|
|
|
ovs_be16 tcp_flags; /* TCP flags. */
|
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. */
|
2013-10-17 14:28:20 -07:00
|
|
|
|
uint8_t nw_frag; /* FLOW_FRAG_* flags. Keep last for the
|
|
|
|
|
BUILD_ASSERT_DECL below */
|
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'. */
|
2013-10-17 14:28:20 -07:00
|
|
|
|
BUILD_ASSERT_DECL(offsetof(struct flow, nw_frag) + 1
|
2013-10-28 13:54:40 -07:00
|
|
|
|
== sizeof(struct flow_tnl) + 154
|
|
|
|
|
&& FLOW_WC_SEQ == 22);
|
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. */
|
2013-05-09 15:24:16 +03:00
|
|
|
|
ovs_be32 tun_src; /* Tunnel outer IPv4 src addr */
|
|
|
|
|
ovs_be32 tun_dst; /* Tunnel outer IPv4 dst addr */
|
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. */
|
2013-08-06 12:57:16 -07:00
|
|
|
|
uint32_t pkt_mark; /* Packet mark. */
|
2013-06-19 16:58:44 -07:00
|
|
|
|
ofp_port_t in_port; /* OpenFlow port or zero. */
|
2012-01-04 16:40:13 -08:00
|
|
|
|
};
|
|
|
|
|
|
2012-11-13 19:19:36 +02:00
|
|
|
|
void flow_extract(struct ofpbuf *, uint32_t priority, uint32_t mark,
|
2013-06-19 16:58:44 -07:00
|
|
|
|
const struct flow_tnl *, const union flow_in_port *in_port,
|
|
|
|
|
struct flow *);
|
2013-01-25 16:22:07 +09:00
|
|
|
|
|
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 *);
|
2012-11-21 18:51:36 -08:00
|
|
|
|
void format_flags(struct ds *ds, const char *(*bit_to_string)(uint32_t),
|
|
|
|
|
uint32_t flags, char del);
|
|
|
|
|
|
2010-09-03 11:30:02 -07:00
|
|
|
|
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);
|
|
|
|
|
|
2013-01-25 16:22:07 +09:00
|
|
|
|
void flow_set_mpls_label(struct flow *flow, ovs_be32 label);
|
|
|
|
|
void flow_set_mpls_ttl(struct flow *flow, uint8_t ttl);
|
|
|
|
|
void flow_set_mpls_tc(struct flow *flow, uint8_t tc);
|
|
|
|
|
void flow_set_mpls_bos(struct flow *flow, uint8_t stack);
|
|
|
|
|
|
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
|
|
|
|
|
2013-06-19 16:58:44 -07:00
|
|
|
|
static inline uint16_t
|
|
|
|
|
ofp_to_u16(ofp_port_t ofp_port)
|
|
|
|
|
{
|
|
|
|
|
return (OVS_FORCE uint16_t) ofp_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
odp_to_u32(odp_port_t odp_port)
|
|
|
|
|
{
|
|
|
|
|
return (OVS_FORCE uint32_t) odp_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
ofp11_to_u32(ofp11_port_t ofp11_port)
|
|
|
|
|
{
|
|
|
|
|
return (OVS_FORCE uint32_t) ofp11_port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline ofp_port_t
|
|
|
|
|
u16_to_ofp(uint16_t port)
|
|
|
|
|
{
|
|
|
|
|
return OFP_PORT_C(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline odp_port_t
|
|
|
|
|
u32_to_odp(uint32_t port)
|
|
|
|
|
{
|
|
|
|
|
return ODP_PORT_C(port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline ofp11_port_t
|
|
|
|
|
u32_to_ofp11(uint32_t port)
|
|
|
|
|
{
|
|
|
|
|
return OFP11_PORT_C(port);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-22 10:33:27 -07:00
|
|
|
|
static inline uint32_t
|
|
|
|
|
hash_ofp_port(ofp_port_t ofp_port)
|
|
|
|
|
{
|
|
|
|
|
return hash_int(ofp_to_u16(ofp_port), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t
|
|
|
|
|
hash_odp_port(odp_port_t odp_port)
|
|
|
|
|
{
|
|
|
|
|
return hash_int(odp_to_u32(odp_port), 0);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2013-06-10 22:48:58 -07:00
|
|
|
|
void flow_wildcards_and(struct flow_wildcards *dst,
|
|
|
|
|
const struct flow_wildcards *src1,
|
|
|
|
|
const struct flow_wildcards *src2);
|
|
|
|
|
void flow_wildcards_or(struct flow_wildcards *dst,
|
|
|
|
|
const struct flow_wildcards *src1,
|
|
|
|
|
const struct flow_wildcards *src2);
|
2010-11-03 11:00:58 -07:00
|
|
|
|
bool flow_wildcards_has_extra(const struct flow_wildcards *,
|
|
|
|
|
const struct flow_wildcards *);
|
|
|
|
|
|
2013-05-09 19:14:20 -07:00
|
|
|
|
void flow_wildcards_fold_minimask(struct flow_wildcards *,
|
|
|
|
|
const struct minimask *);
|
|
|
|
|
|
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
|
|
|
|
|
2013-10-17 14:28:20 -07:00
|
|
|
|
/* Initialize a flow with random fields that matter for nx_hash_fields. */
|
|
|
|
|
void flow_random_hash_fields(struct flow *);
|
2013-06-26 16:37:16 -07:00
|
|
|
|
void flow_mask_hash_fields(const struct flow *, struct flow_wildcards *,
|
|
|
|
|
enum nx_hash_fields);
|
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
|
|
|
|
|
2013-06-10 22:48:58 -07:00
|
|
|
|
uint32_t flow_hash_in_wildcards(const struct flow *,
|
|
|
|
|
const struct flow_wildcards *,
|
|
|
|
|
uint32_t basis);
|
|
|
|
|
|
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
|
2013-02-06 16:13:19 -08:00
|
|
|
|
* *may* be nonzero.
|
2012-09-04 12:43:53 -07:00
|
|
|
|
*
|
|
|
|
|
* '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.
|
|
|
|
|
*
|
2013-02-06 16:13:19 -08:00
|
|
|
|
* Elements in 'values' are allowed to be zero. This is useful for "struct
|
|
|
|
|
* minimatch", for which ensuring that the miniflow and minimask members have
|
|
|
|
|
* same 'map' allows optimization .
|
2012-09-04 12:43:53 -07:00
|
|
|
|
*/
|
|
|
|
|
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 *);
|
2013-02-06 16:13:19 -08:00
|
|
|
|
void miniflow_init_with_minimask(struct miniflow *, const struct flow *,
|
|
|
|
|
const struct minimask *);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
void miniflow_clone(struct miniflow *, const struct miniflow *);
|
2013-08-27 12:25:48 -07:00
|
|
|
|
void miniflow_move(struct miniflow *dst, struct miniflow *);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
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 *);
|
2013-09-25 15:07:21 -07:00
|
|
|
|
static inline ovs_be64 miniflow_get_metadata(const struct miniflow *);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
|
|
|
|
|
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 *);
|
2013-08-27 12:25:48 -07:00
|
|
|
|
void minimask_move(struct minimask *dst, struct minimask *src);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
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 *);
|
2013-09-25 15:07:21 -07:00
|
|
|
|
static inline ovs_be64 minimask_get_metadata_mask(const struct minimask *);
|
2012-09-04 12:43:53 -07:00
|
|
|
|
|
|
|
|
|
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 *);
|
2013-09-25 15:07:21 -07:00
|
|
|
|
|
|
|
|
|
/* Returns the value of the OpenFlow 1.1+ "metadata" field in 'flow'. */
|
|
|
|
|
static inline ovs_be64
|
|
|
|
|
miniflow_get_metadata(const struct miniflow *flow)
|
|
|
|
|
{
|
|
|
|
|
enum { MD_OFS = offsetof(struct flow, metadata) };
|
|
|
|
|
BUILD_ASSERT_DECL(MD_OFS % sizeof(uint32_t) == 0);
|
|
|
|
|
ovs_be32 hi = (OVS_FORCE ovs_be32) miniflow_get(flow, MD_OFS / 4);
|
|
|
|
|
ovs_be32 lo = (OVS_FORCE ovs_be32) miniflow_get(flow, MD_OFS / 4 + 1);
|
|
|
|
|
|
|
|
|
|
return htonll(((uint64_t) ntohl(hi) << 32) | ntohl(lo));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the mask for the OpenFlow 1.1+ "metadata" field in 'mask'.
|
|
|
|
|
*
|
|
|
|
|
* The return value is all-1-bits if 'mask' matches on the whole value of the
|
|
|
|
|
* metadata field, all-0-bits if 'mask' entirely wildcards the metadata field,
|
|
|
|
|
* or some other value if the metadata field is partially matched, partially
|
|
|
|
|
* wildcarded. */
|
|
|
|
|
static inline ovs_be64
|
|
|
|
|
minimask_get_metadata_mask(const struct minimask *mask)
|
|
|
|
|
{
|
|
|
|
|
return miniflow_get_metadata(&mask->masks);
|
|
|
|
|
}
|
2012-08-07 13:43:18 -07:00
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#endif /* flow.h */
|