[hipl-commit] [tiny] Rev 3710: Created module heartbeat_update.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Thu, 25 Mar 2010 15:51:22 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: 25/03/2010 at 15:51:22
Revision: 3710
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Created module heartbeat_update.
  
  This module contains the UPDATE-dependend parts of HEARTBEAT. Therefore
  it requires the modules UPDATE and HEARTBEAT.

Modified:
  A  modules/heartbeat_update/
  A  modules/heartbeat_update/Makefile.am
  A  modules/heartbeat_update/hipd/
  A  modules/heartbeat_update/hipd/hb_update.c
  A  modules/heartbeat_update/hipd/hb_update.h
  A  modules/heartbeat_update/module_info.xml
  M  modules/heartbeat/hipd/heartbeat.c
  M  modules/heartbeat/module_info.xml

=== modified file 'modules/heartbeat/hipd/heartbeat.c'
--- modules/heartbeat/hipd/heartbeat.c  2010-03-25 10:47:44 +0000
+++ modules/heartbeat/hipd/heartbeat.c  2010-03-25 13:50:28 +0000
@@ -50,13 +50,10 @@
 #include "hipd/hip_socket.h"
 #include "hipd/pkt_handling.h"
 
-#include "modules/update/hipd/update.h"
-
 #define HIP_HEARTBEAT_INTERVAL 20
 
 int hip_icmp_sock;
 static int heartbeat_counter = HIP_HEARTBEAT_INTERVAL;
-static const int hip_heartbeat_trigger_update_threshold = 5;
 
 /**
  * This function sends ICMPv6 echo with timestamp to dsthit
@@ -310,11 +307,9 @@
  */
 static int hip_send_heartbeat(hip_ha_t *hadb_entry, void *opaq)
 {
-    int err                                     = 0;
-    int *sockfd                                 = (int *) opaq;
-    uint8_t *heartbeat_counter                  = NULL;
-    hip_common_t *locator_msg                   = NULL;
-    struct hip_locator_info_addr_item *locators = NULL;
+    int err                    = 0;
+    int *sockfd                = (int *) opaq;
+    uint8_t *heartbeat_counter = NULL;
 
     if ((hadb_entry->state == HIP_STATE_ESTABLISHED) &&
         (hadb_entry->outbound_sa_count > 0)) {
@@ -326,31 +321,9 @@
 
         *heartbeat_counter = *heartbeat_counter + 1;
         HIP_DEBUG("heartbeat_counter: %d\n", *heartbeat_counter);
-
-        if (*heartbeat_counter >= hip_heartbeat_trigger_update_threshold) {
-            HIP_DEBUG("HEARTBEAT counter reached threshold, trigger UPDATE\n");
-
-            HIP_IFEL(!(locator_msg = hip_msg_alloc()), -ENOMEM,
-                     "Out of memory while allocation memory for the packet\n");
-            HIP_IFE(hip_create_locators(locator_msg, &locators), -1);
-
-            HIP_IFEL(hip_send_locators_to_one_peer(NULL,
-                                                   hadb_entry,
-                                                   &hadb_entry->our_addr,
-                                                   &hadb_entry->peer_addr,
-                                                   locators,
-                                                   HIP_UPDATE_LOCATOR),
-                     -1, "Failed to trigger update\n");
-
-            *heartbeat_counter = 0;
-        }
     }
 
 out_err:
-    if (locator_msg) {
-        free(locator_msg);
-    }
-
     return err;
 }
 
@@ -367,7 +340,7 @@
     return 0;
 }
 
-static int hip_heartbeat_update_init_state(struct modular_state *state)
+static int hip_heartbeat_init_state(struct modular_state *state)
 {
     int err = 0;
     uint8_t *heartbeat_counter = NULL;
@@ -419,10 +392,9 @@
              -1,
              "Error on registration of hip_heartbeat_maintenance().\n");
 
-    /** @todo This should only be done, if the module UPDATE exists */
-    
HIP_IFEL(lmod_register_state_init_function(&hip_heartbeat_update_init_state),
+    HIP_IFEL(lmod_register_state_init_function(&hip_heartbeat_init_state),
              -1,
-             "Error on registration of hip_heartbeat_update_init_state().\n");
+             "Error on registration of hip_heartbeat_init_state().\n");
 
 out_err:
     return err;

=== modified file 'modules/heartbeat/module_info.xml'
--- modules/heartbeat/module_info.xml   2010-03-13 13:46:21 +0000
+++ modules/heartbeat/module_info.xml   2010-03-25 13:50:28 +0000
@@ -9,10 +9,6 @@
     bugaddress="hipl-users@xxxxxxxxxxxxx"
     webpage="http://infrahip.hiit.fi/";>
     
-    <requires>
-        <module name="update" minversion="0.0.1" />
-    </requires>
-
     <!-- Mandatory: name, header_file, init_function, linkcommand -->
     <application
         name="hipd"

