A set of ofpacts can only have one meter? What an odd API . . . At any rate this is fine.
Acked-by: Ethan Jackson <et...@nicira.com> On Tue, Sep 10, 2013 at 10:27 PM, Ben Pfaff <b...@nicira.com> wrote: > ofproto is too big anyway so we might as well move out code that can > reasonably live elsewhere. > > Signed-off-by: Ben Pfaff <b...@nicira.com> > --- > 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 77aa69c..54df17f 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 a3fb60f..0876ed7 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 b365866..410c2e5 100644 > --- a/ofproto/ofproto.c > +++ b/ofproto/ofproto.c > @@ -1727,7 +1727,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); > } > @@ -2489,30 +2489,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. > @@ -2531,7 +2507,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; > } > @@ -3557,7 +3533,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); > @@ -3664,7 +3640,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 { > -- > 1.7.10.4 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev