From: Ben Pfaff Date: Sat, 7 Sep 2013 02:52:14 +0000 (-0700) Subject: ofproto: Move function find_meter() into ofpacts as ofpacts_get_meter(). X-Git-Tag: v2.0~47 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fovs.git;a=commitdiff_plain;h=8538bbb02a2cf2e56a623a9382840773c2c1e0aa 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 --- diff --git a/lib/ofp-actions.c b/lib/ofp-actions.c index 61e285429..69401bd24 100644 --- a/lib/ofp-actions.c +++ b/lib/ofp-actions.c @@ -2079,6 +2079,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 101c33dd1..de3b6fd9b 100644 --- a/lib/ofp-actions.h +++ b/lib/ofp-actions.h @@ -519,6 +519,7 @@ bool ofpacts_output_to_port(const struct ofpact[], size_t ofpacts_len, ofp_port_t port); 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 7cc9da30e..7f7e42df1 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -2505,30 +2505,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. @@ -2547,7 +2523,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; } @@ -3636,7 +3612,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn, rule->send_flow_removed = (fm->flags & OFPUTIL_FF_SEND_FLOW_REM) != 0; 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); @@ -3744,7 +3720,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 {