public GridletReply askGridletStatusToAgent(int dst_agentID, int dst_resID, Gridlet gridlet) {
    GridletRequest request =
        new GridletRequest(this.get_id(), this.get_id(), dst_agentID, dst_resID, gridlet);
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.GRIDLET_STATUS_REQ,
        new IO_data(request, gridlet.getGridletFileSize(), request.getDst_agentID()));

    Sim_type_p ptag = new Sim_type_p(Tags.GRIDLET_STATUS_REP);
    Sim_event ev = new Sim_event();
    super.sim_get_next(ptag, ev); // only look for this type of ack
    GridletReply gridletReply = GridletReply.get_data(ev);

    Assert.assertEquals(requestID, gridletReply.getRequestID());
    Assert.assertEquals(Tags.GRIDLET_STATUS_REQ, gridletReply.getRequestTAG());
    Assert.assertEquals(Tags.GRIDLET_STATUS_REP, ev.get_tag());
    double evrecv_time = GridSim.clock();
    String msg =
        String.format(
            "%1$f %2$d %3$s <-- GOT GRIDLET_STATUS_REP for Gridlet %4$d of Gridlet %5$d with status %6$d",
            evrecv_time,
            reqrepID,
            this.get_name(),
            gridletReply.getReceivedGridlet().getGridletID(),
            gridletReply.getRequest().getGridlet().getGridletID(),
            gridletReply.getRequest().getGridlet().getGridletStatus());
    this.write(msg);
    return gridletReply;
  }
  protected GISReply requestToGIS() {
    int SIZE = 500;
    double evsend_time = 0;
    GISRequest request = new GISRequest(this.get_id(), this.get_id());
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.GIS_REQUEST,
        new IO_data(request, SIZE, super.getEntityId("GISService")));
    evsend_time = GridSim.clock();
    String msg =
        String.format("%1$f %2$d %3$s --> GAP GIS_REQUEST", evsend_time, reqrepID, this.get_name());
    this.write(msg);

    Sim_event ev = new Sim_event();
    Predicate predicate = new Predicate(Tags.GIS_REPLY);
    super.sim_get_next(predicate, ev); // only look for this type of ack
    GISReply reply = GISReply.get_data(ev);
    Assert.assertEquals(requestID, reply.getRequestID());
    Assert.assertEquals(Tags.GIS_REQUEST, reply.getRequestTAG());
    Assert.assertEquals(Tags.GIS_REPLY, ev.get_tag());
    double evrecv_time = GridSim.clock();
    msg =
        String.format(
            "%1$f %2$d %3$s <-- GAP GIS_REPLY\n",
            evrecv_time, reqrepID, this.get_name(), reply.getGIS());
    this.write(msg);
    return reply;
  }
  public AgentReply hasGridletsAgent(AgentRequest request, boolean trace) {
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    double evsend_time = 0;
    int agentType = request.getDst_entityType();
    int SIZE = 500;
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.HASGRIDLETS_REQUEST,
        new IO_data(request, SIZE, request.getDst_agentID()));
    evsend_time = GridSim.clock();
    String msg =
        String.format(
            "%1$f %2$d %3$s --> AM_%4$s::HASGRIDLETS_REQUEST %6$s (%7$s AID %9$d) %5$s AM_%8$s",
            evsend_time,
            reqrepID,
            this.get_name(),
            super.getEntityName(request.getDst_resID()),
            EntityTypes.toString(request.getDst_entityType()),
            Tags.toString(Tags.HASGRIDLETS_REQUEST),
            super.getEntityName(request.getDst_agentID()),
            super.getEntityName(request.getDst_moveToresID()),
            request.getDst_AID());
    if (trace) {
      this.write(msg);
    }

    Sim_type_p ptag = new Sim_type_p(Tags.HASGRIDLETS_REPLY);
    Sim_event ev = new Sim_event();
    super.sim_get_next(ptag, ev); // only look for this type of ack
    AgentReply agentReply = AgentReply.get_data(ev);
    if (agentReply == null) {
      Assert.fail();
    }
    Assert.assertEquals(requestID, agentReply.getRequestID());
    Assert.assertEquals(Tags.HASGRIDLETS_REQUEST, agentReply.getRequestTAG());
    Assert.assertEquals(ev.get_tag(), Tags.HASGRIDLETS_REPLY);

    double evrecv_time = GridSim.clock();
    msg =
        String.format(
            "%1$f %2$d %3$s <-- AM_%4$s::%7$s %8$s (%6$s AID %10$d) %5$s AM_%9$s",
            evrecv_time,
            reqrepID,
            this.get_name(),
            super.getEntityName(agentReply.getRequest().getDst_resID()),
            EntityTypes.toString(agentType),
            super.getEntityName(request.getDst_agentID()),
            agentReply.isOk(),
            Tags.toString(Tags.HASGRIDLETS_REPLY),
            super.getEntityName(request.getDst_moveToresID()),
            request.getDst_AID());
    if (trace) {
      this.write(msg);
    }
    return agentReply;
  }
