public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@openmesh.com>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven.eckelmann@openmesh.com>
Subject: [B.A.T.M.A.N.] [PATCH 3/5] alfred: Check the TQ of master servers before pushing data
Date: Wed, 24 May 2017 12:32:09 +0200	[thread overview]
Message-ID: <20170524103211.810-3-sven.eckelmann@openmesh.com> (raw)
In-Reply-To: <4690435.IOLn72U8Ez@bentobox>

The TQ value of the server might have changed dramatically since we
received the last announcement of a master server. This can especially
happen when node (which was previously the best server) moves a lot and its
announcements are lost for a while.

Instead of querying the TQ values of each node when receiving an
announcement, just query the TQ value before new data should be pushed to a
master server.

Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
---
 alfred.h |  1 -
 recv.c   | 21 +--------------------
 server.c | 36 +++++++++++++++++++++++++++++++++++-
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/alfred.h b/alfred.h
index 5f7a98c..429953f 100644
--- a/alfred.h
+++ b/alfred.h
@@ -153,7 +153,6 @@ extern alfred_addr alfred_mcast;
 
 /* server.c */
 int alfred_server(struct globals *globals);
-int set_best_server(struct globals *globals);
 void changed_data_type(struct globals *globals, uint8_t arg);
 
 /* client.c */
diff --git a/recv.c b/recv.c
index 8aa512d..12bb3f1 100644
--- a/recv.c
+++ b/recv.c
@@ -268,7 +268,6 @@ process_alfred_announce_master(struct globals *globals,
 			       struct alfred_announce_master_v0 *announce)
 {
 	struct server *server;
-	struct ether_addr *macaddr;
 	struct ether_addr mac;
 	int ret;
 	int len;
@@ -296,6 +295,7 @@ process_alfred_announce_master(struct globals *globals,
 
 		memcpy(&server->hwaddr, &mac, ETH_ALEN);
 		memcpy(&server->address, source, sizeof(*source));
+		server->tq = 0;
 
 		if (hash_add(interface->server_hash, server)) {
 			free(server);
@@ -305,25 +305,6 @@ process_alfred_announce_master(struct globals *globals,
 
 	clock_gettime(CLOCK_MONOTONIC, &server->last_seen);
 
-	/* TQ is not used for master sync mode */
-	if (globals->opmode == OPMODE_MASTER) {
-		server->tq = 0;
-		return 0;
-	}
-
-	if (strcmp(globals->mesh_iface, "none") != 0) {
-		macaddr = translate_mac(globals->mesh_iface,
-					(struct ether_addr *)&server->hwaddr);
-		if (macaddr)
-			server->tq = get_tq(globals->mesh_iface, macaddr);
-		else
-			server->tq = 0;
-	} else {
-		server->tq = 255;
-	}
-
-	set_best_server(globals);
-
 	return 0;
 }
 
diff --git a/server.c b/server.c
index 2c4042a..09acb80 100644
--- a/server.c
+++ b/server.c
@@ -113,7 +113,7 @@ static int create_hashes(struct globals *globals)
 	return 0;
 }
 
-int set_best_server(struct globals *globals)
+static int set_best_server(struct globals *globals)
 {
 	struct hash_it_t *hashit = NULL;
 	struct server *best_server = NULL;
@@ -218,6 +218,39 @@ static int purge_data(struct globals *globals)
 	return 0;
 }
 
+static void update_server_info(struct globals *globals)
+{
+	struct hash_it_t *hashit = NULL;
+	struct interface *interface;
+	struct ether_addr *macaddr;
+
+	/* TQ is not used for master sync mode */
+	if (globals->opmode == OPMODE_MASTER)
+		return;
+
+	list_for_each_entry(interface, &globals->interfaces, list) {
+		while (NULL != (hashit = hash_iterate(interface->server_hash,
+						      hashit))) {
+			struct server *server = hashit->bucket->data;
+
+			if (strcmp(globals->mesh_iface, "none") == 0) {
+				server->tq = 255;
+				continue;
+			}
+
+			macaddr = translate_mac(globals->mesh_iface,
+						&server->hwaddr);
+			if (macaddr)
+				server->tq = get_tq(globals->mesh_iface,
+						    macaddr);
+			else
+				server->tq = 0;
+		}
+	}
+
+	set_best_server(globals);
+}
+
 static void check_if_socket(struct interface *interface, struct globals *globals)
 {
 	int sock;
@@ -422,6 +455,7 @@ int alfred_server(struct globals *globals)
 			sync_data(globals);
 		} else {
 			/* send local data to server */
+			update_server_info(globals);
 			push_local_data(globals);
 		}
 		purge_data(globals);
-- 
2.11.0


  parent reply	other threads:[~2017-05-24 10:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 10:31 [B.A.T.M.A.N.] [PATCH 0/5] alfred: TQ query optimizations Sven Eckelmann
2017-05-24 10:32 ` [B.A.T.M.A.N.] [PATCH 1/5] alfred: Move alfred specific netlink code in separate file Sven Eckelmann
2017-05-24 10:32 ` [B.A.T.M.A.N.] [PATCH 2/5] alfred: Only query tq of remote master in slave mode Sven Eckelmann
2017-05-24 10:32 ` Sven Eckelmann [this message]
2017-05-24 10:32 ` [B.A.T.M.A.N.] [PATCH 4/5] alfred: Cache the TQ values for each originator Sven Eckelmann
2017-05-24 10:32 ` [B.A.T.M.A.N.] [PATCH 5/5] alfred: Cache the global translation table entries Sven Eckelmann
2017-05-31 15:24 ` [B.A.T.M.A.N.] [PATCH 0/5] alfred: TQ query optimizations Simon Wunderlich
2017-06-01  6:15   ` Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170524103211.810-3-sven.eckelmann@openmesh.com \
    --to=sven.eckelmann@openmesh.com \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox