diff mbox series

[ovs-dev,ACL,Meters,3/7] ovn-controller: Add "group-table-list" ovs-appctl command.

Message ID 20180730064638.121021-3-jpettit@ovn.org
State Accepted
Headers show
Series [ovs-dev,ACL,Meters,1/7] ovn: Use C strings instead of ds for extended tables. | expand

Commit Message

Justin Pettit July 30, 2018, 6:46 a.m. UTC
Signed-off-by: Justin Pettit <jpettit@ovn.org>
---
 ovn/controller/ovn-controller.8.xml |  5 +++++
 ovn/controller/ovn-controller.c     | 30 +++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

Comments

Ben Pfaff July 30, 2018, 5:43 p.m. UTC | #1
On Sun, Jul 29, 2018 at 11:46:34PM -0700, Justin Pettit wrote:
> Signed-off-by: Justin Pettit <jpettit@ovn.org>

Thanks for the patches!

I think that group_table_list() is very similar or identical to
meter_table_list() in the previous patch.  Is it possible to write both
of them in terms of a common helper function?

Acked-by: Ben Pfaff <blp@ovn.org>
Justin Pettit July 30, 2018, 8:09 p.m. UTC | #2
> On Jul 30, 2018, at 10:43 AM, Ben Pfaff <blp@ovn.org> wrote:
> 
> On Sun, Jul 29, 2018 at 11:46:34PM -0700, Justin Pettit wrote:
>> Signed-off-by: Justin Pettit <jpettit@ovn.org>
> 
> Thanks for the patches!
> 
> I think that group_table_list() is very similar or identical to
> meter_table_list() in the previous patch.  Is it possible to write both
> of them in terms of a common helper function?

Yes, that's true right now.  I have some patches in my local repo that will dump information specific to the type of table.  Unfortunately, I ran out of time for this release, so it provides just the most basic information right now.  I'd prefer to keep them separate since there should be a quick follow on that will make them quite different.

> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks!

--Justin
Ben Pfaff July 30, 2018, 8:35 p.m. UTC | #3
On Mon, Jul 30, 2018 at 01:09:12PM -0700, Justin Pettit wrote:
> 
> > On Jul 30, 2018, at 10:43 AM, Ben Pfaff <blp@ovn.org> wrote:
> > 
> > On Sun, Jul 29, 2018 at 11:46:34PM -0700, Justin Pettit wrote:
> >> Signed-off-by: Justin Pettit <jpettit@ovn.org>
> > 
> > Thanks for the patches!
> > 
> > I think that group_table_list() is very similar or identical to
> > meter_table_list() in the previous patch.  Is it possible to write both
> > of them in terms of a common helper function?
> 
> Yes, that's true right now.  I have some patches in my local repo that
> will dump information specific to the type of table.  Unfortunately, I
> ran out of time for this release, so it provides just the most basic
> information right now.  I'd prefer to keep them separate since there
> should be a quick follow on that will make them quite different.

That's reasonable, thanks.
diff mbox series

Patch

diff --git a/ovn/controller/ovn-controller.8.xml b/ovn/controller/ovn-controller.8.xml
index 7d8fa66d7313..2e4e53d6b1b1 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -374,6 +374,11 @@ 
         Lists each meter table entry and its local meter id.
       </dd>
 
+      <dt><code>group-table-list</code></dt>
+      <dd>
+        Lists each group table entry and its local group id.
+      </dd>
+
       <dt><code>inject-pkt</code> <var>microflow</var></dt>
       <dd>
       <p>
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 62caace247a8..008f81d70eeb 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -66,6 +66,7 @@  VLOG_DEFINE_THIS_MODULE(main);
 static unixctl_cb_func ovn_controller_exit;
 static unixctl_cb_func ct_zone_list;
 static unixctl_cb_func meter_table_list;
+static unixctl_cb_func group_table_list;
 static unixctl_cb_func inject_pkt;
 
 #define DEFAULT_BRIDGE_NAME "br-int"
@@ -566,6 +567,8 @@  main(int argc, char *argv[])
     /* Initialize group ids for loadbalancing. */
     struct ovn_extend_table group_table;
     ovn_extend_table_init(&group_table);
+    unixctl_command_register("group-table-list", "", 0, 0,
+                             group_table_list, &group_table);
 
     /* Initialize meter ids for QoS. */
     struct ovn_extend_table meter_table;
@@ -1054,6 +1057,33 @@  meter_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
     ds_destroy(&ds);
 }
 
+static void
+group_table_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                 const char *argv[] OVS_UNUSED, void *group_table_)
+{
+    struct ovn_extend_table *group_table = group_table_;
+    struct ds ds = DS_EMPTY_INITIALIZER;
+    struct simap groups = SIMAP_INITIALIZER(&groups);
+
+    struct ovn_extend_table_info *m_installed, *next_group;
+    EXTEND_TABLE_FOR_EACH_INSTALLED (m_installed, next_group, group_table) {
+        simap_put(&groups, m_installed->name, m_installed->table_id);
+    }
+
+    const struct simap_node **nodes = simap_sort(&groups);
+    size_t n_nodes = simap_count(&groups);
+    for (size_t i = 0; i < n_nodes; i++) {
+        const struct simap_node *node = nodes[i];
+        ds_put_format(&ds, "%s: %d\n", node->name, node->data);
+    }
+
+    free(nodes);
+    simap_destroy(&groups);
+
+    unixctl_command_reply(conn, ds_cstr(&ds));
+    ds_destroy(&ds);
+}
+
 static void
 inject_pkt(struct unixctl_conn *conn, int argc OVS_UNUSED,
            const char *argv[], void *pending_pkt_)