=== added directory 'modules/heartbeat_update'
=== added file 'modules/heartbeat_update/Makefile.am'
--- modules/heartbeat_update/Makefile.am        1970-01-01 00:00:00 +0000
+++ modules/heartbeat_update/Makefile.am        2010-03-25 13:50:28 +0000
@@ -0,0 +1,2 @@
+lib_LTLIBRARIES += modules/heartbeat_update/hipd/libhiphbupdate.la
+modules_heartbeat_update_hipd_libhiphbupdate_la_SOURCES = 
modules/heartbeat_update/hipd/hb_update.c

=== added directory 'modules/heartbeat_update/hipd'
=== added file 'modules/heartbeat_update/hipd/hb_update.c'
--- modules/heartbeat_update/hipd/hb_update.c   1970-01-01 00:00:00 +0000
+++ modules/heartbeat_update/hipd/hb_update.c   2010-03-25 13:50:28 +0000
@@ -0,0 +1,71 @@
+/**
+ * @file
+ *
+ * Distributed under <a 
href="http://www.gnu.org/licenses/gpl2.txt";>GNU/GPL</a>.
+ *
+ * @author Tim Just
+ */
+
+#include "hb_update.h"
+#include "hipd/maintenance.h"
+#include "modules/update/hipd/update.h"
+
+static const int hip_heartbeat_trigger_update_threshold = 5;
+
+static int hip_hb_update_trigger(hip_ha_t *hadb_entry, void *unused)
+{
+    int err                                     = 0;
+    uint8_t *heartbeat_counter                  = NULL;
+    hip_common_t *locator_msg                   = NULL;
+    struct hip_locator_info_addr_item *locators = NULL;
+
+    if ((hadb_entry->state == HIP_STATE_ESTABLISHED) &&
+        (hadb_entry->outbound_sa_count > 0)) {
+
+        heartbeat_counter = lmod_get_state_item(hadb_entry->hip_modular_state,
+                                                "heartbeat_update");
+
+        if (*heartbeat_counter >= hip_heartbeat_trigger_update_threshold) {
+            HIP_DEBUG("HEARTBEAT counter reached threshold, trigger UPDATE\n");
+
+            HIP_IFEL(!(locator_msg = hip_msg_alloc()), -ENOMEM,
+                     "Out of memory while allocation memory for the packet\n");
+            HIP_IFE(hip_create_locators(locator_msg, &locators), -1);
+
+            HIP_IFEL(hip_send_locators_to_one_peer(NULL,
+                                                   hadb_entry,
+                                                   &hadb_entry->our_addr,
+                                                   &hadb_entry->peer_addr,
+                                                   locators,
+                                                   HIP_UPDATE_LOCATOR),
+                     -1, "Failed to trigger update\n");
+
+            *heartbeat_counter = 0;
+        }
+    }
+
+out_err:
+    if (locator_msg) {
+        free(locator_msg);
+    }
+
+    return err;
+}
+
+static int hip_hb_update_maintenance(void)
+{
+    hip_for_each_ha(hip_hb_update_trigger, NULL);
+
+    return 0;
+}
+
+int hip_hb_update_init(void)
+{
+    int err = 0;
+
+    HIP_IFEL(hip_register_maint_function(&hip_hb_update_maintenance, 50000),
+             -1,
+             "Error on registration of hip_hb_update_maintenance().\n");
+out_err:
+    return err;
+}

=== added file 'modules/heartbeat_update/hipd/hb_update.h'
--- modules/heartbeat_update/hipd/hb_update.h   1970-01-01 00:00:00 +0000
+++ modules/heartbeat_update/hipd/hb_update.h   2010-03-25 13:50:28 +0000
@@ -0,0 +1,11 @@
+/**
+ * @file
+ *
+ * Distributed under <a href="http://www.gnu.org/licenses/gpl2.txt";>GNU/GPL</a>
+ */
+#ifndef HIP_MODULES_HEARTBEAT_UPDATE_H
+#define HIP_MODULES_HEARTBEAT_UPDATE_H
+
+int hip_hb_update_init(void);
+
+#endif /* HIP_MODULES_HEARTBEAT_UPDATE_H */

=== added file 'modules/heartbeat_update/module_info.xml'
--- modules/heartbeat_update/module_info.xml    1970-01-01 00:00:00 +0000
+++ modules/heartbeat_update/module_info.xml    2010-03-25 13:50:28 +0000
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Mandatory: name, version -->
+<module
+    name="heartbeat_update"
+    version="0.0.1"
+    description="This module enables UPDATE triggering on HEATBEAT failure."
+    developer=""
+    bugaddress="hipl-users@xxxxxxxxxxxxx"
+    webpage="http://infrahip.hiit.fi/";>
+
+     <requires>
+        <module name="heartbeat" minversion="0.0.1" />
+        <module name="update" minversion="0.0.1" />
+    </requires>
+
+    <!-- Mandatory: name, header_file, init_function, linkcommand -->
+    <application
+        name="hipd"
+        header_file="modules/heartbeat_update/hipd/hb_update.h"
+        init_function="hip_hb_update_init"
+        linkcommand="hipd_hipd_LDADD += 
modules/heartbeat_update/hipd/libhiphbupdate.la" />
+</module>
+

Other related posts:

  • » [hipl-commit] [tiny] Rev 3710: Created module heartbeat_update. - Tim Just