예제 #1
0
 private void nextChannel(int currentChannel, Time currentTime) throws IllegalActionException {
   System.out.println("NEXT CHANNEL at" + currentTime);
   removeFromQueue(currentChannel);
   channelQueue.add(currentChannel);
   nextChannel = channelQueue.peek();
   changeChan = true;
   getDirector().fireAt(this, currentTime.add(0.0000001));
 }
예제 #2
0
  /**
   * State machine responsable by receiving the traffic from the data_in port, disassembly the
   * pcredit_outage and send its flits to the output ports (file). If the data_in does not have a
   * token, suspend firing and return.
   *
   * @exception IllegalActionException If there is no director.
   */
  public void fire() throws IllegalActionException {
    super.fire();
    if (_debugging) _debug("fire current_time: " + getDirector().getModelTime());

    // getting current Time
    current_time = getDirector().getModelTime();
    compare_time = current_time.getDoubleValue();

    // if(firstSend.compareTo(compare_time) == 0.0){
    if (compare_time == init_tim) {
      send_msg.send(0, new IntToken("1"));

      if (_debugging) _debug("FIRST sent at: " + compare_time);
      if (compare_time <= stop_time) {
        new_send = ((DoubleToken) interval.getToken()).doubleValue();

        nextSend = current_time.add(new_send);

        getDirector().fireAt(this, nextSend);

        if (_debugging) _debug("after first send at: " + nextSend);
        // Requests to the director to be fire() at the window sample
      }
    } else if (compare_time < init_tim) {
      firstSend = current_time.add(init_tim);

      getDirector().fireAt(this, firstSend);

      if (_debugging) _debug("init_tim at: " + init_tim + " first send at " + firstSend);
    } else if (current_time.getDoubleValue() == nextSend.getDoubleValue()) {
      nextSend = nextSend.add(new_send);
      send_msg.send(0, new IntToken("2"));

      if (_debugging) _debug("msg sent at: " + compare_time);
      if (_debugging) _debug("NEXT SEND AT: " + nextSend);

      getDirector().fireAt(this, nextSend);

    } else if (current_time.getDoubleValue() != nextSend.getDoubleValue()) {
      if (_debugging) _debug("NAO ROLOU " + compare_time);
    }
  } // end public
예제 #3
0
  public void initialize() throws IllegalActionException {
    super.initialize();

    init_tim = ((DoubleToken) initial_time.getToken()).doubleValue();

    current_time = getDirector().getModelTime();

    firstSend = current_time.add(init_tim);

    getDirector().fireAt(this, firstSend);

    // Get the simulation Stop time
    DEstop_time = getDirector().getModelStopTime();
    stop_time = DEstop_time.getDoubleValue();

    if (_debugging) _debug("GET STOP TIME: ");
  }
예제 #4
0
 /**
  * Generate an exponential random number and schedule the next firing.
  *
  * @exception IllegalActionException If the director throws it when scheduling the next firing, or
  *     if the director does not agree to fire the actor at the specified time.
  */
 @Override
 public boolean postfire() throws IllegalActionException {
   boolean result = super.postfire();
   Time currentTime = getDirector().getModelTime();
   if (_outputProduced) {
     $ASSIGN$_outputProduced(false);
     $ASSIGN$SPECIAL$_nextOutputIndex(11, _nextOutputIndex);
     if (_nextOutputIndex >= _length) {
       $ASSIGN$_nextOutputIndex(0);
     }
     $ASSIGN$_nextFiringTime(currentTime.add(_current));
     _fireAt(_nextFiringTime);
   } else if (currentTime.compareTo(_nextFiringTime) >= 0) {
     _fireAt(currentTime);
   }
   if (currentTime.compareTo(_stopTime) >= 0) {
     return false;
   }
   return result;
 }
