Right now, when we want to look at the flows of netdev
datapath, we use the dpif/dump-flows command which provides
it without querying the netdev datapath but rather through the
facets and subfacets.

This commit adds the ability to directly query the netdev
datapath through the dpif interface.

Signed-off-by: Gurucharan Shetty <gshe...@nicira.com>
---
 ofproto/ofproto-dpif.c     |   42 ++++++++++++++++++++++++++++++++++++++++++
 vswitchd/ovs-vswitchd.8.in |    5 +++++
 2 files changed, 47 insertions(+)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index ff1c74d..1a53766 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -5713,6 +5713,46 @@ ofproto_unixctl_dpif_del_flows(struct unixctl_conn *conn,
 }
 
 static void
+ofproto_unixctl_netdev_dump_flows(struct unixctl_conn *conn,
+                                  int argc OVS_UNUSED,
+                                  const char *argv[] OVS_UNUSED,
+                                  void *aux OVS_UNUSED)
+{
+    struct dpif *dpif;
+    struct dpif_flow_dump flow_dump;
+    const struct dpif_flow_stats *stats;
+    const struct nlattr *key, *mask, *actions;
+    size_t key_len, mask_len, actions_len;
+    struct ds ds;
+    int error;
+
+    /* We only have one backer for dpif-netdev. So just use it. */
+    error = dpif_open("ovs-netdev", "netdev", &dpif);
+    if (error) {
+        unixctl_command_reply_error(conn, "No netdev backer found.");
+        return;
+    }
+
+    ds_init(&ds);
+    dpif_flow_dump_start(&flow_dump, dpif);
+    while (dpif_flow_dump_next(&flow_dump, &key, &key_len,
+                               &mask, &mask_len,
+                               &actions, &actions_len, &stats)) {
+        odp_flow_format(key, key_len, mask, mask_len, NULL, &ds, true);
+        ds_put_cstr(&ds, ", ");
+
+        dpif_flow_stats_format(stats, &ds);
+        ds_put_cstr(&ds, ", actions:");
+        format_odp_actions(&ds, actions, actions_len);
+        ds_put_cstr(&ds, "\n");
+    }
+    dpif_flow_dump_done(&flow_dump);
+    dpif_close(dpif);
+    unixctl_command_reply(conn, ds_cstr(&ds));
+    ds_destroy(&ds);
+}
+
+static void
 ofproto_dpif_unixctl_init(void)
 {
     static bool registered;
@@ -5745,6 +5785,8 @@ ofproto_dpif_unixctl_init(void)
                              ofproto_unixctl_dpif_disable_megaflows, NULL);
     unixctl_command_register("dpif/enable-megaflows", "", 0, 0,
                              ofproto_unixctl_dpif_enable_megaflows, NULL);
+    unixctl_command_register("netdev/dump-flows", "", 0, 0,
+                             ofproto_unixctl_netdev_dump_flows, NULL);
 }
 
 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
diff --git a/vswitchd/ovs-vswitchd.8.in b/vswitchd/ovs-vswitchd.8.in
index 4fb3ae3..c72093f 100644
--- a/vswitchd/ovs-vswitchd.8.in
+++ b/vswitchd/ovs-vswitchd.8.in
@@ -212,6 +212,11 @@ information, and partner information.  If \fIport\fR is 
not specified,
 then displays detailed information about all interfaces with CFM
 enabled.
 .
+.SS "NETDEV COMMANDS"
+These commands manage the userspace datapath.
+.IP "\fBnetdev/dump-flows\fR"
+Prints to the console all flow entries in the userspace datapath's flow table.
+.
 .so ofproto/ofproto-dpif-unixctl.man
 .so ofproto/ofproto-unixctl.man
 .so lib/vlog-unixctl.man
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to