1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

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.
This commit is contained in:
Benjamin Valentin 2021-12-03 17:43:23 +01:00
parent 48fc63e0ae
commit ce9017e71b
3 changed files with 28 additions and 4 deletions

View File

@ -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 $@

View File

@ -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

View File

@ -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;
}
}
}