Exemple #4
0
  /** Reads jobs from data_set file and sends them to the Scheduler entity dynamically over time. */
  public void body() {
    super.gridSimHold(10.0); // hold by 10 second

    while (current_gl < total_jobs) {

      Sim_event ev = new Sim_event();
      sim_get_next(ev);

      if (ev.get_tag() == AleaSimTags.EVENT_WAKE) {

        ComplexGridlet gl = readGridlet(current_gl);
        current_gl++;
        if (gl == null && current_gl < total_jobs) {
          super.sim_schedule(this.getEntityId(this.getEntityName()), 0.0, AleaSimTags.EVENT_WAKE);
          continue;
        } else if (gl == null && current_gl >= total_jobs) {
          continue;
        }
        // to synchronize job arrival wrt. the data set.
        double delay = Math.max(0.0, (gl.getArrival_time() - super.clock()));
        // some time is needed to transfer this job to the scheduler, i.e., delay should be delay =
        // delay - transfer_time. Fix this in the future.
        // System.out.println("Sending: "+gl.getGridletID());
        last_delay = delay;
        super.sim_schedule(
            this.getEntityId("Alea_3.0_scheduler"), delay, AleaSimTags.GRIDLET_INFO, gl);

        delay = Math.max(0.0, (gl.getArrival_time() - super.clock()));
        if (current_gl < total_jobs) {
          // use delay - next job will be loaded after the simulation time is equal to the previous
          // job arrival.
          super.sim_schedule(this.getEntityId(this.getEntityName()), delay, AleaSimTags.EVENT_WAKE);
        }

        continue;
      }
    }
    System.out.println("Shuting down - last gridlet = " + current_gl + " of " + total_jobs);
    super.sim_schedule(
        this.getEntityId("Alea_3.0_scheduler"),
        Math.round(last_delay + 2),
        AleaSimTags.SUBMISSION_DONE,
        new Integer(current_gl));
    Sim_event ev = new Sim_event();
    sim_get_next(ev);

    if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) {
      System.out.println(
          "Shuting down the "
              + data_set
              + "_PWALoader... with: "
              + fail
              + " failed or skipped jobs");
    }
    shutdownUserEntity();
    super.terminateIOEntities();
  }
  public AgentReply testTestService() {
    double evsend_time = 0;
    int SIZE = 500;
    AgentRequest request = null;
    request =
        new AgentRequest(
            this.get_id(),
            this.get_id(),
            null,
            this.getVirtualOrganization().getPlatform().getGridElement().get_id(),
            Sim_system.get_entity_id("TestService"),
            EntityTypes.AGENT_ZOMBIE,
            SIZE,
            this.getVirtualOrganization().getPlatform().getGridElement().get_id(),
            EntityTypes.NOBODY);
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.TEST_SERVICE_REQ,
        new IO_data(request, SIZE, Sim_system.get_entity_id("TestService")));
    evsend_time = GridSim.clock();

    String msg =
        String.format(
            "%1$f %2$d %3$s --> %4$s", evsend_time, reqrepID, this.get_name(), "TestService");
    this.write(msg);

    Sim_type_p ptag = new Sim_type_p(Tags.TEST_SERVICE_REP);
    Sim_event ev = new Sim_event();
    super.sim_get_next(ptag, ev); // only look for this type of ack
    AgentReply reply = AgentReply.get_data(ev);

    Assert.assertEquals(requestID, reply.getRequestID());
    Assert.assertEquals(Tags.TEST_SERVICE_REQ, reply.getRequestTAG());
    Assert.assertEquals(Tags.TEST_SERVICE_REP, ev.get_tag());

    double evrecv_time = GridSim.clock();

    msg =
        String.format(
            "%1$f %2$d %3$s <-- %4$s", evrecv_time, reqrepID, this.get_name(), "TestService");
    this.write(msg);

    return reply;
  }
 protected void processEvent(Sim_event ev) {
   int tag = ev.get_tag();
   switch (tag) {
     default:
       this.processOtherEvent(ev);
       break;
   }
 }
  public GridletReply submitGridletToAgent(int dst_agentID, int dst_resID, Gridlet gridlet) {
    GridletRequest request =
        new GridletRequest(this.get_id(), this.get_id(), dst_agentID, dst_resID, gridlet);
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.GRIDLET_SUBMIT_REQ,
        new IO_data(request, gridlet.getGridletFileSize(), request.getDst_agentID()));

    Sim_type_p ptag = new Sim_type_p(Tags.GRIDLET_SUBMIT_REP);
    Sim_event ev = new Sim_event();
    super.sim_get_next(ptag, ev); // only look for this type of ack
    GridletReply reply = GridletReply.get_data(ev);

    Assert.assertEquals(requestID, reply.getRequestID());
    Assert.assertEquals(Tags.GRIDLET_SUBMIT_REQ, reply.getRequestTAG());
    Assert.assertEquals(Tags.GRIDLET_SUBMIT_REP, ev.get_tag());
    double evrecv_time = GridSim.clock();
    if (reply.isOk()) {
      String msg =
          String.format(
              "%1$f %2$d %3$s <-- GOT GRIDLET_REPLY for Gridlet %4$d of Gridlet %5$d with result TRUE on AM_%6$s",
              evrecv_time,
              reqrepID,
              this.get_name(),
              reply.getReceivedGridlet().getGridletID(),
              reply.getRequest().getGridlet().getGridletID(),
              super.getEntityName(reply.getRequest().getDst_resID()));
      this.write(msg);
    } else {
      String msg =
          String.format(
              "%1$f %2$d %3$s <-- GOT GRIDLET_REPLY for Gridlet %4$d of Gridlet %5$d with result FALSE on AM_%6$s",
              evrecv_time,
              reqrepID,
              this.get_name(),
              reply.getReceivedGridlet().getGridletID(),
              reply.getRequest().getGridlet().getGridletID(),
              super.getEntityName(reply.getRequest().getDst_resID()));
      this.write(msg);
    }
    return reply;
  }
  protected ServicesListReply requestServicesList() {
    int SIZE = 500;
    double evsend_time = 0;
    ServicesListRequest request = new ServicesListRequest(this.get_id(), this.get_id());
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    super.send(
        super.output,
        GridSimTags.SCHEDULE_NOW,
        Tags.AP_SERVICES_LIST_REQ,
        new IO_data(request, SIZE, this.getVirtualOrganization().getPlatform().get_id()));
    evsend_time = GridSim.clock();
    String msg =
        String.format(
            "%1$f %2$d %3$s --> %4$s SERVICES_LIST_REQUEST",
            evsend_time,
            reqrepID,
            this.get_name(),
            this.getVirtualOrganization().getPlatform().get_name());
    this.write(msg);

    Sim_event ev = new Sim_event();
    Predicate predicate = new Predicate(Tags.AP_SERVICES_LIST_REP);
    super.sim_get_next(predicate, ev); // only look for this type of ack
    ServicesListReply reply = ServicesListReply.get_data(ev);
    Assert.assertEquals(requestID, reply.getRequestID());
    Assert.assertEquals(Tags.AP_SERVICES_LIST_REQ, reply.getRequestTAG());
    Assert.assertEquals(Tags.AP_SERVICES_LIST_REP, ev.get_tag());
    double evrecv_time = GridSim.clock();
    msg =
        String.format(
            "%1$f %2$d %3$s <-- %4$s SERVICES_LIST_REPLY %5$s",
            evrecv_time,
            reqrepID,
            this.get_name(),
            this.getVirtualOrganization().getPlatform().get_name(),
            reply.getServicesList());
    this.write(msg);
    return reply;
  }
  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;
  }
  AgentReply requestToAgent(AgentRequest request, int tag) {
    int requestID = request.getRequestID();
    int reqrepID = request.getReqrepID();
    double evsend_time = 0;
    int agentType = request.getDst_entityType();
    int SIZE;
    if (tag == Tags.AGENT_RUN_REQ) {
      SIZE = request.getDst_agentSize();
    } else {
      SIZE = 500;
    }
    if ((tag == Tags.AGENT_RUN_REQ)
        || (tag == Tags.AGENT_KILL_REQ)
        || (tag == Tags.AGENT_KILLAWAIT_REQ)
        || (tag == Tags.AGENT_PAUSE_REQ)
        || (tag == Tags.AGENT_RESUME_REQ)) {
      super.send(
          super.output,
          GridSimTags.SCHEDULE_NOW,
          tag,
          new IO_data(request, SIZE, request.getDst_resID()));
    } else {
      super.send(
          super.output,
          GridSimTags.SCHEDULE_NOW,
          tag,
          new IO_data(request, SIZE, request.getDst_agentID()));
    }
    evsend_time = GridSim.clock();
    String msg =
        String.format(
            "%1$f %2$d %3$s --> AM_%4$s::REQUEST %6$s (%7$s AID %9$d) %5$s AM_%8$s",
            evsend_time,
            reqrepID,
            this.get_name(),
            super.getEntityName(request.getDst_resID()),
            EntityTypes.toString(request.getDst_entityType()),
            Tags.toString(tag),
            super.getEntityName(request.getDst_agentID()),
            super.getEntityName(request.getDst_moveToresID()),
            request.getDst_AID());
    this.write(msg);

    Sim_type_p ptag = new Sim_type_p(tag + 1);
    Sim_event ev = new Sim_event();
    super.sim_get_next(ptag, ev); // only look for this type of ack
    AgentReply agentReply = AgentReply.get_data(ev);

    if (agentReply != null) {
      Assert.assertEquals(requestID, agentReply.getRequestID());
      Assert.assertEquals(tag, agentReply.getRequestTAG());
      Assert.assertEquals(ev.get_tag(), tag + 1);

      double evrecv_time = GridSim.clock();
      msg =
          String.format(
              "%1$f %2$d %3$s <-- AM_%4$s::%7$s %8$s (%6$s AID %10$d) %5$s AM_%9$s",
              evrecv_time,
              reqrepID,
              this.get_name(),
              super.getEntityName(agentReply.getRequest().getDst_resID()),
              EntityTypes.toString(agentType),
              super.getEntityName(request.getDst_agentID()),
              agentReply.isOk(),
              Tags.toString(tag),
              super.getEntityName(request.getDst_moveToresID()),
              request.getDst_AID());
      this.write(msg);
    }
    return agentReply;
  }
