You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(24) |
Sep
(14) |
Oct
(13) |
Nov
(5) |
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(2) |
Feb
(53) |
Mar
(29) |
Apr
(5) |
May
(11) |
Jun
(3) |
Jul
(7) |
Aug
(48) |
Sep
(10) |
Oct
(8) |
Nov
(1) |
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(9) |
Jun
|
Jul
|
Aug
|
Sep
(5) |
Oct
(2) |
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <bro...@us...> - 2008-03-13 05:08:53
|
Revision: 153 http://gridsim.svn.sourceforge.net/gridsim/?rev=153&view=rev Author: brobergj Date: 2008-03-12 22:08:59 -0700 (Wed, 12 Mar 2008) Log Message: ----------- Minor updates Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt 2008-03-13 05:08:36 UTC (rev 152) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt 2008-03-13 05:08:59 UTC (rev 153) @@ -1,14 +1,14 @@ /** - * Author: James Broberg - * Date: February 2008 + * Author: James Broberg (adapted from NetEx01) + * Date: March 2008 */ Welcome to the Example of how to use GridSim flow network extension. To compile the example source code: - In Unix/Linux: javac -classpath $GRIDSIM/jars/gridsim.jar:. NetEx01.java - In Windows: javac -classpath %GRIDSIM%\jars\gridsim.jar;. NetEx01.java + In Unix/Linux: javac -classpath $GRIDSIM/jars/gridsim.jar:. FlowNetEx01.java + In Windows: javac -classpath %GRIDSIM%\jars\gridsim.jar;. FlowNetEx01.java where $GRIDSIM or %GRIDSIM% is the location of the gridsimtoolkit package. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-13 05:08:36
|
Revision: 152 http://gridsim.svn.sourceforge.net/gridsim/?rev=152&view=rev Author: brobergj Date: 2008-03-12 22:08:36 -0700 (Wed, 12 Mar 2008) Log Message: ----------- Minor updates Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java 2008-03-13 05:08:11 UTC (rev 151) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java 2008-03-13 05:08:36 UTC (rev 152) @@ -109,6 +109,14 @@ ev.get_data() + ", at time = " + GridSim.clock()); // No need for an ack, it is handled in FlowBuffer now on our behalf + // sends back an ack + IO_data data = new IO_data(ev.get_data(), packetSize, destID_); + write(name_ + ".body(): Sending back " + + ev.get_data() + ", at time = " + GridSim.clock() ); + + // sends through Output buffer of this entity + super.send(super.output, GridSimTags.SCHEDULE_NOW, + GridSimTags.FLOW_ACK, data); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-13 05:08:07
|
Revision: 151 http://gridsim.svn.sourceforge.net/gridsim/?rev=151&view=rev Author: brobergj Date: 2008-03-12 22:08:11 -0700 (Wed, 12 Mar 2008) Log Message: ----------- Minor updates Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java 2008-03-13 05:07:42 UTC (rev 150) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java 2008-03-13 05:08:11 UTC (rev 151) @@ -85,16 +85,20 @@ public void body() { int packetSize = 5242880; // packet size in bytes [5MB] - int size = 1; // number of packets sent + int size = 3; // number of packets sent int i = 0; // get the destination entity ID this.destID_ = GridSim.getEntityId(destName_); + + //super.sim_pause(this.wait_); + this.gridSimHold(this.wait_); + // sends messages over the other side of the link for (i = 0; i < size; i++) { - super.sim_pause(this.wait_); + String msg = "Message_" + i; IO_data data = new IO_data(msg, packetSize, destID_); System.out.println(name_ + ".body(): Sending " + msg + @@ -103,6 +107,10 @@ // sends through Output buffer of this entity super.send(super.output, GridSimTags.SCHEDULE_NOW, GridSimTags.FLOW_SUBMIT, data); + + //super.sim_pause(); + super.sim_pause(10.0); + //this.gridSimHold((Math.random()*10)+1.0); } @@ -113,18 +121,17 @@ { // waiting for incoming event in the Input buffer obj = super.receiveEventObject(); - if (obj instanceof IO_data) { - System.out.println(name_ + ".body(): Receives Ack for " + ((IO_data)obj).getData()); - } - } + System.out.println(name_ + ".body(): Receives Ack for " + obj); + } // Wait for other FlowNetUser instances to finish - //super.sim_pause(600); + this.gridSimHold(1000.0); super.send(destID_, GridSimTags.SCHEDULE_NOW, GridSimTags.END_OF_SIMULATION); + //////////////////////////////////////////////////////// // shut down I/O ports This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-13 05:07:38
|
Revision: 150 http://gridsim.svn.sourceforge.net/gridsim/?rev=150&view=rev Author: brobergj Date: 2008-03-12 22:07:42 -0700 (Wed, 12 Mar 2008) Log Message: ----------- Minor updates Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java 2008-03-12 06:53:08 UTC (rev 149) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java 2008-03-13 05:07:42 UTC (rev 150) @@ -38,15 +38,17 @@ // before creating any entities. We can't run this example without // initializing GridSim first. We will get run-time exception // error. - int num_user = 1; // number of grid users + 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); - GridSim.initNetworkType(GridSimTags.NET_FLOW_LEVEL); // In this example, the topology is: // user(s) --10Mb/s-- r1 --1.5Mb/s-- r2 --10Mb/s-- GridResource(s) @@ -65,8 +67,8 @@ String receipient2 = "test2"; // these entities are the senders - FlowNetUser user1 = new FlowNetUser(sender1, receipient2, 0.0); - FlowNetUser user2 = new FlowNetUser(sender2, receipient1, 10.0); + 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-12 06:53:06
|
Revision: 149 http://gridsim.svn.sourceforge.net/gridsim/?rev=149&view=rev Author: brobergj Date: 2008-03-11 23:53:08 -0700 (Tue, 11 Mar 2008) Log Message: ----------- Bug fixes Modified Paths: -------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java 2008-03-12 06:52:49 UTC (rev 148) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java 2008-03-12 06:53:08 UTC (rev 149) @@ -16,6 +16,7 @@ import eduni.simjava.*; import java.util.*; +import java.util.Random; /** @@ -45,6 +46,8 @@ private ArrayList list_; // list of resources + user entities private boolean hasStarted_; // a flag for background traffic has started private static final int BITS = 8; // 1 byte = 8 bits + + private Random rnd; /** @@ -74,6 +77,8 @@ list_ = null; random_ = null; hasStarted_ = false; + + rnd = new Random(); } /** @@ -244,7 +249,7 @@ int shutdownID = GridSim.getGridSimShutdownEntityId(); // start generating some junk packets or background traffic - startBackgroundTraffic(); + // startBackgroundTraffic(); // Process incoming events while ( Sim_system.running() ) @@ -510,10 +515,11 @@ // last packet contains the actual data FlowPacket np = null; - np = new FlowPacket(obj,pktID_,size,tag,super.get_id(), + np = new FlowPacket(obj,rnd.nextInt(10000000),size,tag,super.get_id(), destId, netServiceType, 1, 1); + - System.out.println("Sending flow packet to link at time = " + GridSim.clock() + " id is " + pktID_); + System.out.println("Sending flow packet to link at time = " + GridSim.clock() + " id is " + np.getID()); pktID_++; // increments packet ID enque(np, GridSimTags.SCHEDULE_NOW); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-12 06:52:45
|
Revision: 148 http://gridsim.svn.sourceforge.net/gridsim/?rev=148&view=rev Author: brobergj Date: 2008-03-11 23:52:49 -0700 (Tue, 11 Mar 2008) Log Message: ----------- Bug fixes Modified Paths: -------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java 2008-03-11 03:01:34 UTC (rev 147) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java 2008-03-12 06:52:49 UTC (rev 148) @@ -166,7 +166,7 @@ * @pre $none * @post $none */ - public synchronized void body() + public void body() { // Process events Object obj = null; @@ -186,32 +186,25 @@ } else if(ev.get_tag() == GridSimTags.FLOW_HOLD) { System.out.println(super.get_name() + ".body(): checkForecast() + at time = " + GridSim.clock()); checkForecast(ev); - break; // Update flow duration forecast } else if (ev.get_tag() == GridSimTags.FLOW_UPDATE) { System.out.println(super.get_name() + ".body(): updateForecast() + at time = " + GridSim.clock()); updateForecast(ev); - break; - //} else if (ev.get_tag() == GridSimTags.FLOW_ACK) { - // System.out.println(super.get_name() + ".body(): submitAckToLink() + at time = " + GridSim.clock()); - //submitAckToLink(ev); - // break; - } - // if this entity is not connected in a network topology - if (obj != null && obj instanceof IO_data) { + } else if (obj != null && obj instanceof IO_data) { System.out.println(super.get_name() + ".body(): getDataFromEvent() + at time = " + GridSim.clock()); getDataFromEvent(ev); - } - // if this entity belongs to a network topology - else if (obj != null && link_ != null) { + } else if (obj != null && link_ != null) { System.out.println(super.get_name() + ".body(): getDataFromLink() + at time = " + GridSim.clock()); getDataFromLink(ev); } ev = null; // reset to null for gc to collect } + + System.out.println(super.get_name() + ":%%%% Exiting body() at time " + + GridSim.clock() ); } /** @@ -221,7 +214,7 @@ * @pre ev != null * @post $none */ - private synchronized void checkForecast(Sim_event ev) { + private void checkForecast(Sim_event ev) { int pktID = (Integer) ev.get_data(); // ID of flow to be checked FlowPacket fp = null; // Reference to flow packet that needs forecast update FlowPacket fpAck = null; @@ -272,7 +265,7 @@ * @pre ev != null * @post $none */ - private synchronized void updateForecast(Sim_event ev) { + private void updateForecast(Sim_event ev) { int pktID = (Integer) ev.get_data(); // ID of flow to be updated FlowPacket fp = null; // Reference to flow packet that needs forecast update double duration = 0.0; // New forecast duration from current Gridsim.clock() @@ -310,8 +303,9 @@ + cancelledFlow); } - + System.out.println(super.get_name() + " setting updated forecast for packet #" + fp.getID()); super.sim_schedule(super.get_id(), duration, GridSimTags.FLOW_HOLD , new Integer(fp.getID())); + } } @@ -391,15 +385,6 @@ ev.get_tag(), io.getData() ); } - private synchronized void submitAckToLink(Sim_event ev) - { - - FlowPacket fp = (FlowPacket)ev.get_data(); - System.out.println("Sending flow packet ack to link at time = " + GridSim.clock() + " id is " - + ((FlowPacket) ev.get_data()).getID()); - super.sim_schedule(this.link_.get_id(), GridSimTags.SCHEDULE_NOW, GridSimTags.PKT_FORWARD, fp); - } - /** * Process incoming events from senders that are using the network * extension @@ -448,7 +433,8 @@ // if flow terminates at next entity, add to active flows // & hold for appropriate duration - if (pkt.getTag() == GridSimTags.FLOW_SUBMIT) { + if (pkt.getTag() == GridSimTags.FLOW_SUBMIT || pkt.getTag() == GridSimTags.GRIDLET_SUBMIT || + pkt.getTag() == GridSimTags.GRIDLET_SUBMIT_ACK || pkt.getTag() == GridSimTags.GRIDLET_RETURN) { np.setStartTime(GridSim.clock()); np.setUpdateTime(GridSim.clock()); duration = np.getSize()*SIZE / np.getBandwidth_(); @@ -457,15 +443,20 @@ System.out.println(super.get_name() + ".getDataFromLink() forecast flow end at " + (GridSim.clock() + duration)); - // if flow is just an ACK of a finished flow do not hold + // if flow is just an ACK of a finished flow do not hold, no action required } else if (pkt.getTag() == GridSimTags.FLOW_RETURN){ - duration = 0.0; + //duration = 0.0; + return; // send the data into entity input/output port - super.sim_schedule(inPort_, duration, tag, - io.getData() ); + // super.sim_schedule(inPort_, duration, tag, + // io.getData() ); } + + // send the data into entity input port + super.sim_schedule(inPort_, GridSimTags.SCHEDULE_NOW, tag, + io.getData() ); + - } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-11 03:01:28
|
Revision: 147 http://gridsim.svn.sourceforge.net/gridsim/?rev=147&view=rev Author: brobergj Date: 2008-03-10 20:01:34 -0700 (Mon, 10 Mar 2008) Log Message: ----------- Porting FlowBuffer back to separate FlowInput/FlowOutput Added Paths: ----------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java 2008-03-11 03:01:34 UTC (rev 147) @@ -0,0 +1,737 @@ +/* + * 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: Output.java,v 1.7 2005/09/02 04:12:04 anthony Exp $ + */ + +package gridsim.net.flow; + +import gridsim.*; +import gridsim.net.*; +import gridsim.util.*; + +import eduni.simjava.*; + +import java.util.*; + + +/** + * GridSim Output defines a port through which a simulation entity sends + * data to the simulated network. + * <p> + * It maintains an event queue to serialize + * the data-out-flow and delivers to the destination entity. + * It works along with Input entity to simulate network + * communication delay. Simultaneous outputs can be modeled by using multiple + * instances of this class + * + * @author Manzur Murshed and Rajkumar Buyya + * @since GridSim Toolkit 1.0 + * @invariant $none + */ +public class FlowOutput extends Sim_entity implements NetIO +{ + private Sim_port outPort_; // output port + private Link link_; // a link to this output entity + private double baudRate_; // baud rate of this entity + private final int SIZE = 8; // 1 byte in bits + private static int pktID_ = 0; // packet ID counter + private Vector packetList_; // store a list of packets + private Random random_; // selects to which junk packets go to + private TrafficGenerator gen_; // background traffic generator + private ArrayList list_; // list of resources + user entities + private boolean hasStarted_; // a flag for background traffic has started + private static final int BITS = 8; // 1 byte = 8 bits + + + /** + * Allocates a new Output object + * @param name the name of this object + * @param baudRate the communication speed + * @throws NullPointerException This happens when creating this entity + * before initializing GridSim package or this entity name + * is <tt>null</tt> or empty + * @pre name != null + * @pre baudRate >= 0.0 + * @post $none + */ + public FlowOutput(String name, double baudRate) throws NullPointerException + { + super(name); + this.baudRate_ = baudRate; + link_ = null; + packetList_ = null; + pktID_ = 0; + + outPort_ = new Sim_port("output_buffer"); + super.add_port(outPort_); + + // for sending background traffic + gen_ = null; + list_ = null; + random_ = null; + hasStarted_ = false; + } + + /** + * Sets the background traffic generator for this entity. + * <p> + * When simulation starts, this entity will automatically sends junk + * packets to resource entities. + * @param gen a background traffic generator + * @return <tt>true</tt> if successful, <tt>false</tt> otherwise + * @pre gen != null + * @post $none + */ + public boolean setBackgroundTraffic(TrafficGenerator gen) + { + if (gen == null) { + return false; + } + + gen_ = gen; + if (list_ == null) { + list_ = new ArrayList(); + } + + return true; + } + + /** + * Sets the background traffic generator for this entity. + * <p> + * When simulation starts, this entity will automatically sends junk + * packets to resource entities and other entities. <br> + * NOTE: Sending background traffic to itself is not supported. + * + * @param gen a background traffic generator + * @param userName a collection of user entity name (in String object). + * @return <tt>true</tt> if successful, <tt>false</tt> otherwise + * @pre gen != null + * @pre userName != null + * @post $none + */ + public boolean setBackgroundTraffic(TrafficGenerator gen, + Collection userName) + { + if (gen == null || userName == null) { + return false; + } + + boolean flag = true; + try + { + gen_ = gen; + if (list_ == null) { + list_ = new ArrayList(); + } + + // iterates through each list to check whether it is a valid + // entity name or not + Iterator it = userName.iterator(); + int id = -1; + while( it.hasNext() ) + { + String name = (String) it.next(); + + // check whether it is sending to itself + id = GridSim.getEntityId("Output_" + name); + if (id == super.get_id()) + { + System.out.println(super.get_name() + + ".setBackgroundTraffic(): Warning - can not send " + + "junk packets to itself."); + continue; + } + + // get the ID of other entity + id = GridSim.getEntityId(name); + if (id > 0) + { + Integer obj = new Integer(id); + list_.add(obj); + } + // ignore for invalid entity + else + { + System.out.println(super.get_name() + + ".setBackgroundTraffic(): Warning - invalid entity " + + "name for \"" + name + "\"."); + } + } + } + catch(Exception e) { + flag = false; + } + + return flag; + } + + /** + * Sets this entity's link. This should be used only if the network + * extensions are being used. + * + * @param link the link to which this Output entity should send data + * @pre link != null + * @post $none + */ + public void addLink(Link link) + { + this.link_ = link; + baudRate_ = link_.getBaudRate(); + packetList_ = new Vector(); + } + + /** + * Gets the baud rate + * @return the baud rate + * @deprecated As of GridSim 2.1, replaced by {@link #getBaudRate()} + * @pre $none + * @post $result >= 0.0 + */ + public double GetBaudRate() { + return this.getBaudRate(); + } + + /** + * Gets the baud rate + * @return the baud rate + * @pre $none + * @post $result >= 0.0 + */ + public double getBaudRate() { + return baudRate_; + } + + /** + * Gets the I/O real number based on a given value + * @param value the specified value + * @return real number + * @deprecated As of GridSim 2.1, replaced by {@link #realIO(double)} + * @pre $none + * @post $result >= 0.0 + */ + public double real_io(double value) { + return this.realIO(value); + } + + /** + * Gets the I/O real number based on a given value + * @param value the specified value + * @return real number + * @pre $none + * @post $result >= 0.0 + */ + public double realIO(double value) { + return GridSimRandom.realIO(value); + } + + /** + * A method that gets one process event at one time until the end + * of a simulation, then delivers an event to the entity (its parent) + * @pre $none + * @post $none + */ + public void body() + { + // find out ids for entities that are not part of simulation network + // topology, such as GIS, GridSimShutdown and GridStatistics + int gisID = GridSim.getGridInfoServiceEntityId(); + int statID = GridSim.getGridStatisticsEntityId(); + int shutdownID = GridSim.getGridSimShutdownEntityId(); + + // start generating some junk packets or background traffic + startBackgroundTraffic(); + + // Process incoming events + while ( Sim_system.running() ) + { + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) { + break; + } + + System.out.println(super.get_name() + ".body(): ev.get_tag() is " + ev.get_tag()); + System.out.println(super.get_name() + ".body(): ev.get_src() is " + ev.get_src()); + + // handle different types of incoming events + switch ( ev.get_tag() ) + { + case GridSimTags.SEND_PACKET: + sendPacket(); + break; + + // submit ping() request + case GridSimTags.INFOPKT_SUBMIT: + sendInfoPacket(ev); + break; + + // replying ping() request from another entity + case GridSimTags.INFOPKT_RETURN: + returnInfoPacket(ev); + break; + + // activate background traffic + case GridSimTags.JUNK_PKT: + generateBackgroundTraffic(); + break; + + // activate background traffic + case GridSimTags.FLOW_ACK: + System.out.println((FlowPacket) ev.get_data()); + enque((FlowPacket) ev.get_data(),GridSimTags.SCHEDULE_NOW); + break; + + default: + defaultSend(ev, gisID, statID, shutdownID); + break; + } + } + } + + /** + * Generates few junk packets at the given interval + * @pre $none + * @post $none + */ + private synchronized void generateBackgroundTraffic() + { + + // get the next inter-arrival time for these junk packets + long time = gen_.getNextPacketTime(); + + // get the sending pattern + int pattern = gen_.getPattern(); + + // for initial start-up, get the list of all resources first + if (hasStarted_ == false) + { + // get list of resource IDs from GIS + LinkedList resList = GridSim.getGridResourceList(); + + // if the list is empty then schedule the next time + if (resList == null && list_.size() == 0) + { + super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); + return; + } + + hasStarted_ = true; + list_.addAll(resList); // add resource IDs into the current list + + // sets the sending pattern + if (pattern == TrafficGenerator.SEND_ONE_ONLY && random_ == null) { + random_ = new Random(); + } + } + + // get the required info for generating this background traffic + long size = gen_.getNextPacketSize(); // packet size + long freq = gen_.getNextPacketFreq(); // packet freq + int type = gen_.getServiceType(); // packet type + int tag = GridSimTags.JUNK_PKT; // packet tag + + // we need to packetsize the data, all packets are sent with size MTU. + // only the last packet contains the data, the receiver should + // throw away all other packets + // int MTU = link_.getMTU(); + // int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); + + /********* // DEBUG info + System.out.println(); + System.out.println(super.get_name() + + ": START GENERATE BG traffic... at time "+ GridSim.clock()); + System.out.println(super.get_name() + + ": NEXT background traffic will start at " + time); + System.out.println(super.get_name() + + " num PACKETS = " + numPackets + ", freq = " + freq); + *********/ + + int i = 0; + int destId = -1; + + // send to one of the entity using uniform distribution + if (pattern == TrafficGenerator.SEND_ONE_ONLY) + { + int index = random_.nextInt( list_.size() ); + destId = ((Integer) list_.get(index)).intValue(); + + /********* // DEBUG info + System.out.println(super.get_name() + ": Destination id = " + + destId + " = " + GridSim.getEntityName(destId) ); + *********/ + + // create junk packets or empty NetPacket. + //for (i = 0; i < freq; i++) { + // convertIntoPacket(MTU, numPackets+1, tag, destId, type); + //} + + convertIntoPacket(size, 1, tag, destId, type); + + + } + // send to all resources + other entities + else if (pattern == TrafficGenerator.SEND_ALL) + { + // send to all resources and user entities + for (int k = 0; k < list_.size(); k++) + { + destId = ((Integer) list_.get(k)).intValue(); + + /********* // DEBUG info + System.out.println(super.get_name() + ": Destination id = " + + destId + " = " + GridSim.getEntityName(destId) ); + *********/ + + // create junk packets or empty NetPacket. + //for (i = 0; i < freq; i++) { + // convertIntoPacket(MTU, numPackets+1, tag, destId, type); + //} + convertIntoPacket(size, 1, tag, destId, type); + + } + } + + // sends the next junk packets + super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); + } + + /** + * Initial start for the background traffic + * @pre $none + * @post $none + */ + private synchronized void startBackgroundTraffic() + { + // if no background traffic generator, then skip the rest + if (gen_ == null) { + return; + } + + // get the next inter-arrival time + long time = gen_.getNextPacketTime(); + System.out.println(super.get_name() + + ": background traffic will start at time " + time); + + // starts background traffic if the inter-arrival time is valid + if (time == -1) { + return; + } + + super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); + } + + /** + * This method processes outgoing data without a network extension. + * @param ev a Sim_event object + * @param gisID the central/default GIS entity ID + * @param statID the GridStatistic entity ID + * @param shutdownID the GridSimShutdown entity ID + * @pre ev != null + * @post $none + */ + private synchronized void defaultSend(Sim_event ev, int gisID, int statID, + int shutdownID) + { + IO_data io = (IO_data) ev.get_data(); + int destId = io.getDestID(); + + /***** // DEBUG info*/ + System.out.println(super.get_name() + ".defaultSend(): Send to " + + GridSim.getEntityName(destId) + " tag = " + ev.get_tag() + " at time = " + GridSim.clock()); + /*****/ + + // if this entity uses a network extension + if (link_ != null && destId != gisID && destId != statID && + destId != shutdownID) + { + System.out.println(super.get_name() + ".defaultSend(): submitToLink() + at time = " + GridSim.clock()); + submitToLink(ev); + return; + } + + // Identify ID of an entity which acts as Input/Buffer + // entity of destination entity + int id = GridSim.getEntityId( "Input_" + + Sim_system.get_entity(destId).get_name() ); + + // Send first and then hold + super.sim_schedule(id, GridSimTags.SCHEDULE_NOW, ev.get_tag(), io); + + double receiverBaudRate = ( (FlowInput) + Sim_system.get_entity(id) ).getBaudRate(); + + // NOTE: io is in byte and baud rate is in bits. 1 byte = 8 bits + // So, convert io into bits + double minBaudRate = Math.min(baudRate_, receiverBaudRate); + double communicationDelay = GridSimRandom.realIO( + (io.getByteSize() * BITS) / minBaudRate); + + // NOTE: Below is a deprecated method for SimJava 2 + //super.sim_hold(communicationDelay); + super.sim_process(communicationDelay); + } + + /** + * This method takes data from an entity. If the size of the data is larger + * than the MTU of the link, then the packet is split into mutiple size + * units. After this it calls outEnque() to queue these packets into its + * buffer. + * + * @param ev A Sim_event data that contains all the data for this method + * to do its task. + * @pre ev != null + * @post $none + */ + private synchronized void submitToLink(Sim_event ev) + { + IO_data data = (IO_data) ev.get_data(); + Object obj = data.getData(); + long size = data.getByteSize(); + int tag = ev.get_tag(); + int destId = data.getDestID(); + int netServiceType = data.getNetServiceLevel(); + + // we need to packetsize the data, all packets are sent with size MTU. + // only the last packet contains the data, the receiver should + // throw away all other packets + //int MTU = link_.getMTU(); + //int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); + + // make dummy packets with null data + //System.out.println("Packetizing data, creating " + numPackets + " dummy packets at time = " + GridSim.clock()); + //convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); + + // last packet contains the actual data + FlowPacket np = null; + np = new FlowPacket(obj,pktID_,size,tag,super.get_id(), + destId, netServiceType, 1, 1); + + System.out.println("Sending flow packet to link at time = " + GridSim.clock() + " id is " + pktID_); + pktID_++; // increments packet ID + enque(np, GridSimTags.SCHEDULE_NOW); + } + + /** + * Creates many dummy or null packets + * @param size packet size (in bytes) + * @param numPackets total number of packets to be created + * @param tag packet tag + * @param destId destination ID for sending the packet + * @param netServiceType level type of service for the packet + * @pre $none + * @post $none + */ + private synchronized void convertIntoPacket(long size, int numPackets, + int tag, int destId, int netServiceType) { + FlowPacket np = null; + for (int i = 0; i < numPackets - 1; i++) + { + // change the tag name for dummy packets, apart from junk packets + if (tag != GridSimTags.JUNK_PKT) { + tag = GridSimTags.EMPTY_PKT; + } + + np = new FlowPacket(null, pktID_, size, tag, super.get_id(), destId, + netServiceType, i+1, numPackets); + + pktID_++; // increments packet ID + enque(np, GridSimTags.SCHEDULE_NOW); + } +} + + /** + * Sends an InfoPacket for ping request + * @param ev a Sim_Event object + * @pre ev != null + * @post $none + */ + private synchronized void sendInfoPacket(Sim_event ev) + { + IO_data data = (IO_data) ev.get_data(); + + // gets all the relevant info + long size = data.getByteSize(); + int destId = data.getDestID(); + int netServiceType = data.getNetServiceLevel(); + int tag = ev.get_tag(); + String name = GridSim.getEntityName( outPort_.get_dest() ); + + // we need to packetsize the data, all packets are sent with size MTU + // only the last packet contains the ping data, the receiver should + // throw away all other data + int MTU = link_.getMTU(); + int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); + + // break ping size into smaller pieces + // Also, make sure that it is not for pinging itself + if (size > MTU && outPort_.get_dest() != destId) + { + // make dummy packets with null data + convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); + } + + // get the remaining ping size + size = data.getByteSize() - MTU*(numPackets-1); + + // create the real InfoPacket + InfoPacket pkt = new InfoPacket(name,pktID_,size,outPort_.get_dest(), + destId,netServiceType); + + // set the required info + pkt.setLast( super.get_id() ); + pkt.addHop( outPort_.get_dest() ); + pkt.addEntryTime( GridSim.clock() ); + pkt.setOriginalPingSize( data.getByteSize() ); + + pktID_++; // increments packet ID + enque(pkt, GridSimTags.SCHEDULE_NOW); + } + + /** + * Sends back the ping() request to the next hop or destination + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + private void returnInfoPacket(Sim_event ev) + { + IO_data data = (IO_data) ev.get_data(); + + // use the original ping size rather than IO_data or InfoPacket size + // since the latter is restricted to MTU + InfoPacket pkt = (InfoPacket) data.getData(); + long size = pkt.getOriginalPingSize(); + + // get other relevant info + int tag = ev.get_tag(); + int destId = pkt.getSrcID(); + int netServiceType = data.getNetServiceLevel(); + + // we need to packetsize the data, all packets are sent with size MTU. + // only the last packet contains the data, the receiver should + // throw away all other packets + int MTU = link_.getMTU(); + int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); + + // make dummy packets with null data + convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); + + // set the original packet of last hop into this entity id + pkt.setLast( super.get_id() ); + enque(pkt, GridSimTags.SCHEDULE_NOW); + } + + /** + * Takes a packet, adds it into a buffer and schedules it to be sent out at + * an appropriate time. + * + * @param pkt The packet to be buffered + * @param delay The length of time this packet should be delayed (exclusive + * of the transmission time) + * @pre pkt != null + * @pre delay > 0 + * @post $none + */ + private synchronized void enque(Packet pkt, double delay) + { + + + packetList_.add(pkt); + if (packetList_.size() == 1) + { + System.out.println(super.get_name() + ".enque() Size is " + pkt.getSize() + " baud " + link_.getBaudRate()); + // Compute expected duration of flow using bottleneck baudRate + // double total = delay + (pkt.getSize()*SIZE / link_.getBaudRate()); + double total = 0.0; + + System.out.println(super.get_name() + ".enque() Time now " + GridSim.clock() + " delay is " + total); + super.sim_schedule(super.get_id(), total, GridSimTags.SEND_PACKET); + } + + } + + /** + * Removes a single packet from the buffer and sends it down the link. + * Then, schedules the next packet in the list. + * @pre $none + * @post $none + */ + private synchronized void sendPacket() + { + if (packetList_ == null || packetList_.isEmpty() == true) { + return; + } + + // submits the first packet in the list + Packet np = (Packet) packetList_.remove(0); + + boolean ping = false; // a flag to determine ping packet or not + int tag = -1; // event tag ID + int dest = -1; // destination ID + + // if a packet belongs to a ping packet + if (np instanceof InfoPacket) + { + ((InfoPacket)np).addExitTime( GridSim.clock() ); + ((InfoPacket)np).addBaudRate( link_.getBaudRate() ); + ping = true; + } + + // if an entity tries to send a packet to itself + if ( np.getDestID() == outPort_.get_dest() ) + { + System.out.println("Sending packet to self!"); + // then change the destination name and id + String destName = super.get_name(); + destName = destName.replaceFirst("Output", "Input"); + dest = Sim_system.get_entity_id(destName); + + // for a ping packet, change the tag + if (ping == true) + { + // don't forget to change the packet tag + tag = GridSimTags.INFOPKT_RETURN; + ((InfoPacket) np).setTag(tag); + } + else { + tag = np.getTag(); + } + } + else // if an entity tries to send to other entity + { + // change or keep the event tag + tag = GridSimTags.PKT_FORWARD; + if (np.getTag() == GridSimTags.JUNK_PKT) { + tag = GridSimTags.JUNK_PKT; + } + + // sends the packet into the link + dest = link_.get_id(); + } + + // send the packet + super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np); + + /***** // DEBUG info **/ + System.out.println(super.get_name() + " send to " + + GridSim.getEntityName(dest) + " tag = " + tag + " time " + GridSim.clock()); + /****/ + + // if the list is not empty, then schedule the next packet in the list + if (packetList_.isEmpty() != true) + { + //double delay = np.getSize() * SIZE / link_.getBaudRate(); + double delay = 0.0; + super.sim_schedule(super.get_id(), delay, GridSimTags.SEND_PACKET); + } + } + +} // end class + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-11 03:00:48
|
Revision: 146 http://gridsim.svn.sourceforge.net/gridsim/?rev=146&view=rev Author: brobergj Date: 2008-03-10 20:00:53 -0700 (Mon, 10 Mar 2008) Log Message: ----------- Porting FlowBuffer back to separate FlowInput/FlowOutput Added Paths: ----------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java (rev 0) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java 2008-03-11 03:00:53 UTC (rev 146) @@ -0,0 +1,493 @@ +/* + * 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: Input.java,v 1.7 2005/09/02 04:12:04 anthony Exp $ + */ + +package gridsim.net.flow; + +import gridsim.*; +import gridsim.net.*; +import gridsim.util.TrafficGenerator; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +import eduni.simjava.*; + +/** + * GridSim Input class defines a port through which a simulation entity + * receives data from the simulated network. + * <p> + * It maintains an event queue + * to serialize the data-in-flow and delivers to its parent entity. + * It accepts messages that comes from GridSim entities 'Output' entity + * and passes the same to the GridSim entity. + * It simulates Network communication delay depending on Baud rate + * and data length. Simultaneous inputs can be modeled using multiple + * instances of this class. + * + * @author Manzur Murshed and Rajkumar Buyya + * @since GridSim Toolkit 1.0 + * @invariant $none + */ +public class FlowInput extends Sim_entity implements NetIO +{ + private Sim_port inPort_; + private Link link_; + private double baudRate_; + private static final int BITS = 8; // 1 byte = 8 bits + private final int SIZE = 8; // 1 byte in bits + + + private HashMap<Integer, Packet> activeFlows_; // stores a list of active Flows + + + /** + * Allocates a new Input object + * @param name the name of this object + * @param baudRate the communication speed + * @throws NullPointerException This happens when creating this entity + * before initializing GridSim package or this entity name + * is <tt>null</tt> or empty + * @pre name != null + * @pre baudRate >= 0.0 + * @post $none + */ + public FlowInput(String name, double baudRate) throws NullPointerException + { + super(name); + this.baudRate_ = baudRate; + link_= null; + + inPort_ = new Sim_port("input_buffer"); + super.add_port(inPort_); + + activeFlows_ = null; + + } + + /** + * Sets the Input entities link. This should be used only if the network + * extensions are being used. + * @param link the link to which this Input entity should send data + * @pre link != null + * @post $none + */ + public void addLink(Link link) + { + this.link_ = link; + baudRate_ = link_.getBaudRate(); + activeFlows_ = new HashMap(); + + } + + /** + * Gets the baud rate + * @return the baud rate + * @deprecated As of GridSim 2.1, replaced by {@link #getBaudRate()} + * @pre $none + * @post $result >= 0.0 + */ + public double GetBaudRate() { + return this.getBaudRate(); + } + + /** + * Gets the baud rate + * @return the baud rate + * @pre $none + * @post $result >= 0.0 + */ + public double getBaudRate() { + return baudRate_; + } + + /** + * Gets the I/O real number based on a given value + * @param value the specified value + * @return real number + * @deprecated As of GridSim 2.1, replaced by {@link #realIO(double)} + * @pre value >= 0.0 + * @post $result >= 0.0 + */ + public double real_io(double value) { + return this.realIO(value); + } + + /** + * Gets the I/O real number based on a given value + * @param value the specified value + * @return real number + * @pre value >= 0.0 + * @post $result >= 0.0 + */ + public double realIO(double value) { + return GridSimRandom.realIO(value); + } + + /** + * This is an empty method and only applicable to + * {@link gridsim.net.Output} class. + * @param gen a background traffic generator + * @param userName a collection of user entity name (in String object). + * @return <tt>false</tt> since this method is not used by this class. + * @pre gen != null + * @pre userName != null + * @post $none + * @see gridsim.net.Output + */ + public boolean setBackgroundTraffic(TrafficGenerator gen, + Collection userName) + { + return false; + } + + /** + * This is an empty method and only applicable to + * {@link gridsim.net.Output} class. + * @param gen a background traffic generator + * @return <tt>false</tt> since this method is not used by this class. + * @pre gen != null + * @post $none + * @see gridsim.net.Output + */ + public boolean setBackgroundTraffic(TrafficGenerator gen) + { + return false; + } + + /** + * A method that gets one process event at one time until the end + * of a simulation, then delivers an event to the entity (its parent) + * @pre $none + * @post $none + */ + public synchronized void body() + { + // Process events + Object obj = null; + while ( Sim_system.running() ) + { + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue + obj = ev.get_data(); // get the incoming data + + System.out.println(super.get_name() + ".body(): ev.get_tag() is " + ev.get_tag()); + System.out.println(super.get_name() + ".body(): ev.get_src() is " + ev.get_src()); + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) { + break; + // Check if initial flow duration estimation was accurate + } else if(ev.get_tag() == GridSimTags.FLOW_HOLD) { + System.out.println(super.get_name() + ".body(): checkForecast() + at time = " + GridSim.clock()); + checkForecast(ev); + break; + // Update flow duration forecast + } else if (ev.get_tag() == GridSimTags.FLOW_UPDATE) { + System.out.println(super.get_name() + ".body(): updateForecast() + at time = " + GridSim.clock()); + updateForecast(ev); + break; + //} else if (ev.get_tag() == GridSimTags.FLOW_ACK) { + // System.out.println(super.get_name() + ".body(): submitAckToLink() + at time = " + GridSim.clock()); + //submitAckToLink(ev); + // break; + } + + // if this entity is not connected in a network topology + if (obj != null && obj instanceof IO_data) { + System.out.println(super.get_name() + ".body(): getDataFromEvent() + at time = " + GridSim.clock()); + getDataFromEvent(ev); + } + + // if this entity belongs to a network topology + else if (obj != null && link_ != null) { + System.out.println(super.get_name() + ".body(): getDataFromLink() + at time = " + GridSim.clock()); + getDataFromLink(ev); + } + + ev = null; // reset to null for gc to collect + } + } + + /** + * Check the forecast of a flow, and send data to output port if flow still exists + * + * @param ev the flow hold notification event + * @pre ev != null + * @post $none + */ + private synchronized void checkForecast(Sim_event ev) { + int pktID = (Integer) ev.get_data(); // ID of flow to be checked + FlowPacket fp = null; // Reference to flow packet that needs forecast update + FlowPacket fpAck = null; + + System.out.println(super.get_name() + ".checkForecast(): checking pkt id # " + pktID); + + // If flow hasn't already finished, send it to inPort + if ((fp = (FlowPacket) activeFlows_.get(pktID)) != null) { + Object data = fp.getData(); + IO_data io = new IO_data( data, fp.getSize(), + inPort_.get_src()); + super.sim_schedule(inPort_, GridSimTags.SCHEDULE_NOW, fp.getTag() , io.getData()); + activeFlows_.remove(pktID); + + // Send ack to source of flow + System.out.println(super.get_name() + ".checkForecast(): flow came from " + GridSim.getEntityName(fp.getSrcID()) + + " heading to " + GridSim.getEntityName(fp.getDestID())); + int oldDestID = fp.getDestID(); + int oldSrcID = fp.getSrcID(); + + IO_data ackData = new IO_data(fp.getData(), fp.getSize(), oldSrcID-2); + fpAck = new FlowPacket(ackData,fp.getID(),fp.getSize(),GridSimTags.FLOW_RETURN,oldDestID+2, + oldSrcID-2, fp.getNetServiceType(), 1, 1); + fpAck.setSize(fp.getSize()); + fpAck.setRemSize(0); + fpAck.setStartTime(fp.getStartTime()); + fpAck.setLatency(fp.getLatency()); + + System.out.println("Sending flow packet ack to link at time = " + GridSim.clock() + " id is " + + fpAck.getID()); + super.sim_schedule(GridSim.getEntityId("Output_" + GridSim.getEntityName(oldDestID)), + GridSimTags.SCHEDULE_NOW, GridSimTags.FLOW_ACK, fpAck); + + //super.sim_schedule(super.get_id(), GridSimTags.SCHEDULE_NOW, GridSimTags.FLOW_ACK, fpAck); + + } else { + System.out.println(super.get_name() + ".checkForecast(): pkt id # " + pktID + " already removed"); + + } + + } + + /** + * Update the forecast of a flow, delete the old forecast and schedule a new flow hold + * event in the future with the corrected forecast + * + * @param ev the flow update notification event + * @pre ev != null + * @post $none + */ + private synchronized void updateForecast(Sim_event ev) { + int pktID = (Integer) ev.get_data(); // ID of flow to be updated + FlowPacket fp = null; // Reference to flow packet that needs forecast update + double duration = 0.0; // New forecast duration from current Gridsim.clock() + long remSizeOld = 0; // Previous remaining size + double bandwidthOld = 0.0; // Previous bottleneck BW + int sourceID = ev.get_src(); // ID of source of notification (FlowLink) + int cancelledFlow = 0; // Count of canceled future events that match old forecast + + System.out.println(super.get_name() + ".updateForecast(): updating pkt id # " + pktID); + + // If flow hasn't already finished and been cleared... + if ((fp = (FlowPacket) activeFlows_.get(pktID)) != null) { + remSizeOld = fp.getRemSize(); + bandwidthOld = fp.getBandwidth_(); + System.out.println(super.get_name() + "updateForecast(): rem size is " + remSizeOld + "BW old is " + bandwidthOld); + Iterator it = (fp.getLinks_()).iterator(); + + while (it.hasNext()) { + FlowLink fl = (FlowLink) it.next(); + if (fl.get_id() == sourceID) { + fp.setBandwidth_(fl.getBaudRate()); + fp.setBottleneckID(sourceID); + } + } + + fp.setRemSize((long)(remSizeOld*BITS - (GridSim.clock()-fp.getUpdateTime())*bandwidthOld)); + duration = fp.getRemSize()/fp.getBandwidth_(); + System.out.println(super.get_name() + " new remaining duration add " + duration); + + FilterFlow filter = new FilterFlow(fp.getID(), GridSimTags.FLOW_HOLD); + cancelledFlow = this.sim_cancel(filter, null); + + if (cancelledFlow != 0) { + System.out.println(super.get_name() + ".updateForecast(): old forecast cancelled #matches " + + cancelledFlow); + } + + + super.sim_schedule(super.get_id(), duration, GridSimTags.FLOW_HOLD , new Integer(fp.getID())); + } + } + + /** + * Process incoming event for data without using the network extension + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + private void getDataFromEvent(Sim_event ev) + { + IO_data io = (IO_data) ev.get_data(); + + // if the sender is not part of the overall network topology + // whereas this entity is, then need to return back the data, + // since it is not compatible. + if (link_ != null) + { + // outName = "Output_xxx", where xxx = sender entity name + String outName = GridSim.getEntityName( ev.get_src() ); + + // NOTE: this is a HACK job. "Output_" has 7 chars. So, + // the idea is to get only the entity name by removing + // "Output_" word in the outName string. + String name = outName.substring(7); + + // if the sender is not system GIS then ignore the message + if (GridSim.getEntityId(name) != GridSim.getGridInfoServiceEntityId()) + { + // sends back the data to "Input_xxx", where + // xxx = sender entity name. If not sent, then the sender + // will wait forever to receive this data. As a result, + // the whole simulation program will be hanged or does not + // terminate successfully. + int id = GridSim.getEntityId("Input_" + name); + super.sim_schedule(id, 0.0, ev.get_tag(), io); + + // print an error message + System.out.println(super.get_name() + ".body(): Error - " + + "incompatible message protocol."); + System.out.println(" Sender: " + name + " is not part " + + "of this entity's network topology."); + System.out.println(" Hence, sending back the received data."); + System.out.println(); + return; + } + } + + // NOTE: need to have a try-catch statement. This is because, + // if the above if statement holds, then Input_receiver will send + // back to Input_sender without going through Output_receiver entity. + // Hence, a try-catch is needed to prevent exception of wrong casting. + try + { + // Simulate Transmission Time after Receiving + // Hold first then dispatch + double senderBaudRate = ( (FlowOutput) + Sim_system.get_entity(ev.get_src()) ).getBaudRate(); + + // NOTE: io is in byte and baud rate is in bits. 1 byte = 8 bits + // So, convert io into bits + double minBaudRate = Math.min(baudRate_, senderBaudRate); + double communicationDelay = GridSimRandom.realIO( + (io.getByteSize() * BITS) / minBaudRate); + + // NOTE: Below is a deprecated method for SimJava 2 + //super.sim_hold(communicationDelay); + super.sim_process(communicationDelay); // receiving time + } + catch (Exception e) { + // .... empty + } + + // Deliver Event to the entity (its parent) to which + // it is acting as buffer + super.sim_schedule( inPort_, GridSimTags.SCHEDULE_NOW, + ev.get_tag(), io.getData() ); + } + + private synchronized void submitAckToLink(Sim_event ev) + { + + FlowPacket fp = (FlowPacket)ev.get_data(); + System.out.println("Sending flow packet ack to link at time = " + GridSim.clock() + " id is " + + ((FlowPacket) ev.get_data()).getID()); + super.sim_schedule(this.link_.get_id(), GridSimTags.SCHEDULE_NOW, GridSimTags.PKT_FORWARD, fp); + } + + /** + * Process incoming events from senders that are using the network + * extension + * @param ev a Sim_event object + * @pre ev != null + * @post $none + */ + private void getDataFromLink(Sim_event ev) + { + Object obj = ev.get_data(); + double duration = 0.0; + + if (obj instanceof Packet) + { + // decrypt the packet into original format + Packet pkt = (Packet) ev.get_data(); + + if (pkt instanceof InfoPacket) + { + processPingRequest( (InfoPacket) pkt); + return; + } + + if (pkt instanceof FlowPacket) + { + FlowPacket np = (FlowPacket) pkt; + int tag = np.getTag(); + System.out.println("Packet id is " + np.getID()); + + // ignore incoming junk packets + if (tag == GridSimTags.JUNK_PKT) { + return; + } + + // ignore incoming null dummy packets + if (tag == GridSimTags.EMPTY_PKT && np.getData() == null) { + return; + } + + // convert the packets into IO_data + Object data = np.getData(); + IO_data io = new IO_data( data, np.getSize(), + inPort_.get_src()); + System.out.println(super.get_name() + ".getDataFromLink() Time now " + GridSim.clock() + + " bottleneck is " + np.getBandwidth_() + " sum lat is " + np.getLatency() ); + + // if flow terminates at next entity, add to active flows + // & hold for appropriate duration + if (pkt.getTag() == GridSimTags.FLOW_SUBMIT) { + np.setStartTime(GridSim.clock()); + np.setUpdateTime(GridSim.clock()); + duration = np.getSize()*SIZE / np.getBandwidth_(); + activeFlows_.put(pkt.getID(), pkt); + super.sim_schedule(super.get_id(), duration, GridSimTags.FLOW_HOLD, new Integer(pkt.getID())); + System.out.println(super.get_name() + ".getDataFromLink() forecast flow end at " + (GridSim.clock() + + duration)); + + // if flow is just an ACK of a finished flow do not hold + } else if (pkt.getTag() == GridSimTags.FLOW_RETURN){ + duration = 0.0; + // send the data into entity input/output port + super.sim_schedule(inPort_, duration, tag, + io.getData() ); + } + + + } + } + } + + /** + * Processes a ping request + * @param pkt a packet for pinging + * @pre pkt != null + * @post $none + */ + private void processPingRequest(InfoPacket pkt) + { + // add more information to ping() packet + pkt.addHop( inPort_.get_dest() ); + pkt.addEntryTime( GridSim.clock() ); + + IO_data io = new IO_data( pkt, pkt.getSize(), inPort_.get_dest() ); + + // send this ping() packet to the entity + super.sim_schedule(inPort_, GridSimTags.SCHEDULE_NOW, + pkt.getTag(), io.getData()); + } + +} // end class + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-11 02:39:50
|
Revision: 145 http://gridsim.svn.sourceforge.net/gridsim/?rev=145&view=rev Author: brobergj Date: 2008-03-10 19:39:51 -0700 (Mon, 10 Mar 2008) Log Message: ----------- +Porting FlowBuffer back to separate FlowInput/FlowOutput Removed Paths: ------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java Deleted: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java 2008-03-11 02:39:17 UTC (rev 144) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowInput.java 2008-03-11 02:39:51 UTC (rev 145) @@ -1,296 +0,0 @@ -/* - * 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: James Broberg - * Organization: The University of Melbourne, Australia - * Created on: - */ - -package gridsim.net.flow; - -import gridsim.*; -import gridsim.net.*; -import eduni.simjava.*; -import gridsim.util.TrafficGenerator; -import java.util.Collection; - -/** - * GridSim Input class defines a port through which a simulation entity - * receives data from the simulated network. - * <p> - * It maintains an event queue - * to serialize the data-in-flow and delivers to its parent entity. - * It accepts messages that comes from GridSim entities 'Output' entity - * and passes the same to the GridSim entity. - * It simulates Network communication delay depending on Baud rate - * and data length. Simultaneous inputs can be modeled using multiple - * instances of this class. - * - * @author James Broberg - * @since GridSim Toolkit 4.0 - * @invariant $none - */ -public class FlowInput extends Sim_entity implements NetIO -{ - private Sim_port inPort_; - private Link link_; - private double baudRate_; - private static final int BITS = 8; // 1 byte = 8 bits - - /** - * Allocates a new Input object - * @param name the name of this object - * @param baudRate the communication speed - * @throws NullPointerException This happens when creating this entity - * before initializing GridSim package or this entity name - * is <tt>null</tt> or empty - * @pre name != null - * @pre baudRate >= 0.0 - * @post $none - */ - public FlowInput(String name, double baudRate) throws NullPointerException - { - super(name); - this.baudRate_ = baudRate; - link_= null; - - inPort_ = new Sim_port("input_buffer"); - super.add_port(inPort_); - } - - /** - * Sets the Input entities link. This should be used only if the network - * extensions are being used. - * @param link the link to which this Input entity should send data - * @pre link != null - * @post $none - */ - public void addLink(Link link) { - this.link_ = link; - } - - /** - * Gets the baud rate - * @return the baud rate - * @pre $none - * @post $result >= 0.0 - */ - public double getBaudRate() { - return baudRate_; - } - - /** - * This is an empty method and only applicable to - * {@link gridsim.net.Output} class. - * @param gen a background traffic generator - * @param userName a collection of user entity name (in String object). - * @return <tt>false</tt> since this method is not used by this class. - * @pre gen != null - * @pre userName != null - * @post $none - * @see gridsim.net.Output - */ - public boolean setBackgroundTraffic(TrafficGenerator gen, - Collection userName) - { - return false; - } - - /** - * This is an empty method and only applicable to - * {@link gridsim.net.Output} class. - * @param gen a background traffic generator - * @return <tt>false</tt> since this method is not used by this class. - * @pre gen != null - * @post $none - * @see gridsim.net.Output - */ - public boolean setBackgroundTraffic(TrafficGenerator gen) - { - return false; - } - - /** - * A method that gets one process event at one time until the end - * of a simulation, then delivers an event to the entity (its parent) - * @pre $none - * @post $none - */ - public void body() - { - // Process events - Object obj = null; - while ( Sim_system.running() ) - { - Sim_event ev = new Sim_event(); - super.sim_get_next(ev); // get the next event in the queue - obj = ev.get_data(); // get the incoming data - - // if the simulation finishes then exit the loop - if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) { - break; - } - - // if this entity is not connected in a network topology - if (obj != null && obj instanceof IO_data) { - getDataFromEvent(ev); - } - - // if this entity belongs to a network topology - else if (obj != null && link_ != null) { - getDataFromLink(ev); - } - - ev = null; // reset to null for gc to collect - } - } - - /** - * Process incoming event for data without using the network extension - * @param ev a Sim_event object - * @pre ev != null - * @post $none - */ - private void getDataFromEvent(Sim_event ev) - { - IO_data io = (IO_data) ev.get_data(); - - // if the sender is not part of the overall network topology - // whereas this entity is, then need to return back the data, - // since it is not compatible. - if (link_ != null) - { - // outName = "Output_xxx", where xxx = sender entity name - String outName = GridSim.getEntityName( ev.get_src() ); - - // NOTE: this is a HACK job. "Output_" has 7 chars. So, - // the idea is to get only the entity name by removing - // "Output_" word in the outName string. - String name = outName.substring(7); - - // if the sender is not system GIS then ignore the message - if (GridSim.getEntityId(name) != GridSim.getGridInfoServiceEntityId()) - { - // sends back the data to "Input_xxx", where - // xxx = sender entity name. If not sent, then the sender - // will wait forever to receive this data. As a result, - // the whole simulation program will be hanged or does not - // terminate successfully. - int id = GridSim.getEntityId("Input_" + name); - super.sim_schedule(id, 0.0, ev.get_tag(), io); - - // print an error message - System.out.println(super.get_name() + ".body(): Error - " + - "incompatible message protocol."); - System.out.println(" Sender: " + name + " is not part " + - "of this entity's network topology."); - System.out.println(" Hence, sending back the received data."); - System.out.println(); - return; - } - } - - // NOTE: need to have a try-catch statement. This is because, - // if the above if statement holds, then Input_receiver will send - // back to Input_sender without going through Output_receiver entity. - // Hence, a try-catch is needed to prevent exception of wrong casting. - try - { - // Simulate Transmission Time after Receiving - // Hold first then dispatch - double senderBaudRate = ( (Output) - Sim_system.get_entity(ev.get_src()) ).getBaudRate(); - - // NOTE: io is in byte and baud rate is in bits. 1 byte = 8 bits - // So, convert io into bits - double minBaudRate = Math.min(baudRate_, senderBaudRate); - double communicationDelay = GridSimRandom.realIO( - (io.getByteSize() * BITS) / minBaudRate); - - // NOTE: Below is a deprecated method for SimJava 2 - //super.sim_hold(communicationDelay); - super.sim_process(communicationDelay); // receiving time - } - catch (Exception e) { - // .... empty - } - - // Deliver Event to the entity (its parent) to which - // it is acting as buffer - super.sim_schedule( inPort_, GridSimTags.SCHEDULE_NOW, - ev.get_tag(), io.getData() ); - } - - /** - * Process incoming events from senders that are using the network - * extension - * @param ev a Sim_event object - * @pre ev != null - * @post $none - */ - private void getDataFromLink(Sim_event ev) - { - Object obj = ev.get_data(); - if (obj instanceof Packet) - { - // decrypt the packet into original format - Packet pkt = (Packet) ev.get_data(); - - if (pkt instanceof InfoPacket) - { - processPingRequest( (InfoPacket) pkt); - return; - } - - // all except last packet in a data session are null packets - if (pkt instanceof NetPacket) - { - NetPacket np = (NetPacket) pkt; - int tag = np.getTag(); - - // ignore incoming junk packets - if (tag == GridSimTags.JUNK_PKT) { - return; - } - - // ignore incoming null dummy packets - if (tag == GridSimTags.EMPTY_PKT && np.getData() == null) { - return; - } - - // convert the packets into IO_data - Object data = np.getData(); - IO_data io = new IO_data( data, np.getSize(), - inPort_.get_dest() ); - - // send the data into entity input port - super.sim_schedule(inPort_, GridSimTags.SCHEDULE_NOW, tag, - io.getData() ); - } - } - } - - /** - * Processes a ping request - * @param pkt a packet for pinging - * @pre pkt != null - * @post $none - */ - private void processPingRequest(InfoPacket pkt) - { - // add more information to ping() packet - pkt.addHop( inPort_.get_dest() ); - pkt.addEntryTime( GridSim.clock() ); - - IO_data io = new IO_data( pkt, pkt.getSize(), inPort_.get_dest() ); - - // send this ping() packet to the entity - super.sim_schedule(inPort_, GridSimTags.SCHEDULE_NOW, - pkt.getTag(), io.getData()); - } - -} // end class - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-03-11 02:39:13
|
Revision: 144 http://gridsim.svn.sourceforge.net/gridsim/?rev=144&view=rev Author: brobergj Date: 2008-03-10 19:39:17 -0700 (Mon, 10 Mar 2008) Log Message: ----------- +Porting FlowBuffer back to separate FlowInput/FlowOutput Removed Paths: ------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java Deleted: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java 2008-03-10 00:10:00 UTC (rev 143) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowOutput.java 2008-03-11 02:39:17 UTC (rev 144) @@ -1,675 +0,0 @@ -/* - * 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: James Broberg - * Organization: The University of Melbourne, Australia - * Created on: - */ - -package gridsim.net.flow; - -import gridsim.*; -import gridsim.net.*; -import gridsim.util.*; - -import eduni.simjava.*; -import java.util.*; - - -/** - * GridSim Output defines a port through which a simulation entity sends - * data to the simulated network. - * <p> - * It maintains an event queue to serialize - * the data-out-flow and delivers to the destination entity. - * It works along with Input entity to simulate network - * communication delay. Simultaneous outputs can be modeled by using multiple - * instances of this class - * - * @author James Broberg - * @since GridSim Toolkit 4.1 - * @invariant $none - */ -public class FlowOutput extends Sim_entity implements NetIO -{ - private Sim_port outPort_; // output port - private Link link_; // a link to this output entity - private double baudRate_; // baud rate of this entity - private final int SIZE = 8; // 1 byte in bits - private int pktID_; // packet ID counter - private Vector packetList_; // store a list of packets - private Random random_; // selects to which junk packets go to - private TrafficGenerator gen_; // background traffic generator - private ArrayList list_; // list of resources + user entities - private boolean hasStarted_; // a flag for background traffic has started - private static final int BITS = 8; // 1 byte = 8 bits - - - /** - * Allocates a new Output object - * @param name the name of this object - * @param baudRate the communication speed - * @throws NullPointerException This happens when creating this entity - * before initializing GridSim package or this entity name - * is <tt>null</tt> or empty - * @pre name != null - * @pre baudRate >= 0.0 - * @post $none - */ - public FlowOutput(String name, double baudRate) throws NullPointerException - { - super(name); - this.baudRate_ = baudRate; - link_ = null; - packetList_ = null; - pktID_ = 0; - - outPort_ = new Sim_port("output_buffer"); - super.add_port(outPort_); - - // for sending background traffic - gen_ = null; - list_ = null; - random_ = null; - hasStarted_ = false; - } - - /** - * Sets the background traffic generator for this entity. - * <p> - * When simulation starts, this entity will automatically sends junk - * packets to resource entities. - * @param gen a background traffic generator - * @return <tt>true</tt> if successful, <tt>false</tt> otherwise - * @pre gen != null - * @post $none - */ - public boolean setBackgroundTraffic(TrafficGenerator gen) - { - if (gen == null) { - return false; - } - - gen_ = gen; - if (list_ == null) { - list_ = new ArrayList(); - } - - return true; - } - - /** - * Sets the background traffic generator for this entity. - * <p> - * When simulation starts, this entity will automatically sends junk - * packets to resource entities and other entities. <br> - * NOTE: Sending background traffic to itself is not supported. - * - * @param gen a background traffic generator - * @param userName a collection of user entity name (in String object). - * @return <tt>true</tt> if successful, <tt>false</tt> otherwise - * @pre gen != null - * @pre userName != null - * @post $none - */ - public boolean setBackgroundTraffic(TrafficGenerator gen, - Collection userName) - { - if (gen == null || userName == null) { - return false; - } - - boolean flag = true; - try - { - gen_ = gen; - if (list_ == null) { - list_ = new ArrayList(); - } - - // iterates through each list to check whether it is a valid - // entity name or not - Iterator it = userName.iterator(); - int id = -1; - while( it.hasNext() ) - { - String name = (String) it.next(); - - // check whether it is sending to itself - id = GridSim.getEntityId("Output_" + name); - if (id == super.get_id()) - { - System.out.println(super.get_name() + - ".setBackgroundTraffic(): Warning - can not send " + - "junk packets to itself."); - continue; - } - - // get the ID of other entity - id = GridSim.getEntityId(name); - if (id > 0) - { - Integer obj = new Integer(id); - list_.add(obj); - } - // ignore for invalid entity - else - { - System.out.println(super.get_name() + - ".setBackgroundTraffic(): Warning - invalid entity " + - "name for \"" + name + "\"."); - } - } - } - catch(Exception e) { - flag = false; - } - - return flag; - } - - /** - * Sets this entity's link. This should be used only if the network - * extensions are being used. - * - * @param link the link to which this Output entity should send data - * @pre link != null - * @post $none - */ - public void addLink(Link link) - { - this.link_ = link; - packetList_ = new Vector(); - } - - /** - * Gets the baud rate - * @return the baud rate - * @pre $none - * @post $result >= 0.0 - */ - public double getBaudRate() { - return baudRate_; - } - - /** - * A method that gets one process event at one time until the end - * of a simulation, then delivers an event to the entity (its parent) - * @pre $none - * @post $none - */ - public void body() - { - // find out ids for entities that are not part of simulation network - // topology, such as GIS, GridSimShutdown and GridStatistics - int gisID = GridSim.getGridInfoServiceEntityId(); - int statID = GridSim.getGridStatisticsEntityId(); - int shutdownID = GridSim.getGridSimShutdownEntityId(); - - // start generating some junk packets or background traffic - startBackgroundTraffic(); - - // Process incoming events - while ( Sim_system.running() ) - { - Sim_event ev = new Sim_event(); - super.sim_get_next(ev); // get the next event in the queue - - // if the simulation finishes then exit the loop - if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) { - break; - } - - // handle different types of incoming events - switch ( ev.get_tag() ) - { - case GridSimTags.SEND_PACKET: - sendPacket(); - break; - - // submit ping() request - case GridSimTags.INFOPKT_SUBMIT: - sendInfoPacket(ev); - break; - - // replying ping() request from another entity - case GridSimTags.INFOPKT_RETURN: - returnInfoPacket(ev); - break; - - // activate background traffic - case GridSimTags.JUNK_PKT: - generateBackgroundTraffic(); - break; - - default: - defaultSend(ev, gisID, statID, shutdownID); - break; - } - } - } - - /** - * Generates few junk packets at the given interval - * @pre $none - * @post $none - */ - private synchronized void generateBackgroundTraffic() - { - // get the next inter-arrival time for these junk packets - long time = gen_.getNextPacketTime(); - - // get the sending pattern - int pattern = gen_.getPattern(); - - // for initial start-up, get the list of all resources first - if (hasStarted_ == false) - { - // get list of resource IDs from GIS - LinkedList resList = GridSim.getGridResourceList(); - - // if the list is empty then schedule the next time - if (resList == null && list_.size() == 0) - { - super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); - return; - } - - hasStarted_ = true; - list_.addAll(resList); // add resource IDs into the current list - - // sets the sending pattern - if (pattern == TrafficGenerator.SEND_ONE_ONLY && random_ == null) { - random_ = new Random(); - } - } - - // get the required info for generating this background traffic - long size = gen_.getNextPacketSize(); // packet size - long freq = gen_.getNextPacketFreq(); // packet freq - int type = gen_.getServiceType(); // packet type - int tag = GridSimTags.JUNK_PKT; // packet tag - - // we need to packetsize the data, all packets are sent with size MTU. - // only the last packet contains the data, the receiver should - // throw away all other packets - int MTU = link_.getMTU(); - int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); - - /********* // DEBUG info - System.out.println(); - System.out.println(super.get_name() + - ": START GENERATE BG traffic... at time "+ GridSim.clock()); - System.out.println(super.get_name() + - ": NEXT background traffic will start at " + time); - System.out.println(super.get_name() + - " num PACKETS = " + numPackets + ", freq = " + freq); - *********/ - - int i = 0; - int destId = -1; - - // send to one of the entity using uniform distribution - if (pattern == TrafficGenerator.SEND_ONE_ONLY) - { - int index = random_.nextInt( list_.size() ); - destId = ((Integer) list_.get(index)).intValue(); - - /********* // DEBUG info - System.out.println(super.get_name() + ": Destination id = " + - destId + " = " + GridSim.getEntityName(destId) ); - *********/ - - // create junk packets or empty NetPacket. - for (i = 0; i < freq; i++) { - convertIntoPacket(MTU, numPackets+1, tag, destId, type); - } - } - // send to all resources + other entities - else if (pattern == TrafficGenerator.SEND_ALL) - { - // send to all resources and user entities - for (int k = 0; k < list_.size(); k++) - { - destId = ((Integer) list_.get(k)).intValue(); - - /********* // DEBUG info - System.out.println(super.get_name() + ": Destination id = " + - destId + " = " + GridSim.getEntityName(destId) ); - *********/ - - // create junk packets or empty NetPacket. - for (i = 0; i < freq; i++) { - convertIntoPacket(MTU, numPackets+1, tag, destId, type); - } - } - } - - // sends the next junk packets - super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); - } - - /** - * Initial start for the background traffic - * @pre $none - * @post $none - */ - private synchronized void startBackgroundTraffic() - { - // if no background traffic generator, then skip the rest - if (gen_ == null) { - return; - } - - // get the next inter-arrival time - long time = gen_.getNextPacketTime(); - System.out.println(super.get_name() + - ": background traffic will start at time " + time); - - // starts background traffic if the inter-arrival time is valid - if (time == -1) { - return; - } - - super.sim_schedule(super.get_id(), time, GridSimTags.JUNK_PKT); - } - - /** - * This method processes outgoing data without a network extension. - * @param ev a Sim_event object - * @param gisID the central/default GIS entity ID - * @param statID the GridStatistic entity ID - * @param shutdownID the GridSimShutdown entity ID - * @pre ev != null - * @post $none - */ - private synchronized void defaultSend(Sim_event ev, int gisID, int statID, - int shutdownID) - { - IO_data io = (IO_data) ev.get_data(); - int destId = io.getDestID(); - - /***** // DEBUG info - System.out.println(super.get_name() + ".defaultSend(): Send to " + - GridSim.getEntityName(destId) + " tag = " + ev.get_tag() ); - *****/ - - // if this entity uses a network extension - if (link_ != null && destId != gisID && destId != statID && - destId != shutdownID) - { - submitToLink(ev); - return; - } - - // Identify ID of an entity which acts as Input/Buffer - // entity of destination entity - int id = GridSim.getEntityId( "Input_" + - Sim_system.get_entity(destId).get_name() ); - - // Send first and then hold - super.sim_schedule(id, GridSimTags.SCHEDULE_NOW, ev.get_tag(), io); - - double receiverBaudRate = ( (FlowInput) - Sim_system.get_entity(id) ).getBaudRate(); - - // NOTE: io is in byte and baud rate is in bits. 1 byte = 8 bits - // So, convert io into bits - double minBaudRate = Math.min(baudRate_, receiverBaudRate); - double communicationDelay = GridSimRandom.realIO( - (io.getByteSize() * BITS) / minBaudRate); - - // NOTE: Below is a deprecated method for SimJava 2 - //super.sim_hold(communicationDelay); - super.sim_process(communicationDelay); - } - - /** - * This method takes data from an entity. If the size of the data is larger - * than the MTU of the link, then the packet is split into mutiple size - * units. After this it calls enque() to queue these packets into its - * buffer. - * - * @param ev A Sim_event data that contains all the data for this method - * to do its task. - * @pre ev != null - * @post $none - */ - private synchronized void submitToLink(Sim_event ev) - { - IO_data data = (IO_data) ev.get_data(); - Object obj = data.getData(); - long size = data.getByteSize(); - int tag = ev.get_tag(); - int destId = data.getDestID(); - int netServiceType = data.getNetServiceLevel(); - - // we need to packetsize the data, all packets are sent with size MTU. - // only the last packet contains the data, the receiver should - // throw away all other packets - int MTU = link_.getMTU(); - int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); - - // make dummy packets with null data - convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); - - // last packet contains the actual data - NetPacket np = null; - np = new NetPacket(obj,pktID_,size - MTU*(numPackets-1),tag,super.get_id(), - destId, netServiceType, numPackets, numPackets); - - pktID_++; // increments packet ID - enque(np, GridSimTags.SCHEDULE_NOW); - } - - /** - * Creates many dummy or null packets - * @param size packet size (in bytes) - * @param numPackets total number of packets to be created - * @param tag packet tag - * @param destId destination ID for sending the packet - * @param netServiceType level type of service for the packet - * @pre $none - * @post $none - */ - private synchronized void convertIntoPacket(long size, int numPackets, - int tag, int destId, int netServiceType) - { - NetPacket np = null; - for (int i = 0; i < numPackets - 1; i++) - { - // change the tag name for dummy packets, apart from junk packets - if (tag != GridSimTags.JUNK_PKT) { - tag = GridSimTags.EMPTY_PKT; - } - - np = new NetPacket(null, pktID_, size, tag, super.get_id(), destId, - netServiceType, i+1, numPackets); - - pktID_++; // increments packet ID - enque(np, GridSimTags.SCHEDULE_NOW); - } - } - - /** - * Sends an InfoPacket for ping request - * @param ev a Sim_Event object - * @pre ev != null - * @post $none - */ - private synchronized void sendInfoPacket(Sim_event ev) - { - IO_data data = (IO_data) ev.get_data(); - - // gets all the relevant info - long size = data.getByteSize(); - int destId = data.getDestID(); - int netServiceType = data.getNetServiceLevel(); - int tag = ev.get_tag(); - String name = GridSim.getEntityName( outPort_.get_dest() ); - - // we need to packetsize the data, all packets are sent with size MTU - // only the last packet contains the ping data, the receiver should - // throw away all other data - int MTU = link_.getMTU(); - int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); - - // break ping size into smaller pieces - // Also, make sure that it is not for pinging itself - if (size > MTU && outPort_.get_dest() != destId) - { - // make dummy packets with null data - convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); - } - - // get the remaining ping size - size = data.getByteSize() - MTU*(numPackets-1); - - // create the real InfoPacket - InfoPacket pkt = new InfoPacket(name,pktID_,size,outPort_.get_dest(), - destId,netServiceType); - - // set the required info - pkt.setLast( super.get_id() ); - pkt.addHop( outPort_.get_dest() ); - pkt.addEntryTime( GridSim.clock() ); - pkt.setOriginalPingSize( data.getByteSize() ); - - pktID_++; // increments packet ID - enque(pkt, GridSimTags.SCHEDULE_NOW); - } - - /** - * Sends back the ping() request to the next hop or destination - * @param ev a Sim_event object - * @pre ev != null - * @post $none - */ - private void returnInfoPacket(Sim_event ev) - { - IO_data data = (IO_data) ev.get_data(); - - // use the original ping size rather than IO_data or InfoPacket size - // since the latter is restricted to MTU - InfoPacket pkt = (InfoPacket) data.getData(); - long size = pkt.getOriginalPingSize(); - - // get other relevant info - int tag = ev.get_tag(); - int destId = pkt.getSrcID(); - int netServiceType = data.getNetServiceLevel(); - - // we need to packetsize the data, all packets are sent with size MTU. - // only the last packet contains the data, the receiver should - // throw away all other packets - int MTU = link_.getMTU(); - int numPackets = (int) Math.ceil( size / (MTU * 1.0) ); - - // make dummy packets with null data - convertIntoPacket(MTU, numPackets, tag, destId, netServiceType); - - // set the original packet of last hop into this entity id - pkt.setLast( super.get_id() ); - enque(pkt, GridSimTags.SCHEDULE_NOW); - } - - /** - * Takes a packet, adds it into a buffer and schedules it to be sent out at - * an appropriate time. - * - * @param pkt The packet to be buffered - * @param delay The length of time this packet should be delayed (exclusive - * of the transmission time) - * @pre pkt != null - * @pre delay > 0 - * @post $none - */ - private synchronized void enque(Packet pkt, double delay) - { - packetList_.add(pkt); - if (packetList_.size() == 1) - { - double total = delay + (pkt.getSize()*SIZE / link_.getBaudRate()); - super.sim_schedule(super.get_id(), total, GridSimTags.SEND_PACKET); - } - } - - /** - * Removes a single packet from the buffer and sends it down the link. - * Then, schedules the next packet in the list. - * @pre $none - * @post $none - */ - private synchronized void sendPacket() - { - if (packetList_ == null || packetList_.isEmpty() == true) { - return; - } - - // submits the first packet in the list - Packet np = (Packet) packetList_.remove(0); - - boolean ping = false; // a flag to determine ping packet or not - int tag = -1; // event tag ID - int dest = -1; // destination ID - - // if a packet belongs to a ping packet - if (np instanceof InfoPacket) - { - ((InfoPacket)np).addExitTime( GridSim.clock() ); - ((InfoPacket)np).addBaudRate( link_.getBaudRate() ); - ping = true; - } - - // if an entity tries to send a packet to itself - if ( np.getDestID() == outPort_.get_dest() ) - { - // then change the destination name and id - String destName = super.get_name(); - destName = destName.replaceFirst("Output", "Input"); - dest = Sim_system.get_entity_id(destName); - - // for a ping packet, change the tag - if (ping == true) - { - // don't forget to change the packet tag - tag = GridSimTags.INFOPKT_RETURN; - ((InfoPacket) np).setTag(tag); - } - else { - tag = np.getTag(); - } - } - else // if an entity tries to send to other entity - { - // change or keep the event tag - tag = GridSimTags.PKT_FORWARD; - if (np.getTag() == GridSimTags.JUNK_PKT) { - tag = GridSimTags.JUNK_PKT; - } - - // sends the packet into the link - dest = link_.get_id(); - } - - // send the packet - super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np); - - /***** // DEBUG info - System.out.println(super.get_name() + " send to " + - GridSim.getEntityName(dest) + " tag = " + tag); - ****/ - - // if the list is not empty, then schedule the next packet in the list - if (packetList_.isEmpty() != true) - { - double delay = np.getSize() * SIZE / link_.getBaudRate(); - super.sim_schedule(super.get_id(), delay, GridSimTags.SEND_PACKET); - } - } - -} // end class - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-10 00:09:56
|
Revision: 143 http://gridsim.svn.sourceforge.net/gridsim/?rev=143&view=rev Author: marcos_dias Date: 2008-03-09 17:10:00 -0700 (Sun, 09 Mar 2008) Log Message: ----------- Some methods have been moved from the allocation policies to TAllocPolicy. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-03-10 00:10:00 UTC (rev 143) @@ -539,20 +539,6 @@ } /** - * Updates the Gridlet's properties, such as status once a - * Gridlet is considered finished. - * @param sgl a SSGridlet object - * @param status the Gridlet status - */ - protected void gridletFinish(SSGridlet sgl, int status) { - // the order is important! Set the status first then finalise - // due to timing issues in SSGridlet class - sgl.setStatus(status); - sgl.finalizeGridlet(); - super.sendFinishGridlet( sgl.getGridlet() ); - } - - /** * This method removes/updates all the entries of a gridlet from the profile * and updates the ranges of current free PEs if the gridlet was in execution. * @param gridlet the Gridlet to be removed Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-03-10 00:10:00 UTC (rev 143) @@ -1169,20 +1169,6 @@ } /** - * Updates the Gridlet's properties, such as status once a - * Gridlet is considered finished. - * @param sgl a SSGridlet object - * @param status the Gridlet status - */ - private void gridletFinish(SSGridlet sgl, int status) { - // the order is important! Set the status first then finalise - // due to timing issues in SSGridlet class - sgl.setStatus(status); - sgl.finalizeGridlet(); - super.sendFinishGridlet( sgl.getGridlet() ); - } - - /** * This method removes/updates all the entries of a gridlet from the profile * and updates the ranges of current free PEs if the gridlet was in execution. * @param gridlet the Gridlet to be removed Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-03-10 00:10:00 UTC (rev 143) @@ -901,20 +901,6 @@ return gridletStarted; } - /** - * Updates the Gridlet's properties, such as status once a - * Gridlet is considered finished. - * @param sgl a SSGridlet object - * @param status the Gridlet status - */ - private void gridletFinish(SSGridlet sgl, int status) { - // the order is important! Set the status first then finalise - // due to timing issues in SSGridlet class - sgl.setStatus(status); - sgl.finalizeGridlet(); - super.sendFinishGridlet( sgl.getGridlet() ); - } - /* * This method obtains the queue from the profile and does a casting */ Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-10 00:10:00 UTC (rev 143) @@ -722,18 +722,4 @@ return gridletStarted; } - - /** - * Updates the Gridlet's properties, such as status once a - * Gridlet is considered finished. - * @param sgl a SSGridlet object - * @param status the Gridlet status - */ - protected void gridletFinish(SSGridlet sgl, int status) { - // the order is important! Set the status first then finalise - // due to timing issues in SSGridlet class - sgl.setStatus(status); - sgl.finalizeGridlet(); - super.sendFinishGridlet( sgl.getGridlet() ); - } } Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PERangeList.java 2008-03-10 00:10:00 UTC (rev 143) @@ -223,7 +223,7 @@ universe.sortRanges(); boolean finished = false; - while(!finished){ + while(!finished) { finished = true; PERangeList diffRange = null; look:{ @@ -288,8 +288,6 @@ return selected; } - //TODO: The method below is not working properly. To fix it. - //TODO: As I am not using it at the moment, leave it as it is. /** * Returns the symmetric difference of two lists of ranges. * The output sequence will contain all elements that are in the ranges @@ -299,41 +297,28 @@ * @return the range corresponding to the symmetric difference */ public static PERangeList symmetricDifference(PERangeList lista, PERangeList listb){ - if(lista == null || listb == null) + if(lista == null && listb != null) + return listb.clone(); + else if(lista != null && listb == null) + return lista.clone(); + else if(lista == null && listb == null) return null; + + PERangeList difference = new PERangeList(); + PERangeList diff = difference(lista, listb); + if(diff != null && diff.size() > 0) + difference.addAll(diff); - PERangeList query = lista; - PERangeList universe = listb; - - for(PERange rangeq : query){ - boolean intersected = false; - PERangeList tempDiff = new PERangeList(); - Iterator<PERange> iterUni = universe.iterator(); - while( !intersected || iterUni.hasNext()){ - PERange rangeu = iterUni.next(); - if(intersect(rangeq, rangeu)){ - PERangeList diffRange = symmetricDifference(rangeq, rangeu); - if(diffRange != null){ - tempDiff.addAll(diffRange); - } - intersected = true; - } - else{ - tempDiff.add(rangeu); - } - } - if(!intersected){ - tempDiff.add(rangeq); - } - universe = tempDiff.clone(); - } + diff = difference(listb, lista); + if(diff != null && diff.size() > 0) + difference.addAll(diff); - if(universe == null || universe.size() == 0){ + if(difference.size() == 0){ return null; } else{ - universe.mergePERanges(); - return universe; + difference.mergePERanges(); + return difference; } } @@ -505,87 +490,8 @@ } return false; } - - /** - * Returns the symmetric difference of two ranges. The output will - * contain a list of ranges that are in one range but not in the other. - * @param rangea the first range - * @param rangeb the second range - * @return the range corresponding to the symmetric difference - */ - private static PERangeList symmetricDifference(PERange rangea, PERange rangeb){ - if(rangea == null || rangeb == null) - return null; - - int starta = rangea.getBeginning(); - int startb = rangeb.getBeginning(); - int enda = rangea.getEnd(); - int endb = rangeb.getEnd(); - - int startai = -1; - int endai = Integer.MAX_VALUE; - - int startbi = -1; - int endbi = Integer.MAX_VALUE; - - while( !(starta > enda) || !(startb > endb) ){ - if(starta < startb){ - if(startai < 0){ - startai = starta; - } - endai = starta; - starta++; - } - else if(startb < starta){ - if(startai < 0){ - startai = startb; - } - endai = startb; - startb++; - } - else{ - break; - } - } - - starta = rangea.getBeginning(); - startb = rangeb.getBeginning(); - - while( !(enda < starta) || !(endb < startb) ){ - if(enda > endb){ - if(endbi == Integer.MAX_VALUE){ - endbi = enda; - } - startbi = enda; - enda--; - } - else if(endb > enda){ - if(endbi == Integer.MAX_VALUE){ - endbi = endb; - } - startbi = endb; - endb--; - } - else{ - break; - } - } - - PERangeList difference = new PERangeList(); - if( (startai >= 0) && (endai != Integer.MAX_VALUE) ){ - PERange rBefore = new PERange(startai, endai); - difference.add(rBefore); - } - - if( (startbi >= 0) && (endbi != Integer.MAX_VALUE) ){ - PERange rAfter = new PERange(startbi, endbi); - difference.add(rAfter); - } - - return difference.size() == 0 ? null : difference; - } - // FOR DEBUGGING PURPOSES ONLY... +// // FOR DEBUGGING PURPOSES ONLY... // public static void main(String args[]){ // // PERange ra = new PERange(0, 10); @@ -600,19 +506,20 @@ //// System.out.println("Consolidated# " + list); // // PERangeList list1 = new PERangeList(); -// list1.add(ra); list1.add(rb); -// list1.add(rc); list1.add(rd); +// list1.add(new PERange(400, 1000)); +//// list1.add(ra); list1.add(rb); +//// list1.add(rc); list1.add(rd); // // PERangeList list2 = new PERangeList(); // list2.add(ra); list2.add(rb); // list2.add(rc); list2.add(rd); // // PERangeList list3 = new PERangeList(); -// list3.add(new PERange(500, 1000)); -// list3.add(new PERange(0, 499)); -// list3.add(new PERange(1001, 1005)); +// list3.add(new PERange(500, 2000)); +//// list3.add(new PERange(0, 499)); +//// list3.add(new PERange(1001, 1005)); // -// PERangeList difference = difference(null, list3); -// System.out.println("Range list " + null + " minus " + list3 + " is " + difference); +// PERangeList difference = symmetricDifference(list1, list3); +// System.out.println("Symmetric difference between list " + list1 + " and " + list3 + " is " + difference); // } } \ No newline at end of file Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-03-09 02:56:01 UTC (rev 142) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/TAllocPolicy.java 2008-03-10 00:10:00 UTC (rev 143) @@ -177,4 +177,18 @@ return finishTime; } + + /** + * Updates the Gridlet's properties, such as status once a + * Gridlet is considered finished. + * @param sgl a SSGridlet object + * @param status the Gridlet status + */ + protected void gridletFinish(SSGridlet sgl, int status) { + // the order is important! Set the status first then finalise + // due to timing issues in SSGridlet class + sgl.setStatus(status); + sgl.finalizeGridlet(); + super.sendFinishGridlet( sgl.getGridlet() ); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-09 02:55:56
|
Revision: 142 http://gridsim.svn.sourceforge.net/gridsim/?rev=142&view=rev Author: marcos_dias Date: 2008-03-08 18:56:01 -0800 (Sat, 08 Mar 2008) Log Message: ----------- The message that shows "Starting GridSim Version X" has been fixed to show the right version of GridSim when the simulation is started. Modified Paths: -------------- trunk/source/gridsim/GridSim.java Modified: trunk/source/gridsim/GridSim.java =================================================================== --- trunk/source/gridsim/GridSim.java 2008-03-09 02:52:03 UTC (rev 141) +++ trunk/source/gridsim/GridSim.java 2008-03-09 02:56:01 UTC (rev 142) @@ -71,6 +71,7 @@ private final int ARRAY_SIZE = 3; private final int SIZE = 12; // Integer object size incl. overhead private final int RESULT = 1; // array[0] = gridlet id, [1] = result + private final static String GRIDSIM_VERSION_STRING = "GridSim Version 4.1"; /////////////////////////// STATIC variables //////////////////// @@ -600,7 +601,7 @@ */ public static void startGridSimulation() throws NullPointerException { - System.out.println("Starting GridSim version 4.0"); + System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING); try { Sim_system.run(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-09 02:52:01
|
Revision: 141 http://gridsim.svn.sourceforge.net/gridsim/?rev=141&view=rev Author: marcos_dias Date: 2008-03-08 18:52:03 -0800 (Sat, 08 Mar 2008) Log Message: ----------- This update includes an option in the aggressive backfilling policies that allows the user to provide an implementation of comparator, which defines how the queued jobs are ordered. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-03-05 02:36:56 UTC (rev 140) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AvailabilityProfileEntry.java 2008-03-09 02:52:03 UTC (rev 141) @@ -3,7 +3,6 @@ * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html - * */ package gridsim.turbo; Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-03-05 02:36:56 UTC (rev 140) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-03-09 02:52:03 UTC (rev 141) @@ -503,7 +503,7 @@ // iterates the waiting queue and for each gridlet, put the ranges // used back in the profile. That is, updates the entries - Collections.sort(queuedGridlets_, orderByPriority_); + Collections.sort(queuedGridlets_, jobOrderHeuristic_); Iterator<SSGridlet> iterQueue = queuedGridlets_.iterator(); while(iterQueue.hasNext()) { Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-03-05 02:36:56 UTC (rev 140) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-03-09 02:52:03 UTC (rev 141) @@ -15,6 +15,7 @@ import gridsim.ParameterException; import gridsim.gui.AllocationAction; +import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; @@ -73,7 +74,7 @@ protected LinkedList<SSGridlet> runningGridlets_; // Queue of Gridlets waiting in this queue - protected LinkedList<SSGridlet> queuedGridlets_; + protected ArrayList<SSGridlet> queuedGridlets_; // The rating of one PE protected int ratingPE_; @@ -84,8 +85,8 @@ // The availability profile protected MPAvailabilityProfile profile_; - // to order the gridlets according to their priorities and submission times - protected OrderGridletsByPriority orderByPriority_; + // heuristic used to order the jobs for backfilling + protected Comparator<SSGridlet> jobOrderHeuristic_; // used by the scheduler to specify the priority of the item protected PrioritySelector prioritySelector_; @@ -141,8 +142,8 @@ // initialises local data structure runningGridlets_ = new LinkedList<SSGridlet>(); - queuedGridlets_ = new LinkedList<SSGridlet>(); - orderByPriority_ = new OrderGridletsByPriority(); + queuedGridlets_ = new ArrayList<SSGridlet>(); + jobOrderHeuristic_ = new OrderGridletsByPriority(); numPartitions_ = numPartitions; profile_ = new MPAvailabilityProfile(); prioritySelector_ = null; @@ -188,6 +189,21 @@ } /** + * Sets the heuristic used to order the jobs considered for backfilling + * @param comparator a comparator implementation that defines + * how gridlets are ordered. + * @return <tt>true</tt> if the heuristic was set correctly; + * <tt>false</tt> otherwise. + */ + public boolean setJobOrderingHeuristic(Comparator<SSGridlet> comparator) { + if(comparator == null) + return false; + + jobOrderHeuristic_ = comparator; + return true; + } + + /** * Indicates whether the borrowing of resources of the partitions from * one another is allowed or not. * @param allow <tt>true</tt> indicates that it is allowed; @@ -372,12 +388,8 @@ } sgl.setPartitionID(queueId); - sgl.setStatus(Gridlet.QUEUED); queuedGridlets_.add(sgl); - - // order gridlets according to their priorities - Collections.sort(queuedGridlets_, orderByPriority_); backfillGridlets(GridSim.clock()); //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -592,14 +604,15 @@ EasyBackFillingPartition queue = getPartition(queueId); - // if queue has a pivot already, then just add - // the job to the waiting queue + // if queue has a pivot already, then check whether the pivot appears + // before in the queue after reordering. If it does, then the job + // to be scheduled becomes the new pivot if(queue.pivot_ != null) { - // checks whether the priority of the pivot is lower than the - // job being considered for scheduling. - // If priority of pivot is higher or equals to sgl's, then do not - // make any change - if(queue.pivot_.getPriority() >= sgl.getPriority()) + + int indexPivot = queuedGridlets_.indexOf(queue.pivot_); + int indexNewGrl = queuedGridlets_.indexOf(sgl); + + if(indexPivot < indexNewGrl) return false; else { profile_.updateEntriesAtProfile(queue.pivot_); @@ -851,6 +864,9 @@ } } + // order gridlets according to the job ordering heuristic provided + Collections.sort(queuedGridlets_, jobOrderHeuristic_); + // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than reference time Iterator<SSGridlet> iter = queuedGridlets_.iterator(); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-05 02:36:56 UTC (rev 140) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-03-09 02:52:03 UTC (rev 141) @@ -16,6 +16,8 @@ import gridsim.gui.AllocationAction; import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.LinkedList; @@ -83,8 +85,11 @@ protected AvailabilityProfile availProfile_; // the resource characteristics object to be used - protected TResourceCharacteristics resource_; + protected TResourceCharacteristics resource_; + // heuristic used to order the jobs for backfilling + protected Comparator<SSGridlet> jobOrderHeuristic_; + // the last time when the schedule updated was called private double lastScheduleUpdate_; @@ -178,6 +183,21 @@ } /** + * Sets the heuristic used to order the jobs considered for backfilling + * @param comparator a comparator implementation that defines + * how gridlets are ordered. + * @return <tt>true</tt> if the heuristic was set correctly; + * <tt>false</tt> otherwise. + */ + public boolean setJobOrderingHeuristic(Comparator<SSGridlet> comparator) { + if(comparator == null) + return false; + + jobOrderHeuristic_ = comparator; + return true; + } + + /** * Schedules/adds to the queue a new <tt>Gridlet</tt> received by the * <tt>GridResource</tt> entity. * @param gridlet a Gridlet object to be executed @@ -478,7 +498,6 @@ sgl.setPERangeList(selected); // changes the Gridlet status -// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); pivot_ = sgl; @@ -679,6 +698,11 @@ pivot_ = null; } } + + // order jobs according to the ordering heuristic provided. + // That is, if one was provided by the user. + if(jobOrderHeuristic_ != null) + Collections.sort(queuedGridlets_, jobOrderHeuristic_); // Start the execution of Gridlets that are queued Iterator<SSGridlet> iter = queuedGridlets_.iterator(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-05 02:36:51
|
Revision: 140 http://gridsim.svn.sourceforge.net/gridsim/?rev=140&view=rev Author: marcos_dias Date: 2008-03-04 18:36:56 -0800 (Tue, 04 Mar 2008) Log Message: ----------- This update gives the user to quit the simulation when a given event occurs. This is useful for users who want to simulate steady state of a system and want to quit the simulation whenever a user submits its last job. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridSim.java branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-03-05 02:36:56 UTC (rev 140) @@ -2013,7 +2013,7 @@ /** * Tells all user entities to shut down the simulation. * {@link gridsim.GridSimShutdown} entity waits for all users - * termination before shuting down other entities. + * termination before shutting down other entities. * @see gridsim.GridSimShutdown * @pre $none * @post $none @@ -2026,6 +2026,23 @@ } /** + * Tells all user entities to shut down the simulation. + * {@link gridsim.GridSimShutdown} will not wait for all users + * termination before shutting down other entities. This method is relevant + * if you want to avoid the cooling down phase of simulation and use + * only the steady state. Therefore, you can shutdown the whole simulation + * when required. + * @see gridsim.GridSimShutdown + * @pre $none + * @post $none + */ + protected void shutdownSimulation() { + if (shutdownID_ != NOT_FOUND) { + send(shutdownID_, 0.0, GridSimTags.ABRUPT_END_OF_SIMULATION); + } + } + + /** * Tells the <tt>GridStatistics</tt> entity the end of the simulation * @pre $none * @post $none Modified: branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSimShutdown.java 2008-03-05 02:36:56 UTC (rev 140) @@ -110,9 +110,10 @@ * end of a simulation based on <tt>reportWriterName</tt> defined in * the Constructor. * <br> - * <b>NOTE:</b> This method shuts down grid resources and GIS entities - * <tt>AFTER</tt> all grid users have been shut down. - * Therefore, the number of grid users given in the + * <b>NOTE:</b> This method shuts down grid resources and GIS entities + * either <tt>AFTER</tt> all grid users have been shut down or + * an entity requires an abrupt end of the whole simulation. + * In the first case, the number of grid users given in the * Constructor <tt>must</tt> be correct. Otherwise, GridSim * package hangs forever or it does not terminate properly. * @pre $none @@ -127,6 +128,11 @@ // with number of user entities given during GridSim.init(). for (int i = 0; i < numUser_; i++) { super.sim_get_next(ev); + if(ev.get_tag() == GridSimTags.ABRUPT_END_OF_SIMULATION) { + System.out.println(super.get_name() + + ": Abrupting stopping simulation!"); + break; + } } // Shutdown GIS - now GIS is responsible for informing end of simulation Modified: branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java 2008-03-02 22:53:59 UTC (rev 139) +++ branches/gridsim4.0-branch3/source/gridsim/GridSimTags.java 2008-03-05 02:36:56 UTC (rev 140) @@ -47,7 +47,12 @@ /** Denotes the end of simulation */ public static final int END_OF_SIMULATION = -1; - + + /** Denotes an abrupt end of simulation. That is, one event of this + * type is enough for {@link GridSimShutdown} to trigger the end of the + * simulation */ + public static final int ABRUPT_END_OF_SIMULATION = -2; + ////////////////////////////////////////////////////////////////////// /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-02 22:54:11
|
Revision: 139 http://gridsim.svn.sourceforge.net/gridsim/?rev=139&view=rev Author: marcos_dias Date: 2008-03-02 14:53:59 -0800 (Sun, 02 Mar 2008) Log Message: ----------- QueuePartition is now a public class. Users extending the multi-partition policies may find it useful. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-03-01 01:10:44 UTC (rev 138) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-03-02 22:53:59 UTC (rev 139) @@ -1041,112 +1041,3 @@ return entry; } } - -/** - * This class represents a partition in this scheduler. It only - * stores a few variables used to control the partition. - * @author Marcos Dias de Assuncao - * @since GridSim Turbo Alpha 0.1 - */ -class QueuePartition { - private int partitionId_; // this partition's identifier - private int initialNumPEs_; // the initial number of PEs allocated - private PERangeList idlePERanges_; // idle resources in this partition - - // to check whether a gridlet can be scheduled in this queue - private QueuePartitionPredicate predicate_; - - /** - * Creates a new <tt>Queuepartition</tt> object. - * @param queueId the partition ID - * @param numPE the number of PEs initially assigned to the partition - * @param predicate the queue predicate - * @see gridsim.turbo.QueuePartitionPredicate - */ - public QueuePartition(int queueId, - int numPE, QueuePartitionPredicate predicate) { - this.partitionId_ = queueId; - initialNumPEs_ = numPE; - predicate_ = predicate; - } - - /** - * Gets the partition ID - * @return the partition ID - */ - public int getPartitionId() { - return partitionId_; - } - - /** - * Sets the partition ID - * @param partitionId the partition ID - * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. - */ - public boolean setPartitionId(int partitionId) { - if(partitionId < 0) - return false; - - partitionId_ = partitionId; - return true; - } - - /** - * Gets the number of PEs initially assigned to the partition - * @return the number of PEs initially assigned to the partition - */ - public int getInitialNumPEs() { - return initialNumPEs_; - } - - /** - * Sets the number of PEs initially assigned to the partition - * @param initialNumPEs the number of PEs initially assigned - * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. - */ - public boolean setInitialNumPEs(int initialNumPEs) { - if(initialNumPEs < 0) - return false; - - initialNumPEs_ = initialNumPEs; - return true; - } - - /** - * Gets the number of PEs currently idle at a partition - * @return the number of PEs currently idle at a partition - */ - public PERangeList getIdlePERanges() { - return idlePERanges_; - } - - /** - * Sets the number of PEs currently idle at a partition - * @param idlePERanges the number of PEs currently idle at a partition - */ - public void setIdlePERanges(PERangeList idlePERanges) { - idlePERanges_ = idlePERanges; - } - - /** - * Gets the predicate of this partition - * @return the predicate of this partition - */ - public QueuePartitionPredicate getPredicate() { - return predicate_; - } - - /** - * Sets the predicate of this partition - * @param predicate the predicate of this partition - * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. - */ - public boolean setPredicate(QueuePartitionPredicate predicate) { - if(predicate == null) - return false; - - predicate_ = predicate; - return true; - } -} - Added: branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartition.java 2008-03-02 22:53:59 UTC (rev 139) @@ -0,0 +1,109 @@ +package gridsim.turbo; + +/** + * This class represents a partition in this scheduler. It only + * stores a few variables used to control the partition. + * @author Marcos Dias de Assuncao + * @since GridSim Turbo Alpha 0.1 + */ +public class QueuePartition { + private int partitionId_; // this partition's identifier + private int initialNumPEs_; // the initial number of PEs allocated + private PERangeList idlePERanges_; // idle resources in this partition + + // to check whether a gridlet can be scheduled in this queue + private QueuePartitionPredicate predicate_; + + /** + * Creates a new <tt>Queuepartition</tt> object. + * @param queueId the partition ID + * @param numPE the number of PEs initially assigned to the partition + * @param predicate the queue predicate + * @see gridsim.turbo.QueuePartitionPredicate + */ + public QueuePartition(int queueId, + int numPE, QueuePartitionPredicate predicate) { + this.partitionId_ = queueId; + initialNumPEs_ = numPE; + predicate_ = predicate; + } + + /** + * Gets the partition ID + * @return the partition ID + */ + public int getPartitionId() { + return partitionId_; + } + + /** + * Sets the partition ID + * @param partitionId the partition ID + * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. + */ + public boolean setPartitionId(int partitionId) { + if(partitionId < 0) + return false; + + partitionId_ = partitionId; + return true; + } + + /** + * Gets the number of PEs initially assigned to the partition + * @return the number of PEs initially assigned to the partition + */ + public int getInitialNumPEs() { + return initialNumPEs_; + } + + /** + * Sets the number of PEs initially assigned to the partition + * @param initialNumPEs the number of PEs initially assigned + * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. + */ + public boolean setInitialNumPEs(int initialNumPEs) { + if(initialNumPEs < 0) + return false; + + initialNumPEs_ = initialNumPEs; + return true; + } + + /** + * Gets the number of PEs currently idle at a partition + * @return the number of PEs currently idle at a partition + */ + public PERangeList getIdlePERanges() { + return idlePERanges_; + } + + /** + * Sets the number of PEs currently idle at a partition + * @param idlePERanges the number of PEs currently idle at a partition + */ + public void setIdlePERanges(PERangeList idlePERanges) { + idlePERanges_ = idlePERanges; + } + + /** + * Gets the predicate of this partition + * @return the predicate of this partition + */ + public QueuePartitionPredicate getPredicate() { + return predicate_; + } + + /** + * Sets the predicate of this partition + * @param predicate the predicate of this partition + * @return <tt>true</tt> if set properly; <tt>false</tt> otherwise. + */ + public boolean setPredicate(QueuePartitionPredicate predicate) { + if(predicate == null) + return false; + + predicate_ = predicate; + return true; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-01 01:10:39
|
Revision: 138 http://gridsim.svn.sourceforge.net/gridsim/?rev=138&view=rev Author: marcos_dias Date: 2008-02-29 17:10:44 -0800 (Fri, 29 Feb 2008) Log Message: ----------- Additional features in the easy backfilling multi partition policy: + Option to provide a priority selector that indicates what priorities the scheduler should assign to gridlets submitted to the resource. + The user can indicate whether the partitions can borrow resources from one another or not. This may be useful if the user wants to implement complex policies where he controls how the resources are allocated to the partitions. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java Added Paths: ----------- branches/gridsim4.0-branch3/source/gridsim/turbo/PrioritySelector.java Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-28 04:11:36 UTC (rev 137) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-03-01 01:10:44 UTC (rev 138) @@ -87,6 +87,13 @@ // to order the gridlets according to their priorities and submission times protected OrderGridletsByPriority orderByPriority_; + // used by the scheduler to specify the priority of the item + protected PrioritySelector prioritySelector_; + + // indicates whether the borrowing of resources by the + // partitions is allowed or not + private boolean allowBorrowing_; + // the number of partitions or queues in this scheduler protected int numPartitions_; @@ -138,7 +145,9 @@ orderByPriority_ = new OrderGridletsByPriority(); numPartitions_ = numPartitions; profile_ = new MPAvailabilityProfile(); + prioritySelector_ = null; lastScheduleUpdate_ = 0.0D; + allowBorrowing_ = true; ratingPE_ = 0; } @@ -177,6 +186,31 @@ profile_.addPartition(partition); return true; } + + /** + * Indicates whether the borrowing of resources of the partitions from + * one another is allowed or not. + * @param allow <tt>true</tt> indicates that it is allowed; + * <tt>false</tt> otherwise. + */ + public void setAllowBorrowing(boolean allow) { + allowBorrowing_ = allow; + } + + /** + * Sets the priority selector to be used by this scheduler. The selector + * defines what priorities the scheduler should assign to the gridlets. + * @param selector the selector to be used. + * @return <tt>true</tt> if the selector has been defined successfully or + * <tt>false</tt> otherwise. + */ + public boolean setPrioritySelector(PrioritySelector selector) { + if(selector == null || Sim_system.running()) + return false; + + prioritySelector_ = selector; + return true; + } /** * Handles internal events that come to this entity. @@ -227,8 +261,13 @@ PERangeList freeRanges = resource_.getFreePERanges().clone(); for(QueuePartition partition : profile_.getPartitions()) { allocPE += partition.getInitialNumPEs(); - PERangeList selected = - super.selectPERangeList(partition.getInitialNumPEs(), freeRanges); + PERangeList selected = null; + + if(partition.getInitialNumPEs() > 0) + selected = super.selectPERangeList(partition.getInitialNumPEs(), freeRanges); + else + selected = new PERangeList(); + partition.setIdlePERanges(selected); freeRanges = PERangeList.difference(freeRanges, selected); } @@ -281,7 +320,7 @@ public void gridletSubmit(Gridlet gridlet, boolean ack) { int reqPE = gridlet.getNumPE(); - try{ + try { // reject the Gridlet if it requires more PEs than the resource // is able to provide if(reqPE > super.totalPE_){ @@ -296,13 +335,15 @@ return; } } - catch(Exception ex){ + catch(Exception ex) { System.out.println(super.get_name() + ": Exception on submission of a Gridlet"); } // Create a resource Gridlet SSGridlet sgl = new SSGridlet(gridlet); + if(prioritySelector_ != null) + sgl.setPriority(prioritySelector_.getSchedulePriority(sgl)); //-------------- FOR DEBUGGING PURPOSES ONLY -------------- @@ -480,7 +521,7 @@ // If the queue to which the gridlet is assigned does not have the // required PEs, then tries to borrow the additional PEs from other queues - if(!success) { + if(!success && allowBorrowing_) { // gets all available PEs during given time interval PERangeList overallAvailPEs = profile_.getImmediateAvailability(executionTime); @@ -595,14 +636,19 @@ anchor = (Integer)availObjQueue[0]; startTimeQueue=profile_.get(anchor).getTime(); } + + double startTimeAll; + if (!allowBorrowing_) + startTimeAll = Double.MAX_VALUE; + else { + anchor = (Integer)availObj[0]; + startTimeAll=profile_.get(anchor).getTime(); + } - anchor = (Integer)availObj[0]; - double startTimeAll = profile_.get(anchor).getTime(); - // if the time if the selected partition is smaller or the same as // considering all the partitions, so that means that we can select // resources from the selected partition - if(startTimeQueue <= startTimeAll) { + if(startTimeQueue < Double.MAX_VALUE && startTimeQueue <= startTimeAll) { ranges = (PERangeList)availObjQueue[2]; ranges = super.selectPERangeList(reqPE, ranges); @@ -617,7 +663,7 @@ } // If the queue to which the gridlet is assigned does not have the // required PEs, then try to borrow the additional PEs from other queues. - else { + else if (startTimeAll < Double.MAX_VALUE) { PERangeList addRanges = (PERangeList)availObj[2]; // the anchor index, the entry in the profile where @@ -653,6 +699,9 @@ profile_.allocatePERanges(queueId, anchorIndex, tailIndex, ranges, startTime, finishTime); } + else { + return false; + } queue.pivot_ = sgl; @@ -660,7 +709,6 @@ sgl.setPERangeList(ranges); // change Gridlet status -// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-02-28 04:11:36 UTC (rev 137) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-03-01 01:10:44 UTC (rev 138) @@ -37,7 +37,7 @@ super(); queues_ = new HashMap<Integer, QueuePartition>(); } - + /** * Returns the number of PEs assigned to the partitions * @return the number of PEs assigned to the partitions @@ -266,7 +266,7 @@ * @return the list of ranges of PEs available */ public PERangeList getImmediateAvailability(double duration) { - + double startTime = GridSim.clock(); // start time is now // the gridlet's expected finish time @@ -426,7 +426,7 @@ * array[2] = the list of PEs available at that time */ public Object[] checkPERangesAvailability(int reqPE, double duration) { - + // the anchor index, the entry in the profile where // the gridlet will be placed OR the closest entry to the // point where the anchor of the advance reservation will be placed Added: branches/gridsim4.0-branch3/source/gridsim/turbo/PrioritySelector.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/PrioritySelector.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/PrioritySelector.java 2008-03-01 01:10:44 UTC (rev 138) @@ -0,0 +1,30 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.turbo; + +/** + * This interface is used by a scheduler to obtain the priority of a given + * schedule item (i.e. gridlet or advance reservation). This information is + * used by allocation policies that use priorities + * such as {@link EBMultiplePartitions}. + * + * @author Marcos Dias de Assuncao + * @since GridSim Turbo Alpha 0.1 + */ + +public interface PrioritySelector { + + /** + * Returns the priority of the item to be assigned by the scheduler + * or allocation policy. + * @param item the item whose priority needs to be obtained. + * @return the priority of the schedule item or <tt>-1</tt> if unknown. + */ + int getSchedulePriority(ScheduleItem item); + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-28 04:11:40
|
Revision: 137 http://gridsim.svn.sourceforge.net/gridsim/?rev=137&view=rev Author: marcos_dias Date: 2008-02-27 20:11:36 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Inclusion of a parallel space shared policy with queue partitions, easy backfilling, priorities and advance reservation. Modified Paths: -------------- branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java branches/gridsim4.0-branch3/source/gridsim/GridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARTGridResource.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java Added Paths: ----------- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java Modified: branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java 2008-02-27 23:37:51 UTC (rev 136) +++ branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java 2008-02-28 04:11:36 UTC (rev 137) @@ -63,7 +63,7 @@ * <tt>java -Xmx</tt> option when running the simulation. * <li> If you are running an experiment using the network extension, * i.e. the gridsim.net package, then you need to use - * {@link #Workload(String, double, double, int, String, String, int)} + * {@link #WorkloadWithReservation(String, double, double, int, String, String, int)} * instead. * <li> The default job file size for sending to and receiving from * a resource is {@link gridsim.net.Link#DEFAULT_MTU}. @@ -605,10 +605,12 @@ Gridlet gl = null; int counter = 1; // starts at 1, since gridletID_ starts at 1 too + int fails = 0; + int returned = 0; Sim_event ev = new Sim_event(); Object[] reservObj = null; - while ( Sim_system.running() && counter < gridletID_ ) { + while ( Sim_system.running()) { super.sim_get_next(ev); // get the next available event data = ev.get_data(); // get the event's data @@ -668,6 +670,7 @@ if(!success) { list_.add(resGl); counter++; + fails++; } } @@ -676,9 +679,16 @@ gl = (Gridlet) data; list_.add(gl); counter++; + returned++; } + + if(counter == gridletID_) + break; } +// System.out.println("gridlet ID = " + gridletID_ +// + ", fails = " + fails + ", returned = " + returned + ", counter=" + counter); + // shut down all the entities, including GridStatistics entity since // we used it to record certain events. shutdownGridStatisticsEntity(); Added: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java (rev 0) +++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboAREBMultipleQueuesExample01.java 2008-02-28 04:11:36 UTC (rev 137) @@ -0,0 +1,206 @@ + +package examples.workload.ar; + +import examples.QueuePredicateExample; +import examples.WorkloadWithReservation; +import gridsim.GridResource; +import gridsim.GridSim; +import gridsim.Machine; +import gridsim.MachineList; +import gridsim.ResourceCalendar; +import gridsim.turbo.AREBMultiplePartitions; +import gridsim.turbo.ARTGridResource; +import gridsim.turbo.TResourceCharacteristics; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.LinkedList; +import java.util.Random; + + +/** + * Test Driver class for this example. This example just tests + * the same features provided by the ParallelSpaceShared policy + */ +public class TurboAREBMultipleQueuesExample01 +{ + /** + * Creates main() to run this example + */ + public static void main(String[] args) + { + long startTime = System.currentTimeMillis(); + if(args.length == 0){ + System.out.println("Please provide the location of the workload file!"); + System.exit(1); + } + + try { + + ////////////////////////////////////////// + // Get the workload to be used The format should be: + // ASCII text, gzip or zip. + + String fileName = args[0]; + ArrayList<GridResource> resources = new ArrayList<GridResource>(); + + ////////////////////////////////////////// + // 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. + + // number of grid user entities + any Workload entities. + int num_user = 1; + 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"); + GridSim.init(num_user, calendar, trace_flag); + + ////////////////////////////////////////// + // Creates one or more GridResource entities + int totalResource = 1; // total number of Grid resources + int rating = 377; // rating of each PE in MIPS + int totalPE = 9; // total number of PEs for each Machine + int totalMachine = 128; // total number of Machines + int i = 0; + + String[] resArray = new String[totalResource]; + for (i = 0; i < totalResource; i++) + { + String resName = "Res_" + i; + GridResource resource = createGridResource(resName, rating, totalMachine, totalPE); + resources.add(resource); + + // add a resource name into an array + resArray[i] = resName; + } + + ////////////////////////////////////////// + // Creates one Workload trace entity. + + int resID = 0; + Random r = new Random(); + resID = r.nextInt(totalResource); + WorkloadWithReservation workload = + new WorkloadWithReservation("Load_1", fileName, resArray[resID], rating); + + // sets how long in advance the reservations are made (24 hours here) + workload.setARTimeInAdvance( 24 * 60 * 60 ); + + // sets the probability of a job read from the trace file being an advance reservation + workload.setReservationProbability(0.5); + + ////////////////////////////////////////// + // Starts the simulation in debug mode +// GridSim.startGridSimulation(true); + + // Start the simulation in normal mode + GridSim.startGridSimulation(); + + ////////////////////////////////////////// + // Final step: Prints the Gridlets when simulation is over + long finishTime = System.currentTimeMillis(); + System.out.println("The simulation took " + (finishTime - startTime) + " milliseconds"); + + // prints the Gridlets inside a Workload entity + // workload.printGridletList(trace_flag); + } + catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Creates one Grid resource. A Grid resource contains one or more + * Machines. Similarly, a Machine contains one or more PEs (Processing + * Elements or CPUs). + * @param name a Grid Resource name + * @param peRating rating of each PE + * @param totalMachine total number of Machines + * @param totalPE total number of PEs for each Machine + */ + private static GridResource createGridResource(String name, int peRating, + int totalMachine, int totalPE) + { + + ////////////////////////////////////////// + // 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++) + { + ////////////////////////////////////////// + // 4. Create one Machine with its id and list of PEs or CPUs + mList.add( new Machine(i, totalPE, peRating) ); + } + + ////////////////////////////////////////// + // 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 = 0.0; // time zone this resource located + double cost = 3.0; // the cost of using this resource + + TResourceCharacteristics resConfig = + new TResourceCharacteristics(arch, os, mList, + TResourceCharacteristics.AREB_MULTI_PARTITIONS, + time_zone, cost); + + AREBMultiplePartitions policy = null; + try { + policy = new AREBMultiplePartitions(name, "Policy", 3); + } catch (Exception e1) { + e1.printStackTrace(); + } + + // creates three partitions, one for small jobs, one for medium size jobs + // and another for long jobs + QueuePredicateExample express = new QueuePredicateExample(0, 1000, peRating); + QueuePredicateExample medium = new QueuePredicateExample(1000, 10000, peRating); + QueuePredicateExample large = new QueuePredicateExample(10000, Integer.MAX_VALUE, peRating); + + policy.createPartition(0, resConfig.getNumPE() / 3, express); + policy.createPartition(1, resConfig.getNumPE() / 3, medium); + policy.createPartition(2, resConfig.getNumPE() / 3, large); + + ////////////////////////////////////////// + // 6. Finally, we need to create a GridResource object. + double baud_rate = 10000.0; // communication speed + 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(); + ResourceCalendar resCalendar = new ResourceCalendar(time_zone, + peakLoad, offPeakLoad, holidayLoad, weekends, + holidays, seed); + + ARTGridResource gridRes = null; + try { + gridRes = new ARTGridResource(name, baud_rate, resConfig, resCalendar, policy); + } + catch (Exception e) { + e.printStackTrace(); + } + + System.out.println("Creates one Grid resource with name = " + name); + return gridRes; + } +} // end class + Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java =================================================================== --- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-02-27 23:37:51 UTC (rev 136) +++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-02-28 04:11:36 UTC (rev 137) @@ -85,10 +85,10 @@ ////////////////////////////////////////// // Starts the simulation in debug mode - GridSim.startGridSimulation(true); +// GridSim.startGridSimulation(true); // Start the simulation in normal mode -// GridSim.startGridSimulation(); + GridSim.startGridSimulation(); ////////////////////////////////////////// // Final step: Prints the Gridlets when simulation is over Modified: branches/gridsim4.0-branch3/source/gridsim/GridResource.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-27 23:37:51 UTC (rev 136) +++ branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-28 04:11:36 UTC (rev 137) @@ -11,6 +11,7 @@ import gridsim.net.*; import gridsim.turbo.ARCBMultiplePartitions; +import gridsim.turbo.AREBMultiplePartitions; import gridsim.turbo.ARParallelSpaceShared; import gridsim.turbo.CBMultiplePartitions; import gridsim.turbo.EBParallelSpaceShared; @@ -662,6 +663,11 @@ "ARCBMultipleQueues", 1); break; + case TResourceCharacteristics.AREB_MULTI_PARTITIONS: + policy_ = new AREBMultiplePartitions(super.get_name(), + "AREBMultipleQueues", 1); + break; + default: throw new Exception(super.get_name()+" : Error - supports"+ " only TimeShared or SpaceShared policy."); Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-27 23:37:51 UTC (rev 136) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-28 04:11:36 UTC (rev 137) @@ -29,11 +29,7 @@ * other partition. * * We use an availability profile to store the availability of processing - * elements. In order to represent the pivots (i.e. the first jobs in the - * partitions), we schedule them creating the entries in the availability - * profile. This way, we do not need to store the pivots' start times - * (or shadow times) and extra nodes in different variables. It also makes - * the search for available resources for a new pivot easier. + * elements. * <p> * <b>LIMITATIONS:</b><br> * <ul> @@ -74,9 +70,9 @@ private double lastCheckExpiryTime_; /** - * Allocates a new <tt>CBMultipleQueues</tt> object. + * Allocates a new <tt>ARCBMultipleQueues</tt> object. * If the policy is create with only one partition, it will then work as - * a normal aggressive (EASY) backfilling scheduler. + * a conservative backfilling scheduler. * * @param resourceName the <tt>GridResource</tt> entity name that will * contain this allocation policy @@ -104,9 +100,9 @@ } /** - * Allocates a new <tt>CBMultipleQueues</tt> object. + * Allocates a new <tt>ARCBMultipleQueues</tt> object. * If the policy is create with only one partition, it will then work as - * a normal aggressive (EASY) backfilling scheduler. + * a conservative backfilling scheduler. * * @param resourceName the <tt>GridResource</tt> entity name that will * contain this allocation policy @@ -591,7 +587,7 @@ int itemsStarted = 0; // finishes the advance reservations first - itemsFinished = finishReservation(currentTime); + itemsFinished = finishReservations(currentTime); // then finishes the Gridlets whose start time is smaller // or equals to the current simulation time @@ -605,11 +601,11 @@ } // starts the advance reservations - itemsStarted = startReservation(currentTime); + itemsStarted = startReservations(currentTime); // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than current time - itemsStarted += super.backfillGridlets(currentTime); + itemsStarted += super.startQueuedGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- @@ -628,7 +624,7 @@ * equals to refTime will be completed * @return the number of reservations completed */ - protected int finishReservation(double refTime) { + protected int finishReservations(double refTime) { int reservationFinished = 0; Iterator<SSReservation> iterRes = reservTable_.values().iterator(); @@ -664,7 +660,7 @@ * @refTime the reservations whose start time is smaller * or equals to refTime will be started */ - protected int startReservation(double refTime) { + protected int startReservations(double refTime) { LinkedList<SSReservation> startedReservations = new LinkedList<SSReservation>(); int numStartedRes = 0; Added: branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java (rev 0) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/AREBMultiplePartitions.java 2008-02-28 04:11:36 UTC (rev 137) @@ -0,0 +1,1145 @@ +/* + * Title: GridSim Toolkit + * Description: GridSim (Grid Simulation) Toolkit for Modelling and Simulation + * of Parallel and Distributed Systems such as Clusters and Grids + * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + */ + +package gridsim.turbo; + +import eduni.simjava.Sim_event; +import gridsim.GridSim; +import gridsim.GridSimTags; +import gridsim.Gridlet; +import gridsim.IO_data; +import gridsim.gui.AllocationAction; + +import java.util.Calendar; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedList; + +/** + * This class implements a non-FCFS policy to schedule parallel jobs. The + * policy is based on easy backfilling and supports advance reservation. + * This policy can use multiple partitions or queues and the jobs can be + * directed to these partitions using a partition predicate + * ({@link QueuePartitionPredicate}. A partition can borrow resources from + * another when it requires and the resources are not being used by the + * other partition. + * + * We use an availability profile to store the availability of processing + * elements. In order to represent the pivots (i.e. the first jobs in the + * partitions), we schedule them creating the entries in the availability + * profile. This way, we do not need to store the pivots' start times + * (or shadow times) and extra nodes in different variables. It also makes + * the search for available resources for a new pivot easier. + * <p> + * <b>LIMITATIONS:</b><br> + * <ul> + * <li> The list of machines comprising this resource must be + * homogeneous. + * <li> Local load is not considered. If you would like to simulate this, + * you have to model the local load as gridlets. It is more precise + * and faster. To do so, please check {@link Lublin99Workload}. + * <li> Gridlets cannot be paused nor migrated. + * </ul> + * + * @see gridsim.GridSim + * @see gridsim.ResourceCharacteristics + * @see gridsim.turbo.TAllocPolicy + * @see gridsim.turbo.EBMultiplePartitions + * @see gridsim.turbo.QueuePartitionPredicate + * @see gridsim.turbo.PERange + * @see gridsim.turbo.PERangeList + */ + +public class AREBMultiplePartitions extends + EBMultiplePartitions implements ARTPolicy { + + // a new reservation table + private LinkedHashMap<Integer, SSReservation> reservTable_; + + // a table that contains expired reservations + private LinkedHashMap<Integer, SSReservation> expiryTable_; + + // default booking/reservation commit period + private int commitPeriod_; + + // internal event tags used by this gridlet + // a tag to denote expiry time + private final int EXPIRY_TIME = 12; + + // last time the expiration of reservations was checked + private double lastCheckExpiryTime_; + + /** + * Allocates a new <tt>AREBMultiplePartitions</tt> object. + * If the policy is create with only one partition, it will then work as + * a normal aggressive (EASY) backfilling scheduler. + * + * @param resourceName the <tt>GridResource</tt> entity name that will + * contain this allocation policy + * @param entityName this object entity name + * @param numPartitions The number of partitions of the scheduling queue + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> Creating this entity before initialising GridSim package + * <li> The entity name is <tt>null</tt> or empty + * <li> The entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs, which means that the Gridlets cannot be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean, + * String[], String[], String) + */ + public AREBMultiplePartitions(String resourceName, + String entityName, int numPartitions) throws Exception { + super(resourceName, entityName, numPartitions); + commitPeriod_ = 30*60; // set the expiration time into 30 mins + init(); + } + + /** + * Allocates a new <tt>AREBMultiplePartitions</tt> object. + * If the policy is create with only one partition, it will then work as + * a normal aggressive (EASY) backfilling scheduler. + * + * @param resourceName the <tt>GridResource</tt> entity name that will + * contain this allocation policy + * @param entityName this object entity name + * @param numPartitions The number of partitions of the scheduling queue + * @param commitPeriod a default commit period time for a user to commit + * a reservation (unit is in second). <b>NOTE:</b> once it is set, you cannot + * change the time again. + * @throws Exception This happens when one of the following scenarios occur: + * <ul> + * <li> Creating this entity before initialising GridSim package + * <li> The entity name is <tt>null</tt> or empty + * <li> The entity has <tt>zero</tt> number of PEs (Processing + * Elements). <br> + * No PEs, which means that the Gridlets cannot be processed. + * A GridResource must contain one or more Machines. + * A Machine must contain one or more PEs. + * </ul> + * + * @see gridsim.GridSim#init(int, Calendar, boolean, + * String[], String[], String) + */ + public AREBMultiplePartitions(String resourceName, + String entityName, int numPartitions, + int commitPeriod) throws Exception { + super(resourceName, entityName, numPartitions); + if (commitPeriod <= 0) { + throw new Exception(resourceName + "." + entityName + + ": Error - Invalid expiry time."); + } + commitPeriod_ = commitPeriod; + init(); + } + + /** + * Handles internal events that come to this entity. + */ + public void body() { + super.body(); + reservTable_.clear(); + expiryTable_.clear(); + lastCheckExpiryTime_ = 0.0D; + } + + // -------------------- GRIDLET RELATED METHODS --------------------- + + /** + * Schedules a new <tt>Gridlet</tt> received by the <tt>GridResource</tt> entity. + * @param gridlet a Gridlet object to be executed + * @param ack an acknowledgement, i.e. <tt>true</tt> if the + * user wants to know whether this operation is successful + * or not, <tt>false</tt> otherwise. + */ + public void gridletSubmit(Gridlet gridlet, boolean ack) { + if(!gridlet.hasReserved()) { + super.gridletSubmit(gridlet, ack); + } + else { + handleReservationGridlet(gridlet, ack); + } + } + + /** + * Schedules a new Gridlet received by the <tt>ARTGridResource</tt> + * entity and for which an advance reservation has been made. + * @param gridlet a Gridlet object to be executed + * @param ack an acknowledgement, i.e. <tt>true</tt> if the + * user wants to know whether this operation is successful + * or not, <tt>false</tt> otherwise. + */ + private void handleReservationGridlet(Gridlet gridlet, boolean ack) { + + double currentTime = GridSim.clock(); + + int freePE; + int reqPE = gridlet.getNumPE(); + // gets the advance reservation + SSReservation sRes = reservTable_.get(gridlet.getReservationID()); + + // create an SSGridlet + SSGridlet sgl = new SSGridlet(gridlet); + + // forecast the execution time of the gridlet + double executionTime = + super.forecastExecutionTime(ratingPE_, sgl.getLength()); + + /////////////// FOR DEBUGGING PURPOSES ONLY //////// + + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_ARRIVED, true, sgl); + + ///////////////////////////////////////////////////// + + boolean success = true; + if(sRes == null) { + String userName = GridSim.getEntityName( gridlet.getUserID() ); + System.out.println(super.get_name() + ".gridletSubmit(): " + + " Gridlet #" + gridlet.getGridletID() + " from " + + userName + " cannot be accepted because the reservation #" + + gridlet.getReservationID() + " has not been found."); + success = false; + } + // check if the gridlet is requiring more PEs than what + // the reservation currently has + else if( (freePE = sRes.getNumRemainingPE()) < reqPE ) { + String userName = GridSim.getEntityName( gridlet.getUserID() ); + System.out.println(super.get_name() + ".gridletSubmit(): " + + " Gridlet #" + gridlet.getGridletID() + " from " + + userName + " cannot be accepted because the reservation #" + + sRes.getID() + " has only " + freePE + " PEs."); + success = false; + } + // check whether the gridlet is expected to run for longer than + // the time previously reserved + else if (executionTime >= sRes.getDurationTime()) { + String userName = GridSim.getEntityName( gridlet.getUserID() ); + System.out.println(super.get_name() + ".gridletSubmit(): " + + " Gridlet #" + gridlet.getGridletID() + " from " + + userName + " cannot be accepted because the reservation #" + + sRes.getID() + " is for " + sRes.getDurationTime() + + " while the gridlet is expected to run for " + + executionTime + " seconds."); + success = false; + } + + if(!success) { + try { + gridlet.setGridletStatus(Gridlet.FAILED); + super.sendFinishGridlet(gridlet); + return; + } + catch(Exception ex){ + System.out.println(super.get_name() + + ": Exception on submission of a Gridlet. Message = " + + ex.getMessage()); + return; + } + } + else { + // selects a list of ranges for the gridlet from the PEs available + // for the reservation + PERangeList selected = null; + success = ( ( selected = sRes.selectPERangeList(reqPE) ) != null ); + + sgl.setPERangeList(selected); + double resStartTime = sRes.getStartTime(); + sgl.setStartTime(resStartTime); + sgl.setActualFinishTime(resStartTime + executionTime); + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + + // if the reservation has not been committed, then commit the + // reservation + if (sRes.getStatus() == Reservation.STATUS_NOT_COMMITTED) { + sRes.setStatus(Reservation.STATUS_COMMITTED); + super.sendInternalEvent(resStartTime - currentTime, + CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); + } + // if the reservation has already started, then update the + // schedule, which will force the gridlets in the queue to + // be started + else if(sRes.getStatus() == Reservation.STATUS_IN_PROGRESS) { + super.sendInternalEvent(resStartTime - currentTime, + CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); + } + } + + //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- + + // Notifies the listeners that a Gridlet has been either scheduled + // to run immediately or put in the waiting queue + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, true, sgl); + + //--------------------------------------------------------------- + + // sends back an ack if required + if (ack == true) { + super.sendAck(GridSimTags.GRIDLET_SUBMIT_ACK, true, + gridlet.getGridletID(), gridlet.getUserID() + ); + } + } + + //---------------- RESERVATION RELATED PUBLIC METHODS --------------------- + + /** + * Handles an advance reservation request.<br> + * @param message the advance reservation message received + * @pre message != null + */ + public void handleCreateReservation(ARMessage message) { + double currentTime = GridSim.clock(); + + // gets the reservation object and extract some + // information from it + Reservation reservation = message.getReservation(); + double startTime = reservation.getStartTime(); + int duration = reservation.getDurationTime(); + int reqPE = reservation.getNumPE(); + + // creates a Server Side Reservation (i.e. SSReservation) + SSReservation sRes = new SSReservation(reservation); + sRes.setPartitionID(profile_.getCorrespondingPartitionID(sRes)); + double expTime = Double.NaN; + + // creates a response message to be sent to the requester + ARMessage response = message.createResponse(); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + // informs the listeners that a reservation request has arrived + GridSim.notifyListeners(this.get_id(), + AllocationAction.ITEM_ARRIVED, true, sRes); + + //---------------------------------------------------------- + + if (reqPE > super.totalPE_) { + String userName = GridSim.getEntityName( message.getSourceID() ); + System.out.println(super.get_name() + ".handleCreateReservation():" + + " Reservation #" + reservation.getID() + " from " + + userName + " user requires " + reservation.getNumPE() + + " PEs from " + startTime + " to " + (startTime + duration)); + System.out.println("--> The resource has only " + + super.totalPE_ + " PEs available."); + + reservation.setStatus(Reservation.STATUS_FAILED); + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return; + } + + boolean success = true; + + // if start time is 0, then it is an immediate reservation + if(startTime == 0 || startTime == currentTime) { + success = handleImmediateReservation(sRes); + expTime = sRes.getActualFinishTime(); + } + else { + success = handleAdvanceReservation(sRes); + expTime = currentTime + commitPeriod_; + } + + if(!success) { + String userName = GridSim.getEntityName( message.getSourceID() ); + System.out.println(super.get_name() + ".handleCreateReservation():" + + " Reservation #" + reservation.getID() + " from " + + userName + " user requires " + reservation.getNumPE() + + " PEs from " + startTime + " to " + (startTime + duration)); + System.out.println("--> The resource could not handle the reservation."); + + reservation.setStatus(Reservation.STATUS_FAILED); + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return; + } + + // if the expiration time is greater than the start time of the + // reservation, then set the expiration time as the start time + if(expTime > startTime) { + expTime = startTime; + } + + // if the start time of the reservation is equals to the current + // time, meaning that it is an immediate reservation, then start + // the reservation straight away. Therefore, sets the status to + // committed and sends an internal event to start the reservation + if(currentTime == startTime) { + sRes.setStatus(Reservation.STATUS_COMMITTED); + super.sendInternalEvent(GridSimTags.SCHEDULE_NOW, + CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); + } + else { + sRes.setStatus(Reservation.STATUS_NOT_COMMITTED); + } + + sRes.setExpiryTime(expTime); + + // add the reservation into the reservation table and sends the + // response message to the requester + reservTable_.put(new Integer(sRes.getID()), sRes); + sendARMessage(response); + + // then send this into itself to check for expired reservations + super.sendInternalEvent(expTime - currentTime, + EXPIRY_TIME); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + // Informs the listeners about the reservation that has been created + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_SCHEDULED, + true, sRes); + } + + /** + * Handles a commit reservation request. + * @param message the advance reservation message received + */ + public void handleCommitReservation(ARMessage message) { + + // gets the reservation id of the message + int reservationId = message.getReservationID(); + SSReservation sRes = null; + + // creates a response message to be sent to the requester + ARMessage response = message.createResponse(); + boolean success = true; + + // Tries to find the reservation in the lists + if(reservTable_.containsKey(reservationId)) { + sRes = reservTable_.get(reservationId); + } + else if(expiryTable_.containsKey(reservationId)) { + sRes = expiryTable_.get(reservationId); + switch(sRes.getStatus()) { + case Reservation.STATUS_CANCELLED: + System.out.println(super.get_name() + ".handleCommitReservation()" + + " Reservation # " + reservationId + + " cannot be committed because it has" + + " previously been cancelled by the allocation policy."); + break; + case Reservation.STATUS_FINISHED: + System.out.println(super.get_name() + ".handleCommitReservation()" + + " Reservation # " + reservationId + + " cannot be committed because it has finished."); + break; + default: + System.out.println(super.get_name() + ".handleCommitReservation()" + + " Reservation # " + reservationId + + " cannot be committed because it is in the expiry list."); + break; + } + success = false; + } + else { + System.out.println(super.get_name() + ".handleCommitReservation() " + + "Reservation # " + reservationId + " cannot be committed "+ + "because the allocation policy could not find it."); + success = false; + } + + // if there was no success, then sets the error code to failure and + // sends the message back to the requester + if(!success) { + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + sendARMessage(response); + return; + } + + // sets the reservation to committed if it has not been set before + if(sRes.getStatus() == Reservation.STATUS_NOT_COMMITTED) { + sRes.setStatus(Reservation.STATUS_COMMITTED); + + // then send this into itself to start the reservation + super.sendInternalEvent(sRes.getStartTime() - GridSim.clock(), + CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); + } + + // sends the response message with no error + sendARMessage(response); + + //-------------- FOR DEBUGGING PURPOSES ONLY -------------- + + GridSim.notifyListeners(this.get_id(), + AllocationAction.ITEM_STATUS_CHANGED, true, sRes); + + //---------------------------------------------------------- + } + + /** + * Handles a modify reservation request<br> + * (NOTE: <b>NOT SUPPORTED YET</b>). + * @param message the advance reservation message received. + */ + public void handleModifyReservation(ARMessage message) { + System.out.println(super.get_name() + + ".handleModifyReservation(): not supported at the moment."); + } + + /** + * Handles a cancel reservation request<br> + * (NOTE: <b>NOT SUPPORTED YET</b>). + * @param message the advance reservation message received. + */ + public void handleCancelReservation(ARMessage message) { + System.out.println(super.get_name() + + ".handleCancelReservation(): not supported at the moment."); + } + + /** + * Handles a query free time request. + * @param message the advance reservation message received. + */ + public void handleQueryAvailability(ARMessage message) { +// // gets the reservation id of the message +// Reservation reservation = message.getReservation(); +// +// // creates a response message to be sent to the requester +// ARMessage response = message.createResponse(); +// +// // gets the start time and finish time the user is interested in +// double startTime = reservation.getStartTime(); +// int duration = reservation.getDurationTime(); +// +// // gets the availability information from the availability profile +// AvailabilityInfo availability = getAvailabilityInfo(startTime, duration); +// +// // sets the options as the availability over the requested period +// response.getReservation().setReservationOptions(availability); +// +// // Sends the response back to the user +// sendARMessage(response); + } + + /** + * Handles a query reservation request. + * @param message the advance reservation message received. + */ + public void handleQueryReservation(ARMessage message) { + + // gets the reservation id of the message + int reservationId = message.getReservationID(); + + // creates a response message to be sent to the requester + ARMessage response = message.createResponse(); + + // Tries to find the reservation in the lists + if(!reservTable_.containsKey(reservationId) + && !expiryTable_.containsKey(reservationId) ) { + System.out.println(super.get_name() + ".handleQueryReservation()" + + " Error querying the status of reservation # " + reservationId + + " because Grid Resource #" + super.resId_ + + " could not find it."); + response.setErrorCode(ARMessage.EC_OPERATION_FAILURE); + } + + // Just sends the message because the reply has a reference to + // the reservation object, which contains the status of the reservation + sendARMessage(response); + } + + /** + * Process and event sent to this entity + * @param ev the event to be handled + */ + public void processOtherEvent(Sim_event ev) { + + // handle an internal event + double currentTime = GridSim.clock(); + + if(ev.get_src() == myId_) { + switch(ev.get_tag()) { + + // checks the expiry time for a given gridlet + case EXPIRY_TIME: + if(currentTime > lastCheckExpiryTime_) { + checkExpiryTime(); + } + lastCheckExpiryTime_ = currentTime; + break; + + default: + super.processOtherEvent(ev); + break; + } + } + else + super.processOtherEvent(ev); + } + + // --------------------- PROTECTED METHODS ----------------------- + + /** + * This method is called to update the schedule. It removes completed + * gridlets and return them to the users and verifies whether there are + * gridlets in the waiting list that should start execution. It also + * removes old entries from the availability profile. + */ + protected void updateSchedule() { + + int itemsFinished = 0; + double currentTime = GridSim.clock(); + int itemsStarted = 0; + + // finishes the advance reservations first + itemsFinished = finishReservations(currentTime); + + // then finishes the Gridlets whose start time is smaller + // or equals to the current simulation time + itemsFinished += super.finishRunningGridlets(currentTime); + + // remove past entries from the availability profile + MPProfileEntry currentStatus = profile_.removePastEntries(currentTime); + if(currentStatus != null) { + profile_.setCurrentStatus(currentStatus); + resource_.resetFreePERanges(currentStatus.getPERanges()); + } + + // starts the advance reservations + itemsStarted = startReservations(currentTime); + + // Start the execution of Gridlets that are queued and whose + // potential start execution time is smaller than current time + itemsStarted += backfillGridlets(currentTime); + + //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- + + // If a gridlet has started execution or one has finished, + // then inform the listeners + if(itemsStarted > 0 || itemsFinished > 0){ + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + } + } + + /** + * This method is called to finish a reservation and consequently update + * the availability profile. + * @param refTime the time reference to check what reservations should + * be finished. All reservations whose finish time is smaller or + * equals to refTime will be completed + * @return the number of reservations completed + */ + protected int finishReservations(double refTime) { + int reservationFinished = 0; + + Iterator<SSReservation> iterRes = reservTable_.values().iterator(); + while(iterRes.hasNext()) { + SSReservation sRes = iterRes.next(); + if(sRes.getActualFinishTime() <= refTime) { + // Finish the reservation and include ranges in the + // list of ranges to be released + sRes.setStatus(Reservation.STATUS_FINISHED); + reservationFinished++; + iterRes.remove(); + expiryTable_.put(sRes.getID(), sRes); + } + } + + if(reservationFinished > 0) { + + //------------- USED FOR DEBUGGING PURPOSES ONLY ------------------ + + // If a gridlet has started execution or one has finished, + // then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //----------------------------------------------------------------- + } + + return reservationFinished; + } + + /** + * This method is called to start a reservation and consequently update + * the availability profile. + * @refTime the reservations whose start time is smaller + * or equals to refTime will be started + */ + protected int startReservations(double refTime) { + LinkedList<SSReservation> startedReservations = new LinkedList<SSReservation>(); + int numStartedRes = 0; + + Iterator<SSReservation> iterRes = reservTable_.values().iterator(); + while(iterRes.hasNext()) { + SSReservation sRes = iterRes.next(); + + if(sRes.getStartTime() <= refTime && + sRes.getStatus() == Reservation.STATUS_COMMITTED) { + + // Start the reservation and update the ranges of + // PEs currently available + sRes.setStatus(Reservation.STATUS_IN_PROGRESS); + + startedReservations.add(sRes); + + super.sendInternalEvent(sRes.getActualFinishTime()-refTime, + CBParallelSpaceShared.UPDATE_SCHEDULE_TAG); + + numStartedRes++; + } + } + return numStartedRes; + } + + /** + * This method returns a list that corresponds to the free time slots + * in the scheduling queue managed by this scheduler or + * resource allocation policy. + * + * @param startTime the start time in which the requester is interested. + * @param duration the duration in which the requester is interested. + * @return the list of free time slots. The list is actually a list of + * entries that correspond to the availability profile between the times + * specified by the requester. + */ + protected AvailabilityInfo getAvailabilityInfo(double startTime, int duration) { + + AvailabilityInfo list = new AvailabilityInfo(); + int anchorIndex = -1; + double currentTime = GridSim.clock(); + + // if the user specified the start time as 0, it means that the + // user is interested to know the availability starting from the + // current time, or the time when the resource received this request + if(startTime == 0) { + startTime = currentTime; + } + + list.setStartTime(startTime); + + // calculate the reservation's finish time + double finishTime = startTime + duration; + list.setFinishTime(finishTime); + + // a pointer to the anchor entry (described above) + MPProfileEntry anchorEntry = null; + int length = profile_.size(); + AvailabilityInfoEntry firstEntry = null; + + anchorEntry = (startTime <= currentTime) ? null : + profile_.getPrecedingEntry(startTime); + + // if the entry is null, then it means that the reservation is + // before the first entry of the profile, so the intersection list + // has to start with the ranges of PEs currently available + if (anchorEntry == null) { + PERangeList peList = (resource_.getFreePERanges() == null) ? + new PERangeList() : resource_.getFreePERanges().clone(); + firstEntry = + new AvailabilityInfoEntry(startTime, peList); + } + else { + PERangeList newList = anchorEntry.getPERanges(); + newList = (newList != null) ? newList.clone() : new PERangeList(); + firstEntry = new AvailabilityInfoEntry(startTime, newList); + anchorIndex = profile_.indexOf(anchorEntry); + } + + list.add(firstEntry); + AvailabilityInfoEntry previousEntry = firstEntry; + + // Iterates the availability profile and adds all the entries + // whose times are between start and finish time in the list + // to be returned. It removes repeated entries. + for(int i=anchorIndex+1; i<length; i++) { + MPProfileEntry nextEntry = profile_.get(i); + if(nextEntry.getTime() <= startTime) + continue; + if(nextEntry.getTime() > finishTime){ + break; + } + else { + PERangeList peList = nextEntry.getPERanges(); + peList = (peList != null) ? peList.clone() : new PERangeList(); + + if( !previousEntry.getAvailRanges().equals(peList)) { + AvailabilityInfoEntry tsEntry = + new AvailabilityInfoEntry(nextEntry.getTime(), peList); + list.add(tsEntry); + previousEntry = tsEntry; + } + } + } + + return list; + } + + /** + * This method returns a list that corresponds to the free time slots + * in the scheduling queue managed by this scheduler or + * resource allocation policy. This returns the resources available + * for a given partition. + * @param queueId the id of the partition whose availability is to be queried. + * @param startTime the start time in which the requester is interested. + * @param duration the duration in which the requester is interested. + * @return the list of free time slots. The list is actually a list of + * entries that correspond to the availability profile between the times + * specified by the requester. + */ + protected AvailabilityInfo getAvailabilityInfo(int queueId, + double startTime, int duration) { + + AvailabilityInfo list = new AvailabilityInfo(); + int anchorIndex = -1; + double currentTime = GridSim.clock(); + QueuePartition partition = profile_.getPartition(queueId); + + // if the user specified the start time as 0, it means that the + // user is interested to know the availability starting from the + // current time, or the time when the resource received this request + if(startTime == 0) { + startTime = currentTime; + } + + list.setStartTime(startTime); + + // calculate the reservation's finish time + double finishTime = startTime + duration; + list.setFinishTime(finishTime); + + // a pointer to the anchor entry (described above) + MPProfileEntry anchorEntry = null; + int length = profile_.size(); + AvailabilityInfoEntry firstEntry = null; + + anchorEntry = (startTime <= currentTime) ? null : + profile_.getPrecedingEntry(startTime); + + // if the entry is null, then it means that the reservation is + // before the first entry of the profile, so the intersection list + // has to start with the ranges of PEs currently available + if (anchorEntry == null) { + PERangeList peList = (partition.getIdlePERanges() == null) ? + new PERangeList() : partition.getIdlePERanges().clone(); + firstEntry = + new AvailabilityInfoEntry(startTime, peList); + } + else { + PERangeList newList = anchorEntry.getPERanges(queueId); + newList = (newList != null) ? newList.clone() : new PERangeList(); + firstEntry = new AvailabilityInfoEntry(startTime, newList); + anchorIndex = profile_.indexOf(anchorEntry); + } + + list.add(firstEntry); + AvailabilityInfoEntry previousEntry = firstEntry; + + // Iterates the availability profile and adds all the entries + // whose times are between start and finish time in the list + // to be returned. It removes repeated entries. + for(int i=anchorIndex+1; i<length; i++) { + MPProfileEntry nextEntry = profile_.get(i); + if(nextEntry.getTime() <= startTime) + continue; + if(nextEntry.getTime() > finishTime){ + break; + } + else { + PERangeList peList = nextEntry.getPERanges(queueId); + peList = (peList != null) ? peList.clone() : new PERangeList(); + + if( !previousEntry.getAvailRanges().equals(peList)) { + AvailabilityInfoEntry tsEntry = + new AvailabilityInfoEntry(nextEntry.getTime(), peList); + list.add(tsEntry); + previousEntry = tsEntry; + } + } + } + + return list; + } + + /** + * Sends a reservation message. + * @param message the message to be sent + */ + protected void sendARMessage(ARMessage message) { + // send message to the destination + super.sim_schedule(super.outputPort_, GridSimTags.SCHEDULE_NOW, + message.getMessageType(), new IO_data(message, + message.getMessageSize(), message.getDestinationID())); + } + + // ------------------------- PRIVATE MTHODS ---------------------- + + /** + * Checks for expiry time of a given reservations in the list. + * @param reservation the reservation to be checked + */ + private void checkExpiryTime() { + + double currentTime = GridSim.clock(); // get current time + + // gridlets whose start time is larger than reference time + // will be shifted forwards when the compression of the + // schedule takes place + double referenceTime = Double.MAX_VALUE; + LinkedList<SSReservation> removedRes = new LinkedList<SSReservation>(); + + Iterator<SSReservation> iterRes = reservTable_.values().iterator(); + while(iterRes.hasNext()) { + SSReservation sRes = iterRes.next(); + int status = sRes.getStatus(); + + // check for expiry time + if (status == Reservation.STATUS_NOT_COMMITTED && + sRes.getExpiryTime() <= currentTime) { + System.out.println(super.get_name() + ".checkExpiryTime(): " + + "Reservation # " + sRes.getID() + " has not been " + + "committed and has hence been cancelled at time #" + currentTime); + + // update the profile (i.e. removes/updates entries at the profile) + removeReservation(sRes); + + sRes.setStatus(Reservation.STATUS_CANCELLED); + expiryTable_.put(sRes.getID(), sRes); + iterRes.remove(); + + if(sRes.getStartTime() < referenceTime) { + referenceTime = sRes.getStartTime(); + } + removedRes.add(sRes); + } + } + + if(removedRes.size() > 0) { + + //-------------- USED FOR DEBUGGING PURPOSES ONLY ----------------- + + // If a gridlet has been cancelled, then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, true, removedRes); + + //----------------------------------------------------------------- + + // backfills Gridlets to fill the fragment created by the + // cancellation of the advance reservation + super.backfillGridlets(currentTime); +// super.compressSchedule(referenceTime, false); + + //---------------- USED FOR DEBUGGING PURPOSES ONLY ---------------- + + // If a gridlet has started execution or one has finished, + // then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.SCHEDULE_CHANGED, true); + + //----------------------------------------------------------------- + } + } + + /** + * This method removes/updates all the entries of a reservation from + * the profile and updates the ranges of current free PEs if the + * reservation was in execution. + * @param reservation the Reservation to be removed + */ + private void removeReservation(SSReservation reservation) { + // check whether the reservation is in progress + boolean inProgress = reservation.getStatus() == Reservation.STATUS_IN_PROGRESS; + + // removes the reservation from the profile + profile_.updateEntriesAtProfile(reservation); + + // removes from the queue all gridlets that are associated to the + // advance reservation. This iterates the lists and removes the + // gridlets that have this reservation has their reservation ID + int reservationId = reservation.getID(); + LinkedList<SSGridlet> removedGridlets = new LinkedList<SSGridlet>(); + + Iterator<SSGridlet> iterGrl = + inProgress ? runningGridlets_.iterator() : queuedGridlets_.iterator(); + + while(iterGrl.hasNext()) { + SSGridlet gridlet = iterGrl.next(); + if(gridlet.getReservationID() == reservationId + && gridlet.getStatus() != Gridlet.SUCCESS + && gridlet.getStatus() != Gridlet.FAILED) { + + gridlet.setStatus(Gridlet.CANCELED); + gridlet.finalizeGridlet(); + super.sendFinishGridlet(gridlet.getGridlet()); + + removedGridlets.add(gridlet); + iterGrl.remove(); + } + } + + // notifies the listener that the gridlets have been cancelled + if(removedGridlets.size() > 0) { + + //---------------- USED FOR DEBUGGING PURPOSES ONLY ---------------- + + // If a gridlet has been cancelled, then inform the listeners + GridSim.notifyListeners(this.get_id(), AllocationAction.ITEM_CANCELLED, + false, removedGridlets); + + //------------------------------------------------------------------ + } + } + + /* + * Handles an immediate reservation + * @return true if the reservation was successful + */ + private boolean handleImmediateReservation(SSReservation res) { + double startTime = GridSim.clock(); + res.setStartTime(startTime); + + int duration = res.getDurationTime(); + int reqPE = res.getNumPE(); + int queueId = res.getPartitionID(); + + // check the start time against the availability. That is, + // check if there are enough PEs currently free and + // whether they will be available until the termination + // of the advance reservation + PERangeList ranges = profile_.getImmediateAvailability(queueId, duration); + + // if there are resource available in the queue, then allocate it + if(ranges.getNumPE() >= reqPE) { + // gets the list of PEs selected for the reservation + PERangeList selected = super.selectPERangeList(reqPE, ranges); + + // allocates the list of PEs to the reservation + res.setPERangeList(selected); + + // updates the availability profile accordingly + profile_.allocateImmediateRanges(queueId, startTime + duration, selected); + } + // Tries all the queues + else { + + // gets all available PEs during given time interval + PERangeList overallAvailPEs = + profile_.getImmediateAvailability(duration); + + if(overallAvailPEs.getNumPE() < reqPE) + return false; + + // removes PEs already obtained from selected partition + PERangeList addRanges = + PERangeList.difference(overallAvailPEs, ranges); + + // additional PEs required + int addRequired = reqPE - ranges.getNumPE(); + + if(addRanges != null && addRanges.getNumPE() >= addRequired) { + // borrows the additional PEs required from the partitions + // and adds them into the specified queue + addRanges = super.selectPERangeList(addRequired, addRanges); + profile_.transferPEs(queueId, addRanges, startTime, startTime + duration); + + // allocates the ranges to the gridlet + ranges.addAll(addRanges); + profile_.allocateImmediateRanges(queueId, startTime + duration, ranges); + res.setPERangeList(ranges); + } + else { + return false; + } + } + return true; + } + + /* + * Handles an advance reservation + * @return true if the reservation was successful + */ + private boolean handleAdvanceReservation(SSReservation res) { + + double startTime = res.getStartTime(); + int duration = res.getDurationTime(); + int reqPE = res.getNumPE(); + int queueId = res.getPartitionID(); + + // check whether there are PEs available over the time + // frame requested + Object[] availObjQueue = + ... [truncated message content] |
From: <mar...@us...> - 2008-02-27 23:37:47
|
Revision: 136 http://gridsim.svn.sourceforge.net/gridsim/?rev=136&view=rev Author: marcos_dias Date: 2008-02-27 15:37:51 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Small changes in the allocation policies. They do not affect any simulation results obtained with the previous versions. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/GridSim.java Modified: branches/gridsim4.0-branch3/source/gridsim/GridSim.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-02-27 23:36:05 UTC (rev 135) +++ branches/gridsim4.0-branch3/source/gridsim/GridSim.java 2008-02-27 23:37:51 UTC (rev 136) @@ -806,7 +806,7 @@ public static void smallPause(){ Sim_system.pauseSimulation(); try { - Thread.currentThread().sleep(500); + Thread.currentThread().sleep(300); } catch (InterruptedException e) { System.out.println("GridSim.smallPause() :" + " Exception while making small pause in the simulation."); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-27 23:36:08
|
Revision: 135 http://gridsim.svn.sourceforge.net/gridsim/?rev=135&view=rev Author: marcos_dias Date: 2008-02-27 15:36:05 -0800 (Wed, 27 Feb 2008) Log Message: ----------- Small changes in the allocation policies. They do not affect any simulation results obtained with the previous versions. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/Accumulator.java branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java Modified: branches/gridsim4.0-branch3/source/gridsim/Accumulator.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/Accumulator.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/Accumulator.java 2008-02-27 23:36:05 UTC (rev 135) @@ -4,7 +4,6 @@ * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html * - * $Id: Accumulator.java,v 1.2 2007/11/05 06:33:29 marcosd Exp $ */ package gridsim; @@ -94,70 +93,158 @@ /** * Calculates the mean of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMean()} * @return the mean of accumalated items * @pre $none * @post $none */ + public double mean() { + return this.getMean(); + } + + /** + * Calculates the mean of accumulated items + * @return the mean of accumalated items + * @pre $none + * @post $none + */ public double getMean() { return mean_; } /** * Calculates the standard deviation of accumulated items + * @deprecated As of GridSim 2.1, replaced by + * {@link #getStandardDeviation()} * @return the Standard Deviation of accumulated items * @pre $none * @post $none */ + public double sd() { + return this.getStandardDeviation(); + } + + /** + * Calculates the standard deviation of accumulated items + * @return the Standard Deviation of accumulated items + * @pre $none + * @post $none + */ public double getStandardDeviation() { - return sqrMean_ - (mean_ * mean_); + return Math.sqrt( this.getVariance() ); } /** + * Calculates the variance of accumulated items + * @return the Standard Deviation of accumulated items + * @pre $none + * @post $none + */ + public double getVariance() { + return sqrMean_ - (mean_ * mean_); + } + + /** * Finds the smallest number of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMin()} * @return the smallest of accumulated items * @pre $none * @post $none */ + public double min() { + return this.getMin(); + } + + /** + * Finds the smallest number of accumulated items + * @return the smallest of accumulated items + * @pre $none + * @post $none + */ public double getMin() { return min_; } /** * Finds the largest number of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getMax()} * @return the largest of accumulated items * @pre $none * @post $none */ + public double max() { + return this.getMax(); + } + + /** + * Finds the largest number of accumulated items + * @return the largest of accumulated items + * @pre $none + * @post $none + */ public double getMax() { return max_; } /** * Finds the last accumulated item + * @deprecated As of GridSim 2.1, replaced by {@link #getLast()} * @return the last accumulated item * @pre $none * @post $none */ + public double last() { + return this.getLast(); + } + + /** + * Finds the last accumulated item + * @return the last accumulated item + * @pre $none + * @post $none + */ public double getLast() { return last_; } /** * Counts the number of items accumulated so far + * @deprecated As of GridSim 2.1, replaced by {@link #getCount()} * @return the number of items accumulated so far * @pre $none * @post $result >= 0 */ + public int count() { + return this.getCount(); + } + + /** + * Counts the number of items accumulated so far + * @return the number of items accumulated so far + * @pre $none + * @post $result >= 0 + */ public int getCount() { return n_; } /** * Calculates the sum of accumulated items + * @deprecated As of GridSim 2.1, replaced by {@link #getSum()} * @return the sum of accumulated items * @pre $none * @post $none */ + public double sum() { + return this.getSum(); + } + + /** + * Calculates the sum of accumulated items + * @return the sum of accumulated items + * @pre $none + * @post $none + */ public double getSum() { return n_ * mean_; } @@ -165,9 +252,20 @@ /** * Determines the size of Accumulator object * @return the size of this object + * @deprecated As of GridSim 2.1, replaced by {@link #getByteSize()} * @pre $none * @post $result > 0 */ + public static int ByteSize() { + return getByteSize(); + } + + /** + * Determines the size of Accumulator object + * @return the size of this object + * @pre $none + * @post $result > 0 + */ public static int getByteSize() { int totalInt = 4; // contains only 1 int Modified: branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/AllocPolicy.java 2008-02-27 23:36:05 UTC (rev 135) @@ -419,7 +419,7 @@ /** * Calculates the current load of a GridResource for a given number of * Gridlets currently in execution. This method can be overridden by - * child class, if the below algorithm doesn't suitable for a particular + * child class, if the below algorithm isn't suitable for a particular * type of scheduling: * <code> * <br> <br> Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -609,7 +609,7 @@ // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than current time - itemsStarted += super.startQueuedGridlets(currentTime); + itemsStarted += super.backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -371,7 +371,7 @@ * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // Start the execution of Gridlets that are queued and whose Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-27 23:36:05 UTC (rev 135) @@ -177,7 +177,14 @@ Sim_event ev = new Sim_event(); while ( Sim_system.running() ) { super.sim_get_next(ev); - processEvent(ev); + + // if the simulation finishes then exit the loop + if (ev.get_tag() == GridSimTags.END_OF_SIMULATION || + super.isEndSimulation() == true) { + break; + } + + processEvent(ev); } // CHECK for ANY INTERNAL EVENTS WAITING TO BE PROCESSED Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-27 23:36:05 UTC (rev 135) @@ -331,19 +331,13 @@ } sgl.setPartitionID(queueId); - - // If there are no jobs in the queue list, then check if - // there are enough PEs to process the job immediately - boolean success = startGridlet(sgl); - // if the job could not be scheduled immediately, then enqueue it - if(!success) { - scheduleGridlet(sgl); - queuedGridlets_.add(sgl); - - // order gridlets according to their priorities - Collections.sort(queuedGridlets_, orderByPriority_); - } + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + + // order gridlets according to their priorities + Collections.sort(queuedGridlets_, orderByPriority_); + backfillGridlets(GridSim.clock()); //------------------ FOR DEBUGGING PURPOSES ONLY ---------------- @@ -666,7 +660,7 @@ sgl.setPERangeList(ranges); // change Gridlet status - sgl.setStatus(Gridlet.QUEUED); +// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); @@ -742,7 +736,7 @@ // Start the execution of Gridlets that are queued and whose // potential start execution time is smaller than current time - itemsStarted = startQueuedGridlets(currentTime); + itemsStarted = backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- @@ -781,13 +775,14 @@ } /** - * This method starts gridlets that are in the queue and - * whose start time is smaller than the reference time and updates - * the availability profile and ranges of PEs currently available accordingly + * This method starts/backfills that are in the queue and pivots (first jobs + * in the partitions) whose start time is smaller than the reference time + * and updates the availability profile and ranges of PEs + * currently available accordingly * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // first checks whether the pivots can be started Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-26 04:57:09 UTC (rev 134) +++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-27 23:36:05 UTC (rev 135) @@ -217,21 +217,9 @@ //---------------------------------------------------------- - // If there are no jobs in the queue list, then check if - // there are enough PEs to process the job immediately - boolean success = false; - int freePE = super.resource_.getNumFreePE(); - - if( reqPE <= freePE ) { - success = startGridlet(sgl); - } - - // if the job could not be scheduled immediately, then - // it has to be put in the waiting queue - if(!success) { - scheduleGridlet(sgl); - queuedGridlets_.add(sgl); - } + sgl.setStatus(Gridlet.QUEUED); + queuedGridlets_.add(sgl); + backfillGridlets(GridSim.clock()); // sends back an ack if required if (ack == true) { @@ -490,7 +478,7 @@ sgl.setPERangeList(selected); // changes the Gridlet status - sgl.setStatus(Gridlet.QUEUED); +// sgl.setStatus(Gridlet.QUEUED); sgl.setStartTime(startTime); sgl.setActualFinishTime(finishTime); pivot_ = sgl; @@ -576,7 +564,6 @@ if(finishTime > shadowTime_) extraPEs_ = PERangeList.difference(extraPEs_, selected); - } /** @@ -662,7 +649,7 @@ resource_.resetFreePERanges(currentStatus.getPERanges()); } - itemsStarted = startQueuedGridlets(currentTime); + itemsStarted = backfillGridlets(currentTime); //---------------- USED FOR DEBUGGING PURPOSES ONLY -------------------- @@ -675,13 +662,11 @@ } /** - * This method starts gridlets that are in the queue and - * whose start time is smaller than the reference time and updates - * the availability accordingly + * This method backfills/starts gridlets that are in the queue * @param currentTime the current simulation time * @return the number of gridlets started */ - protected int startQueuedGridlets(double currentTime) { + protected int backfillGridlets(double currentTime) { int gridletStarted = 0; // first checks the pivot first @@ -720,7 +705,7 @@ * @param sgl a SSGridlet object * @param status the Gridlet status */ - private void gridletFinish(SSGridlet sgl, int status) { + protected void gridletFinish(SSGridlet sgl, int status) { // the order is important! Set the status first then finalise // due to timing issues in SSGridlet class sgl.setStatus(status); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-26 04:57:40
|
Revision: 134 http://gridsim.svn.sourceforge.net/gridsim/?rev=134&view=rev Author: marcos_dias Date: 2008-02-25 20:57:09 -0800 (Mon, 25 Feb 2008) Log Message: ----------- Workload class back to previous status as the creation of gridlets with imprecise execution time will be handled in a different way. Modified Paths: -------------- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java Modified: branches/gridsim4.0-branch3/source/gridsim/util/Workload.java =================================================================== --- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-26 04:48:35 UTC (rev 133) +++ branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-26 04:57:09 UTC (rev 134) @@ -669,14 +669,18 @@ Long l = new Long( array[SUBMIT_TIME].trim() ); long submitTime = l.intValue(); - // get the run time estimate + // get the run time obj = new Integer( array[REQ_RUN_TIME].trim() ); - int runTimeEstimate = obj.intValue(); - - // get the run time estimate - obj = new Integer( array[RUN_TIME].trim() ); int runTime = obj.intValue(); - + + // if the required run time field is ignored, then use + // the actual run time + if (runTime == IRRELEVANT) + { + obj = new Integer( array[RUN_TIME].trim() ); + runTime = obj.intValue(); + } + // according to the SWF manual, runtime of 0 is possible due // to rounding down. E.g. runtime is 0.4 seconds -> runtime = 0 if (runTime == 0) { @@ -705,7 +709,7 @@ } // submit a Gridlet - submitGridlet(id, submitTime, runTime, runTimeEstimate, numProc); + submitGridlet(id, submitTime, runTime, numProc); } catch (Exception e) { @@ -721,7 +725,6 @@ * @param id a Gridlet ID * @param submitTime Gridlet's submit time * @param runTime Gridlet's actual run time - * @param runTimeEstimate Gridlet's run time estimate * @param numProc number of processors * @pre id >= 0 * @pre submitTime >= 0 @@ -729,8 +732,8 @@ * @pre numProc > 0 * @post $none */ - protected void submitGridlet(int id, long submitTime, int runTime, - int runTimeEstimate, int numProc) + protected void submitGridlet(int id, long submitTime, + int runTime, int numProc) { // create the gridlet int len = runTime * rating_; // calculate a job length for each PE @@ -738,13 +741,6 @@ gl.setUserID( super.get_id() ); // set the owner ID gl.setNumPE(numProc); // set the requested num of proc - // If runtime estimate was provided, then use it - if(runTimeEstimate != IRRELEVANT) { - // calculate ths job expected length for each PE - int expLen = runTimeEstimate * rating_; - gl.setExpectedGridletLength(expLen); - } - // printing to inform user if (gridletID_ == 1 || gridletID_ % INTERVAL == 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-02-26 04:48:29
|
Revision: 133 http://gridsim.svn.sourceforge.net/gridsim/?rev=133&view=rev Author: brobergj Date: 2008-02-25 20:48:35 -0800 (Mon, 25 Feb 2008) Log Message: ----------- *Removed flow ack code, as it is handled in FlowBuffer now on our behalf Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java 2008-02-26 04:47:39 UTC (rev 132) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java 2008-02-26 04:48:35 UTC (rev 133) @@ -58,7 +58,8 @@ public FlowTest(String name, String destName) throws Exception { - super(name, new FlowLink(name+"_link",10485760,250, Integer.MAX_VALUE)); + // 10,485,760 baud = 10Mb/s + super(name, new FlowLink(name+"_link",10485760,250,Integer.MAX_VALUE)); // get this entity name from Sim_entity this.name_ = super.get_name(); @@ -107,14 +108,8 @@ write(super.get_name() + ".body(): receive " + ev.get_data() + ", at time = " + GridSim.clock()); - // sends back an ack - IO_data data = new IO_data(ev.get_data(), packetSize, destID_); - write(name_ + ".body(): Sending back " + - ev.get_data() + ", at time = " + GridSim.clock() ); - - // sends through Output buffer of this entity - super.send(super.output, GridSimTags.SCHEDULE_NOW, - GridSimTags.FLOW_RETURN , data); + // No need for an ack, it is handled in FlowBuffer now on our behalf + } // handle a ping requests. You need to write the below code This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-02-26 04:47:42
|
Revision: 132 http://gridsim.svn.sourceforge.net/gridsim/?rev=132&view=rev Author: brobergj Date: 2008-02-25 20:47:39 -0800 (Mon, 25 Feb 2008) Log Message: ----------- *Added delay parameter so multiple instances can be created that start sending flows at different times. Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java 2008-02-26 04:45:39 UTC (rev 131) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java 2008-02-26 04:47:39 UTC (rev 132) @@ -29,6 +29,7 @@ private String name_; // my entity name private String destName_; // destination name private int destID_; // destination id + private double wait_; // Delay until I begin sending /** Custom tag that denotes sending a message */ public static final int SEND_MSG = 1; @@ -43,7 +44,7 @@ * @throws Exception This happens when name is null or haven't * initialized GridSim. */ - public FlowNetUser(String name, String destName, Link link) throws Exception + public FlowNetUser(String name, String destName, Link link, double wait) throws Exception { super(name, link); @@ -54,12 +55,15 @@ this.myID_ = super.get_id(); // get the destination entity name - destName_ = destName; + this.destName_ = destName; + + // get the waiting time before sending + this.wait_ = wait; } - public FlowNetUser(String name, String destName) throws Exception + public FlowNetUser(String name, String destName, double wait) throws Exception { - // 10 485 760 bits = 10Mb + // 10,485,760 baud = 10Mb/s super(name, new FlowLink(name+"_link",10485760,450,Integer.MAX_VALUE)); // get this entity name from Sim_entity @@ -70,6 +74,9 @@ // get the destination entity name destName_ = destName; + + // get the waiting time before sending + this.wait_ = wait; } /** @@ -78,7 +85,7 @@ public void body() { int packetSize = 5242880; // packet size in bytes [5MB] - int size = 2; // number of packets sent + int size = 1; // number of packets sent int i = 0; // get the destination entity ID @@ -87,6 +94,7 @@ // sends messages over the other side of the link for (i = 0; i < size; i++) { + super.sim_pause(this.wait_); String msg = "Message_" + i; IO_data data = new IO_data(msg, packetSize, destID_); System.out.println(name_ + ".body(): Sending " + msg + @@ -96,7 +104,6 @@ super.send(super.output, GridSimTags.SCHEDULE_NOW, GridSimTags.FLOW_SUBMIT, data); - super.sim_pause(10); } //////////////////////////////////////////////////////// @@ -106,37 +113,16 @@ { // waiting for incoming event in the Input buffer obj = super.receiveEventObject(); - System.out.println(name_ + ".body(): Receives Ack for " + obj); + if (obj instanceof IO_data) { + System.out.println(name_ + ".body(): Receives Ack for " + ((IO_data)obj).getData()); + } } + // Wait for other FlowNetUser instances to finish + //super.sim_pause(600); - super.sim_pause(20); - //////////////////////////////////////////////////////// - // ping functionality - //InfoPacket pkt = null; - - // There are 2 ways to ping an entity: - // a. non-blocking call, i.e. - //super.ping(destID_, size); // (i) ping - //super.gridSimHold(10); // (ii) do something else - //pkt = super.getPingResult(); // (iii) get the result back - - // b. blocking call, i.e. ping and wait for a result - //System.out.println(name_ + ".body(): Sending ping,at time = " + GridSim.clock() ); - //pkt = super.pingBlockingCall(destID_, 1500); - - // print the result - //System.out.println("\n-------- " + name_ + " ----------------"); - //System.out.println(pkt); - //System.out.println("-------- " + name_ + " ----------------\n"); - - //////////////////////////////////////////////////////// - // sends back denoting end of simulation - - //super.gridSimHold(3000); - - + super.send(destID_, GridSimTags.SCHEDULE_NOW, GridSimTags.END_OF_SIMULATION); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-02-26 04:45:34
|
Revision: 131 http://gridsim.svn.sourceforge.net/gridsim/?rev=131&view=rev Author: brobergj Date: 2008-02-25 20:45:39 -0800 (Mon, 25 Feb 2008) Log Message: ----------- *Added proper dogbone/dumbell topology Modified Paths: -------------- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java Modified: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java =================================================================== --- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java 2008-02-26 04:44:05 UTC (rev 130) +++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java 2008-02-26 04:45:39 UTC (rev 131) @@ -49,7 +49,7 @@ GridSim.initNetworkType(GridSimTags.NET_FLOW_LEVEL); // In this example, the topology is: - // user(s) --1Mb/s-- r1 --10Mb/s-- r2 --1Mb/s-- GridResource(s) + // 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 @@ -61,31 +61,33 @@ String sender1 = "user1"; String receipient1 = "test1"; - //String sender2 = "user2"; - //String receipient2 = "test2"; + String sender2 = "user2"; + String receipient2 = "test2"; - // this entity is the sender - FlowNetUser user1 = new FlowNetUser(sender1, receipient1); - //NetUser user2 = new NetUser(sender2, receipient2); + // these entities are the senders + FlowNetUser user1 = new FlowNetUser(sender1, receipient2, 0.0); + FlowNetUser user2 = new FlowNetUser(sender2, receipient1, 10.0); - FlowTest test1 = new FlowTest(receipient1, sender1); - //Test test2 = new Test(receipient2, sender2); + // 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",Integer.MAX_VALUE); - //r1.attachHost(user2, userSched2); + FIFOScheduler userSched2 = new FIFOScheduler("NetUserSched_1"); + r1.attachHost(user2, userSched2); - FIFOScheduler userSched3 = new FIFOScheduler("NetUserSched_2"); - r2.attachHost(test1, userSched3); + FIFOScheduler testSched1 = new FIFOScheduler("FlowTestSched_0"); + r2.attachHost(test1, testSched1); - //FIFOScheduler userSched4 = new FIFOScheduler("NetUserSched_3",Integer.MAX_VALUE); - //r2.attachHost(test2, userSched4); + FIFOScheduler testSched2 = new FIFOScheduler("FlowTestSched_1"); + r2.attachHost(test2, testSched2); ////////////////////////////////////////// // Second step: Creates a physical link - double baud_rate = 1572864; // bits/sec [1.5Mb/s] + 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 @@ -95,18 +97,7 @@ r1.attachRouter(r2, link, r1Sched, r2Sched); - // OR ... - // use a default value - // Link link = new SimpleLink("link"); - ////////////////////////////////////////// - // Third step: Creates one or more entities. - // This can be users or resources. In this example, - // we create user's entities only. - - - - ////////////////////////////////////////// // Final step: Starts the simulation GridSim.startGridSimulation(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-02-26 04:44:00
|
Revision: 130 http://gridsim.svn.sourceforge.net/gridsim/?rev=130&view=rev Author: brobergj Date: 2008-02-25 20:44:05 -0800 (Mon, 25 Feb 2008) Log Message: ----------- *Minor changes Modified Paths: -------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java 2008-02-26 04:40:33 UTC (rev 129) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java 2008-02-26 04:44:05 UTC (rev 130) @@ -35,7 +35,7 @@ private double bandwidth_; // Bottleneck baud rate private int bottleneckID; // Bottleneck link ID - + private Vector baudRates_; // list of entity's baud rate on path from source to dest private Vector links_; // list of entity's links on path from source to dest @@ -372,6 +372,17 @@ public double getLatency() { return latency; } + + /** + * Sets the current latency over the path from source to dest. + * + * param latency + * @pre $none + * @post $none + */ + public void setLatency(double latency) { + this.latency = latency; + } /** * Adds to the current sum of latency over the path from source to dest. @@ -538,7 +549,7 @@ } /** - * ets the FlowLink ID of the bottleneck of this flow + * Sets the FlowLink ID of the bottleneck of this flow * * param bottleneckID the ID of the bottleneck FlowLink * @pre $none @@ -548,5 +559,20 @@ this.bottleneckID = bottleneckID; } + /** + * Sets the source ID for a FlowPacket + * + * param srcID the id of the source of this flow + * @pre $none + * @post $none + */ + public void setSrcID(int srcID) { + this.srcID = srcID; + } + + public void setTag(int tag) { + this.tag = tag; + } + } // end class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bro...@us...> - 2008-02-26 04:40:28
|
Revision: 129 http://gridsim.svn.sourceforge.net/gridsim/?rev=129&view=rev Author: brobergj Date: 2008-02-25 20:40:33 -0800 (Mon, 25 Feb 2008) Log Message: ----------- *Minor changes Modified Paths: -------------- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-26 04:39:24 UTC (rev 128) +++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-26 04:40:33 UTC (rev 129) @@ -378,8 +378,9 @@ } if (np.getTag() == GridSimTags.FLOW_RETURN) { - System.out.println("Dereg flow # " + np.getID() +" here"); - // Deregister passing flow as it is npw de-active on this link + System.out.println(super.get_name() + ".deque() Dereg flow # " + np.getID() +" here"); + // Deregister passing flow as it is now de-active on this link + ((FlowPacket)np).addLatency(this.getDelay()); deregisterFlow(np); } @@ -477,10 +478,10 @@ if (this.getBaudRate() > tempFlow.getBandwidth_() && tempFlow.getID() != np.getID() && tempFlow.getBottleneckID() == this.get_id()) { // Need to notify flow - System.out.println(super.get_name() + ".registerFlow(): flow #" + np.getID() + System.out.println(super.get_name() + ".deregisterFlow(): flow #" + np.getID() + " bottleneck now " + this.getBaudRate() + " at time " + GridSim.clock()); // I can notify directly as I know the destId's!!!! - System.out.println(super.get_name() + ".registerFlow(): updating flow #" + tempFlow.getID() + System.out.println(super.get_name() + ".deregisterFlow(): updating flow #" + tempFlow.getID() + " destination " + tempFlow.getDestID()); super.sim_schedule(GridSim.getEntityId("Output_" + GridSim.getEntityName(tempFlow.getDestID())), GridSimTags.SCHEDULE_NOW, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |