Switch to using enum ofp14_flow_update_event instead of
enum nx_flow_update_event in struct ofputil_flow_update as
the former can encode all values defined for the latter but
the reverse is not true.

Also use switch rather than if when testing event values
to give a little bit of extra type checking.

This is in preparation for supporting OpenFlow 1.4 flow monitor replies.

Signed-off-by: Simon Horman <ho...@verge.net.au>

---
v3
* Rebase

v2
* No change
---
 lib/ofp-print.c   |  14 +++++--
 lib/ofp-util.c    | 107 +++++++++++++++++++++++++++++++++++++++++++++++-------
 lib/ofp-util.h    |   2 +-
 ofproto/connmgr.c |  19 ++++++----
 ofproto/connmgr.h |   3 +-
 ofproto/ofproto.c |  19 ++++++----
 6 files changed, 130 insertions(+), 34 deletions(-)

diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 40eb16d..3d3fa0b 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -2304,24 +2304,30 @@ ofp_print_nxst_flow_monitor_reply(struct ds *string,
 
         ds_put_cstr(string, "\n event=");
         switch (update.event) {
-        case NXFME_ADDED:
+        case OFPFME14_ADDED:
             ds_put_cstr(string, "ADDED");
             break;
 
-        case NXFME_DELETED:
+        case OFPFME14_REMOVED:
             ds_put_format(string, "DELETED reason=%s",
                           ofp_flow_removed_reason_to_string(update.reason,
                                                             reasonbuf,
                                                             sizeof reasonbuf));
             break;
 
-        case NXFME_MODIFIED:
+        case OFPFME14_MODIFIED:
             ds_put_cstr(string, "MODIFIED");
             break;
 
-        case NXFME_ABBREV:
+        case OFPFME14_ABBREV:
             ds_put_format(string, "ABBREV xid=0x%"PRIx32, ntohl(update.xid));
             continue;
+
+        case OFPFME14_INITIAL:
+        case OFPFME14_PAUSED:
+        case OFPFME14_RESUMED:
+        default:
+            OVS_NOT_REACHED();
         }
 
         ds_put_format(string, " table=%"PRIu8, update.table_id);
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 2c3bb0e..7296d89 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -5429,6 +5429,57 @@ ofputil_append_flow_monitor_request(
     }
 }
 
