[ovs-dev] [nxm 23/42] ofp-util: New functions make_nxmsg(), make_nxmsg_xid().

Justin Pettit jpettit at nicira.com
Fri Nov 5 00:58:21 UTC 2010


Looks good.

--Justin


On Oct 28, 2010, at 10:27 AM, Ben Pfaff wrote:

> These functions slightly simplify constructing Nicira vendor extension
> messages.
> ---
> lib/ofp-util.c        |   21 +++++++++++++++++++++
> lib/ofp-util.h        |    3 +++
> ofproto/ofproto.c     |    6 ++----
> ofproto/status.c      |    6 ++----
> utilities/ovs-ofctl.c |   10 +++-------
> 5 files changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/lib/ofp-util.c b/lib/ofp-util.c
> index 25ae976..536ef94 100644
> --- a/lib/ofp-util.c
> +++ b/lib/ofp-util.c
> @@ -59,6 +59,14 @@ make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **bufferp)
>     return put_openflow_xid(openflow_len, type, alloc_xid(), *bufferp);
> }
> 
> +/* Similar to make_openflow() but creates a Nicira vendor extension message
> + * with the specific 'subtype'.  'subtype' should be in host byte order. */
> +void *
> +make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **bufferp)
> +{
> +    return make_nxmsg_xid(openflow_len, subtype, alloc_xid(), bufferp);
> +}
> +
> /* Allocates and stores in '*bufferp' a new ofpbuf with a size of
>  * 'openflow_len', starting with an OpenFlow header with the given 'type' and
>  * transaction id 'xid'.  Allocated bytes beyond the header, if any, are
> @@ -80,6 +88,19 @@ make_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
>     return put_openflow_xid(openflow_len, type, xid, *bufferp);
> }
> 
> +/* Similar to make_openflow_xid() but creates a Nicira vendor extension message
> + * with the specific 'subtype'.  'subtype' should be in host byte order. */
> +void *
> +make_nxmsg_xid(size_t openflow_len, uint32_t subtype, uint32_t xid,
> +               struct ofpbuf **bufferp)
> +{
> +    struct nicira_header *nxh = make_openflow_xid(openflow_len, OFPT_VENDOR,
> +                                                  xid, bufferp);
> +    nxh->vendor = htonl(NX_VENDOR_ID);
> +    nxh->subtype = htonl(subtype);
> +    return nxh;
> +}
> +
> /* Appends 'openflow_len' bytes to 'buffer', starting with an OpenFlow header
>  * with the given 'type' and an arbitrary transaction id.  Allocated bytes
>  * beyond the header, if any, are zeroed.
> diff --git a/lib/ofp-util.h b/lib/ofp-util.h
> index 48a77ad..85ae59d 100644
> --- a/lib/ofp-util.h
> +++ b/lib/ofp-util.h
> @@ -28,8 +28,11 @@ struct ofp_action_header;
> 
> /* OpenFlow protocol utility functions. */
> void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **);
> +void *make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **);
> void *make_openflow_xid(size_t openflow_len, uint8_t type,
>                         uint32_t xid, struct ofpbuf **);
> +void *make_nxmsg_xid(size_t openflow_len, uint32_t subtype, uint32_t xid,
> +                     struct ofpbuf **);
> void *put_openflow(size_t openflow_len, uint8_t type, struct ofpbuf *);
> void *put_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
>                        struct ofpbuf *);
> diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
> index ac91b41..8422786 100644
> --- a/ofproto/ofproto.c
> +++ b/ofproto/ofproto.c
> @@ -3956,10 +3956,8 @@ handle_role_request(struct ofproto *ofproto,
>     }
>     ofconn->role = role;
> 
> -    reply = make_openflow_xid(sizeof *reply, OFPT_VENDOR, msg->header.xid,
> -                              &buf);
> -    reply->nxh.vendor = htonl(NX_VENDOR_ID);
> -    reply->nxh.subtype = htonl(NXT_ROLE_REPLY);
> +    reply = make_nxmsg_xid(sizeof *reply, NXT_ROLE_REPLY, msg->header.xid,
> +                           &buf);
>     reply->role = htonl(role);
>     queue_tx(buf, ofconn, ofconn->reply_counter);
> 
> diff --git a/ofproto/status.c b/ofproto/status.c
> index 27db498..b5bc33a 100644
> --- a/ofproto/status.c
> +++ b/ofproto/status.c
> @@ -77,10 +77,8 @@ switch_status_handle_request(struct switch_status *ss, struct rconn *rconn,
>             c->cb(&sr, c->aux);
>         }
>     }
> -    reply = make_openflow_xid(sizeof *reply + sr.output.length,
> -                              OFPT_VENDOR, request->header.xid, &b);
> -    reply->vendor = htonl(NX_VENDOR_ID);
> -    reply->subtype = htonl(NXT_STATUS_REPLY);
> +    reply = make_nxmsg_xid(sizeof *reply + sr.output.length,
> +                           NXT_STATUS_REPLY, request->header.xid, &b);
>     memcpy(reply + 1, sr.output.string, sr.output.length);
>     retval = rconn_send(rconn, b, NULL);
>     if (retval && retval != EAGAIN) {
> diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
> index 553a773..85ef3c9 100644
> --- a/utilities/ovs-ofctl.c
> +++ b/utilities/ovs-ofctl.c
> @@ -354,9 +354,7 @@ do_status(int argc, char *argv[])
>     struct vconn *vconn;
>     struct ofpbuf *b;
> 
> -    request = make_openflow(sizeof *request, OFPT_VENDOR, &b);
> -    request->vendor = htonl(NX_VENDOR_ID);
> -    request->subtype = htonl(NXT_STATUS_REQUEST);
> +    request = make_nxmsg(sizeof *request, NXT_STATUS_REQUEST, &b);
>     if (argc > 2) {
>         ofpbuf_put(b, argv[2], strlen(argv[2]));
>         update_openflow_length(b);
> @@ -610,10 +608,8 @@ do_tun_cookie(int argc OVS_UNUSED, char *argv[])
>     struct ofpbuf *buffer;
>     struct vconn *vconn;
> 
> -    tun_id_cookie = make_openflow(sizeof *tun_id_cookie, OFPT_VENDOR, &buffer);
> -
> -    tun_id_cookie->vendor = htonl(NX_VENDOR_ID);
> -    tun_id_cookie->subtype = htonl(NXT_TUN_ID_FROM_COOKIE);
> +    tun_id_cookie = make_nxmsg(sizeof *tun_id_cookie, NXT_TUN_ID_FROM_COOKIE,
> +                               &buffer);
>     tun_id_cookie->set = !strcmp(argv[2], "true");
> 
>     open_vconn(argv[1], &vconn);
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org





More information about the dev mailing list