Exemple #11
0
  public void body() {
    ArrayList<String> oppnetTasks = null;
    Help helpObject = null;

    boolean admitted = false;
    boolean Done = false;
    boolean Released = false;
    boolean sent = false;
    Node Inviting_Node = null;
    boolean validated = false;
    boolean joined = false;
    boolean canForward = false;
    boolean member = false;
    boolean admit = false;

    Helper Candidate_Helper = null;

    // Step 2.1: Node listens to incoming messages
    Sim_event ev = new Sim_event();
    ev = this.NODE_listen();
    if (ev.get_data() != null) {
      sim_trace(
          1,
          "Step 2.1 Done: "
              + this.get_name()
              + ", "
              + this.get_id()
              + " received a message from a node with id "
              + ev.get_src());

      // Step 2.2: Node processes the message (Node_processMsg)
      this.NODE_processMsg(this.msgPayloadReadtime);
      sim_trace(1, "msgpayloadReadtime from helper " + this.msgPayloadReadtime);
      validated = this.NODE_validate(ev);
      if (validated) {

        sim_trace(
            1,
            "Step 2.2 Done: "
                + this.get_name()
                + ", "
                + this.get_id()
                + " processes the message and it is a help request from "
                + Sim_system.get_entity(ev.get_src()).get_name()
                + ", "
                + Sim_system.get_entity(ev.get_src()).get_id());
        Inviting_Node = (Node) Sim_system.get_entity(ev.get_src());

        // Step 2.3: Node accepts invitation if it can join oppnet or is willing to join oppnet
        joined =
            this.NODE_joinOppnet(
                this.category,
                this.helperWorkloadRatio,
                Inviting_Node,
                this.ctrlMsgDelTimeThroughLinkToParent);

        if (joined) {
          sim_trace(
              1,
              "Step 2.3 Done: "
                  + this.get_name()
                  + ", "
                  + this.get_id()
                  + " accepted invitation of "
                  + Inviting_Node.get_name()
                  + ", "
                  + Inviting_Node.get_id());

          // Step 2.4: Node listens to admission notification
          ev = new Sim_event();
          ev = this.NODE_listen();
          if (ev.get_data() != null) {
            sim_trace(
                1,
                "Step 2.4 Done: "
                    + this.get_name()
                    + ", "
                    + this.get_id()
                    + " received a message from a node with id "
                    + ev.get_src());

            // Step 2.5: Node process the message (Node_processMsg)
            this.NODE_processMsg(this.msgPayloadReadtime);
            sim_process(this.msgPayloadReadtime);
            // Step 2.5a: Node_validate
            if (ev.get_data().equals("Admitted")) {
              sim_trace(
                  1,
                  "Step 2.5a Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " processes the message and it is admission notification from  "
                      + Sim_system.get_entity(ev.get_src()).get_name()
                      + ", "
                      + Sim_system.get_entity(ev.get_src()).get_id());
              admitted = true;
              Inviting_Node = (Node) Sim_system.get_entity(ev.get_src());
            }
          }
        } // if(joined)
      } // end if(validated)
    } // end if(ev.get_data()!=null))
    boolean received_helpObject = false;
    boolean received_oppnetTasks = false;

    if (admitted) {

      // Step 2.6: Node listen to help object and oppnet tasks from inviting node (Node_listen)
      while ((!received_helpObject) || (!received_oppnetTasks)) {
        ev = new Sim_event();
        ev = this.NODE_listen();
        if (ev.get_data() != null) {
          sim_trace(
              1,
              "Step 2.6: "
                  + this.get_name()
                  + ", "
                  + this.get_id()
                  + " received a message from a node with id "
                  + ev.get_src());
          // Step 2.7: Node processes the message (Node_processMsg)
          this.NODE_processMsg(this.msgPayloadReadtime);

          if (!received_helpObject && ((ev.get_tag() == 19) || (ev.get_tag() == 220))) {
            sim_trace(
                1,
                "Step 2.7: "
                    + this.get_name()
                    + ", "
                    + this.get_id()
                    + " processes the message and it is the help object from "
                    + Sim_system.get_entity(ev.get_src()).get_name()
                    + ","
                    + ev.get_src());
            helpObject = (Help) ev.get_data();
            received_helpObject = true;
          }
          if (!received_oppnetTasks && ((ev.get_tag() == 110) || (ev.get_tag() == 221))) {
            sim_trace(
                1,
                "Step 2.8: "
                    + this.get_name()
                    + ", "
                    + this.get_id()
                    + " processes the message and it is the oppnet tasks from "
                    + Sim_system.get_entity(ev.get_src()).get_name()
                    + ","
                    + ev.get_src());
            oppnetTasks = (ArrayList) ev.get_data();
            received_oppnetTasks = true;
          }
        }
      }

      // Step 2.9: Node checks which of the oppnet tasks it can perform (Node_selectTask) and
      // (Node_runApp)
      ArrayList<String> DeviceTasks = new ArrayList<String>();

      Done = this.NODE_selectTask(this, this.DeviceApps, oppnetTasks, helpObject, pr);
      // Done =  this.NODE_runApp(this.get_id(), this.get_name(), DeviceTasks, this.pr, helpObject);
      //  Done =  this.NODE_runApp(this, this.get_id(), this.get_name(), DeviceTasks, this.pr,
      // helpObject);

      // Step 2.10: Node check if the task done is the goal
      if (Done) {
        sim_trace(
            1, "Step 2.10: " + this.get_name() + ", " + this.get_id() + " is done with the goal");
        Released =
            this.NODE_reqRelease(
                this.get_id(),
                this.get_name(),
                Inviting_Node,
                this.ctrlMsgDelTimeThroughLinkToParent,
                "Done..ReqRelease");
      }

      if (!Done) {
        // Step 2.11: Helper did not do the goal.. so It scans for
        sim_trace(
            1,
            "Step 2.11: "
                + this.get_name()
                + ", "
                + this.get_id()
                + " I could not do the goal,, I will forward");
        CandidateHelpers = this.NODE_scan(this, pr, 100);

        sim_trace(
            1,
            "Step 2.12 Done: "
                + this.get_name()
                + ", "
                + this.get_id()
                + " is done scanning for helpers in range and found the following:");
        double startTime = Math.floor(Sim_system.sim_clock() * 100) / 100;

        if (CandidateHelpers.size() == 0) {
          sim_trace(1, "None");
          sim_trace(
              1,
              "Step 2.13: "
                  + this.get_name()
                  + ", "
                  + this.get_id()
                  + " Could not find grand kids");
          Released =
              this.NODE_reqRelease(
                  this.get_id(),
                  this.get_name(),
                  Inviting_Node,
                  this.ctrlMsgDelTimeThroughLinkToParent,
                  "NoGrandKids..ReqRelease");
          sent = true;
        } else {
          for (int z = 0; z < CandidateHelpers.size(); z++)
            sim_trace(
                1,
                this.get_name()
                    + ", "
                    + this.get_id()
                    + ", found "
                    + CandidateHelpers.get(z).get_name()
                    + ", ID = "
                    + CandidateHelpers.get(z).get_id());
        } // end else

        int i = 0;
        while (i < CandidateHelpers.size()) {
          // Step 2.14: Node discovers services in candidate helpers(Node_discover)
          canForward = this.NODE_discover(CandidateHelpers.get(i));

          if (canForward) {
            Candidate_Helper = CandidateHelpers.get(i);
            sim_trace(
                1,
                "Step 2.14 Done: "
                    + this.get_name()
                    + " ,"
                    + this.get_id()
                    + " discovered forwarding services in "
                    + Candidate_Helper.get_name()
                    + ", "
                    + Candidate_Helper.get_id());

            // Step 2.15: Node checks if the candidate helper is already a member of Oppnet
            // (Node_isMember)

            member = this.NODE_isMember(pr.oppnet, Candidate_Helper);
            if (member) {
              sim_trace(
                  1,
                  "Step 2.15 Done:"
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id()
                      + " is already a member of oppnet");
            } else {
              sim_trace(
                  1,
                  "Step 2.15 Done:"
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id()
                      + " is not a member of oppnet");

              // Step 2.16: Node sends a request for help to candidate helper (Node_regHelp)
              this.NODE_reqHelp(Candidate_Helper);
              this.numOfRequestedHelpersPerNode++;
              sim_trace(
                  1,
                  "Step 2.16 Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " sent a request for help to "
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id());
            } // end else
          } // end if(canForward)

          // Step 2.17: Node listens to invitation acceptance from candidate helper (Node_listen)
          ev = new Sim_event();
          ev = this.NODE_listen();
          if (ev.get_data() != null) {

            sim_trace(
                1,
                "Step 2.17 Done: "
                    + this.get_name()
                    + ", "
                    + this.get_id()
                    + " received a message from a node with id "
                    + ev.get_src());

            // Step 2.18a: Node evaluate the the node that accepted the invitation (Node_evalAdmit)
            this.NODE_processMsg(this.msgPayloadReadtime);
            admit = this.NODE_evalAdmit(ev, Candidate_Helper);

            if (ev.get_data().equals("Released")) {
              sim_trace(
                  1,
                  "Step 2.18a Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " evaluated the message and source and it is released notification from "
                      + Inviting_Node.get_name()
                      + ", "
                      + Inviting_Node.get_id());
              Released = true;
              break;
            }
            if (ev.get_data().equals("Done..ReqRelease")) {
              sim_trace(
                  1,
                  "Step 2.18a Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " evaluated the message and source and it is Done notification from "
                      + Sim_system.get_entity(ev.get_src()).get_name()
                      + ", "
                      + Sim_system.get_entity(ev.get_src()).get_id());
              Done = true;
              Released =
                  this.NODE_reqRelease(
                      this.get_id(),
                      this.get_name(),
                      Inviting_Node,
                      this.ctrlMsgDelTimeThroughLinkToParent,
                      "Done..ReqRelease");
              if (Released) break;
            }
            if (admit) {
              this.numOfJoindHelpersPerNode++;
              this.AdmittedHelpers.add(Candidate_Helper);
              pr.oppnet = this.NODE_addNode(pr.oppnet, Candidate_Helper);
              sim_trace(
                  1,
                  "Step 2.19a Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " added "
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id()
                      + " to oppnet");
              //  sim_trace(1, "Helper Integration Time = "+
              // Math.floor(Sim_system.sim_clock()*100)/100);
              double endTime = Math.floor(Sim_system.sim_clock() * 100) / 100;

              this.hlprIntegTime.add((endTime - startTime));

              // Step 2.20: Node sends help object to admitted helper (Node_report)
              this.NODE_report(Candidate_Helper, this.task2Runtime, 220, helpObject);
              sim_trace(
                  1,
                  "Step 2.20 Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " sent help object to "
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id());
              this.performedUrgent = true;
              this.tasksRunTimes.add(this.task2Runtime);

              // Step 2.21: Node sends oppnet tasks to admitted helper (Node_report)
              this.NODE_sendData(Candidate_Helper, this.task3Runtime, 221, oppnetTasks);
              sim_trace(
                  1,
                  "Step 2.21 Done: "
                      + this.get_name()
                      + ", "
                      + this.get_id()
                      + " sent oppnet tasks to "
                      + Candidate_Helper.get_name()
                      + ", "
                      + Candidate_Helper.get_id());
              this.tasksRunTimes.add(this.task3Runtime);

              break; // break once a single helper is integrated since it is a single helper mode
            } // end if(admit)
          } // end if(ev.get_data() != null)

          i++;
        } // end while(i<CandidateHelpers.size())

        if (!Released && !Done) {

          // Step 2.22a helper listens to Done or not Done from admitted helper or release from
          // inviting node
          int AH = 0;
          ev = new Sim_event();
          ev = this.NODE_listen();
          while (ev.get_data() != null) {
            sim_trace(
                1,
                "Step 2.22a Done: "
                    + this.get_name()
                    + " received a message from a node with id "
                    + ev.get_src());

            // Step 2.22b node process the message

            this.NODE_processMsg(this.msgPayloadReadtime);
            if (ev.get_data().equals("Done..ReqRelease")) {
              sim_trace(
                  1,
                  "Step 2.22b Done: "
                      + this.get_name()
                      + ","
                      + this.get_id()
                      + " evaluated the message and source and it is DONE notification from "
                      + Sim_system.get_entity(ev.get_src()).get_name()
                      + ", "
                      + Sim_system.get_entity(ev.get_src()).get_id());
              Done = true;

              // Step 2.23:Helper sends to inviting node that its admitted helpers done the job
              Released =
                  this.NODE_reqRelease(
                      this.get_id(),
                      this.get_name(),
                      Inviting_Node,
                      this.ctrlMsgDelTimeThroughLinkToParent,
                      "Done..ReqRelease");
              if (Released) break;
            } else if (ev.get_data().equals("NoGrandKids..ReqRelease")) {
              sim_trace(
                  1,
                  "Step 2.23 Done: "
                      + this.get_name()
                      + ","
                      + this.get_id()
                      + " evaluated the message and source and it is NoGrandKids notification from "
                      + Sim_system.get_entity(ev.get_src()).get_name()
                      + ", "
                      + Sim_system.get_entity(ev.get_src()).get_id());
              AH++;

              if (AH >= AdmittedHelpers.size() && (!Done) && (!Released) && (!sent)) {
                System.out.println(
                    this.get_name()
                        + ","
                        + this.get_id()
                        + " AH = "
                        + AH
                        + " admittedHelpers= "
                        + AdmittedHelpers.size());
                Released =
                    this.NODE_reqRelease(
                        this.get_id(),
                        this.get_name(),
                        Inviting_Node,
                        this.ctrlMsgDelTimeThroughLinkToParent,
                        "NoGrandKids..ReqRelease");

                if (Released) break;
              }
            } else if (ev.get_data().equals("Released")) {
              sim_trace(
                  1,
                  "Step 2.24 Done: "
                      + this.get_name()
                      + ","
                      + this.get_id()
                      + " evaluated the message and source and it is Released notification from "
                      + Sim_system.get_entity(ev.get_src()).get_name()
                      + ", "
                      + Sim_system.get_entity(ev.get_src()).get_id());
              Released = true;
              break;
            }
            ev = new Sim_event();
            ev = this.NODE_listen();
          } // end while(ev.get_data()!=null)
        } // end if (!released)

        // Step 2.25: release all children
        int w = 0;
        while (w < AdmittedHelpers.size()) {
          this.NODE_release(
              AdmittedHelpers.get(w), AdmittedHelpers.get(w).ctrlMsgDelTimeThroughLinkToParent);
          sim_trace(
              1,
              "Step 2.25 Done: "
                  + this.get_name()
                  + ", "
                  + this.get_id()
                  + " sent Released notification to "
                  + AdmittedHelpers.get(w).get_name()
                  + ", "
                  + AdmittedHelpers.get(w).get_id());

          pr.oppnet = this.NODE_remNode(AdmittedHelpers.get(w), pr.oppnet);
          sim_trace(
              1,
              "Step 2.26 Done: "
                  + this.get_name()
                  + ", "
                  + this.get_id()
                  + " removed "
                  + AdmittedHelpers.get(w).get_name()
                  + ", "
                  + AdmittedHelpers.get(w).get_id()
                  + " from oppnet");

          w++;
        }
      } // end if (!Done)
    } // if (admitted)

    SimOutput so = new SimOutput();
    String filename;
    PrintWriter oppnetFileWriter;

    if (this.AdmittedHelpers.size() > 0) {
      filename = "HelperIntegTime.txt";
      oppnetFileWriter = null;
      this.sumHelperItegTimePerInvNodePerIter = so.calculate_Sum(this.hlprIntegTime);
      so.outputFile1(
          this.hlprIntegTime.size(),
          true,
          filename,
          oppnetFileWriter,
          "Sum Helper Integ Time Per Node Per Iter",
          this.sumHelperItegTimePerInvNodePerIter,
          this.get_name(),
          this.get_id());

      //////////////////////////////////////////////////////////////////////////////////////////////////////////

      filename = "NumRequestedHelpers.txt";
      oppnetFileWriter = null;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Number of Requested Helpers Per Node Per Iter",
          this.numOfRequestedHelpersPerNode,
          this.get_name(),
          this.get_id());
      //////////////////////////////////////////////////////////////////////////////////////////////////////////

      filename = "NumJoinedHelpers.txt";
      oppnetFileWriter = null;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Number of Joined Helpers Per Node Per Iter",
          this.numOfJoindHelpersPerNode,
          this.get_name(),
          this.get_id());
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////
      filename = "NumRefusedHelpers.txt";
      oppnetFileWriter = null;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Number of Refused Helpers Per Node Per Iter",
          (this.numOfRequestedHelpersPerNode - this.numOfJoindHelpersPerNode),
          this.get_name(),
          this.get_id());
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
      filename = "NumAdmittedHelpers.txt";
      oppnetFileWriter = null;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Number of Admitted Helpers Per Node Per Iter",
          (this.AdmittedHelpers.size()),
          this.get_name(),
          this.get_id());
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }
    if (admitted) {
      filename = "HelperUnhurriedTask.txt";
      File f = new File(filename);

      oppnetFileWriter = null;
      int value;
      if (this.performedUnhurried) value = 1;
      else value = 0;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Performed Unhurried Task",
          value,
          this.get_name(),
          this.get_id());
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

      filename = "HelperUrgentTask.txt";
      File f2 = new File(filename);
      oppnetFileWriter = null;
      if (this.performedUrgent) value = 1;
      else value = 0;
      so.outputFile(
          true,
          filename,
          oppnetFileWriter,
          "Performed Urgent Task",
          value,
          this.get_name(),
          this.get_id());

      /////////////////////////////////////////////////////////////////////////////////////////////////////////

      this.sumTasksRunTimes = so.calculate_Sum(this.tasksRunTimes);

      filename = "TasksRuntimes.txt";
      // File file1 = new File(filename);
      oppnetFileWriter = null;
      so.outputFile1(
          this.tasksRunTimes.size(),
          true,
          filename,
          oppnetFileWriter,
          "Sum Task Runtimes Per Node Per Iter",
          this.sumTasksRunTimes,
          this.get_name(),
          this.get_id());
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

  } // end body