[ovs-dev] [PATCH 3/3] ovs-ofctl: Make "ovs-ofctl monitor" respond to echo requests.

Ben Pfaff blp at nicira.com
Wed Oct 24 16:51:22 UTC 2012


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 <hmai at nicira.com>
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
 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 a67a554..4f7dbbf 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -1271,8 +1271,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;
@@ -1325,12 +1329,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(vconn, reply);
+                    if (retval && retval != EAGAIN) {
+                        ovs_fatal(retval, "failed to send echo reply");
+                    }
+                }
+                break;
             }
+            ofpbuf_delete(b);
         }
 
         if (exiting) {
@@ -1400,7 +1420,7 @@ ofctl_monitor(int argc, char *argv[])
         }
     }
 
-    monitor_vconn(vconn);
+    monitor_vconn(vconn, true);
 }
 
 static void
@@ -1409,7 +1429,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
-- 
1.7.10.4




More information about the dev mailing list