From 05f453a895297bd53f18554126048184bcbf1723 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 3 May 2013 13:58:29 -0700 Subject: [PATCH] ovs-ofctl: Make "ovs-ofctl monitor" respond to echo requests. Otherwise the command will time out after a while when there's no traffic, which probably isn't what we want. Reported-by: Henry Mai Signed-off-by: Ben Pfaff Acked-by: Ethan Jackson --- utilities/ovs-ofctl.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 9f97bbc6c..63c19bdd5 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -1312,8 +1312,12 @@ ofctl_unblock(struct unixctl_conn *conn, int argc OVS_UNUSED, } } +/* Prints to stdout all of the messages received on 'vconn'. + * + * Iff 'reply_to_echo_requests' is true, sends a reply to any echo request + * received on 'vconn'. */ static void -monitor_vconn(struct vconn *vconn) +monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests) { struct barrier_aux barrier_aux = { vconn, NULL }; struct unixctl_server *server; @@ -1368,12 +1372,28 @@ monitor_vconn(struct vconn *vconn) ofptype_decode(&type, b->data); ofp_print(stderr, b->data, b->size, verbosity + 2); - ofpbuf_delete(b); - if (barrier_aux.conn && type == OFPTYPE_BARRIER_REPLY) { - unixctl_command_reply(barrier_aux.conn, NULL); - barrier_aux.conn = NULL; + switch ((int) type) { + case OFPTYPE_BARRIER_REPLY: + if (barrier_aux.conn) { + unixctl_command_reply(barrier_aux.conn, NULL); + barrier_aux.conn = NULL; + } + break; + + case OFPTYPE_ECHO_REQUEST: + if (reply_to_echo_requests) { + struct ofpbuf *reply; + + reply = make_echo_reply(b->data); + retval = vconn_send_block(vconn, reply); + if (retval) { + ovs_fatal(retval, "failed to send echo reply"); + } + } + break; } + ofpbuf_delete(b); } if (exiting) { @@ -1456,7 +1476,7 @@ ofctl_monitor(int argc, char *argv[]) } } - monitor_vconn(vconn); + monitor_vconn(vconn, true); } static void @@ -1465,7 +1485,7 @@ ofctl_snoop(int argc OVS_UNUSED, char *argv[]) struct vconn *vconn; open_vconn__(argv[1], SNOOP, &vconn); - monitor_vconn(vconn); + monitor_vconn(vconn, false); } static void -- 2.47.0