@Override protected void handle_contact_down(ContactDownEvent event) { Link link = event.contact().link(); assert (link != null) : "TableBasedRouter : handle_contact_down : link is null"; assert (!link.isdeleted()) : "TableBasedRouter : handle_contact_down : link is deleted"; // "if there are any bundles queued on the link when it goes down, // schedule a timer to cancel those transmissions and reroute the // bundles in case the link takes too long to come back up" [DTN2] int num_queued = link.queue().size(); if (num_queued != 0) { RerouteTimer reroute_timer = reroute_timers_.get(link.name()); if (reroute_timer == null) { Log.d( TAG, String.format( "link %s went down with %d bundles queued, " + "scheduling reroute timer in %d seconds", link.name(), num_queued, link.params().potential_downtime())); RerouteTimer t = new RerouteTimer(this, link); t.schedule_in(link.params().potential_downtime()); reroute_timers_.put(link.name(), t); } } }
@Override protected void handle_contact_up(ContactUpEvent event) { Link link = event.contact().link(); assert (link != null) : "TabledBasedRouter: handle_contact_up : link is null"; assert (!link.isdeleted()) : "TabledBasedRouter: handle_contact_up : link is deleted"; if (!link.isopen()) { Log.e( TAG, String.format("contact up(link %s): event delivered but link not open", link.name())); } add_nexthop_route(link); check_next_hop(link); // "check if there's a pending reroute timer on the link, and if // so, cancel it. // // note that there's a possibility that a link just bounces // between up and down states but can't ever really send a bundle // (or part of one), which we don't handle here since we can't // distinguish that case from one in which the CL is actually // sending data, just taking a long time to do so." [DTN2] RerouteTimer reroute_timer = reroute_timers_.get(link.name()); if (reroute_timer != null) { Log.d(TAG, String.format("link %s reopened, cancelling reroute timer", link.name())); reroute_timers_.remove(link.name()); reroute_timer.cancel(); } }
@Override protected void handle_link_deleted(LinkDeletedEvent event) { Link link = event.link(); assert (link != null) : "TableBasedRouter: handle_link_deleted: link is null"; route_table_.del_entries_for_nexthop(link); RerouteTimer t = reroute_timers_.get(link.name()); if (t != null) { Log.d(TAG, String.format("link %s deleted, cancelling reroute timer", link.name())); reroute_timers_.remove(link.name()); t.cancel(); } }