[ovs-discuss] flow_fields_match() in Open vSwitch?

Macapuna, Carlos A. B. carlosmacapuna at gmail.com
Tue Feb 2 20:45:03 UTC 2010


We extended the OpenFlow reference implementation (v.89 and v1.0) to
support wildcarded flow matching on arbitrary bitmasks of the Ethernet
fields. It was a straightforward task, needing only a slightly
modification of the function (flow_fields_match) within the flow.c
(openflow-1.0.0/udatapath/switch-flow.c or
openflow-0.9.0/datapath/flow.c):

----flow.c----
/* Internal function used to compare fields in flow. */
static inline
int flow_fields_match(const struct sw_flow_key *a, const struct sw_flow_key
*b,
              uint32_t w, uint32_t src_mask, uint32_t dst_mask)
{
    return ((w & OFPFW_IN_PORT || a->in_port == b->in_port)
        && (w & OFPFW_DL_VLAN || a->dl_vlan == b->dl_vlan)
//        && (w & OFPFW_DL_SRC || !memcmp(a->dl_src, b->dl_src, ETH_ALEN))
 // Modified
//        && (w & OFPFW_DL_DST || !memcmp(a->dl_dst, b->dl_dst, ETH_ALEN))
 // Modified
        && (w & OFPFW_DL_SRC || !bf_mask(a->dl_src, b->dl_src, ETH_ALEN)) //
Modified
        && (w & OFPFW_DL_DST || !bf_mask(a->dl_dst, b->dl_dst, ETH_ALEN)) //
Modified
        && (w & OFPFW_DL_TYPE || a->dl_type == b->dl_type)
        && !((a->nw_src ^ b->nw_src) & src_mask)
        && !((a->nw_dst ^ b->nw_dst) & dst_mask)
        && (w & OFPFW_NW_PROTO || a->nw_proto == b->nw_proto)
        && (w & OFPFW_TP_SRC || a->tp_src == b->tp_src)
        && (w & OFPFW_TP_DST || a->tp_dst == b->tp_dst));
}

/* Modified -Bloom Filter match */
int bf_mask(uint8_t *a_dl, uint8_t *b_dl, size_t eth_alen)
{
    uint8_t a_tmp[eth_alen];
    uint8_t b_tmp[eth_alen];
    memcpy(a_tmp, a_dl, eth_alen);
    memcpy(b_tmp, b_dl, eth_alen);
    int res1, res2, i;
    res1 = 0;
    res2 = 0;
    for (i=0; i<eth_alen; i++){
        res1 = res1 + (a_tmp[i]^(a_tmp[i]&b_tmp[i]));
        res2 = res2 + (b_tmp[i]^(a_tmp[i]&b_tmp[i]));
    }
    return (res1==0?0:res2);
}
----flow.c----

As we want to support the same functionality in Open vSwitches, we
have looked at the code to make the same customization but had no
success so far in finding where the flow match is performed in Open
vSwitch, noting that flow.c is quite different from flow.c in
OpenFlow.
Any developer that points as to the right place in the code to look at?

Thanks,


-- 
Carlos Macapuna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://openvswitch.org/pipermail/ovs-discuss/attachments/20100202/633f8cff/attachment-0002.html>


More information about the discuss mailing list