42 #define BLACKLIST_TIMEOUT 10
43 #define BLACKLIST_THRESHOLD 3
44 #define BLACKLIST_SIZE 3
49 #define FLOOD_ROUTE_RETURN_OK 1
50 #define FLOOD_ROUTE_RETURN_CONTINUE 0
51 #define FLOOD_ROUTE_RETURN_FAIL -1
53 struct blacklist_entry_t {
54 struct blacklist_entry_t *
next;
58 clock_time_t timestamp;
61 struct routing_list_entry_t {
63 struct routing_list_entry_t *
next;
69 struct routing_entry_t {
95 PROCESS(routing_process,
"FLOOD ROUTE process");
97 MEMB(blacklist_mem,
struct blacklist_entry_t, BLACKLIST_SIZE);
113 struct blacklist_entry_t *
entry;
127 if( entry->counter > BLACKLIST_THRESHOLD ) {
128 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"%u.%u blacklisted", neighbour->u8[0], neighbour->u8[1]);
139 if( entry ==
NULL ) {
140 LOG(LOGD_DTN, LOG_ROUTE, LOGL_WRN,
"Cannot allocate memory for blacklist");
159 struct blacklist_entry_t *
entry;
166 memset(entry, 0,
sizeof(
struct blacklist_entry_t));
210 ticket = convergence_layer_get_transmit_ticket();
211 if( ticket ==
NULL ) {
212 LOG(LOGD_DTN, LOG_ROUTE, LOGL_WRN,
"unable to allocate transmit ticket");
221 convergence_layer_enqueue_bundle(ticket);
233 struct mmem * bundlemem =
NULL;
238 return FLOOD_ROUTE_RETURN_CONTINUE;
242 if( bundlemem ==
NULL ) {
243 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"cannot read bundle %lu", entry->bundle_number);
244 return FLOOD_ROUTE_RETURN_CONTINUE;
248 if( ret == DELIVERY_STATE_WAIT_FOR_APP ) {
251 }
else if( ret == DELIVERY_STATE_DELETE ) {
253 entry->flags &= ~ROUTING_FLAG_LOCAL;
260 }
else if( ret == DELIVERY_STATE_BUSY ) {
264 return FLOOD_ROUTE_RETURN_CONTINUE;
274 struct discovery_neighbour_list_entry *nei_l =
NULL;
275 rimeaddr_t dest_node;
291 if( nei_l ==
NULL ) {
292 return FLOOD_ROUTE_RETURN_CONTINUE;
296 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"send bundle %lu to %u.%u directly", entry->bundle_number, nei_l->neighbour.u8[0], nei_l->neighbour.u8[1]);
299 entry->flags |= ROUTING_FLAG_IN_TRANSIT;
305 entry->flags &= ~ROUTING_FLAG_IN_TRANSIT;
308 return FLOOD_ROUTE_RETURN_FAIL;
322 struct discovery_neighbour_list_entry *nei_l =
NULL;
336 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"not sending bundle to originator");
342 if(
rimeaddr_cmp(&nei_l->neighbour, &entry->received_from_node) ) {
343 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"not sending back to sender");
351 if (
rimeaddr_cmp(&entry->neighbours[i], &nei_l->neighbour)){
352 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle %lu already sent to node %u.%u!", entry->bundle_number, entry->neighbours[i].u8[0], entry->neighbours[i].u8[1]);
361 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"send bundle %lu to %u.%u", entry->bundle_number, nei_l->neighbour.u8[0], nei_l->neighbour.u8[1]);
364 entry->flags |= ROUTING_FLAG_IN_TRANSIT;
370 entry->flags &= ~ROUTING_FLAG_IN_TRANSIT;
373 return FLOOD_ROUTE_RETURN_FAIL;
381 return FLOOD_ROUTE_RETURN_CONTINUE;
389 struct routing_list_entry_t * n =
NULL;
391 int try_to_forward = 1;
395 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"send to known neighbours");
400 for( n = (
struct routing_list_entry_t *)
list_head(routing_list);
404 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
405 if( entry ==
NULL ) {
406 LOG(LOGD_DTN, LOG_ROUTE, LOGL_WRN,
"Bundle with invalid MMEM structure");
420 if( !(entry->flags & ROUTING_FLAG_FORWARD) || (entry->flags & ROUTING_FLAG_IN_TRANSIT) || !try_to_forward ) {
429 }
else if( h == FLOOD_ROUTE_RETURN_CONTINUE ) {
431 }
else if( h == FLOOD_ROUTE_RETURN_FAIL ) {
441 }
else if( h == FLOOD_ROUTE_RETURN_CONTINUE ) {
443 }
else if( h == FLOOD_ROUTE_RETURN_FAIL ) {
463 struct routing_list_entry_t * n =
NULL;
467 for( n = (
struct routing_list_entry_t *)
list_head(routing_list);
471 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
473 if( entry->bundle_number == bundle_number ) {
479 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle not in storage yet");
483 if( (entry->flags & ROUTING_FLAG_LOCAL) || (entry->flags & ROUTING_FLAG_FORWARD) ) {
487 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"Deleting bundle %lu", bundle_number);
498 struct routing_list_entry_t * n =
NULL;
500 struct mmem * bundlemem =
NULL;
503 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"agent announces bundle %lu", *bundle_number);
510 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
512 if( entry->bundle_number == *bundle_number ) {
513 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"agent announces bundle %lu that is already known", *bundle_number);
524 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"cannot allocate list entry for bundle, please increase BUNDLE_STORAGE_SIZE");
528 memset(n, 0,
sizeof(
struct routing_list_entry_t));
531 if( !
mmem_alloc(&n->entry,
sizeof(
struct routing_entry_t)) ) {
532 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"cannot allocate routing struct for bundle, MMEM is full");
539 if( bundlemem ==
NULL ) {
540 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"unable to read bundle %lu", *bundle_number);
548 if( bundle ==
NULL ) {
549 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"invalid bundle pointer for bundle %lu", *bundle_number);
559 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
560 memset(entry, 0,
sizeof(
struct routing_entry_t));
566 if( bundle->dst_node == dtn_node_id ) {
568 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for local");
569 entry->flags |= ROUTING_FLAG_LOCAL;
572 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for forward");
573 entry->flags |= ROUTING_FLAG_FORWARD;
576 if( !(bundle->flags & BUNDLE_FLAG_SINGLETON) ) {
578 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for forward");
579 entry->flags |= ROUTING_FLAG_FORWARD;
584 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for local and forward");
585 entry->flags |= ROUTING_FLAG_LOCAL;
586 entry->flags |= ROUTING_FLAG_FORWARD;
613 struct routing_list_entry_t * n =
NULL;
616 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"flood_del_bundle for bundle %lu", bundle_number);
623 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
625 if( entry->bundle_number == bundle_number ) {
631 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"flood_del_bundle for bundle %lu that we do not know", bundle_number);
635 memset(
MMEM_PTR(&n->entry), 0,
sizeof(
struct routing_entry_t));
642 memset(n, 0,
sizeof(
struct routing_list_entry_t));
655 struct routing_list_entry_t * n =
NULL;
666 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
668 if( entry->bundle_number == ticket->bundle_number ) {
675 convergence_layer_free_transmit_ticket(ticket);
677 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle not in storage");
682 entry->flags &= ~ROUTING_FLAG_IN_TRANSIT;
684 if( status == ROUTING_STATUS_NACK ||
685 status == ROUTING_STATUS_FAIL ) {
700 convergence_layer_free_transmit_ticket(ticket);
705 if( status == ROUTING_STATUS_ERROR ) {
706 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle %lu has fatal error, deleting", ticket->bundle_number);
714 convergence_layer_free_transmit_ticket(ticket);
724 #ifndef TEST_DO_NOT_DELETE_ON_DIRECT_DELIVERY
727 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle sent to destination node");
731 convergence_layer_free_transmit_ticket(ticket);
735 entry->flags &= ~ROUTING_FLAG_FORWARD;
741 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle for %u.%u delivered to %u.%u", dest_n.u8[0], dest_n.u8[1], ticket->neighbour.u8[0], ticket->neighbour.u8[1]);
746 rimeaddr_copy(&entry->neighbours[entry->send_to], &ticket->neighbour);
748 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle %lu sent to %u nodes", ticket->bundle_number, entry->send_to);
751 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle %lu sent to max number of nodes, deleting", ticket->bundle_number);
754 entry->flags &= ~ROUTING_FLAG_FORWARD;
759 convergence_layer_free_transmit_ticket(ticket);
767 struct routing_list_entry_t * n =
NULL;
774 if( bundle ==
NULL ) {
775 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"flood_locally_delivered called with invalid pointer");
780 for( n = (
struct routing_list_entry_t *)
list_head(routing_list);
784 entry = (
struct routing_entry_t *)
MMEM_PTR(&n->entry);
786 if( entry->bundle_number == bundle->bundle_num ) {
792 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle not in storage yet");
800 entry->flags &= ~ROUTING_FLAG_LOCAL;
812 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle %lu sent to %u nodes", entry->bundle_number, entry->send_to);
815 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle %lu sent to max number of nodes, deleting", entry->bundle_number);
818 entry->flags &= ~ROUTING_FLAG_FORWARD;
832 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"FLOOD ROUTE process in running");