[ovs-dev,v3,10/19] bridge: Update keepalive status in OVSDB

Submitted by Bhanuprakash Bodireddy on Aug. 4, 2017, 8:07 a.m.

Details

Message ID 1501834086-31829-11-git-send-email-bhanuprakash.bodireddy@intel.com
State New
Headers show

Commit Message

Bhanuprakash Bodireddy Aug. 4, 2017, 8:07 a.m.
This commit allows vswitchd thread to update the OVSDB with the
status of all registered PMD threads. The status can be monitored
using ovsdb-client and the sample output is below.

$ ovsdb-client monitor Open_vSwitch Open_vSwitch keepalive

    row                            action keepalive
7b746190-ee71-4dcc-becf-f8cb9c7cb909 old  { "pmd62"="ALIVE,0,9226457935188922"
                                            "pmd63"="ALIVE,1,9226457935189628"
                                            "pmd64"="ALIVE,2,9226457935189897"
                                            "pmd65"="ALIVE,3,9226457935190127"}

                                     new  { "pmd62"="ALIVE,0,9226460230167364"
                                            "pmd63"="ALIVE,1,9226460230168100"
                                            "pmd64"="ALIVE,2,9226460230168905"
                                            "pmd65"="ALIVE,3,9226460230169632"}

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 lib/keepalive.c   | 15 +++++++++++++++
 lib/keepalive.h   |  1 +
 vswitchd/bridge.c | 26 ++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)

Patch hide | download patch | download mbox

diff --git a/lib/keepalive.c b/lib/keepalive.c
index 509a0d1..83ce26d 100644
--- a/lib/keepalive.c
+++ b/lib/keepalive.c
@@ -339,6 +339,21 @@  get_ka_stats(void)
     ovs_mutex_unlock(&mutex);
 }
 
+struct smap *
+ka_stats_run(void)
+{
+    struct smap *ka_stats = NULL;
+
+    ovs_mutex_lock(&mutex);
+    if (keepalive_stats) {
+        ka_stats = keepalive_stats;
+        keepalive_stats = NULL;
+    }
+    ovs_mutex_unlock(&mutex);
+
+    return ka_stats;
+}
+
 static int
 ka_init__(void)
 {
diff --git a/lib/keepalive.h b/lib/keepalive.h
index b18f6e0..cedc390 100644
--- a/lib/keepalive.h
+++ b/lib/keepalive.h
@@ -101,6 +101,7 @@  int get_ka_init_status(void);
 int ka_alloc_portstats(unsigned, int);
 void ka_destroy_portstats(void);
 void get_ka_stats(void);
+struct smap *ka_stats_run(void);
 
 void dispatch_heartbeats(void);
 #endif /* keepalive.h */
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index 8ff91df..56c55f5 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -286,6 +286,7 @@  static bool port_is_synthetic(const struct port *);
 
 static void reconfigure_system_stats(const struct ovsrec_open_vswitch *);
 static void run_system_stats(void);
+static void run_keepalive_stats(void);
 
 static void bridge_configure_mirrors(struct bridge *);
 static struct mirror *mirror_create(struct bridge *,
@@ -403,6 +404,7 @@  bridge_init(const char *remote)
 
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_cur_cfg);
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_statistics);
+    ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_keepalive);
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_datapath_types);
     ovsdb_idl_omit_alert(idl, &ovsrec_open_vswitch_col_iface_types);
     ovsdb_idl_omit(idl, &ovsrec_open_vswitch_col_external_ids);
@@ -2686,6 +2688,29 @@  run_system_stats(void)
     }
 }
 
+void
+run_keepalive_stats(void)
+{
+    struct smap *ka_stats;
+    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(idl);
+
+    ka_stats = ka_stats_run();
+    if (ka_stats && cfg) {
+        struct ovsdb_idl_txn *txn;
+        struct ovsdb_datum datum;
+
+        txn = ovsdb_idl_txn_create(idl);
+        ovsdb_datum_from_smap(&datum, ka_stats);
+        smap_destroy(ka_stats);
+        ovsdb_idl_txn_write(&cfg->header_, &ovsrec_open_vswitch_col_keepalive,
+                            &datum);
+        ovsdb_idl_txn_commit(txn);
+        ovsdb_idl_txn_destroy(txn);
+
+        free(ka_stats);
+    }
+}
+
 static const char *
 ofp12_controller_role_to_str(enum ofp12_controller_role role)
 {
@@ -3038,6 +3063,7 @@  bridge_run(void)
     run_stats_update();
     run_status_update();
     run_system_stats();
+    run_keepalive_stats();
 }
 
 void