Ejemplo n.º 1
0
  protected PingReply requestPing(int src_id, int dst_id) {
    int SIZE = 500;
    double evsend_time = 0;
    PingRequest request = new PingRequest(this.get_id(), this.get_id(), src_id, dst_id);
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output, GridSimTags.SCHEDULE_NOW, Tags.PING_REQ, new IO_data(request, SIZE, src_id));
    evsend_time = GridSim.clock();
    String msg =
        String.format(
            "%1$f %2$d %3$s --> AM_%4$s PING_REQUEST AM_%5$s",
            evsend_time,
            reqrepID,
            this.get_name(),
            super.getEntityName(src_id),
            super.getEntityName(dst_id));
    this.write(msg);

    Sim_event ev = new Sim_event();
    Predicate predicate = new Predicate(Tags.PING_REP);
    super.sim_get_next(predicate, ev); // only look for this type of ack
    PingReply reply = PingReply.get_data(ev);
    Assert.assertEquals(requestID, reply.getRequestID());
    Assert.assertEquals(Tags.PING_REQ, reply.getRequestTAG());
    Assert.assertEquals(Tags.PING_REP, ev.get_tag());
    double evrecv_time = GridSim.clock();
    msg =
        String.format(
            "%1$f %2$d %3$s <-- AM_%4$s PING_REQUEST AM_%5$s",
            evrecv_time,
            reqrepID,
            this.get_name(),
            super.getEntityName(src_id),
            super.getEntityName(dst_id));
    this.write(msg);
    return reply;
  }