netdev: Abstract "features" interface away from OpenFlow 1.0.
[sliver-openvswitch.git] / lib / ofp-print.c
index f0c134f..c5312a3 100644 (file)
@@ -121,20 +121,8 @@ ofp_print_packet_in(struct ds *string, const struct ofp_header *oh,
         }
     }
 
-    switch (pin.reason) {
-    case OFPR_NO_MATCH:
-        ds_put_cstr(string, " (via no_match)");
-        break;
-    case OFPR_ACTION:
-        ds_put_cstr(string, " (via action)");
-        break;
-    case OFPR_INVALID_TTL:
-        ds_put_cstr(string, " (via invalid_ttl)");
-        break;
-    default:
-        ds_put_format(string, " (***reason %"PRIu8"***)", pin.reason);
-        break;
-    }
+    ds_put_format(string, " (via %s)",
+                  ofputil_packet_in_reason_to_string(pin.reason));
 
     ds_put_format(string, " data_len=%zu", pin.packet_len);
     if (pin.buffer_id == UINT32_MAX) {
@@ -188,6 +176,8 @@ ofp_print_action(struct ds *s, const union ofp_action *a,
     const struct nx_action_multipath *nam;
     const struct nx_action_autopath *naa;
     const struct nx_action_output_reg *naor;
+    const struct nx_action_fin_timeout *naft;
+    const struct nx_action_controller *nac;
     struct mf_subfield subfield;
     uint16_t port;
 
@@ -350,6 +340,38 @@ ofp_print_action(struct ds *s, const union ofp_action *a,
         ds_put_cstr(s, "exit");
         break;
 
+    case OFPUTIL_NXAST_FIN_TIMEOUT:
+        naft = (const struct nx_action_fin_timeout *) a;
+        ds_put_cstr(s, "fin_timeout(");
+        if (naft->fin_idle_timeout) {
+            ds_put_format(s, "idle_timeout=%"PRIu16",",
+                          ntohs(naft->fin_idle_timeout));
+        }
+        if (naft->fin_hard_timeout) {
+            ds_put_format(s, "hard_timeout=%"PRIu16",",
+                          ntohs(naft->fin_hard_timeout));
+        }
+        ds_chomp(s, ',');
+        ds_put_char(s, ')');
+        break;
+
+    case OFPUTIL_NXAST_CONTROLLER:
+        nac = (const struct nx_action_controller *) a;
+        ds_put_cstr(s, "controller(");
+        if (nac->reason != OFPR_ACTION) {
+            ds_put_format(s, "reason=%s,",
+                          ofputil_packet_in_reason_to_string(nac->reason));
+        }
+        if (nac->max_len != htons(UINT16_MAX)) {
+            ds_put_format(s, "max_len=%"PRIu16",", ntohs(nac->max_len));
+        }
+        if (nac->controller_id != htons(0)) {
+            ds_put_format(s, "id=%"PRIu16",", ntohs(nac->controller_id));
+        }
+        ds_chomp(s, ',');
+        ds_put_char(s, ')');
+        break;
+
     default:
         break;
     }
@@ -404,7 +426,7 @@ ofp_print_packet_out(struct ds *string, const struct ofp_packet_out *opo,
     ofp_print_actions(string, po.actions, po.n_actions);
 
     if (po.buffer_id == UINT32_MAX) {
-        ds_put_format(string, " data_len=%d", po.packet_len);
+        ds_put_format(string, " data_len=%zu", po.packet_len);
         if (verbosity > 0 && po.packet_len > 0) {
             char *packet = ofp_packet_to_string(po.packet, po.packet_len);
             ds_put_char(string, '\n');
@@ -762,7 +784,7 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header *oh,
     bool need_priority;
     enum ofperr error;
 
-    error = ofputil_decode_flow_mod(&fm, oh, true);
+    error = ofputil_decode_flow_mod(&fm, oh, OFPUTIL_P_OF10_TID);
     if (error) {
         ofp_print_error(s, error);
         return;
@@ -870,6 +892,24 @@ ofp_print_duration(struct ds *string, unsigned int sec, unsigned int nsec)
     ds_put_char(string, 's');
 }
 
+static const char *
+ofp_flow_removed_reason_to_string(enum ofp_flow_removed_reason reason)
+{
+    static char s[32];
+
+    switch (reason) {
+    case OFPRR_IDLE_TIMEOUT:
+        return "idle";
+    case OFPRR_HARD_TIMEOUT:
+        return "hard";
+    case OFPRR_DELETE:
+        return "delete";
+    default:
+        sprintf(s, "%d", (int) reason);
+        return s;
+    }
+}
+
 static void
 ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
 {
@@ -885,21 +925,8 @@ ofp_print_flow_removed(struct ds *string, const struct ofp_header *oh)
     ds_put_char(string, ' ');
     cls_rule_format(&fr.rule, string);
 
-    ds_put_cstr(string, " reason=");
-    switch (fr.reason) {
-    case OFPRR_IDLE_TIMEOUT:
-        ds_put_cstr(string, "idle");
-        break;
-    case OFPRR_HARD_TIMEOUT:
-        ds_put_cstr(string, "hard");
-        break;
-    case OFPRR_DELETE:
-        ds_put_cstr(string, "delete");
-        break;
-    default:
-        ds_put_format(string, "**%"PRIu8"**", fr.reason);
-        break;
-    }
+    ds_put_format(string, " reason=%s",
+                  ofp_flow_removed_reason_to_string(fr.reason));
 
     if (fr.cookie != htonll(0)) {
         ds_put_format(string, " cookie:0x%"PRIx64, ntohll(fr.cookie));
@@ -1292,8 +1319,8 @@ ofp_print_nxt_set_flow_format(struct ds *string,
     uint32_t format = ntohl(nsff->format);
 
     ds_put_cstr(string, " format=");
-    if (ofputil_flow_format_is_valid(format)) {
-        ds_put_cstr(string, ofputil_flow_format_to_string(format));
+    if (ofputil_nx_flow_format_is_valid(format)) {
+        ds_put_cstr(string, ofputil_nx_flow_format_to_string(format));
     } else {
         ds_put_format(string, "%"PRIu32, format);
     }
@@ -1313,6 +1340,82 @@ ofp_print_nxt_set_packet_in_format(struct ds *string,
     }
 }
 
+static const char *
+ofp_port_reason_to_string(enum ofp_port_reason reason)
+{
+    static char s[32];
+
+    switch (reason) {
+    case OFPPR_ADD:
+        return "add";
+
+    case OFPPR_DELETE:
+        return "delete";
+
+    case OFPPR_MODIFY:
+        return "modify";
+
+    default:
+        sprintf(s, "%d", (int) reason);
+        return s;
+    }
+}
+
+static void
+ofp_print_nxt_set_async_config(struct ds *string,
+                               const struct nx_async_config *nac)
+{
+    int i;
+
+    for (i = 0; i < 2; i++) {
+        int j;
+
+        ds_put_format(string, "\n %s:\n", i == 0 ? "master" : "slave");
+
+        ds_put_cstr(string, "       PACKET_IN:");
+        for (j = 0; j < 32; j++) {
+            if (nac->packet_in_mask[i] & htonl(1u << j)) {
+                ds_put_format(string, " %s",
+                              ofputil_packet_in_reason_to_string(j));
+            }
+        }
+        if (!nac->packet_in_mask[i]) {
+            ds_put_cstr(string, " (off)");
+        }
+        ds_put_char(string, '\n');
+
+        ds_put_cstr(string, "     PORT_STATUS:");
+        for (j = 0; j < 32; j++) {
+            if (nac->port_status_mask[i] & htonl(1u << j)) {
+                ds_put_format(string, " %s", ofp_port_reason_to_string(j));
+            }
+        }
+        if (!nac->port_status_mask[i]) {
+            ds_put_cstr(string, " (off)");
+        }
+        ds_put_char(string, '\n');
+
+        ds_put_cstr(string, "    FLOW_REMOVED:");
+        for (j = 0; j < 32; j++) {
+            if (nac->flow_removed_mask[i] & htonl(1u << j)) {
+                ds_put_format(string, " %s",
+                              ofp_flow_removed_reason_to_string(j));
+            }
+        }
+        if (!nac->flow_removed_mask[i]) {
+            ds_put_cstr(string, " (off)");
+        }
+        ds_put_char(string, '\n');
+    }
+}
+
+static void
+ofp_print_nxt_set_controller_id(struct ds *string,
+                                const struct nx_controller_id *nci)
+{
+    ds_put_format(string, " id=%"PRIu16, ntohs(nci->controller_id));
+}
+
 static void
 ofp_to_string__(const struct ofp_header *oh,
                 const struct ofputil_msg_type *type, struct ds *string,
@@ -1321,8 +1424,18 @@ ofp_to_string__(const struct ofp_header *oh,
     enum ofputil_msg_code code;
     const void *msg = oh;
 
-    ds_put_format(string, "%s (xid=0x%"PRIx32"):",
-                  ofputil_msg_type_name(type), ntohl(oh->xid));
+    ds_put_cstr(string, ofputil_msg_type_name(type));
+    switch (oh->version) {
+    case OFP10_VERSION:
+        break;
+    case OFP11_VERSION:
+        ds_put_cstr(string, " (OF1.1)");
+        break;
+    default:
+        ds_put_format(string, " (OF 0x%02"PRIx8")", oh->version);
+        break;
+    }
+    ds_put_format(string, " (xid=0x%"PRIx32"):", ntohl(oh->xid));
 
     code = ofputil_msg_type_code(type);
     switch (code) {
@@ -1472,6 +1585,14 @@ ofp_to_string__(const struct ofp_header *oh,
     case OFPUTIL_NXT_FLOW_AGE:
         break;
 
+    case OFPUTIL_NXT_SET_CONTROLLER_ID:
+        ofp_print_nxt_set_controller_id(string, msg);
+        break;
+
+    case OFPUTIL_NXT_SET_ASYNC_CONFIG:
+        ofp_print_nxt_set_async_config(string, msg);
+        break;
+
     case OFPUTIL_NXST_AGGREGATE_REPLY:
         ofp_print_stats_reply(string, oh);
         ofp_print_nxst_aggregate_reply(string, msg);
@@ -1526,91 +1647,6 @@ ofp_to_string(const void *oh_, size_t len, int verbosity)
     ds_put_hex_dump(&string, oh, len, 0, true);
     return ds_steal_cstr(&string);
 }
-
-/* Returns the name for the specified OpenFlow message type as a string,
- * e.g. "OFPT_FEATURES_REPLY".  If no name is known, the string returned is a
- * hex number, e.g. "0x55".
- *
- * The caller must free the returned string when it is no longer needed. */
-char *
-ofp_message_type_to_string(uint8_t type)
-{
-    const char *name;
-
-    switch (type) {
-    case OFPT_HELLO:
-        name = "HELLO";
-        break;
-    case OFPT_ERROR:
-        name = "ERROR";
-        break;
-    case OFPT_ECHO_REQUEST:
-        name = "ECHO_REQUEST";
-        break;
-    case OFPT_ECHO_REPLY:
-        name = "ECHO_REPLY";
-        break;
-    case OFPT_VENDOR:
-        name = "VENDOR";
-        break;
-    case OFPT_FEATURES_REQUEST:
-        name = "FEATURES_REQUEST";
-        break;
-    case OFPT_FEATURES_REPLY:
-        name = "FEATURES_REPLY";
-        break;
-    case OFPT_GET_CONFIG_REQUEST:
-        name = "GET_CONFIG_REQUEST";
-        break;
-    case OFPT_GET_CONFIG_REPLY:
-        name = "GET_CONFIG_REPLY";
-        break;
-    case OFPT_SET_CONFIG:
-        name = "SET_CONFIG";
-        break;
-    case OFPT_PACKET_IN:
-        name = "PACKET_IN";
-        break;
-    case OFPT_FLOW_REMOVED:
-        name = "FLOW_REMOVED";
-        break;
-    case OFPT_PORT_STATUS:
-        name = "PORT_STATUS";
-        break;
-    case OFPT_PACKET_OUT:
-        name = "PACKET_OUT";
-        break;
-    case OFPT_FLOW_MOD:
-        name = "FLOW_MOD";
-        break;
-    case OFPT_PORT_MOD:
-        name = "PORT_MOD";
-        break;
-    case OFPT_STATS_REQUEST:
-        name = "STATS_REQUEST";
-        break;
-    case OFPT_STATS_REPLY:
-        name = "STATS_REPLY";
-        break;
-    case OFPT_BARRIER_REQUEST:
-        name = "BARRIER_REQUEST";
-        break;
-    case OFPT_BARRIER_REPLY:
-        name = "BARRIER_REPLY";
-        break;
-    case OFPT_QUEUE_GET_CONFIG_REQUEST:
-        name = "QUEUE_GET_CONFIG_REQUEST";
-        break;
-    case OFPT_QUEUE_GET_CONFIG_REPLY:
-        name = "QUEUE_GET_CONFIG_REPLY";
-        break;
-    default:
-        name = NULL;
-        break;
-    }
-
-    return name ? xasprintf("OFPT_%s", name) : xasprintf("0x%02"PRIx8, type);
-}
 \f
 static void
 print_and_free(FILE *stream, char *string)