44 #include "contiki-lib.h" 45 #include "contiki-net.h" 49 #include "dev/watchdog.h" 52 #define DEBUG DEBUG_NONE 55 #define TRICKLE_VERBOSE 0 57 #if DEBUG && TRICKLE_VERBOSE 58 #define VERBOSE_PRINTF(...) PRINTF(__VA_ARGS__) 59 #define VERBOSE_PRINT_SEED(s) PRINT_SEED(s) 61 #define VERBOSE_PRINTF(...) 62 #define VERBOSE_PRINT_SEED(...) 68 #if ROLL_TM_SHORT_SEEDS 69 typedef union seed_id_u {
74 #define seed_is_null(s) ((s)->id == 0) 75 #define PRINT_SEED(s) PRINTF("0x%02x%02x", (s)->u8[0], (s)->u8[1]) 77 typedef uip_ip6addr_t seed_id_t;
79 #define seed_is_null(s) uip_is_addr_unspecified(s) 80 #define PRINT_SEED(s) PRINT6ADDR(s) 82 #define seed_id_cmp(a, b) (memcmp((a), (b), sizeof(seed_id_t)) == 0) 83 #define seed_id_cpy(a, b) (memcpy((a), (b), sizeof(seed_id_t))) 86 struct trickle_param {
91 clock_time_t t_last_trigger;
99 uint8_t inconsistency;
107 #define TRICKLE_TIME(m, d) ((clock_time_t)((m) << (d))) 112 #define TRICKLE_IMAX(t) ((uint32_t)((t)->i_min << (t)->i_max)) 119 #define TRICKLE_ACTIVE(t) ((uint32_t)(TRICKLE_IMAX(t) * t->t_active)) 126 #define TRICKLE_DWELL(t) ((uint32_t)(TRICKLE_IMAX(t) * t->t_dwell)) 132 #define SUPPRESSION_ENABLED(t) ((t)->k != ROLL_TM_INFINITE_REDUNDANCY) 138 #define SUPPRESSION_DISABLED(t) ((t)->k == ROLL_TM_INFINITE_REDUNDANCY) 143 #define TIMER_CONFIGURE(m) do { \ 144 t[m].i_min = ROLL_TM_IMIN_##m; \ 145 t[m].i_max = ROLL_TM_IMAX_##m; \ 146 t[m].k = ROLL_TM_K_##m; \ 147 t[m].t_active = ROLL_TM_T_ACTIVE_##m; \ 148 t[m].t_dwell = ROLL_TM_T_DWELL_##m; \ 149 t[m].t_last_trigger = clock_time(); \ 169 #define SEQ_VAL_IS_EQ(i1, i2) ((i1) == (i2)) 174 #define SEQ_VAL_IS_LT(i1, i2) \ 177 ((((i1) < (i2)) && ((int16_t)((i2) - (i1)) < 0x4000)) || \ 178 (((i1) > (i2)) && ((int16_t)((i1) - (i2)) > 0x4000))) \ 184 #define SEQ_VAL_IS_GT(i1, i2) \ 187 ((((i1) < (i2)) && ((int16_t)((i2) - (i1)) > 0x4000)) || \ 188 (((i1) > (i2)) && ((int16_t)((i1) - (i2)) < 0x4000))) \ 194 #define SEQ_VAL_ADD(s, n) (((s) + (n)) % 0x8000) 197 struct sliding_window {
206 #define SLIDING_WINDOW_U_BIT 0x80 207 #define SLIDING_WINDOW_M_BIT 0x40 208 #define SLIDING_WINDOW_L_BIT 0x20 209 #define SLIDING_WINDOW_B_BIT 0x10 215 #define SLIDING_WINDOW_IS_USED(w) ((w)->flags & SLIDING_WINDOW_U_BIT) 221 #define SLIDING_WINDOW_IS_USED_SET(w) ((w)->flags |= SLIDING_WINDOW_U_BIT) 227 #define SLIDING_WINDOW_IS_USED_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_U_BIT) 228 #define window_free(w) SLIDING_WINDOW_IS_USED_CLR(w) 234 #define SLIDING_WINDOW_LISTED_SET(w) ((w)->flags |= SLIDING_WINDOW_L_BIT) 240 #define SLIDING_WINDOW_LISTED_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_L_BIT) 246 #define SLIDING_WINDOW_IS_LISTED(w) ((w)->flags & SLIDING_WINDOW_L_BIT) 252 #define SLIDING_WINDOW_M_SET(w) ((w)->flags |= SLIDING_WINDOW_M_BIT) 258 #define SLIDING_WINDOW_M_CLR(w) ((w)->flags &= ~SLIDING_WINDOW_M_BIT) 264 #define SLIDING_WINDOW_GET_M(w) \ 265 ((uint8_t)(((w)->flags & SLIDING_WINDOW_M_BIT) == SLIDING_WINDOW_M_BIT)) 268 struct mcast_packet {
269 #if ROLL_TM_SHORT_SEEDS 277 struct sliding_window *sw;
283 #define MCAST_PACKET_U_BIT 0x80 284 #define MCAST_PACKET_S_BIT 0x20 285 #define MCAST_PACKET_L_BIT 0x10 288 #if ROLL_TM_SHORT_SEEDS 289 #define MCAST_PACKET_GET_SEED(p) ((seed_id_t *)&((p)->seed_id)) 291 #define MCAST_PACKET_GET_SEED(p) \ 292 ((seed_id_t *)&((struct uip_ip_hdr *)&(p)->buff[UIP_LLH_LEN])->srcipaddr) 299 #define MCAST_PACKET_TTL(p) \ 300 (((struct uip_ip_hdr *)(p)->buff)->ttl) 306 #define MCAST_PACKET_USED_SET(p) ((p)->flags |= MCAST_PACKET_U_BIT) 312 #define MCAST_PACKET_USED_CLR(p) ((p)->flags &= ~MCAST_PACKET_U_BIT) 317 #define MCAST_PACKET_IS_USED(p) ((p)->flags & MCAST_PACKET_U_BIT) 322 #define MCAST_PACKET_MUST_SEND(p) ((p)->flags & MCAST_PACKET_S_BIT) 328 #define MCAST_PACKET_SEND_SET(p) ((p)->flags |= MCAST_PACKET_S_BIT) 334 #define MCAST_PACKET_SEND_CLR(p) ((p)->flags &= ~MCAST_PACKET_S_BIT) 340 #define MCAST_PACKET_IS_LISTED(p) ((p)->flags & MCAST_PACKET_L_BIT) 346 #define MCAST_PACKET_LISTED_SET(p) ((p)->flags |= MCAST_PACKET_L_BIT) 352 #define MCAST_PACKET_LISTED_CLR(p) ((p)->flags &= ~MCAST_PACKET_L_BIT) 358 #define MCAST_PACKET_FREE(p) ((p)->flags = 0) 361 struct sequence_list_header {
367 #define SEQUENCE_LIST_S_BIT 0x80 368 #define SEQUENCE_LIST_M_BIT 0x40 369 #define SEQUENCE_LIST_RES 0x3F 375 #define SEQUENCE_LIST_GET_M(l) \ 376 ((uint8_t)(((l)->flags & SEQUENCE_LIST_M_BIT) == SEQUENCE_LIST_M_BIT)) 382 #define SEQUENCE_LIST_GET_S(l) \ 383 ((uint8_t)(((l)->flags & SEQUENCE_LIST_S_BIT) == SEQUENCE_LIST_S_BIT)) 389 #if ROLL_TM_SHORT_SEEDS 394 #if !ROLL_TM_SHORT_SEEDS 401 #define HBHO_OPT_TYPE_TRICKLE 0x0C 402 #define HBHO_LEN_LONG_SEED 2 403 #define HBHO_LEN_SHORT_SEED 4 404 #define HBHO_TOTAL_LEN 8 409 #define HBH_GET_M(h) (((h)->flags & 0x80) == 0x80) 415 #define HBH_SET_M(h) ((h)->flags |= 0x80) 421 #define HBH_GET_SV_MSB(h) ((h)->flags & 0x7F) 424 #if ROLL_TM_CONF_DEST_ALL_NODES 425 #define roll_tm_create_dest(a) uip_create_linklocal_allnodes_mcast(a) 427 #define roll_tm_create_dest(a) uip_create_linklocal_allrouters_mcast(a) 434 #define ROLL_TM_STATS_ADD(x) stats.x++ 435 #define ROLL_TM_STATS_INIT() do { memset(&stats, 0, sizeof(stats)); } while(0) 437 #define ROLL_TM_STATS_ADD(x) 438 #define ROLL_TM_STATS_INIT() 443 static struct trickle_param t[2];
449 static struct trickle_param *loctpptr;
450 static struct sequence_list_header *locslhptr;
451 static struct sliding_window *locswptr;
452 static struct sliding_window *iterswptr;
453 static struct mcast_packet *locmpptr;
454 static struct hbho_mcast *lochbhmptr;
455 static uint16_t last_seq;
459 #define UIP_DATA_BUF ((uint8_t *)&uip_buf[uip_l2_l3_hdr_len + UIP_UDPH_LEN]) 460 #define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) 461 #define UIP_EXT_BUF ((struct uip_ext_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN]) 462 #define UIP_EXT_BUF_NEXT ((uint8_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + HBHO_TOTAL_LEN]) 463 #define UIP_EXT_OPT_FIRST ((struct hbho_mcast *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + 2]) 464 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN]) 465 #define UIP_ICMP_BUF ((struct uip_icmp_hdr *)&uip_buf[uip_l2_l3_hdr_len]) 466 #define UIP_ICMP_PAYLOAD ((unsigned char *)&uip_buf[uip_l2_l3_icmp_hdr_len]) 467 extern uint16_t uip_slen;
471 static void icmp_input(
void);
472 static void icmp_output(
void);
473 static void window_update_bounds(
void);
474 static void reset_trickle_timer(uint8_t);
475 static void handle_timer(
void *);
479 UIP_ICMP6_HANDLER_CODE_ANY, icmp_input);
484 random_interval(clock_time_t i_min, uint8_t d)
488 VERBOSE_PRINTF(
"ROLL TM: Random [%lu, %lu)\n", (
unsigned long)min,
496 double_interval(
void *ptr)
498 struct trickle_param *param = (
struct trickle_param *)ptr;
506 offset = (int16_t)(
clock_time() - param->t_end);
509 if(param->i_current < param->i_max) {
513 param->t_start = param->t_end;
514 param->t_end = param->t_start + (param->i_min << param->i_current);
516 next = random_interval(param->i_min, param->i_current);
522 param->t_next = next;
523 ctimer_set(¶m->ct, param->t_next, handle_timer, (
void *)param);
525 VERBOSE_PRINTF(
"ROLL TM: Doubling at %lu (offset %d), Start %lu, End %lu," 527 (
unsigned long)param->t_start,
528 (
unsigned long)param->t_end, (
unsigned long)param->t_next);
536 handle_timer(
void *ptr)
538 struct trickle_param *param;
539 clock_time_t diff_last;
540 clock_time_t diff_start;
543 param = (
struct trickle_param *)ptr;
546 }
else if(param == &t[1]) {
554 if(uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) {
556 (
"ROLL TM: Suppressing timer processing. Stack not ready\n");
557 reset_trickle_timer(m);
561 VERBOSE_PRINTF(
"ROLL TM: M=%u Periodic at %lu, last=%lu\n",
563 (
unsigned long)param->t_last_trigger);
567 diff_last = param->t_next - param->t_last_trigger;
568 diff_start = param->t_next - param->t_start;
569 param->t_last_trigger = param->t_next;
572 (
"ROLL TM: M=%u Periodic diff from last %lu, from start %lu\n", m,
573 (
unsigned long)diff_last, (
unsigned long)diff_start);
577 locmpptr >= buffered_msgs; locmpptr--) {
594 if(locmpptr->active == 0) {
595 locmpptr->active += diff_start;
596 locmpptr->dwell += diff_start;
598 locmpptr->active += diff_last;
599 locmpptr->dwell += diff_last;
602 VERBOSE_PRINTF(
"ROLL TM: M=%u Packet %u active %lu of %lu\n",
603 m, locmpptr->seq_val, locmpptr->active,
607 locmpptr->sw->count--;
608 PRINTF(
"ROLL TM: M=%u Free Packet %u (%lu > %lu), Window now at %u\n",
609 m, locmpptr->seq_val, locmpptr->dwell,
611 if(locmpptr->sw->count == 0) {
612 PRINTF(
"ROLL TM: M=%u Free Window ", m);
613 PRINT_SEED(&locmpptr->sw->seed_id);
615 window_free(locmpptr->sw);
623 PRINTF(
"ROLL TM: M=%u Periodic - Sending packet from Seed ", m);
624 PRINT_SEED(&locmpptr->sw->seed_id);
625 PRINTF(
" seq %u\n", locmpptr->seq_val);
629 UIP_MCAST6_STATS_ADD(mcast_fwd);
640 if(param->c < param->k) {
646 param->inconsistency = 0;
649 window_update_bounds();
653 if(param->t_next >= param->t_end) {
657 param->t_next = param->t_end - param->t_next;
660 (
"ROLL TM: M=%u Periodic at %lu, Interval End at %lu in %lu\n", m,
661 (
unsigned long)
clock_time(), (
unsigned long)param->t_end,
662 (
unsigned long)param->t_next);
663 ctimer_set(¶m->ct, param->t_next, double_interval, (
void *)param);
669 reset_trickle_timer(uint8_t index)
672 t[index].t_end = t[index].t_start + (t[index].i_min);
673 t[index].i_current = 0;
675 t[index].t_next = random_interval(t[index].i_min, t[index].i_current);
678 (
"ROLL TM: M=%u Reset at %lu, Start %lu, End %lu, New Interval %lu\n",
679 index, (
unsigned long)t[index].t_start, (
unsigned long)t[index].t_start,
680 (
unsigned long)t[index].t_end, (
unsigned long)t[index].t_next);
682 ctimer_set(&t[index].ct, t[index].t_next, handle_timer, (
void *)&t[index]);
685 static struct sliding_window *
688 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
691 iterswptr->count = 0;
692 iterswptr->lower_bound = -1;
693 iterswptr->upper_bound = -1;
694 iterswptr->min_listed = -1;
701 static struct sliding_window *
702 window_lookup(seed_id_t *s, uint8_t m)
704 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
707 VERBOSE_PRINT_SEED(&iterswptr->seed_id);
708 VERBOSE_PRINTF(
"\n");
709 if(seed_id_cmp(s, &iterswptr->seed_id) &&
718 window_update_bounds()
720 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
722 iterswptr->lower_bound = -1;
726 locmpptr >= buffered_msgs; locmpptr--) {
728 iterswptr = locmpptr->sw;
729 VERBOSE_PRINTF(
"ROLL TM: Update Bounds: [%d - %d] vs %u\n",
730 iterswptr->lower_bound, iterswptr->upper_bound,
732 if(iterswptr->lower_bound < 0
733 ||
SEQ_VAL_IS_LT(locmpptr->seq_val, iterswptr->lower_bound)) {
734 iterswptr->lower_bound = locmpptr->seq_val;
736 if(iterswptr->upper_bound < 0 ||
738 iterswptr->upper_bound = locmpptr->seq_val;
744 static struct mcast_packet *
747 struct sliding_window *largest = windows;
748 struct mcast_packet *rv;
750 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
752 if(iterswptr->count > largest->count) {
757 if(largest->count == 1) {
762 PRINTF(
"ROLL TM: Reclaim from Seed ");
763 PRINT_SEED(&largest->seed_id);
764 PRINTF(
" M=%u, count was %u\n",
768 locmpptr >= buffered_msgs; locmpptr--) {
772 PRINTF(
"ROLL TM: Reclaim seq. val %u\n", locmpptr->seq_val);
775 window_update_bounds();
776 VERBOSE_PRINTF(
"ROLL TM: Reclaim - new bounds [%u , %u]\n",
777 largest->lower_bound, largest->upper_bound);
786 static struct mcast_packet *
790 locmpptr >= buffered_msgs; locmpptr--) {
801 struct sequence_list_header *sl;
803 uint16_t payload_len;
805 PRINTF(
"ROLL TM: ICMPv6 Out\n");
813 sl = (
struct sequence_list_header *)UIP_ICMP_PAYLOAD;
816 VERBOSE_PRINTF(
"ROLL TM: ICMPv6 Out - Hdr @ %p, payload @ %p\n",
UIP_ICMP_BUF, sl);
818 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
821 memset(sl, 0,
sizeof(
struct sequence_list_header));
822 #if ROLL_TM_SHORT_SEEDS 823 sl->flags = SEQUENCE_LIST_S_BIT;
826 sl->flags |= SEQUENCE_LIST_M_BIT;
828 seed_id_cpy(&sl->seed_id, &iterswptr->seed_id);
830 PRINTF(
"ROLL TM: ICMPv6 Out - Seq. F=0x%02x, Seed ID=", sl->flags);
831 PRINT_SEED(&sl->seed_id);
833 buffer = (uint8_t *)sl +
sizeof(
struct sequence_list_header);
836 locmpptr >= buffered_msgs; locmpptr--) {
839 if(locmpptr->sw == iterswptr) {
841 PRINTF(
", %u", locmpptr->seq_val);
842 *buffer = (uint8_t)(locmpptr->seq_val >> 8);
844 *buffer = (uint8_t)(locmpptr->seq_val & 0xFF);
849 PRINTF(
", Len=%u\n", sl->seq_len);
852 if(sl->seq_len > 0) {
853 payload_len +=
sizeof(
struct sequence_list_header) + sl->seq_len * 2;
854 sl = (
struct sequence_list_header *)buffer;
859 if(payload_len == 0) {
860 VERBOSE_PRINTF(
"ROLL TM: ICMPv6 Out - nothing to send\n");
867 UIP_IP_BUF->len[0] = (UIP_ICMPH_LEN + payload_len) >> 8;
868 UIP_IP_BUF->len[1] = (UIP_ICMPH_LEN + payload_len) & 0xff;
876 uip_len = UIP_IPH_LEN + UIP_ICMPH_LEN + payload_len;
878 VERBOSE_PRINTF(
"ROLL TM: ICMPv6 Out - %u bytes\n", payload_len);
881 ROLL_TM_STATS_ADD(icmp_out);
900 PRINTF(
"ROLL TM: Multicast I/O\n");
902 #if UIP_CONF_IPV6_CHECKS 904 PRINTF(
"ROLL TM: Mcast I/O, bad destination\n");
905 UIP_MCAST6_STATS_ADD(mcast_bad);
906 return UIP_MCAST6_DROP;
913 PRINTF(
"ROLL TM: Mcast I/O, bad source\n");
914 UIP_MCAST6_STATS_ADD(mcast_bad);
915 return UIP_MCAST6_DROP;
921 PRINTF(
"ROLL TM: Mcast I/O, bad proto\n");
922 UIP_MCAST6_STATS_ADD(mcast_bad);
923 return UIP_MCAST6_DROP;
926 if(UIP_EXT_OPT_FIRST->type != HBHO_OPT_TYPE_TRICKLE) {
927 PRINTF(
"ROLL TM: Mcast I/O, bad HBHO type\n");
928 UIP_MCAST6_STATS_ADD(mcast_bad);
929 return UIP_MCAST6_DROP;
932 lochbhmptr = UIP_EXT_OPT_FIRST;
934 PRINTF(
"ROLL TM: HBHO T=%u, L=%u, M=%u, S=0x%02x%02x\n",
935 lochbhmptr->type, lochbhmptr->len,
HBH_GET_M(lochbhmptr),
939 #if ROLL_TM_SHORT_SEEDS 941 if(lochbhmptr->len != HBHO_LEN_SHORT_SEED) {
942 PRINTF(
"ROLL TM: Mcast I/O, bad length\n");
943 UIP_MCAST6_STATS_ADD(mcast_bad);
944 return UIP_MCAST6_DROP;
948 if(lochbhmptr->len != HBHO_LEN_LONG_SEED) {
949 PRINTF(
"ROLL TM: Mcast I/O, bad length\n");
950 UIP_MCAST6_STATS_ADD(mcast_bad);
951 return UIP_MCAST6_DROP;
956 if(in == ROLL_TM_DGRAM_IN) {
957 UIP_MCAST6_STATS_ADD(mcast_in_all);
962 #if ROLL_TM_SHORT_SEEDS 963 seed_ptr = &lochbhmptr->seed_id;
969 locswptr = window_lookup(seed_ptr, m);
971 seq_val = lochbhmptr->seq_id_lsb;
977 PRINTF(
"ROLL TM: Too old\n");
978 UIP_MCAST6_STATS_ADD(mcast_dropped);
979 return UIP_MCAST6_DROP;
982 locmpptr >= buffered_msgs; locmpptr--) {
984 locmpptr->sw == locswptr &&
988 PRINTF(
"ROLL TM: Seen before\n");
989 UIP_MCAST6_STATS_ADD(mcast_dropped);
990 return UIP_MCAST6_DROP;
995 PRINTF(
"ROLL TM: New message\n");
1000 locswptr = window_allocate();
1001 PRINTF(
"ROLL TM: New seed\n");
1005 PRINTF(
"ROLL TM: Failed to allocate window\n");
1006 UIP_MCAST6_STATS_ADD(mcast_dropped);
1007 return UIP_MCAST6_DROP;
1011 locmpptr = buffer_allocate();
1013 PRINTF(
"ROLL TM: Buffer allocation failed, reclaiming\n");
1014 locmpptr = buffer_reclaim();
1020 PRINTF(
"ROLL TM: Buffer reclaim failed\n");
1021 if(locswptr->count == 0) {
1022 window_free(locswptr);
1023 UIP_MCAST6_STATS_ADD(mcast_dropped);
1024 return UIP_MCAST6_DROP;
1027 #if UIP_MCAST6_STATS 1028 if(in == ROLL_TM_DGRAM_IN) {
1029 UIP_MCAST6_STATS_ADD(mcast_in_unique);
1040 seed_id_cpy(&locswptr->seed_id, seed_ptr);
1041 PRINTF(
"ROLL TM: Window for seed ");
1042 PRINT_SEED(&locswptr->seed_id);
1043 PRINTF(
" M=%u, count=%u\n",
1047 if(locswptr->count == 0) {
1048 locswptr->lower_bound = seq_val;
1049 VERBOSE_PRINTF(
"ROLL TM: New Lower Bound %u\n", locswptr->lower_bound);
1053 if(locswptr->count == 0 ||
SEQ_VAL_IS_GT(seq_val, locswptr->upper_bound)) {
1054 locswptr->upper_bound = seq_val;
1055 VERBOSE_PRINTF(
"ROLL TM: New Upper Bound %u\n", locswptr->upper_bound);
1060 memset(locmpptr, 0,
sizeof(
struct mcast_packet));
1062 locmpptr->sw = locswptr;
1064 locmpptr->seq_val = seq_val;
1067 PRINTF(
"ROLL TM: Window for seed ");
1068 PRINT_SEED(&locswptr->seed_id);
1069 PRINTF(
" M=%u, %u values within [%u , %u]\n",
1071 locswptr->lower_bound, locswptr->upper_bound);
1079 if(in == ROLL_TM_DGRAM_IN) {
1083 t[m].inconsistency = 1;
1085 PRINTF(
"ROLL TM: Inconsistency. Reset T%u\n", m);
1086 reset_trickle_timer(m);
1090 return UIP_MCAST6_ACCEPT;
1097 uint8_t inconsistency;
1102 #if UIP_CONF_IPV6_CHECKS 1104 PRINTF(
"ROLL TM: ICMPv6 In, bad source ");
1109 ROLL_TM_STATS_ADD(icmp_bad);
1115 PRINTF(
"ROLL TM: ICMPv6 In, bad destination\n");
1116 ROLL_TM_STATS_ADD(icmp_bad);
1121 PRINTF(
"ROLL TM: ICMPv6 In, bad ICMP code\n");
1122 ROLL_TM_STATS_ADD(icmp_bad);
1127 PRINTF(
"ROLL TM: ICMPv6 In, bad TTL\n");
1128 ROLL_TM_STATS_ADD(icmp_bad);
1133 PRINTF(
"ROLL TM: ICMPv6 In from ");
1137 ROLL_TM_STATS_ADD(icmp_in);
1140 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
1147 locmpptr >= buffered_msgs; locmpptr--) {
1151 locslhptr = (
struct sequence_list_header *)UIP_ICMP_PAYLOAD;
1153 VERBOSE_PRINTF(
"ROLL TM: ICMPv6 In, parse from %p to %p\n",
1155 (uint8_t *)UIP_ICMP_PAYLOAD +
uip_len -
1156 uip_l2_l3_icmp_hdr_len);
1158 (
struct sequence_list_header *)((uint8_t *)UIP_ICMP_PAYLOAD +
1159 uip_len - uip_l2_l3_icmp_hdr_len)) {
1160 VERBOSE_PRINTF(
"ROLL TM: ICMPv6 In, seq hdr @ %p\n", locslhptr);
1162 if((locslhptr->flags & SEQUENCE_LIST_RES) != 0) {
1163 PRINTF(
"ROLL TM: ICMPv6 In, non-zero reserved bits\n");
1168 #if ROLL_TM_SHORT_SEEDS 1170 ROLL_TM_STATS_ADD(icmp_bad);
1175 ROLL_TM_STATS_ADD(icmp_bad);
1180 PRINTF(
"ROLL TM: ICMPv6 In, Sequence List for Seed ID ");
1181 PRINT_SEED(&locslhptr->seed_id);
1185 seq_ptr = (uint16_t *)((uint8_t *)locslhptr
1186 +
sizeof(
struct sequence_list_header));
1187 end_ptr = (uint16_t *)((uint8_t *)locslhptr
1188 +
sizeof(
struct sequence_list_header) +
1189 locslhptr->seq_len * 2);
1197 locswptr = window_lookup(&locslhptr->seed_id,
1203 locswptr->min_listed = -1;
1204 PRINTF(
"ROLL TM: ICMPv6 In, Window bounds [%u , %u]\n",
1205 locswptr->lower_bound, locswptr->upper_bound);
1206 for(; seq_ptr < end_ptr; seq_ptr++) {
1210 PRINTF(
"ROLL TM: ICMPv6 In, Check seq %u @ %p\n", val, seq_ptr);
1212 PRINTF(
"ROLL TM: Inconsistency - Advertised Seq. ID %u GT upper" 1213 " bound %u\n", val, locswptr->upper_bound);
1214 loctpptr->inconsistency = 1;
1226 locmpptr >= buffered_msgs; locmpptr--) {
1232 PRINTF(
"ROLL TM: ICMPv6 In, %u listed\n", locmpptr->seq_val);
1236 if(locswptr->min_listed == -1 ||
1238 locswptr->min_listed = val;
1245 PRINTF(
"ROLL TM: Inconsistency - ");
1246 PRINTF(
"Advertised Seq. ID %u within bounds", val);
1247 PRINTF(
" [%u, %u] but no matching entry\n",
1248 locswptr->lower_bound, locswptr->upper_bound);
1249 loctpptr->inconsistency = 1;
1258 PRINTF(
"ROLL TM: Inconsistency - Advertised window unknown to us\n");
1259 loctpptr->inconsistency = 1;
1261 locslhptr = (
struct sequence_list_header *)(((uint8_t *)locslhptr) +
1262 sizeof(
struct sequence_list_header) + (2 * locslhptr->seq_len));
1267 PRINTF(
"ROLL TM: ICMPv6 In, Check our buffer\n");
1269 locmpptr >= buffered_msgs; locmpptr--) {
1271 locswptr = locmpptr->sw;
1272 PRINTF(
"ROLL TM: ICMPv6 In, ");
1273 PRINTF(
"Check %u, Seed L: %u, This L: %u Min L: %d\n",
1281 PRINTF(
"ROLL TM: Inconsistency - Seed ID ");
1282 PRINT_SEED(&locswptr->seed_id);
1283 PRINTF(
" was not listed\n");
1284 loctpptr->inconsistency = 1;
1289 (locswptr->min_listed >= 0) &&
1291 PRINTF(
"ROLL TM: Inconsistency - ");
1292 PRINTF(
"Seq. %u was not listed but %u was\n",
1293 locmpptr->seq_val, locswptr->min_listed);
1294 loctpptr->inconsistency = 1;
1303 if(t[0].inconsistency) {
1304 reset_trickle_timer(0);
1308 if(t[1].inconsistency) {
1309 reset_trickle_timer(1);
1325 PRINTF(
"ROLL TM: Multicast Out can not add HBHO. Packet too long\n");
1330 memmove(UIP_EXT_BUF_NEXT, UIP_EXT_BUF,
uip_len - UIP_IPH_LEN);
1331 memset(UIP_EXT_BUF, 0, HBHO_TOTAL_LEN);
1334 UIP_EXT_BUF->len = 0;
1336 lochbhmptr = UIP_EXT_OPT_FIRST;
1337 lochbhmptr->type = HBHO_OPT_TYPE_TRICKLE;
1341 lochbhmptr->flags = last_seq >> 8;
1342 lochbhmptr->seq_id_lsb = last_seq & 0xFF;
1343 #if ROLL_TM_SHORT_SEEDS 1345 lochbhmptr->len = HBHO_LEN_SHORT_SEED;
1347 lochbhmptr->len = HBHO_LEN_LONG_SEED;
1349 lochbhmptr->padn_type = UIP_EXT_HDR_OPT_PADN;
1350 lochbhmptr->padn_len = 0;
1354 #if ROLL_TM_SET_M_BIT 1366 PRINTF(
"ROLL TM: Multicast Out, HBHO: T=%u, L=%u, M=%u, S=0x%02x%02x\n",
1367 lochbhmptr->type, lochbhmptr->len,
HBH_GET_M(lochbhmptr),
1379 if(
accept(ROLL_TM_DGRAM_OUT)) {
1381 UIP_MCAST6_STATS_ADD(mcast_out);
1397 if(
accept(ROLL_TM_DGRAM_IN) == UIP_MCAST6_DROP) {
1398 return UIP_MCAST6_DROP;
1401 if(!uip_ds6_is_my_maddr(&
UIP_IP_BUF->destipaddr)) {
1402 PRINTF(
"ROLL TM: Not a group member. No further processing\n");
1403 return UIP_MCAST6_DROP;
1405 PRINTF(
"ROLL TM: Ours. Deliver to upper layers\n");
1406 UIP_MCAST6_STATS_ADD(mcast_in_ours);
1407 return UIP_MCAST6_ACCEPT;
1414 PRINTF(
"ROLL TM: ROLL Multicast - Draft #%u\n",
ROLL_TM_VER);
1416 memset(windows, 0,
sizeof(windows));
1417 memset(buffered_msgs, 0,
sizeof(buffered_msgs));
1418 memset(t, 0,
sizeof(t));
1420 ROLL_TM_STATS_INIT();
1421 UIP_MCAST6_STATS_INIT(&stats);
1426 for(iterswptr = &windows[
ROLL_TM_WINS - 1]; iterswptr >= windows;
1428 iterswptr->lower_bound = -1;
1429 iterswptr->upper_bound = -1;
1430 iterswptr->min_listed = -1;
1434 reset_trickle_timer(0);
1436 reset_trickle_timer(1);
#define UIP_IP_BUF
Pointer to IP header.
#define ROLL_TM_WINS
Number of Sliding Windows In essence: How many unique sources of simultaneous multicast traffic do we...
#define SLIDING_WINDOW_M_CLR(w)
Clear M bit for window w w: pointer to a sliding window.
#define SEQ_VAL_IS_EQ(i1, i2)
s1 is said to be equal s2 iif SEQ_VAL_IS_EQ(s1, s2) == 1
uip_lladdr_t uip_lladdr
Host L2 address.
uint8_t tcpip_output(const uip_lladdr_t *a)
Output packet to layer 2 The eventual parameter is the MAC address of the destination.
#define SLIDING_WINDOW_LISTED_SET(w)
Set 'Is Seen' bit for window w w: pointer to a sliding window.
Header file for ICMPv6 message and error handing (RFC 4443)
Multicast stats extension for the ROLL TM engine.
Header file for the implementation of the ROLL-TM multicast engine.
#define TRICKLE_TIME(m, d)
Convert a timer to a sane clock_time_t value after d doublings m is a value of Imin, d is a number of doublings Careful of overflows.
#define uip_is_addr_linklocal_allrouters_mcast(a)
Is IPv6 address a the link local all-routers multicast address.
#define MCAST_PACKET_IS_LISTED(p)
Is the message p listed in current ICMP message? p: pointer to a struct mcast_packet.
uint16_t uip_len
The length of the packet in the uip_buf buffer.
#define ROLL_TM_IP_HOP_LIMIT
Hop limit for ICMP messages.
#define ICMP6_ROLL_TM
ROLL Trickle Multicast.
The data structure used to represent a multicast engine.
void tcpip_ipv6_output(void)
This function does address resolution and then calls tcpip_output.
#define SLIDING_WINDOW_IS_USED(w)
Is Occupied sliding window location w w: pointer to a sliding window.
#define ROLL_TM_ICMP_CODE
ROLL TM ICMPv6 code field.
#define UIP_ICMP_BUF
Pointer to ICMP header.
#define TRICKLE_DWELL(t)
Convert Tdwell for a trickle timer to a sane clock_time_t value t is a pointer to the timer Careful o...
#define UIP_PROTO_HBHO
extension headers types
#define UIP_BUFSIZE
The size of the uIP packet buffer.
A set of debugging macros for the IP stack
#define MCAST_PACKET_SEND_CLR(p)
Clear 'Must Send' bit for message p p: pointer to a struct mcast_packet.
#define HBH_SET_M(h)
Set the Trickle Parametrization bit for a multicast HBHO header m: pointer to the HBHO header...
#define SEQUENCE_LIST_GET_S(l)
Get the Seed ID Length for an ICMPv6 sequence list l: pointer to a sequence list structure.
uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
#define UIP_LLADDR_LEN
802.15.4 address
const struct uip_mcast6_driver roll_tm_driver
The ROLL TM engine driver.
#define TRICKLE_ACTIVE(t)
Convert Tactive for a trickle timer to a sane clock_time_t value t is a pointer to the timer Careful ...
This header file contains configuration directives for uIPv6 multicast support.
#define SLIDING_WINDOW_M_SET(w)
Set M bit for window w w: pointer to a sliding window.
uint8_t(* in)(void)
Process an incoming multicast datagram and determine whether it should be delivered up the stack or n...
#define SLIDING_WINDOW_GET_M(w)
Retrieve trickle parametrization for sliding window at location w w: pointer to a sliding window...
#define uip_is_addr_mcast_non_routable(a)
is address a non-routable multicast address.
static uint8_t accept(uint8_t in)
Processes an incoming or outgoing multicast message and determines whether it should be dropped or ac...
#define SLIDING_WINDOW_IS_USED_SET(w)
Set 'Is Used' bit for window w w: pointer to a sliding window.
#define UIP_LLH_LEN
The link level header length.
#define SLIDING_WINDOW_IS_LISTED(w)
Is the sliding window at location w listed in current ICMP message? w: pointer to a sliding window...
void ctimer_set(struct ctimer *c, clock_time_t t, void(*f)(void *), void *ptr)
Set a callback timer.
#define uip_is_addr_unspecified(a)
Is IPv6 address a the unspecified address a is of type uip_ipaddr_t.
#define MCAST_PACKET_USED_SET(p)
Set 'Is Used' bit for packet p p: pointer to a packet buffer.
#define SUPPRESSION_DISABLED(t)
Check if suppression is disabled for trickle_param t t is a pointer to the timer. ...
clock_time_t clock_time(void)
Get the current clock time.
#define SEQ_VAL_ADD(s, n)
Add n to s: (s + n) modulo (2 ^ SERIAL_BITS) => ((s + n) % 0x8000)
#define MCAST_PACKET_MUST_SEND(p)
Must we send this message this pass?
#define SEQUENCE_LIST_GET_M(l)
Get the Trickle Parametrization for an ICMPv6 sequence list l: pointer to a sequence list structure...
#define MCAST_PACKET_SEND_SET(p)
Set 'Must Send' bit for message p p: pointer to a struct mcast_packet.
#define HBH_GET_M(h)
Get the Trickle Parametrization for a multicast HBHO header m: pointer to the HBHO header...
void(* out)(void)
Process an outgoing datagram with a multicast IPv6 destination address.
#define ROLL_TM_BUFF_NUM
Maximum Number of Buffered Multicast Messages This buffer is shared across all Seed IDs...
#define ROLL_TM_VER
Supported Draft Version.
void(* init)(void)
Initialize the multicast engine.
uint8_t uip_ext_len
The length of the extension headers.
#define SUPPRESSION_ENABLED(t)
Check if suppression is enabled for trickle_param t t is a pointer to the timer.
#define SLIDING_WINDOW_LISTED_CLR(w)
Clear 'Is Seen' bit for window w w: pointer to a sliding window.
uint16_t uip_icmp6chksum(void)
Calculate the ICMP checksum of the packet in uip_buf.
#define uip_is_addr_linklocal_allnodes_mcast(a)
Is IPv6 address a the link local all-nodes multicast address.
#define MCAST_PACKET_FREE(p)
Free a multicast packet buffer p: pointer to a struct mcast_packet.
void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
Register a handler which can handle a specific ICMPv6 message type.
#define MCAST_PACKET_LISTED_CLR(p)
Clear 'Is Listed' bit for message p p: pointer to a struct mcast_packet.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define SEQ_VAL_IS_LT(i1, i2)
s1 is said to be less than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1
unsigned short random_rand(void)
Generates a new random number using the cc2538 RNG.
#define uip_is_addr_linklocal(a)
is addr (a) a link local unicast address, see RFC 4291 i.e.
#define MCAST_PACKET_LISTED_SET(p)
Set 'Is Listed' bit for message p p: pointer to a struct mcast_packet.
#define MCAST_PACKET_TTL(p)
Get the TTL of a buffered packet p: pointer to a packet buffer.
#define MCAST_PACKET_IS_USED(p)
Is Occupied buffer location p.
#define HBH_GET_SV_MSB(h)
Retrieve the Sequence Value MSB from a multicast HBHO header m: pointer to the HBHO header...
#define TIMER_CONFIGURE(m)
Init trickle_timer[m].
void uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
Source address selection, see RFC 3484.
#define SEQ_VAL_IS_GT(i1, i2)
s1 is said to be greater than s2 iif SEQ_VAL_IS_LT(s1, s2) == 1