/*---------------------------------------------------------------------------*/ void uip_ds6_neighbor_periodic(void) { /* Periodic processing on neighbors */ uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); while(nbr != NULL) { switch(nbr->state) { case NBR_REACHABLE: if(stimer_expired(&nbr->reachable)) { PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&nbr->ipaddr); PRINTF(")\n"); nbr->state = NBR_STALE; } break; #if UIP_ND6_SEND_NA case NBR_INCOMPLETE: if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { uip_ds6_nbr_rm(nbr); } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) { nbr->nscount++; PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount); uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr); stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; case NBR_DELAY: if(stimer_expired(&nbr->reachable)) { nbr->state = NBR_PROBE; nbr->nscount = 0; PRINTF("DELAY: moving to PROBE\n"); stimer_set(&nbr->sendns, 0); } break; case NBR_PROBE: if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) { uip_ds6_defrt_t *locdefrt; PRINTF("PROBE END\n"); if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) { if (!locdefrt->isinfinite) { uip_ds6_defrt_rm(locdefrt); } } uip_ds6_nbr_rm(nbr); } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) { nbr->nscount++; PRINTF("PROBE: NS %u\n", nbr->nscount); uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr); stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; #endif /* UIP_ND6_SEND_NA */ default: break; } nbr = nbr_table_next(ds6_neighbors, nbr); } }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(struct net_buf *buf) { uip_ds6_addr_t *locaddr; uip_ds6_prefix_t *locprefix; /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); #if UIP_ND6_DEF_MAXDADNS > 0 } else if((locaddr->state == ADDR_TENTATIVE) && (locaddr->dadnscount <= uip_ds6_if.maxdadns) && (timer_expired(&locaddr->dadtimer))) { uip_ds6_dad(NULL, locaddr); #endif /* UIP_ND6_DEF_MAXDADNS > 0 */ } } } /* Periodic processing on default routers */ uip_ds6_defrt_periodic(); /* for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite) && (stimer_expired(&(locdefrt->lifetime)))) { uip_ds6_defrt_rm(locdefrt); } }*/ #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused && !locprefix->isinfinite && stimer_expired(&(locprefix->vlifetime))) { uip_ds6_prefix_rm(locprefix); } } #endif /* !UIP_CONF_ROUTER */ uip_ds6_neighbor_periodic(buf); #if UIP_CONF_ROUTER && UIP_ND6_SEND_RA /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) { uip_ds6_send_ra_periodic(); } #endif /* UIP_CONF_ROUTER && UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
/*---------------------------------------------------------------------------*/ void uip_ds6_br_periodic(void) { #if !UIP_CONF_6LBR for(locbr = uip_ds6_br_list; locbr < uip_ds6_br_list + UIP_DS6_BR_NB; locbr++) { if(locbr->state == BR_ST_USED && stimer_expired(&locbr->timeout)) { /* remove all thing associate to border router */ uip_ds6_br_rm(locbr); } else if(stimer_expired(&locbr->rs_timer) && (locbr->state == BR_ST_MUST_SEND_RS || locbr->state == BR_ST_SENDING_RS)) { /* Send RS if needed well before all timer expired */ uip_ds6_defrt_t *d; d = list_head(defaultrouterlist); uint8_t allnotdone = 0; while(d != NULL) { if(d->br == locbr) { if(d->state != DEFRT_ST_SENDING_RS && locbr->state == BR_ST_MUST_SEND_RS) { /* Init defrt to send unicast RS */ d->state = DEFRT_ST_SENDING_RS; } if(d->state == DEFRT_ST_SENDING_RS) { if(locbr->rscount > UIP_ND6_MAX_RTR_SOLICITATIONS) { uip_ds6_defrt_rm(d); } else { /* Must send unicast RS */ uip_nd6_rs_unicast_output(&d->ipaddr); allnotdone = 1; } } } d = list_item_next(d); } if(list_head(defaultrouterlist) == NULL) { uip_ds6_send_rs(); locbr->state = BR_ST_USED; return; } if(locbr->state == BR_ST_MUST_SEND_RS) { locbr->state = BR_ST_SENDING_RS; locbr->rscount = 1; } else if(!allnotdone) { locbr->state = BR_ST_USED; } else { locbr->rscount++; } stimer_set(&locbr->rs_timer, UIP_ND6_MAX_RTR_SOLICITATION_DELAY); } } #endif /* !UIP_CONF_6LBR */ }
void udp_apps_appcall(void) { #ifdef UIP_DHCP switch(uip_udp_conn->lport) { case UIP_HTONS(IP_PORT_DHCP_SERVER): case UIP_HTONS(IP_PORT_DHCP_CLIENT): dhcpc_appcall(); break; // case UIP_HTONS(IP_PORT_NTP): // ntpd_appcall(); break; default: break; } if( stimer_expired(&dhcpc_state.stimer) ) { dhcpc_state.state = DHCP_STATE_INITIAL; dhcpc_unconfigured(&dhcpc_state); dhcpc_appcall(); } #endif // UIP_DHCP }
/*---------------------------------------------------------------------------*/ void uip_netif_periodic(void) { for(i = 1; i < UIP_CONF_NETIF_MAX_ADDRESSES; i++) { if((uip_netif_physical_if.addresses[i].state != NOT_USED) && (uip_netif_physical_if.addresses[i].is_infinite != 1) && (stimer_expired(&uip_netif_physical_if.addresses[i].vlifetime))) { uip_netif_addr_rm((&uip_netif_physical_if.addresses[i])); } } etimer_reset(&uip_netif_timer_periodic); return; }
void debugPrint() { //Print all our IP addresses when timer expires. if (stimer_expired(&ipPrintTimer)) { stimer_reset(&ipPrintTimer); printIPAddresses(); printLinkLocalAddress(); printGloballAddress(); printIPV6Neighbourlist(); //PRINT_CYAN("Rx counter = %i, TX counter = %i\n",ule6loTestIn_getnofReceivedPacket(),ule6loTestIn_getnofSentPacket()); } }
//Event timer callback void do_timeout1() { counter_etimer++; if(timer_expired(&timer_timer)) { counter_timer++; } if(stimer_expired(&timer_stimer)) { counter_stimer++; } printf("\n\rProcess 1: %s", counter_timer == counter_etimer && counter_timer == counter_stimer ? "SUCCESS" : "FAIL"); }
/*-----------------------------------------------------------------------------------*/ void coap_notify_observers(resource_t *resource, int32_t obs_counter, void *notification) { coap_packet_t *const coap_res = (coap_packet_t *) notification; coap_observer_t* obs = NULL; uint8_t preferred_type = coap_res->type; PRINTF("Observing: Notification from %s\n", resource->url); /* Iterate over observers. */ for (obs = (coap_observer_t*)list_head(observers_list); obs; obs = obs->next) { if (obs->url==resource->url) /* using RESOURCE url pointer as handle */ { coap_transaction_t *transaction = NULL; /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers. */ if ( (transaction = coap_new_transaction(coap_get_mid(), &obs->addr, obs->port)) ) { PRINTF(" Observer "); PRINT6ADDR(&obs->addr); PRINTF(":%u\n", obs->port); /* Update last MID for RST matching. */ obs->last_mid = transaction->mid; /* Prepare response */ coap_res->mid = transaction->mid; coap_set_header_observe(coap_res, obs_counter); coap_set_header_token(coap_res, obs->token, obs->token_len); /* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */ if (stimer_expired(&obs->refresh_timer)) { PRINTF(" Refreshing with CON\n"); coap_res->type = COAP_TYPE_CON; stimer_restart(&obs->refresh_timer); } else { coap_res->type = preferred_type; } transaction->packet_len = coap_serialize_message(coap_res, transaction->packet); coap_send_transaction(transaction); } } } }
PROCESS_THREAD(rest_manager_process, ev, data) { PROCESS_BEGIN(); /*start the coap or http server*/ process_start(SERVER_PROCESS, NULL); PROCESS_PAUSE(); /*Periodic resources are only available to COAP implementation*/ #ifdef WITH_COAP periodic_resource_t* periodic_resource = NULL; for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services); periodic_resource; periodic_resource = periodic_resource->next) { if (periodic_resource->period) { PRINTF("Set timer for Res: %s to %lu\n", periodic_resource->resource->url, periodic_resource->period); etimer_set(periodic_resource->handler_cb_timer, periodic_resource->period); } } while(1) { PROCESS_WAIT_EVENT(); if (ev == PROCESS_EVENT_TIMER) { for (periodic_resource = (periodic_resource_t*)list_head(restful_periodic_services);periodic_resource;periodic_resource = periodic_resource->next) { if (periodic_resource->period && etimer_expired(periodic_resource->handler_cb_timer)) { PRINTF("Etimer expired for %s (period:%lu life:%lu)\n", periodic_resource->resource->url, periodic_resource->period, periodic_resource->lifetime); /*call the periodic handler function if exists*/ if (periodic_resource->periodic_handler) { if ((periodic_resource->periodic_handler)(periodic_resource->resource)) { PRINTF("RES CHANGE\n"); if (!stimer_expired(periodic_resource->lifetime_timer)) { PRINTF("TIMER NOT EXPIRED\n"); resource_changed(periodic_resource); periodic_resource->lifetime = stimer_remaining(periodic_resource->lifetime_timer); } else { periodic_resource->lifetime = 0; } } PRINTF("%s lifetime %lu (%lu) expired %d\n", periodic_resource->resource->url, stimer_remaining(periodic_resource->lifetime_timer), periodic_resource->lifetime, stimer_expired(periodic_resource->lifetime_timer)); } etimer_reset(periodic_resource->handler_cb_timer); } } } } #endif /*WITH_COAP*/ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void uip_ds6_defrt_periodic(void) { uip_ds6_defrt_t *d; d = list_head(defaultrouterlist); while(d != NULL) { if(!d->isinfinite && stimer_expired(&d->lifetime)) { PRINTF("uip_ds6_defrt_periodic: defrt lifetime expired\n"); uip_ds6_defrt_rm(d); d = list_head(defaultrouterlist); } else { d = list_item_next(d); } } }
/*-----------------------------------------------------------------------------------*/ void coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len) { coap_observer_t* obs = NULL; for (obs = (coap_observer_t*)list_head(observers_list); obs; obs = obs->next) { if (obs->url==url) /* using RESOURCE url string as handle */ { coap_transaction_t *transaction = NULL; /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */ if ( (transaction = coap_new_transaction(coap_get_tid(), &obs->addr, obs->port)) ) { /* Use CON to check whether client is still there/interested after COAP_OBSERVING_REFRESH_INTERVAL. */ if (stimer_expired(&obs->refresh_timer)) { PRINTF("Observing: Refresh client with CON\n"); type = COAP_TYPE_CON; stimer_restart(&obs->refresh_timer); } /* prepare response */ coap_packet_t push[1]; /* This way the packet can be treated as pointer as usual. */ coap_init_message(push, (coap_message_type_t)type, OK_200, transaction->tid ); coap_set_header_observe(push, observe); coap_set_header_token(push, obs->token, obs->token_len); coap_set_payload(push, payload, payload_len); transaction->packet_len = coap_serialize_message(push, transaction->packet); PRINTF("Observing: Notify from /%s for ", url); PRINT6ADDR(&obs->addr); PRINTF(":%u\n", obs->port); PRINTF(" %.*s\n", payload_len, payload); coap_send_transaction(transaction); } } } }
/*---------------------------------------------------------------------------*/ static void handle_periodic_timer(void *ptr) { rpl_purge_routes(); rpl_recalculate_ranks(); /* handle DIS */ #if UIP_ND6_ENGINE != UIP_ND6_ENGINE_RPL #if RPL_DIS_SEND next_dis++; if(rpl_get_any_dag() == NULL && next_dis >= RPL_DIS_INTERVAL) { next_dis = 0; dis_output(NULL); } #endif #else if(rpl_get_any_dag() == NULL && stimer_expired(&uip_ds6_timer_dis)) { discount++; dis_output(NULL); stimer_set(&uip_ds6_timer_dis, rs_rtx_time(discount)); } #endif ctimer_reset(&periodic_timer); }
static void handle_dhcp(process_event_t message) { time_t seconds; switch( dhcpc_state.state ) { case DHCP_STATE_INITIAL: dhcpc_state.state = DHCP_STATE_DISCOVER; xid++; send_discover(); stimer_set(&dhcpc_state.stimer, (time_t)10 ); // normally set the timer for 60 seconds, // but because the ARP table is empty give DHCP server only 10 seconds. break; case DHCP_STATE_DISCOVER: if( !stimer_expired(&dhcpc_state.stimer) && message == DHCP_OFFER ) { parse_msg(); dhcpc_state.state = DHCP_STATE_REQUEST; xid++; send_request(); stimer_set(&dhcpc_state.stimer, (time_t)10 ); // set the timer for 10 seconds } else { dhcpc_state.state = DHCP_STATE_INITIAL; } break; case DHCP_STATE_REQUEST: if( !stimer_expired(&dhcpc_state.stimer) && message == DHCP_ACK ) { parse_msg(); dhcpc_state.state = DHCP_STATE_LEASED; PRINTF("Got IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&dhcpc_state.ipaddr)); PRINTF("Got netmask %d.%d.%d.%d\n", uip_ipaddr_to_quad(&dhcpc_state.netmask)); PRINTF("Got DNS server %d.%d.%d.%d\n", uip_ipaddr_to_quad(&dhcpc_state.dnsaddr)); PRINTF("Got default router %d.%d.%d.%d\n", uip_ipaddr_to_quad(&dhcpc_state.default_router)); PRINTF("Lease expires in %ld seconds\n", uip_ntohs(dhcpc_state.lease_time[0])*65536ul + uip_ntohs(dhcpc_state.lease_time[1])); dhcpc_configured(&dhcpc_state); #define MAX_TICKS (~((time_t)0) / 2) #define MAX_TICKS32 (~((time_t)0)) if((uip_ntohs(dhcpc_state.lease_time[0])*65536ul + uip_ntohs(dhcpc_state.lease_time[1]))/2 <= MAX_TICKS32) { seconds = ( uip_ntohs(dhcpc_state.lease_time[0])*65536ul + uip_ntohs(dhcpc_state.lease_time[1]) )/2; } else { seconds = MAX_TICKS32; } stimer_set(&dhcpc_state.stimer, seconds); // set the timer for half of lease_time seconds } else { dhcpc_state.state = DHCP_STATE_INITIAL; } break; case DHCP_STATE_LEASED: if( stimer_expired(&dhcpc_state.stimer) ) { dhcpc_state.state = DHCP_STATE_INITIAL; } break; case DHCP_STATE_REREQUEST: case DHCP_STATE_RELEASE: default: dhcpc_state.state = DHCP_STATE_INITIAL; break; } }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); #if UIP_ND6_DEF_MAXDADNS > 0 } else if((locaddr->state == ADDR_TENTATIVE) && (locaddr->dadnscount <= uip_ds6_if.maxdadns) && (timer_expired(&locaddr->dadtimer)) && (uip_len == 0)) { uip_ds6_dad(locaddr); #endif /* UIP_ND6_DEF_MAXDADNS > 0 */ } } } /* Periodic processing on default routers */ for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite) && (stimer_expired(&(locdefrt->lifetime)))) { uip_ds6_defrt_rm(locdefrt); } } #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused && !locprefix->isinfinite && stimer_expired(&(locprefix->vlifetime))) { uip_ds6_prefix_rm(locprefix); } } #endif /* !UIP_CONF_ROUTER */ /* Periodic processing on neighbors */ for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB; locnbr++) { if(locnbr->isused) { switch(locnbr->state) { case NBR_INCOMPLETE: if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&locnbr->sendns) && (uip_len == 0)) { locnbr->nscount++; PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr); stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; case NBR_REACHABLE: if(stimer_expired(&locnbr->reachable)) { PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&locnbr->ipaddr); PRINTF(")\n"); locnbr->state = NBR_STALE; } break; case NBR_DELAY: if(stimer_expired(&locnbr->reachable)) { locnbr->state = NBR_PROBE; locnbr->nscount = 0; PRINTF("DELAY: moving to PROBE\n"); stimer_set(&locnbr->sendns, 0); } break; case NBR_PROBE: if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) { PRINTF("PROBE END\n"); if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) { if (!locdefrt->isinfinite) { uip_ds6_defrt_rm(locdefrt); } } uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&locnbr->sendns) && (uip_len == 0)) { locnbr->nscount++; PRINTF("PROBE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr); stimer_set(&locnbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; default: break; } } } #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) { uip_ds6_send_ra_periodic(); } #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
/*---------------------------------------------------------------------------*/ int rpl_route_clean(rpl_route_entry_t *state) { return stimer_expired(&state->lifetime); }
/** Periodic processing on neighbors */ void uip_ds6_neighbor_periodic(void) { uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors); while(nbr != NULL) { switch(nbr->state) { case NBR_REACHABLE: if(stimer_expired(&nbr->reachable)) { #if UIP_CONF_IPV6_RPL /* when a neighbor leave its REACHABLE state and is a default router, instead of going to STALE state it enters DELAY state in order to force a NUD on it. Otherwise, if there is no upward traffic, the node never knows if the default router is still reachable. This mimics the 6LoWPAN-ND behavior. */ if(uip_ds6_defrt_lookup(&nbr->ipaddr) != NULL) { PRINTF("REACHABLE: defrt moving to DELAY ("); PRINT6ADDR(&nbr->ipaddr); PRINTF(")\n"); nbr->state = NBR_DELAY; stimer_set(&nbr->reachable, UIP_ND6_DELAY_FIRST_PROBE_TIME); nbr->nscount = 0; } else { PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&nbr->ipaddr); PRINTF(")\n"); nbr->state = NBR_STALE; } #else /* UIP_CONF_IPV6_RPL */ PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&nbr->ipaddr); PRINTF(")\n"); nbr->state = NBR_STALE; #endif /* UIP_CONF_IPV6_RPL */ } break; case NBR_INCOMPLETE: if(nbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { uip_ds6_nbr_rm(nbr); } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) { nbr->nscount++; PRINTF("NBR_INCOMPLETE: NS %u\n", nbr->nscount); uip_nd6_ns_output(NULL, NULL, &nbr->ipaddr); stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; case NBR_DELAY: if(stimer_expired(&nbr->reachable)) { nbr->state = NBR_PROBE; nbr->nscount = 0; PRINTF("DELAY: moving to PROBE\n"); stimer_set(&nbr->sendns, 0); } break; case NBR_PROBE: if(nbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) { uip_ds6_defrt_t *locdefrt; PRINTF("PROBE END\n"); if((locdefrt = uip_ds6_defrt_lookup(&nbr->ipaddr)) != NULL) { if (!locdefrt->isinfinite) { uip_ds6_defrt_rm(locdefrt); } } uip_ds6_nbr_rm(nbr); } else if(stimer_expired(&nbr->sendns) && (uip_len == 0)) { nbr->nscount++; PRINTF("PROBE: NS %u\n", nbr->nscount); uip_nd6_ns_output(NULL, &nbr->ipaddr, &nbr->ipaddr); stimer_set(&nbr->sendns, uip_ds6_if.retrans_timer / 1000); } break; default: break; } nbr = nbr_table_next(ds6_neighbors, nbr); } }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { #if CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER /* Start RPL only when the device has global IPv6 */ if(!rpl_started && uip_ds6_get_global(ADDR_PREFERRED)) { rpl_init(); rpl_started = 1; } #endif /* CONF_6LOWPAN_ND_OPTI_START && UIP_CONF_6L_ROUTER */ /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); #if UIP_ND6_DEF_MAXDADNS > 0 } else if((locaddr->state == ADDR_TENTATIVE) && (locaddr->dadnscount <= uip_ds6_if.maxdadns) && (timer_expired(&locaddr->dadtimer)) && (uip_len == 0)) { uip_ds6_dad(locaddr); #endif /* UIP_ND6_DEF_MAXDADNS > 0 */ } } } /* Periodic processing on default routers */ uip_ds6_defrt_periodic(); /* for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite) && (stimer_expired(&(locdefrt->lifetime)))) { uip_ds6_defrt_rm(locdefrt); } }*/ #if CONF_6LOWPAN_ND /* Periodic processing on context prefixes */ for(loccontext = uip_ds6_context_pref_list; loccontext < uip_ds6_context_pref_list + UIP_DS6_CONTEXT_PREF_NB; loccontext++) { if(loccontext->state != CONTEXT_PREF_ST_FREE) { #if UIP_CONF_6LBR if(stimer_expired(&loccontext->lifetime) && loccontext->br->state != BR_ST_NEW_VERSION) { switch(loccontext->state) { case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } #else /* UIP_CONF_6LBR */ if(stimer_expired(&loccontext->lifetime)) { switch(loccontext->state) { case CONTEXT_PREF_ST_UNCOMPRESSONLY: case CONTEXT_PREF_ST_RM: /* Valid lifetime expired, so remove */ loccontext->state = CONTEXT_PREF_ST_FREE; break; case CONTEXT_PREF_ST_SENDING: /* receive-only mode for a period of twice the default Router Lifetime */ loccontext->state = CONTEXT_PREF_ST_UNCOMPRESSONLY; stimer_set(&loccontext->lifetime, loccontext->router_lifetime * 2); break; case CONTEXT_PREF_ST_ADD: /* before c=0, now c=1 */ loccontext->state = CONTEXT_PREF_ST_COMPRESS; stimer_set(&loccontext->lifetime, loccontext->vlifetime * 60); break; } } else if(is_timeout_percent(&loccontext->lifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN) && loccontext->state == CONTEXT_PREF_ST_COMPRESS) { if(loccontext->br->state != BR_ST_SENDING_RS) { loccontext->br->state = BR_ST_MUST_SEND_RS; } loccontext->state = CONTEXT_PREF_ST_SENDING; } #endif /* UIP_CONF_6LBR */ } } #endif /* CONF_6LOWPAN_ND */ #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for(locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if(locprefix->isused && !locprefix->isinfinite) { if(stimer_expired(&(locprefix->vlifetime))) { uip_ds6_prefix_rm(locprefix); #if UIP_CONF_6LR || UIP_CONF_6LN } else if(is_timeout_percent(&locprefix->vlifetime, UIP_DS6_RS_PERCENT_LIFETIME_RETRAN, UIP_DS6_RS_MINLIFETIME_RETRAN)) { if(locprefix->br->state != BR_ST_SENDING_RS) { locprefix->br->state = BR_ST_MUST_SEND_RS; } #endif /* UIP_CONF_6LR || UIP_CONF_6LN */ } } } #endif /* !UIP_CONF_ROUTER */ /* Periodic processing on border router */ #if CONF_6LOWPAN_ND uip_ds6_br_periodic(); #endif /* CONF_6LOWPAN_ND */ /* Periodic processing on Duplication Address*/ #if UIP_CONF_6LBR for(locdad = uip_ds6_dup_addr_list; locdad < uip_ds6_dup_addr_list + UIP_DS6_DUPADDR_NB; locdad++) { if(locdad->isused && stimer_expired(&locdad->lifetime)) { uip_ds6_dup_addr_rm(locdad); } } #endif /* UIP_CONF_6LBR */ uip_ds6_neighbor_periodic(); #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA #if !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra) && (uip_len == 0)) { uip_ds6_send_ra_periodic(); } #endif /* !CONF_6LOWPAN_ND || UIP_ND6_RA_PERIODIC */ #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
/*---------------------------------------------------------------------------*/ void uip_ds6_periodic(void) { /* This flag signals whether we allow or not to send a packet in the current * invocation. */ u8_t allow_output = 1; /* minimum lifetime */ min_lifetime = 0xFFFFFFFF; /* router with minimum lifetime */ min_defrt = NULL; /* Periodic processing on registrations */ for(locreg = uip_ds6_reg_list; locreg < uip_ds6_reg_list + UIP_DS6_REG_LIST_SIZE; locreg++) { if (locreg->isused) { if (stimer_expired(&locreg->reg_lifetime)) { uip_ds6_reg_rm(locreg); } else if (allow_output) { /* If no output is allowed, it is pointless to enter here in this invocation */ if (uip_ds6_if.registration_in_progress) { /* There is a registration in progress */ if ((locreg == uip_ds6_if.registration_in_progress) && (timer_expired(&locreg->registration_timer))) { /* We already sent a NS message for this address but there has been no response */ if(locreg->reg_count >= UIP_ND6_MAX_UNICAST_SOLICIT) { /* NUD failed. Signal the need for next-hop determination by deleting the * NCE (RFC 4861) */ uip_ds6_reg_rm(locreg); /* And then, delete neighbor and corresponding router (as hosts only keep * NCEs for routers in 6lowpan-nd) */ locnbr = uip_ds6_nbr_lookup(&locreg->defrt->ipaddr); uip_ds6_nbr_rm(locnbr); uip_ds6_defrt_rm(locreg->defrt); /* Since we are deleting a default router, we must delete also all * registrations with that router. * Be careful here, uip_ds6_reg_cleanup_defrt() modifies the value of locreg!*/ uip_ds6_reg_cleanup_defrt(locreg->defrt); /* We will also need to start sending RS, as specified in I-D.ietf-6lowpan-nd * for NUD failure case */ uip_ds6_send_rs(NULL); uip_ds6_if.registration_in_progress = NULL; } else { locreg->reg_count++; timer_restart(&locreg->registration_timer); uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME); } allow_output = 0; /* Prevent this invocation from sending anything else */ } } else { /* There are no registrations in progress, let's see this entry needs (re)registration * or deletion */ if ((locreg->state == REG_GARBAGE_COLLECTIBLE) || (locreg->state == REG_TO_BE_UNREGISTERED) || ((locreg->state == REG_REGISTERED) && (stimer_remaining(&locreg->reg_lifetime) < stimer_elapsed(&locreg->reg_lifetime)))) { /* Issue (re)registration */ uip_ds6_if.registration_in_progress = locreg; locreg->reg_count++; timer_set(&locreg->registration_timer, (uip_ds6_if.retrans_timer / 1000) * (CLOCK_SECOND /* FIXME @@@jwg!!!!*/+250)); if (locreg->state == REG_TO_BE_UNREGISTERED) { uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, 0); } else { uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME); } allow_output = 0; /* Prevent this invocation from sending anything else */ } } } } } /* Periodic processing on unicast addresses */ for(locaddr = uip_ds6_if.addr_list; locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) { if(locaddr->isused) { if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) { uip_ds6_addr_rm(locaddr); } else if (allow_output) { if (stimer_remaining(&locaddr->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locaddr->vlifetime); min_defrt = locaddr->defrt; } } } } /* Periodic processing on default routers */ if (uip_ds6_defrt_choose() == NULL) { if (allow_output) { /* If default router list is empty, start sending RS */ uip_ds6_send_rs(NULL); allow_output = 0; /* Prevent this invocation from sending anything else */ } } else { for(locdefrt = uip_ds6_defrt_list; locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) { if((locdefrt->isused) && (!locdefrt->isinfinite)) { if (stimer_expired(&(locdefrt->lifetime))) { uip_ds6_defrt_rm(locdefrt); /* If default router list is empty, we will start sending RS in * the next invocation of ds6_periodic() */ } else { if (allow_output) { if (stimer_remaining(&locdefrt->lifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locdefrt->lifetime); min_defrt = locdefrt; } } } } } } #if !UIP_CONF_ROUTER /* Periodic processing on prefixes */ for (locprefix = uip_ds6_prefix_list; locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) { if((locprefix->isused) && (!locprefix->isinfinite)) { if (stimer_expired(&locprefix->vlifetime)) { uip_ds6_prefix_rm(locprefix); } else if (allow_output) { if (stimer_remaining(&locprefix->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&locprefix->vlifetime); min_defrt = locprefix->defrt; } } } } #endif /* !UIP_CONF_ROUTER */ #if CONF_6LOWPAN_ND_6CO /* Periodic processing on contexts */ for(loccontext = uip_ds6_addr_context_table; loccontext < uip_ds6_addr_context_table + SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS; loccontext++) { if(loccontext->state != NOT_IN_USE) { if (stimer_expired(&loccontext->vlifetime)) { if (loccontext->state != EXPIRED) { loccontext->state = IN_USE_UNCOMPRESS_ONLY; stimer_set(&loccontext->vlifetime, 2 * loccontext->defrt_lifetime); } else { uip_ds6_context_rm(loccontext); } } else if (allow_output) { if (stimer_remaining(&loccontext->vlifetime) < min_lifetime) { min_lifetime = stimer_remaining(&loccontext->vlifetime); min_defrt = loccontext->defrt; } } } } #endif /* CONF_6LOWPAN_ND_6CO */ /* Start sending RS well before the minimum of the lifetimes (def. router, * context, or prefix) expires */ if ((allow_output) && (min_lifetime < UIP_DS6_LIFETIME_THRESHOLD)) { /* Start sending RSs to the router with minimum lifetime (if possible) */ uip_ds6_send_rs(min_defrt); allow_output = 0; } /* Periodic processing on neighbors */ for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB; locnbr++) { if(locnbr->isused) { switch (locnbr->state) { #if UIP_CONF_ROUTER /* There can not be INCOMPLETE NCEs in a host in 6lowpan-nd */ case NBR_INCOMPLETE: if (allow_output) { if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) { uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&(locnbr->sendns))) { locnbr->nscount++; PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; #endif /* UIP_CONF_ROUTER */ case NBR_REACHABLE: if(stimer_expired(&(locnbr->reachable))) { PRINTF("REACHABLE: moving to STALE ("); PRINT6ADDR(&locnbr->ipaddr); PRINTF(")\n"); locnbr->state = NBR_STALE; NEIGHBOR_STATE_CHANGED(locnbr); } break; case NBR_DELAY: if (allow_output) { if(stimer_expired(&(locnbr->reachable))) { locnbr->state = NBR_PROBE; locnbr->nscount = 1; NEIGHBOR_STATE_CHANGED(locnbr); PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; case NBR_PROBE: if (allow_output) { if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) { PRINTF("PROBE END \n"); if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) { uip_ds6_defrt_rm(locdefrt); } uip_ds6_nbr_rm(locnbr); } else if(stimer_expired(&(locnbr->sendns))) { locnbr->nscount++; PRINTF("PROBE: NS %u\n", locnbr->nscount); uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0); stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000); allow_output = 0; } } break; default: break; } } } #if UIP_CONF_ROUTER & UIP_ND6_SEND_RA /* Periodic RA sending */ if(stimer_expired(&uip_ds6_timer_ra)) { uip_ds6_send_ra_periodic(); } #endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */ etimer_reset(&uip_ds6_timer_periodic); return; }
/** * \brief Performs periodic tasks for 6LP-GW variable management, such as * processing of neighbor lifetimes and DAD timers */ void pgw_periodic() { /* periodic processing of contexts */ for(loccontext = pgw_addr_context_table; loccontext < pgw_addr_context_table + SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS; loccontext++) { if (loccontext->state != NOT_IN_USE) { if (stimer_expired(&loccontext->vlifetime)) { switch(loccontext->state) { case IN_USE_UNCOMPRESS_ONLY: loccontext->state = IN_USE_COMPRESS; stimer_set(&loccontext->vlifetime, PGW_CONTEXT_LIFETIME); context_chaged = 1; break; case IN_USE_COMPRESS: loccontext->state = EXPIRED; if (loccontext->vlifetime.interval > PGW_MIN_CONTEXT_CHANGE_DELAY) { stimer_reset(&loccontext->vlifetime); } else { /* This way we make sure that, if the context is eventually deleted, * No other context will use its id in a period of at least * MIN_CONTEXT_CHANGE_DELAY */ stimer_set(&loccontext->vlifetime, PGW_MIN_CONTEXT_CHANGE_DELAY); } context_chaged = 1; break; case EXPIRED: pgw_context_rm(loccontext); break; } } } } /* periodic processing of neighbors */ for(locnbr = pgw_6ln_cache; locnbr < pgw_6ln_cache + MAX_6LOWPAN_NEIGHBORS; locnbr++) { if(locnbr->isused) { /* * If the reachable timer is expired, we delete the NCE, * regardless of the NCE's state. */ if(stimer_expired(&(locnbr->reachable))) { /* I-D.ietf-6lowpan-nd: Should the Registration Lifetime in a NCE expire, * then the router MUST delete the cache entry. */ pgw_nbr_rm(locnbr); } else if ((locnbr->state == PGW_TENTATIVE) && (!uip_is_addr_link_local(&locnbr->ipaddr))) { if ((locnbr->dadnscount <= PGW_MAX_DAD_NS) && (timer_expired(&locnbr->dadtimer))) { pgw_dad(locnbr); /* If we found a neighbor requiring DAD, perform it. If there were * more neighbors requiring it, we'll do it in further invocations */ return; } } } } etimer_reset(&pgw_timer_periodic); return; }