1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #7966 from miri64/gnrc_netif2/fix/7424-follow-up

examples: tests: port applications to gnrc_netif2
This commit is contained in:
Martine Lenders 2017-11-13 20:32:02 +01:00 committed by GitHub
commit b573348be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 56 additions and 71 deletions

View File

@ -30,7 +30,7 @@
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
/* import "ifconfig" shell command, used for printing addresses */
extern int _netif_config(int argc, char **argv);
extern int _gnrc_netif2_config(int argc, char **argv);
int main(void)
{
@ -44,7 +44,7 @@ int main(void)
/* print network addresses */
puts("Configured network interfaces:");
_netif_config(0, NULL);
_gnrc_netif2_config(0, NULL);
/* initialize nanocoap server instance */
uint8_t buf[COAP_INBUF_SIZE];

View File

@ -13,7 +13,8 @@
*/
#include <string.h>
#include "net/gnrc/ipv6/netif.h"
#include "net/gnrc/netif2/internal.h"
#include "net/ipv6/ext/rh.h"
#include "net/gnrc/rpl/srh.h"
#define ENABLE_DEBUG (0)
@ -72,7 +73,7 @@ int gnrc_rpl_srh_process(ipv6_hdr_t *ipv6, gnrc_rpl_srh_t *rh)
tmp_addr_len = sizeof(ipv6_addr_t) - tmp_pref_elided;
}
memcpy(&tmp.u8[tmp_pref_elided], &addr_vec[k * compri_addr_len], tmp_addr_len);
if (gnrc_ipv6_netif_find_by_addr(NULL, &tmp) != KERNEL_PID_UNDEF) {
if (gnrc_netif2_get_by_ipv6_addr(&tmp) != NULL) {
if (found && ((k - found_pos) > 1)) {
DEBUG("RPL SRH: found multiple addresses that belong to me - discard\n");
/* TODO send an ICMP Parameter Problem (Code 0) and discard the packet */

View File

@ -7,7 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := msb-430 msb-430h nucleo32-f031 nucleo32-f042 \
nucleo32-l031 nucleo-f334 nucleo-l053 \
stm32f0discovery telosb z1
USEMODULE += gnrc_netdev
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
USEMODULE += enc28j60

View File

@ -7,7 +7,6 @@ BOARD_INSUFFICIENT_MEMORY := msb-430 msb-430h nucleo32-f031 nucleo32-f042 \
nucleo32-l031 nucleo-l053 stm32f0discovery telosb \
z1
USEMODULE += gnrc_netdev
USEMODULE += gnrc_netdev_default
USEMODULE += auto_init_gnrc_netif
USEMODULE += encx24j600

View File

@ -29,38 +29,39 @@
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/netreg.h"
#include "net/gnrc/netapi.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/netif2.h"
#include "net/gnrc/netif/hdr.h"
static void _init_interface(void)
{
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
gnrc_netif2_t *iface;
ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
gnrc_netif_get(ifs);
iface = gnrc_netif2_iter(NULL);
addr.u8[0] = 0xfd;
addr.u8[1] = 0x01;
addr.u8[15] = 0x02;
/* fd01::02 */
gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
addr.u8[15] = 0x03;
/* fd01::03 */
gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
/* add addresses fd01::02/64 and fd01::3/64 to interface */
for (uint8_t i = 0x2; i <= 0x3; i++) {
addr.u8[15] = i;
if (gnrc_netapi_set(iface->pid, NETOPT_IPV6_ADDR, 64U << 8U, &addr,
sizeof(addr)) < 0) {
printf("error: unable to add IPv6 address fd01::%x/64 to interface %u\n",
addr.u8[15], iface->pid);
}
}
}
static void _send_packet_raw(void)
{
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
gnrc_netif_get(ifs);
gnrc_netif2_t *iface = gnrc_netif2_iter(NULL);
gnrc_netif_hdr_t netif_hdr;
gnrc_netif_hdr_init(&netif_hdr, 8, 8);
netif_hdr.if_pid = ifs[0];
netif_hdr.if_pid = iface->pid;
uint8_t data[] = {
/* IPv6 Header */
@ -128,15 +129,13 @@ static void _send_packet_raw(void)
static void _send_packet_parsed(void)
{
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
gnrc_netif_get(ifs);
gnrc_netif2_t *iface = gnrc_netif2_iter(NULL);
gnrc_netif_hdr_t netif_hdr;
gnrc_netif_hdr_init(&netif_hdr, 8, 8);
netif_hdr.if_pid = ifs[0];
netif_hdr.if_pid = iface->pid;
uint8_t ipv6_data[] = {
/* IPv6 Header */

View File

@ -2,7 +2,7 @@
APPLICATION = gnrc_ipv6_nib
include ../Makefile.tests_common
BOARD_INSUFFICIENT_MEMORY := chronos nucleo32-f031 nucleo32-f042
BOARD_INSUFFICIENT_MEMORY := chronos nucleo32-f031 nucleo32-f042 nucleo32-l031
USEMODULE += gnrc_ipv6
USEMODULE += gnrc_ipv6_nib

View File

@ -2,7 +2,7 @@
APPLICATION = gnrc_ndp2
include ../Makefile.tests_common
BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 nucleo32-f042
BOARD_INSUFFICIENT_MEMORY := chronos nucleo32-f031 nucleo32-f042 nucleo32-l031
USEMODULE += gnrc_ipv6_nib
USEMODULE += gnrc_ndp2

View File

@ -24,34 +24,34 @@
#include "shell.h"
#include "msg.h"
#include "net/ipv6/addr.h"
#include "net/gnrc/ipv6/netif.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/netreg.h"
#include "net/gnrc/netapi.h"
#include "net/gnrc/netif.h"
#include "net/gnrc/netif2.h"
#include "net/gnrc/netif/hdr.h"
#include "net/gnrc/pktdump.h"
static void _init_interface(void)
{
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
gnrc_netif2_t *netif = gnrc_netif2_iter(NULL);
ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
gnrc_netif_get(ifs);
/* fd01::01 */
addr.u8[0] = 0xfd;
addr.u8[1] = 0x01;
addr.u8[15] = 0x01;
gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
if (gnrc_netapi_set(netif->pid, NETOPT_IPV6_ADDR, 64U << 8U, &addr,
sizeof(addr)) < 0) {
printf("error: unable to add IPv6 address fd01::1/64 to interface %u\n",
netif->pid);
}
}
static void _send_packet(void)
{
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
gnrc_netif_get(ifs);
gnrc_netif2_t *netif = gnrc_netif2_iter(NULL);
struct {
gnrc_netif_hdr_t netif_hdr;
@ -64,7 +64,7 @@ static void _send_packet(void)
gnrc_netif_hdr_init(&(netif_hdr.netif_hdr), 8, 8);
netif_hdr.netif_hdr.if_pid = ifs[0];
netif_hdr.netif_hdr.if_pid = netif->pid;
uint8_t data1[] = {
/* 6LoWPAN Header */

View File

@ -40,7 +40,7 @@ sock_udp_ep_t sock_dns_server;
/* import "ifconfig" shell command, used for printing addresses */
extern int _netif_config(int argc, char **argv);
extern int _gnrc_netif2_config(int argc, char **argv);
int main(void)
{
@ -53,7 +53,7 @@ int main(void)
/* print network addresses */
puts("Configured network interfaces:");
_netif_config(0, NULL);
_gnrc_netif2_config(0, NULL);
int res = sock_dns_query(TEST_NAME, addr, AF_UNSPEC);
if (res > 0) {

View File

@ -1,7 +1,7 @@
APPLICATION = gnrc_sock_udp
include ../Makefile.tests_common
BOARD_INSUFFICIENT_MEMORY := nucleo32-f031 nucleo32-f042
BOARD_INSUFFICIENT_MEMORY := chronos nucleo32-f031 nucleo32-f042
USEMODULE += gnrc_sock_check_reuse
USEMODULE += gnrc_sock_udp

View File

@ -11,6 +11,7 @@
#include "thread.h"
#include "net/af.h"
#include "net/gnrc/ipv6.h"
#include "net/gnrc/netif2.h"
#include "net/gnrc/tcp.h"
#define ENABLE_DEBUG (0)
@ -40,25 +41,24 @@ uint8_t bufs[CONNS][NBYTE];
uint8_t stacks[CONNS][THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF];
/* "ifconfig" shell command */
extern int _netif_config(int argc, char **argv);
extern int _gnrc_netif2_config(int argc, char **argv);
/* Server thread */
void *srv_thread(void *arg);
int main(void)
{
/* Get PID of the a network interface */
kernel_pid_t ifs[GNRC_NETIF_NUMOF];
size_t numof = gnrc_netif_get(ifs);
if (10 <= numof) {
gnrc_netif2_t *netif;
if (!(netif = gnrc_netif2_iter(NULL))) {
printf("No valid network interface found\n");
return -1;
}
/* Set pre-configured IP address */
char if_pid[] = {ifs[0] + '0', '\0'};
char if_pid[] = {netif->pid + '0', '\0'};
char *cmd[] = {"ifconfig", if_pid, "add", "unicast", LOCAL_ADDR};
_netif_config(5, cmd);
_gnrc_netif2_config(5, cmd);
/* Test configuration */
printf("\nStarting server: LOCAL_ADDR=%s, LOCAL_PORT=%d, ", LOCAL_ADDR, LOCAL_PORT);

View File

@ -9,8 +9,8 @@ FEATURES_REQUIRED += periph_timer # xtimer required for this application
USEMODULE += gnrc
USEMODULE += gnrc_neterr
USEMODULE += gnrc_netif
USEMODULE += gnrc_netdev
USEMODULE += gnrc_netif2
USEMODULE += netdev_eth
USEMODULE += netdev_test
USEMODULE += od

View File

@ -22,7 +22,7 @@
#include "msg.h"
#include "net/ethernet.h"
#include "net/gnrc.h"
#include "net/gnrc/netdev/eth.h"
#include "net/gnrc/netif2/ethernet.h"
#include "net/netdev_test.h"
#include "od.h"
#include "thread.h"
@ -53,7 +53,6 @@ static const uint8_t _test_dst[] = { 0xf5, 0x19, 0x9a, 0x1d, 0xd8, 0x8f };
static const uint8_t _test_src[] = { 0x41, 0x9b, 0x9f, 0x56, 0x36, 0x46 };
static char _mac_stack[_MAC_STACKSIZE];
static gnrc_netdev_t _gnrc_dev;
static netdev_test_t _dev;
static msg_t _main_msg_queue[_MAIN_MSG_QUEUE_SIZE];
static uint8_t _tmp[_EXP_LENGTH];
@ -197,15 +196,12 @@ static int test_receive(void)
puts("=================");
puts("expected");
puts("=================");
puts(gnrc_netif_addr_to_str(addr_str, sizeof(addr_str),
_test_src,
ETHERNET_ADDR_LEN));
puts(gnrc_netif2_addr_to_str(_test_src, ETHERNET_ADDR_LEN, addr_str));
puts("=================");
puts("received source");
puts("=================");
puts(gnrc_netif_addr_to_str(addr_str, sizeof(addr_str),
gnrc_netif_hdr_get_src_addr(hdr->data),
ETHERNET_ADDR_LEN));
puts(gnrc_netif2_addr_to_str(gnrc_netif_hdr_get_src_addr(hdr->data),
ETHERNET_ADDR_LEN, addr_str));
return 0;
}
if (memcmp(gnrc_netif_hdr_get_dst_addr(hdr->data), _dev_addr,
@ -215,15 +211,12 @@ static int test_receive(void)
puts("=================");
puts("expected");
puts("=================");
puts(gnrc_netif_addr_to_str(addr_str, sizeof(addr_str),
_dev_addr,
ETHERNET_ADDR_LEN));
puts(gnrc_netif2_addr_to_str(_dev_addr, ETHERNET_ADDR_LEN, addr_str));
puts("====================");
puts("received destination");
puts("====================");
puts(gnrc_netif_addr_to_str(addr_str, sizeof(addr_str),
gnrc_netif_hdr_get_dst_addr(hdr->data),
ETHERNET_ADDR_LEN));
puts(gnrc_netif2_addr_to_str(gnrc_netif_hdr_get_dst_addr(hdr->data),
ETHERNET_ADDR_LEN, addr_str));
return 0;
}
@ -265,13 +258,8 @@ int main(void)
netdev_test_set_send_cb(&_dev, _dev_send);
netdev_test_set_get_cb(&_dev, NETOPT_ADDRESS, _dev_get_addr);
netdev_test_set_set_cb(&_dev, NETOPT_ADDRESS, _dev_set_addr);
gnrc_netdev_eth_init(&_gnrc_dev, (netdev_t *)(&_dev));
_mac_pid = gnrc_netdev_init(_mac_stack, _MAC_STACKSIZE, _MAC_PRIO,
"gnrc_netdev_eth_test", &_gnrc_dev);
if (_mac_pid <= KERNEL_PID_UNDEF) {
puts("Could not start MAC thread\n");
return 1;
}
_mac_pid = gnrc_netif2_ethernet_create(_mac_stack, _MAC_STACKSIZE, _MAC_PRIO,
"netdev_test", (netdev_t *)&_dev)->pid;
/* test execution */
EXECUTE(test_get_addr);

View File

@ -24,7 +24,7 @@
void microcoap_server_loop(void);
/* import "ifconfig" shell command, used for printing addresses */
extern int _netif_config(int argc, char **argv);
extern int _gnrc_netif2_config(int argc, char **argv);
int main(void)
{
@ -35,7 +35,7 @@ int main(void)
/* print network addresses */
puts("Configured network interfaces:");
_netif_config(0, NULL);
_gnrc_netif2_config(0, NULL);
/* start coap server loop */
microcoap_server_loop();

View File

@ -1,5 +1,4 @@
USEMODULE += gnrc_ipv6_nib
USEMODULE += gnrc_ipv6_netif
CFLAGS += -DGNRC_IPV6_NIB_CONF_ROUTER=1
CFLAGS += -DGNRC_IPV6_NIB_NUMOF=16