37 #define DISCOVERY_NEIGHBOUR_CACHE 3
38 #define DISCOVERY_NEIGHBOUR_TIMEOUT 5
39 #define DISCOVERY_CYCLE 0.2
40 #define DISCOVERY_TRIES 5
46 struct discovery_basic_neighbour_list_entry {
47 struct discovery_basic_neighbour_list_entry *
next;
49 clock_time_t timestamp;
53 PROCESS(discovery_process,
"DISCOVERY process");
59 MEMB(neighbour_mem,
struct discovery_basic_neighbour_list_entry, DISCOVERY_NEIGHBOUR_CACHE);
61 uint8_t discovery_status = 0;
62 uint8_t discovery_pending = 0;
63 uint8_t discovery_pending_start = 0;
64 static struct etimer discovery_timeout_timer;
65 static struct etimer discovery_pending_timer;
92 struct discovery_basic_neighbour_list_entry *
entry;
96 entry = entry->next) {
112 if( discovery_status == 0 ) {
116 rimeaddr_t dest={{0,0}};
117 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"dtn_send_discover");
119 convergence_layer_send_discovery((uint8_t *)
"DTN_DISCOVERY", 13, &dest);
129 uint8_t test[8]=
"DTN_HERE";
131 for (i=
sizeof(test); i>0 ; i--){
132 if(test[i-1]!=msg[i-1]){
147 uint8_t test[13]=
"DTN_DISCOVERY";
149 for (i=
sizeof(test); i>0; i--) {
150 if(test[i-1]!=msg[i-1]) {
155 if( discovery_status == 0 ) {
159 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"DTN DISCOVERY");
160 convergence_layer_send_discovery((uint8_t *)
"DTN_HERE", 8, dest);
170 discovery_status = 1;
179 discovery_status = 0;
190 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"received from %u:%u", source->u8[1], source->u8[0]);
197 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"is_discover");
203 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"is_beacon");
214 struct discovery_basic_neighbour_list_entry *
entry;
218 entry = entry->next) {
225 if( entry ==
NULL ) {
228 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"sending DTN BEACON Event for %u.%u", neighbour->u8[0], neighbour->u8[1]);
229 process_post(&agent_process, dtn_beacon_event, &entry->neighbour);
245 struct discovery_basic_neighbour_list_entry *
entry;
249 entry = entry->next) {
271 struct discovery_basic_neighbour_list_entry *
entry;
274 if( entry ==
NULL ) {
276 struct discovery_basic_neighbour_list_entry *
delete =
list_head(neighbour_list);
277 clock_time_t age = 0;
282 entry = entry->next) {
283 if( entry->active && (
clock_time() - entry->timestamp) > age ) {
289 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_INF,
"Removing neighbour %u.%u to make room", delete->neighbour.u8[0], delete->neighbour.u8[1]);
300 memset(entry, 0,
sizeof(
struct discovery_basic_neighbour_list_entry));
302 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"DISCOVERY: Saving neighbour %u.%u", neighbour->u8[0], neighbour->u8[1]);
319 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"agent asks to discover %u.%u", dest->u8[0], dest->u8[1]);
327 discovery_pending_start = 1;
350 discovery_pending = 0;
359 discovery_pending = 1;
371 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_DBG,
"Basic Discovery process running");
377 struct discovery_basic_neighbour_list_entry *
entry;
381 entry = entry->next) {
382 if( entry->active && (
clock_time() - entry->timestamp) > (DISCOVERY_NEIGHBOUR_TIMEOUT * CLOCK_SECOND) ) {
383 LOG(LOGD_DTN, LOG_DISCOVERY, LOGL_INF,
"Neighbour %u.%u timed out: %lu vs. %lu = %lu", entry->neighbour.u8[0], entry->neighbour.u8[1],
clock_time(), entry->timestamp,
clock_time() - entry->timestamp);
386 convergence_layer_neighbour_down(&entry->neighbour);
399 if( discovery_pending &&
etimer_expired(&discovery_pending_timer) ) {
401 discovery_pending ++;
403 if( discovery_pending > (DISCOVERY_TRIES + 1)) {
413 if( discovery_pending_start ) {
415 discovery_pending_start = 0;
423 .name =
"B_DISCOVERY",