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). */
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)
}
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) {
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]) {
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)
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. */