[ovs-dev] <conntrack><dpif-netdev>: ovs-appctl dump and flush command for userspace conntrack

sourabh.bansal at wipro.com sourabh.bansal at wipro.com
Fri Feb 19 10:35:57 UTC 2016


Hi Joe,

Thanks for pointing out my mistake. Please find below updated one.


m 69e63a45e2773c124deb885bbc3d5deb3e032126 Mon Sep 17 00:00:00 2001
From: soumyadeep chowdhury <soumyadeep.chowdhury at wipro.com>
Date: Fri, 19 Feb 2016 07:39:34 -0500
Subject: [PATCH 4/4] Write the functions for dump-conntrack and
 flush-conntrack

Signed-off-by: Sourabh Bansal <sourabh.bansal at wipro.com>
---
 ovs-userconntrack_20151115/lib/dpif-netdev.c | 82 ++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/ovs-userconntrack_20151115/lib/dpif-netdev.c b/ovs-userconntrack_20151115/lib/dpif-netdev.c
index 340e37c..f950780 100644
--- a/ovs-userconntrack_20151115/lib/dpif-netdev.c
+++ b/ovs-userconntrack_20151115/lib/dpif-netdev.c
@@ -715,6 +715,84 @@ dpif_netdev_pmd_info(struct unixctl_conn *conn, int argc, const char *argv[],
     unixctl_command_reply(conn, ds_cstr(&reply));
     ds_destroy(&reply);
 }
+
+/*This function will dump the entries present in conntrack table*/
+static void
+dpif_netdev_dump_conntrack(struct unixctl_conn *conn, int argc, const char *argv[],
+                             void *aux OVS_UNUSED)
+{
+    struct dp_netdev *dp = NULL;
+    struct ct_dpif_dump_state *dump;
+    struct ct_dpif_entry cte;
+    uint16_t *pzone = NULL;
+    struct dpif *dpif;
+
+    ovs_mutex_lock(&dp_netdev_mutex);
+
+    if (argc == 2) {
+        dp = shash_find_data(&dp_netdevs, argv[1]);
+    } else if (shash_count(&dp_netdevs) == 1) {
+                  /* There's only one datapath */
+        dp = shash_first(&dp_netdevs)->data;
+    }
+
+    if (!dp) {
+       ovs_mutex_unlock(&dp_netdev_mutex);
+       unixctl_command_reply_error(conn,
+                              "please specify an existing datapath");
+       return;
+    }
+    ovs_mutex_unlock(&dp_netdev_mutex);
+    dpif = dp->dpif;
+
+    int verbosity = 1;
+    int print_statistics = 0;
+
+    struct ds s = DS_EMPTY_INITIALIZER;
+
+    ct_dpif_dump_start(dpif, &dump, pzone);
+    while (!ct_dpif_dump_next(dump, &cte)) {
+
+        ct_dpif_format_entry(&cte, &s, verbosity,
+        print_statistics);
+        ct_dpif_entry_uninit(&cte);
+    }
+
+    unixctl_command_reply(conn, ds_cstr(&s));
+    ds_destroy(&s);
+
+    ct_dpif_dump_done(dump);
+    return;
+}
+
+/*This function will flush the entries present in conntrack table*/
+static void
+dpif_netdev_flush_conntrack(struct unixctl_conn *conn, int argc, const char *argv[],
+                     void *aux OVS_UNUSED)
+{
+    struct dp_netdev *dp = NULL;
+    struct dpif *dpif;
+    uint16_t *pzone = NULL;
+
+    ovs_mutex_lock(&dp_netdev_mutex);
+    if (argc == 2) {
+        dp = shash_find_data(&dp_netdevs, argv[1]);
+    } else if (shash_count(&dp_netdevs) == 1) {
+        dp = shash_first(&dp_netdevs)->data;
+    }
+
+    ovs_mutex_unlock(&dp_netdev_mutex);
+
+    struct ds s = DS_EMPTY_INITIALIZER;
+
+    dpif = dp->dpif;
+    ct_dpif_flush(dpif,pzone);
+
+    unixctl_command_reply(conn, ds_cstr(&s));
+    ds_destroy(&s);
+
+}
+


 static int
 dpif_netdev_init(void)
@@ -728,6 +806,10 @@ dpif_netdev_init(void)
     unixctl_command_register("dpif-netdev/pmd-stats-clear", "[dp]",
                              0, 1, dpif_netdev_pmd_info,
                              (void *)&clear_aux);
+    unixctl_command_register("dump-conntrack", "Dump the entire conntrack table",
+                              0, 0, dpif_netdev_dump_conntrack, NULL);
+    unixctl_command_register("flush-conntrack", "Flush the entire conntrack table",
+                              0, 0, dpif_netdev_flush_conntrack, NULL);
     return 0;
 }

Regards,
Sourabh Bansal

-----Original Message-----
From: Joe Stringer [mailto:joe at ovn.org]
Sent: Friday, February 19, 2016 3:08 AM
To: Sourabh Bansal (NEP) <sourabh.bansal at wipro.com>
Cc: Daniele Di Proietto <diproiettod at vmware.com>; ovs dev <dev at openvswitch.org>
Subject: Re: [ovs-dev] <conntrack><dpif-netdev>: ovs-appctl dump and flush command for userspace conntrack

