Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 5/6] test: introduce new SWIM packet filter by component names
Date: Fri, 12 Apr 2019 01:22:29 +0300	[thread overview]
Message-ID: <f1544845ec0eaae775a9bc954c540c48ef4649d6.1555021137.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1555021137.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1555021137.git.v.shpilevoy@tarantool.org>

In the next patch on payloads it is wanted to drop only packets
containing certain sections such as anti-entropy, dissemination.
New SWIM test transport filters allow to implement this with
ease.

Part of #3234
---
 test/unit/swim_test_utils.c | 54 +++++++++++++++++++++++++++++++++++++
 test/unit/swim_test_utils.h |  9 +++++++
 2 files changed, 63 insertions(+)

diff --git a/test/unit/swim_test_utils.c b/test/unit/swim_test_utils.c
index d933434e9..fd528d166 100644
--- a/test/unit/swim_test_utils.c
+++ b/test/unit/swim_test_utils.c
@@ -35,6 +35,7 @@
 #include "uuid/tt_uuid.h"
 #include "trivia/util.h"
 #include "fiber.h"
+#include "msgpuck.h"
 
 /**
  * SWIM cluster node and its UUID. UUID is stored separately
@@ -314,6 +315,59 @@ swim_cluster_set_drop_in(struct swim_cluster *cluster, int i, double value)
 	swim_cluster_set_drop_generic(cluster, i, value, true, false);
 }
 
+/**
+ * A list of components to drop used by component packet filter.
+ */
+struct swim_drop_components {
+	/** List of component body keys. */
+	const int *keys;
+	/** Length of @a keys. */
+	int key_count;
+};
+
+/**
+ * Check if a packet contains any of the components to filter out.
+ */
+static bool
+swim_filter_drop_component(const char *data, int size, void *udata, int dir)
+{
+	(void) size;
+	(void) dir;
+	struct swim_drop_components *dc = (struct swim_drop_components *) udata;
+	/* Skip meta. */
+	mp_next(&data);
+	int map_size = mp_decode_map(&data);
+	for (int i = 0; i < map_size; ++i) {
+		int key = mp_decode_uint(&data);
+		for (int j = 0; j < dc->key_count; ++j) {
+			if (dc->keys[j] == key)
+				return true;
+		}
+		/* Skip value. */
+		mp_next(&data);
+	}
+	return false;
+}
+
+void
+swim_cluster_drop_components(struct swim_cluster *cluster, int i,
+			     const int *keys, int key_count)
+{
+	int fd = swim_fd(swim_cluster_node(cluster, i));
+	if (key_count == 0) {
+		swim_test_transport_remove_filter(fd,
+						  swim_filter_drop_component);
+		return;
+	}
+	struct swim_drop_components *dc =
+		(struct swim_drop_components *) malloc(sizeof(*dc));
+	assert(dc != NULL);
+	dc->key_count = key_count;
+	dc->keys = keys;
+	swim_test_transport_add_filter(fd, swim_filter_drop_component, free,
+				       dc);
+}
+
 /** Check if @a s1 knows every member of @a s2's table. */
 static inline bool
 swim1_contains_swim2(struct swim *s1, struct swim *s2)
diff --git a/test/unit/swim_test_utils.h b/test/unit/swim_test_utils.h
index af428c792..6ea136e36 100644
--- a/test/unit/swim_test_utils.h
+++ b/test/unit/swim_test_utils.h
@@ -109,6 +109,15 @@ swim_cluster_set_drop_out(struct swim_cluster *cluster, int i, double value);
 void
 swim_cluster_set_drop_in(struct swim_cluster *cluster, int i, double value);
 
+/**
+ * Drop all packets from/to a SWIM instance with id @a i
+ * containing components specified in @a keys. Components are
+ * defined by the constants in the packet body.
+ */
+void
+swim_cluster_drop_components(struct swim_cluster *cluster, int i,
+			     const int *keys, int key_count);
+
 /**
  * Explicitly add a member of id @a from_id to a member of id
  * @a to_id.
-- 
2.17.2 (Apple Git-113)

  parent reply	other threads:[~2019-04-11 22:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 22:22 [tarantool-patches] [PATCH 0/6] swim payload Vladislav Shpilevoy
2019-04-11 22:22 ` [tarantool-patches] [PATCH 1/6] swim: factor out MP_BIN decoding from swim_decode_uuid Vladislav Shpilevoy
2019-04-11 23:09   ` [tarantool-patches] " Konstantin Osipov
2019-04-12 19:23     ` Vladislav Shpilevoy
2019-04-11 22:22 ` [tarantool-patches] [PATCH 2/6] swim: replace event_bin and member_bin with the passport Vladislav Shpilevoy
2019-04-11 23:10   ` [tarantool-patches] " Konstantin Osipov
2019-04-12 19:23     ` Vladislav Shpilevoy
2019-04-11 22:22 ` [tarantool-patches] [PATCH 3/6] swim: factor out 'update' part of swim_member_upsert() Vladislav Shpilevoy
2019-04-11 23:11   ` [tarantool-patches] " Konstantin Osipov
2019-04-12 19:23     ` Vladislav Shpilevoy
2019-04-11 22:22 ` [tarantool-patches] [PATCH 4/6] test: generalize SWIM fake descriptor filters Vladislav Shpilevoy
2019-04-11 23:11   ` [tarantool-patches] " Konstantin Osipov
2019-04-12 19:23     ` Vladislav Shpilevoy
2019-04-11 22:22 ` Vladislav Shpilevoy [this message]
2019-04-11 23:11   ` [tarantool-patches] Re: [PATCH 5/6] test: introduce new SWIM packet filter by component names Konstantin Osipov
2019-04-12 19:23     ` Vladislav Shpilevoy
2019-04-11 22:22 ` [tarantool-patches] [PATCH 6/6] swim: introduce payload Vladislav Shpilevoy
2019-04-18 15:12   ` [tarantool-patches] " Konstantin Osipov
2019-04-18 17:43     ` Vladislav Shpilevoy
2019-04-18 18:03       ` Konstantin Osipov
2019-04-18 20:40         ` Vladislav Shpilevoy
2019-04-18 17:43 ` [tarantool-patches] [PATCH 5.5/6] swim: rename TTL to TTD Vladislav Shpilevoy
2019-04-18 17:48   ` [tarantool-patches] " Konstantin Osipov
2019-04-18 20:40     ` Vladislav Shpilevoy
2019-04-18 18:16 ` [tarantool-patches] [PATCH 7/6] swim: drop incarnation_inc parameter from update() routines Vladislav Shpilevoy
2019-04-18 18:20   ` [tarantool-patches] " Konstantin Osipov
2019-04-18 20:40     ` Vladislav Shpilevoy

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=f1544845ec0eaae775a9bc954c540c48ef4649d6.1555021137.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 5/6] test: introduce new SWIM packet filter by component names' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox