/** * "When new links are added or opened, and if we're configured to add nexthop routes, try to add * a new route for the given link." [DTN2] */ public void add_nexthop_route(final Link link) { // "If we're configured to do so, create a route entry for the eid // specified by the link when it connected, using the // scheme-specific code to transform the URI to wildcard // the service part" [DTN2] EndpointID eid = link.remote_eid(); if (config_.add_nexthop_routes() && !eid.equals(EndpointID.NULL_EID())) { EndpointIDPattern eid_pattern = new EndpointIDPattern(link.remote_eid()); // "attempt to build a route pattern from link's remote_eid" [DTN2] if (!eid_pattern.append_service_wildcard()) // "else assign remote_eid as-is" [DTN2] eid_pattern.assign(link.remote_eid()); RouteEntryVec ignored = new RouteEntryVec(); if (route_table_.get_matching(eid_pattern, link, ignored) == 0) { RouteEntry entry = new RouteEntry(eid_pattern, link); entry.set_action(ForwardingInfo.action_t.FORWARD_ACTION); add_route(entry); } } }
/** "Try to forward a bundle to a next hop route." [DTN2] */ protected boolean fwd_to_nexthop(Bundle bundle, RouteEntry route) { Link link = route.link(); // "if the link is available and not open, open it" [DTN2] if (link.isNotUnavailable() && (!link.isopen()) && (!link.isopening())) { Log.d(TAG, String.format("opening %s because a message is intended for it", link.name())); actions_.open_link(link); } // "if the link is open and has space in the queue, then queue the // bundle for transmission there" [DTN2] if (link.isopen() && !link.queue_is_full()) { Log.d(TAG, String.format("queuing %d on %s", bundle.bundleid(), link.name())); actions_.queue_bundle(bundle, link, route.action(), route.custody_spec()); return true; } // "otherwise we can't send the bundle now, so put it on the link's // deferred list and log reason why we can't forward it" [DTN2] DeferredList deferred = deferred_list(link); if (!bundle.is_queued_on(deferred.list())) { ForwardingInfo info = new ForwardingInfo( ForwardingInfo.state_t.NONE, route.action(), link.name_str(), 0xffffffff, link.remote_eid(), route.custody_spec()); deferred.add(bundle, info); } else { Log.w( TAG, String.format( "bundle %d already exists on deferred list of link %s", bundle.bundleid(), link.name())); } if (!link.isNotUnavailable()) { Log.d( TAG, String.format( "can't forward bundle %d to %s because link not available", bundle.bundleid(), link.name())); } else if (!link.isopen()) { Log.d( TAG, String.format( TAG, "can't forward bundle %d to %s because link not open", bundle.bundleid(), link.name())); } else if (link.queue_is_full()) { Log.d( TAG, String.format( TAG, "can't forward bundle %d to %s because link queue is full", bundle.bundleid(), link.name())); } else { Log.d(TAG, String.format(TAG, "can't forward %d to %s", bundle.bundleid(), link.name())); } return false; }