ofproto: Move function find_meter() into ofpacts as ofpacts_get_meter().
authorBen Pfaff <blp@nicira.com>
Sat, 7 Sep 2013 02:52:14 +0000 (19:52 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 13 Sep 2013 00:43:05 +0000 (17:43 -0700)
ofproto is too big anyway so we might as well move out code that can
reasonably live elsewhere.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
lib/ofp-actions.c
lib/ofp-actions.h
ofproto/ofproto.c

index 77aa69c..54df17f 100644 (file)
@@ -2117,6 +2117,30 @@ ofpacts_equal(const struct ofpact *a, size_t a_len,
 {
     return a_len == b_len && !memcmp(a, b, a_len);
 }
+
+/* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
+ * 'ofpacts'.  If found, returns its meter ID; if not, returns 0.
+ *
+ * This function relies on the order of 'ofpacts' being correct (as checked by
+ * ofpacts_verify()). */
+uint32_t
+ofpacts_get_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
+{
+    const struct ofpact *a;
+
+    OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
+        enum ovs_instruction_type inst;
+
+        inst = ovs_instruction_type_from_ofpact_type(a->type);
+        if (a->type == OFPACT_METER) {
+            return ofpact_get_METER(a)->meter_id;
+        } else if (inst > OVSINST_OFPIT13_METER) {
+            break;
+        }
+    }
+
+    return 0;
+}
 \f
 /* Formatting ofpacts. */
 
index a3fb60f..0876ed7 100644 (file)
@@ -530,6 +530,7 @@ bool ofpacts_output_to_group(const struct ofpact[], size_t ofpacts_len,
                              uint32_t group_id);
 bool ofpacts_equal(const struct ofpact a[], size_t a_len,
                    const struct ofpact b[], size_t b_len);
+uint32_t ofpacts_get_meter(const struct ofpact[], size_t ofpacts_len);
 
 /* Formatting ofpacts.
  *
index 8cf6d9b..21faa97 100644 (file)
@@ -1762,7 +1762,7 @@ ofproto_add_flow(struct ofproto *ofproto, const struct match *match,
         fm.match = *match;
         fm.priority = priority;
         fm.buffer_id = UINT32_MAX;
-        fm.ofpacts = ofpacts;
+        fm.ofpacts = CONST_CAST(struct ofpact *, ofpacts);
         fm.ofpacts_len = ofpacts_len;
         add_flow(ofproto, NULL, &fm, NULL);
     }
@@ -2524,30 +2524,6 @@ reject_slave_controller(struct ofconn *ofconn)
     }
 }
 
-/* Finds the OFPACT_METER action, if any, in the 'ofpacts_len' bytes of
- * 'ofpacts'.  If found, returns its meter ID; if not, returns 0.
- *
- * This function relies on the order of 'ofpacts' being correct (as checked by
- * ofpacts_verify()). */
-static uint32_t
-find_meter(const struct ofpact ofpacts[], size_t ofpacts_len)
-{
-    const struct ofpact *a;
-
-    OFPACT_FOR_EACH (a, ofpacts, ofpacts_len) {
-        enum ovs_instruction_type inst;
-
-        inst = ovs_instruction_type_from_ofpact_type(a->type);
-        if (a->type == OFPACT_METER) {
-            return ofpact_get_METER(a)->meter_id;
-        } else if (inst > OVSINST_OFPIT13_METER) {
-            break;
-        }
-    }
-
-    return 0;
-}
-
 /* Checks that the 'ofpacts_len' bytes of actions in 'ofpacts' are appropriate
  * for a packet with the prerequisites satisfied by 'flow' in table 'table_id'.
  * 'flow' may be temporarily modified, but is restored at return.
@@ -2566,7 +2542,7 @@ ofproto_check_ofpacts(struct ofproto *ofproto,
         return error;
     }
 
-    mid = find_meter(ofpacts, ofpacts_len);
+    mid = ofpacts_get_meter(ofpacts, ofpacts_len);
     if (mid && ofproto_get_provider_meter_id(ofproto, mid) == UINT32_MAX) {
         return OFPERR_OFPMMFC_INVALID_METER;
     }
@@ -3654,7 +3630,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn,
 
     rule->ofpacts = xmemdup(fm->ofpacts, fm->ofpacts_len);
     rule->ofpacts_len = fm->ofpacts_len;
-    rule->meter_id = find_meter(rule->ofpacts, rule->ofpacts_len);
+    rule->meter_id = ofpacts_get_meter(rule->ofpacts, rule->ofpacts_len);
     list_init(&rule->meter_list_node);
     rule->eviction_group = NULL;
     list_init(&rule->expirable);
@@ -3760,7 +3736,8 @@ modify_flows__(struct ofproto *ofproto, struct ofconn *ofconn,
             rule->ofpacts_len = fm->ofpacts_len;
             ovs_rwlock_unlock(&rule->rwlock);
 
-            rule->meter_id = find_meter(rule->ofpacts, rule->ofpacts_len);
+            rule->meter_id = ofpacts_get_meter(rule->ofpacts,
+                                               rule->ofpacts_len);
             rule->ofproto->ofproto_class->rule_modify_actions(rule,
                                                               reset_counters);
         } else {