mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #17338 from benpicco/tools/zep_dispatch-mac_pin
tools/zep_dispatch: allow to pin nodes to MAC address
This commit is contained in:
commit
32def76a3c
2
dist/tools/zep_dispatch/Makefile
vendored
2
dist/tools/zep_dispatch/Makefile
vendored
@ -22,6 +22,8 @@ RIOT_INCLUDE += -I$(RIOTBASE)/sys/include
|
||||
|
||||
SRCS := main.c topology.c zep_parser.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
|
||||
|
||||
$(DISPATCH): $(SRCS) bin
|
||||
$(CC) $(CFLAGS) $(CFLAGS_EXTRA) $(SRCS) -o $@
|
||||
|
3
dist/tools/zep_dispatch/example.topo
vendored
3
dist/tools/zep_dispatch/example.topo
vendored
@ -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
|
||||
|
27
dist/tools/zep_dispatch/topology.c
vendored
27
dist/tools/zep_dispatch/topology.c
vendored
@ -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";
|
||||
}
|
||||
@ -264,9 +276,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -49,6 +49,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
|
||||
|
Loading…
Reference in New Issue
Block a user