/** "Hook to ask the router if the bundle can be deleted." [DTN2] */ @Override public boolean can_delete_bundle(final Bundle bundle) { Log.d( TAG, String.format("TableBasedRouter::can_delete_bundle: checking if we can delete %s", bundle)); // "check if we haven't yet done anything with this bundle" [DTN2] if (bundle .fwdlog() .get_count( ForwardingInfo.state_t.TRANSMITTED.getCode() | ForwardingInfo.state_t.DELIVERED.getCode(), ForwardingInfo.ANY_ACTION) == 0) { Log.d( TAG, String.format( "TableBasedRouter::can_delete_bundle(%d): " + "not yet transmitted or delivered", bundle.bundleid())); return false; } // check if we have local custody if (bundle.local_custody()) { Log.d( TAG, String.format( "TableBasedRouter::can_delete_bundle(%d): " + "not deleting because we have custody", bundle.bundleid())); return false; } return true; }
/** * "Check the route table entries that match the given bundle and have not already been found in * the bundle history. If a match is found, call fwd_to_nexthop on it." [DTN2] * * @param bundle the bundle to forward * @return "the number of links on which the bundle was queued (i.e. the number of matching route * entries.)" [DTN2] */ protected int route_bundle(Bundle bundle) { RouteEntryVec matches = new RouteEntryVec(); Log.d(TAG, String.format("route_bundle: checking bundle %d", bundle.bundleid())); // "check to see if forwarding is suppressed to all nodes" [DTN2] if (bundle .fwdlog() .get_count( EndpointIDPattern.WILDCARD_EID(), ForwardingInfo.state_t.SUPPRESSED.getCode(), ForwardingInfo.ANY_ACTION) > 0) { Log.i( TAG, String.format( "route_bundle: " + "ignoring bundle %d since forwarding is suppressed", bundle.bundleid())); return 0; } Link null_link = null; route_table_.get_matching(bundle.dest(), null_link, matches); // "sort the matching routes by priority, allowing subclasses to // override the way in which the sorting occurs" [DTN2] sort_routes(matches); Log.d( TAG, String.format( "route_bundle bundle id %d: checking %d route entry matches", bundle.bundleid(), matches.size())); int count = 0; Iterator<RouteEntry> itr = matches.iterator(); while (itr.hasNext()) { RouteEntry route = itr.next(); Log.d( TAG, String.format( "checking route entry %s link %s (%s)", route.toString(), route.link().name(), route.link())); if (!should_fwd(bundle, route)) { continue; } if (deferred_list(route.link()).list().contains(bundle)) { Log.d( TAG, String.format( "route_bundle bundle %d: " + "ignoring link %s since already deferred", bundle.bundleid(), route.link().name())); continue; } // "because there may be bundles that already have deferred // transmission on the link, we first call check_next_hop to // get them into the queue before trying to route the new // arrival, otherwise it might leapfrog the other deferred // bundles" [DTN2] check_next_hop(route.link()); if (!fwd_to_nexthop(bundle, route)) { continue; } ++count; } Log.d( TAG, String.format( "route_bundle bundle id %d: forwarded on %d links", bundle.bundleid(), count)); return count; }