Looks good, Ethan
On Tue, Feb 7, 2012 at 15:06, Ben Pfaff <[email protected]> wrote: > Upcoming commits add a user for ofputil_packet_in_reason_from_string() > and more users for ofputil_packet_in_reason_to_string(). > > Signed-off-by: Ben Pfaff <[email protected]> > --- > lib/ofp-print.c | 22 ++-------------------- > lib/ofp-util.c | 35 +++++++++++++++++++++++++++++++++++ > lib/ofp-util.h | 4 ++++ > 3 files changed, 41 insertions(+), 20 deletions(-) > > diff --git a/lib/ofp-print.c b/lib/ofp-print.c > index 1e36662..ae7ed08 100644 > --- a/lib/ofp-print.c > +++ b/lib/ofp-print.c > @@ -80,24 +80,6 @@ ofp_packet_to_string(const void *data, size_t len) > return ds_cstr(&ds); > } > > -static const char * > -ofp_packet_in_reason_to_string(enum ofp_packet_in_reason reason) > -{ > - static char s[32]; > - > - switch (reason) { > - case OFPR_NO_MATCH: > - return "no_match"; > - case OFPR_ACTION: > - return "action"; > - case OFPR_INVALID_TTL: > - return "invalid_ttl"; > - default: > - sprintf(s, "%d", (int) reason); > - return s; > - } > -} > - > static void > ofp_print_packet_in(struct ds *string, const struct ofp_header *oh, > int verbosity) > @@ -140,7 +122,7 @@ ofp_print_packet_in(struct ds *string, const struct > ofp_header *oh, > } > > ds_put_format(string, " (via %s)", > - ofp_packet_in_reason_to_string(pin.reason)); > + ofputil_packet_in_reason_to_string(pin.reason)); > > ds_put_format(string, " data_len=%zu", pin.packet_len); > if (pin.buffer_id == UINT32_MAX) { > @@ -1354,7 +1336,7 @@ ofp_print_nxt_set_async_config(struct ds *string, > for (j = 0; j < 32; j++) { > if (nac->packet_in_mask[i] & htonl(1u << j)) { > ds_put_format(string, " %s", > - ofp_packet_in_reason_to_string(j)); > + ofputil_packet_in_reason_to_string(j)); > } > } > if (!nac->packet_in_mask[i]) { > diff --git a/lib/ofp-util.c b/lib/ofp-util.c > index 53b5af1..704823a 100644 > --- a/lib/ofp-util.c > +++ b/lib/ofp-util.c > @@ -1756,6 +1756,41 @@ ofputil_encode_packet_in(const struct > ofputil_packet_in *pin, > return packet; > } > > +const char * > +ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason reason) > +{ > + static char s[INT_STRLEN(int) + 1]; > + > + switch (reason) { > + case OFPR_NO_MATCH: > + return "no_match"; > + case OFPR_ACTION: > + return "action"; > + case OFPR_INVALID_TTL: > + return "invalid_ttl"; > + > + case OFPR_N_REASONS: > + default: > + sprintf(s, "%d", (int) reason); > + return s; > + } > +} > + > +bool > +ofputil_packet_in_reason_from_string(const char *s, > + enum ofp_packet_in_reason *reason) > +{ > + int i; > + > + for (i = 0; i < OFPR_N_REASONS; i++) { > + if (!strcasecmp(s, ofputil_packet_in_reason_to_string(i))) { > + *reason = i; > + return true; > + } > + } > + return false; > +} > + > enum ofperr > ofputil_decode_packet_out(struct ofputil_packet_out *po, > const struct ofp_packet_out *opo) > diff --git a/lib/ofp-util.h b/lib/ofp-util.h > index 72abd0b..0ca1d99 100644 > --- a/lib/ofp-util.h > +++ b/lib/ofp-util.h > @@ -246,6 +246,10 @@ struct ofpbuf *ofputil_encode_packet_in(const struct > ofputil_packet_in *, > int ofputil_decode_packet_in(struct ofputil_packet_in *pi, > const struct ofp_header *oh); > > +const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason); > +bool ofputil_packet_in_reason_from_string(const char *, > + enum ofp_packet_in_reason *); > + > /* Abstract packet-out message. */ > struct ofputil_packet_out { > const void *packet; /* Packet data, if buffer_id == UINT32_MAX. */ > -- > 1.7.2.5 > > _______________________________________________ > dev mailing list > [email protected] > http://openvswitch.org/mailman/listinfo/dev _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