+static enum ofperr
+nx_to_ofp14_flow_update_event(enum nx_flow_update_event nx_event,
+                              enum ofp14_flow_update_event *ofp_event)
+{
+    switch (nx_event) {
+    case NXFME_ADDED:
+        *ofp_event = OFPFME14_ADDED;
+        break;
+    case NXFME_DELETED:
+        *ofp_event = OFPFME14_REMOVED;
+        break;
+    case NXFME_MODIFIED:
+        *ofp_event = OFPFME14_MODIFIED;
+        break;
+    case NXFME_ABBREV:
+        *ofp_event = OFPFME14_ABBREV;
+        break;
+    default:
+        return OFPERR_NXBRC_FM_BAD_EVENT;
+    }
+
+    return 0;
+}
+
+static enum ofperr
+nx_from_ofp14_flow_update_event(enum ofp14_flow_update_event ofp_event,
+                                enum nx_flow_update_event *nx_event)
+{
+    switch (ofp_event) {
+    case OFPFME14_INITIAL:
+    case OFPFME14_ADDED:
+        *nx_event = NXFME_ADDED;
+        break;
+    case OFPFME14_REMOVED:
+        *nx_event = NXFME_DELETED;
+        break;
+    case OFPFME14_MODIFIED:
+        *nx_event = NXFME_MODIFIED;
+        break;
+    case OFPFME14_ABBREV:
+        *nx_event = NXFME_ABBREV;
+        break;
+    case OFPFME14_PAUSED:
+    case OFPFME14_RESUMED:
+    default:
+        return OFPERR_NXBRC_FM_BAD_EVENT;
+    }
+
+    return 0;
+}
+
 /* Converts an NXST_FLOW_MONITOR reply (also known as a flow update) in 'msg'
  * into an abstract ofputil_flow_update in 'update'.  The caller must have
  * initialized update->match to point to space allocated for a match.
@@ -5450,8 +5501,10 @@ ofputil_decode_flow_update(struct ofputil_flow_update 
*update,
                            struct ofpbuf *msg, struct ofpbuf *ofpacts)
 {
     struct nx_flow_update_header *nfuh;
+    enum nx_flow_update_event nevent;
     unsigned int length;
     struct ofp_header *oh;
+    enum ofperr error;
 
     if (!msg->frame) {
         ofpraw_pull_assert(msg);
@@ -5468,13 +5521,22 @@ ofputil_decode_flow_update(struct ofputil_flow_update 
*update,
     oh = msg->frame;
 
     nfuh = ofpbuf_data(msg);
-    update->event = ntohs(nfuh->event);
+    nevent = ntohs(nfuh->event);
     length = ntohs(nfuh->length);
     if (length > ofpbuf_size(msg) || length % 8) {
         goto bad_len;
     }
 
-    if (update->event == NXFME_ABBREV) {
+    error = nx_to_ofp14_flow_update_event(nevent, &update->event);
+    if (error) {
+        VLOG_WARN_RL(&bad_ofmsg_rl,
+                     "NXST_FLOW_MONITOR reply has bad event %"PRIu16,
+                     ntohs(nfuh->event));
+        return error;
+    }
+
+    switch (update->event) {
+    case OFPFME14_ABBREV: {
         struct nx_flow_update_abbrev *nfua;
 
         if (length != sizeof *nfua) {
@@ -5484,9 +5546,10 @@ ofputil_decode_flow_update(struct ofputil_flow_update 
*update,
         nfua = ofpbuf_pull(msg, sizeof *nfua);
         update->xid = nfua->xid;
         return 0;
-    } else if (update->event == NXFME_ADDED
-               || update->event == NXFME_DELETED
-               || update->event == NXFME_MODIFIED) {
+    }
+    case OFPFME14_ADDED:
+    case OFPFME14_REMOVED:
+    case OFPFME14_MODIFIED: {
         struct nx_flow_update_full *nfuf;
         unsigned int actions_len;
         unsigned int match_len;
@@ -5524,11 +5587,12 @@ ofputil_decode_flow_update(struct ofputil_flow_update 
*update,
         update->ofpacts = ofpbuf_data(ofpacts);
         update->ofpacts_len = ofpbuf_size(ofpacts);
         return 0;
-    } else {
-        VLOG_WARN_RL(&bad_ofmsg_rl,
-                     "NXST_FLOW_MONITOR reply has bad event %"PRIu16,
-                     ntohs(nfuh->event));
-        return OFPERR_NXBRC_FM_BAD_EVENT;
+    }
+    case OFPFME14_INITIAL:
+    case OFPFME14_PAUSED:
+    case OFPFME14_RESUMED:
+    default:
+        OVS_NOT_REACHED();
     }
 
 bad_len:
@@ -5575,18 +5639,25 @@ ofputil_append_flow_update(const struct 
ofputil_flow_update *update,
 {
     enum ofp_version version = ofpmp_version(replies);
     struct nx_flow_update_header *nfuh;
+    enum nx_flow_update_event nevent;
     struct ofpbuf *msg;
     size_t start_ofs;
 
     msg = ofpbuf_from_list(list_back(replies));
     start_ofs = ofpbuf_size(msg);
 
-    if (update->event == NXFME_ABBREV) {
+    switch(update->event) {
+    case OFPFME14_ABBREV: {
         struct nx_flow_update_abbrev *nfua;
 
         nfua = ofpbuf_put_zeros(msg, sizeof *nfua);
         nfua->xid = update->xid;
-    } else {
+        break;
+    }
+    case OFPFME14_INITIAL:
+    case OFPFME14_ADDED:
+    case OFPFME14_REMOVED:
+    case OFPFME14_MODIFIED: {
         struct nx_flow_update_full *nfuf;
         int match_len;
 
@@ -5602,11 +5673,21 @@ ofputil_append_flow_update(const struct 
ofputil_flow_update *update,
         nfuf->match_len = htons(match_len);
         nfuf->table_id = update->table_id;
         nfuf->cookie = update->cookie;
+        break;
+    }
+    case OFPFME14_PAUSED:
+    case OFPFME14_RESUMED:
+    default:
+       OVS_NOT_REACHED();
     }
 
     nfuh = ofpbuf_at_assert(msg, start_ofs, sizeof *nfuh);
     nfuh->length = htons(ofpbuf_size(msg) - start_ofs);
-    nfuh->event = htons(update->event);
+
+    if (nx_from_ofp14_flow_update_event(update->event, &nevent)) {
+        OVS_NOT_REACHED();
+    }
+    nfuh->event = htons(nevent);
 
     ofpmp_postappend(replies, start_ofs);
 }
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 899f38d..ef0c33e 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -858,7 +858,7 @@ void ofputil_append_flow_monitor_request(
 
 /* Abstract nx_flow_update. */
 struct ofputil_flow_update {
-    enum nx_flow_update_event event;
+    enum ofp14_flow_update_event event;
 
     /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
     enum ofp_flow_removed_reason reason;
diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c
index 05ff4ce..a173456 100644
--- a/ofproto/connmgr.c
+++ b/ofproto/connmgr.c
@@ -2069,7 +2069,7 @@ ofmonitor_destroy(struct ofmonitor *m)
 
 void
 ofmonitor_report(struct connmgr *mgr, struct rule *rule,
-                 enum nx_flow_update_event event,
+                 enum ofp14_flow_update_event event,
                  enum ofp_flow_removed_reason reason,
                  const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid,
                  const struct rule_actions *old_actions)
@@ -2083,22 +2083,25 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule,
     }
 
     switch (event) {
-    case NXFME_ADDED:
+    case OFPFME14_ADDED:
         update = OFPFMF14_ADD;
         rule->add_seqno = rule->modify_seqno = monitor_seqno++;
         break;
 
-    case NXFME_DELETED:
+    case OFPFME14_REMOVED:
         update = OFPFMF14_REMOVED;
         break;
 
-    case NXFME_MODIFIED:
+    case OFPFME14_MODIFIED:
         update = OFPFMF14_MODIFY;
         rule->modify_seqno = monitor_seqno++;
         break;
 
     default:
-    case NXFME_ABBREV:
+    case OFPFME14_INITIAL:
+    case OFPFME14_ABBREV:
+    case OFPFME14_PAUSED:
+    case OFPFME14_RESUMED:
         OVS_NOT_REACHED();
     }
 
