Esempio n. 1
0
  /**
   * "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);
      }
    }
  }
Esempio n. 2
0
  /**
   * "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;
  }