Beispiel #1
0
 public void start_ping() {
   for (int i = 0; i < Network.size(); i++) {
     if (i != this.nodeId)
       EDSimulator.add(
           this.ping_frequency,
           new Message(Message.PING_SCHED, "PING_SCHED " + i),
           Network.get(this.nodeId),
           this.mypid);
   }
 }
Beispiel #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;
     }
   }
 }
Beispiel #3
0
 // methode appelee lorsqu'un message est recu par le protocole HelloWorld du noeud
 public void processEvent(Node node, int pid, Object event) {
   if (((Message) event).getType() == Message.APP_UPDATE) {
     this.state++;
     this.log("APP Update " + this.state);
     if (CommonState.r.nextInt(10) < 5) { // On envoie un message a un noeud aleatoire
       this.send(
           new Message(Message.APP_MSG, "APP MSG " + this.nodeId + "-" + this.state),
           Network.get(CommonState.r.nextInt(Network.size())));
     }
     if (CommonState.r.nextInt(1000) < 5) { // On broadcast
       for (int i = 0; i < Network.size(); i++)
         this.send(
             new Message(Message.APP_MSG, "APP BROADCAST MSG " + this.nodeId + "-" + this.state),
             Network.get(i));
     }
     // On ajoute le prochain APP update
     EDSimulator.add(
         10 + CommonState.r.nextInt(10),
         new Message(Message.APP_UPDATE, "APP Update"),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.APP_MSG) {
     this.receive((Message) event);
   } else if (((Message) event).getType() == Message.PING_SCHED) {
     // On doit envoyer un ping
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.send(new Message(Message.PING, "PING " + this.nodeId), Network.get(from));
     // On ajoute le prochain ping timeout
     EDSimulator.add(
         this.ping_timeout,
         new Message(Message.PING_TIMEOUT, "PING_TIMEOUT " + from),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.PING) {
     this.receive((Message) event);
     // On a reçu un ping, on renvoie un pong
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.send(new Message(Message.PONG, "PONG " + this.nodeId), Network.get(from));
   } else if (((Message) event).getType() == Message.PONG) {
     this.receive((Message) event);
     // On a reçu un pong, on enregistre la reception du pong
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.last_pong[from] = CommonState.getTime();
     if (!this.nodes_alive[from]) {
       this.log("\033[22;32mFalse Failure Detection on " + from + "\033[22;0m");
       this.nodes_alive[from] = true;
     }
     // On ajoute le prochain ping
     EDSimulator.add(
         this.ping_frequency,
         new Message(Message.PING_SCHED, "PING_SCHED " + from),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.PING_TIMEOUT) {
     this.receive((Message) event);
     // On a reçu un ping timeout, le processus est peut etre mort
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     long time_ping = CommonState.getTime() - this.ping_timeout;
     if (this.nodes_alive[from] && this.last_pong[from] < time_ping) {
       this.log("\033[22;31mFailure Detection on " + from + "\033[22;0m");
       this.nodes_alive[from] = false;
     }
   } else {
     this.log("Crash !");
     Network.get(this.nodeId).setFailState(Fallible.DEAD);
   }
 }