[ovs-dev] [PATCH 04/19] Add oputil_of12_put_match()

Simon Horman horms at verge.net.au
Thu Jun 14 10:31:03 UTC 2012


On Thu, Jun 14, 2012 at 06:12:18PM +0900, Simon Horman wrote:
> On Wed, Jun 13, 2012 at 11:12:59PM -0700, Ben Pfaff wrote:
> > On Thu, Jun 14, 2012 at 08:51:52AM +0900, Simon Horman wrote:
> > > Signed-off-by: Simon Horman <horms at verge.net.au>
> > 
> > s/oputil/ofputil/
> > 
> > I'd be happier to have a more generic function: one that accepted a
> > "protocol" parameter and used the correct match type based on the
> > protocol.  Not a big deal to factor that in later, though, I guess.
> 
> Sure, something like the following?

Sorry, that was a bit bogus. I think the following is better.


commit 72f5a1a8326f754b7dbe34e70f25a6589b70ba46
Author: Simon Horman <horms at verge.net.au>
Date:   Fri Jun 8 19:29:32 2012 +0900

    Add ofputil_put_match()
    
    This wraps nx_put_match() to provide an extra header as necessary.
    
    For Open Flow 1.0 + NXM extensions nx_put_match() is comprises
    the entire match.
    
    For Open Flow 1.2 a header is required before
    the match supplied by x_put_match().
    
    Signed-off-by: Simon Horman <horms at verge.net.au>
    
    ---
    
    v2
    * First post

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 760ec85..756c0f8 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -1537,6 +1537,38 @@ ofputil_make_flow_mod_table_id(bool flow_mod_table_id)
     return msg;
 }
 
+static int
+ofputil_put_match(struct ofpbuf *msg, const struct cls_rule *cr,
+                  ovs_be64 cookie, ovs_be64 cookie_mask,
+                  enum ofputil_protocol protocol)
+{
+    int match_len;
+
+    switch (protocol) {
+    case OFPUTIL_P_OF10:
+    case OFPUTIL_P_OF10_TID:
+        NOT_REACHED();
+        break;
+
+    case OFPUTIL_P_NXM:
+    case OFPUTIL_P_NXM_TID:
+        match_len = nx_put_match(msg, false, cr, cookie, cookie_mask);
+        break;
+
+    case OFPUTIL_P_OF12: {
+        struct ofp11_match_header *omh = ofpbuf_put_uninit(msg, sizeof *omh);
+
+        match_len = nx_put_match(msg, true, cr, cookie, cookie_mask) +
+            sizeof *omh;
+        omh->type = htons(OFPMT_OXM);
+        omh->length = htons(match_len);
+        break;
+    }
+    }
+
+    return match_len;
+}
+
 /* Converts an OFPT_FLOW_MOD or NXT_FLOW_MOD message 'oh' into an abstract
  * flow_mod in 'fm'.  Returns 0 if successful, otherwise an OpenFlow error
  * code.
@@ -1728,8 +1760,8 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
         nfm = msg->data;
         nfm->command = htons(command);
         nfm->cookie = fm->new_cookie;
-        match_len = nx_put_match(msg, false, &fm->cr,
-                                 fm->cookie, fm->cookie_mask);
+        match_len = ofputil_put_match(msg, &fm->cr, fm->cookie,
+                                      fm->cookie_mask, OFPUTIL_P_NXM);
         nfm->idle_timeout = htons(fm->idle_timeout);
         nfm->hard_timeout = htons(fm->hard_timeout);
         nfm->priority = htons(fm->cr.priority);
@@ -1885,8 +1917,8 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
 
         subtype = fsr->aggregate ? NXST_AGGREGATE : NXST_FLOW;
         ofputil_make_stats_request(sizeof *nfsr, OFPST_VENDOR, subtype, &msg);
-        match_len = nx_put_match(msg, false, &fsr->match,
-                                 fsr->cookie, fsr->cookie_mask);
+        match_len = ofputil_put_match(msg, &fsr->match, fsr->cookie,
+                                      fsr->cookie_mask, OFPUTIL_P_NXM);
 
         nfsr = ofputil_stats_msg_body(msg->data);
         nfsr->out_port = htons(fsr->out_port);
@@ -2107,7 +2139,8 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs,
         nfs->hard_age = htons(fs->hard_age < 0 ? 0
                               : fs->hard_age < UINT16_MAX ? fs->hard_age + 1
                               : UINT16_MAX);
-        nfs->match_len = htons(nx_put_match(reply, false, &fs->rule, 0, 0));
+        nfs->match_len = htons(ofputil_put_match(reply, &fs->rule,
+                                                 0, 0, OFPUTIL_P_NXM));
         nfs->cookie = fs->cookie;
         nfs->packet_count = htonll(fs->packet_count);
         nfs->byte_count = htonll(fs->byte_count);



More information about the dev mailing list