diff --git a/RIOT/examples/dynamic_app/main.c b/RIOT/examples/dynamic_app/main.c index 496d851..c085164 100755 --- a/RIOT/examples/dynamic_app/main.c +++ b/RIOT/examples/dynamic_app/main.c @@ -156,6 +156,14 @@ int crea_rpl_dodag_root(char *arg1, char *arg2) printf("successfully added a new RPL DODAG\n"); return 0; } +int _gnrc_rpl_send_dis(void) +{ + gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes); + + puts("success: send a DIS\n"); + return 0; +} + /***************** /RPL functions ****************/ /*void *sock_time_server_thread(void *arg) @@ -365,12 +373,14 @@ static void _init_interface(void) } //init RPL //init_RPL(ifs[0]); + _gnrc_rpl_send_dis(); memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); /* model ipv6 addr: dead:beef::Hwaddr */ if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ crea_rpl_dodag_root("1", "dead:beef::3402"); + _gnrc_rpl_send_dis(); client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); // xtimer_usleep(200); //time_server=thread_create(sock_time_server_stack,sizeof(sock_time_server_stack),6,THREAD_CREATE_STACKTEST,sock_time_server_thread,NULL,"sock_time_server_thread"); diff --git a/RIOT/examples/gnrc_networking/Makefile b/RIOT/examples/gnrc_networking/Makefile index b2758eb..fb2498a 100755 --- a/RIOT/examples/gnrc_networking/Makefile +++ b/RIOT/examples/gnrc_networking/Makefile @@ -12,7 +12,7 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ microbit calliope-mini - +DISABLE_MODULE += net_gnrc_sixlowpan_iphc # Include packages that pull up and auto-init the link layer. # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present USEMODULE += gnrc_netdev_default diff --git a/RIOT/examples/real_time_app/main.c b/RIOT/examples/real_time_app/main.c index 5c2ad75..87d364e 100755 --- a/RIOT/examples/real_time_app/main.c +++ b/RIOT/examples/real_time_app/main.c @@ -27,6 +27,7 @@ #include #include "../../boards/stm32f4discovery/include/board.h" #include "../../boards/stm32f4discovery/include/periph_conf.h" +#include "periph/gpio.h" #include "net/sock/udp.h" #include "net/gnrc/ipv6.h" #include "net/af.h" @@ -80,14 +81,14 @@ #define PWM_FREQ 100 #define PWM_RES 100 -#define DEADLINE 24000 +#define DEADLINE 15000 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; // addr ipv6 link local node 2: fe80::3634:5110:3473:3762 uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62}; //addr ipv6 link local node 3: fe80::3634:5110:3471:3766 -uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x33,0x47,0x11,0x37,0x2c,0x34,0x12}; +uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e}; //static char _stack_server[GNRC_PKTDUMP_STACKSIZE]; char pwm_stack[THREAD_STACKSIZE_MAIN]; @@ -211,8 +212,20 @@ void *sock_server_thread(void *arg) if(tourne == 1) pwm_set(PWM_DEV(0),1,31); if(timer_run == 0) { + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { + puts("Error sending reply"); + } + gpio_clear(LED1_PIN); + gpio_clear(LED2_PIN); + gpio_set(LED0_PIN); timer_set(TIMER_DEV(1),0,25200); printf("relance timer\n"); + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { + puts("Error in synchronization"); + return NULL; + } + offset = sntp_get_offset(); + printf("offset : %i\n",(int)offset); timer_run = 1; } } @@ -225,6 +238,12 @@ void *sock_server_thread(void *arg) timer_run=0; timer_clear(TIMER_DEV(1),0); printf("clear timer\n"); + if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { + puts("Error sending reply"); + } + gpio_clear(LED2_PIN); + gpio_clear(LED0_PIN); + gpio_set(LED1_PIN); } if(deadline<=DEADLINE && compteur <5) { compteur++; @@ -241,9 +260,12 @@ void *sock_client_thread(void *arg) { (void) arg; Data data; + int vitesse=2; + uint8_t buf[3]; data.donnees[0] = 'g'; data.donnees[1] = 'o'; //uint8_t paquet[]; + ssize_t res; sock_udp_ep_t remote = { .family = AF_INET6 }; remote.port = 1234; @@ -252,18 +274,42 @@ void *sock_client_thread(void *arg) remote.addr.ipv6[2] = 0xbe; remote.addr.ipv6[3] = 0xef; remote.addr.ipv6[14] = 0x34; - remote.addr.ipv6[15] = 0x12; - // memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN); + remote.addr.ipv6[15] = 0x1e; + while (1) { - // //ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6, - // // IPV6_ADDR_MCAST_SCP_LINK_LOCAL); data.heure_actuelle = xtimer_now_usec(); - if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { puts("Error sending message"); } puts("Send a message"); - xtimer_sleep(2); + if(vitesse==2) { + gpio_clear(LED0_PIN); + gpio_toggle(LED1_PIN); + } + else { + gpio_clear(LED1_PIN); + gpio_toggle(LED0_PIN); + } + if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) { + if (res == -ETIMEDOUT) { + puts("Timed out"); + } + else { + puts("Error receiving message"); + } + } + else { + printf("Received message: \""); + for (int i = 0; i < res; i++) { + printf("%c", buf[i]); + } + if(buf[0] == 'n') + vitesse = 2; + else vitesse = 1; + printf("\"\n"); + } + xtimer_sleep(vitesse); } return NULL; } @@ -273,6 +319,9 @@ static void arret_urgence(void *arg,int channel) pwm_set(PWM_DEV(0),1,0); tourne = 0; timer_run = 0; + gpio_clear(LED0_PIN); + gpio_clear(LED1_PIN); + gpio_set(LED2_PIN); printf("Arret d'urgence\n"); } @@ -330,7 +379,7 @@ static void _init_pwm(void) if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x12; + tmp_addr.u8[15] = 0x1e; //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); tmp_addr.u8[14] = 0x37; @@ -338,21 +387,19 @@ static void _init_pwm(void) //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); - xtimer_usleep(10000); + //xtimer_usleep(10000); time_server=thread_create(sock_time_server_stack,sizeof(sock_time_server_stack),6,THREAD_CREATE_STACKTEST,sock_time_server_thread,NULL,"sock_time_server_thread"); - xtimer_usleep(200); + // xtimer_usleep(200); }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x12; + tmp_addr.u8[15] = 0x1e; //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); tmp_addr.u8[14] = 0x34; tmp_addr.u8[15] = 0x02; //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); - //sntp_sync(&local,5000); - //printf("temps : %i\n",(int)sntp_get_offset()); - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x12)){ + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ tmp_addr.u8[14] = 0x34; tmp_addr.u8[15] = 0x02; //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 @@ -362,9 +409,9 @@ static void _init_pwm(void) //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); //start_server("1234"); - _init_timer(); - _init_pwm(); - server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); + _init_timer(); + _init_pwm(); + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); }else{ diff --git a/RIOT/examples/statistique_app/Makefile b/RIOT/examples/statistique_app/Makefile new file mode 100755 index 0000000..0214b5c --- /dev/null +++ b/RIOT/examples/statistique_app/Makefile @@ -0,0 +1,67 @@ +# name of your application +APPLICATION = real_time_app + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ + nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \ + stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ + yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ + microbit calliope-mini + +# Include packages that pull up and auto-init the link layer. +USEMODULE += gnrc_sock_udp +USEMODULE += sntp +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present +USEMODULE += gnrc_netdev_default +USEMODULE += auto_init_gnrc_netif +# Specify the mandatory networking modules for IPv6 and UDP +USEMODULE += gnrc_ipv6_router_default +USEMODULE += gnrc_udp +# Add a routing protocol +USEMODULE += gnrc_rpl +#USEMODULE += auto_init_gnrc_rpl +# This application dumps received packets to STDIO using the pktdump module +#USEMODULE += gnrc_pktdump +# Additional networking modules that can be dropped if not needed +USEMODULE += gnrc_icmpv6_echo +# Add also the shell, some shell commands +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps +USEMODULE += netstats_l2 +USEMODULE += netstats_ipv6 +USEMODULE += netstats_rpl +#include our RF module +USEMODULE += at86rf231 +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +CFLAGS += -DDEVELHELP + +# Comment this out to join RPL DODAGs even if DIOs do not contain +# DODAG Configuration Options (see the doc for more info) +# CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include + +# Set a custom channel if needed +ifneq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz + DEFAULT_CHANNEL ?= 0 + CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) +else + ifneq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz + DEFAULT_CHANNEL ?= 5 + FLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL) + else # radio is IEEE 802.15.4 2.4 GHz + DEFAULT_CHANNEL ?= 26 + CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) + endif +endif diff --git a/RIOT/examples/statistique_app/main.c b/RIOT/examples/statistique_app/main.c new file mode 100755 index 0000000..6e1e5a6 --- /dev/null +++ b/RIOT/examples/statistique_app/main.c @@ -0,0 +1,309 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for demonstrating the RIOT network stack + * + * @author Hauke Petersen + * + * @} + */ +#include +#include +#include +#include +#include +#include + +#include +#include "../../boards/stm32f4discovery/include/board.h" +#include "../../boards/stm32f4discovery/include/periph_conf.h" +#include "periph/gpio.h" +#include "net/sock/udp.h" +#include "net/gnrc/ipv6.h" +#include "net/af.h" +#include "net/sixlowpan.h" +#include "net/gnrc/pktdump.h" +#include "shell.h" +#include "shell_commands.h" +#include "msg.h" +#include "thread.h" +#include "sched.h" +#include "thread.h" +#include "kernel_types.h" +#include "net/netstats.h" +#include "net/ipv6/addr.h" +#include "periph/timer.h" +#include "net/gnrc/ipv6/netif.h" +#include "net/gnrc/netif.h" +#include "net/gnrc/netapi.h" +#include "net/netopt.h" +#include "net/gnrc/pkt.h" +#include "net/gnrc/pktbuf.h" +#include "net/gnrc/netif/hdr.h" +#include "net/gnrc/sixlowpan/netif.h" +#include "net/fib.h" +#include "net/gnrc/udp.h" +#include "periph/pwm.h" +#include "od.h" +#include "net/sntp.h" +#include "net/ntp_packet.h" +#ifdef MODULE_SCHEDSTATISTICS +#include "xtimer.h" +#endif + +#ifdef MODULE_TLSF +#include "tlsf.h" +#endif + +#define MAIN_QUEUE_SIZE (8) +/** + * @brief The maximal expected link layer address length in byte + */ +#define MAX_ADDR_LEN (8U) + +/** + * @brief The default IPv6 prefix length if not specified. + */ +#define SC_NETIF_IPV6_DEFAULT_PREFIX_LEN (64) + +#define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) +#define MSG_TYPE_ISR (0x3456) + +#define PWM_FREQ 100 +#define PWM_RES 100 +#define DEADLINE 15000 + +// addr ipv6 link local node 1: fe80::3734:510e:3317:3402 +uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; +// addr ipv6 link local node 2: fe80::3634:5110:3473:3762 +uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62}; +//addr ipv6 link local node 3: fe80::3634:5110:3471:3766 +uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e}; + +//static char _stack_server[GNRC_PKTDUMP_STACKSIZE]; +char sock_server_stack[THREAD_STACKSIZE_MAIN]; +char sock_client_stack[THREAD_STACKSIZE_MAIN]; +char sock_time_server_stack[THREAD_STACKSIZE_MAIN]; +// static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, +// KERNEL_PID_UNDEF); +// +// kernel_pid_t gnrc_server_pid = KERNEL_PID_UNDEF; +// +kernel_pid_t server, client, time_server; +int ordre = 0; +int64_t offset = 0; +int timer_run = 0; +int tourne = 0; +sock_udp_ep_t local = SOCK_IPV6_EP_ANY; +sock_udp_t sock; +sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; +sock_udp_t sock_ntp; +static ntp_packet_t sntp_packet; + +typedef struct tableau { + uint32_t heure_actuelle; +}Data; + + +void *sock_time_server_thread(void *arg) +{ + (void) arg; + local_ntp.port = NTP_PORT; + + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { + puts("Error creating UDP sock"); + return NULL; + } + + while (1) { + sock_udp_ep_t remote; + ssize_t res; + + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, + &remote)) >= 0) { + puts("Received a message"); + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); + + // printf("%c\n",remote.addr.ipv6[15]); + //xtimer_ticks64_t now = xtimer_now64(); + // heure actuelle du serveur + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); + sntp_packet.origin.seconds=sntp_packet.transmit.seconds; + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); + //printf("heure actuelle : %lu\n",xtimer_now_usec()); + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); + //memset(&sntp_packet, 0, sizeof(sntp_packet)); + //ntp_packet_set_vn(&sntp_packet); + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { + puts("Error sending reply"); + } + } + } + return NULL; +} + +void *sock_server_thread(void *arg) +{ + (void) arg; + Data buf; + int deadline; + local.port = 1234; + sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 }; + ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402"); + + if (sock_udp_create(&sock, &local, NULL, 0) < 0) { + puts("Error creating UDP sock"); + return NULL; + } + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { + puts("Error in synchronization"); + return NULL; + } + offset = sntp_get_offset(); + printf("offset : %i\n",(int)offset); + + while (1) { + sock_udp_ep_t remote; + ssize_t res; + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT,&remote)) >= 0) { + deadline = xtimer_now_usec() + offset - buf.heure_actuelle; + printf("tps de transmission : %i\n",deadline); + } + } + return NULL; +} + +void *sock_client_thread(void *arg) +{ + (void) arg; + Data data; +// data.donnees[0] = 'g'; +// data.donnees[1] = 'o'; + //uint8_t paquet[]; + sock_udp_ep_t remote = { .family = AF_INET6 }; + + remote.port = 1234; + remote.addr.ipv6[0] = 0xde; + remote.addr.ipv6[1] = 0xad; + remote.addr.ipv6[2] = 0xbe; + remote.addr.ipv6[3] = 0xef; + remote.addr.ipv6[14] = 0x37; + remote.addr.ipv6[15] = 0x62; + + while (1) { + data.heure_actuelle = xtimer_now_usec(); + printf("%d\n",sizeof(data)); + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { + puts("Error sending message"); + } + xtimer_sleep(1); + } + return NULL; +} + + + + static void _init_interface(void) + { + kernel_pid_t ifs[GNRC_NETIF_NUMOF]; + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; + uint8_t hwaddr[MAX_ADDR_LEN]; + int res; + + gnrc_netif_get(ifs); + + //addresses gobales + addr.u8[0] = 0xde; + addr.u8[1] = 0xad; + addr.u8[2] = 0xbe; + addr.u8[3] = 0xef; + + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); + + if (res >= 0) { + addr.u8[14] = *hwaddr; + addr.u8[15] = *(hwaddr+1); + } + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); + + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); + /* model ipv6 addr: dead:beef::Hwaddr */ + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ + + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x1e; + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + tmp_addr.u8[14] = 0x37; + tmp_addr.u8[15] = 0x62; + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); + //xtimer_usleep(10000); + time_server=thread_create(sock_time_server_stack,sizeof(sock_time_server_stack),6,THREAD_CREATE_STACKTEST,sock_time_server_thread,NULL,"sock_time_server_thread"); + // xtimer_usleep(200); + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x1e; + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x02; + //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x02; + //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); tmp_addr.u8[14] = 0x37; + tmp_addr.u8[14] = 0x37; + tmp_addr.u8[15] = 0x62; + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + //start_server("1234"); + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); + + + }else{ + puts("new node ?"); + } + } + +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +extern int udp_cmd(int argc, char **argv); + +static const shell_command_t shell_commands[] = { + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, + { NULL, NULL, NULL } +}; + + +int main(void) +{ + + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT network stack example application"); + _init_interface(); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should be never reached */ + return 0; +} diff --git a/RIOT/examples/statistique_app/udp.c b/RIOT/examples/statistique_app/udp.c new file mode 100755 index 0000000..74189c1 --- /dev/null +++ b/RIOT/examples/statistique_app/udp.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Demonstrating the sending and receiving of UDP data + * + * @author Hauke Petersen + * + * @} + */ + +#include +#include + +#include "net/gnrc.h" +#include "net/gnrc/ipv6.h" +#include "net/gnrc/udp.h" +#include "net/gnrc/pktdump.h" +#include "timex.h" +#include "xtimer.h" + +//static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + // KERNEL_PID_UNDEF); + + +static void send(char *addr_str, char *port_str, char *data, unsigned int num, + unsigned int delay) +{ + uint16_t port; + ipv6_addr_t addr; + + /* parse destination address */ + if (ipv6_addr_from_str(&addr, addr_str) == NULL) { + puts("Error: unable to parse destination address"); + return; + } + /* parse port */ + port = (uint16_t)atoi(port_str); + if (port == 0) { + puts("Error: unable to parse destination port"); + return; + } + + for (unsigned int i = 0; i < num; i++) { + gnrc_pktsnip_t *payload, *udp, *ip; + unsigned payload_size; + /* allocate payload */ + payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF); + if (payload == NULL) { + puts("Error: unable to copy data to packet buffer"); + return; + } + /* store size for output */ + payload_size = (unsigned)payload->size; + /* allocate UDP header, set source port := destination port */ + udp = gnrc_udp_hdr_build(payload, port, port); + if (udp == NULL) { + puts("Error: unable to allocate UDP header"); + gnrc_pktbuf_release(payload); + return; + } + /* allocate IPv6 header */ + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); + if (ip == NULL) { + puts("Error: unable to allocate IPv6 header"); + gnrc_pktbuf_release(udp); + return; + } + /* send packet */ + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { + puts("Error: unable to locate UDP thread"); + gnrc_pktbuf_release(ip); + return; + } + /* access to `payload` was implicitly given up with the send operation above + * => use temporary variable for output */ + printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str, + port); + xtimer_usleep(delay); + } +} + +static void start_server(char *port_str) +{ +// uint16_t port; +// +// /* check if server is already running */ +// if (server.target.pid != KERNEL_PID_UNDEF) { +// printf("Error: server already running on port %" PRIu32 "\n", +// server.demux_ctx); +// return; +// } +// /* parse port */ +// port = (uint16_t)atoi(port_str); +// if (port == 0) { +// puts("Error: invalid port specified"); +// return; +// } +// /* start server (which means registering pktdump for the chosen port) */ +// server.target.pid = gnrc_pktdump_pid; +// server.demux_ctx = (uint32_t)port; +// gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); +// printf("Success: started UDP server on port %" PRIu16 "\n", port); +} + +static void stop_server(void) +{ +// /* check if server is running at all */ +// if (server.target.pid == KERNEL_PID_UNDEF) { +// printf("Error: server was not running\n"); +// return; +// } +// /* stop server */ +// gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server); +// server.target.pid = KERNEL_PID_UNDEF; +// puts("Success: stopped UDP server"); +} + +int udp_cmd(int argc, char **argv) +{ + if (argc < 2) { + printf("usage: %s [send|server]\n", argv[0]); + return 1; + } + + if (strcmp(argv[1], "send") == 0) { + uint32_t num = 1; + uint32_t delay = 1000000; + if (argc < 5) { + printf("usage: %s send [ []]\n", + argv[0]); + return 1; + } + if (argc > 5) { + num = (uint32_t)atoi(argv[5]); + } + if (argc > 6) { + delay = (uint32_t)atoi(argv[6]); + } + send(argv[2], argv[3], argv[4], num, delay); + } + else if (strcmp(argv[1], "server") == 0) { + if (argc < 3) { + printf("usage: %s server [start|stop]\n", argv[0]); + return 1; + } + if (strcmp(argv[2], "start") == 0) { + if (argc < 4) { + printf("usage %s server start \n", argv[0]); + return 1; + } + start_server(argv[3]); + } + else if (strcmp(argv[2], "stop") == 0) { + stop_server(); + } + else { + puts("error: invalid command"); + } + } + else { + puts("error: invalid command"); + } + return 0; +} diff --git a/RIOT/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c b/RIOT/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c index 5d97b9c..0831414 100755 --- a/RIOT/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c +++ b/RIOT/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c @@ -20,7 +20,7 @@ #include "net/gnrc/ipv6/hdr.h" #include "utlist.h" -#define ENABLE_DEBUG (0) +#define ENABLE_DEBUG (1) #include "debug.h" #if ENABLE_DEBUG @@ -108,5 +108,10 @@ void gnrc_icmpv6_echo_req_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6_hdr, gnrc_pktbuf_release(pkt); } } +/**************************************************************************/ +//Traceroute PFE7 + +//Traceroute PFE7 +/**************************************************************************/ /** @} */ diff --git a/RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c b/RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c index 68c1b12..38d8c43 100755 --- a/RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c +++ b/RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c @@ -906,7 +906,7 @@ static void _receive(gnrc_pktsnip_t *pkt) #ifdef MODULE_GNRC_IPV6_ROUTER /* only routers redirect */ /* redirect to next hop */ - DEBUG("ipv6: decrement hop limit to %u\n", (uint8_t) (hdr->hl - 1)); + printf("ipv6: decrement hop limit to %u\n", (uint8_t) (hdr->hl - 1)); /* RFC 4291, section 2.5.6 states: "Routers must not forward any * packets with Link-Local source or destination addresses to other @@ -923,7 +923,7 @@ static void _receive(gnrc_pktsnip_t *pkt) gnrc_pktsnip_t *reversed_pkt = NULL, *ptr = pkt; DEBUG("ipv6: forward packet to next hop\n"); - + printf ("transmission\n"); /* pkt might not be writable yet, if header was given above */ ipv6 = gnrc_pktbuf_start_write(ipv6); if (ipv6 == NULL) { diff --git a/RIOT/sys/net/gnrc/sock/udp/gnrc_sock_udp.c b/RIOT/sys/net/gnrc/sock/udp/gnrc_sock_udp.c index 86629cc..e203586 100755 --- a/RIOT/sys/net/gnrc/sock/udp/gnrc_sock_udp.c +++ b/RIOT/sys/net/gnrc/sock/udp/gnrc_sock_udp.c @@ -265,10 +265,12 @@ ssize_t sock_udp_send(sock_udp_t *sock, const void *data, size_t len, * there was no remote given on create, take from local */ rem.family = local.family; } + payload = gnrc_pktbuf_add(NULL, (void *)data, len, GNRC_NETTYPE_UNDEF); if (payload == NULL) { return -ENOMEM; } + pkt = gnrc_udp_hdr_build(payload, src_port, dst_port); if (pkt == NULL) { gnrc_pktbuf_release(payload); -- libgit2 0.21.2