示例#1
0
文件: HubMod.java 项目: bitlug/lansim
  /** USES R-R SCHEDULING TO SERVICE THE PORTS */
  public boolean step(double TimeStep) {
    absoluteTime++;
    int noOfDataPorts = 0;
    for (int x = 0; x < noOfPorts; x++) {
      if (ports[x].hasData()) {
        noOfDataPorts++;
      }
    }
    if (noOfDataPorts == 1) {
      for (int i = 0; i < noOfPorts; i++) {
        if (ports[i].hasData()) {
          Packet packet = ports[i].getPacket(this);
          modUI.getModWin().msg.append("\nFrom:" + i + "   To:");
          for (int j = 0; j < noOfPorts; j++) {
            if (j != i) {
              modUI.getModWin().msg.append(" " + j);
              Packet tempPacket = new Packet(packet);
              tempPacket.dataUI = null;
              ports[j].putPacket(tempPacket, this);
              ports[j].setActive(true);
              newPacket = true;
            }
          }
          return true;
        }
      }

    } else if (noOfDataPorts > 1) {
      modUI.getModWin().msg.append("\nMultiple Packets, ports:  ");
      for (int i = 0; i < noOfPorts; i++) {
        if (ports[i].hasData()) {
          modUI.getModWin().msg.append(" " + i);
          Packet packet = ports[i].getPacket(this);
          for (int j = 0; j < noOfPorts; j++) {
            Packet tempPacket = new Packet(packet);
            tempPacket.dataUI = null;
            tempPacket.gotCorrupted();
            ports[j].putPacket(tempPacket, this);
            ports[j].setActive(true);
            newPacket = true;
          }
          return false;
        }
      }
    }
    // boolean Success or failure
    return true;
  }
示例#2
0
文件: HubMod.java 项目: bitlug/lansim
 /**
  * Adds a new port (connection)
  *
  * @return The error code if any. e.g. ERROR_ALREADY_MAX_ports is returned if no more ports of
  *     type wireType can be handeled by this module.
  */
 public int addPort(Port port, int wireType) {
   if (noOfPorts < MAXPORTS) {
     ports[noOfPorts++] = port;
     port.setActive(true);
     modUI.getModWin().msg.append("\nADDED port " + noOfPorts);
     return 1;
   } else return ERROR_ALREADY_MAX_PORTS;
 }