[ovs-dev] [PATCHv3 2/6] odp-util: Specify export features when serialising flows.

Andy Zhou azhou at nicira.com
Fri May 16 03:11:23 UTC 2014


On Wed, May 14, 2014 at 11:57 PM, Joe Stringer <joestringer at nicira.com> wrote:
> Signed-off-by: Joe Stringer <joestringer at nicira.com>
> ---
> v3: First post.
> ---
>  lib/odp-util.c |   41 +++++++++++++++++++++++++----------------
>  1 file changed, 25 insertions(+), 16 deletions(-)
>
> diff --git a/lib/odp-util.c b/lib/odp-util.c
> index 6cff2f1..ff3cb7e 100644
> --- a/lib/odp-util.c
> +++ b/lib/odp-util.c
> @@ -2482,16 +2482,16 @@ ovs_to_odp_frag_mask(uint8_t nw_frag_mask)
>
>  static void
>  odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
> -                         const struct flow *mask, odp_port_t odp_in_port,
> -                         size_t max_mpls_depth, bool export_mask)
> +                         const struct flow *mask, const struct flow *data,
> +                         odp_port_t odp_in_port, size_t max_mpls_depth,
> +                         uint64_t export_mask)
Changing export_mask from bool to uint64_t seems to be overkill.  I
hope we can avoid doing this.
How about we the following prototype:
odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
                         const struct flow *mask, odp_port_t odp_in_port,
                         size_t max_mpls_depth, bool dp_recirc, bool
export_mask)
--------------------------------------------------------->  ^^^^^^^^^^^^^^^

/* dp_recirc indicates that datapath understands recirculation */

The decision of exporting recirc_id and dp_hash will be simple:

     if (dp_recric) {
           nl_msg_put_u32(buf, OVS_KEY_ATTR_RECIRC_ID ...)
           nl_msg_put_u32(buf, OVS_KEY_ATTR_DP_HASH ... )
     }

We can obtain dp_recirc value similar to max_mpls_depth.

For example: in ofproto-dpif-upcall.c  we can call
ofproto_dpif_get_enable_recirc() to obtain the value.

dp_recirc can always be set to true within the user space datapath.

Would this work?