예제 #5
0
  // NOTE: No clone() method, so don't clone this.
  public void fire() throws IllegalActionException {
    super.fire();
    double increment = 0.0;

    if ((input.getWidth() > 0) && input.hasToken(0)) {
      DoubleToken in = (DoubleToken) input.get(0);
      increment = in.doubleValue();
    }

    output.broadcast(new DoubleToken(value + increment));
    value += 1.0;

    Director director = getDirector();
    Time time = director.getModelTime();
    count++;

    if (count >= 5) {
      director.fireAt(this, time.add(1.0));
      count = 0;
    } else {
      director.fireAt(this, time);
    }
  }
예제 #6
0
  public void fire() throws IllegalActionException {
    Time currentTime =
        getDirector().getModelTime(); // Get the model time to be used for various calculations

    if (changeChan) { // Check if we need to change the channel in this fire period
      setChannel(nextChannel); // Change to the next required channel
      changeChan = false; // Return to normal operation upon the next fire
      if (input.hasToken(
          0)) { // If this fire was initiated by a token on the input, consume it to avoid loops
        input.get(0);
      }
    } else if (input.hasToken(0)) { // Wireless token has been received f
      SinkData channel =
          channelStore.get(currentChannel); // Retrieve the information for the current channel
      switch (channel.state) { // Determine what stage of the system we are at
        case FIRSTRX: // Stage one, we will be receiving the first synchronisation packet
          handleFirstRX(channel, currentTime);
          break;
        case SECONDRX: // Stage two, we will be receiving the second synchronisation packet
          handleSecondRX(channel, currentTime);
          break;
        case NCALC: // Stage 4, we will be receiving the first synchronisation packet of the
                    // sequence to ascertain the n value
          handleNCalc(channel, currentTime);
          break;
        default: // We are in a state that does not require an input token, so we discard it
          input.get(0);
          break;
      }
    } else { // No token has been received so it is a fire initiated by the source and not a token
             // on the input
      SinkData channel = null; // Initialise a channel to be used later
      int desiredChannelNum =
          currentChannel; // Initialise a variable to store the channel required for this firing
      for (int channelNum :
          channelStore
              .keySet()) { // We need to find the channel that has caused the actor to be fired in
                           // this time period
        channel =
            channelStore.get(channelNum); // Retrieve the information for the channel being checked
        if (channel.nextFireTime != null
            && channel.state
                != states.FINISHED) { // If we have a valid firing time, that has been initialised
          if (!channel.nextFireTime.equals(
              currentTime)) { // We are on an incorrect channel, continue searching
            continue;
          } else { // We have found the correct channel
            desiredChannelNum = channelNum; // Set the desired channel to the channel we have found
            break;
          }
        }
      }
      if (currentChannel == desiredChannelNum) { // If we are on the channel that we desire
        System.out.println(
            channel.nextFireTime.getDoubleValue() <= currentTime.getDoubleValue() + 0.4);
        if (channel.nextFireTime.getDoubleValue()
            <= currentTime.getDoubleValue() + 0.4) { // If we are not too early for the firing time
          switch (channel.state) { // Determine what stage of the system we are at
            case FIRSTTX: // Stage 3, we are in the receive period for the channels sink so we can
                          // transmit a packet
              handleFirstTX(channel, currentTime);
              changeChan = true; // Change back to the channel back to what we had previously
              getDirector().fireAt(this, currentTime.add(0.000001));
              break;
            case SECONDTX: // Stage 5, we are in the receive period for the second time, so we can
                           // transmit a packet
              handleSecondTX(channel, currentTime);
              changeChan = true; // Change back to the channel back to what we had previously
              getDirector().fireAt(this, currentTime.add(0.000001));
              break;
          }
        }
      } else if (desiredChannelNum
          != 0) { // We are not on the desired channel, so we have to change to it
        //		System.out.println(currentChannel + " : " + desiredChannelNum);
        nextChannel =
            currentChannel; // Set the channel we will change back to after the transmit to our
                            // current channel
        setChannel(desiredChannelNum); // Set the channel to the desired channel
        channel.nextFireTime =
            currentTime.add(
                0.0000001); // Set the channels fire time to when we are firing it so we can detect
                            // which channel fired
        getDirector()
            .fireAt(
                this,
                currentTime.add(0.0000001)); // Fire the actor again so we can process the transmit
      }
    }
  }