On 17 February 2016 at 04:50,  <sourabh.bansal at wipro.com> wrote:
> Hi Daniele,
>
> Like to contribute the following changes to your userconntrack branch.
> Please review and provide your comments
>
> Change Description:
>
> This implementation is based on top of this branch (By Daniele Di Proietto):
> https://github.com/ddiproietto/ovs/tree/userconntrack_20151115
>
> and this provides following two commands to ovs-appctl  command -
>
>
> 1.       Ovs-appctl dump-conntrack     - To dump the conntrack table entries
>
> 2.       Ovs-appctl flush-conntrack       - To flush the conntrack table entries
>
> Corresponding function implementations are -
> dpif_netdev_dump_conntrack()
> dpif_netdev_flush_conntrack()
>
> and these functions are registered with unixctl_command_register() so
> that it can be accessed via ovs-appctl command
>
> List of change files:
>
> 1.       /lib/dpif-netdev.c

This functionality is already available here, in the same codebase:
https://github.com/ddiproietto/ovs/blob/userconntrack_20151115/lib/dpctl.c#L1246


> Change Diff:
>
> *** /home/bansal/submission_code/ovs-userconntrack_20151115/lib/dpif-netdev.c     2016-02-17 10:00:12.114559489 -0500
> --- /home/bansal/orig/ovs-userconntrack_20151115/lib/dpif-netdev.c   2015-11-16 01:07:25.000000000 -0500
> ***************
> *** 715,797 ****

The usual way to prepare and send patches for projects like this is using "git format-patch" or "git send-email".

>       unixctl_command_reply(conn, ds_cstr(&reply));
>       ds_destroy(&reply);
>   }
> -
> - /*This function will dump the entries prestent in conntrack table*/
> - static void
> - dpif_netdev_dump_conntrack(struct unixctl_conn *conn, int argc, const char *argv[],
> -                              void *aux OVS_UNUSED)
> - {
> -     struct dp_netdev *dp = NULL;
> -     struct ct_dpif_dump_state *dump;
> -     struct ct_dpif_entry cte;
> -     uint16_t *pzone = NULL;
> -     struct dpif *dpif;
> -
> -     ovs_mutex_lock(&dp_netdev_mutex);
> -
> -     if (argc == 2) {
> -         dp = shash_find_data(&dp_netdevs, argv[1]);
> -     } else if (shash_count(&dp_netdevs) == 1) {
> -                   /* There's only one datapath */
> -         dp = shash_first(&dp_netdevs)->data;
> -     }
> -
> -     if (!dp) {
> -        ovs_mutex_unlock(&dp_netdev_mutex);
> -        unixctl_command_reply_error(conn,
> -                               "please specify an existing datapath");
> -        return;
> -     }
> -     ovs_mutex_unlock(&dp_netdev_mutex);
> -     dpif = dp->dpif;
> -
> -     int verbosity = 1;
> -     int print_statistics = 0;
> -
> -     struct ds s = DS_EMPTY_INITIALIZER;
> -
> -     ct_dpif_dump_start(dpif, &dump, pzone);
> -     while (!ct_dpif_dump_next(dump, &cte)) {
> -
> -         ct_dpif_format_entry(&cte, &s, verbosity,
> -         print_statistics);
> -         ct_dpif_entry_uninit(&cte);
> -     }
> -
> -     unixctl_command_reply(conn, ds_cstr(&s));
> -     ds_destroy(&s);
> -
> -     ct_dpif_dump_done(dump);
> -     return;
> - }
> -
> - /*This function will flush the entries prestent in conntrack table*/
> - static void
> - dpif_netdev_flush_conntrack(struct unixctl_conn *conn, int argc, const char *argv[],
> -                      void *aux OVS_UNUSED)
> - {
> -     struct dp_netdev *dp = NULL;
> -     struct dpif *dpif;
> -     uint16_t *pzone = NULL;
> -
> -     ovs_mutex_lock(&dp_netdev_mutex);
> -     if (argc == 2) {
> -         dp = shash_find_data(&dp_netdevs, argv[1]);
> -     } else if (shash_count(&dp_netdevs) == 1) {
> -         dp = shash_first(&dp_netdevs)->data;
> -     }
> -
> -     ovs_mutex_unlock(&dp_netdev_mutex);
> -
> -     struct ds s = DS_EMPTY_INITIALIZER;
> -
> -     dpif = dp->dpif;
> -     ct_dpif_flush(dpif,pzone);
> -
> -     unixctl_command_reply(conn, ds_cstr(&s));
> -     ds_destroy(&s);
> -
> - }
>
>   static int
>   dpif_netdev_init(void)
> --- 715,720 ----
> ***************
> *** 805,814 ****
>       unixctl_command_register("dpif-netdev/pmd-stats-clear", "[dp]",
>                                0, 1, dpif_netdev_pmd_info,
>                                (void *)&clear_aux);
> -     unixctl_command_register("dump-conntrack", "Dump the entire conntrack table",
> -                               0, 0, dpif_netdev_dump_conntrack, NULL);
> -     unixctl_command_register("flush-conntrack", "Flush the entire conntrack table",
> -                               0, 0, dpif_netdev_flush_conntrack, NULL);
>       return 0;
>   }

It looks like your diff is in the reverse order of what you intended.

> Regards,
> Sourabh Bansal
> The information contained in this electronic message and any
> attachments to this message are intended for the exclusive use of the
> addressee(s) and may contain proprietary, confidential or privileged
> information. If you are not the intended recipient, you should not
> disseminate, distribute or copy this e-mail. Please notify the sender
> immediately and destroy all copies of this message and any
> attachments. WARNING: Computer viruses can be transmitted via email.
> The recipient should check this email and any attachments for the
> presence of viruses. The company accepts no liability for any damage
> caused by any virus transmitted by this email. www.wipro.com

This disclaimer makes entirely *no* sense on a public mailing list, please refrain from using it.
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com


More information about the dev mailing list