45 #define EPIDEMIC_ROUTE_RETURN_OK 1
46 #define EPIDEMIC_ROUTE_RETURN_CONTINUE 0
47 #define EPIDEMIC_ROUTE_RETURN_FAIL -1
49 struct neighbour_list_entry_t {
54 uint32_t bundles[ROUTING_BUNDLES_PER_NEIGHBOUR];
60 struct routing_entry_t {
62 struct routing_entry_t *
next;
77 PROCESS(routing_process,
"Epidemic ROUTE process");
80 LIST(routing_bundle_list);
82 MEMB(routing_neighbour_mem,
struct neighbour_list_entry_t, ROUTING_NEIGHBOURS);
83 LIST(routing_neigbour_list);
109 struct neighbour_list_entry_t *
entry =
NULL;
111 for(entry =
list_head(routing_neigbour_list);
123 struct neighbour_list_entry_t * routing_epidemic_create_neighbour(rimeaddr_t * dest)
125 struct neighbour_list_entry_t *
entry =
NULL;
128 if( entry !=
NULL ) {
134 if( entry ==
NULL ) {
139 memset(entry, 0,
sizeof(
struct neighbour_list_entry_t));
145 list_add(routing_neigbour_list, entry);
150 void routing_epidemic_delete_neighbour(rimeaddr_t * dest)
152 struct neighbour_list_entry_t * entry =
NULL;
155 if( entry !=
NULL ) {
163 memb_free(&routing_neighbour_mem, entry);
166 void routing_epidemic_store_sent_bundle(rimeaddr_t * dest, uint32_t
bundle_number)
168 struct neighbour_list_entry_t * n =
NULL;
172 n = routing_epidemic_create_neighbour(dest);
175 for(h=0; h<n->bundles_pointer; h++) {
176 if( n->bundles[h] == bundle_number ) {
183 n->bundles_pointer ++;
186 uint8_t routing_epidemic_was_bundle_sent(rimeaddr_t * dest, uint32_t bundle_number)
188 struct neighbour_list_entry_t * n =
NULL;
192 n = routing_epidemic_create_neighbour(dest);
195 for(h=0; h<n->bundles_pointer; h++) {
196 if( n->bundles[h] == bundle_number ) {
210 routing_epidemic_create_neighbour(dest);
225 ticket = convergence_layer_get_transmit_ticket();
226 if( ticket ==
NULL ) {
227 LOG(LOGD_DTN, LOG_ROUTE, LOGL_WRN,
"unable to allocate transmit ticket");
236 convergence_layer_enqueue_bundle(ticket);
248 struct mmem * bundlemem =
NULL;
253 if( bundlemem ==
NULL ) {
254 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"cannot read bundle %lu", entry->bundle_number);
255 return EPIDEMIC_ROUTE_RETURN_CONTINUE;
273 struct neighbour_list_entry_t * n =
NULL;
276 for( n =
list_head(routing_neigbour_list);
280 if( routing_epidemic_was_bundle_sent(&n->neighbour, entry->bundle_number) ) {
284 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"send bundle %lu to %u.%u", entry->bundle_number, n->neighbour.u8[0], n->neighbour.u8[1]);
287 entry->flags |= ROUTING_FLAG_IN_TRANSIT;
293 entry->flags &= ~ROUTING_FLAG_IN_TRANSIT;
296 return EPIDEMIC_ROUTE_RETURN_FAIL;
303 return EPIDEMIC_ROUTE_RETURN_CONTINUE;
311 struct routing_entry_t * n =
NULL;
312 int try_to_forward = 1;
315 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"send to known neighbours");
320 for( n = (
struct routing_entry_t *)
list_head(routing_bundle_list);
329 if( !(n->flags & ROUTING_FLAG_FORWARD) || (n->flags & ROUTING_FLAG_IN_TRANSIT) || !try_to_forward ) {
337 }
else if( h == EPIDEMIC_ROUTE_RETURN_CONTINUE ) {
339 }
else if( h == EPIDEMIC_ROUTE_RETURN_FAIL ) {
361 struct routing_entry_t * n =
NULL;
362 struct mmem * bundlemem =
NULL;
364 uint32_t source_node_eid;
367 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"agent announces bundle %lu", *bundle_number);
374 if( n->bundle_number == *bundle_number ) {
375 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"agent announces bundle %lu that is already known", *bundle_number);
386 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"cannot allocate list entry for bundle, please increase BUNDLE_STORAGE_SIZE");
391 memset(n, 0,
sizeof(
struct routing_entry_t));
395 if( bundlemem ==
NULL ) {
396 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"unable to read bundle %lu", *bundle_number);
403 if( bundle ==
NULL ) {
404 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"invalid bundle pointer for bundle %lu", *bundle_number);
414 if( bundle->dst_node == dtn_node_id ) {
416 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for local");
417 n->flags |= ROUTING_FLAG_LOCAL;
420 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for forward");
421 n->flags |= ROUTING_FLAG_FORWARD;
424 if( !(bundle->flags & BUNDLE_FLAG_SINGLETON) ) {
426 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for forward");
427 n->flags |= ROUTING_FLAG_FORWARD;
432 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"bundle is for local and forward");
433 n->flags |= ROUTING_FLAG_LOCAL;
434 n->flags |= ROUTING_FLAG_FORWARD;
444 routing_epidemic_store_sent_bundle(&source_node, *bundle_number);
445 routing_epidemic_store_sent_bundle(&bundle->msrc, *bundle_number);
465 struct routing_entry_t * n =
NULL;
467 LOG(LOGD_DTN, LOG_ROUTE, LOGL_DBG,
"EPIDEMIC_del_bundle for bundle %lu", bundle_number);
474 if( n->bundle_number == bundle_number ) {
480 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"epidemic_del_bundle for bundle %lu that we do not know", bundle_number);
497 struct routing_entry_t * n =
NULL;
507 if( n->bundle_number == ticket->bundle_number ) {
513 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle not in storage");
518 n->flags &= ~ROUTING_FLAG_IN_TRANSIT;
520 if( status == ROUTING_STATUS_NACK ||
521 status == ROUTING_STATUS_FAIL ) {
527 convergence_layer_free_transmit_ticket(ticket);
532 if( status == ROUTING_STATUS_ERROR ) {
533 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle %lu has fatal error, deleting", ticket->bundle_number);
539 convergence_layer_free_transmit_ticket(ticket);
548 routing_epidemic_store_sent_bundle(&ticket->neighbour, ticket->bundle_number);
551 convergence_layer_free_transmit_ticket(ticket);
559 struct routing_entry_t * n =
NULL;
565 if( bundle ==
NULL ) {
566 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"EPIDEMIC_locally_delivered called with invalid pointer");
571 for( n = (
struct routing_entry_t *)
list_head(routing_bundle_list);
575 if( n->bundle_number == bundle->bundle_num ) {
581 LOG(LOGD_DTN, LOG_ROUTE, LOGL_ERR,
"Bundle not in storage yet");
589 n->flags &= ~ROUTING_FLAG_LOCAL;
608 LOG(LOGD_DTN, LOG_ROUTE, LOGL_INF,
"FLOOD ROUTE process in running");