예제 #7
0
  /**
   * If a new message is available at the inputs, record it in the list indexed with the time that
   * the message shall be completed, and loop through the list to check whether there is collision.
   * If the current time matches one of the times that we have previously recorded as the completion
   * time for a transmission, then output the received message to the <i>received</i> output port if
   * it is not lost to a collision; otherwise, output it to the <i>collided</i> output port.
   *
   * @exception IllegalActionException If an error occurs reading or writing inputs or outputs.
   */
  public void fire() throws IllegalActionException {
    super.fire();

    Time currentTime = getDirector().getModelTime();

    if (_debugging) {
      _debug("---------------------------------");
      _debug("Current time is: " + currentTime);
    }

    if (message.hasToken(0) && power.hasToken(0) && duration.hasToken(0)) {
      double powerValue = ((DoubleToken) power.get(0)).doubleValue();

      if (_debugging) {
        _debug("Received message with power: " + powerValue);
      }

      if (powerValue < _powerThreshold) {
        // The signal it too weak to be detected, simply drop it.
        message.get(0);
        duration.get(0);

        if (_debugging) {
          _debug("Message power is below threshold. Ignoring.");
        }
      } else {
        // Record the reception.
        Reception reception = new Reception();
        reception.data = message.get(0);
        reception.power = powerValue;
        reception.arrivalTime = currentTime.getDoubleValue();
        reception.collided = false;
        reception.duration = ((DoubleToken) duration.get(0)).doubleValue();

        if (_debugging) {
          _debug("Message is above threshold and has duration: " + reception.duration);
        }

        // Update the total power density.
        _totalPower = _totalPower + reception.power;

        // Put the new reception into the list of prior receptions.
        Time time = currentTime.add(reception.duration);
        reception.expiration = time.getDoubleValue();

        _receptions.add(reception);

        // Schedule this actor to be fired at the end of
        // the duration of the message.
        _fireAt(time);
      }
    }

    // Loop through the prior receptions (and the new one)
    // to mark whether a message is collided according to the new total
    // power density. Also, any prior receptions that are now
    // expiring are sent to one of the two outputs.
    Iterator priorReceptions = _receptions.listIterator();

    while (priorReceptions.hasNext()) {
      Reception priorReception = (Reception) priorReceptions.next();

      if (_debugging) {
        _debug("Checking reception with arrival time: " + priorReception.arrivalTime);
      }

      // If the reception is now expiring, send it to one of the two
      // output ports.
      if (priorReception.expiration == currentTime.getDoubleValue()) {
        if (_debugging) {
          _debug(
              "Current time matches expiration "
                  + "time of a prior message that arrived at: "
                  + priorReception.arrivalTime);
        }

        // The time matches a pending reception.
        priorReceptions.remove();

        // Update the total power.
        _totalPower = _totalPower - priorReception.power;

        // Quantization errors may take this negative. Do not allow.
        if (_totalPower < 0.0) {
          _totalPower = 0.0;
        }

        if (!priorReception.collided) {
          received.send(0, priorReception.data);

          if (_debugging) {
            _debug("Message has been received: " + priorReception.data);
          }
        } else {
          collided.send(0, priorReception.data);

          if (_debugging) {
            _debug("Message has been lost: " + priorReception.data);
          }
        }

        continue;
      }

      // Check the snr to see whether to mark this prior reception
      // collided.
      double powerWithoutThisOne = _totalPower - priorReception.power;

      // Quantization errors may make this negative.
      if (powerWithoutThisOne < 0.0) {
        powerWithoutThisOne = 0.0;
      }

      double snr = priorReception.power / powerWithoutThisOne;

      if (!priorReception.collided && (snr <= _SNRThresholdInDB)) {
        priorReception.collided = true;

        if (_debugging) {
          _debug(
              "Message now has a collision. SNR is: " + snr + ". Total power is: " + _totalPower);
        }
      }
    }
  }