[Babel-users] Revised [PATCH 1/2] Allow to independently monitor events for neighbour, interface, route, xroute

Christof Schulze christof.schulze at gmx.net
Sun Aug 11 23:21:20 BST 2019


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 monitor neighbour, monitor route, monitor xroute,
monitor interface that will exclusively show changes for these structures.
---
  babeld.man      | 16 ++++++++++
  configuration.c | 44 ++++++++++++++++++++++-----
  configuration.h |  8 +++++
  local.c         | 81 ++++++++++++++++++++++++++++++++++++++++---------
  local.h         | 19 +++++++++++-
  5 files changed, 146 insertions(+), 22 deletions(-)

diff --git a/babeld.man b/babeld.man
index e763723..789947e 100644
--- a/babeld.man
+++ b/babeld.man
@@ -625,6 +625,22 @@ any configuration file directive, including
  and
  .BR unmonitor ;
  .IP \(bu
+.B monitor neighbour
+and
+.BR unmonitor neighbour;
+.IP \(bu
+.B monitor route
+and
+.BR unmonitor route ;
+.IP \(bu
+.B monitor xroute
+and
+.BR unmonitor xroute ;
+.IP \(bu
+.B monitor interface
+and
+.BR unmonitor interface ;
+.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 d4d7421..058b6b9 100644
--- a/configuration.c
+++ b/configuration.c
@@ -996,15 +996,45 @@ parse_config_line(int c, gnc_t gnc, void *closure,
              goto fail;
          *action_return = CONFIG_ACTION_DUMP;
      } else if(strcmp(token, "monitor") == 0) {
-        c = skip_eol(c, gnc, closure);
-        if(c < -1 || !action_return)
-            goto fail;
-        *action_return = CONFIG_ACTION_MONITOR;
+	*action_return = CONFIG_ACTION_MONITOR;
+	char *token2 = NULL;
+	c = skip_whitespace(c, gnc, closure);
+	c = getword(c, &token2, gnc, closure);
+	if (token2)
+	{
+	    if (strcmp(token2, "route") == 0)
+		*action_return = CONFIG_ACTION_ROUTE_MONITOR;
+	    else if (strcmp(token2, "interface") == 0)
+		*action_return = CONFIG_ACTION_INTERFACE_MONITOR;
+	    else if (strcmp(token2, "xroute") == 0)
+		*action_return = CONFIG_ACTION_XROUTE_MONITOR;
+	    else if (strcmp(token2, "neighbour") == 0)
+		*action_return = CONFIG_ACTION_NEIGHBOUR_MONITOR;
+	    free(token2);
+	    c = skip_eol(c, gnc, closure);
+	}
+	else // monitor was detected but none of the specialties - monitoring everything.
+	    c = -1;
      } else if(strcmp(token, "unmonitor") == 0) {
-        c = skip_eol(c, gnc, closure);
-        if(c < -1 || !action_return)
-            goto fail;
          *action_return = CONFIG_ACTION_UNMONITOR;
+	char *token2 = NULL;
+	c = skip_whitespace(c, gnc, closure);
+	c = getword(c, &token2, gnc, closure);
+	if (token2)
+	{
+	    if (strcmp(token2, "route") == 0)
+		*action_return = CONFIG_ACTION_ROUTE_UNMONITOR;
+	    else if (strcmp(token2, "interface") == 0)
+		*action_return = CONFIG_ACTION_INTERFACE_UNMONITOR;
+	    else if (strcmp(token2, "xroute") == 0)
+		*action_return = CONFIG_ACTION_XROUTE_UNMONITOR;
+	    else if (strcmp(token2, "neighbour") == 0)
+		*action_return = CONFIG_ACTION_NEIGHBOUR_UNMONITOR;
+	    free(token2);
+	    c = skip_eol(c, gnc, closure);
+	}
+	else // ummonitor was detected but none of the specialties - unmonitoring everything.
+	    c = -1;
      } else if(config_finalised && !local_server_write) {
          /* The remaining directives are only allowed in read-write mode. */
          c = skip_to_eol(c, gnc, closure);
diff --git a/configuration.h b/configuration.h
index 0ebfd48..fe6b522 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..01122f9 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_XROUTE);
+            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.20.1




More information about the Babel-users mailing list