From: Ben Pfaff Date: Wed, 8 Jun 2011 21:03:47 +0000 (-0700) Subject: dpif: Improve logging of upcalls. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01545c1a3c626ce2748a0d7f58719b2c4c9c6f5c;p=openvswitch dpif: Improve logging of upcalls. The kernel now provides the entire flow key for a packet sent up to userspace, but dpif_recv() would only log the in_port. This change makes userspace log the entire flow key. This would have made a bug that I recently looked at a bit easier to investigate. --- diff --git a/lib/dpif.c b/lib/dpif.c index 1106d6be..4e3788d4 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -952,6 +952,18 @@ dpif_execute(struct dpif *dpif, return error; } +/* Returns a string that represents 'type', for use in log messages. */ +const char * +dpif_upcall_type_to_string(enum dpif_upcall_type type) +{ + switch (type) { + case DPIF_UC_MISS: return "miss"; + case DPIF_UC_ACTION: return "action"; + case DPIF_UC_SAMPLE: return "sample"; + case DPIF_N_UC_TYPES: default: return ""; + } +} + static bool OVS_UNUSED is_valid_listen_mask(int listen_mask) { @@ -1045,20 +1057,22 @@ dpif_recv(struct dpif *dpif, struct dpif_upcall *upcall) { int error = dpif->dpif_class->recv(dpif, upcall); if (!error && !VLOG_DROP_DBG(&dpmsg_rl)) { - struct flow flow; - char *s; - - s = ofp_packet_to_string(upcall->packet->data, - upcall->packet->size, upcall->packet->size); - odp_flow_key_to_flow(upcall->key, upcall->key_len, &flow); - - VLOG_DBG("%s: %s upcall on port %"PRIu16": %s", dpif_name(dpif), - (upcall->type == DPIF_UC_MISS ? "miss" - : upcall->type == DPIF_UC_ACTION ? "action" - : upcall->type == DPIF_UC_SAMPLE ? "sample" - : ""), - flow.in_port, s); - free(s); + struct ds flow; + char *packet; + + packet = ofp_packet_to_string(upcall->packet->data, + upcall->packet->size, + upcall->packet->size); + + ds_init(&flow); + odp_flow_key_format(upcall->key, upcall->key_len, &flow); + + VLOG_DBG("%s: %s upcall:\n%s\n%s", + dpif_name(dpif), dpif_upcall_type_to_string(upcall->type), + ds_cstr(&flow), packet); + + ds_destroy(&flow); + free(packet); } return error; } diff --git a/lib/dpif.h b/lib/dpif.h index 60e3cb48..4a71153a 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -160,6 +160,8 @@ enum dpif_upcall_type { DPIF_N_UC_TYPES }; +const char *dpif_upcall_type_to_string(enum dpif_upcall_type); + /* A packet passed up from the datapath to userspace. * * If 'key' or 'actions' is nonnull, then it points into data owned by