Exemple #1
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;
   }
 }
Exemple #2
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());
    }
  }
Exemple #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;
     }
   }
 }
Exemple #4
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;
     */
  }