@@ -2109,7 +2112,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule,
         if (ofconn->monitor_paused) {
             /* Only send NXFME_DELETED notifications for flows that were added
              * before we paused. */
-            if (event != NXFME_DELETED
+            if (event != OFPFME14_REMOVED
                 || rule->add_seqno > ofconn->monitor_paused) {
                 continue;
             }
@@ -2146,7 +2149,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule,
                 struct match match;
 
                 fu.event = event;
-                fu.reason = event == NXFME_DELETED ? reason : 0;
+                fu.reason = event == OFPFME14_REMOVED ? reason : 0;
                 fu.table_id = rule->table_id;
                 fu.cookie = rule->flow_cookie;
                 minimatch_expand(&rule->cr.match, &match);
@@ -2170,7 +2173,7 @@ ofmonitor_report(struct connmgr *mgr, struct rule *rule,
             } else if (!ofconn->sent_abbrev_update) {
                 struct ofputil_flow_update fu;
 
-                fu.event = NXFME_ABBREV;
+                fu.event = OFPFME14_ABBREV;
                 fu.xid = abbrev_xid;
                 ofputil_append_flow_update(&fu, &ofconn->updates);
 
diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h
index fc6afbd..07ec9e4 100644
--- a/ofproto/connmgr.h
+++ b/ofproto/connmgr.h
@@ -222,7 +222,8 @@ void ofmonitor_destroy(struct ofmonitor *)
     OVS_REQUIRES(ofproto_mutex);
 
 void ofmonitor_report(struct connmgr *, struct rule *,
-                      enum nx_flow_update_event, enum ofp_flow_removed_reason,
+                      enum ofp14_flow_update_event,
+                      enum ofp_flow_removed_reason,
                       const struct ofconn *abbrev_ofconn, ovs_be32 abbrev_xid,
                       const struct rule_actions *old_actions)
     OVS_REQUIRES(ofproto_mutex);
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 211f45e..8de552f 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -4098,7 +4098,7 @@ add_flow(struct ofproto *ofproto, struct ofputil_flow_mod 
*fm,
         }
     }
 
-    ofmonitor_report(ofproto->connmgr, rule, NXFME_ADDED, 0,
+    ofmonitor_report(ofproto->connmgr, rule, OFPFME14_ADDED, 0,
                      req ? req->ofconn : NULL, req ? req->xid : 0, NULL);
 
     return req ? send_buffered_packet(req->ofconn, fm->buffer_id, rule) : 0;
@@ -4120,7 +4120,7 @@ modify_flows__(struct ofproto *ofproto, struct 
ofputil_flow_mod *fm,
     OVS_REQUIRES(ofproto_mutex)
 {
     struct list dead_cookies = LIST_INITIALIZER(&dead_cookies);
-    enum nx_flow_update_event event;
+    enum ofp14_flow_update_event event;
     size_t i;
 
     if (ofproto->ofproto_class->rule_premodify_actions) {
@@ -4136,7 +4136,7 @@ modify_flows__(struct ofproto *ofproto, struct 
ofputil_flow_mod *fm,
         }
     }
 
-    event = fm->command == OFPFC_ADD ? NXFME_ADDED : NXFME_MODIFIED;
+    event = fm->command == OFPFC_ADD ? OFPFME14_ADDED : OFPFME14_MODIFIED;
     for (i = 0; i < rules->n; i++) {
         struct rule *rule = rules->rules[i];
 
@@ -4195,7 +4195,7 @@ modify_flows__(struct ofproto *ofproto, struct 
ofputil_flow_mod *fm,
             ofproto->ofproto_class->rule_modify_actions(rule, reset_counters);
         }
 
-        if (event != NXFME_MODIFIED || change_actions || change_cookie) {
+        if (event != OFPFME14_MODIFIED || change_actions || change_cookie) {
             ofmonitor_report(ofproto->connmgr, rule, event, 0,
                              req ? req->ofconn : NULL, req ? req->xid : 0,
                              change_actions ? actions : NULL);
@@ -4311,7 +4311,7 @@ delete_flows__(const struct rule_collection *rules,
 
             ofproto_rule_send_removed(rule, reason);
 
-            ofmonitor_report(ofproto->connmgr, rule, NXFME_DELETED, reason,
+            ofmonitor_report(ofproto->connmgr, rule, OFPFME14_REMOVED, reason,
                              req ? req->ofconn : NULL, req ? req->xid : 0,
                              NULL);
             oftable_remove_rule(rule);
@@ -4707,8 +4707,13 @@ ofproto_compose_flow_refresh_update(const struct rule 
*rule,
     struct ofputil_flow_update fu;
     struct match match;
 
-    fu.event = (flags & (OFPFMF14_INITIAL | OFPFMF14_ADD)
-                ? NXFME_ADDED : NXFME_MODIFIED);
+    if (flags & OFPFMF14_INITIAL) {
+        fu.event = OFPFME14_INITIAL;
+    } else if (flags & OFPFMF14_ADD) {
+        fu.event = OFPFME14_ADDED;
+    } else {
+        fu.event = OFPFME14_MODIFIED;
+    }
     fu.reason = 0;
     ovs_mutex_lock(&rule->mutex);
     fu.idle_timeout = rule->idle_timeout;
-- 
2.0.0.rc2

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to