예제 #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;
   }
 }
예제 #2
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;
     }
   }
 }