Exemple #1
0
  @Override
  public void initialize(Node node) {
    KoalaNode koalaNode = (KoalaNode) node.getProtocol(pid);
    RenaterNode renaterNode = (RenaterNode) node.getProtocol(phid);
    ChordNode chordNode = (ChordNode) node.getProtocol(cpid);

    String id = getID();
    int dcID = NodeUtilities.getDCID(id);

    koalaNode.setID(id);
    renaterNode.setID(id);
    chordNode.setID(id);

    koalaNode.setNode(node);
    renaterNode.setNode(node);

    NodeUtilities.Nodes.put(id, node);

    double[] cords;
    if (NodeUtilities.Gateways.containsKey(dcID + "")) {
      renaterNode.setGateway(NodeUtilities.Gateways.get(dcID + "").getID());
      cords =
          this.getRandomCirclePoint(
              NodeUtilities.CenterPerDC[dcID][0], NodeUtilities.CenterPerDC[dcID][1], distance);
      //        	System.out.println(id + " is not gateway, its gateway is " +
      // NodeUtilities.Gateways.get(dcID+"").getID());
    } else {
      NodeUtilities.Gateways.put(dcID + "", renaterNode);
      cords = new double[] {NodeUtilities.CenterPerDC[dcID][0], NodeUtilities.CenterPerDC[dcID][1]};
    }

    renaterNode.setX(cords[0]);
    renaterNode.setY(cords[1]);
    renaterNode.setJoined(true);
  }
Exemple #2
0
  private String getID() {
    ArrayList<String> emptyDC = new ArrayList<String>();
    for (int i = 0; i < NodeUtilities.NR_DC; i++) {
      if (!NodeUtilities.Gateways.containsKey(i + "")) emptyDC.add(i + "");
    }

    if (emptyDC.size() != 0)
      return emptyDC.get(CommonState.r.nextInt(emptyDC.size()))
          + "-"
          + CommonState.r.nextInt(NodeUtilities.NR_NODE_PER_DC);

    ArrayList<String> emptyNodeID = new ArrayList<String>();
    for (int i = 0; i < NodeUtilities.NR_DC; i++) {
      for (int j = 0; j < NodeUtilities.NR_NODE_PER_DC; j++) {
        String id = i + "-" + j;
        if (!NodeUtilities.Nodes.containsKey(id)) emptyNodeID.add(id);
      }
    }

    if (emptyNodeID.size() == 0) return null;

    return emptyNodeID.get(CommonState.r.nextInt(emptyNodeID.size()));
  }