[Babel-users] [PATCH] v2: Allow to independently monitor events for neighbour, interface, route, xroute

Christof Schulze christof.schulze at gmx.net
Fri Dec 7 23:08:35 GMT 2018


This is version 2 of the patch, wrapping the pointer arithmetics in a 
set of inline functions to improve readability of the code.

In large networks there is much traffic on the socket. This induces high
load even when only a subset of the data is relevant. This commit
introduces new commands on the socket for neighbour-monitor,
route-monitor, xroute-monitor, interface-monitor that will exclusively
show changes for these structures.
---
   babeld.man      | 16 ++++++++++++
   configuration.c | 40 ++++++++++++++++++++++++++++
   configuration.h |  8 ++++++
   local.c         | 81 +++++++++++++++++++++++++++++++++++++++++++++++----------
   local.h         | 19 +++++++++++++-
   5 files changed, 149 insertions(+), 15 deletions(-)

diff --git a/babeld.man b/babeld.man
index cde4a2a..a05c82c 100644
--- a/babeld.man
+++ b/babeld.man
@@ -619,6 +619,22 @@ any configuration file directive, including
   and
   .BR unmonitor ;
   .IP \(bu
+.B neighbour-monitor
+and
+.BR neighbour-unmonitor ;
+.IP \(bu
+.B route-monitor
+and
+.BR route-unmonitor ;
+.IP \(bu
+.B xroute-monitor
+and
+.BR xroute-unmonitor ;
+.IP \(bu
+.B interface-monitor
+and
+.BR interface-unmonitor ;
+.IP \(bu
   .BR quit .
   .SH EXAMPLES
   You can participate in a Babel network by simply running
diff --git a/configuration.c b/configuration.c
index 6a11d53..cf0287f 100644
--- a/configuration.c
+++ b/configuration.c
@@ -986,6 +986,46 @@ parse_config_line(int c, gnc_t gnc, void *closure,
           if(c < -1 || !action_return)
               goto fail;
           *action_return = CONFIG_ACTION_DUMP;
+    } else if(strcmp(token, "neighbour-monitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_NEIGHBOUR_MONITOR;
+    } else if(strcmp(token, "neighbour-unmonitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_NEIGHBOUR_UNMONITOR;
+    } else if(strcmp(token, "route-monitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_ROUTE_MONITOR;
+    } else if(strcmp(token, "route-unmonitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_ROUTE_UNMONITOR;
+    } else if(strcmp(token, "xroute-monitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_XROUTE_MONITOR;
+    } else if(strcmp(token, "xroute-unmonitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_XROUTE_UNMONITOR;
+    } else if(strcmp(token, "interface-monitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_INTERFACE_MONITOR;
+    } else if(strcmp(token, "interface-unmonitor") == 0) {
+        c = skip_eol(c, gnc, closure);
+        if(c < -1 || !action_return)
+            goto fail;
+        *action_return = CONFIG_ACTION_INTERFACE_UNMONITOR;
       } else if(strcmp(token, "monitor") == 0) {
           c = skip_eol(c, gnc, closure);
           if(c < -1 || !action_return)
diff --git a/configuration.h b/configuration.h
index de2b1ba..8c7d395 100644
--- a/configuration.h
+++ b/configuration.h
@@ -28,6 +28,14 @@ THE SOFTWARE.
   #define CONFIG_ACTION_MONITOR 3
   #define CONFIG_ACTION_UNMONITOR 4
   #define CONFIG_ACTION_NO 5
+#define CONFIG_ACTION_NEIGHBOUR_MONITOR 6
+#define CONFIG_ACTION_NEIGHBOUR_UNMONITOR 7
+#define CONFIG_ACTION_ROUTE_MONITOR 8
+#define CONFIG_ACTION_ROUTE_UNMONITOR 9
+#define CONFIG_ACTION_XROUTE_MONITOR 10
+#define CONFIG_ACTION_XROUTE_UNMONITOR 11
+#define CONFIG_ACTION_INTERFACE_MONITOR 12
+#define CONFIG_ACTION_INTERFACE_UNMONITOR 13
   
   struct filter_result {
       unsigned int add_metric; /* allow = 0, deny = INF, metric = <0..INF> */
diff --git a/local.c b/local.c
index bb8fe8b..0aa9feb 100644
--- a/local.c
+++ b/local.c
@@ -131,7 +131,7 @@ local_notify_interface(struct interface *ifp, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_INTERFACE))
               local_notify_interface_1(&local_sockets[i], ifp, kind);
       }
   }
@@ -186,7 +186,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_NEIGHBOUR))
               local_notify_neighbour_1(&local_sockets[i], neigh, kind);
       }
   }
@@ -223,7 +223,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_XROUTE))
               local_notify_xroute_1(&local_sockets[i], xroute, kind);
       }
   }
@@ -268,26 +268,36 @@ local_notify_route(struct babel_route *route, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_ROUTE))
               local_notify_route_1(&local_sockets[i], route, kind);
       }
   }
   