>  {
>      struct ovs_key_ethernet *eth_key;
>      size_t encap;
> -    const struct flow *data = export_mask ? mask : flow;
>
>      nl_msg_put_u32(buf, OVS_KEY_ATTR_PRIORITY, data->skb_priority);
>
> -    if (flow->tunnel.ip_dst || export_mask) {
> +    if (flow->tunnel.ip_dst || export_mask & 1 << OVS_KEY_ATTR_TUNNEL) {
>          tun_key_to_attr(buf, &data->tunnel);
>      }
>
> @@ -2507,7 +2507,7 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>
>      /* Add an ingress port attribute if this is a mask or 'odp_in_port'
>       * is not the magical value "ODPP_NONE". */
> -    if (export_mask || odp_in_port != ODPP_NONE) {
> +    if (export_mask & 1 << OVS_KEY_ATTR_IN_PORT || odp_in_port != ODPP_NONE) {
>          nl_msg_put_odp_port(buf, OVS_KEY_ATTR_IN_PORT, odp_in_port);
>      }
>
> @@ -2517,7 +2517,7 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>      memcpy(eth_key->eth_dst, data->dl_dst, ETH_ADDR_LEN);
>
>      if (flow->vlan_tci != htons(0) || flow->dl_type == htons(ETH_TYPE_VLAN)) {
> -        if (export_mask) {
> +        if (export_mask & 1 << OVS_KEY_ATTR_ETHERTYPE) {
>              nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
>          } else {
>              nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, htons(ETH_TYPE_VLAN));
> @@ -2543,7 +2543,7 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>           *  <none>   0xffff   Any non-Ethernet II frame (except valid
>           *                    802.3 SNAP packet with valid eth_type).
>           */
> -        if (export_mask) {
> +        if (export_mask & 1 << OVS_KEY_ATTR_ETHERTYPE) {
>              nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, OVS_BE16_MAX);
>          }
>          goto unencap;
> @@ -2561,8 +2561,9 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>          ipv4_key->ipv4_proto = data->nw_proto;
>          ipv4_key->ipv4_tos = data->nw_tos;
>          ipv4_key->ipv4_ttl = data->nw_ttl;
> -        ipv4_key->ipv4_frag = export_mask ? ovs_to_odp_frag_mask(data->nw_frag)
> -                                      : ovs_to_odp_frag(data->nw_frag);
> +        ipv4_key->ipv4_frag = export_mask & 1 << OVS_KEY_ATTR_IPV4
> +                              ? ovs_to_odp_frag_mask(data->nw_frag)
> +                              : ovs_to_odp_frag(data->nw_frag);
>      } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
>          struct ovs_key_ipv6 *ipv6_key;
>
> @@ -2574,8 +2575,9 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>          ipv6_key->ipv6_proto = data->nw_proto;
>          ipv6_key->ipv6_tclass = data->nw_tos;
>          ipv6_key->ipv6_hlimit = data->nw_ttl;
> -        ipv6_key->ipv6_frag = export_mask ? ovs_to_odp_frag_mask(data->nw_frag)
> -                                      : ovs_to_odp_frag(data->nw_frag);
> +        ipv6_key->ipv6_frag = export_mask & 1 << OVS_KEY_ATTR_IPV6
> +                              ? ovs_to_odp_frag_mask(data->nw_frag)
> +                              : ovs_to_odp_frag(data->nw_frag);
>      } else if (flow->dl_type == htons(ETH_TYPE_ARP) ||
>                 flow->dl_type == htons(ETH_TYPE_RARP)) {
>          struct ovs_key_arp *arp_key;
> @@ -2646,8 +2648,9 @@ odp_flow_key_from_flow__(struct ofpbuf *buf, const struct flow *flow,
>              if (flow->tp_dst == htons(0)
>                  && (flow->tp_src == htons(ND_NEIGHBOR_SOLICIT)
>                      || flow->tp_src == htons(ND_NEIGHBOR_ADVERT))
> -                && (!export_mask || (data->tp_src == htons(0xffff)
> -                                     && data->tp_dst == htons(0xffff)))) {
> +                && (!(export_mask & 1 << OVS_KEY_ATTR_ND)
> +                    || (data->tp_src == htons(0xffff)
> +                        && data->tp_dst == htons(0xffff)))) {
>
>                  struct ovs_key_nd *nd_key;
>
> @@ -2679,7 +2682,7 @@ void
>  odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow,
>                         const struct flow *mask, odp_port_t odp_in_port)
>  {
> -    odp_flow_key_from_flow__(buf, flow, mask, odp_in_port, SIZE_MAX, false);
> +    odp_flow_key_from_flow__(buf, flow, mask, flow, odp_in_port, SIZE_MAX, 0);
>  }
>
>  /* Appends a representation of 'mask' as OVS_KEY_ATTR_* attributes to
> @@ -2695,8 +2698,14 @@ odp_flow_key_from_mask(struct ofpbuf *buf, const struct flow *mask,
>                         const struct flow *flow, uint32_t odp_in_port_mask,
>                         size_t max_mpls_depth)
>  {
> -    odp_flow_key_from_flow__(buf, flow, mask,
> -                             u32_to_odp(odp_in_port_mask), max_mpls_depth, true);
> +    uint64_t export_mask;
> +
> +    export_mask = (1 << OVS_KEY_ATTR_TUNNEL | 1 << OVS_KEY_ATTR_IN_PORT
> +                   | 1 << OVS_KEY_ATTR_ETHERTYPE | 1 << OVS_KEY_ATTR_IPV4
> +                   | 1 << OVS_KEY_ATTR_IPV6 | 1 << OVS_KEY_ATTR_ND);
> +    odp_flow_key_from_flow__(buf, flow, mask, mask,
> +                             u32_to_odp(odp_in_port_mask), max_mpls_depth,
> +                             export_mask);
>  }
>
>  /* Generate ODP flow key from the given packet metadata */
> --
> 1.7.10.4
>



More information about the dev mailing list