From: Ben Pfaff Date: Tue, 7 Feb 2012 22:46:34 +0000 (-0800) Subject: ofp-util: New functions for string versions of ofp_packet_in_reason. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c1a76a4673be09de56743400dfb1d1c8d8d0799;p=openvswitch ofp-util: New functions for string versions of ofp_packet_in_reason. 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 --- diff --git a/include/openflow/openflow.h b/include/openflow/openflow.h index a707087b..cfdb1923 100644 --- a/include/openflow/openflow.h +++ b/include/openflow/openflow.h @@ -294,7 +294,8 @@ OFP_ASSERT(sizeof(struct ofp_port_mod) == 32); enum ofp_packet_in_reason { OFPR_NO_MATCH, /* No matching flow. */ OFPR_ACTION, /* Action explicitly output to controller. */ - OFPR_INVALID_TTL /* Packet has invalid TTL. */ + OFPR_INVALID_TTL, /* Packet has invalid TTL. */ + OFPR_N_REASONS }; /* Packet received on port (datapath -> controller). */ diff --git a/lib/ofp-print.c b/lib/ofp-print.c index f1eeebb4..5f55da3b 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) { @@ -1376,7 +1358,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 ffdccda4..f9f42490 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -1784,6 +1784,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 59d6b1ab..6da65277 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -248,6 +248,10 @@ int ofputil_decode_packet_in(struct ofputil_packet_in *, struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *, enum nx_packet_in_format); +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. */