From: <aca...@us...> - 2008-07-22 09:44:27
|
Revision: 188 http://gridsim.svn.sourceforge.net/gridsim/?rev=188&view=rev Author: acaminero Date: 2008-07-22 09:44:36 +0000 (Tue, 22 Jul 2008) Log Message: ----------- Examples for the finite buffers extension Added Paths: ----------- branches/gridsim4.0-branch2/source/gridsim/fnbExample/ branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletExample_main.java branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser.java branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser_2.java branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbUser.java branches/gridsim4.0-branch2/source/gridsim/fnbExample/GridletSubmission.java branches/gridsim4.0-branch2/source/gridsim/fnbExample/mainExample.java Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletExample_main.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletExample_main.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletExample_main.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,289 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.fnbExample; + +import gridsim.*; +import gridsim.datagrid.*; +import gridsim.datagrid.index.DataGIS; +import gridsim.datagrid.index.TopRegionalRC; +import gridsim.datagrid.storage.HarddriveStorage; +import gridsim.datagrid.storage.Storage; +import gridsim.net.FIFOScheduler; +import gridsim.net.Link; +import gridsim.net.RIPRouter; +import gridsim.net.Router; +import gridsim.net.SimpleLink; +import gridsim.net.fnb.*; + + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.LinkedList; + + +/** + * This example demonstates the usage of DataGridlets in simulations. This class + * initializes all the entities, which are the same as in the other datagrid + * examples. The DataGridlet management is implemented in the class GridletUser. + * + * @author Uros Cibej and Anthony Sulistio + */ +public class FnbDataGridletExample_main { + public static void main(String[] args) { + + DataGIS gis = null; + TopRegionalRC rc = null; + DataGridUser user = null; + + int max_buffer_size = 1500; + int min_th = 466; + int max_th = 1400; + + // FIRST STEP--------------------------------------------- + // Initialize the GridSim package + int num_user = 1; // number of grid users + Calendar calendar = Calendar.getInstance(); + boolean trace_flag = false; // means trace GridSim events + boolean gisFlag = false; // means using DataGIS instead + GridSim.init(num_user, calendar, trace_flag, gisFlag); + + int totalUser = 15; + int totalResource = 5; + int total_gl = totalResource; + + //GridSim.init(NUM_USER, calendar, trace_flag); + GridSim.initNetworkType(GridSimTags.NET_BUFFER_PACKET_LEVEL); + + // set the GIS into DataGIS that handles specifically for data grid + // scenarios + try { + gis = new DataGIS(); + GridSim.setGIS(gis); + } catch (Exception e) { + e.printStackTrace(); + } + + // SECOND STEP--------------------------------------------- + // Create a top level Replica Catalogue + double baud_rate = 1000000000; // bits/sec + double propDelay = 10; // propagation delay in millisecond + int mtu = 1500; // max. transmission unit in byte + try { + SimpleLink l = new SimpleLink("rc_link", baud_rate, propDelay, mtu); + rc = new TopRegionalRC(l); + } catch (Exception e1) { + e1.printStackTrace(); + } + + // THIRD STEP--------------------------------------------- + // Create resources + int i = 0; + + ArrayList resList = new ArrayList(totalResource); + for (i = 0; i < totalResource; i++) { + DataGridResource res = createGridResource("Res_" + i, baud_rate, + propDelay, mtu); + resList.add(res); + } + + // FOURTH STEP--------------------------------------------- + // Create user(s) + try { + + for (i = 0; i < totalUser; i++) { + // To try a different examen, change the user class. + /* user = new FnbDataGridletUser("SIM_0_User_" + i, baud_rate, + propDelay, mtu, total_gl);*/ + + user = new FnbDataGridletUser_2("SIM_0_User_" + i, baud_rate, + propDelay, mtu); + user.setReplicaCatalogue(TopRegionalRC.DEFAULT_NAME); + } + } catch (Exception e2) { + e2.printStackTrace(); + } + + // FIFTH STEP--------------------------------------------- + // Create network + FnbRouter r1 = new FnbRIPRouter("router1", 1); // router 1 + FnbRouter r2 = new FnbRIPRouter("router2", 2); // router 2 + + try { + // connect the routers + baud_rate = 10000; + Link link = new SimpleLink("r1_r2_link", baud_rate, propDelay, mtu); + RED r1Sched = new RED("r1Sched", baud_rate, max_buffer_size, min_th, max_th, 0.003, 0.2, false); + RED r2Sched = new RED("r2Sched", baud_rate, max_buffer_size, min_th, max_th, 0.003, 0.2, false); + + // attach r2 to r1 + r1.attachRouter(r2, link, r1Sched, r2Sched); + } catch (Exception e3) + { + e3.printStackTrace(); + } + + // FIFTH STEP--------------------------------------------- + // Connect resources, users and catalogues to the network + + try + { + // connect resources + GridResource resObj = null; + for (i = 0; i < resList.size(); i++) + { + RED resSched = new RED("resSched_" +i, baud_rate, max_buffer_size, min_th, max_th, + 0.003, 0.2, false); + resObj = (GridResource) resList.get(i); + r2.attachHost(resObj, resSched); // attach the resource to router r2 + } + // connect user + RED userSched = new RED("userSched", baud_rate, max_buffer_size, min_th, max_th, + 0.003, 0.2, false); + r1.attachHost(user, userSched); // atach the user to router r1 + + // connect rc + RED rcSched = new RED("rcSched", baud_rate, 200, min_th, max_th, + 0.003, 0.2, false); + r2.attachHost(rc, rcSched); // attach RC + + } catch (Exception e4) // (ParameterException e4) + { + e4.printStackTrace(); + } + + // SIXTH STEP--------------------------------------------- + // Finally start the simulation + + + System.out.println("---- fnbWhiteList_ ---"); + for (int w = 0; w < GridSim.fnbWhiteList_.size(); w++) + { + System.out.println(GridSim.getEntityName(GridSim.fnbWhiteList_.get(w). + intValue())); + } + System.out.println("-------"); + + GridSim.startGridSimulation(); + + System.out.println("\n FINISH ..."); + } + + private static DataGridResource createGridResource(String name, + double baud_rate, double delay, int MTU) { + System.out.println(); + System.out.println("Starting to create one Grid resource with " + + "3 Machines"); + + // Here are the steps needed to create a Grid resource: + // 1. We need to create an object of MachineList to store one or more + // Machines + MachineList mList = new MachineList(); + + // 2. A Machine contains one or more PEs or CPUs. Therefore, should + // create an object of PEList to store these PEs before creating + // a Machine. + PEList peList1 = new PEList(); + + // 3. Create PEs and add these into an object of PEList. + // In this example, we are using a resource from + // hpc420.hpcc.jp, AIST, Tokyo, Japan + // Note: these data are taken the from GridSim paper, page 25. + // In this example, all PEs has the same MIPS (Millions + // Instruction Per Second) Rating for a Machine. + peList1.add(new PE(0, 377)); // need to store PE id and MIPS Rating + peList1.add(new PE(1, 377)); + peList1.add(new PE(2, 377)); + peList1.add(new PE(3, 377)); + + // 4. Create one Machine with its id and list of PEs or CPUs + mList.add(new Machine(0, peList1)); // First Machine + + // 5. Repeat the process from 2 if we want to create more Machines + // In this example, the AIST in Japan has 3 Machines with same + // MIPS Rating but different PEs. + // NOTE: if you only want to create one Machine for one Grid resource, + // then you could skip this step. + PEList peList2 = new PEList(); + + peList2.add(new PE(0, 377)); + peList2.add(new PE(1, 377)); + peList2.add(new PE(2, 377)); + peList2.add(new PE(3, 377)); + + mList.add(new Machine(1, peList2)); // Second Machine + + PEList peList3 = new PEList(); + // System.out.println("Creates a PE list for the 3rd Machine"); + + peList3.add(new PE(0, 377)); + peList3.add(new PE(1, 377)); + + mList.add(new Machine(2, peList3)); // Third Machine + + // 6. Create a ResourceCharacteristics object that stores the + // properties of a Grid resource: architecture, OS, list of + // Machines, allocation policy: time- or space-shared, time zone + // and its price (G$/PE time unit). + String arch = "Sun Ultra"; // system architecture + String os = "Solaris"; // operating system + double time_zone = 9.0; // time zone this resource located + double cost = 3.0; // the cost of using this resource + + ResourceCharacteristics resConfig = new ResourceCharacteristics(arch, + os, mList, ResourceCharacteristics.TIME_SHARED, time_zone, cost); + + // System.out.println("Creates the properties of a Grid resource and " + + // "stores the Machine list"); + + // 7. Finally, we need to create a GridResource object. + long seed = 11L * 13 * 17 * 19 * 23 + 1; + double peakLoad = 0.0; // the resource load during peak hour + double offPeakLoad = 0.0; // the resource load during off-peak hr + double holidayLoad = 0.0; // the resource load during holiday + + // incorporates weekends so the grid resource is on 7 days a week + LinkedList Weekends = new LinkedList(); + Weekends.add(new Integer(Calendar.SATURDAY)); + Weekends.add(new Integer(Calendar.SUNDAY)); + + // incorporates holidays. However, no holidays are set in this example + LinkedList Holidays = new LinkedList(); + DataGridResource gridRes = null; + try { + // create the replica manager + SimpleReplicaManager rm = new SimpleReplicaManager("RM_" + name, + name); + + // create the resource calendar + ResourceCalendar cal = new ResourceCalendar(time_zone, peakLoad, + offPeakLoad, holidayLoad, Weekends, Holidays, seed); + + // create a storage + Storage storage = new HarddriveStorage("storage", 100000); // 100GB + + // create the DataGrid resource + gridRes = new DataGridResource(name, new SimpleLink(name + "_link", + baud_rate, delay, MTU), resConfig, cal, rm); + + // add a storage to the resource + gridRes.addStorage(storage); + + // tell the resource about a replica catalogue + gridRes.setReplicaCatalogue(TopRegionalRC.DEFAULT_NAME); + + } catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Finally, creates one Grid resource (name: " + name + + " - id: " + gridRes.get_id() + ")"); + System.out.println(); + + return gridRes; + } +} Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,160 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.fnbExample; + +import eduni.simjava.Sim_event; +import eduni.simjava.Sim_type_p; +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.GridletList; +import gridsim.ParameterException; +import gridsim.datagrid.DataGridTags; +import gridsim.datagrid.DataGridUser; +import gridsim.datagrid.DataGridlet; +import gridsim.datagrid.File; +import gridsim.net.SimpleLink; +import eduni.simjava.Sim_system; +import gridsim.net.fnb.Fnb_failed_gridlet_file; + +/** + * This class implements a user which creates a set of data gridlets, i.e. a set + * of jobs that require a certain amount of computational power and some data in + * order to execute. The required data is described as a set of files that have + * to be available on the site when the gridlet starts to execute. When the + * gridlets are created, the user submits them to a set of resources and waits + * until all the gridlets have finished executing. + * + * @author Uros Cibej and Anthony Sulistio + */ +public class FnbDataGridletUser extends DataGridUser { + + + GridletList outList; // the list of outgoing gridlets + GridletList receiveList; //the list of executed gridlets + + int TOTAL_GL; + + // Constructor + FnbDataGridletUser(String name, double baud_rate, double delay, int MTU, int total_gl) + throws Exception { + + super(name, new SimpleLink(name + "_link", baud_rate, delay, MTU)); + this.receiveList = new GridletList(); + this.outList = new GridletList(); + + TOTAL_GL = total_gl; + + System.out.println("Creating a Gridlet user entity with name = " + name + + ", and id = " + super.getEntityId(name)); + } + + public void body() { + + experiment(); // execute a set of gridlets + + //////////////////////////////////////////////////////// + // shut down I/O ports + shutdownUserEntity(); + terminateIOEntities(); + System.out.println(this.get_name() + ":%%%% Exiting body() at time " + + GridSim.clock()); + } + + private void experiment() { + //wait for all the entities to register + super.gridSimHold(50.0); + + File f1 = null; + File f2 = null; + + //1. create new files + try { + f1 = new File("file1", 5); + f2 = new File("file2", 1); + } catch (ParameterException e) { + System.out.println("Error creating files"); + } + + //2. add files to a resource + //System.out.println("********* addMaster : file1 and file2 "); + if ((addMaster(f1, GridSim.getEntityId("Res_0")) == false) || + (addMaster(f2, GridSim.getEntityId("Res_1")) == false)) + { + System.out.println(" ************************ \n " + super.get_name() + + ": addMaster failed. Shutting down simulation\n ************************ "); + + } + else + { + //3. create TOTAL_GL data gridlets + for (int i = 0; i < TOTAL_GL; i++) + { + // set the ID of this gridlet, the gridlet length in MI, the size of + // the file before and after execution and whether we would like to + // log the history of this object + DataGridlet g = new DataGridlet(i, 1000, 10, 10, false); + + //the gridlet requires two files in order to execute + + //System.out.println("********* addRequiredFile "); + g.addRequiredFile(f1.getName()); + g.addRequiredFile(f2.getName()); + + // the gridlet needs the user id, so that the resource will be able + // to send it back when finished + g.setUserID(this.get_id()); + this.outList.add(g); + } + + //4. submit the data gridlets + for (int i = 0; i < TOTAL_GL; i++) + { + DataGridlet g = (DataGridlet) outList.get(i); + System.out.println(super.get_name() + ": Submitting gridlet " + i + + " to resource " + i); + + super.send(GridSim.getEntityId("Res_" + i), 0, + DataGridTags.DATAGRIDLET_SUBMIT, g); + } + + //5. wait for the gridlets to finish the execution + int counter = 0; + int glID ; + while ((Sim_system.running()) && (counter <TOTAL_GL)) + { + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue + + switch (ev.get_tag()) + { + // if everything works fine + case GridSimTags.GRIDLET_RETURN: + DataGridlet dg = (DataGridlet) ev.get_data(); + this.receiveList.add(dg); + counter = counter +1; + System.out.println(super.get_name() + ": Received back gridlet " + + dg.getGridletID()); + break; + + + // if the gl suffers a dropped pkt + case GridSimTags.FNB_GRIDLET_FAILED_BECAUSE_PACKET_DROPPED: + Fnb_failed_gridlet_file fglf = (Fnb_failed_gridlet_file)ev.get_data(); + glID = fglf.getEntityID(); + counter = counter +1; + System.out.println(super.get_name() + ": FNB_GRIDLET_FAILED_BECAUSE_PACKET_DROPPED. Gridlet " + glID); + break; + + }//switch (ev.get_tag()) + + }// while ((Sim_system.running()) && (counter <TOTAL_GL)) + + }// else + } + +} // end class Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser_2.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser_2.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbDataGridletUser_2.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,138 @@ +package gridsim.fnbExample; + +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +import gridsim.GridSim; +import gridsim.IO_data; +import gridsim.ParameterException; +import gridsim.datagrid.DataGridUser; +import gridsim.datagrid.File; +import gridsim.net.SimpleLink; + +import java.util.ArrayList; + +/** + * This is an implementation of a user which performs a set of file managing + * operations on the Data Grid. + * + * @author Uros Cibej and Anthony Sulistio + */ +class FnbDataGridletUser_2 extends DataGridUser { + + private String name_; // user name + + // Constructor + FnbDataGridletUser_2(String name, double baud_rate, double delay, int MTU) + throws Exception { + + super(name, new SimpleLink(name + "_link", baud_rate, delay, MTU)); + this.name_ = name; + + // Gets an ID for this entity + int userID = super.getEntityId(name); + System.out.println("Creating a grid user entity with name = " + name + + ", and id = " + userID); + } + + /** + * The core method that handles communications among GridSim entities. + */ + public void body() { + + experiment(); // execute a set of demands + + // shut down I/O ports + shutdownUserEntity(); + terminateIOEntities(); + System.out.println(this.name_ + ":%%%% Exiting body() at time " + + GridSim.clock()); + } + + private void experiment() { + + // wait for all entities to register + super.gridSimHold(50.0); + int location = 0; + boolean ok = true; + + // create three new files and add them as master files to resource Res_2 + try { + ArrayList fList = new ArrayList(); + int i = 0; + + do{ + + File fNew = new File("file_" + i, 10); + + if (addMaster(fNew, GridSim.getEntityId("Res_2")) == false) + { + System.out.println(" ************************ \n " + + super.get_name() + + ": addMaster failed. Shutting down simulation\n ************************ "); + + ok = false; + + } + + i++; + + + }while ((i < 3) && (ok)); + + } catch (ParameterException e) { + e.printStackTrace(); + } + + if (ok) + { + // get the full name of file1, i.e. file1+ID, where ID is a unique + // number assigned to the file by the top replica catalogue. + String name = getFullFilename("file_0"); + File f = null; + int fileLocation; + if (name != null) + { + // get the location of the file + location = this.getReplicaLocation(name); + if (location != -1) + { + // transfer the file + f = this.getFile(name, location); + System.out.println("user:" + this.get_name() + + ":-Transfer of file " + name + " succesful"); + } + } + + // replicate this file to Res_0 + replicateFile(f, GridSim.getEntityId("Res_0")); + + // replicate this file to Res_1 + replicateFile(f, GridSim.getEntityId("Res_1")); + + // delete replica of file from Res_0 + deleteFile(f.getName(), GridSim.getEntityId("Res_0")); + + // trying to delete a master file will not succeed + // for deleting the master file one should use deleteMaster() + deleteFile(f.getName(), GridSim.getEntityId("Res_2")); + + // but a master file cannot be deleted while there are replicas of the + // file on the Data Grid, so the following will also produce an error + deleteMaster(f.getName(), GridSim.getEntityId("Res_2")); + + // so we first have to delete the replica of file from Res_1 + deleteFile(f.getName(), GridSim.getEntityId("Res_1")); + + // and then we can delete the master file + deleteMaster(f.getName(), GridSim.getEntityId("Res_2")); + + }//if (ok) + } + +} // end class + Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbUser.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbUser.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/FnbUser.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,920 @@ +package gridsim.fnbExample; + +/* + * Title: FnbUser + * Description: An example of how to use the new functionality on finite buffers + * Date: May 2007 + */ + +import gridsim.fnbExample.*; +import gridsim.*; +import gridsim.net.Link; +import java.util.Random; +import java.util.ArrayList; +import java.io.FileWriter; +import eduni.simjava.Sim_system; +import eduni.simjava.Sim_event; +import gridsim.net.fnb.Fnb_failed_gridlet_file; + +/** + * An example of how to use the new functionality on finite buffers + * @author Agustin Caminero, Universidad de Castilla La Mancha (UCLM), Spain. May 2007 + */ +public class FnbUser extends GridUser { + + + public static final int BASE = 44; // the base for our constants (chosen at random) + + /**This constant is to tell the user when he should submit a gridlet*/ + public static final int SUBMIT_GRIDLET = BASE + 1; + + private ArrayList GridletSubmittedList_; // list of submitted Gridlets (array of GridletSubmission) + // private GridletList GridletReceiveList_; // list of received Gridlets + + int receivedGridletCounter; // counts how many gridlets have already comeback after being successfully executed + int ToS_; + int NUM_GRIDLETS; + int myID_; // for a user whose name is "User_0", its myID_ will be 0 + + + // The sizes of gridlets + long gridletLength; + long gridletInput; + long gridletOutput; + + double gridletSubmissionTime []; + // we keep here the time when each gridlet is submitted + + double gridletLatencyTime []; + + int droppedGridletsCounter; + // a counter to keep the number of gridlets which are failed because of dropped packets + + boolean droppedGridletsArray[]; + // a list of the failed gridlets (those which failed because of dropped packets) + + double init_time; //the time when this user will start submitting gridlets + + int resID;//the id of the resource to which this user will send his gl + + + + /** + * Creates a GridUserFailure object + * @param name this entity name + * @param link a network link connecting this entity + * @param myID for a user whose name is "User_0", its myID_ will be 0 + * @param pollTime the time between polls + * @param glLength length (MI) for the gridlets of this user + * @param glIn input file size for the gridlets of this user + * @param glOut output file size for the gridlets of this user + * @param init_time the time when this user will start submitting gridlets + * @param resID the id of the resource to which this user will send his gl + * @throws java.lang.Exception happens if either name or link is empty + * @pre name != null + * @pre link != null + * @post $none + */ + public FnbUser(String name, Link link, int myID, + long glLength, long glIn, long glOut, double init_time, int resID) throws Exception + { + //super(name,link, true); + super(name,link); + + this.GridletSubmittedList_ = new ArrayList(); + //this.GridletReceiveList_ = new GridletList(); + receivedGridletCounter = 0; + ToS_ = 0; + this.myID_ = myID; + + + gridletLength = glLength; + gridletInput = glIn; + gridletOutput = glOut; + + droppedGridletsCounter = 0; + + this.init_time = init_time; + this.resID = resID; + + } + + /** + * Creates a GridUserFailure object + * @param name this entity name + * @param link a network link connecting this entity + * @param regionalGIS a regional GridInformationService (GIS) entity name + * @param myID for a user whose name is "User_0", its myID_ will be 0 + * @param pollTime the time between polls + * @throws java.lang.Exception happens if one of the inputs is empty + * @pre name != null + * @pre link != null + * @pre regionalGIS != null + * @post $none + */ + public FnbUser(String name, Link link, String regionalGIS, int myID) throws + Exception + { + //super(name, link, true, regionalGIS); + super(name, link, regionalGIS); + ToS_ = 0; + this.myID_= myID; + + + } + + /** + * Sets the number of gridlets that this user has to submit. + * Also, create the submission and reception times arrays. + * @param gridlet_num the number of gridlets + */ + public void setGridletNumber(int gridlet_num) + { + NUM_GRIDLETS = gridlet_num; + + gridletSubmissionTime = new double[NUM_GRIDLETS]; + gridletLatencyTime = new double[NUM_GRIDLETS]; + + droppedGridletsArray = new boolean[NUM_GRIDLETS]; + for (int i = 0; i < NUM_GRIDLETS; i++) + { + droppedGridletsArray[i] = false; + } + + } + + /** + * Sets the Type of Service (ToS) that this packet receives in the network + * @param ToS Type of Service + */ + public void setNetServiceLevel(int ToS) { + this.ToS_ = ToS; + } + + + /** + * This function retrieves the list of available resources from the RegGIS. + * @return an array containing the ids of the resources + * */ + int [] getResList() + { + Object[] resList; + resList = super.getLocalResourceList(); + + /* + // REMOVE !!!!! + System.out.println("\n*********" + + super.get_name() + + ": Trying to get list of resources from GIS." + + "\n");*/ + + while ((resList == null) || (resList.length == 0)) + { + + resList = super.getLocalResourceList(); + + } + + int resourceID[] = null; + + if ((resList != null) && (resList.length != 0)) // if we have any resource + { + // System.out.println(super.get_name() + ": Got list of resources +++ "); + resourceID = new int[resList.length]; + + for (int x = 0; x < resList.length; x++) + { + // Resource list contains list of resource IDs + resourceID[x] = ((Integer) resList[x]).intValue(); + + } + + } + return resourceID; + } + + /** + * Handles incoming requests to this entity. + * @pre $none + * @post $none + */ + public void body() + { + initializeResultsFile(); + + createGridlet(NUM_GRIDLETS); + + //System.out.println(super.get_name() + ": sizeOf(): " + ); + + super.send(super.get_id(), + GridSimTags.SCHEDULE_NOW + init_time, + SUBMIT_GRIDLET); + + // init_time has been initialized at the constructor + + /* // Uncomment this if you want more info on the progress of the sims + System.out.println(super.get_name() + + ": initial SUBMIT_GRIDLET event will be at clock: " + + init_time + ". Current clock: " + + GridSim.clock());*/ + + + + // Now, we have the framework of the entity: + while (Sim_system.running()) + { + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue + + switch (ev.get_tag()) + { + // submit a gridlet + case SUBMIT_GRIDLET: + /* // Uncomment this if you want more info on the progress of the sims + System.out.println(super.get_name() + + ": received an SUBMIT_GRIDLET event. Clock: " + + GridSim.clock());*/ + processGridletSubmission(ev); // process the received event + + ev = null; // new, to call the garbage collector + break; + + // Receive a gridlet back + case GridSimTags.GRIDLET_RETURN: + /* // Uncomment this if you want more info on the progress of the sims + System.out.println(super.get_name() + + ": received an GRIDLET_RETURN event. Clock: " + + GridSim.clock());*/ + processGridletReturn(ev); + + ev = null; // new, to call the garbage collector + break; + + case GridSimTags.END_OF_SIMULATION: + System.out.println("\n============== " + super.get_name() + + ". Ending simulation..."); + break; + + // A gridlet has failed because a packet was dropped + case GridSimTags.FNB_GRIDLET_FAILED_BECAUSE_PACKET_DROPPED: + processGridletPacketDropping(ev); + + ev = null; // new, to call the garbage collector + break; + + default: + System.out.println(super.get_name() + + ": Received an event: " + ev.get_tag()); + + ev = null; // new, to call the garbage collector + break; + + } // switch (ev.get_tag()) + + }// while (Sim_system.running()) + + // remove I/O entities created during construction of this entity + super.terminateIOEntities(); + + //printGridletList(GridletReceiveList_, super.get_name(), false, gridletLatencyTime); + + }// body() + + /** + * This functions process the fail of a gridlet. The failure has happened + * because a packet was dropped. + * @param ev an incoming event + * */ + public void processGridletPacketDropping(Sim_event ev) + { + + Fnb_failed_gridlet_file fglf = (Fnb_failed_gridlet_file)ev.get_data(); + int glID = fglf.getEntityID(); + double clock = GridSim.clock(); + + if (droppedGridletsArray[glID] == false) + { + System.out.println("<<<<<<<<<<<<< " + super.get_name() + + ": Receiving GRIDLET_FAILED_BECAUSE_PACKET_DROPPED at time = " + + GridSim.clock() + ". Gridlet # " + glID); + + fw_write(super.get_name() + "\t" + glID + "\tGRIDLET_DROPPED\t" + clock + + "\n", super.get_name() + "_DroppedGridlets"); + + droppedGridletsArray[glID] = true; + + droppedGridletsCounter = droppedGridletsCounter + 1; + + removeGridletFromGridletSubmittedList(glID); + + if (receivedGridletCounter + droppedGridletsCounter == + NUM_GRIDLETS) + { + // In this case, the user has finished his work, as all the gridlets are back or failed. + // So, finish the simulation. + super.finishSimulation(); + } + + }//if (droppedGridletsArray[glID] == false) + + ev = null; // new, to call the garbage collector + } + + /** This function remove a gridlet from the GridletSubmittedList. + * @param glID the id of the gridlet to be removed */ + void removeGridletFromGridletSubmittedList(int glID) + { + int i = 0; + boolean found = false; + while ((i < GridletSubmittedList_.size()) && (!found)) + { + if (glID == + (((GridletSubmission) GridletSubmittedList_.get(i)).getGridlet()). + getGridletID()) + { + GridletSubmittedList_.remove(i); + found = true; + } + + i++; + } + } + /** + * This functions process the submission of a gridlet. We have to get the + * list of available resources from the RegGIS, choose one of them, and + * submit the gridlet. + * @param ev an incoming event + * */ + public void processGridletSubmission(Sim_event ev) + { + + /* We have to submit: + - the gridlet whose id comes with the event + - all the gridlets with the "gridletSub.getSubmitted() == false" + + So, set the gridletSub.getSubmitted() to false for the gridlet whose id comes with the event + */ + + int i = 0; + GridletSubmission gridletSub; + int resourceID[]; + Random random = new Random(5); // a random generator with a random seed + int index; + Gridlet gl; + Integer obj; + int glID; + + // This is becasue the initial GRIDLET_SUBMIT event, at the beginning + // of sims, does not have any gridlet id. We have to submit all the gridlets. + if (ev.get_data() instanceof Integer) + { + obj = (Integer) ev.get_data(); + glID = obj.intValue(); // get the gridlet id. + } + else + { + glID = 99; // a value at random, not used at all in this case + } + while (i < GridletSubmittedList_.size()) + { + gridletSub = (GridletSubmission)GridletSubmittedList_.get(i); + + if ( (gridletSub.getGridlet()).getGridletID() == glID ) + { + ((GridletSubmission) GridletSubmittedList_.get(i)).setSubmitted(false); + // set this gridlet whose id comes with the event as not submitted, + // so that it is submitted as soon as possible. + + } + + // Submit the gridlets with the "gridletSub.getSubmitted() == false" + if ( (gridletSub.getSubmitted() == false)) + { + // we have to resubmit this gridlet + gl = ((GridletSubmission) GridletSubmittedList_.get(i)). + getGridlet(); + + //resourceID = getResList(); // Get list of resources from the regGIS + // This list will never be empty + + + //index = random.nextInt(resourceID.length); + + System.out.println(">>>>>>>>>>>" + super.get_name() + + ". Sending Gridlet #" + i + + " to " + + GridSim.getEntityName(resID) + " at clock: " + + GridSim.clock()); + + + gridletSubmissionTime[gl.getGridletID()] = GridSim.clock(); + + super.gridletSubmit(gl, resID, 0, false, ToS_); + + ((GridletSubmission) GridletSubmittedList_.get(i)). + setSubmitted(true); // set the gridlet as submitted + + // Write into a results file + write(super.get_name(), "Sending", gl.getGridletID(), + GridSim.getEntityName(resID), gl.getGridletStatusString(), + GridSim.clock()); + + } // if (gridletSub.getSubmitted() == false) + + i++; + + } // while (i < GridletSubmittedList_.size()) + + }// processGridletSubmission + + /** + * This functions process the return of a gridlet. We pay attention to the status of the gridlet + * and then decide what we have to do the next + * @param ev an incoming event + * */ + public void processGridletReturn(Sim_event ev) + { + Object obj = (Object) ev.get_data(); + Gridlet gl = null; + Random random = new Random(5); // a random generator with a random seed + + if (obj instanceof Gridlet) + { + gl = (Gridlet) obj; + + gridletLatencyTime[gl.getGridletID()] = GridSim.clock(); + + // Write into a results file + write(super.get_name(), "Receiving", gl.getGridletID(), + GridSim.getEntityName(gl.getResourceID()), + gl.getGridletStatusString(), + GridSim.clock()); + + //////////////////////////////////////////////////// Gridlet Success + if (gl.getGridletStatusString().compareTo("Success") == 0) + { + // Gridlet successed! + System.out.println("<<<<<<<<<<<<< " + super.get_name() + + ": Receiving Gridlet #" + + gl.getGridletID() + + " with status Success at time = " + + GridSim.clock() + " from resource " + + GridSim.getEntityName(gl.getResourceID())); + + //this.GridletReceiveList_.add(gl); // add into the received list + + receivedGridletCounter = receivedGridletCounter +1; + + gridletLatencyTime[gl.getGridletID()] = gridletLatencyTime[ + gl.getGridletID()] - + gridletSubmissionTime[gl.getGridletID()]; + + + // remove the gridlet, to safe memory + removeGridletFromGridletSubmittedList(gl.getGridletID()); + gl = null; + + // We have received all the gridlets. So, finish the simulation. + if ((receivedGridletCounter == NUM_GRIDLETS) || + (receivedGridletCounter + droppedGridletsCounter == NUM_GRIDLETS)) + { + super.finishSimulation(); + } + + + + } // if (gl.getGridletStatusString() == "Success") + + ///////////////////////////////////////////////////// Gridlet Failed + else if (gl.getGridletStatusString().compareTo("Failed") == 0) + { + System.out.println("<<<<<<<<<<<<< " + super.get_name() + + ": Receiving Gridlet #" + + gl.getGridletID() + + " with status Failed at time = " + + GridSim.clock() + " from resource " + + GridSim.getEntityName(gl.getResourceID())); + + // Send the gridlet as soon as we have resources available. + // This gridlet will be resend as soon as possible, in the first loop. + int pos = findGridletInGridletSubmittedList(gl); + if (pos == -1) + System.out.println("+++++++ " + super.get_name() + + ". Gridlet not found in GridletSubmittedList. +++++++"); + else + { + + ((GridletSubmission) GridletSubmittedList_.get( + pos)).setSubmitted(true); + // set this gridlet as submitted, because otherwise this gridlet may be submitted several times. + // A gridlet will only be submitted when the event carrying its id reaches the user + + // Now, schedule an event to this entity to submit the gridlet + // The gridlet will be sent as soon as possible + + Integer glID_Int = new Integer(gl.getGridletID()); + // This event includes the gridletID, so that the user will try to submit only this gridlet + super.send(super.get_id(), + GridSimTags.SCHEDULE_NOW, + SUBMIT_GRIDLET, glID_Int); + + + } + + } // if (gl.getGridletStatusString() == "Failed") + else + System.out.println("<<<<<<<<<<<<< " + super.get_name() + + ": Receiving Gridlet #" + + gl.getGridletID() + " with status " + + gl.getGridletStatusString() + + " at time = " + + GridSim.clock() + " from resource " + + GridSim.getEntityName(gl.getResourceID()) + + " resID: " + gl.getResourceID()); + + }// if (obj instanceof Gridlet) + + + } + + /** + * Prints the Gridlet objects + * @param list the list of gridlets + * @param name the name of the user + * @param detail if we want the gridlet's history or not + * @param gridletLatencyTime array containing the latencies of gridlets. + * Latencies are from the moment when the gridlet is sent, till + * the moment they are back at the user. They take into account the last submission of a gridlet + * (when the gridlet is successfully run) + */ + private static void printGridletList(GridletList list, String name, + boolean detail, double gridletLatencyTime[]) + { + int size = list.size(); + Gridlet gridlet = null; + + String indent = " "; + System.out.println(); + System.out.println("============= OUTPUT for " + name + " =========="); + System.out.println("Gridlet ID" + indent + "STATUS" + indent + + "Resource ID" + indent + "Cost" + indent + + "CPU Time"+ indent + "Latency"); + + // a loop to print the overall result + int i = 0; + for (i = 0; i < size; i++) + { + gridlet = (Gridlet) list.get(i); + System.out.print(indent + gridlet.getGridletID() + indent + + indent); + + System.out.print(gridlet.getGridletStatusString()); + + System.out.println(indent + indent + gridlet.getResourceID() + + indent + indent + gridlet.getProcessingCost() + + indent + indent + gridlet.getActualCPUTime()+ + indent + indent + + gridletLatencyTime[gridlet.getGridletID()]); + + writeFin(name, gridlet.getGridletID(), + GridSim.getEntityName(gridlet.getResourceID()), + gridlet.getProcessingCost(), gridlet.getActualCPUTime(), + GridSim.clock()); + + + + } + + + if (detail == true) + { + // a loop to print each Gridlet's history + for (i = 0; i < size; i++) + { + gridlet = (Gridlet) list.get(i); + System.out.println(gridlet.getGridletHistory()); + + System.out.print("Gridlet #" + gridlet.getGridletID()); + System.out.println(", length = " + gridlet.getGridletLength() + + ", finished so far = " + + gridlet.getGridletFinishedSoFar()); + System.out.println("======================================\n"); + } + } + + System.out.println("================================================="); + + } + + /** + * This method will show you how to create Gridlets + * @param userID owner ID of a Gridlet + * @param numGridlet number of Gridlet to be created + */ + private void createGridlet(int userID, int numGridlet) + { + + for (int i = 0; i < numGridlet; i++) + { + // Creates a Gridlet + Gridlet gl = new Gridlet(i, gridletLength, gridletInput, gridletOutput); + gl.setUserID(userID); + + GridletSubmission gst = new GridletSubmission(gl, false); + + // add this gridlet into a list + this.GridletSubmittedList_.add(gst); + + } + + } + + /** + * Gets a list of received Gridlets + * @return a list of received/completed Gridlets + */ + /*public GridletList getGridletList() { + return GridletReceiveList_; + }*/ + + /** + * Tells you the possition of this gridlet in the GridletSubmittedList_ + * @param gl the gridlet + * @return the position of this gridlet in the list of submitted gridlets */ + public int findGridletInGridletSubmittedList(Gridlet gl) + { + Gridlet g = null; + GridletSubmission gst = null; + for (int i = 0; i< GridletSubmittedList_.size(); i++) + { + gst = (GridletSubmission)GridletSubmittedList_.get(i); + g = gst.getGridlet(); + + if ( g.getGridletID() == gl.getGridletID() ) + return i; + } + + return -1; + } + + /** + * This function returns true if the gridlet is in the GridletReceiveList_. + * This is, the gridlet has already been successfully executed, and + * received back at the user. Returns false otherwise + * @param glID the id of the gridlet + * */ + /*public boolean IsInGridletReceiveList(int glID) + { + for (int i = 0; i<GridletReceiveList_.size(); i++) + { + if (((Gridlet)GridletReceiveList_.get(i)).getGridletID() == glID) + return true; + } + + return false; + + }*/ + + /** This function resets the gridlet into its original values of length and gridletFinishedSoFar + * @param gl the gridlet to be resetted */ + public void resetGridlet (Gridlet gl) + { + gl.setGridletLength(gridletLength); + gl.setGridletFinishedSoFar(0); + + } + + /** + * This method will show you how to create Gridlets + * @param userID the id of the user to whom this gl belongs + * @param numGridlet number of Gridlet to be created + * @param MILength length of the gridlet in MI + * @param size size of the input/output files + */ + private void createGridlet(int numGridlet) + { + // This function has been copied from the source code sent by Anthony (MainUser.java) + + long data; + int MI = 0; + double percent = 0.30; // 30 % + Random r = new Random(); + + // running approx. 20 mins on CERN node of 70k MIPS +/- 30% + double min_size = gridletLength - (gridletLength * percent); + double max_size = gridletLength + (gridletLength * percent); + int range = 1 + (int) (max_size - min_size); // round up + + + // for network + double data_min = gridletInput - (gridletInput * percent); + double data_max = gridletInput + (gridletInput * percent); + int data_range = 1 + (int) (data_max - data_min); // round up + + + for (int i = 0; i < numGridlet; i++) + { + MI = (int) min_size + r.nextInt(range); + data = (long) data_min + r.nextInt(data_range); + + // Creates a Gridlet + Gridlet gl = new Gridlet(i, MI, data, data); + gl.setUserID(super.get_id()); + gl.setNetServiceLevel(ToS_); + + GridletSubmission gst = new GridletSubmission(gl, false); + + // add this gridlet into a list + this.GridletSubmittedList_.add(gst); + + } + + } + + /** + * Write some data into the final results file. + * @param user user name + * @param glID gridlet id + * @param resName Name of the resource + * @param cost the processing cost of the gridlet + * @param cpu the cpu time + * @param clock Current time + * */ + public static void writeFin(String user, int glID, String resName, double cost, double cpu, double clock) + { + // Write into a results file + FileWriter fwriter = null; + try + { + fwriter = new FileWriter(user+"_Fin", true); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while opening file " + user+"_Fin"); + } + + try + { + fwriter.write(user +"\t "+ glID + "\t" + + resName + "\t" + cost + "\t"+ cpu + "\t" + + clock + "\n"); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while writing on file " + user+"_Fin"); + } + + try + { + fwriter.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while closing file " + user+"_Fin"); + } + + } + + /** + * Write some data into a results file. + * @param user user name + * @param event Values: "Sending" or "Receive" a gridlet + * @param glID gridlet id + * @param resName Name of the resource + * @param status Status of the gridlet + * @param clock Current time + * */ + public void write(String user, String event, int glID, String resName, String status, double clock) + { + // Write into a results file + FileWriter fwriter = null; + try + { + fwriter = new FileWriter(super.get_name(), true); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while opening file " + super.get_name()); + } + + try + { + fwriter.write(user + "\t " + event + "\t" + glID + "\t" + + resName + "\t" + status + "\t\t" + clock + "\n"); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while writing on file " + super.get_name()); + } + + try + { + fwriter.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while closing file " + super.get_name()); + } + + } + + + /** + * Initialize the results files (put headers over each column) + * */ + public void initializeResultsFile() + { + // Initialize the results file + FileWriter fwriter = null; + FileWriter fwriterFin = null; + FileWriter fwriterDropped = null; + try + { + fwriter = new FileWriter(super.get_name(), true); + fwriterFin = new FileWriter(super.get_name() + "_Fin", true); + fwriterDropped = new FileWriter(super.get_name() + "_DroppedGridlets", true); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while opening file " + super.get_name()+" or " + super.get_name()+"_Fin"); + } + + try + { + fwriter.write( + "User \t\t Event \t GridletID \t Resource \t GridletStatus \t\t\t Clock \n"); + fwriterFin.write( "User \t\t GridletID \t Resource \t Cost \t CPU time \t Latency\n"); + + fwriterDropped.write( "User \t\t GridletID \t Status \t Time\n"); + + + + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while writing on file " + super.get_name() + + " or " + super.get_name() + "_Fin" + " or " + super.get_name() + "_DroppedGridlets"); + } + + try + { + fwriter.close(); + fwriterFin.close(); + fwriterDropped.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println( + "Unwanted errors while closing file " + super.get_name() + " or " + + super.get_name() + "_Fin" + " or " + super.get_name() + + "_DroppedGridlets"); + } + } + /** + * Prints out the given message into stdout. + * In addition, writes it into a file. + * @param msg a message + * @param file file where we want to write + */ + private static void fw_write(String msg, String file) + { + //System.out.print(msg); + FileWriter fwriter = null; + + try + { + fwriter = new FileWriter(file, true); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while opening file " + file); + } + + try + { + fwriter.write(msg); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while writing on file " + file); + } + + try + { + fwriter.close(); + } catch (Exception ex) + { + ex.printStackTrace(); + System.out.println("Unwanted errors while closing file " + file); + } + } + + +} Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/GridletSubmission.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/GridletSubmission.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/GridletSubmission.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,64 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + * $Id:$ + */ + + +/* + * Agustin Caminero + * Instituto de Investigacion en Informatica de Albacete + * Universidad de Castilla La Mancha, Spain + * January, 2007. + * + * This class implements the submission time of each gridlet. + * + */ + + +package gridsim.fnbExample; + +import gridsim.Gridlet; + +/** + * @author Agustin Caminero, Universidad de Castilla La Mancha (UCLM), Spain. Nov 2006. + * This class implements the submission time of each gridlet. + * @since GridSim 4.1 + */ +public class GridletSubmission +{ + private Gridlet gl; + private boolean submitted; // whether this gridlet has been already submitted or not + + public GridletSubmission(Gridlet gl,boolean submitted) + { + this.gl = gl; + this.submitted = submitted; + } + + public Gridlet getGridlet() + { + return gl; + } + + public boolean getSubmitted() + { + return submitted; + } + + public void setGridlet(Gridlet g) + { + this.gl = g; + } + + public void setSubmitted(boolean submitted) + { + this.submitted = submitted; + } + + + +} Property changes on: branches/gridsim4.0-branch2/source/gridsim/fnbExample/GridletSubmission.java ___________________________________________________________________ Added: svn:executable + * Added: branches/gridsim4.0-branch2/source/gridsim/fnbExample/mainExample.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/fnbExample/mainExample.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/fnbExample/mainExample.java 2008-07-22 09:44:36 UTC (rev 188) @@ -0,0 +1,1194 @@ +package gridsim.fnbExample; + + +/* + * Author: Agustin Caminero, Universidad de Castilla La Mancha, (Spain). + * Date: May 2007 + */ + + +import gridsim.net.fnb.*; +import gridsim.*; +import gridsim.net.*; +import java.util.*; +import gridsim.index.RegionalGIS; +import gridsim.fnbExample.*; +import gridsim.util.TrafficGenerator; +import eduni.simjava.distributions.Sim_uniform_obj; +import gridsim.util.Poisson; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.FileWriter; + + +/** + * @author Agustin Caminero, Universidad de Castilla La Mancha (UCLM), Spain. May 2007. + */ +public class mainExample +{ + /** + * Creates main() to run this example + */ + public static void main(String[] args) + { + System.out.println("Starting finite buffers example ..."); + + try + { + if (args.length < 1) + { + System.out.println( + "Usage: java mainExample config_file"); + return; + } + + /////////// args[0] + String CONFIG_FILE = args[0]; + + + /////////////////////////////////// + String storeStats_str = searchForValueString("STORE_STATS", + CONFIG_FILE); + + boolean STORE_STATS; + + if (storeStats_str.compareTo("TRUE") == 0) + STORE_STATS = true; + else + STORE_STATS = false; + + /////////////////////////////////// + int TOT... [truncated message content] |