|
From: <sul...@us...> - 2008-10-12 06:37:35
|
Revision: 255
http://gridsim.svn.sourceforge.net/gridsim/?rev=255&view=rev
Author: sulistio
Date: 2008-10-12 06:37:26 +0000 (Sun, 12 Oct 2008)
Log Message:
-----------
add Finite Buffer and Flow examples, done by Agustin and James respectively
Added Paths:
-----------
trunk/examples/Network/FiniteBuffer01/
trunk/examples/Network/FiniteBuffer01/FnbUser.java
trunk/examples/Network/FiniteBuffer01/GridletSubmission.java
trunk/examples/Network/FiniteBuffer01/README.txt
trunk/examples/Network/FiniteBuffer01/mainExample.java
trunk/examples/Network/FiniteBuffer01/network_example.txt
trunk/examples/Network/Flow/
trunk/examples/Network/Flow/Example01/
trunk/examples/Network/Flow/Example01/FlowNetEx01.java
trunk/examples/Network/Flow/Example01/FlowNetUser.java
trunk/examples/Network/Flow/Example01/FlowTest.java
trunk/examples/Network/Flow/Example01/README.txt
trunk/examples/Network/Flow/Example01/output.txt
trunk/examples/Network/Flow/Example01/test1.csv
trunk/examples/Network/Flow/Example01/test2.csv
trunk/examples/Network/Flow/Example02/
trunk/examples/Network/Flow/Example02/FlowNetEx02.java
trunk/examples/Network/Flow/Example02/FlowNetUser.java
trunk/examples/Network/Flow/Example02/README.txt
trunk/examples/Network/Flow/Example02/User_0.csv
trunk/examples/Network/Flow/Example02/User_1.csv
trunk/examples/Network/Flow/Example02/output.txt
trunk/examples/Network/Flow/Example02/router1_report.csv
trunk/examples/Network/Flow/Example02/router2_report.csv
Added: trunk/examples/Network/FiniteBuffer01/FnbUser.java
===================================================================
--- trunk/examples/Network/FiniteBuffer01/FnbUser.java (rev 0)
+++ trunk/examples/Network/FiniteBuffer01/FnbUser.java 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,817 @@
+/*
+ * 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
+ *
+ * Authors: Agustin Caminero and Anthony Sulistio
+ * Organization: Universidad de Castilla La Mancha (UCLM), Spain.
+ * Copyright (c) 2008, The University of Melbourne, Australia and
+ * Universidad de Castilla La Mancha (UCLM), Spain
+ */
+
+
+import gridsim.*;
+import gridsim.net.Link;
+import java.util.Random;
+import java.util.ArrayList;
+import java.io.*;
+import eduni.simjava.Sim_system;
+import eduni.simjava.Sim_event;
+import gridsim.net.fnb.*;
+
+
+/**
+ * An example of how to use the new functionality on finite buffers.
+ * The functionality of this class, implemented in the body() method, is as follows.
+ * 1. create n number of gridlets and a new csv file for statistics purposes
+ * 2. send a reminder to itself to send the gridlets
+ * 3. after receving a reminder at a later time, proceeds to
+ * the processGridletSubmission() method, where
+ * - it submits all gridlets in the list to a particular resource
+ * - it sets the gridlet submission time and status
+ *
+ * 4. after submitting all gridlets, then wait for incoming events
+ * - if a new event is regarding to receiving a Gridlet
+ * + remove this gridlet from the submission list
+ * + sets the gridlet latency time and status
+ *
+ * - if a new event is regarding to a gridlet being dropped in the network
+ * + remove this gridlet from the submission list
+ * + sets the gridlet latency time and status
+ * + marks this gridlet as being dropped by the router
+ *
+ * 5. after all gridlets have been received, then exit the body() method and
+ * prints the statistics into a csv file.
+ *
+ * @author Agustin Caminero and Anthony Sulistio
+ */
+public class FnbUser extends GridUser
+{
+ // list of submitted Gridlets (array of GridletSubmission)
+ private ArrayList GridletSubmittedList_;
+
+ // counts how many gridlets have already comeback after being successfully
+ // executed
+ private int receivedGridletCounter;
+ private int ToS_; // type of service for differentiated network QoS
+ private int NUM_GRIDLETS;
+
+ // for a user whose name is "User_0", its myID_ will be 0, and so on.
+ // this ID is set at the beginning or when you create an object of this class
+ private int myID_;
+
+ // The sizes of gridlets
+ private long gridletLength; // denotes computational time
+ private long gridletInput; // denotes input file size for each gridlet
+ private long gridletOutput; // denotes output file size for each gridlet
+
+ // we store the time when each gridlet is submitted
+ private double gridletSubmissionTime[];
+
+ // we store the most recent status of each gridlet during execution
+ private String gridletStatus[];
+
+ // we store the total execution time, i.e.
+ // time of receiving - time of submission
+ double gridletLatencyTime[];
+
+ // a counter to keep the number of gridlets which are failed because of
+ // dropped packets
+ int droppedGridletsCounter;
+
+ // a list of the failed gridlets (those which failed because of
+ // dropped packets)
+ boolean droppedGridletsArray[];
+
+ 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 FnbUser object
+ * @param name this entity name
+ * @param link a network link connecting this entity
+ * @param myID a user ID
+ * @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 resource ID for sending the user's Gridlets
+ * @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);
+
+ this.GridletSubmittedList_ = new ArrayList();
+ receivedGridletCounter = 0;
+ droppedGridletsCounter = 0;
+ ToS_ = 0;
+ this.myID_ = myID;
+
+ gridletLength = glLength;
+ gridletInput = glIn;
+ gridletOutput = glOut;
+
+ this.init_time = init_time;
+ this.resID = resID;
+ }
+
+
+ /**
+ * Creates a FnbUser object
+ * @param name this entity name
+ * @param link a network link connecting this entity
+ * @param regionalGIS a regional GridInformationService (GIS) entity name
+ * @param myID a user ID
+ * @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, regionalGIS);
+
+ this.GridletSubmittedList_ = new ArrayList();
+ receivedGridletCounter = 0;
+ droppedGridletsCounter = 0;
+ ToS_ = 0;
+ this.myID_ = myID;
+
+ gridletLength = 0;
+ gridletInput = 0;
+ gridletOutput = 0;
+
+ this.init_time = 0;
+ this.resID = 0;
+ }
+
+
+ /**
+ * Sets the number of gridlets for submission.
+ * Also, creates 2 arrays for storing submission and receiving time of
+ * each Gridlet
+ * @param gridlet_num number of gridlets
+ */
+ public void setGridletNumber(int gridlet_num)
+ {
+ NUM_GRIDLETS = gridlet_num;
+ gridletSubmissionTime = new double[NUM_GRIDLETS];
+ gridletLatencyTime = new double[NUM_GRIDLETS];
+ gridletStatus = new String[NUM_GRIDLETS];
+
+ // initialise whether each Gridlet has been dropped in the network or not
+ droppedGridletsArray = new boolean[NUM_GRIDLETS];
+ for (int i = 0; i < NUM_GRIDLETS; i++)
+ {
+ droppedGridletsArray[i] = false; // hasn't been dropped in the network
+ gridletStatus[i] = "Created";
+ }
+ }
+
+
+ /**
+ * 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;
+ }
+
+
+ /**
+ * Handles incoming requests to this entity.
+ * @pre $none
+ * @post $none
+ */
+ public void body()
+ {
+ initializeResultsFile(); // create new files for statistics
+ createGridlet(NUM_GRIDLETS); // create gridlets
+
+ // send a reminder to itself at time init_time, with a message to
+ // submit Gridlets.
+ super.send(super.get_id(), GridSimTags.SCHEDULE_NOW + init_time * 10,
+ GridSimTags.GRIDLET_SUBMIT);
+
+ /*****
+ // 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());
+ ******/
+
+
+ // a loop that keeps waiting for incoming events
+ while (Sim_system.running())
+ {
+ Sim_event ev = new Sim_event();
+ super.sim_get_next(ev); // get the next event in the incoming queue
+
+ // exit the loop if we get a signal of end of simulation
+ if (ev.get_tag() == GridSimTags.END_OF_SIMULATION)
+ {
+ System.out.println("============== " + super.get_name() +
+ ". Ending simulation...");
+ break;
+ }
+
+ // for other events or activities
+ switch (ev.get_tag())
+ {
+ // submit a gridlet
+ case GridSimTags.GRIDLET_SUBMIT: //SUBMIT_GRIDLET:
+ /***
+ // Uncomment this if you want more info on the progress
+ System.out.println(super.get_name() +
+ ": received an SUBMIT_GRIDLET event. Clock: " + GridSim.clock());
+ ****/
+ processGridletSubmission(ev); // process the received event
+ break;
+
+ // Receive a gridlet back from the resource
+ case GridSimTags.GRIDLET_RETURN:
+ /*****
+ // Uncomment this if you want more info on the progress
+ System.out.println(super.get_name() +
+ ": received an GRIDLET_RETURN event. Clock: " + GridSim.clock());
+ ****/
+ processGridletReturn(ev);
+ break;
+
+ // A gridlet has failed because a packet was dropped
+ case GridSimTags.FNB_GRIDLET_FAILED_BECAUSE_PACKET_DROPPED:
+ processGridletPacketDropping(ev);
+ break;
+
+ default:
+ System.out.println(super.get_name() +
+ ": Received an unknown event: " + ev.get_tag());
+ break;
+
+ } // switch (ev.get_tag())
+
+ ev = null;
+
+ }// while (Sim_system.running())
+
+ // remove I/O entities created during construction of this entity
+ super.terminateIOEntities();
+
+ // print the statistics regarding to this experiment
+ printStatistics();
+
+ }// body()
+
+
+ /**
+ * This functions process the fail of a gridlet. The failure has happened
+ * because a packet was dropped.
+ * @param ev an incoming event
+ */
+ private void processGridletPacketDropping(Sim_event ev)
+ {
+ FnbMessageDropGridlet msgDropGl = (FnbMessageDropGridlet) ev.get_data();
+ int glID = msgDropGl.getEntityID();
+ double clock = GridSim.clock();
+
+ if (droppedGridletsArray[glID] == false)
+ {
+ System.out.println("<<< " + super.get_name() +
+ ": Receiving GRIDLET_FAILED_BECAUSE_PACKET_DROPPED at time = " +
+ clock + ". Gridlet # " + glID);
+
+ // Commented. Write to a single file instead of a different one
+ //write(super.get_name() + ", " + glID + ", GRIDLET_DROPPED, " + clock + "\n",
+ // super.get_name() + "_DroppedGridlets.csv");
+
+ // find out the total execution time, from the submission time
+ gridletLatencyTime[glID] = GridSim.clock() - gridletSubmissionTime[glID];
+
+ // get the latest status of a gridlet
+ gridletStatus[glID] = "Dropped by router";
+
+ // set the status of this gridlet ID
+ droppedGridletsArray[glID] = true; // we have a dropped Gridlet
+ droppedGridletsCounter++; // increment the counter
+
+ // remove this gridlet from the submission list
+ // we don't re-send this gridlet
+ removeGridletFromGridletSubmittedList(glID);
+
+ // In this case, the user has finished his work, as all the gridlets
+ // are back or failed. So, finish the simulation.
+ if (receivedGridletCounter + droppedGridletsCounter == NUM_GRIDLETS)
+ {
+ super.finishSimulation();
+ //System.out.println("**** " + super.get_name() + ": FINISHED!!");
+ }
+
+ System.out.println("<<< " + super.get_name() +
+ ": Finished processing GRIDLET_FAILED_BECAUSE_PACKET_DROPPED\nfor Gridlet # " +
+ glID + ". Received: " + receivedGridletCounter +
+ ". Dropped: " + droppedGridletsCounter +
+ ". NUM_GRIDLETS: " + NUM_GRIDLETS);
+
+ } //if (droppedGridletsArray[glID] == false)
+
+ ev = null;
+ }
+
+
+ /**
+ * This function remove a gridlet from the submission list.
+ * @param glID the id of the gridlet to be removed
+ */
+ private void removeGridletFromGridletSubmittedList(int glID)
+ {
+ int i = 0;
+ while (i < GridletSubmittedList_.size())
+ {
+ GridletSubmission obj = (GridletSubmission) GridletSubmittedList_.get(i);
+ int id = obj.getGridletID();
+
+ // if found the maching Gridlet
+ if (glID == id)
+ {
+ GridletSubmittedList_.remove(i);
+ break;
+ }
+
+ i++;
+ }
+ }
+
+
+ /**
+ * This method submits all the gridlets that have not been submitted before
+ * @param ev an incoming event
+ */
+ private void processGridletSubmission(Sim_event ev)
+ {
+ int i = 0;
+ GridletSubmission gridletSub;
+ Gridlet gl;
+
+ while (i < GridletSubmittedList_.size())
+ {
+ gridletSub = (GridletSubmission) GridletSubmittedList_.get(i);
+
+ // Submit the gridlets have not been submitted before
+ if (gridletSub.getSubmitted() == false)
+ {
+ // we have to resubmit this gridlet
+ gl = gridletSub.getGridlet();
+
+ System.out.println(">>> " + super.get_name() +
+ ". Sending Gridlet #" + i + " to " +
+ GridSim.getEntityName(resID) + " at clock: " + GridSim.clock());
+
+ // set the submission time
+ gridletSubmissionTime[gl.getGridletID()] = GridSim.clock();
+ gridletStatus[gl.getGridletID()] = "Submitted";
+
+ // send the gridlet to a particular resource
+ super.gridletSubmit(gl, resID, 0, false, ToS_);
+
+ gridletSub.setSubmitted(true); // set this gridlet as submitted
+
+ // Write into a 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;
+
+ int glID;
+
+ if (obj instanceof Gridlet)
+ {
+ gl = (Gridlet) obj;
+
+ glID = gl.getGridletID();
+ System.out.println("<<< " + super.get_name() +
+ ": Receiving Gridlet #" + glID + " with status " +
+ gl.getGridletStatusString() + " at time = " + GridSim.clock() +
+ " from " + GridSim.getEntityName(gl.getResourceID()) );
+
+ // Write into a file
+ write(super.get_name(), "Receiving", glID,
+ GridSim.getEntityName(gl.getResourceID()),
+ gl.getGridletStatusString(), GridSim.clock());
+
+ receivedGridletCounter++;
+
+ // find out the total execution time, from the submission time
+ gridletLatencyTime[glID] = GridSim.clock() -
+ gridletSubmissionTime[glID];
+
+ // get the latest status of a gridlet
+ gridletStatus[glID] = gl.getGridletStatusString();
+
+ // remove the gridlet
+ removeGridletFromGridletSubmittedList(glID);
+ gl = null;
+
+ // We have received all the gridlets. So, finish the simulation.
+ if ((receivedGridletCounter == NUM_GRIDLETS) ||
+ (receivedGridletCounter + droppedGridletsCounter == NUM_GRIDLETS))
+ {
+ super.finishSimulation();
+ //System.out.println("**** " + super.get_name() + ": FINISHED!!");
+ }
+
+
+ System.out.println("<<< " + super.get_name() +
+ ": Finished processing the return of Gridlet # " +
+ glID + "\nReceived: " + receivedGridletCounter +
+ ". Dropped: " + droppedGridletsCounter +
+ ". NUM_GRIDLETS: " + NUM_GRIDLETS);
+
+
+ } // if (obj instanceof Gridlet)
+ }
+
+
+ private void printStatistics()
+ {
+ String name = super.get_name();
+ String filename = name + ".csv";
+ StringBuffer str = new StringBuffer(1000); // store 1000 chars
+
+ // print the heading name first
+ str.append("\n\ngridletID, status, time, latency time (time - submit time)\n");
+ for (int i = 0; i < gridletStatus.length; i++)
+ {
+ double time = gridletLatencyTime[i] + gridletSubmissionTime[i];
+ str.append(i); // gridlet ID
+ str.append(", ");
+ str.append(gridletStatus[i]);
+ str.append(", "); // gridlet status
+ str.append(time);
+ str.append(", ");
+ str.append(gridletLatencyTime[i]);
+ str.append("\n");
+ }
+
+ this.write(str.toString(), filename);
+ }
+
+
+ /**
+ * 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 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);
+ }
+ }
+
+
+ /**
+ * 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
+ */
+ private int findGridletInGridletSubmittedList(Gridlet gl)
+ {
+ Gridlet g = null;
+ GridletSubmission gst = null;
+ for (int i = 0; i< GridletSubmittedList_.size(); i++)
+ {
+ gst = (GridletSubmission)GridletSubmittedList_.get(i);
+ if ( gst.getGridletID() == gl.getGridletID() )
+ {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+
+ /**
+ * This method will show you how to create Gridlets
+ * @param numGridlet number of Gridlet to be created
+ */
+ private void createGridlet(int numGridlet)
+ {
+ 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 input and output file transfer
+ 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
+ */
+ private 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.csv", true);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while opening file " + user + "_Fin.csv");
+ }
+
+ try
+ {
+ fwriter.write(user + ", "+ glID + ", " +
+ resName + ", " + cost + ", "+ cpu + ", " + + 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
+ */
+ private void write(String user, String event, int glID, String resName,
+ String status, double clock)
+ {
+ FileWriter fwriter = null;
+ try
+ {
+ fwriter = new FileWriter(super.get_name() + ".csv", true);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while opening file " + super.get_name());
+ }
+
+ try
+ {
+ fwriter.write(user + ", " + event + ", " + glID + ", " +
+ resName + ", " + status + ", " + 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)
+ */
+ private void initializeResultsFile()
+ {
+ // Initialize the results file
+ FileWriter fwriter = null;
+ FileWriter fwriterFin = null;
+ FileWriter fwriterDropped = null;
+
+ try
+ {
+ // overwrite existing file
+ fwriter = new FileWriter(super.get_name() + ".csv");
+ //fwriterFin = new FileWriter(super.get_name() + "_Fin.csv");
+ //fwriterDropped = new FileWriter(super.get_name() + "_DroppedGridlets.csv");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println("Unwanted errors while opening file "
+ + super.get_name() + " or " + super.get_name() + "_Fin.csv");
+ }
+
+ try
+ {
+ fwriter.write("User Name, Event, GridletID, Resource, GridletStatus, Time\n");
+ //fwriterFin.write( "User, GridletID, Resource, Cost, CPU time, Latency\n");
+ //fwriterDropped.write( "User, GridletID, Status, Time\n");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println("Unwanted errors while writing on file "
+ + super.get_name() + " or " + super.get_name() + "_Fin.csv or "
+ + super.get_name() + "_DroppedGridlets.csv");
+ }
+
+ 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.csv or "
+ + super.get_name() + "_DroppedGridlets.csv");
+ }
+ }
+
+
+ /**
+ * 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 void write(String msg, String file)
+ {
+ 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);
+ }
+ }
+
+} // end class
+
Added: trunk/examples/Network/FiniteBuffer01/GridletSubmission.java
===================================================================
--- trunk/examples/Network/FiniteBuffer01/GridletSubmission.java (rev 0)
+++ trunk/examples/Network/FiniteBuffer01/GridletSubmission.java 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,80 @@
+/*
+ * 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
+ *
+ * Author: Agustin Caminero
+ * Organization: Universidad de Castilla La Mancha (UCLM), Spain.
+ * Copyright (c) 2008, The University of Melbourne, Australia and
+ * Universidad de Castilla La Mancha (UCLM), Spain
+ */
+
+
+import gridsim.Gridlet;
+
+
+/**
+ * This class implements the submission time of each gridlet.
+ * @author Agustin Caminero
+ */
+public class GridletSubmission
+{
+ private Gridlet gl;
+
+ // whether this gridlet has been already submitted or not
+ private boolean submitted;
+
+ /**
+ * A constructor
+ * @param gl a Gridlet object
+ * @param submitted whether this gridlet has been already submitted or not
+ */
+ public GridletSubmission(Gridlet gl, boolean submitted)
+ {
+ this.gl = gl;
+ this.submitted = submitted;
+ }
+
+ /**
+ * Gets a Gridlet object
+ */
+ public Gridlet getGridlet()
+ {
+ return gl;
+ }
+
+ /**
+ * Gets the gridlet ID
+ */
+ public int getGridletID()
+ {
+ return gl.getGridletID();
+ }
+
+ /**
+ * Finds whether this gridlet has been already submitted or not
+ */
+ public boolean getSubmitted()
+ {
+ return submitted;
+ }
+
+ /**
+ * Sets a Gridlet object
+ */
+ public void setGridlet(Gridlet g)
+ {
+ this.gl = g;
+ }
+
+ /**
+ * Sets the status of this Gridlet, whether it has been submitted or not
+ */
+ public void setSubmitted(boolean submitted)
+ {
+ this.submitted = submitted;
+ }
+
+} // end class
+
Added: trunk/examples/Network/FiniteBuffer01/README.txt
===================================================================
--- trunk/examples/Network/FiniteBuffer01/README.txt (rev 0)
+++ trunk/examples/Network/FiniteBuffer01/README.txt 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,81 @@
+/*
+ * Title: GridSim Toolkit
+ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation
+ * of Parallel and Distributed Systems such as Clusters and Grids
+ * An example of how to use the failure functionality.
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: Universidad de Castilla La Mancha (UCLM), Spain.
+ * Copyright (c) 2008, The University of Melbourne, Australia and
+ * Universidad de Castilla La Mancha (UCLM), Spain
+ */
+
+Welcome to the example of how to use the finite network buffers functionality
+To compile the example source code:
+ In Unix/Linux: javac -classpath $GRIDSIM/jars/gridsim.jar:. *.java
+ In Windows: javac -classpath %GRIDSIM%\jars\gridsim.jar;. *.java
+
+where $GRIDSIM or %GRIDSIM% is the location of the gridsimtoolkit package.
+
+
+To run the class file:
+In Unix/Linux:
+ java -classpath $GRIDSIM/jars/gridsim.jar:. mainExample sched stats
+
+In Windows:
+ java -classpath %GRIDSIM%\jars\gridsim.jar;. mainExample sched stats
+
+where sched = {red, ared, fifo}, and stats = {true, false}.
+* sched refers to one of the FNB schedulers.
+ By default, sched = fifo if no parameter is included in the program.
+
+* stats refers to recording network statistics.
+ stats = true means turn on the network statistics.
+ stats = false means turn off the network statistics.
+
+
+NOTE: This example uses probabilistic distributions and random variables.
+ Hence, when running this example many times, the values may be different.
+
+The example may take a long time, even if the statistics collection is off.
+To make the experiment shorter, decrease the number of users, the number
+of jobs per user, jobs IO files sizes, or increase baud rate of links,
+buffer sizes, thresholds of RED/ARED.
+This way, less packets will get dropped and experiments will take less time.
+
+
+When running the example file, it will produce the following files:
+
+ sim_trace -> created by the SimJava2 package (lower-level) to trace every
+ events (performed by SimJava and GridSim) during the simulation.
+ We don't need to worry about this file. Not to important for our
+ example.
+
+ sim_report -> created by the SimJava2 package (lower-level) of GridSim.
+ This is a simulation report that contains general information about
+ running this experiment. We don't need to worry about this file.
+ Not to important for our example.
+
+ User_0.csv, User_1.csv, ... -> contain statistics regarding to
+ gridlets submission, and the status of each gridlet at the end of simulation.
+
+Next, the below files are only created when the statistics collection is ON
+(i.e. stats = true). Keep in mind that experiments will take longer time
+if stats are ON.
+
+ Router0_to_Res_0_Buffers.csv, Router0_to_Res_1_Buffers.csv, ...
+ -> Contains statistics on the progress of buffers parameter
+ (avg. queue size, ...), in intervals.
+
+ Router0_to_Res_0_DroppedPkts.csv, Router0_to_Res_1_DroppedPkts.csv, ...
+ -> Contains stats on the amount of droppped pkts, in intervals.
+
+ Router0_to_Res_0_MaxBufferSize.csv, Router0_to_Res_1_MaxBufferSize.csv, ...
+ -> Contains stats on the maximum buffer size, in intervals
+
+NOTE:
+* When you run the program multiple times, the new statistics
+ will overwrite the existing csv files.
+
+* You can open these csv files on Excel or any text editors.
Added: trunk/examples/Network/FiniteBuffer01/mainExample.java
===================================================================
--- trunk/examples/Network/FiniteBuffer01/mainExample.java (rev 0)
+++ trunk/examples/Network/FiniteBuffer01/mainExample.java 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,455 @@
+/*
+ * 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
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: Universidad de Castilla La Mancha (UCLM), Spain.
+ * Copyright (c) 2008, The University of Melbourne, Australia and
+ * Universidad de Castilla La Mancha (UCLM), Spain
+ */
+
+
+import gridsim.net.fnb.*;
+import gridsim.*;
+import gridsim.net.*;
+import java.util.*;
+import gridsim.index.RegionalGIS;
+import java.io.BufferedReader;
+import java.io.FileReader;
+
+
+/**
+ * A main class that runs this example.
+ * @author Agustin Caminero and Anthony Sulistio
+ */
+public class mainExample
+{
+ /**
+ * Creates main() to run this example.
+ * Command-line argument:
+ * - args[0] = SCHED, for choosing different FNB schedulers.
+ * SCHED = {red, ared, fifo}. Default SCHED is fifo.
+ *
+ * - args[1] = STATS, for choosing whether to turn on the statistics
+ * on routers or not.
+ * STATS = {true, false}. Default STATS is false.
+ *
+ */
+ public static void main(String args[])
+ {
+ System.out.println("Starting finite buffers example ...");
+
+ try
+ {
+ /************
+ The network topology is as follows:
+
+ 1Gbps 1Gbps 1Gbps
+ Users --------- Router1 ----------- Router0 --------- Resource_0
+ |------------ RegionalGIS
+ 1Gbps
+ ************/
+
+ // scheduling algorithm for buffers:
+ // GridSimTags.FNB_RED, GridSimTags.FNB_ARED, or GridSimTags.FNB_FIFO;
+ int SCHED_ALG = GridSimTags.FNB_FIFO;
+ String NETWORK_FILE = "network_example.txt";
+
+ if (args.length >= 1)
+ {
+ if (args[0].compareToIgnoreCase("red") == 0)
+ {
+ SCHED_ALG = GridSimTags.FNB_RED;
+ System.out.println("Using a FNB_RED scheduling.");
+ }
+ else if (args[0].compareToIgnoreCase("ared") == 0)
+ {
+ SCHED_ALG = GridSimTags.FNB_ARED;
+ System.out.println("Using a FNB_ARED scheduling.");
+ }
+ }
+ else
+ {
+ System.out.println("Using a default FNB_FIFO scheduling.");
+ }
+
+ boolean STORE_STATS = false; // records stats in the router or not
+ if (args.length >= 2)
+ {
+ Boolean boolObj = new Boolean(args[1]);
+ STORE_STATS = boolObj.booleanValue();
+ }
+
+ int NUM_USERS = 2; // num of users
+ int NUM_GIS = 1; // num of GIS objects
+
+ int GB = 1000000000; // 1 GB in bits
+ double BW_RES = 1*GB; // baud rate for the link of Resource_0
+ double BW_USERS = 1*GB; // baud rate for the link of users
+ double BW_GIS = 1*GB; // baud rate for the link of RegionalGIS
+
+ int MAX_TH = 15; // max threshold for the RED algorithm
+ int MIN_TH = 5; // min threshold for the RED algorithm
+
+ // common parameters for all the FNB schedulers
+ double MAX_P = 0.02; // maximum value for the dropping probability
+ double QUEUE_WEIGHT = 0.0001; // the queue weight
+
+ // the bigger the buffer size, the lower num of packets being rejected
+ int MAX_BUF_SIZE = 30;
+
+ int TOTAL_GRIDLET = 5; // gridlets each user has
+ int GRIDLET_SIZE_BASE = 42000;
+ long GRIDLET_FILESIZE_BASE_IN = 150000;
+ long GRIDLET_FILESIZE_BASE_OUT = 150000;
+
+ int totalResource = 2; // total number of resources
+ int totalMachine = 1;
+ int totalPE = 4;
+ int rating; // rating (MIPS) of the PEs of the resources
+
+
+ //////////////////////////////////////////
+ // First step: Initialize the GridSim package. It should be called
+ // before creating any entities. We can't run this example without
+ // initializing GridSim first. We will get run-time exception
+ // error.
+
+ // a flag that denotes whether to trace GridSim events or not.
+ boolean trace_flag = false;
+ Calendar calendar = Calendar.getInstance();
+
+ // Initialize the GridSim package
+ GridSim.init(NUM_USERS, calendar, trace_flag);
+ GridSim.initNetworkType(GridSimTags.NET_BUFFER_PACKET_LEVEL);
+
+
+ //////////////////////////////////////////
+ // Second step: Builds the network topology among Routers.
+
+ double[] weights = {1, 2}; // for ToS
+
+ System.out.println("Reading network from " + NETWORK_FILE);
+ LinkedList routerList = FnbNetworkReader.createSCFQ(NETWORK_FILE,
+ weights, MAX_BUF_SIZE, SCHED_ALG, MIN_TH, MAX_TH,
+ MAX_P, QUEUE_WEIGHT, STORE_STATS);
+
+
+ //////////////////////////////////////////
+ // Third step: Creates one or more RegionalGIS entities,
+ // linked to a router of the topology
+
+ String ROUTER_RES = "Router0"; // router where resources will be conected
+ String ROUTER_USERS = "Router1"; // router where users will be conected
+ String ROUTER_GIS = "Router0"; // router where GIS will be connected
+
+ int gisIndex = 0; // a variable to select the primary GIS entity
+ RegionalGIS gis = null;
+
+ double baud_rate;
+ double propDelay = 10; // propagation delay in millisecond
+ int mtu = 1500; // max. transmission unit in byte
+
+ ArrayList gisList = new ArrayList(NUM_GIS); // list of GIS entities
+ ArrayList resList = new ArrayList(totalResource); // a list of resources
+
+ Router router = null;
+ int i = 0; // a temp variable for a loop
+
+ for (i = 0; i < NUM_GIS; i++)
+ {
+ String gisName = "RegGIS_" + i; // regional GIS name
+ baud_rate = BW_GIS;
+
+ // a network link attached to this regional GIS entity
+ Link link = new SimpleLink(gisName + "_link", baud_rate,
+ propDelay, mtu);
+
+ gis = new RegionalGIS(gisName, link);
+ gisList.add(gis); // store the regional GIS entity into an array
+
+ router = FnbNetworkReader.getRouter(ROUTER_GIS, routerList);
+
+ System.out.println("=== Created " + gisName
+ + " (id: " + gis.get_id()
+ + "), connected to " + router.get_name());
+
+ linkNetworkSCFQ(router, gis, weights, MAX_BUF_SIZE, SCHED_ALG,
+ MIN_TH, MAX_TH, MAX_P, QUEUE_WEIGHT, STORE_STATS);
+ System.out.println();
+ }
+
+
+ //////////////////////////////////////////
+ // Fourth step: Creates one or more GridResource entities,
+ // linked to a router of the topology
+ String sched_alg;
+ for (i = 0; i < totalResource; i++)
+ {
+ sched_alg = "SPACE";
+ baud_rate = BW_RES;
+ totalMachine = 10;
+ rating = 49000;
+
+ router = FnbNetworkReader.getRouter(ROUTER_RES, routerList);
+ GridResource res = createGridResource("Res_" + i, baud_rate,
+ propDelay, mtu, totalPE, totalMachine, rating, sched_alg);
+
+ gisIndex = 0; // CHANGE if we have more than 1 RegGIS
+ gis = (RegionalGIS) gisList.get(gisIndex);
+
+ // set the regional GIS entity
+ if (res.setRegionalGIS(gis) == false)
+ {
+ System.out.println("FAILURE when setting regional GIS for resource "
+ + res.get_name());
+ }
+
+ // add a resource into a list
+ resList.add(res);
+
+ System.out.println("=== Created " + GridSim.getEntityName(res.get_id())
+ + ": " + totalMachine + " machines, each with " + totalPE
+ + " PEs.\nConnected to " + router.get_name()
+ + ", and registered to " + gis.get_name());
+
+ // link a resource to this router object
+ linkNetworkSCFQ(router, res, weights, MAX_BUF_SIZE, SCHED_ALG,
+ MIN_TH, MAX_TH, MAX_P, QUEUE_WEIGHT, STORE_STATS);
+ System.out.println();
+ }
+
+
+ //////////////////////////////////////////
+ // Fifth step: Creates one or more user entities,
+ // linked to a router of the topology
+
+ // Each user will send to only one resource
+ int resID = -1; // resource ID
+
+ Random random = new Random(); // a random generator
+ for (i = 0; i < NUM_USERS; i++)
+ {
+ String name = "User_" + i;
+
+ // Connect each user with a router, following our topology.
+ router = FnbNetworkReader.getRouter(ROUTER_USERS, routerList);
+ baud_rate = BW_USERS;
+
+ // schedule the initial sending of gridlets. The sending will
+ // start in a ramdom time within 5 min (300 sec)
+ double init_time = 3000 * random.nextDouble();
+
+ // a network link attached to this entity
+ Link link = new SimpleLink(name+"_link", baud_rate, propDelay, mtu);
+
+ // randomly choose a resource from the list
+ int index = random.nextInt(resList.size());
+ resID = ((GridResource) resList.get(index)).get_id();
+
+ FnbUser user = new FnbUser(name, link, i, GRIDLET_SIZE_BASE,
+ GRIDLET_FILESIZE_BASE_IN, GRIDLET_FILESIZE_BASE_OUT,
+ init_time, resID);
+
+ user.setGridletNumber(TOTAL_GRIDLET); // total jobs for execution
+
+ // for each user, determines the Type of Service (ToS)
+ // for sending objects over the network. The greater ToS is,
+ // the more bandwidth allocation
+ int ToS = random.nextInt(weights.length);
+ user.setNetServiceLevel(ToS);
+
+ System.out.println("=== Created " + name
+ + " (id: " + user.get_id() + "), connected to "
+ + router.get_name() + ", with " + TOTAL_GRIDLET
+ + " gridlets.\nRegistered to " + gis.get_name()
+ + ". ToS: " + ToS + ". Init time: " + init_time);
+
+ linkNetworkSCFQ(router, user, weights, MAX_BUF_SIZE, SCHED_ALG,
+ MIN_TH, MAX_TH, MAX_P, QUEUE_WEIGHT, STORE_STATS);
+
+ gis = (RegionalGIS) gisList.get(gisIndex);
+ user.setRegionalGIS(gis); // set the regional GIS entities
+ System.out.println();
+
+ } // create users
+ System.out.println();
+
+ //////////////////////////////////////////
+ // Final step: Starts the simulation
+ GridSim.startGridSimulation();
+ System.out.println("\nFinish finite buffers example");
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.out.println("Unwanted errors happen");
+ }
+ }
+
+
+ /**
+ * Links a particular entity with a given Router, using SCFQ schedulers.
+ * Since we are using the SCFQ packet scheduler, we need to
+ * specify the weight for each Type of Service (ToS).
+ *
+ * @param router a Router object
+ * @param obj a GridSim entity to be attached to the Router
+ * @param weight a weight of ToS
+ * @param max_buf_size maximum buffer size
+ */
+ private static void linkNetworkSCFQ(Router router, GridSimCore obj,
+ double[] weight, int max_buf_size, int drop_alg, int min_th,
+ int max_th, double max_p, double queue_weight, boolean stats)
+ throws Exception
+ {
+ if (router == null)
+ {
+ System.out.println("Error - router is NULL !!");
+ return;
+ }
+
+ // get the baud rate of a link
+ double baud_rate = obj.getLink().getBaudRate();
+ PacketScheduler pktObj;
+
+ if (drop_alg == GridSimTags.FNB_ARED)
+ {
+ System.out.println("linkNetworkSCFQ(): creating ARED scheduler.");
+
+ // create the packet scheduler for this link
+ pktObj = new ARED(router.get_name() + "_to_" + obj.get_name(),
+ baud_rate, max_p, max_buf_size, queue_weight, stats);
+
+ ((ARED) pktObj).setWeights(weight);
+ }
+ else if (drop_alg == GridSimTags.FNB_RED)
+ {
+ System.out.println("linkNetworkSCFQ(): creating RED scheduler.");
+
+ // create the packet scheduler for this link
+ pktObj = new RED(router.get_name() + "_to_" + obj.get_name(),
+ baud_rate, max_buf_size, min_th, max_th,
+ max_p, queue_weight, stats);
+
+ ((RED) pktObj).setWeights(weight);
+ }
+ else // if (drop_alg == GridSimTags.FNB_FIFO)
+ {
+
+ System.out.println("linkNetworkSCFQ(): creating FIFO scheduler.");
+
+ // create the packet scheduler for this link
+ pktObj = new FIFO(router.get_name() + "_to_" + obj.get_name(),
+ baud_rate, max_buf_size, queue_weight, stats);
+
+ // This is also needed here, as SCFQ is the scheduler for this link
+ ((FIFO) pktObj).setWeights(weight);
+
+ }
+
+ // attach this GridSim entity to a Router
+ router.attachHost(obj, pktObj);
+ }
+
+
+ /**
+ * Creates one Grid resource. A Grid resource contains one or more
+ * Machines. Similarly, a Machine contains one or more PEs (Processing
+ * Elements or CPUs).
+ * <p>
+ * In this simple example, we are simulating one Grid resource with three
+ * Machines that contains one or more PEs.
+ * @param name a Grid Resource name
+ * @param baud_rate the bandwidth of this entity
+ * @param delay the propagation delay
+ * @param MTU Maximum Transmission Unit
+ * @param totalPE number of PE per machine
+ * @param totalMachine number of machines in this resources
+ * @param rating rating of mahcines in this resource
+ * @param sched_alg the scheduling algorithm of this resource
+ * @return a GridResource object
+ */
+ private static GridResource createGridResource(String name, double baud_rate,
+ double delay, int MTU, int totalPE, int totalMachine,
+ int rating, String sched_alg)
+ {
+ // 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();
+ for (int i = 0; i < totalMachine; i++)
+ {
+ // 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 peList = new PEList();
+
+ // 3. Create PEs and add these into an object of PEList.
+ for (int k = 0; k < totalPE; k++)
+ {
+ // need to store PE id and MIPS Rating
+ peList.add(new PE(k, rating));
+ }
+
+ // 4. Create one Machine with its id and list of PEs or CPUs
+ mList.add(new Machine(i, peList));
+ }
+
+ // 5. 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
+ int scheduling_alg = 0; // space_shared or time_shared
+
+ if (sched_alg.equals("SPACE"))
+ {
+ scheduling_alg = ResourceCharacteristics.SPACE_SHARED;
+ }
+ else if (sched_alg.equals("TIME"))
+ {
+ scheduling_alg = ResourceCharacteristics.TIME_SHARED;
+ }
+
+ ResourceCharacteristics resConfig = new ResourceCharacteristics(arch, os,
+ mList, scheduling_alg, time_zone, cost);
+
+
+ // 6. 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();
+ GridResource gridRes = null;
+ try
+ {
+ // creates a GridResource with a link
+ gridRes = new GridResource(name,
+ new SimpleLink(name + "_link", baud_rate, delay, MTU),
+ seed, resConfig, peakLoad, offPeakLoad, holidayLoad, Weekends, Holidays);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return gridRes;
+ }
+
+} // end class
+
Added: trunk/examples/Network/FiniteBuffer01/network_example.txt
===================================================================
--- trunk/examples/Network/FiniteBuffer01/network_example.txt (rev 0)
+++ trunk/examples/Network/FiniteBuffer01/network_example.txt 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,13 @@
+# total number of Routers
+2
+
+# specifies each router name and whether to log its activities or not
+# by default no logging is required
+Router0
+Router1
+
+# x1 x2 0.0 10 1200
+# specify the link between two Routers
+# The format is:
+# Router_name1 Router_name2 baud_rate(GB/s) prop_delay(ms) mtu(byte)
+Router0 Router1 0.001 10.0 1500
Added: trunk/examples/Network/Flow/Example01/FlowNetEx01.java
===================================================================
--- trunk/examples/Network/Flow/Example01/FlowNetEx01.java (rev 0)
+++ trunk/examples/Network/Flow/Example01/FlowNetEx01.java 2008-10-12 06:37:26 UTC (rev 255)
@@ -0,0 +1,117 @@
+/*
+ * Author: Anthony Sulistio
+ * Author: James Broberg (adapted from NetEx01)
+ * Date: March 2008
+ * Description: A simple program to demonstrate of how to use GridSim
+ * network extension package.
+ * This example shows how to create two GridSim entities and
+ * connect them via a link. NetUser entity sends messages to
+ * Test entity and Test entity sends back these messages.
+ */
+
+import gridsim.*;
+import gridsim.net.*;
+import gridsim.net.flow.*;
+
+import java.util.*;
+
+
+
+/**
+ * Test Driver class for this example
+ */
+public class FlowNetEx01
+{
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args)
+ {
+ System.out.println("Starting network example ...");
+
+ try
+ {
+
+ //////////////////////////////////////////
+ // First step: Initialize the GridSim package. It should be called
+ // before creating any entities. We can't run this example without
+ // initializing GridSim first. We will get run-time exception
+ // error.
+ int num_user = 4; // number of grid users
+ Calendar calendar = Calendar.getInstance();
+ boolean trace_flag = false; // mean trace GridSim events
+
+ // Initialize the GridSim package without any statistical
+ // functionalities. Hence, no GridSim_stat.txt file is created.
+ System.out.println("Initializing GridSim package");
+
+ // It is essential to set the network type before calling GridSim.init()
+ GridSim.initNetworkType(GridSimTags.NET_FLOW_LEVEL);
+ GridSim.init(num_user, calendar, trace_flag);
+
+ // In this example, the topology is:
+ // user(s) --10Mb/s-- r1 --1.5Mb/s-- r2 --10Mb/s-- GridResource(s)
+
+ // create the routers.
+ // If trace_flag is set to "true", then this experiment will create
+ // the following files (apart from sim_trace and sim_report):
+ // - router1_report.csv
+ // - router2_report.csv
+ Router r1 = new FlowRouter("router1", trace_flag); // router 1
+ Router r2 = new FlowRouter("router2", trace_flag); // router 2
+
+ String sender1 = "user1";
+ String receipient1 = "test1";
+ String sender2 = "user2";
+ String receipient2 = "test2";
+
+ // these entities are the senders
+ FlowNetUser user1 = new FlowNetUser(sender1, receipient2, 5.0);
+ FlowNetUser user2 = new FlowNetUser(sender2, receipient1, 20.0);
+
+ // these entities are the receipients
+ FlowTest test1 = new FlowTest(receipient1, sender2);
+ FlowTest test2 = new FlowTest(receipient2, sender1);
+
+ // The schedulers are redundent and will be stripped out soon
+ FIFOScheduler userSched1 = new FIFOScheduler("NetUserSched_0");
+ r1.attachHost(user1, userSched1);
+
+ FIFOScheduler userSched2 = new FIFOScheduler("NetUserSched_1");
+ r1.attachHost(user2, userSched2);
+
+ FIFOScheduler testSched1 = new FIFOScheduler("FlowTestSched_0");
+ r2.attachHost(test1, testSched1);
+
+ FIFOScheduler testSched2 = new FIFOScheduler("FlowTestSched_1");
+ r2.attachHost(test2, testSched2);
+
+ //////////////////////////////////////////
+ // Second step: Creates a physical link
+ double baud_rate = 1572864; // bits/sec (baud) [1.5Mb/s]
+ double propDelay = 300; // propagation delay in millisecond
+ int mtu = Integer.MAX_VALUE;; // max. transmission unit in byte
+
+ Link link = new FlowLink("r1_r2_link", baud_rate, propDelay, mtu);
+ FIFOScheduler r1Sched = new FIFOScheduler("r1_Sched");
+ FIFOScheduler r2Sched ...
[truncated message content] |