示例#1
0
  public boolean execute() {
    // Initialize statistics
    IncrementalStats[] stats = new IncrementalStats[ID.BITS];
    for (int i = 0; i < stats.length; i++) stats[i] = new IncrementalStats();

    int size = Network.size();
    for (int i = 0; i < size; i++) {
      Node node = Network.get(i);
      long lid = IDUtil.getID(node, hid);
      Chord chord = (Chord) node.getProtocol(pid);
      for (int j = 0; j < ID.BITS; j++) {
        Node finger = chord.getFinger(j);
        if (finger != null) {
          long rid = IDUtil.getID(finger, hid);
          long dist = ID.dist(lid, rid);
          stats[j].add(dist);
        }
      }
    }

    // Print final statistics
    for (int i = 0; i < stats.length; i++) {
      System.out.println(prefix + ": TIME " + CommonState.getTime() + " " + i + " " + stats[i]);
      stats[i] = new IncrementalStats();
    }

    return false;
  }
示例#2
0
 public void setInfected(boolean infected) {
   if (infected) {
     if (status == 0) {
       Linkable l = (Linkable) node.getProtocol(p.lid);
       Transport t = (Transport) node.getProtocol(p.tid);
       for (int i = 0; i < l.degree(); i++) {
         t.send(node, l.getNeighbor(i), INFECTION, p.pid);
       }
       status = 1;
     }
   } else {
     status = 0;
   }
 }
示例#3
0
 public void processEvent(Node node, int pid, Object event) {
   if (status == 2) return;
   Linkable l = (Linkable) node.getProtocol(p.lid);
   Transport t = (Transport) node.getProtocol(p.tid);
   if (event == TIMEOUT) {
     if (status == SUSCEPTIBLE) status = INFECTED;
     if (status == INFECTED) {
       EDSimulator.add(p.period, TIMEOUT, node, pid);
       int r = CommonState.r.nextInt(l.degree());
       t.send(node, l.getNeighbor(r), INFECTION, pid);
     }
   } else if (event == INFECTION) {
     if (status == SUSCEPTIBLE) {
       status = INFECTED;
       EDSimulator.add(p.period, TIMEOUT, node, pid);
       int r = CommonState.r.nextInt(l.degree());
       t.send(node, l.getNeighbor(r), INFECTION, pid);
     } else if (status == INFECTED) {
       float chance = CommonState.r.nextFloat();
       if (chance < p.prob) status = REMOVED;
     }
   }
 }
示例#4
0
  /**
   * This is the standard method the define periodic activity. The frequency of execution of this
   * method is defined by a {@link peersim.edsim.CDScheduler} component in the configuration.
   */
  public void nextCycle(Node node, int pid) {
    Linkable linkable = (Linkable) node.getProtocol(FastConfig.getLinkable(pid));
    if (linkable.degree() > 0) {
      Node peern = linkable.getNeighbor(CommonState.r.nextInt(linkable.degree()));

      // XXX quick and dirty handling of failures
      // (message would be lost anyway, we save time)
      if (!peern.isUp()) {
        return;
      }

      ((Transport) node.getProtocol(FastConfig.getTransport(pid)))
          .send(
              node,
              peern,
              new FloodMessage(value, ddl, node, node, String.valueOf(node.getID())),
              pid);
      System.out.println("Start " + node.getID() + " ->" + peern.getID());
    }
  }
示例#5
0
  /** This is the standard method to define to process incoming messages. */
  public void processEvent(Node node, int pid, Object event) {

    FloodMessage aem = (FloodMessage) event;

    if (aem.value == this.value) {

      System.out.println(
          "Sucess  at time: "
              + CommonState.getTime()
              + " ddl="
              + aem.ddl
              + ", path is: "
              + aem.path
              + "->"
              + node.getID()
              + "  search value:"
              + aem.value
              + " this node'value is:"
              + value);
    } else {
      aem.ddl++;
      if (aem.ddl <= 8) {
        System.out.println(
            "Forward at time: "
                + CommonState.getTime()
                + " ddl="
                + aem.ddl
                + ", path is: "
                + aem.path
                + "->"
                + node.getID()
                + "  search value:"
                + aem.value
                + " this node'value is:"
                + value);
        Linkable linkable = (Linkable) node.getProtocol(FastConfig.getLinkable(pid));

        if (linkable.degree() > 0) {
          for (int i = 0; i < linkable.degree(); i++) {

            Node peern = linkable.getNeighbor(i);
            if (peern.getID() != aem.sender.getID()
                && peern.getID() != aem.directsender.getID()) // ��ԭʼ��sender����һ��ת���ڵ�
            {
              // XXX quick and dirty handling of failures
              // (message would be lost anyway, we save time)
              if (!peern.isUp()) {
                return;
              }

              ((Transport) node.getProtocol(FastConfig.getTransport(pid)))
                  .send(
                      node,
                      peern,
                      new FloodMessage(
                          aem.value,
                          aem.ddl,
                          aem.sender,
                          node,
                          aem.path + "->" + String.valueOf(node.getID())),
                      pid);
            }
          }
        }
      } else {
        System.out.println(
            "Failed  at time: "
                + CommonState.getTime()
                + " ddl="
                + aem.ddl
                + ", path is: "
                + aem.path
                + "->"
                + node.getID()
                + "  search value:"
                + aem.value
                + " this node'value is:"
                + value);
      }
    }
    /*
    if( aem.sender!=null )
    ((Transport)node.getProtocol(FastConfig.getTransport(pid))).
    send(
    node,
    aem.sender,
    new AverageMessage(value,null),
    pid);

    value = (value + aem.value) / 2;
     */
  }
示例#6
0
 // envoi d'un message (l'envoi se fait via la couche transport)
 public void send(Message msg, Node dest) {
   this.log("Send " + msg.getContent() + " to " + dest.getID());
   this.transport.send(getMyNode(), dest, msg, this.mypid);
 }