Esempio n. 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);
   }
 }
Esempio n. 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;
     }
   }
 }
  /**
   * Schedules the protocol at given node for the first execution adding it to the priority queue of
   * the event driven simulation. The time of the first execution is determined by a reference point
   * in time and {@link #firstDelay}, which defines the delay from the reference point. The
   * reference point is the maximum of the current time, and the value of parameter {@value
   * peersim.core.Scheduler#PAR_FROM} of the protocol being scheduled. If the calculated time of the
   * first execution is not valid according to the schedule of the protocol then no execution is
   * scheduled for that protocol.
   *
   * <p>A final note: for performance reasons, the recommended practice is not to use parameter
   * {@value peersim.core.Scheduler#PAR_FROM} in protocols, but to schedule {@link CDScheduler}
   * itself for the desired time, whenever possible (e.g., it is not possible if {@link CDScheduler}
   * is used as a {@link NodeInitializer}).
   */
  public void initialize(Node n) {
    /*XXX
     * If "from" is not the current time and this is used as a control (not node
     * initializer) then we dump _lots_ of events in the queue
     * that are just stored there until "from" comes. This reduces performance,
     * and should be fixed. When fixed, the final comment can be removed from the
     * docs.
     */

    final long time = CommonState.getTime();
    for (int i = 0; i < pid.length; ++i) {
      Object nceclone = null;
      try {
        nceclone = nce[i].clone();
      } catch (CloneNotSupportedException e) {
      } // cannot possibly happen

      final long delay = firstDelay(sch[pid[i]].step);
      final long nexttime = Math.max(time, sch[pid[i]].from) + delay;
      if (nexttime < sch[pid[i]].until) EDSimulator.add(nexttime - time, nceclone, n, pid[i]);
    }
  }
Esempio n. 4
0
  @Override
  public boolean execute() {
    // TODO Auto-generated method stub

    Node n;

    if (ok) {
      System.out.println("Création de l'index");
      Message message = new Message();

      n = Network.get(23);
      message.setType("createIndex");
      message.setIndexName("dcs");
      message.setSource(23);
      message.setDestinataire(23);

      ok = false;
      EDSimulator.add(0, message, n, pid);
    } else if (ok2) {
      System.out.println("Lecture n°1");
      n = Network.get(23);
      try (BufferedReader reader =
          new BufferedReader(new FileReader("/Users/dcs/vrac/test/wikiDocs<60"))) {
        while (true) {
          String s = new String();
          s = reader.readLine();
          if (s == null) break;
          String[] tmp = s.split(";");

          if (tmp.length >= 2 && tmp[1].length() > 2) {
            @SuppressWarnings("static-access")
            BFP2P bf_tmp =
                new BFP2P(config_log.sizeOfBF, config_log.sizeOfBF / config_log.numberOfFragment);
            bf_tmp.addAll(tmp[1]);
            // bf_tmp.add("/" + line);
            Message message = new Message();

            message.setType("add");
            message.setIndexName("dcs");
            message.setPath("/");
            message.setData(bf_tmp);
            message.setDestinataire(23);
            line++;
            ControlerNw.config_log.addTotalFilterCreated(1);
            ;
            EDSimulator.add(0, message, n, pid);
          }

          if (line == 1600000) break;
        }
        reader.close();
        ok2 = false;

        /** *********** */
        ok3 = true;
        //	Config.ObserverNw_OK = true;
        /** *********** */
        System.out.println("Fini de lecture " + line + " lignes");
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else if (ok3) {
      System.out.println("Lecture les dernières lignes");

      n = Network.get(23);
      try (BufferedReader reader =
          new BufferedReader(new FileReader("/Users/dcs/vrac/test/wikiDocs<60"))) {
        for (int i = 0; i < line; i++) reader.readLine();

        while (true) {
          String s = new String();
          s = reader.readLine();
          if (s == null) break;
          String[] tmp = s.split(";");

          if (tmp.length >= 2 && tmp[1].length() > 2) {
            @SuppressWarnings("static-access")
            BFP2P bf_tmp =
                new BFP2P(config_log.sizeOfBF, config_log.sizeOfBF / config_log.numberOfFragment);

            bf_tmp.addAll(tmp[1]);
            Message message = new Message();

            message.setType("add");
            message.setIndexName("dcs");
            message.setPath("/");
            message.setData(bf_tmp);
            message.setDestinataire(23);
            line++;
            ControlerNw.config_log.addTotalFilterCreated(1);
            ;
            EDSimulator.add(0, message, n, pid);
          }
        }
        reader.close();
        ok3 = false;
        System.out.println("Fini de lecture " + line + " lignes");
        Config.ObserverNw_OK = true;
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    return false;
  }
Esempio n. 5
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);
   }
 }