simap: New data structure for string-to-integer maps.
[openvswitch] / lib / ofp-util.c
index 69e2b175ed38df1814a25bd61cf77575f02f736b..90124ec86af0104bda224608d142f7ab22c44423 100644 (file)
@@ -1461,10 +1461,7 @@ ofputil_decode_flow_mod(struct ofputil_flow_mod *fm,
 }
 
 /* Converts 'fm' into an OFPT_FLOW_MOD or NXT_FLOW_MOD message according to
- * 'protocol' and returns the message.
- *
- * 'flow_mod_table_id' should be true if the NXT_FLOW_MOD_TABLE_ID extension is
- * enabled, false otherwise. */
+ * 'protocol' and returns the message. */
 struct ofpbuf *
 ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
                         enum ofputil_protocol protocol)
@@ -2371,6 +2368,13 @@ ofputil_decode_ofp11_port(struct ofputil_phy_port *pp,
     return 0;
 }
 
+static size_t
+ofputil_get_phy_port_size(uint8_t ofp_version)
+{
+    return ofp_version == OFP10_VERSION ? sizeof(struct ofp10_phy_port)
+                                        : sizeof(struct ofp11_port);
+}
+
 static void
 ofputil_encode_ofp10_phy_port(const struct ofputil_phy_port *pp,
                               struct ofp10_phy_port *opp)
@@ -2543,20 +2547,17 @@ ofputil_decode_switch_features(const struct ofp_switch_features *osf,
     features->n_tables = osf->n_tables;
 
     features->capabilities = ntohl(osf->capabilities) & OFPC_COMMON;
-    if (osf->header.version == OFP10_VERSION) {
-        if (b->size % sizeof(struct ofp10_phy_port)) {
-            return OFPERR_OFPBRC_BAD_LEN;
-        }
 
+    if (b->size % ofputil_get_phy_port_size(osf->header.version)) {
+        return OFPERR_OFPBRC_BAD_LEN;
+    }
+
+    if (osf->header.version == OFP10_VERSION) {
         if (osf->capabilities & htonl(OFPC10_STP)) {
             features->capabilities |= OFPUTIL_C_STP;
         }
         features->actions = decode_action_bits(osf->actions, of10_action_bits);
     } else if (osf->header.version == OFP11_VERSION) {
-        if (b->size % sizeof(struct ofp11_port)) {
-            return OFPERR_OFPBRC_BAD_LEN;
-        }
-
         if (osf->capabilities & htonl(OFPC11_GROUP_STATS)) {
             features->capabilities |= OFPUTIL_C_GROUP_STATS;
         }
@@ -2572,10 +2573,7 @@ ofputil_decode_switch_features(const struct ofp_switch_features *osf,
 static bool
 max_ports_in_features(const struct ofp_switch_features *osf)
 {
-    size_t pp_size = osf->header.version == OFP10_VERSION ?
-                        sizeof(struct ofp10_phy_port) :
-                        sizeof(struct ofp11_port);
-
+    size_t pp_size = ofputil_get_phy_port_size(osf->header.version);
     return ntohs(osf->header.length) + pp_size > UINT16_MAX;
 }
 
@@ -3308,6 +3306,7 @@ ofputil_check_output_port(uint16_t port, int max_ports)
     case OFPP_FLOOD:
     case OFPP_ALL:
     case OFPP_CONTROLLER:
+    case OFPP_NONE:
     case OFPP_LOCAL:
         return 0;
 
@@ -3403,9 +3402,7 @@ ofputil_pull_phy_port(uint8_t ofp_version, struct ofpbuf *b,
  * 'ofp_version', returns the number of elements. */
 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *b)
 {
-    return (ofp_version == OFP10_VERSION
-            ? b->size / sizeof(struct ofp10_phy_port)
-            : b->size / sizeof(struct ofp11_port));
+    return b->size / ofputil_get_phy_port_size(ofp_version);
 }
 
 static enum ofperr
@@ -3761,11 +3758,13 @@ ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf)
 bool
 action_outputs_to_port(const union ofp_action *action, ovs_be16 port)
 {
-    switch (ntohs(action->type)) {
-    case OFPAT10_OUTPUT:
+    switch (ofputil_decode_action(action)) {
+    case OFPUTIL_OFPAT10_OUTPUT:
         return action->output.port == port;
-    case OFPAT10_ENQUEUE:
+    case OFPUTIL_OFPAT10_ENQUEUE:
         return ((const struct ofp_action_enqueue *) action)->port == port;
+    case OFPUTIL_NXAST_CONTROLLER:
+        return port == htons(OFPP_CONTROLLER);
     default:
         return false;
     }