From d6fb622dcb9cb048b564621a73cf4165edc857ea Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 6 Sep 2013 19:52:14 -0700 Subject: [PATCH] ofproto: Move function find_meter() into ofpacts as ofpacts_get_meter(). ofproto is too big anyway so we might as well move out code that can reasonably live elsewhere. Signed-off-by: Ben Pfaff Acked-by: Ethan Jackson --- lib/ofp-actions.c | 24 ++++++++++++++++++++++++ lib/ofp-actions.h | 1 + ofproto/ofproto.c | 33 +++++---------------------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 77aa69cec..54df17ffe 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -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; +} /* Formatting ofpacts. */ diff --git a/lib/ofp-actions.h b/lib/ofp-actions.h index a3fb60f27..0876ed702 100644 --- a/lib/ofp-actions.h +++ b/lib/ofp-actions.h @@ -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. * diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 8cf6d9bca..21faa975d 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -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 { -- 2.43.0