From ce9017e71b74fecfea0ce8c3a21d24babeaba926 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 3 Dec 2021 17:43:23 +0100 Subject: [PATCH 1/2] tools/zep_dispatch: allow to pin nodes to MAC address Positions in the topology are handed out first come first serve. This makes it hard to have a reproducable setup if the ZEP dispatcher is restarted (e.g. to modify the topology). Fix this by allowing to specify a MAC address for each node. If a node with a pinned MAC address connects, it will always be assigned to the same topology node. --- dist/tools/zep_dispatch/Makefile | 2 ++ dist/tools/zep_dispatch/example.topo | 3 +++ dist/tools/zep_dispatch/topology.c | 27 +++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/dist/tools/zep_dispatch/Makefile b/dist/tools/zep_dispatch/Makefile index 9e4ffed41f..97cedb1284 100644 --- a/dist/tools/zep_dispatch/Makefile +++ b/dist/tools/zep_dispatch/Makefile @@ -21,6 +21,8 @@ RIOT_INCLUDE += -I$(RIOTBASE)/sys/include SRCS := $(wildcard *.c) SRCS += $(RIOTBASE)/sys/net/link_layer/ieee802154/ieee802154.c +SRCS += $(RIOTBASE)/sys/fmt/fmt.c +SRCS += $(RIOTBASE)/sys/net/link_layer/l2util/l2util.c $(BINARY): $(SRCS) $(CC) $(CFLAGS) $(CFLAGS_EXTRA) $(SRCS) -o $@ diff --git a/dist/tools/zep_dispatch/example.topo b/dist/tools/zep_dispatch/example.topo index 7e46fc4980..f55bd7f131 100644 --- a/dist/tools/zep_dispatch/example.topo +++ b/dist/tools/zep_dispatch/example.topo @@ -1,3 +1,6 @@ +# uncomment to pin node A to a specific MAC address +# A := BA:7C:18:E4:C0:45:65:AF + # A and B are connected with an ideal link A B # A and C are connected with a symmetric link with 10% packet loss diff --git a/dist/tools/zep_dispatch/topology.c b/dist/tools/zep_dispatch/topology.c index 1eabfb6907..f56c73b2a5 100644 --- a/dist/tools/zep_dispatch/topology.c +++ b/dist/tools/zep_dispatch/topology.c @@ -37,6 +37,8 @@ struct edge { float weight_b_a; }; +size_t l2util_addr_from_str(const char *str, uint8_t *out); + static char *_fmt_addr(char *out, size_t out_len, const uint8_t *addr, uint8_t addr_len) { char *start = out; @@ -70,9 +72,8 @@ static struct node *_find_or_create_node(list_node_t *nodes, const char *name) struct node *node = _find_node_by_name(nodes, name); if (node == NULL) { - node = malloc(sizeof(*node)); + node = calloc(1, sizeof(*node)); strncpy(node->name, name, sizeof(node->name) - 1); - node->mac_len = 0; list_add(nodes, &node->next); } @@ -96,6 +97,17 @@ static bool _parse_line(char *line, list_node_t *nodes, list_node_t *edges) return false; } + /* add node with a defined MAC address */ + if (strcmp(b, ":=") == 0) { + struct node *n = _find_or_create_node(nodes, a); + if (n == NULL) { + return false; + } + + n->mac_len = l2util_addr_from_str(e_ab, n->mac); + return true; + } + if (e_ab == NULL) { e_ab = "1"; } @@ -255,9 +267,16 @@ bool topology_add(topology_t *t, const uint8_t *mac, uint8_t mac_len, continue; } - /* abort if node is already in list */ + /* node is already in the list - either it is connected or MAC was pinned */ if (memcmp(super->mac, mac, mac_len) == 0) { - return true; + if (super->addr.sin6_port == addr->sin6_port) { + /* abort if node is already connected */ + return true; + } else { + /* use pre-allocated node */ + empty = super; + break; + } } } From 92d245de3b6172731367b9e3af7dbfec400c835f Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 3 Dec 2021 18:29:41 +0100 Subject: [PATCH 2/2] examples/gnrc_{networking, border_router}: allow to set ZEP L2 address --- examples/gnrc_border_router/Makefile.native.conf | 5 +++++ examples/gnrc_networking/Makefile | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index 013bc5d88d..d6dcab5c9f 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -23,3 +23,8 @@ TERMPROG ?= sudo $(RIOTTOOLS)/zep_dispatch/start_network.sh $(TERMPROG_FLAGS) # -z [::1]:$PORT for each ZEP device TERMFLAGS ?= $(patsubst %,-z [::1]:%, $(shell seq $(ZEP_PORT_BASE) $(ZEP_PORT_MAX))) + +# set optional ZEP l2 address +ifneq (,$(ZEP_MAC)) + TERMFLAGS += --eui64=$(ZEP_MAC) +endif diff --git a/examples/gnrc_networking/Makefile b/examples/gnrc_networking/Makefile index f52d8cb532..858fa72527 100644 --- a/examples/gnrc_networking/Makefile +++ b/examples/gnrc_networking/Makefile @@ -52,6 +52,10 @@ ZEP_PORT_BASE ?= 17754 ifeq (1,$(USE_ZEP)) TERMFLAGS += -z [::1]:$(ZEP_PORT_BASE) USEMODULE += socket_zep + + ifneq (,$(ZEP_MAC)) + TERMFLAGS += --eui64=$(ZEP_MAC) + endif endif # Uncomment the following 2 lines to specify static link lokal IPv6 address