On Thu, Jun 14, 2012 at 08:52:07AM +0900, Simon Horman wrote:
> Signed-off-by: Simon Horman <[email protected]>
> ---
>  lib/ofp-util.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 45 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/ofp-util.c b/lib/ofp-util.c
> index 2bc0af0..1fc6dc6 100644
> --- a/lib/ofp-util.c
> +++ b/lib/ofp-util.c
> @@ -2408,6 +2408,24 @@ ofputil_encode_flow_removed(const struct 
> ofputil_flow_removed *fr,
>      return msg;
>  }
>  
> +static void
> +ofputil_decode_packet_in_finish(struct ofputil_packet_in *pin,
> +                                struct cls_rule *rule,
> +                                struct ofpbuf *b)
> +{
> +    pin->packet = b->data;
> +    pin->packet_len = b->size;
> +
> +    pin->fmd.in_port = rule->flow.in_port;
> +
> +    pin->fmd.tun_id = rule->flow.tun_id;
> +    pin->fmd.tun_id_mask = rule->wc.tun_id_mask;
> +
> +    memcpy(pin->fmd.regs, rule->flow.regs, sizeof pin->fmd.regs);
> +    memcpy(pin->fmd.reg_masks, rule->wc.reg_masks,
> +           sizeof pin->fmd.reg_masks);
> +}
> +
>  enum ofperr
>  ofputil_decode_packet_in(struct ofputil_packet_in *pin,
>                           const struct ofp_header *oh)
> @@ -2419,7 +2437,7 @@ ofputil_decode_packet_in(struct ofputil_packet_in *pin,
>      code = ofputil_msg_type_code(type);
>      memset(pin, 0, sizeof *pin);
>  
> -    if (code == OFPUTIL_OFPT_PACKET_IN) {
> +    if (code == OFPUTIL_OFPT_PACKET_IN && oh->version == OFP10_VERSION) {

I am wondering if it would be better to rename OFPUTIL_OFPT_PACKET_IN as
OFPUTIL_OFPT10_PACKET_IN and add OFPUTIL_OFPT12_PACKET_IN and avoid
checking oh->version directly here. The same probably applies to other
the decoders for other messages that differ between Open Flow 1.0 and 1.2.

>          const struct ofp_packet_in *opi = (const struct ofp_packet_in *) oh;
>  
>          pin->packet = opi->data;
> @@ -2449,23 +2467,39 @@ ofputil_decode_packet_in(struct ofputil_packet_in 
> *pin,
>              return OFPERR_OFPBRC_BAD_LEN;
>          }
>  
> -        pin->packet = b.data;
> -        pin->packet_len = b.size;
>          pin->reason = npi->reason;
>          pin->table_id = npi->table_id;
>          pin->cookie = npi->cookie;
>  
> -        pin->fmd.in_port = rule.flow.in_port;
> +        pin->buffer_id = ntohl(npi->buffer_id);
> +        pin->total_len = ntohs(npi->total_len);
>  
> -        pin->fmd.tun_id = rule.flow.tun_id;
> -        pin->fmd.tun_id_mask = rule.wc.tun_id_mask;
> +        ofputil_decode_packet_in_finish(pin, &rule, &b);
> +    } else if (code == OFPUTIL_OFPT_PACKET_IN && oh->version == 
> OFP12_VERSION) {
> +        const struct ofp11_packet_in *o11pi;
> +        struct cls_rule rule;
> +        struct ofpbuf b;
> +        int error;
>  
> -        memcpy(pin->fmd.regs, rule.flow.regs, sizeof pin->fmd.regs);
> -        memcpy(pin->fmd.reg_masks, rule.wc.reg_masks,
> -               sizeof pin->fmd.reg_masks);
> +        ofpbuf_use_const(&b, oh, ntohs(oh->length));
>  
> -        pin->buffer_id = ntohl(npi->buffer_id);
> -        pin->total_len = ntohs(npi->total_len);
> +        o11pi = ofpbuf_pull(&b, sizeof *o11pi);
> +        error = ofputil_pull_ofp12_match(&b, 0, &rule, NULL, NULL);
> +        if (error) {
> +            return error;
> +        }
> +
> +        if (!ofpbuf_try_pull(&b, 2)) {
> +            return OFPERR_OFPBRC_BAD_LEN;
> +        }
> +
> +        pin->reason = o11pi->reason;
> +        pin->table_id = o11pi->table_id;
> +
> +        pin->buffer_id = ntohl(o11pi->buffer_id);
> +        pin->total_len = ntohs(o11pi->total_len);
> +
> +        ofputil_decode_packet_in_finish(pin, &rule, &b);
>      } else {
>          NOT_REACHED();
>      }
> -- 
> 1.7.10.2.484.gcd07cc5
> 
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to