Exemplo n.º 1
0
  /**
   * Returns the optimal next action to taken based on future knowledge. The first element of the
   * context array should be the time. That is the time when the user needs to make a decision. It
   * could be the current time for the user or some time in the future.
   *
   * <p>StepOptimalScheduler looks one step into the future and returns the optimal decision in the
   * first element of the returned array based on the current NIC state:
   *
   * <ul>
   *   <li>If the current stat is WiFiNIC.OFF, then the command is WiFiNIC.ON
   *   <li>If the current state is WiFiNIC.DISCONNECTED, then the command is WiFiNIC.CONNECTED and
   *       also contains the BSSID of the AP to connect in the second element.
   *   <li>If the current state is WiFiNIC.CONNECTED, then the command will be WiFiNIC.DATA_TX.
   * </ul>
   *
   * @param context the state of the WiFiNIC
   * @return the optimal COMMAND and the BSSID if action is ASSOCIATE
   * @throws SchedulerException if the medium is not available at the requested time
   */
  public ArrayList query(ArrayList context) throws SchedulerException {

    now = (Double) context.get(0);
    Log.debug(this, "Query " + context);

    if (!medium.hasTime(now))
      throw new SchedulerException("The medium is not available at time " + now);

    if (context.size() < 2) throw new SchedulerException("Malformed context array");

    int niccondition = (Integer) context.get(1);
    HashSet futurestatus = (HashSet) medium.scan(now);
    ArrayList<Object> command = new ArrayList<Object>(3);
    command.add(NIC.WiFi);

    if (futurestatus == null) {
      command.add(WiFiNIC.NOP);
    }

    if (futurestatus.size() == 0) {
      command.add(WiFiNIC.NOP);
    }

    if (niccondition == WiFiNIC.OFF) {
      command.add(WiFiNIC.ON);
    }

    if (niccondition == WiFiNIC.DISCONNECTED) {
      command.add(WiFiNIC.CONNECTED);
      command.add(findNextAP(futurestatus));
    }

    if (niccondition == WiFiNIC.CONNECTED) {
      command.add(WiFiNIC.DATA_TX);
      command.add(endtime);
    }

    /* If the user is connected to an AP, just check if it will be available and return DATA_TX */
    Log.debug(this, "Command " + command);
    return command;
  }
Exemplo n.º 2
0
 /**
  * Initializes the scheduler. An optimal scheduler does not have much to do in terms of
  * initialization but this method should still be called before any other method of the scheduler
  * is called.
  *
  * @param goal data transmission goal of the scheduler
  * @param energysens energy sensitivity of the scheduler
  * @param delaysens delay sensitivity of the scheduler
  */
 public void initialize(double goal, double energysens, double delaysens) {
   Log.info(this, "initializing");
 }