+
   static void
-local_notify_all_1(struct local_socket *s)
+local_notify_all_neighbour_1(struct local_socket *s)
   {
-    struct interface *ifp;
       struct neighbour *neigh;
-    struct xroute_stream *xroutes;
-    struct route_stream *routes;
+
+    FOR_ALL_NEIGHBOURS(neigh) {
+        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
+    }
+}
+
+static void
+local_notify_all_interface_1(struct local_socket *s)
+{
+    struct interface *ifp;
   
       FOR_ALL_INTERFACES(ifp) {
           local_notify_interface_1(s, ifp, LOCAL_ADD);
       }
+}
   
-    FOR_ALL_NEIGHBOURS(neigh) {
-        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
-    }
+static void
+local_notify_all_xroute_1(struct local_socket *s)
+{
+    struct xroute_stream *xroutes;
   
       xroutes = xroute_stream();
       if(xroutes) {
@@ -299,6 +309,12 @@ local_notify_all_1(struct local_socket *s)
           }
           xroute_stream_done(xroutes);
       }
+}
+
+static void
+local_notify_all_route_1(struct local_socket *s)
+{
+    struct route_stream *routes;
   
       routes = route_stream(ROUTE_ALL);
       if(routes) {
@@ -310,7 +326,16 @@ local_notify_all_1(struct local_socket *s)
           }
           route_stream_done(routes);
       }
-    return;
+}
+
+
+static void
+local_notify_all_1(struct local_socket *s)
+{
+    local_notify_all_interface_1(s);
+    local_notify_all_neighbour_1(s);
+    local_notify_all_xroute_1(s);
+    local_notify_all_route_1(s);
   }
   
   int
@@ -353,12 +378,40 @@ local_read(struct local_socket *s)
           case CONFIG_ACTION_DUMP:
               local_notify_all_1(s);
               break;
+        case CONFIG_ACTION_INTERFACE_MONITOR:
+	    set_flag(&s->monitor, MONITOR_INTERFACE);
+            local_notify_all_interface_1(s);
+            break;
+        case CONFIG_ACTION_INTERFACE_UNMONITOR:
+	    unset_flag(&s->monitor, MONITOR_INTERFACE);
+            break;
+        case CONFIG_ACTION_ROUTE_MONITOR:
+	    set_flag(&s->monitor, MONITOR_ROUTE);
+            local_notify_all_route_1(s);
+            break;
+        case CONFIG_ACTION_ROUTE_UNMONITOR:
+	    unset_flag(&s->monitor, MONITOR_ROUTE);
+            break;
+        case CONFIG_ACTION_XROUTE_MONITOR:
+	    set_flag(&s->monitor, MONITOR_XROUTE);
+            local_notify_all_xroute_1(s);
+            break;
+        case CONFIG_ACTION_XROUTE_UNMONITOR:
+	    unset_flag(&s->monitor, MONITOR_ROUTE);
+            break;
+        case CONFIG_ACTION_NEIGHBOUR_MONITOR:
+	    set_flag(&s->monitor, MONITOR_NEIGHBOUR);
+            local_notify_all_neighbour_1(s);
+            break;
+        case CONFIG_ACTION_NEIGHBOUR_UNMONITOR:
+	    unset_flag(&s->monitor, MONITOR_NEIGHBOUR);
+            break;
           case CONFIG_ACTION_MONITOR:
+            s->monitor = 0xff;
               local_notify_all_1(s);
-            s->monitor = 1;
               break;
           case CONFIG_ACTION_UNMONITOR:
-            s->monitor = 0;
+            s->monitor = 0x00;
               break;
           case CONFIG_ACTION_NO:
               snprintf(reply, sizeof(reply), "no%s%s\n",
diff --git a/local.h b/local.h
index 2316111..6e5ecfc 100644
--- a/local.h
+++ b/local.h
@@ -38,9 +38,26 @@ struct local_socket {
       int fd;
       char *buf;
       int n;
-    int monitor;
+    uint8_t monitor;
   };
   
+#define MONITOR_NEIGHBOUR 1
+#define MONITOR_INTERFACE 2
+#define MONITOR_ROUTE 3
+#define MONITOR_XROUTE 4
+
+inline void set_flag(uint8_t *d, uint8_t flag) {
+    *d |= 0x01 << flag;
+}
+
+inline void unset_flag(uint8_t *d, uint8_t flag) {
+    *d &= ~( 0x01 << flag );
+}
+
+inline uint8_t get_flag(uint8_t *s, uint8_t flag) {
+    return *s & (0x01 << flag);
+}
+
   extern int local_server_socket;
   extern struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
   extern int num_local_sockets;
-- 
2.11.0




More information about the Babel-users mailing list