Commit eb2661bde66e12a9b064c0d332978bedc49a61d2
Merge branch 'master' of https://archives.plil.fr/mobeissa/PFE7
fusion necessaire
Showing
9 changed files
with
636 additions
and
22 deletions
Show diff stats
RIOT/examples/dynamic_app/main.c
... | ... | @@ -156,6 +156,14 @@ int crea_rpl_dodag_root(char *arg1, char *arg2) |
156 | 156 | printf("successfully added a new RPL DODAG\n"); |
157 | 157 | return 0; |
158 | 158 | } |
159 | +int _gnrc_rpl_send_dis(void) | |
160 | +{ | |
161 | + gnrc_rpl_send_DIS(NULL, (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes); | |
162 | + | |
163 | + puts("success: send a DIS\n"); | |
164 | + return 0; | |
165 | +} | |
166 | + | |
159 | 167 | /***************** /RPL functions ****************/ |
160 | 168 | |
161 | 169 | /*void *sock_time_server_thread(void *arg) |
... | ... | @@ -365,12 +373,14 @@ static void _init_interface(void) |
365 | 373 | } |
366 | 374 | //init RPL |
367 | 375 | //init_RPL(ifs[0]); |
376 | + _gnrc_rpl_send_dis(); | |
368 | 377 | memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); |
369 | 378 | |
370 | 379 | gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); |
371 | 380 | /* model ipv6 addr: dead:beef::Hwaddr */ |
372 | 381 | if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ |
373 | 382 | crea_rpl_dodag_root("1", "dead:beef::3402"); |
383 | + _gnrc_rpl_send_dis(); | |
374 | 384 | client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); |
375 | 385 | // xtimer_usleep(200); |
376 | 386 | //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"); | ... | ... |
RIOT/examples/gnrc_networking/Makefile
... | ... | @@ -12,7 +12,7 @@ BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ |
12 | 12 | stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ |
13 | 13 | yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ |
14 | 14 | microbit calliope-mini |
15 | - | |
15 | +DISABLE_MODULE += net_gnrc_sixlowpan_iphc | |
16 | 16 | # Include packages that pull up and auto-init the link layer. |
17 | 17 | # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present |
18 | 18 | USEMODULE += gnrc_netdev_default | ... | ... |
RIOT/examples/real_time_app/main.c
... | ... | @@ -27,6 +27,7 @@ |
27 | 27 | #include <arpa/inet.h> |
28 | 28 | #include "../../boards/stm32f4discovery/include/board.h" |
29 | 29 | #include "../../boards/stm32f4discovery/include/periph_conf.h" |
30 | +#include "periph/gpio.h" | |
30 | 31 | #include "net/sock/udp.h" |
31 | 32 | #include "net/gnrc/ipv6.h" |
32 | 33 | #include "net/af.h" |
... | ... | @@ -80,14 +81,14 @@ |
80 | 81 | |
81 | 82 | #define PWM_FREQ 100 |
82 | 83 | #define PWM_RES 100 |
83 | -#define DEADLINE 24000 | |
84 | +#define DEADLINE 15000 | |
84 | 85 | |
85 | 86 | // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 |
86 | 87 | uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; |
87 | 88 | // addr ipv6 link local node 2: fe80::3634:5110:3473:3762 |
88 | 89 | uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62}; |
89 | 90 | //addr ipv6 link local node 3: fe80::3634:5110:3471:3766 |
90 | -uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x33,0x47,0x11,0x37,0x2c,0x34,0x12}; | |
91 | +uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e}; | |
91 | 92 | |
92 | 93 | //static char _stack_server[GNRC_PKTDUMP_STACKSIZE]; |
93 | 94 | char pwm_stack[THREAD_STACKSIZE_MAIN]; |
... | ... | @@ -211,8 +212,20 @@ void *sock_server_thread(void *arg) |
211 | 212 | if(tourne == 1) |
212 | 213 | pwm_set(PWM_DEV(0),1,31); |
213 | 214 | if(timer_run == 0) { |
215 | + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { | |
216 | + puts("Error sending reply"); | |
217 | + } | |
218 | + gpio_clear(LED1_PIN); | |
219 | + gpio_clear(LED2_PIN); | |
220 | + gpio_set(LED0_PIN); | |
214 | 221 | timer_set(TIMER_DEV(1),0,25200); |
215 | 222 | printf("relance timer\n"); |
223 | + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
224 | + puts("Error in synchronization"); | |
225 | + return NULL; | |
226 | + } | |
227 | + offset = sntp_get_offset(); | |
228 | + printf("offset : %i\n",(int)offset); | |
216 | 229 | timer_run = 1; |
217 | 230 | } |
218 | 231 | } |
... | ... | @@ -225,6 +238,12 @@ void *sock_server_thread(void *arg) |
225 | 238 | timer_run=0; |
226 | 239 | timer_clear(TIMER_DEV(1),0); |
227 | 240 | printf("clear timer\n"); |
241 | + if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { | |
242 | + puts("Error sending reply"); | |
243 | + } | |
244 | + gpio_clear(LED2_PIN); | |
245 | + gpio_clear(LED0_PIN); | |
246 | + gpio_set(LED1_PIN); | |
228 | 247 | } |
229 | 248 | if(deadline<=DEADLINE && compteur <5) { |
230 | 249 | compteur++; |
... | ... | @@ -241,9 +260,12 @@ void *sock_client_thread(void *arg) |
241 | 260 | { |
242 | 261 | (void) arg; |
243 | 262 | Data data; |
263 | + int vitesse=2; | |
264 | + uint8_t buf[3]; | |
244 | 265 | data.donnees[0] = 'g'; |
245 | 266 | data.donnees[1] = 'o'; |
246 | 267 | //uint8_t paquet[]; |
268 | + ssize_t res; | |
247 | 269 | sock_udp_ep_t remote = { .family = AF_INET6 }; |
248 | 270 | |
249 | 271 | remote.port = 1234; |
... | ... | @@ -252,18 +274,42 @@ void *sock_client_thread(void *arg) |
252 | 274 | remote.addr.ipv6[2] = 0xbe; |
253 | 275 | remote.addr.ipv6[3] = 0xef; |
254 | 276 | remote.addr.ipv6[14] = 0x34; |
255 | - remote.addr.ipv6[15] = 0x12; | |
256 | - // memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN); | |
277 | + remote.addr.ipv6[15] = 0x1e; | |
278 | + | |
257 | 279 | while (1) { |
258 | - // //ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6, | |
259 | - // // IPV6_ADDR_MCAST_SCP_LINK_LOCAL); | |
260 | 280 | data.heure_actuelle = xtimer_now_usec(); |
261 | 281 | |
262 | - if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { | |
282 | + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { | |
263 | 283 | puts("Error sending message"); |
264 | 284 | } |
265 | 285 | puts("Send a message"); |
266 | - xtimer_sleep(2); | |
286 | + if(vitesse==2) { | |
287 | + gpio_clear(LED0_PIN); | |
288 | + gpio_toggle(LED1_PIN); | |
289 | + } | |
290 | + else { | |
291 | + gpio_clear(LED1_PIN); | |
292 | + gpio_toggle(LED0_PIN); | |
293 | + } | |
294 | + if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) { | |
295 | + if (res == -ETIMEDOUT) { | |
296 | + puts("Timed out"); | |
297 | + } | |
298 | + else { | |
299 | + puts("Error receiving message"); | |
300 | + } | |
301 | + } | |
302 | + else { | |
303 | + printf("Received message: \""); | |
304 | + for (int i = 0; i < res; i++) { | |
305 | + printf("%c", buf[i]); | |
306 | + } | |
307 | + if(buf[0] == 'n') | |
308 | + vitesse = 2; | |
309 | + else vitesse = 1; | |
310 | + printf("\"\n"); | |
311 | + } | |
312 | + xtimer_sleep(vitesse); | |
267 | 313 | } |
268 | 314 | return NULL; |
269 | 315 | } |
... | ... | @@ -273,6 +319,9 @@ static void arret_urgence(void *arg,int channel) |
273 | 319 | pwm_set(PWM_DEV(0),1,0); |
274 | 320 | tourne = 0; |
275 | 321 | timer_run = 0; |
322 | + gpio_clear(LED0_PIN); | |
323 | + gpio_clear(LED1_PIN); | |
324 | + gpio_set(LED2_PIN); | |
276 | 325 | printf("Arret d'urgence\n"); |
277 | 326 | } |
278 | 327 | |
... | ... | @@ -330,7 +379,7 @@ static void _init_pwm(void) |
330 | 379 | if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ |
331 | 380 | |
332 | 381 | tmp_addr.u8[14] = 0x34; |
333 | - tmp_addr.u8[15] = 0x12; | |
382 | + tmp_addr.u8[15] = 0x1e; | |
334 | 383 | //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 |
335 | 384 | fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); |
336 | 385 | tmp_addr.u8[14] = 0x37; |
... | ... | @@ -338,21 +387,19 @@ static void _init_pwm(void) |
338 | 387 | //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 |
339 | 388 | fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); |
340 | 389 | client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); |
341 | - xtimer_usleep(10000); | |
390 | + //xtimer_usleep(10000); | |
342 | 391 | 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"); |
343 | - xtimer_usleep(200); | |
392 | + // xtimer_usleep(200); | |
344 | 393 | }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ |
345 | 394 | tmp_addr.u8[14] = 0x34; |
346 | - tmp_addr.u8[15] = 0x12; | |
395 | + tmp_addr.u8[15] = 0x1e; | |
347 | 396 | //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 |
348 | 397 | fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); |
349 | 398 | tmp_addr.u8[14] = 0x34; |
350 | 399 | tmp_addr.u8[15] = 0x02; |
351 | 400 | //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 |
352 | 401 | fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); |
353 | - //sntp_sync(&local,5000); | |
354 | - //printf("temps : %i\n",(int)sntp_get_offset()); | |
355 | - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x12)){ | |
402 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ | |
356 | 403 | tmp_addr.u8[14] = 0x34; |
357 | 404 | tmp_addr.u8[15] = 0x02; |
358 | 405 | //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 |
... | ... | @@ -362,9 +409,9 @@ static void _init_pwm(void) |
362 | 409 | //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 |
363 | 410 | fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); |
364 | 411 | //start_server("1234"); |
365 | - _init_timer(); | |
366 | - _init_pwm(); | |
367 | - server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
412 | + _init_timer(); | |
413 | + _init_pwm(); | |
414 | + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
368 | 415 | |
369 | 416 | |
370 | 417 | }else{ | ... | ... |
... | ... | @@ -0,0 +1,67 @@ |
1 | +# name of your application | |
2 | +APPLICATION = real_time_app | |
3 | + | |
4 | +# If no BOARD is found in the environment, use this default: | |
5 | +BOARD ?= native | |
6 | + | |
7 | +# This has to be the absolute path to the RIOT base directory: | |
8 | +RIOTBASE ?= $(CURDIR)/../.. | |
9 | + | |
10 | +BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ | |
11 | + nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \ | |
12 | + stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ | |
13 | + yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ | |
14 | + microbit calliope-mini | |
15 | + | |
16 | +# Include packages that pull up and auto-init the link layer. | |
17 | +USEMODULE += gnrc_sock_udp | |
18 | +USEMODULE += sntp | |
19 | +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present | |
20 | +USEMODULE += gnrc_netdev_default | |
21 | +USEMODULE += auto_init_gnrc_netif | |
22 | +# Specify the mandatory networking modules for IPv6 and UDP | |
23 | +USEMODULE += gnrc_ipv6_router_default | |
24 | +USEMODULE += gnrc_udp | |
25 | +# Add a routing protocol | |
26 | +USEMODULE += gnrc_rpl | |
27 | +#USEMODULE += auto_init_gnrc_rpl | |
28 | +# This application dumps received packets to STDIO using the pktdump module | |
29 | +#USEMODULE += gnrc_pktdump | |
30 | +# Additional networking modules that can be dropped if not needed | |
31 | +USEMODULE += gnrc_icmpv6_echo | |
32 | +# Add also the shell, some shell commands | |
33 | +USEMODULE += shell | |
34 | +USEMODULE += shell_commands | |
35 | +USEMODULE += ps | |
36 | +USEMODULE += netstats_l2 | |
37 | +USEMODULE += netstats_ipv6 | |
38 | +USEMODULE += netstats_rpl | |
39 | +#include our RF module | |
40 | +USEMODULE += at86rf231 | |
41 | +# Comment this out to disable code in RIOT that does safety checking | |
42 | +# which is not needed in a production environment but helps in the | |
43 | +# development process: | |
44 | +CFLAGS += -DDEVELHELP | |
45 | + | |
46 | +# Comment this out to join RPL DODAGs even if DIOs do not contain | |
47 | +# DODAG Configuration Options (see the doc for more info) | |
48 | +# CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN | |
49 | + | |
50 | +# Change this to 0 show compiler invocation lines by default: | |
51 | +QUIET ?= 1 | |
52 | + | |
53 | +include $(RIOTBASE)/Makefile.include | |
54 | + | |
55 | +# Set a custom channel if needed | |
56 | +ifneq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz | |
57 | + DEFAULT_CHANNEL ?= 0 | |
58 | + CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) | |
59 | +else | |
60 | + ifneq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz | |
61 | + DEFAULT_CHANNEL ?= 5 | |
62 | + FLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL) | |
63 | + else # radio is IEEE 802.15.4 2.4 GHz | |
64 | + DEFAULT_CHANNEL ?= 26 | |
65 | + CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) | |
66 | + endif | |
67 | +endif | ... | ... |
... | ... | @@ -0,0 +1,309 @@ |
1 | +/* | |
2 | + * Copyright (C) 2015 Freie Universitรคt Berlin | |
3 | + * | |
4 | + * This file is subject to the terms and conditions of the GNU Lesser | |
5 | + * General Public License v2.1. See the file LICENSE in the top level | |
6 | + * directory for more details. | |
7 | + */ | |
8 | + | |
9 | +/** | |
10 | + * @ingroup examples | |
11 | + * @{ | |
12 | + * | |
13 | + * @file | |
14 | + * @brief Example application for demonstrating the RIOT network stack | |
15 | + * | |
16 | + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> | |
17 | + * | |
18 | + * @} | |
19 | + */ | |
20 | +#include <stdbool.h> | |
21 | +#include <stdint.h> | |
22 | +#include <stdio.h> | |
23 | +#include <stdlib.h> | |
24 | +#include <string.h> | |
25 | +#include <inttypes.h> | |
26 | + | |
27 | +#include <arpa/inet.h> | |
28 | +#include "../../boards/stm32f4discovery/include/board.h" | |
29 | +#include "../../boards/stm32f4discovery/include/periph_conf.h" | |
30 | +#include "periph/gpio.h" | |
31 | +#include "net/sock/udp.h" | |
32 | +#include "net/gnrc/ipv6.h" | |
33 | +#include "net/af.h" | |
34 | +#include "net/sixlowpan.h" | |
35 | +#include "net/gnrc/pktdump.h" | |
36 | +#include "shell.h" | |
37 | +#include "shell_commands.h" | |
38 | +#include "msg.h" | |
39 | +#include "thread.h" | |
40 | +#include "sched.h" | |
41 | +#include "thread.h" | |
42 | +#include "kernel_types.h" | |
43 | +#include "net/netstats.h" | |
44 | +#include "net/ipv6/addr.h" | |
45 | +#include "periph/timer.h" | |
46 | +#include "net/gnrc/ipv6/netif.h" | |
47 | +#include "net/gnrc/netif.h" | |
48 | +#include "net/gnrc/netapi.h" | |
49 | +#include "net/netopt.h" | |
50 | +#include "net/gnrc/pkt.h" | |
51 | +#include "net/gnrc/pktbuf.h" | |
52 | +#include "net/gnrc/netif/hdr.h" | |
53 | +#include "net/gnrc/sixlowpan/netif.h" | |
54 | +#include "net/fib.h" | |
55 | +#include "net/gnrc/udp.h" | |
56 | +#include "periph/pwm.h" | |
57 | +#include "od.h" | |
58 | +#include "net/sntp.h" | |
59 | +#include "net/ntp_packet.h" | |
60 | +#ifdef MODULE_SCHEDSTATISTICS | |
61 | +#include "xtimer.h" | |
62 | +#endif | |
63 | + | |
64 | +#ifdef MODULE_TLSF | |
65 | +#include "tlsf.h" | |
66 | +#endif | |
67 | + | |
68 | +#define MAIN_QUEUE_SIZE (8) | |
69 | +/** | |
70 | + * @brief The maximal expected link layer address length in byte | |
71 | + */ | |
72 | +#define MAX_ADDR_LEN (8U) | |
73 | + | |
74 | +/** | |
75 | + * @brief The default IPv6 prefix length if not specified. | |
76 | + */ | |
77 | +#define SC_NETIF_IPV6_DEFAULT_PREFIX_LEN (64) | |
78 | + | |
79 | +#define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) | |
80 | +#define MSG_TYPE_ISR (0x3456) | |
81 | + | |
82 | +#define PWM_FREQ 100 | |
83 | +#define PWM_RES 100 | |
84 | +#define DEADLINE 15000 | |
85 | + | |
86 | +// addr ipv6 link local node 1: fe80::3734:510e:3317:3402 | |
87 | +uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; | |
88 | +// addr ipv6 link local node 2: fe80::3634:5110:3473:3762 | |
89 | +uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62}; | |
90 | +//addr ipv6 link local node 3: fe80::3634:5110:3471:3766 | |
91 | +uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e}; | |
92 | + | |
93 | +//static char _stack_server[GNRC_PKTDUMP_STACKSIZE]; | |
94 | +char sock_server_stack[THREAD_STACKSIZE_MAIN]; | |
95 | +char sock_client_stack[THREAD_STACKSIZE_MAIN]; | |
96 | +char sock_time_server_stack[THREAD_STACKSIZE_MAIN]; | |
97 | +// static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, | |
98 | +// KERNEL_PID_UNDEF); | |
99 | +// | |
100 | +// kernel_pid_t gnrc_server_pid = KERNEL_PID_UNDEF; | |
101 | +// | |
102 | +kernel_pid_t server, client, time_server; | |
103 | +int ordre = 0; | |
104 | +int64_t offset = 0; | |
105 | +int timer_run = 0; | |
106 | +int tourne = 0; | |
107 | +sock_udp_ep_t local = SOCK_IPV6_EP_ANY; | |
108 | +sock_udp_t sock; | |
109 | +sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; | |
110 | +sock_udp_t sock_ntp; | |
111 | +static ntp_packet_t sntp_packet; | |
112 | + | |
113 | +typedef struct tableau { | |
114 | + uint32_t heure_actuelle; | |
115 | +}Data; | |
116 | + | |
117 | + | |
118 | +void *sock_time_server_thread(void *arg) | |
119 | +{ | |
120 | + (void) arg; | |
121 | + local_ntp.port = NTP_PORT; | |
122 | + | |
123 | + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { | |
124 | + puts("Error creating UDP sock"); | |
125 | + return NULL; | |
126 | + } | |
127 | + | |
128 | + while (1) { | |
129 | + sock_udp_ep_t remote; | |
130 | + ssize_t res; | |
131 | + | |
132 | + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, | |
133 | + &remote)) >= 0) { | |
134 | + puts("Received a message"); | |
135 | + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
136 | + | |
137 | + // printf("%c\n",remote.addr.ipv6[15]); | |
138 | + //xtimer_ticks64_t now = xtimer_now64(); | |
139 | + // heure actuelle du serveur | |
140 | + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); | |
141 | + sntp_packet.origin.seconds=sntp_packet.transmit.seconds; | |
142 | + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); | |
143 | + //printf("heure actuelle : %lu\n",xtimer_now_usec()); | |
144 | + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
145 | + //memset(&sntp_packet, 0, sizeof(sntp_packet)); | |
146 | + //ntp_packet_set_vn(&sntp_packet); | |
147 | + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); | |
148 | + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { | |
149 | + puts("Error sending reply"); | |
150 | + } | |
151 | + } | |
152 | + } | |
153 | + return NULL; | |
154 | +} | |
155 | + | |
156 | +void *sock_server_thread(void *arg) | |
157 | +{ | |
158 | + (void) arg; | |
159 | + Data buf; | |
160 | + int deadline; | |
161 | + local.port = 1234; | |
162 | + sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 }; | |
163 | + ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402"); | |
164 | + | |
165 | + if (sock_udp_create(&sock, &local, NULL, 0) < 0) { | |
166 | + puts("Error creating UDP sock"); | |
167 | + return NULL; | |
168 | + } | |
169 | + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
170 | + puts("Error in synchronization"); | |
171 | + return NULL; | |
172 | + } | |
173 | + offset = sntp_get_offset(); | |
174 | + printf("offset : %i\n",(int)offset); | |
175 | + | |
176 | + while (1) { | |
177 | + sock_udp_ep_t remote; | |
178 | + ssize_t res; | |
179 | + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT,&remote)) >= 0) { | |
180 | + deadline = xtimer_now_usec() + offset - buf.heure_actuelle; | |
181 | + printf("tps de transmission : %i\n",deadline); | |
182 | + } | |
183 | + } | |
184 | + return NULL; | |
185 | +} | |
186 | + | |
187 | +void *sock_client_thread(void *arg) | |
188 | +{ | |
189 | + (void) arg; | |
190 | + Data data; | |
191 | +// data.donnees[0] = 'g'; | |
192 | +// data.donnees[1] = 'o'; | |
193 | + //uint8_t paquet[]; | |
194 | + sock_udp_ep_t remote = { .family = AF_INET6 }; | |
195 | + | |
196 | + remote.port = 1234; | |
197 | + remote.addr.ipv6[0] = 0xde; | |
198 | + remote.addr.ipv6[1] = 0xad; | |
199 | + remote.addr.ipv6[2] = 0xbe; | |
200 | + remote.addr.ipv6[3] = 0xef; | |
201 | + remote.addr.ipv6[14] = 0x37; | |
202 | + remote.addr.ipv6[15] = 0x62; | |
203 | + | |
204 | + while (1) { | |
205 | + data.heure_actuelle = xtimer_now_usec(); | |
206 | + printf("%d\n",sizeof(data)); | |
207 | + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { | |
208 | + puts("Error sending message"); | |
209 | + } | |
210 | + xtimer_sleep(1); | |
211 | + } | |
212 | + return NULL; | |
213 | +} | |
214 | + | |
215 | + | |
216 | + | |
217 | + static void _init_interface(void) | |
218 | + { | |
219 | + kernel_pid_t ifs[GNRC_NETIF_NUMOF]; | |
220 | + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; | |
221 | + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; | |
222 | + uint8_t hwaddr[MAX_ADDR_LEN]; | |
223 | + int res; | |
224 | + | |
225 | + gnrc_netif_get(ifs); | |
226 | + | |
227 | + //addresses gobales | |
228 | + addr.u8[0] = 0xde; | |
229 | + addr.u8[1] = 0xad; | |
230 | + addr.u8[2] = 0xbe; | |
231 | + addr.u8[3] = 0xef; | |
232 | + | |
233 | + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); | |
234 | + | |
235 | + if (res >= 0) { | |
236 | + addr.u8[14] = *hwaddr; | |
237 | + addr.u8[15] = *(hwaddr+1); | |
238 | + } | |
239 | + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); | |
240 | + | |
241 | + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); | |
242 | + /* model ipv6 addr: dead:beef::Hwaddr */ | |
243 | + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ | |
244 | + | |
245 | + tmp_addr.u8[14] = 0x34; | |
246 | + tmp_addr.u8[15] = 0x1e; | |
247 | + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 | |
248 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
249 | + tmp_addr.u8[14] = 0x37; | |
250 | + tmp_addr.u8[15] = 0x62; | |
251 | + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
252 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
253 | + client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); | |
254 | + //xtimer_usleep(10000); | |
255 | + 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"); | |
256 | + // xtimer_usleep(200); | |
257 | + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ | |
258 | + tmp_addr.u8[14] = 0x34; | |
259 | + tmp_addr.u8[15] = 0x1e; | |
260 | + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 | |
261 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
262 | + tmp_addr.u8[14] = 0x34; | |
263 | + tmp_addr.u8[15] = 0x02; | |
264 | + //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 | |
265 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
266 | + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
267 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ | |
268 | + tmp_addr.u8[14] = 0x34; | |
269 | + tmp_addr.u8[15] = 0x02; | |
270 | + //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 | |
271 | + 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; | |
272 | + tmp_addr.u8[14] = 0x37; | |
273 | + tmp_addr.u8[15] = 0x62; | |
274 | + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
275 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
276 | + //start_server("1234"); | |
277 | + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
278 | + | |
279 | + | |
280 | + }else{ | |
281 | + puts("new node ?"); | |
282 | + } | |
283 | + } | |
284 | + | |
285 | +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; | |
286 | + | |
287 | +extern int udp_cmd(int argc, char **argv); | |
288 | + | |
289 | +static const shell_command_t shell_commands[] = { | |
290 | + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, | |
291 | + { NULL, NULL, NULL } | |
292 | +}; | |
293 | + | |
294 | + | |
295 | +int main(void) | |
296 | +{ | |
297 | + | |
298 | + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); | |
299 | + puts("RIOT network stack example application"); | |
300 | + _init_interface(); | |
301 | + | |
302 | + /* start shell */ | |
303 | + puts("All up, running the shell now"); | |
304 | + char line_buf[SHELL_DEFAULT_BUFSIZE]; | |
305 | + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | |
306 | + | |
307 | + /* should be never reached */ | |
308 | + return 0; | |
309 | +} | ... | ... |
... | ... | @@ -0,0 +1,174 @@ |
1 | +/* | |
2 | + * Copyright (C) 2015 Freie Universitรคt Berlin | |
3 | + * | |
4 | + * This file is subject to the terms and conditions of the GNU Lesser | |
5 | + * General Public License v2.1. See the file LICENSE in the top level | |
6 | + * directory for more details. | |
7 | + */ | |
8 | + | |
9 | +/** | |
10 | + * @ingroup examples | |
11 | + * @{ | |
12 | + * | |
13 | + * @file | |
14 | + * @brief Demonstrating the sending and receiving of UDP data | |
15 | + * | |
16 | + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> | |
17 | + * | |
18 | + * @} | |
19 | + */ | |
20 | + | |
21 | +#include <stdio.h> | |
22 | +#include <inttypes.h> | |
23 | + | |
24 | +#include "net/gnrc.h" | |
25 | +#include "net/gnrc/ipv6.h" | |
26 | +#include "net/gnrc/udp.h" | |
27 | +#include "net/gnrc/pktdump.h" | |
28 | +#include "timex.h" | |
29 | +#include "xtimer.h" | |
30 | + | |
31 | +//static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, | |
32 | + // KERNEL_PID_UNDEF); | |
33 | + | |
34 | + | |
35 | +static void send(char *addr_str, char *port_str, char *data, unsigned int num, | |
36 | + unsigned int delay) | |
37 | +{ | |
38 | + uint16_t port; | |
39 | + ipv6_addr_t addr; | |
40 | + | |
41 | + /* parse destination address */ | |
42 | + if (ipv6_addr_from_str(&addr, addr_str) == NULL) { | |
43 | + puts("Error: unable to parse destination address"); | |
44 | + return; | |
45 | + } | |
46 | + /* parse port */ | |
47 | + port = (uint16_t)atoi(port_str); | |
48 | + if (port == 0) { | |
49 | + puts("Error: unable to parse destination port"); | |
50 | + return; | |
51 | + } | |
52 | + | |
53 | + for (unsigned int i = 0; i < num; i++) { | |
54 | + gnrc_pktsnip_t *payload, *udp, *ip; | |
55 | + unsigned payload_size; | |
56 | + /* allocate payload */ | |
57 | + payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF); | |
58 | + if (payload == NULL) { | |
59 | + puts("Error: unable to copy data to packet buffer"); | |
60 | + return; | |
61 | + } | |
62 | + /* store size for output */ | |
63 | + payload_size = (unsigned)payload->size; | |
64 | + /* allocate UDP header, set source port := destination port */ | |
65 | + udp = gnrc_udp_hdr_build(payload, port, port); | |
66 | + if (udp == NULL) { | |
67 | + puts("Error: unable to allocate UDP header"); | |
68 | + gnrc_pktbuf_release(payload); | |
69 | + return; | |
70 | + } | |
71 | + /* allocate IPv6 header */ | |
72 | + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); | |
73 | + if (ip == NULL) { | |
74 | + puts("Error: unable to allocate IPv6 header"); | |
75 | + gnrc_pktbuf_release(udp); | |
76 | + return; | |
77 | + } | |
78 | + /* send packet */ | |
79 | + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { | |
80 | + puts("Error: unable to locate UDP thread"); | |
81 | + gnrc_pktbuf_release(ip); | |
82 | + return; | |
83 | + } | |
84 | + /* access to `payload` was implicitly given up with the send operation above | |
85 | + * => use temporary variable for output */ | |
86 | + printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str, | |
87 | + port); | |
88 | + xtimer_usleep(delay); | |
89 | + } | |
90 | +} | |
91 | + | |
92 | +static void start_server(char *port_str) | |
93 | +{ | |
94 | +// uint16_t port; | |
95 | +// | |
96 | +// /* check if server is already running */ | |
97 | +// if (server.target.pid != KERNEL_PID_UNDEF) { | |
98 | +// printf("Error: server already running on port %" PRIu32 "\n", | |
99 | +// server.demux_ctx); | |
100 | +// return; | |
101 | +// } | |
102 | +// /* parse port */ | |
103 | +// port = (uint16_t)atoi(port_str); | |
104 | +// if (port == 0) { | |
105 | +// puts("Error: invalid port specified"); | |
106 | +// return; | |
107 | +// } | |
108 | +// /* start server (which means registering pktdump for the chosen port) */ | |
109 | +// server.target.pid = gnrc_pktdump_pid; | |
110 | +// server.demux_ctx = (uint32_t)port; | |
111 | +// gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); | |
112 | +// printf("Success: started UDP server on port %" PRIu16 "\n", port); | |
113 | +} | |
114 | + | |
115 | +static void stop_server(void) | |
116 | +{ | |
117 | +// /* check if server is running at all */ | |
118 | +// if (server.target.pid == KERNEL_PID_UNDEF) { | |
119 | +// printf("Error: server was not running\n"); | |
120 | +// return; | |
121 | +// } | |
122 | +// /* stop server */ | |
123 | +// gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server); | |
124 | +// server.target.pid = KERNEL_PID_UNDEF; | |
125 | +// puts("Success: stopped UDP server"); | |
126 | +} | |
127 | + | |
128 | +int udp_cmd(int argc, char **argv) | |
129 | +{ | |
130 | + if (argc < 2) { | |
131 | + printf("usage: %s [send|server]\n", argv[0]); | |
132 | + return 1; | |
133 | + } | |
134 | + | |
135 | + if (strcmp(argv[1], "send") == 0) { | |
136 | + uint32_t num = 1; | |
137 | + uint32_t delay = 1000000; | |
138 | + if (argc < 5) { | |
139 | + printf("usage: %s send <addr> <port> <data> [<num> [<delay in us>]]\n", | |
140 | + argv[0]); | |
141 | + return 1; | |
142 | + } | |
143 | + if (argc > 5) { | |
144 | + num = (uint32_t)atoi(argv[5]); | |
145 | + } | |
146 | + if (argc > 6) { | |
147 | + delay = (uint32_t)atoi(argv[6]); | |
148 | + } | |
149 | + send(argv[2], argv[3], argv[4], num, delay); | |
150 | + } | |
151 | + else if (strcmp(argv[1], "server") == 0) { | |
152 | + if (argc < 3) { | |
153 | + printf("usage: %s server [start|stop]\n", argv[0]); | |
154 | + return 1; | |
155 | + } | |
156 | + if (strcmp(argv[2], "start") == 0) { | |
157 | + if (argc < 4) { | |
158 | + printf("usage %s server start <port>\n", argv[0]); | |
159 | + return 1; | |
160 | + } | |
161 | + start_server(argv[3]); | |
162 | + } | |
163 | + else if (strcmp(argv[2], "stop") == 0) { | |
164 | + stop_server(); | |
165 | + } | |
166 | + else { | |
167 | + puts("error: invalid command"); | |
168 | + } | |
169 | + } | |
170 | + else { | |
171 | + puts("error: invalid command"); | |
172 | + } | |
173 | + return 0; | |
174 | +} | ... | ... |
RIOT/sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c
... | ... | @@ -20,7 +20,7 @@ |
20 | 20 | #include "net/gnrc/ipv6/hdr.h" |
21 | 21 | #include "utlist.h" |
22 | 22 | |
23 | -#define ENABLE_DEBUG (0) | |
23 | +#define ENABLE_DEBUG (1) | |
24 | 24 | #include "debug.h" |
25 | 25 | |
26 | 26 | #if ENABLE_DEBUG |
... | ... | @@ -108,5 +108,10 @@ void gnrc_icmpv6_echo_req_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6_hdr, |
108 | 108 | gnrc_pktbuf_release(pkt); |
109 | 109 | } |
110 | 110 | } |
111 | +/**************************************************************************/ | |
112 | +//Traceroute PFE7 | |
113 | + | |
114 | +//Traceroute PFE7 | |
115 | +/**************************************************************************/ | |
111 | 116 | |
112 | 117 | /** @} */ | ... | ... |
RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
... | ... | @@ -906,7 +906,7 @@ static void _receive(gnrc_pktsnip_t *pkt) |
906 | 906 | |
907 | 907 | #ifdef MODULE_GNRC_IPV6_ROUTER /* only routers redirect */ |
908 | 908 | /* redirect to next hop */ |
909 | - DEBUG("ipv6: decrement hop limit to %u\n", (uint8_t) (hdr->hl - 1)); | |
909 | + printf("ipv6: decrement hop limit to %u\n", (uint8_t) (hdr->hl - 1)); | |
910 | 910 | |
911 | 911 | /* RFC 4291, section 2.5.6 states: "Routers must not forward any |
912 | 912 | * packets with Link-Local source or destination addresses to other |
... | ... | @@ -923,7 +923,7 @@ static void _receive(gnrc_pktsnip_t *pkt) |
923 | 923 | gnrc_pktsnip_t *reversed_pkt = NULL, *ptr = pkt; |
924 | 924 | |
925 | 925 | DEBUG("ipv6: forward packet to next hop\n"); |
926 | - | |
926 | + printf ("transmission\n"); | |
927 | 927 | /* pkt might not be writable yet, if header was given above */ |
928 | 928 | ipv6 = gnrc_pktbuf_start_write(ipv6); |
929 | 929 | if (ipv6 == NULL) { | ... | ... |
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, |
265 | 265 | * there was no remote given on create, take from local */ |
266 | 266 | rem.family = local.family; |
267 | 267 | } |
268 | + | |
268 | 269 | payload = gnrc_pktbuf_add(NULL, (void *)data, len, GNRC_NETTYPE_UNDEF); |
269 | 270 | if (payload == NULL) { |
270 | 271 | return -ENOMEM; |
271 | 272 | } |
273 | + | |
272 | 274 | pkt = gnrc_udp_hdr_build(payload, src_port, dst_port); |
273 | 275 | if (pkt == NULL) { |
274 | 276 | gnrc_pktbuf_release(payload); | ... | ... |