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-02-26 04:39:22
|
Revision: 128
http://gridsim.svn.sourceforge.net/gridsim/?rev=128&view=rev
Author: brobergj
Date: 2008-02-25 20:39:24 -0800 (Mon, 25 Feb 2008)
Log Message:
-----------
*FlowBuffer now handles the Acks for FlowPackets, after they have been held the appropriate duration
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-25 01:14:13 UTC (rev 127)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-26 04:39:24 UTC (rev 128)
@@ -35,7 +35,7 @@
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_; // unique packet ID counter
+ private static int pktID_ = 0; // packet ID counter
private Vector outPacketList_; // store a list of packets
private HashMap<Integer, Packet> activeFlows_; // stores a list of active Flows
private Random random_; // selects to which junk packets go to
@@ -63,7 +63,7 @@
link_ = null;
outPacketList_ = null;
activeFlows_ = null;
- pktID_ = 0;
+ //pktID_ = 0;
outPort_ = new Sim_port("output_buffer");
super.add_port(outPort_);
@@ -74,7 +74,7 @@
random_ = null;
hasStarted_ = false;
- System.out.println("Initialising FB id " + super.get_id() + " name " + super.get_name());
+ System.out.println("Initialising FlowBuffer id " + super.get_id() + " name " + super.get_name());
}
/**
@@ -307,6 +307,10 @@
System.out.println(super.get_name() + ".body(): updateForecast() + at time = " + GridSim.clock());
updateForecast(ev);
break;
+
+ case GridSimTags.FLOW_RETURN:
+ submitAckToLink(ev);
+ break;
default:
defaultSend(ev, gisID, statID, shutdownID);
@@ -328,6 +332,7 @@
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);
@@ -337,7 +342,23 @@
IO_data io = new IO_data( data, fp.getSize(),
outPort_.get_src());
super.sim_schedule(outPort_, GridSimTags.SCHEDULE_NOW, fp.getTag() , io.getData());
- activeFlows_.remove(pktID);
+ 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 - 1);
+ fpAck = new FlowPacket(ackData,fp.getID(),fp.getSize(),GridSimTags.FLOW_RETURN,super.get_id(),
+ oldSrcID - 1, fp.getNetServiceType(), 1, 1);
+ fpAck.setRemSize(0);
+ fpAck.setStartTime(fp.getStartTime());
+ fpAck.setLatency(fp.getLatency());
+
+ super.sim_schedule(super.get_id(), GridSimTags.SCHEDULE_NOW, GridSimTags.FLOW_RETURN, fpAck);
+
} else {
System.out.println(super.get_name() + ".checkForecast(): pkt id # " + pktID + " already removed");
@@ -550,7 +571,7 @@
return;
}
- // Identify ID of an entity which acts as Input/Buffer
+/* // 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() );
@@ -569,7 +590,7 @@
// NOTE: Below is a deprecated method for SimJava 2
//super.sim_hold(communicationDelay);
- super.sim_process(communicationDelay);
+ super.sim_process(communicationDelay);*/
}
/**
@@ -611,7 +632,15 @@
pktID_++; // increments packet ID
outEnque(np, GridSimTags.SCHEDULE_NOW);
}
+
+ 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 " + pktID_);
+ outEnque(fp, GridSimTags.SCHEDULE_NOW);
+ }
+
/**
* Creates many dummy or null packets
* @param size packet size (in bytes)
@@ -782,12 +811,6 @@
ping = true;
tag = GridSimTags.INFOPKT_SUBMIT;
}
-
- //if (np instanceof FlowPacket && np.getTag() == GridSimTags.FLOW_SUBMIT ) {
- // ((FlowPacket)np).addBaudRate( link_.getBaudRate() );
- // ((FlowPacket)np).addLatency( link_.getDelay() );
- //}
-
// if an entity tries to send a packet to itself
if ( np.getDestID() == outPort_.get_dest() )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-25 01:14:09
|
Revision: 127
http://gridsim.svn.sourceforge.net/gridsim/?rev=127&view=rev
Author: brobergj
Date: 2008-02-24 17:14:13 -0800 (Sun, 24 Feb 2008)
Log Message:
-----------
*Changed pktID to static int as it must be unique amongst all flows from all sources!
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-22 04:36:44 UTC (rev 126)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-25 01:14:13 UTC (rev 127)
@@ -35,7 +35,7 @@
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 static int pktID_; // unique packet ID counter
private Vector outPacketList_; // store a list of packets
private HashMap<Integer, Packet> activeFlows_; // stores a list of active Flows
private Random random_; // selects to which junk packets go to
@@ -860,7 +860,6 @@
return;
}
- // all except last packet in a data session are null packets
if (pkt instanceof FlowPacket)
{
FlowPacket np = (FlowPacket) pkt;
@@ -882,7 +881,7 @@
IO_data io = new IO_data( data, np.getSize(),
outPort_.get_src());
System.out.println(super.get_name() + ".getDataFromLink() Time now " + GridSim.clock()
- + " bottleneck was " + np.getBandwidth_() + " sum lat is " + np.getLatency() );
+ + " bottleneck is " + np.getBandwidth_() + " sum lat is " + np.getLatency() );
// if flow terminates at next entity, add to active flows
// & hold for appropriate duration
@@ -892,7 +891,9 @@
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;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 04:36:38
|
Revision: 126
http://gridsim.svn.sourceforge.net/gridsim/?rev=126&view=rev
Author: brobergj
Date: 2008-02-21 20:36:44 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Initial upload of flow networking example
Added Paths:
-----------
branches/gridsim4.0-branch2/examples/FlowNetEx01/
branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java
branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java
branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java
branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt
Added: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java
===================================================================
--- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java (rev 0)
+++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetEx01.java 2008-02-22 04:36:44 UTC (rev 126)
@@ -0,0 +1,125 @@
+package FlowNetEx01;
+
+/*
+ * Author: Anthony Sulistio
+ * Date: November 2004
+ * Description: A simple program to demonstrate of how to use GridSim
+ * network extension package.
+ * This example shows how to create two GridSim entities and
+ * connect them via a link. NetUser entity sends messages to
+ * Test entity and Test entity sends back these messages.
+ */
+
+import gridsim.*;
+import gridsim.net.*;
+import gridsim.net.flow.*;
+
+import java.util.*;
+
+
+
+/**
+ * Test Driver class for this example
+ */
+public class FlowNetEx01
+{
+ /**
+ * Creates main() to run this example
+ */
+ public static void main(String[] args)
+ {
+ System.out.println("Starting network example ...");
+
+ try
+ {
+
+ //////////////////////////////////////////
+ // First step: Initialize the GridSim package. It should be called
+ // before creating any entities. We can't run this example without
+ // initializing GridSim first. We will get run-time exception
+ // error.
+ int num_user = 1; // 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");
+ GridSim.init(num_user, calendar, trace_flag);
+ GridSim.initNetworkType(GridSimTags.NET_FLOW_LEVEL);
+
+ // In this example, the topology is:
+ // user(s) --1Mb/s-- r1 --10Mb/s-- r2 --1Mb/s-- GridResource(s)
+
+ // create the routers.
+ // If trace_flag is set to "true", then this experiment will create
+ // the following files (apart from sim_trace and sim_report):
+ // - router1_report.csv
+ // - router2_report.csv
+ Router r1 = new FlowRouter("router1", trace_flag); // router 1
+ Router r2 = new FlowRouter("router2", trace_flag); // router 2
+
+ String sender1 = "user1";
+ String receipient1 = "test1";
+ //String sender2 = "user2";
+ //String receipient2 = "test2";
+
+ // this entity is the sender
+ FlowNetUser user1 = new FlowNetUser(sender1, receipient1);
+ //NetUser user2 = new NetUser(sender2, receipient2);
+
+ FlowTest test1 = new FlowTest(receipient1, sender1);
+ //Test test2 = new Test(receipient2, sender2);
+
+ FIFOScheduler userSched1 = new FIFOScheduler("NetUserSched_0");
+ r1.attachHost(user1, userSched1);
+
+ //FIFOScheduler userSched2 = new FIFOScheduler("NetUserSched_1",Integer.MAX_VALUE);
+ //r1.attachHost(user2, userSched2);
+
+ FIFOScheduler userSched3 = new FIFOScheduler("NetUserSched_2");
+ r2.attachHost(test1, userSched3);
+
+ //FIFOScheduler userSched4 = new FIFOScheduler("NetUserSched_3",Integer.MAX_VALUE);
+ //r2.attachHost(test2, userSched4);
+
+ //////////////////////////////////////////
+ // Second step: Creates a physical link
+ double baud_rate = 1572864; // bits/sec [1.5Mb/s]
+ double propDelay = 300; // propagation delay in millisecond
+ int mtu = Integer.MAX_VALUE;; // max. transmission unit in byte
+
+ Link link = new FlowLink("r1_r2_link", baud_rate, propDelay, mtu);
+ FIFOScheduler r1Sched = new FIFOScheduler("r1_Sched");
+ FIFOScheduler r2Sched = new FIFOScheduler("r2_Sched");
+
+ 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();
+
+ System.out.println("\nFinish network example ...");
+ }
+ catch (Exception e)
+ {
+
+ e.printStackTrace();
+ System.err.print(e.toString());
+ System.out.println("Unwanted errors happen");
+ }
+ }
+
+} // end class
+
Added: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java
===================================================================
--- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java (rev 0)
+++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowNetUser.java 2008-02-22 04:36:44 UTC (rev 126)
@@ -0,0 +1,153 @@
+package FlowNetEx01;
+
+/*
+ * Author: Anthony Sulistio
+ * Date: November 2004
+ * Description: A simple program to demonstrate of how to use GridSim
+ * network extension package.
+ * This example shows how to create two GridSim entities and
+ * connect them via a link. NetUser entity sends messages to
+ * Test entity and Test entity sends back these messages.
+ */
+
+import gridsim.*;
+import gridsim.net.*;
+import gridsim.net.flow.*;
+import eduni.simjava.*;
+import java.util.*;
+
+
+/**
+ * This class basically sends one or more messages to the other
+ * entity over a link. Then, it waits for an ack.
+ * Finally, before finishing the simulation, it pings the other
+ * entity.
+ */
+public class FlowNetUser extends GridSim
+{
+ private int myID_; // my entity ID
+ private String name_; // my entity name
+ private String destName_; // destination name
+ private int destID_; // destination id
+
+ /** Custom tag that denotes sending a message */
+ public static final int SEND_MSG = 1;
+ public static final int ACK_MSG = 2;
+
+
+ /**
+ * Creates a new NetUser object
+ * @param name this entity name
+ * @param destName the destination entity's name
+ * @param link the physical link that connects this entity to destName
+ * @throws Exception This happens when name is null or haven't
+ * initialized GridSim.
+ */
+ public FlowNetUser(String name, String destName, Link link) throws Exception
+ {
+ super(name, link);
+
+ // get this entity name from Sim_entity
+ this.name_ = super.get_name();
+
+ // get this entity ID from Sim_entity
+ this.myID_ = super.get_id();
+
+ // get the destination entity name
+ destName_ = destName;
+ }
+
+ public FlowNetUser(String name, String destName) throws Exception
+ {
+ // 10 485 760 bits = 10Mb
+ super(name, new FlowLink(name+"_link",10485760,450,Integer.MAX_VALUE));
+
+ // get this entity name from Sim_entity
+ this.name_ = super.get_name();
+
+ // get this entity ID from Sim_entity
+ this.myID_ = super.get_id();
+
+ // get the destination entity name
+ destName_ = destName;
+ }
+
+ /**
+ * The core method that handles communications among GridSim entities.
+ */
+ public void body()
+ {
+ int packetSize = 5242880; // packet size in bytes [5MB]
+ int size = 2; // number of packets sent
+ int i = 0;
+
+ // get the destination entity ID
+ this.destID_ = GridSim.getEntityId(destName_);
+
+ // sends messages over the other side of the link
+ for (i = 0; i < size; i++)
+ {
+ String msg = "Message_" + i;
+ IO_data data = new IO_data(msg, packetSize, destID_);
+ System.out.println(name_ + ".body(): Sending " + msg +
+ ", at time = " + GridSim.clock() );
+
+ // sends through Output buffer of this entity
+ super.send(super.output, GridSimTags.SCHEDULE_NOW,
+ GridSimTags.FLOW_SUBMIT, data);
+
+ super.sim_pause(10);
+ }
+
+ ////////////////////////////////////////////////////////
+ // get the ack back
+ Object obj = null;
+ for (i = 0; i < size; i++)
+ {
+ // waiting for incoming event in the Input buffer
+ obj = super.receiveEventObject();
+ System.out.println(name_ + ".body(): Receives Ack for " + obj);
+ }
+
+
+
+ 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);
+
+ ////////////////////////////////////////////////////////
+ // shut down I/O ports
+ shutdownUserEntity();
+ terminateIOEntities();
+
+ System.out.println(this.name_ + ":%%%% Exiting body() at time " +
+ GridSim.clock() );
+ }
+
+} // end class
+
Added: branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java
===================================================================
--- branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java (rev 0)
+++ branches/gridsim4.0-branch2/examples/FlowNetEx01/FlowTest.java 2008-02-22 04:36:44 UTC (rev 126)
@@ -0,0 +1,173 @@
+package FlowNetEx01;
+
+/*
+ * Author: Anthony Sulistio
+ * Date: November 2004
+ * Description: A simple program to demonstrate of how to use GridSim
+ * network extension package.
+ * This example shows how to create two GridSim entities and
+ * connect them via a link. NetUser entity sends messages to
+ * Test entity and Test entity sends back these messages.
+ */
+
+import java.util.*;
+import gridsim.*;
+import gridsim.net.*;
+import gridsim.net.flow.*;
+import gridsim.util.SimReport;
+import eduni.simjava.*;
+
+
+/**
+ * This class handles incoming requests and sends back an ack.
+ * In addition, this class logs every activities.
+ */
+public class FlowTest extends GridSim
+{
+ private int myID_; // my entity ID
+ private String name_; // my entity name
+ private String destName_; // destination name
+ private int destID_; // destination id
+ private SimReport report_; // logs every activity
+
+ /**
+ * Creates a new NetUser object
+ * @param name this entity name
+ * @param destName the destination entity's name
+ * @param link the physical link that connects this entity to destName
+ * @throws Exception This happens when name is null or haven't
+ * initialized GridSim.
+ */
+ public FlowTest(String name, String destName, Link link) throws Exception
+ {
+ super(name, link);
+
+ // get this entity name from Sim_entity
+ this.name_ = super.get_name();
+
+ // get this entity ID from Sim_entity
+ this.myID_ = super.get_id();
+
+ // get the destination entity name
+ this.destName_ = destName;
+
+ // logs every activity. It will automatically create name.csv file
+ report_ = new SimReport(name);
+ report_.write("Creates " + name);
+ }
+
+ public FlowTest(String name, String destName) throws Exception
+ {
+ super(name, new FlowLink(name+"_link",10485760,250, Integer.MAX_VALUE));
+
+ // get this entity name from Sim_entity
+ this.name_ = super.get_name();
+
+ // get this entity ID from Sim_entity
+ this.myID_ = super.get_id();
+
+ // get the destination entity name
+ this.destName_ = destName;
+
+
+ // logs every activity. It will automatically create name.csv file
+ report_ = new SimReport(name);
+ report_.write("Creates " + name);
+ }
+
+ /**
+ * The core method that handles communications among GridSim entities.
+ */
+ public void body()
+ {
+ // get the destination entity ID
+ this.destID_ = GridSim.getEntityId(destName_);
+
+ int packetSize = 1500; // packet size in bytes
+ Sim_event ev = new Sim_event(); // an event
+
+ // a loop waiting for incoming events
+ while ( Sim_system.running() )
+ {
+ // get the next event from the Input buffer
+ super.sim_get_next(ev);
+
+ // if an event denotes end of simulation
+ if (ev.get_tag() == GridSimTags.END_OF_SIMULATION)
+ {
+ System.out.println();
+ write(super.get_name() + ".body(): exiting ...");
+ break;
+ }
+
+ // if an event denotes another event type
+ else if (ev.get_tag() == GridSimTags.FLOW_SUBMIT)
+ {
+ System.out.println();
+ 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);
+ }
+
+ // handle a ping requests. You need to write the below code
+ // for every class that extends from GridSim or GridSimCore.
+ // Otherwise, the ping functionality is not working.
+ else if (ev.get_tag() == GridSimTags.INFOPKT_SUBMIT)
+ {
+ processPingRequest(ev);
+ }
+ }
+
+ ////////////////////////////////////////////////////////
+ // shut down I/O ports
+ shutdownUserEntity();
+ terminateIOEntities();
+
+ // don't forget to close the file
+ if (report_ != null) {
+ report_.finalWrite();
+ }
+
+ System.out.println(this.name_ + ":%%%% Exiting body() at time " +
+ GridSim.clock() );
+ }
+
+ /**
+ * Handles ping request
+ * @param ev a Sim_event object
+ */
+ private void processPingRequest(Sim_event ev)
+ {
+ InfoPacket pkt = (InfoPacket) ev.get_data();
+ pkt.setTag(GridSimTags.INFOPKT_RETURN);
+ pkt.setDestID( pkt.getSrcID() );
+
+ // sends back to the sender
+ super.send(super.output, GridSimTags.SCHEDULE_NOW,
+ GridSimTags.INFOPKT_RETURN,
+ new IO_data(pkt,pkt.getSize(),pkt.getSrcID()) );
+ }
+
+ /**
+ * Prints out the given message into stdout.
+ * In addition, writes it into a file.
+ * @param msg a message
+ */
+ private void write(String msg)
+ {
+ System.out.println(msg);
+ if (report_ != null) {
+ report_.write(msg);
+ }
+ }
+
+} // end class
+
Added: branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt
===================================================================
--- branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt (rev 0)
+++ branches/gridsim4.0-branch2/examples/FlowNetEx01/README.txt 2008-02-22 04:36:44 UTC (rev 126)
@@ -0,0 +1,53 @@
+
+/**
+ * Author: James Broberg
+ * Date: February 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
+
+where $GRIDSIM or %GRIDSIM% is the location of the gridsimtoolkit package.
+
+
+To run the class file:
+ In Unix/Linux: java -classpath $GRIDSIM/jars/gridsim.jar:. FlowNetEx01 > file.txt
+ In Windows: java -classpath %GRIDSIM%\jars\gridsim.jar;. FlowNetEx01 > file.txt
+
+
+The above command means run the program and output the results into a file
+named "file.txt" rather than into screen or standard output.
+To prevent from overwriting an existing file, I renamed "file.txt" into
+"output.txt"
+NOTE: When you open "output.txt" file, it tells you that this example creates
+ two entities: "user" and "test". Both entities exchanging messages.
+
+
+When running the example file, it will produce the following files:
+
+ tracefile -> created by SimJava 1.2, now being replaced by sim_trace.
+ NOTE: GridSim 2.1 uses SimJava 1.2
+ GridSim 2.2 onwards use SimJava2
+
+ sim_trace -> created by the SimJava2 package (lower-level) to trace every
+ events (performed by SimJava and GridSim) during the simulation.
+ We don't need to worry about this file. Not to important for our
+ example.
+
+ sim_report -> created by the SimJava2 package (lower-level) of GridSim.
+ This is a simulation report that contains general information about
+ running this experiment. We don't need to worry about this file.
+ Not to important for our example.
+
+ test.csv -> created by Test.java to record every incoming activities.
+ The format of this file is:
+ simulation_time, ...
+
+ where ... means other descriptive information.
+
+NOTE: sim_trace, sim_report and test.csv will be overwritten if running
+ a new experiment.
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 02:11:12
|
Revision: 125
http://gridsim.svn.sourceforge.net/gridsim/?rev=125&view=rev
Author: brobergj
Date: 2008-02-21 18:11:17 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Added comments and javadoc
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java 2008-02-22 02:11:02 UTC (rev 124)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java 2008-02-22 02:11:17 UTC (rev 125)
@@ -38,6 +38,7 @@
*
* @invariant $none
* @since GridSim Toolkit 3.1
+ * @author James Broberg, The University of Melbourne
* @author Gokul Poduval & Chen-Khong Tham, National University of Singapore
*/
public class FlowRouter extends Router
@@ -52,14 +53,14 @@
/**
- * Creates a new RIPRouter object.
+ * Creates a new FlowRouter object.
* By default, <b>no recording or logging</b>
* is done for packets' activities. If you want to log operations of this
- * entity, please use {@link #RIPRouter(String, boolean)}.
+ * entity, please use {@link #FlowRouter(String, boolean)}.
*
* @param name Name of this router
* @throws NullPointerException This happens when name is empty or null
- * @see #RIPRouter(String, boolean)
+ * @see #FlowRouter(String, boolean)
* @pre name != null
* @post $none
*/
@@ -68,7 +69,7 @@
}
/**
- * Creates a new RIPRouter object with logging facility if it is turned on.
+ * Creates a new FlowRouter object with logging facility if it is turned on.
* <br>
* NOTE: If logging facility is turned on, there are some overheads
* in terms of performance and memory consumption.
@@ -288,10 +289,6 @@
System.out.println(super.get_name() + ".processEvent(): processNetPacket() + at time = " + GridSim.clock());
processNetPacket(ev, ev.get_tag());
break;
-
- //case GridSimTags.FLOW_FORWARD:
- // processFlowPacket(ev, ev.get_tag());
- // break;
case GridSimTags.ROUTER_AD:
receiveAd(ev);
@@ -312,8 +309,6 @@
/**
* Processes incoming network packets, one at a time.
- * The incoming packet will be split up into smaller pieces if
- * the packet size > MTU of the other end.
*
* @param ev a Sim_event object
* @pre ev != null
@@ -346,18 +341,7 @@
((InfoPacket) pkt).addBaudRate(sched.getBaudRate());
}
-// if (pkt instanceof FlowPacket && pkt.getTag() == GridSimTags.FLOW_SUBMIT ) {
-// ((FlowPacket)pkt).addBaudRate( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getBaudRate() );
-// ((FlowPacket)pkt).addLatency( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getDelay() );
-// }
-
- // check downlink MTU, and split accordingly
- //String linkName = getLinkName( pkt.getDestID() );
- //Link downLink = (Link) Sim_system.get_entity(linkName);
- //int MTU = downLink.getMTU();
- //int numPackets = (int) Math.ceil(pkt.getSize() / (MTU * 1.0));
-
System.out.println(super.get_name() + ".processNetPacket() check sched Time now " + GridSim.clock());
// if no packets at the moment
if (sched.size() == 0)
@@ -366,12 +350,7 @@
" size " + pkt.getSize()*BITS + " baud sched " + sched.getBaudRate() +
" largest double " + Double.MAX_VALUE);
- //if (numPackets == 1) {
- // nextTime = (pkt.getSize() * BITS) / sched.getBaudRate();
- //}
- //else {
- // nextTime = (MTU * BITS * 1.0) / sched.getBaudRate();
- //}
+
System.out.println(super.get_name() + ".processNetPacket() set internal event to " +
"fire");
// Fire internal event without delay (delay is incurred entirely at source
@@ -389,19 +368,6 @@
//super.write("break this packet into, " + numPackets);
}
- // break a large packet into smaller ones that fit into MTU
- // by making null or empty packets except for the last one
- /*for (int i = 0; i < numPackets - 1; i++)
- {
- NetPacket np = new NetPacket(null, pkt.getID(), MTU, tag,
- pkt.getSrcID(), pkt.getDestID(),
- pkt.getNetServiceType(),i+1,numPackets);
-
- np.setLast(id);
- super.write("enqueing, " + np);
- sched.enque(np); // put the packet into the scheduler
- }*/
-
// put the actual packet into the last one and resize it accordingly
pkt.setLast(id);
pkt.setSize(pkt.getSize());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 02:10:58
|
Revision: 124
http://gridsim.svn.sourceforge.net/gridsim/?rev=124&view=rev
Author: brobergj
Date: 2008-02-21 18:11:02 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Added comments and javadoc
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-22 02:10:46 UTC (rev 123)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java 2008-02-22 02:11:02 UTC (rev 124)
@@ -16,7 +16,6 @@
import gridsim.*;
import gridsim.net.Link;
import gridsim.net.Packet;
-import eduni.simjava.*;
/**
@@ -28,18 +27,18 @@
*/
public class FlowPacket implements Packet
{
- private int destID; // where the packet wants to go
+ private int destID; // where the flow wants to go
private int srcID; // sender ID
- private long size; // packet size (for calculating transmission time)
- private long remSize; // remaining packet size
+ private long size; // flow size (for calculating transmission time)
+ private long remSize; // remaining flow size
private Object obj; // the actual object, the type depends on context
private double bandwidth_; // Bottleneck baud rate
private int bottleneckID; // Bottleneck link ID
- private Vector baudRates_; // list of entity's baud rate
+ private Vector baudRates_; // list of entity's baud rate on path from source to dest
- private Vector links_;
+ private Vector links_; // list of entity's links on path from source to dest
// Sum of latency (delay) on path
private double latency;
@@ -63,7 +62,7 @@
private int pktID_; // a unique packet ID issued by an entity
/**
- * Constructs a network packet for data that fits into a single network
+ * Constructs a network flow for data that fits into a single network
* packet.
*
* @param data The data to be encapsulated.
@@ -96,6 +95,7 @@
this.latency = 0.0;
this.bandwidth_ = Double.MAX_VALUE;
this.baudRates_ = new Vector();
+ this.links_ = new Vector();
this.bottleneckID = -1;
}
@@ -362,14 +362,36 @@
return totalPkts;
}
+ /**
+ * Returns the current sum of latency over the path from source to dest.
+ *
+ * @return latency
+ * @pre $none
+ * @post $none
+ */
public double getLatency() {
return latency;
}
+ /**
+ * Adds to the current sum of latency over the path from source to dest.
+ *
+ * @param latency the latency of a given link
+ * @pre $none
+ * @post $none
+ */
public void addLatency(double latency) {
this.latency += latency;
}
+ /**
+ * Adds baud rate of current link, and sets bottleneck
+ * bandwidth and ID if the link is this flow's bottleneck
+ *
+ * @param link a given link
+ * @pre $none
+ * @post $none
+ */
public synchronized void addBaudRate(Link link)
{
double baudRate = link.getBaudRate();
@@ -385,14 +407,35 @@
}
}
+ /**
+ * Returns the current bottleneck bandwidth of this flow.
+ *
+ * @return bandwidth_
+ * @pre $none
+ * @post $none
+ */
public double getBandwidth_() {
return bandwidth_;
}
+ /**
+ * Sets the current bottleneck bandwidth of this flow.
+ *
+ * param bandwidth_ the current bottleneck bandwidth
+ * @pre $none
+ * @post $none
+ */
public synchronized void setBandwidth_(double bandwidth_) {
this.bandwidth_ = bandwidth_;
}
+ /**
+ * Adds current link, and calls addBaudRate() and addLatency()
+ *
+ * @param link a given link
+ * @pre $none
+ * @post $none
+ */
public synchronized void addLink(Link link)
{
if (links_ == null) {
@@ -404,38 +447,103 @@
this.addLatency(link.getDelay());
}
+ /**
+ * Returns the current start time of this flow.
+ *
+ * @return startTime
+ * @pre $none
+ * @post $none
+ */
public double getStartTime() {
return startTime;
}
+ /**
+ * Sets the current start time of this flow.
+ *
+ * @param startTime the time a flow begins holding at the destination
+ * @pre $none
+ * @post $none
+ */
public void setStartTime(double startTime) {
this.startTime = startTime;
}
+ /**
+ * Returns the last time a flow was updated (i.e. bottleneck
+ * bandwidth changed and forecast was recomputed)
+ *
+ * @return updateTime
+ * @pre $none
+ * @post $none
+ */
public double getUpdateTime() {
return updateTime;
}
+ /**
+ * Sets the last time a flow was updated (i.e. bottleneck
+ * bandwidth changed and forecast was recomputed)
+ *
+ * @param updateTime the time a flow's forecast was last updated
+ * @pre $none
+ * @post $none
+ */
public void setUpdateTime(double updateTime) {
this.updateTime = updateTime;
}
+ /**
+ * Returns the remaining size of a flow
+ *
+ * @return remSize
+ * @pre $none
+ * @post $none
+ */
public long getRemSize() {
return remSize;
}
+ /**
+ * Sets the remaining size of a flow
+ *
+ * param remSize the remaining size of a flow
+ * @pre $none
+ * @post $none
+ */
public void setRemSize(long remSize) {
this.remSize = remSize;
}
+ /**
+ * Returns a vector of links that make up this flow's path
+ *
+ * @return links_
+ * @pre $none
+ * @post $none
+ */
public Vector getLinks_() {
return links_;
}
+ /**
+ * Returns the FlowLink ID of the bottleneck of this flow
+ *
+ * @return bottleneckID
+ * @pre $none
+ * @post $none
+ */
public int getBottleneckID() {
return bottleneckID;
}
+ /**
+ * ets the FlowLink ID of the bottleneck of this flow
+ *
+ * param bottleneckID the ID of the bottleneck FlowLink
+ * @pre $none
+ * @post $none
+ */
public void setBottleneckID(int bottleneckID) {
this.bottleneckID = bottleneckID;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 02:10:41
|
Revision: 123
http://gridsim.svn.sourceforge.net/gridsim/?rev=123&view=rev
Author: brobergj
Date: 2008-02-21 18:10:46 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Added comments and javadoc
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-22 02:10:33 UTC (rev 122)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-22 02:10:46 UTC (rev 123)
@@ -7,7 +7,7 @@
*
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
- * FlowLink.java - Simulates a network link
+ * FlowLink.java - Simulates a network link with active flows
*
*/
@@ -23,7 +23,7 @@
/**
- * This class enables flow level networking over a shared link. It is based
+ * This class enables flow level networking over a shared link. It is partially based
* on SimpleLink.java by Gokul Poduval & Chen-Khong Tham
*
* @invariant $none
@@ -34,7 +34,7 @@
public class FlowLink extends Link
{
private Vector q_;
- private HashMap flows_;
+ private HashMap flows_; // Stores references to flows that are currently active on this link
private double lastUpdateTime_; // a timer to denote the last update time
private int inEnd1_;
private int outEnd1_;
@@ -225,7 +225,7 @@
}
// process the received event
- System.out.println(super.get_name() + ".body(): processEvent() + at time = " + GridSim.clock());
+ System.out.println(super.get_name() + ".body(): processEvent() at time = " + GridSim.clock());
processEvent(ev);
sim_completed(ev);
}
@@ -253,8 +253,7 @@
{
case GridSimTags.PKT_FORWARD: // for normal packets
case GridSimTags.JUNK_PKT: // for background traffic
- case GridSimTags.FLOW_UPDATE:
- System.out.println(super.get_name() + ".processEvent(): enque() + at time = " + GridSim.clock());
+ System.out.println(super.get_name() + ".processEvent(): enque() at time = " + GridSim.clock());
enque(ev);
break;
@@ -328,7 +327,7 @@
}
/**
- * Puts an event into a queue and sends an internal event to itself
+ * Puts an event into a queue, sends an internal event to itself and registers the flow
* @param ev a Sim_event object
* @pre ev != null
* @post $none
@@ -341,6 +340,7 @@
sendInternalEvent(super.delay_ / super.MILLI_SEC); // delay in ms
}
+ // Register passing flow as active on this link
if (((Packet)ev.get_data()).getTag() == GridSimTags.FLOW_SUBMIT) {
registerFlow((Packet)ev.get_data());
}
@@ -379,12 +379,13 @@
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
deregisterFlow(np);
}
// sends the packet
super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np);
- System.out.println(super.get_name() + " deque() + at time = " + GridSim.clock());
+ System.out.println(super.get_name() + ".deque() + at time = " + GridSim.clock());
}
@@ -416,13 +417,13 @@
/**
* Registers active flow to link, and link to flow
- * active flows
+ * @param np a packet
* @pre $none
* @post $none
*/
private synchronized void registerFlow(Packet np) {
- FlowPacket tempFlow;
+ FlowPacket tempFlow = null;
// Add flow to link
flows_.put(np.getID(), np );
@@ -450,11 +451,14 @@
GridSimTags.FLOW_UPDATE, new Integer(tempFlow.getID()));
}
}
-
-
-
}
+ /**
+ * Deregisters active flow on link
+ * @param np a packet
+ * @pre $none
+ * @post $none
+ */
private synchronized void deregisterFlow(Packet np) {
FlowPacket fp = null;
FlowPacket tempFlow;
@@ -464,12 +468,12 @@
System.out.println(super.get_name() + ".deregisterFlow() success flow # " + np.getID()
+ " " + fp.getBandwidth_());
- // Check if this affects any existing flows
+ // Check if this affects any existing flows
Iterator<Integer> flowsIter = flows_.keySet().iterator();
while(flowsIter.hasNext()) {
tempFlow = (FlowPacket) flows_.get(flowsIter.next());
// If change in bandwidth affects an existing flow i.e. is > current bottleneck
- // AND this link is the flow's bottleneck
+ // AND this link is the particular flow's bottleneck
if (this.getBaudRate() > tempFlow.getBandwidth_() && tempFlow.getID() != np.getID() &&
tempFlow.getBottleneckID() == this.get_id()) {
// Need to notify flow
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 02:10:28
|
Revision: 122
http://gridsim.svn.sourceforge.net/gridsim/?rev=122&view=rev
Author: brobergj
Date: 2008-02-21 18:10:33 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Added comments and javadoc
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-22 02:10:20 UTC (rev 121)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-22 02:10:33 UTC (rev 122)
@@ -4,14 +4,13 @@
* of Parallel and Distributed Systems such as Clusters and Grids
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
- * Author: James Broberg & Anthony Sulistio (Adapted from original Output.java)
+ * Author: James Broberg & Anthony Sulistio (Adapted from original Input.java & Output.java)
*/
package gridsim.net.flow;
import gridsim.*;
import gridsim.net.*;
-import gridsim.net.flow.*;
import gridsim.util.*;
import eduni.simjava.*;
@@ -20,17 +19,14 @@
/**
- * GridSim Output defines a port through which a simulation entity sends
- * data to the simulated network.
+ * GridSim FlowBuffer defines a port through which a simulation entity sends
+ * and receives data to the simulated network using flow networking principles.
* <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
+ * the data-out-flow and data-in-flow and delivers to the destination entity.
*
- * @author Manzur Murshed and Rajkumar Buyya
- * @since GridSim Toolkit 1.0
+ * @author James Broberg
+ * @since GridSim Toolkit 4.0
* @invariant $none
*/
public class FlowBuffer extends Sim_entity implements NetIO
@@ -50,7 +46,7 @@
/**
- * Allocates a new Output object
+ * Allocates a new FlowBuffer object
* @param name the name of this object
* @param baudRate the communication speed
* @throws NullPointerException This happens when creating this entity
@@ -91,6 +87,8 @@
* @pre gen != null
* @post $none
*/
+
+ // TODO: Background traffic not yet implemented, do not use!
public boolean setBackgroundTraffic(TrafficGenerator gen)
{
if (gen == null) {
@@ -119,6 +117,8 @@
* @pre userName != null
* @post $none
*/
+
+ // TODO: Background traffic not yet implemented, do not use!
public boolean setBackgroundTraffic(TrafficGenerator gen,
Collection userName)
{
@@ -179,7 +179,7 @@
* 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
+ * @param link the link to which this FlowBuffer entity should send data
* @pre link != null
* @post $none
*/
@@ -244,8 +244,6 @@
public void body()
{
- //System.out.println("Hello FlowOutput");
-
// find out ids for entities that are not part of simulation network
// topology, such as GIS, GridSimShutdown and GridStatistics
int gisID = GridSim.getGridInfoServiceEntityId();
@@ -253,7 +251,7 @@
int shutdownID = GridSim.getGridSimShutdownEntityId();
// start generating some junk packets or background traffic
- startBackgroundTraffic();
+ // startBackgroundTraffic();
// Process incoming events
while ( Sim_system.running() )
@@ -303,7 +301,8 @@
System.out.println(super.get_name() + ".body(): checkForecast() + at time = " + GridSim.clock());
checkForecast(ev);
break;
-
+
+ // Update flow duration forecase
case GridSimTags.FLOW_UPDATE:
System.out.println(super.get_name() + ".body(): updateForecast() + at time = " + GridSim.clock());
updateForecast(ev);
@@ -319,13 +318,20 @@
GridSim.clock() );
}
+ /**
+ * 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();
- FlowPacket fp = null;
+ int pktID = (Integer) ev.get_data(); // ID of flow to be checked
+ FlowPacket fp = null; // Reference to flow packet that needs forecast update
System.out.println(super.get_name() + ".checkForecast(): checking pkt id # " + pktID);
- // If flow hasn't already finished
+ // If flow hasn't already finished, send it to outPort
if ((fp = (FlowPacket) activeFlows_.get(pktID)) != null) {
Object data = fp.getData();
IO_data io = new IO_data( data, fp.getSize(),
@@ -339,10 +345,18 @@
}
+ /**
+ * 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 from current Gridsim.clock()
+ 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)
@@ -354,7 +368,7 @@
if ((fp = (FlowPacket) activeFlows_.get(pktID)) != null) {
remSizeOld = fp.getRemSize();
bandwidthOld = fp.getBandwidth_();
- System.out.println(super.get_name() + " rem size is " + remSizeOld + "BW old is " + bandwidthOld);
+ System.out.println(super.get_name() + "updateForecast(): rem size is " + remSizeOld + "BW old is " + bandwidthOld);
Iterator it = (fp.getLinks_()).iterator();
while (it.hasNext()) {
@@ -486,6 +500,7 @@
* @pre $none
* @post $none
*/
+ // TODO: Background traffic not yet implemented, do not use!
private synchronized void startBackgroundTraffic()
{
// if no background traffic generator, then skip the rest
@@ -632,6 +647,7 @@
* @pre ev != null
* @post $none
*/
+ // TODO: Untested in flow model, and probably not useful
private synchronized void sendInfoPacket(Sim_event ev)
{
IO_data data = (IO_data) ev.get_data();
@@ -673,56 +689,14 @@
pktID_++; // increments packet ID
outEnque(pkt, GridSimTags.SCHEDULE_NOW);
}
-
- private synchronized void sendInfoPacket(int dest)
- {
- // IO_data data = (IO_data) ev.get_data();
- // gets all the relevant info
- long size = 1500;
- int destId = dest;
-// / 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,0);
-
- // set the required info
- pkt.setLast( super.get_id() );
- pkt.addHop( outPort_.get_dest() );
- pkt.addEntryTime( GridSim.clock() );
- pkt.setOriginalPingSize( 1500 );
- pkt.setTag(GridSimTags.INFOPKT_SUBMIT);
-
- pktID_++; // increments packet ID
- outEnque(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
*/
+ // TODO: Untested in flow model, and probably not useful
private void returnInfoPacket(Sim_event ev)
{
IO_data data = (IO_data) ev.get_data();
@@ -765,9 +739,6 @@
private synchronized void outEnque(Packet pkt, double delay)
{
- //if ((pkt instanceof InfoPacket) != true) {
- // sendInfoPacket(pkt.getDestID());
- //}
outPacketList_.add(pkt);
if (outPacketList_.size() == 1)
@@ -779,10 +750,7 @@
System.out.println(super.get_name() + ".outEnque() Time now " + GridSim.clock() + " delay is " + total);
super.sim_schedule(super.get_id(), total, GridSimTags.SEND_PACKET);
- }
-
-
-
+ }
}
@@ -869,6 +837,13 @@
}
}
+ /**
+ * 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();
@@ -921,7 +896,7 @@
// 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 port
+ // send the data into entity input/output port
super.sim_schedule(outPort_, duration, tag,
io.getData() );
}
@@ -931,6 +906,13 @@
}
}
+ /**
+ * Processes a ping request
+ * @param pkt a packet for pinging
+ * @pre pkt != null
+ * @post $none
+ */
+ // TODO: Untested in flow model, and probably not useful
private void processPingRequest(InfoPacket pkt)
{
// add more information to ping() packet
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-22 02:10:17
|
Revision: 121
http://gridsim.svn.sourceforge.net/gridsim/?rev=121&view=rev
Author: brobergj
Date: 2008-02-21 18:10:20 -0800 (Thu, 21 Feb 2008)
Log Message:
-----------
*Added comments and javadoc
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java 2008-02-21 06:10:02 UTC (rev 120)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java 2008-02-22 02:10:20 UTC (rev 121)
@@ -6,7 +6,6 @@
*
* Author: James Broberg
*
- * $Id: FilterResult.java,v 1.3 2005/03/10 04:35:17 anthony Exp $
*/
package gridsim.net.flow;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-21 06:10:09
|
Revision: 120
http://gridsim.svn.sourceforge.net/gridsim/?rev=120&view=rev
Author: brobergj
Date: 2008-02-20 22:10:02 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
*Add Link information (BW, latency) to FlowPacket at FlowLink
instead of FlowRouter and BlowBuffer
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java 2008-02-21 06:06:35 UTC (rev 119)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java 2008-02-21 06:10:02 UTC (rev 120)
@@ -346,11 +346,11 @@
((InfoPacket) pkt).addBaudRate(sched.getBaudRate());
}
- if (pkt instanceof FlowPacket && pkt.getTag() == GridSimTags.FLOW_SUBMIT ) {
- ((FlowPacket)pkt).addBaudRate( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getBaudRate() );
- ((FlowPacket)pkt).addLatency( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getDelay() );
+// if (pkt instanceof FlowPacket && pkt.getTag() == GridSimTags.FLOW_SUBMIT ) {
+// ((FlowPacket)pkt).addBaudRate( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getBaudRate() );
+// ((FlowPacket)pkt).addLatency( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getDelay() );
- }
+// }
// check downlink MTU, and split accordingly
//String linkName = getLinkName( pkt.getDestID() );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-21 06:06:30
|
Revision: 119
http://gridsim.svn.sourceforge.net/gridsim/?rev=119&view=rev
Author: brobergj
Date: 2008-02-20 22:06:35 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
*Made tracking of bottleneck easier via addLink()
*Track bottleneck Link ID at all times
*Track remaining flow size
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-21 05:35:52 UTC (rev 118)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java 2008-02-21 06:06:35 UTC (rev 119)
@@ -31,10 +31,11 @@
private int destID; // where the packet wants to go
private int srcID; // sender ID
private long size; // packet size (for calculating transmission time)
- private long origSize; // original packet size
+ private long remSize; // remaining packet size
private Object obj; // the actual object, the type depends on context
private double bandwidth_; // Bottleneck baud rate
+ private int bottleneckID; // Bottleneck link ID
private Vector baudRates_; // list of entity's baud rate
@@ -43,6 +44,12 @@
// Sum of latency (delay) on path
private double latency;
+ // Packet start time
+ private double startTime;
+
+ // Packet last size update time
+ private double updateTime;
+
// original tag with which the encapsulated object was submitted
private int tag;
@@ -74,7 +81,9 @@
{
this.obj = data ;
this.size = size ;
- this.origSize = size ;
+ this.remSize = size ;
+ this.startTime = -1.0;
+ this.updateTime = -1.0;
this.tag = tag ;
this.destID = destID;
this.srcID = srcID ;
@@ -87,6 +96,7 @@
this.latency = 0.0;
this.bandwidth_ = Double.MAX_VALUE;
this.baudRates_ = new Vector();
+ this.bottleneckID = -1;
}
@@ -118,6 +128,9 @@
{
this.obj = data;
this.size = size;
+ this.remSize = size ;
+ this.startTime = -1.0;
+ this.updateTime = -1.0;
this.tag = tag;
this.destID = destID;
this.srcID = srcID;
@@ -130,6 +143,8 @@
this.latency = 0.0;
this.bandwidth_ = -1;
this.baudRates_ = new Vector();
+ this.links_ = new Vector();
+ this.bottleneckID = -1;
}
@@ -227,16 +242,6 @@
}
/**
- * Gets the original size of this packet
- * @return the packet size
- * @pre $none
- * @post $none
- */
- public long getOrigSize() {
- return origSize;
- }
-
- /**
* Sets the packet size
* @param size the packet size
* @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
@@ -365,15 +370,18 @@
this.latency += latency;
}
- public void addBaudRate(double baudRate)
+ public synchronized void addBaudRate(Link link)
{
+ double baudRate = link.getBaudRate();
+
if (baudRates_ == null) {
return;
}
baudRates_.add( new Double(baudRate) );
if (bandwidth_ < 0 || baudRate < this.bandwidth_) {
- this.bandwidth_ = baudRate;
+ this.setBandwidth_(baudRate);
+ this.setBottleneckID(link.get_id());
}
}
@@ -381,18 +389,56 @@
return bandwidth_;
}
- public void setBandwidth_(double bandwidth_) {
+ public synchronized void setBandwidth_(double bandwidth_) {
this.bandwidth_ = bandwidth_;
}
- public void addLink(Link link)
+ public synchronized void addLink(Link link)
{
if (links_ == null) {
return;
}
links_.add( link );
+ this.addBaudRate(link);
+ this.addLatency(link.getDelay());
}
+ public double getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(double startTime) {
+ this.startTime = startTime;
+ }
+
+ public double getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(double updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public long getRemSize() {
+ return remSize;
+ }
+
+ public void setRemSize(long remSize) {
+ this.remSize = remSize;
+ }
+
+ public Vector getLinks_() {
+ return links_;
+ }
+
+ public int getBottleneckID() {
+ return bottleneckID;
+ }
+
+ public void setBottleneckID(int bottleneckID) {
+ this.bottleneckID = bottleneckID;
+ }
+
} // 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-21 05:35:49
|
Revision: 118
http://gridsim.svn.sourceforge.net/gridsim/?rev=118&view=rev
Author: brobergj
Date: 2008-02-20 21:35:52 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
*Fixed deregisterFlow(), now notifies any affected active flows if bottleneck bandwidth increases
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-21 05:33:52 UTC (rev 117)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-21 05:35:52 UTC (rev 118)
@@ -253,6 +253,7 @@
{
case GridSimTags.PKT_FORWARD: // for normal packets
case GridSimTags.JUNK_PKT: // for background traffic
+ case GridSimTags.FLOW_UPDATE:
System.out.println(super.get_name() + ".processEvent(): enque() + at time = " + GridSim.clock());
enque(ev);
break;
@@ -420,25 +421,33 @@
* @post $none
*/
private synchronized void registerFlow(Packet np) {
+
+ FlowPacket tempFlow;
+
+ // Add flow to link
+ flows_.put(np.getID(), np );
+
System.out.println(super.get_name() + ".registerFlow(): registering flow #" + np.getID()
+ " total of " + flows_.size() + " flows");
-
- // Add flow to link
- flows_.put(np.getID(), np );
-
+
// Register link to flow
((FlowPacket)np).addLink(this);
// Check if this affects any existing flows
Iterator<Integer> flowsIter = flows_.keySet().iterator();
while(flowsIter.hasNext()) {
+ tempFlow = (FlowPacket) flows_.get(flowsIter.next());
// If change in bandwidth affects an existing flow i.e. is < current bottleneck
- if (this.getBaudRate() < ((FlowPacket) flows_.get(flowsIter.next())).getBandwidth_() &&
- ((FlowPacket) flows_.get(flowsIter.next())).getID() != np.getID()) {
+ if (this.getBaudRate() < tempFlow.getBandwidth_() && tempFlow.getID() != np.getID()) {
// Need to notify flow
System.out.println(super.get_name() + ".registerFlow(): flow #" + np.getID()
+ " bottleneck now " + this.getBaudRate() + " at time " + GridSim.clock());
- // I can notify directly as I have know the destId's!!!!
+ // I can notify directly as I know the destId's!!!!
+ System.out.println(super.get_name() + ".registerFlow(): updating flow #" + tempFlow.getID()
+ + " destination " + tempFlow.getDestID());
+ super.sim_schedule(GridSim.getEntityId("Output_" +
+ GridSim.getEntityName(tempFlow.getDestID())), GridSimTags.SCHEDULE_NOW,
+ GridSimTags.FLOW_UPDATE, new Integer(tempFlow.getID()));
}
}
@@ -448,10 +457,33 @@
private synchronized void deregisterFlow(Packet np) {
FlowPacket fp = null;
+ FlowPacket tempFlow;
+
if ((fp = (FlowPacket) flows_.remove(np.getID())) != null) {
System.out.println(super.get_name() + ".deregisterFlow() success flow # " + np.getID()
+ " " + fp.getBandwidth_());
+
+ // Check if this affects any existing flows
+ Iterator<Integer> flowsIter = flows_.keySet().iterator();
+ while(flowsIter.hasNext()) {
+ tempFlow = (FlowPacket) flows_.get(flowsIter.next());
+ // If change in bandwidth affects an existing flow i.e. is > current bottleneck
+ // AND this link is the flow's bottleneck
+ 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()
+ + " 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()
+ + " destination " + tempFlow.getDestID());
+ super.sim_schedule(GridSim.getEntityId("Output_" +
+ GridSim.getEntityName(tempFlow.getDestID())), GridSimTags.SCHEDULE_NOW,
+ GridSimTags.FLOW_UPDATE, new Integer(tempFlow.getID()));
+ }
+
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-21 05:33:46
|
Revision: 117
http://gridsim.svn.sourceforge.net/gridsim/?rev=117&view=rev
Author: brobergj
Date: 2008-02-20 21:33:52 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
*Added FLOW_UPDATE support, supporting methods
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-21 03:43:39 UTC (rev 116)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-21 05:33:52 UTC (rev 117)
@@ -11,6 +11,7 @@
import gridsim.*;
import gridsim.net.*;
+import gridsim.net.flow.*;
import gridsim.util.*;
import eduni.simjava.*;
@@ -76,6 +77,8 @@
list_ = null;
random_ = null;
hasStarted_ = false;
+
+ System.out.println("Initialising FB id " + super.get_id() + " name " + super.get_name());
}
/**
@@ -300,6 +303,11 @@
System.out.println(super.get_name() + ".body(): checkForecast() + at time = " + GridSim.clock());
checkForecast(ev);
break;
+
+ case GridSimTags.FLOW_UPDATE:
+ System.out.println(super.get_name() + ".body(): updateForecast() + at time = " + GridSim.clock());
+ updateForecast(ev);
+ break;
default:
defaultSend(ev, gisID, statID, shutdownID);
@@ -311,7 +319,7 @@
GridSim.clock() );
}
- private void checkForecast(Sim_event ev) {
+ private synchronized void checkForecast(Sim_event ev) {
int pktID = (Integer) ev.get_data();
FlowPacket fp = null;
@@ -323,13 +331,56 @@
IO_data io = new IO_data( data, fp.getSize(),
outPort_.get_src());
super.sim_schedule(outPort_, GridSimTags.SCHEDULE_NOW, fp.getTag() , io.getData());
+ activeFlows_.remove(pktID);
} else {
System.out.println(super.get_name() + ".checkForecast(): pkt id # " + pktID + " already removed");
}
}
+
+ 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 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() + " 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");
+ }
+
+
+ super.sim_schedule(super.get_id(), duration, GridSimTags.FLOW_HOLD , new Integer(fp.getID()));
+ }
+ }
+
/**
* Generates few junk packets at the given interval
* @pre $none
@@ -764,10 +815,10 @@
tag = GridSimTags.INFOPKT_SUBMIT;
}
- if (np instanceof FlowPacket && np.getTag() == GridSimTags.FLOW_SUBMIT ) {
- ((FlowPacket)np).addBaudRate( link_.getBaudRate() );
- ((FlowPacket)np).addLatency( link_.getDelay() );
- }
+ //if (np instanceof FlowPacket && np.getTag() == GridSimTags.FLOW_SUBMIT ) {
+ // ((FlowPacket)np).addBaudRate( link_.getBaudRate() );
+ // ((FlowPacket)np).addLatency( link_.getDelay() );
+ //}
// if an entity tries to send a packet to itself
@@ -861,9 +912,11 @@
// if flow terminates at next entity, add to active flows
// & hold for appropriate duration
if (pkt.getTag() == GridSimTags.FLOW_SUBMIT) {
- 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()));
+ 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()));
// if flow is just an ACK of a finished flow do not hold
} else if (pkt.getTag() == GridSimTags.FLOW_RETURN){
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-21 03:43:33
|
Revision: 116
http://gridsim.svn.sourceforge.net/gridsim/?rev=116&view=rev
Author: brobergj
Date: 2008-02-20 19:43:39 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
*Fixed spelling and descriptive error
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/net/Link.java
Modified: branches/gridsim4.0-branch2/source/gridsim/net/Link.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/Link.java 2008-02-21 03:26:43 UTC (rev 115)
+++ branches/gridsim4.0-branch2/source/gridsim/net/Link.java 2008-02-21 03:43:39 UTC (rev 116)
@@ -96,7 +96,7 @@
throw new ParameterException(msg + "baud rate must be > 0.");
}
else if (propDelay <= 0) {
- throw new ParameterException(msg+"propagation delay mut be < 0.");
+ throw new ParameterException(msg+"propagation delay must be > 0.");
}
else if (MTU <= 0) {
throw new ParameterException(msg + "MTU must be > 0.");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-21 03:26:39
|
Revision: 115
http://gridsim.svn.sourceforge.net/gridsim/?rev=115&view=rev
Author: brobergj
Date: 2008-02-20 19:26:43 -0800 (Wed, 20 Feb 2008)
Log Message:
-----------
Added new FilterFlow Sim_predicate class, to find future events relating to flow duration forecasts. This is used when we wish to invalidate a future event due to the bottleneck bandwidth changing, thus making the associated forecast incorrect.
Added Paths:
-----------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java
Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java (rev 0)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FilterFlow.java 2008-02-21 03:26:43 UTC (rev 115)
@@ -0,0 +1,100 @@
+/*
+ * 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
+ *
+ * $Id: FilterResult.java,v 1.3 2005/03/10 04:35:17 anthony Exp $
+ */
+
+package gridsim.net.flow;
+
+import eduni.simjava.Sim_predicate;
+import eduni.simjava.Sim_event;
+
+
+/**
+ * Look for a specific incoming event that matches a given event tag name and a
+ * flow id. Incoming events with a matching tag name <b>must</b>
+ * contain a data object of type
+ * <tt>Integer</tt>, where <tt>Integer</tt> stores the flow id.
+ * <br><br>
+ *
+ * This class is used by {@link eduni.simjava.Sim_system}
+ * to select or filter an event already present in the entity's deferred queue
+ * (incoming buffer), or used to selectively wait for a future event.
+ * <br> <br>
+ *
+ *
+ *
+ * @author James Broberg
+ * @since GridSim Toolkit 4.0
+ * @invariant $none
+ */
+public class FilterFlow extends Sim_predicate
+{
+ private int tag_; // event tag to be matched
+ private int flowID_; // event or flow ID
+
+
+ /**
+ * Finds an incoming events that matches with the given flow ID and
+ * event tag name
+ * @param flowID a unique flow ID to differentiate
+ * itself among other events with the same tag name
+ * @param tag a matching event tag name
+ * @pre $none
+ * @post $none
+ */
+ public FilterFlow(int flowID, int tag)
+ {
+ tag_ = tag;
+ flowID_ = flowID;
+ }
+
+ /**
+ * Checks whether an event matches the required constraints or not.<br>
+ * NOTE: This method is not used directly by the user. Instead, it is
+ * called by {@link eduni.simjava.Sim_system}.
+ *
+ * @param ev an incoming event to compare with
+ * @return <tt>true</tt> if an event matches, <tt>false</tt> otherwise
+ * @pre ev != null
+ * @post $none
+ */
+ public boolean match(Sim_event ev)
+ {
+ if (ev == null) {
+ return false;
+ }
+
+ boolean result = false;
+ try
+ {
+ // find an event with a matching tag first
+ if ( tag_ == ev.get_tag() )
+ {
+ Object obj = ev.get_data();
+
+ // if the event's data contains the correct data
+ if (obj instanceof Integer)
+ {
+ int id = (Integer)obj;
+
+ // if the data contains the correct ID or value
+ if (id == flowID_) {
+ result = true;
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ result = false;
+ }
+
+ return result;
+ }
+
+} // end class
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mar...@us...> - 2008-02-19 08:46:38
|
Revision: 114
http://gridsim.svn.sourceforge.net/gridsim/?rev=114&view=rev
Author: marcos_dias
Date: 2008-02-19 00:46:43 -0800 (Tue, 19 Feb 2008)
Log Message:
-----------
Inclusion of expected duration of a gridlet based on the runtime estimate.
Modified Paths:
--------------
branches/gridsim4.0-branch3/source/gridsim/Gridlet.java
branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.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
branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java
branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java
branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java
branches/gridsim4.0-branch3/source/gridsim/util/Workload.java
Modified: branches/gridsim4.0-branch3/source/gridsim/Gridlet.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/Gridlet.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -55,6 +55,11 @@
// the size of this Gridlet to be executed in a GridResource (unit: in MI)
private double gridletLength_;
+
+ // the expected size of this Gridlet to be executed in a GridResource
+ // (unit: in MI). This value is calculated based on the runtime estimate
+ // provided by the user.
+ private double expectedGridletLength_;
// the input file size of this Gridlet before execution (unit: in byte)
private long gridletFileSize_; // in byte = program + input data size
@@ -196,6 +201,7 @@
this.num_ = null;
this.history_ = null;
this.newline_ = null;
+ this.expectedGridletLength_ = -1; // unknown
}
/**
@@ -298,7 +304,29 @@
gridletLength_ = gridletLength;
return true;
}
+
+ /**
+ * Sets the expected length or size (in MI) of this Gridlet
+ * to be executed in a GridResource based on the runtime estimate provided
+ * by the user.
+ * This Gridlet length is calculated for 1 PE only <tt>not</tt> the total
+ * length.
+ *
+ * @param gridletLength the length or size (in MI) of this Gridlet
+ * to be executed in a GridResource
+ * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
+ * @pre gridletLength > 0
+ * @post $none
+ */
+ public boolean setExpectedGridletLength(double gridletLength) {
+ if (gridletLength <= 0) {
+ return false;
+ }
+ expectedGridletLength_ = gridletLength;
+ return true;
+ }
+
/**
* Sets the network service level for sending this gridlet over a network
* @param netServiceLevel determines the kind of service this gridlet
@@ -873,6 +901,17 @@
}
/**
+ * Gets the expected length of this Gridlet based on the runtime estimate
+ * @return the length of this Gridlet based on the user's runtime estimate
+ * @pre $none
+ * @post $result >= 0.0
+ */
+ public double getExpectedGridletLength() {
+ return expectedGridletLength_ > 0 ?
+ expectedGridletLength_ : gridletLength_;
+ }
+
+ /**
* Gets the total execution time of this Gridlet from the latest
* GridResource
* @return the total execution time of this Gridlet in a GridResource
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/ResourceWindow.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -223,7 +223,7 @@
case AllocationAction.ITEM_SCHEDULED:
for(ScheduleItem item : list){
- double finishTime = item.getFinishTime();
+ double finishTime = item.getActualFinishTime();
settings_.setTimeSpan(finishTime);
}
pnItem_.updateItem(list.getLast());
@@ -762,7 +762,7 @@
int textHeight, textWidth;
// gets the time duration of the gridlet
- double duration = item.getFinishTime() - item.getStartTime();
+ double duration = item.getActualFinishTime() - item.getStartTime();
width = (int) (duration * scaleX_);
firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_);
@@ -838,7 +838,7 @@
int width, height;
// gets the time duration of the gridlet
- double duration = item.getFinishTime() - item.getStartTime();
+ double duration = item.getActualFinishTime() - item.getStartTime();
width = (int) (duration * scaleX_);
firstX = SHIFT_X + (int) (item.getStartTime() * scaleX_);
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -253,7 +253,7 @@
sgl.setPERangeList(selected);
double resStartTime = sRes.getStartTime();
sgl.setStartTime(resStartTime);
- sgl.setFinishTime(resStartTime + executionTime);
+ sgl.setActualFinishTime(resStartTime + executionTime);
sgl.setStatus(Gridlet.QUEUED);
queuedGridlets_.add(sgl);
@@ -342,7 +342,7 @@
// if start time is 0, then it is an immediate reservation
if(startTime == 0 || startTime == currentTime) {
success = handleImmediateReservation(sRes);
- expTime = sRes.getFinishTime();
+ expTime = sRes.getActualFinishTime();
}
else {
success = handleAdvanceReservation(sRes);
@@ -634,7 +634,7 @@
Iterator<SSReservation> iterRes = reservTable_.values().iterator();
while(iterRes.hasNext()) {
SSReservation sRes = iterRes.next();
- if(sRes.getFinishTime() <= refTime) {
+ if(sRes.getActualFinishTime() <= refTime) {
// Finish the reservation and include ranges in the
// list of ranges to be released
sRes.setStatus(Reservation.STATUS_FINISHED);
@@ -681,7 +681,7 @@
startedReservations.add(sRes);
- super.sendInternalEvent(sRes.getFinishTime()-refTime,
+ super.sendInternalEvent(sRes.getActualFinishTime()-refTime,
CBParallelSpaceShared.UPDATE_SCHEDULE_TAG);
numStartedRes++;
@@ -1089,7 +1089,7 @@
// allocates the ranges and updates the availability profile
profile_.allocatePERanges(queueId, anchorIndex,
- tailIndex, selected, startTime, res.getFinishTime());
+ tailIndex, selected, startTime, res.getActualFinishTime());
}
else {
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -278,11 +278,11 @@
// updates the availability profile accordingly
allocateImmediatePERanges(tailIndex, selected,
- currentTime, sRes.getFinishTime());
+ currentTime, sRes.getActualFinishTime());
// the expiration time for immediate reservation is the
// termination time
- expTime = sRes.getFinishTime();
+ expTime = sRes.getActualFinishTime();
}
}
// It is not an immediate reservation
@@ -323,7 +323,7 @@
// allocates the ranges and updates the availability profile
allocatePERanges(anchorIndex, tailIndex, selected,
- startTime, sRes.getFinishTime());
+ startTime, sRes.getActualFinishTime());
// calculate the expiration time of the reservation
expTime = currentTime + commitPeriod_;
@@ -414,7 +414,7 @@
" because it is already in the expiry list.");
success = false;
}
- else if( (sRes = reservTable_.get(reservationId)).getFinishTime() <= currentTime ) {
+ else if( (sRes = reservTable_.get(reservationId)).getActualFinishTime() <= currentTime ) {
System.out.println(super.get_name() + ".handleCancelReservation()" +
" Reservation # " + reservationId + " cannot be cancelled because " +
" it has already finished.");
@@ -748,7 +748,7 @@
sgl.setPERangeList(selected);
double resStartTime = sRes.getStartTime();
sgl.setStartTime(resStartTime);
- sgl.setFinishTime(resStartTime + executionTime);
+ sgl.setActualFinishTime(resStartTime + executionTime);
sgl.setStatus(Gridlet.QUEUED);
queuedGridlets_.add(sgl);
@@ -923,7 +923,7 @@
allocatedRanges.addAll(sRes.getPERangeList().clone());
startedReservations.add(sRes);
- super.sendInternalEvent(sRes.getFinishTime()-refTime,
+ super.sendInternalEvent(sRes.getActualFinishTime()-refTime,
CBParallelSpaceShared.UPDATE_SCHEDULE_TAG);
numStartedRes++;
@@ -971,7 +971,7 @@
Iterator<SSReservation> iterRes = reservTable_.values().iterator();
while(iterRes.hasNext()) {
SSReservation sRes = iterRes.next();
- if(sRes.getFinishTime() <= refTime) {
+ if(sRes.getActualFinishTime() <= refTime) {
// Finish the reservation and include ranges in the
// list of ranges to be released
sRes.setStatus(Reservation.STATUS_FINISHED);
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -155,7 +155,7 @@
// queue yet. It will probably be done shortly,
// so just send a null to the user.
if(sgl.getStatus() == Gridlet.SUCCESS ||
- sgl.getFinishTime() <= currentTime){
+ sgl.getActualFinishTime() <= currentTime){
super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL,
null, gridletId, userId);
return; // return as it is impossible to cancel the Gridlet
@@ -322,7 +322,7 @@
// change Gridlet status
sgl.setStatus(Gridlet.QUEUED);
sgl.setStartTime(startTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
//------------------ FOR DEBUGGING PURPOSES ONLY ----------------
@@ -354,7 +354,7 @@
// as gridlets are removed from running queue once they finish
// time is smaller than current time, then testing the time
// is enough. There's no need to check status
- if(gridlet.getFinishTime() <= currentTime) {
+ if(gridlet.getActualFinishTime() <= currentTime) {
gridletFinish(gridlet, Gridlet.SUCCESS);
iter.remove();
itemsFinished++;
@@ -386,7 +386,7 @@
// change Gridlet status
gridlet.setStatus(Gridlet.INEXEC);
- super.sendInternalEvent(gridlet.getFinishTime()-currentTime,
+ super.sendInternalEvent(gridlet.getActualFinishTime()-currentTime,
UPDATE_SCHEDULE_TAG);
}
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -361,7 +361,7 @@
// queue yet. It will probably be done shortly,
// so just send a null to the user.
if(sgl.getStatus() == Gridlet.SUCCESS ||
- sgl.getFinishTime() <= currentTime){
+ sgl.getActualFinishTime() <= currentTime){
super.sendCancelGridlet(GridSimTags.GRIDLET_CANCEL,
null, gridletId, userId);
return; // return as it is impossible to cancel the Gridlet
@@ -559,7 +559,7 @@
double startTime = removedItem.getStartTime();
// the entries between reference time and endTime must be updated
- double endTime = removedItem.getFinishTime();
+ double endTime = removedItem.getActualFinishTime();
// if the Gridlet was running, then update the range of PEs currently
// available and set the reference time as current simulation time
@@ -646,7 +646,7 @@
// as gridlets are removed from running queue once they finish
// time is smaller than current time, then testing the time
// is enough. There's no need to check status
- if(gridlet.getFinishTime() <= currentTime) {
+ if(gridlet.getActualFinishTime() <= currentTime) {
// Update the list of ranges released
if(!reserved) {
releasedRanges.addAll(gridlet.getPERangeList().clone());
@@ -690,7 +690,7 @@
// change Gridlet status
gridlet.setStatus(Gridlet.INEXEC);
- super.sendInternalEvent(gridlet.getFinishTime()-currentTime,
+ super.sendInternalEvent(gridlet.getActualFinishTime()-currentTime,
UPDATE_SCHEDULE_TAG);
}
}
@@ -793,7 +793,7 @@
// add this Gridlet into execution list
runningGridlets_.add(sgl);
sgl.setStartTime(currentTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
// change Gridlet status
sgl.setStatus(Gridlet.INEXEC);
@@ -846,7 +846,7 @@
// change Gridlet status
sgl.setStatus(Gridlet.QUEUED);
sgl.setStartTime(startTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
}
/**
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultiplePartitions.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -522,7 +522,7 @@
// add this Gridlet into execution list
runningGridlets_.add(sgl);
sgl.setStartTime(currentTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
// change Gridlet status
sgl.setStatus(Gridlet.INEXEC);
@@ -569,7 +569,7 @@
else {
profile_.updateEntriesAtProfile(queue.pivot_);
queue.pivot_.setStartTime(-1);
- queue.pivot_.setFinishTime(-1);
+ queue.pivot_.setActualFinishTime(-1);
queue.pivot_ = null;
}
}
@@ -668,7 +668,7 @@
// change Gridlet status
sgl.setStatus(Gridlet.QUEUED);
sgl.setStartTime(startTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
//------------------ FOR DEBUGGING PURPOSES ONLY ----------------
@@ -770,7 +770,7 @@
// as gridlets are removed from running queue once they finish
// time is smaller than current time, then testing the time
// is enough. There's no need to check status
- if(gridlet.getFinishTime() <= currentTime) {
+ if(gridlet.getActualFinishTime() <= currentTime) {
gridletFinish(gridlet, Gridlet.SUCCESS);
iter.remove();
itemsFinished++;
@@ -802,7 +802,7 @@
// change Gridlet status
queue.pivot_.setStatus(Gridlet.INEXEC);
- super.sendInternalEvent(queue.pivot_.getFinishTime()-currentTime,
+ super.sendInternalEvent(queue.pivot_.getActualFinishTime()-currentTime,
UPDATE_SCHEDULE_TAG);
queue.pivot_ = null;
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -422,7 +422,7 @@
// add this Gridlet into execution list
runningGridlets_.add(sgl);
sgl.setStartTime(currentTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
// change Gridlet status
sgl.setStatus(Gridlet.INEXEC);
@@ -492,7 +492,7 @@
// changes the Gridlet status
sgl.setStatus(Gridlet.QUEUED);
sgl.setStartTime(startTime);
- sgl.setFinishTime(finishTime);
+ sgl.setActualFinishTime(finishTime);
pivot_ = sgl;
//------------------ FOR DEBUGGING PURPOSES ONLY ----------------
@@ -631,7 +631,7 @@
// as gridlets are removed from running queue once they finish
// time is smaller than current time, then testing the time
// is enough. There's no need to check status
- if(gridlet.getFinishTime() <= currentTime) {
+ if(gridlet.getActualFinishTime() <= currentTime) {
// Update the list of ranges released
gridletFinish(gridlet, Gridlet.SUCCESS);
iter.remove();
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -909,7 +909,7 @@
double startTime = removedItem.getStartTime();
// the entries between reference time and endTime must be updated
- double finishTime = removedItem.getFinishTime();
+ double finishTime = removedItem.getActualFinishTime();
// transfer the PEs back to the queue
transferPEs(partitionId, allocatedRanges, startTime, finishTime);
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -43,9 +43,12 @@
// the time when the Gridlet is to start execution
private double startTime_;
- // estimation of Gridlet finished time
- private double finishedTime_;
+ // the finish time of the Gridlet
+ private double actualFinishTime_;
+ // estimation of Gridlet finished time
+ private double expectedFinishTime_;
+
// num PE needed to execute this Gridlet
private int numPE_;
@@ -415,30 +418,56 @@
}
/**
- * Sets the finish time for this Gridlet. If time is negative, then it is
- * being ignored.
+ * Sets the actual finish time for this Gridlet. That is, the time when
+ * the gridlet will finish. If time is negative, then it is being ignored.
* @param time finish time
* @pre time >= 0.0
* @post $none
*/
- public void setFinishTime(double time) {
+ public void setActualFinishTime(double time) {
if (time < 0.0) {
return;
}
- finishedTime_ = time;
+ actualFinishTime_ = time;
}
+
+ /**
+ * Sets the item's expected finish time. That is, this end
+ * time is based on the estimate provided by the user and may
+ * not reflect the actual finish time of the schedule item.
+ * @param time the expected finish time
+ * @pre time >= 0.0
+ * @post $none
+ */
+ public void setExpectedFinishTime(double time) {
+ if (time < 0.0) {
+ return;
+ }
+ expectedFinishTime_ = time;
+ }
+
/**
* Gets the Gridlet's finish time
* @return finish time of a gridlet or <tt>-1.0</tt> if
* it cannot finish in this hourly slot
- * @pre $none
- * @post $result >= -1.0
*/
- public double getFinishTime() {
- return finishedTime_;
+ public double getActualFinishTime() {
+ return actualFinishTime_;
}
+
+ /**
+ * Gets the gridlet's expected finish time. That is, this end
+ * time is based on the estimate provided by the user and may
+ * not reflect the actual finish time of the schedule item.
+ * @return finish time of an item or equals to the actual
+ * finish time if not known.
+ */
+ public double getExpectedFinishTime() {
+ return expectedFinishTime_ > 0 ?
+ expectedFinishTime_ : actualFinishTime_;
+ }
/**
* Gets this Gridlet object
@@ -476,10 +505,11 @@
* for debugging purposes
*/
public String toString(){
- String result = "Gridlet {id=" +
- getID() + ", start time=" +
- startTime_ + ", finish time=" +
- finishedTime_ + ", n. PEs=" + numPE_ +
+ String result = "Gridlet {id=" + getID() +
+ ", start time=" + startTime_ +
+ ", expected finish time=" + expectedFinishTime_ +
+ ", actual finish time=" + actualFinishTime_ +
+ ", n. PEs=" + numPE_ +
", ranges=" + peRangeList_ + "}";
return result;
}
@@ -501,9 +531,11 @@
" " + timeDescr + "\n" +
"Start Time: " + decFormater_.format(convertTime(startTime_, timeUnit)) +
" " + timeDescr + "\n" +
- "FinishTime: " + decFormater_.format(convertTime(finishedTime_, timeUnit)) +
+ "Exp. Finish Time: " + decFormater_.format(convertTime(expectedFinishTime_, timeUnit)) +
+ " " + timeDescr + "\n" +
+ "Finish Time: " + decFormater_.format(convertTime(actualFinishTime_, timeUnit)) +
" " + timeDescr + "\n" +
- "Duration: " + decFormater_.format(convertTime(finishedTime_ - startTime_, timeUnit)) +
+ "Duration: " + decFormater_.format(convertTime(actualFinishTime_ - startTime_, timeUnit)) +
" " + timeDescr + "\n" +
"Length: " + decFormater_.format(gridlet_.getGridletLength()) + " MIs" + "\n" +
"Num. PEs: " + numPE_;
@@ -524,7 +556,8 @@
this.gridlet_.setSubmissionTime(arrivalTime_);
// default values
- this.finishedTime_ = NOT_FOUND; // Cannot finish in this hourly slot.
+ this.actualFinishTime_ = NOT_FOUND; // Cannot finish in this hourly slot.
+ this.expectedFinishTime_ = NOT_FOUND;
this.startTime_ = NOT_FOUND;
this.totalCompletionTime_ = 0.0;
this.startExecTime_ = 0.0;
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -312,7 +312,7 @@
* @pre $none
* @post $none
*/
- public double getFinishTime() {
+ public double getActualFinishTime() {
if(reservation_==null)
return UNKNOWN;
@@ -320,6 +320,17 @@
}
/**
+ * Gets the reservation's expected finish time. That is, this end
+ * time is based on the estimate provided by the user.<br>
+ * <b>NOTE:</b> for advance reservations, the actual and expected finish
+ * times are the same.
+ * @return finish time of the advance reservation.
+ */
+ public double getExpectedFinishTime() {
+ return getActualFinishTime();
+ }
+
+ /**
* Gets this object's duration time in seconds
* @return the reservation duration time in seconds
* @pre $none
@@ -399,7 +410,7 @@
" " + unitDesc + "\n" +
"Start Time: " + decFormater_.format(convertTime(reservation_.getStartTime(), timeUnit)) +
" " + unitDesc + "\n" +
- "FinishTime: " + decFormater_.format(convertTime(getFinishTime(), timeUnit)) +
+ "FinishTime: " + decFormater_.format(convertTime(getActualFinishTime(), timeUnit)) +
" " + unitDesc + "\n" +
"Duration: " + decFormater_.format(convertTime(reservation_.getDurationTime(), timeUnit)) +
" " + unitDesc + "\n" +
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -66,13 +66,23 @@
double getStartTime();
/**
- * Gets the item's finish time
+ * Gets the item's real finish time. That is, the actual
+ * time when the item is to finish
* @return finish time of an item or <tt>-1.0</tt> if
* not known
*/
- double getFinishTime();
+ double getActualFinishTime();
/**
+ * Gets the item's expected finish time. That is, this end
+ * time is based on the estimate provided by the user and may
+ * not reflect the actual finish time of the schedule item.
+ * @return finish time of an item or equals to the actual
+ * finish time if not known.
+ */
+ double getExpectedFinishTime();
+
+ /**
* Gets the priority of this item assigned by the scheduler
* @return the priority or <tt>-1</tt> if not found
*/
Modified: branches/gridsim4.0-branch3/source/gridsim/util/Workload.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-19 02:42:56 UTC (rev 113)
+++ branches/gridsim4.0-branch3/source/gridsim/util/Workload.java 2008-02-19 08:46:43 UTC (rev 114)
@@ -660,8 +660,7 @@
if (JOB_NUM == IRRELEVANT) {
id = gridletID_;
}
- else
- {
+ else {
obj = new Integer( array[JOB_NUM].trim() );
id = obj.intValue();
}
@@ -670,18 +669,14 @@
Long l = new Long( array[SUBMIT_TIME].trim() );
long submitTime = l.intValue();
- // get the run time
+ // get the run time estimate
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) {
@@ -710,7 +705,7 @@
}
// submit a Gridlet
- submitGridlet(id, submitTime, runTime, numProc);
+ submitGridlet(id, submitTime, runTime, runTimeEstimate, numProc);
}
catch (Exception e)
{
@@ -725,7 +720,8 @@
* resource
* @param id a Gridlet ID
* @param submitTime Gridlet's submit time
- * @param runTime Gridlet's run 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
@@ -733,13 +729,21 @@
* @pre numProc > 0
* @post $none
*/
- protected void submitGridlet(int id, long submitTime, int runTime, int numProc)
+ protected void submitGridlet(int id, long submitTime, int runTime,
+ int runTimeEstimate, int numProc)
{
// create the gridlet
int len = runTime * rating_; // calculate a job length for each PE
Gridlet gl = new Gridlet(id, len, size_, size_, GridSim.isTraceEnabled());
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-19 02:42:51
|
Revision: 113
http://gridsim.svn.sourceforge.net/gridsim/?rev=113&view=rev
Author: brobergj
Date: 2008-02-18 18:42:56 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*FlowRouter simulates a flow network router with RIP as the advertising
protocol (adapted from RIPRouter.java)
*It still depends on a scheduler although it performs no useful function, and this dependency will be remove ASAP
Added Paths:
-----------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java (rev 0)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowRouter.java 2008-02-19 02:42:56 UTC (rev 113)
@@ -0,0 +1,735 @@
+/*
+ * ** Network and Service Differentiation Extensions to GridSim 3.0 **
+ *
+ * Author: James Broberg
+ *
+ * Author: Gokul Poduval & Chen-Khong Tham
+ * Computer Communication Networks (CCN) Lab
+ * Dept of Electrical & Computer Engineering
+ * National University of Singapore
+ * August 2004
+ *
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * FlowRouter.java - Simulates a flow network router with RIP as the advertising
+ * protocol (adapted from RIPRouter.java)
+ *
+ */
+package gridsim.net.flow;
+
+import eduni.simjava.*;
+import gridsim.*;
+import gridsim.net.*;
+import gridsim.util.*;
+import java.util.*;
+
+
+/**
+ * This class implements a Router using a form of RIP for routing. The routing
+ * protocol used here is similar to <a
+ * href="http://www.ietf.org/rfc/rfc1058.txt">Routing Information Protocol
+ * (RIP) </a>. The routing protocol is run before Gridlets etc. can be
+ * submitted.
+ * <p>
+ * In case there are more than two routes to a destination, the
+ * route with the lower hopcount is used. Since in this simulation routers
+ * relay perfect information and links do not break down, RIP should be a
+ * reliable protocol to use.
+ *
+ * @invariant $none
+ * @since GridSim Toolkit 3.1
+ * @author Gokul Poduval & Chen-Khong Tham, National University of Singapore
+ */
+public class FlowRouter extends Router
+{
+ private Hashtable linkTable;
+ private Hashtable schedTable; // table of schedulers
+ private Hashtable hostTable;
+ private Hashtable routerTable;
+ private Hashtable forwardTable;
+ private int id;
+ private static final int BITS = 8; // 1 byte in bits
+
+
+ /**
+ * Creates a new RIPRouter object.
+ * By default, <b>no recording or logging</b>
+ * is done for packets' activities. If you want to log operations of this
+ * entity, please use {@link #RIPRouter(String, boolean)}.
+ *
+ * @param name Name of this router
+ * @throws NullPointerException This happens when name is empty or null
+ * @see #RIPRouter(String, boolean)
+ * @pre name != null
+ * @post $none
+ */
+ public FlowRouter(String name) throws NullPointerException {
+ this(name, false);
+ }
+
+ /**
+ * Creates a new RIPRouter object with logging facility if it is turned on.
+ * <br>
+ * NOTE: If logging facility is turned on, there are some overheads
+ * in terms of performance and memory consumption.
+ *
+ * @param name Name of this router
+ * @param trace <tt>true</tt> if you want to record this router's
+ * activity, <tt>false</tt> otherwise
+ * @throws NullPointerException This happens when name is empty or null
+ * @pre name != null
+ * @post $none
+ */
+ public FlowRouter(String name, boolean trace) throws NullPointerException
+ {
+ super(name, trace);
+ init();
+ }
+
+ /**
+ * Initialises all variables
+ * @pre $none
+ * @post $none
+ */
+ private void init()
+ {
+ this.id = super.get_id();
+ linkTable = new Hashtable();
+ hostTable = new Hashtable();
+ routerTable = new Hashtable();
+ forwardTable = new Hashtable();
+ schedTable = new Hashtable();
+ }
+
+ /**
+ * Informs the registered entities regarding to the end of a simulation.
+ * @pre $none
+ * @post $none
+ */
+ protected void processEndSimulation() {
+ // ... empty - maybe need to clean up all the hashtables
+ }
+
+ /**
+ * Joins two routers with a Link.
+ * @param router The router on the other side to which this one will
+ * be attached.
+ * @param link This is the link that will be used to connect the two
+ * routers.
+ * @param thisSched The scheduling policy used on this routers egress port
+ * when sending data through it.
+ * @param otherSched The scheduling policy that will be used on the
+ * egress port of the router being connected to when
+ * sending data to this router.
+ * @pre router != null
+ * @pre link != null
+ * @pre thisSched != null
+ * @pre otherSched != null
+ * @post $none
+ */
+ public void attachRouter(Router router, Link link,
+ PacketScheduler thisSched, PacketScheduler otherSched)
+ {
+ String msg = super.get_name() + ".attachRouter(): Error - ";
+ if (router == null)
+ {
+ System.out.println(msg + "the router is null.");
+ return;
+ }
+
+ if (link == null)
+ {
+ System.out.println(msg + "the link is null.");
+ return;
+ }
+
+ if (thisSched == null || otherSched == null)
+ {
+ System.out.println(msg +
+ "the one or more packet schedulers are null.");
+ return;
+ }
+
+ thisSched.setBaudRate( link.getBaudRate() );
+ otherSched.setBaudRate( link.getBaudRate() );
+
+ link.attach(this, router);
+ this.attachRouter(router, link, thisSched);
+ router.attachRouter(this, link, otherSched);
+ }
+
+ /**
+ * Joins two routers together. This is called by the routers themselves
+ * and should not be called by other entities.
+ *
+ * @param router The Router to which this router will be connected.
+ * @param link The Link that will be used to join these routers.
+ * @param sched The scheduling policy used on the egress port of the
+ * router when sending data through this route.
+ * @pre router != null
+ * @pre link != null
+ * @pre sched != null
+ * @post $none
+ */
+ public void attachRouter(Router router, Link link, PacketScheduler sched)
+ {
+ String msg = super.get_name() + ".attachRouter(): Error - ";
+ if (router == null)
+ {
+ System.out.println(msg + "the router is null.");
+ return;
+ }
+
+ if (link == null)
+ {
+ System.out.println(msg + "the link is null.");
+ return;
+ }
+
+ if (sched == null)
+ {
+ System.out.println(msg + "the packet scheduler is null.");
+ return;
+ }
+
+ linkTable.put(router.get_name(), link.get_name());
+
+ if (!schedTable.containsKey( link.get_name()) ) {
+ schedTable.put(link.get_name(), sched);
+ }
+
+ routerTable.put( link.get_name(), router.get_name() );
+ hostTable.put( link.get_name(), router.get_name() );
+
+ // logging or recording ...
+ if (reportWriter_ != null)
+ {
+ StringBuffer sb = null;
+ sb = new StringBuffer("attach this ROUTER, with router, ");
+ sb.append( router.get_name() );
+ sb.append(", with link, ");
+ sb.append( link.get_name() );
+ sb.append(", with packet scheduler, ");
+ sb.append( sched.getSchedName() );
+
+ super.write( sb.toString() );
+ }
+ }
+
+ /**
+ * Attaches an entity to this router. The link between the router and the
+ * entity being attached is taken from
+ * {@link gridsim.GridSimCore#getLink()}.
+ *
+ * @param entity The entity to be attached.
+ * @param sched The scheduling policy that will be used on the egress
+ * port when the router sends data to the entity being
+ * joined.
+ * @see gridsim.GridSimCore#getLink()
+ * @pre entity != null
+ * @pre sched != null
+ * @post $none
+ */
+ public void attachHost(GridSimCore entity, PacketScheduler sched)
+ {
+ String msg = super.get_name() + ".attachHost(): Error - ";
+ if (entity == null)
+ {
+ System.out.println(msg + "the entity is null.");
+ return;
+ }
+
+ if (sched == null)
+ {
+ System.out.println(msg + "the packet scheduler is null.");
+ return;
+ }
+
+ Link link = entity.getLink();
+ sched.setBaudRate( link.getBaudRate() );
+ link.attach(this, entity);
+ linkTable.put( entity.get_name(), link.get_name() );
+
+ if (!schedTable.containsKey( link.get_name() )) {
+ schedTable.put(link.get_name(), sched);
+ }
+
+ hostTable.put( link.get_name(), entity.get_name() );
+
+ // recording ...
+ if (reportWriter_ != null)
+ {
+ StringBuffer sb = null;
+ sb = new StringBuffer("attach this ROUTER, to entity, ");
+ sb.append( entity.get_name() );
+ sb.append(", with packet scheduler, ");
+ sb.append( sched.getSchedName() );
+
+ super.write( sb.toString() );
+ }
+ }
+
+ /**
+ * Processes incoming events
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ protected synchronized void processEvent(Sim_event ev)
+ {
+
+ System.out.println("Event was scheduled for " + ev.event_time());
+
+ switch ( ev.get_tag() )
+ {
+
+ case GridSimTags.PKT_FORWARD:
+ case GridSimTags.JUNK_PKT:
+ System.out.println(super.get_name() + ".processEvent(): processNetPacket() + at time = " + GridSim.clock());
+ processNetPacket(ev, ev.get_tag());
+ break;
+
+ //case GridSimTags.FLOW_FORWARD:
+ // processFlowPacket(ev, ev.get_tag());
+ // break;
+
+ case GridSimTags.ROUTER_AD:
+ receiveAd(ev);
+ break;
+
+ case GridSimTags.INSIGNIFICANT:
+ System.out.println(super.get_name() + ".processEvent(): processInternalEvent() + at time = " + GridSim.clock());
+ processInternalEvent(ev);
+ break;
+
+ default:
+ System.out.println(super.get_name() + ".body(): Unable to " +
+ "handle request from GridSimTags " +
+ "with constant number " + ev.get_tag() );
+ break;
+ }
+ }
+
+ /**
+ * Processes incoming network packets, one at a time.
+ * The incoming packet will be split up into smaller pieces if
+ * the packet size > MTU of the other end.
+ *
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ private synchronized void processNetPacket(Sim_event ev, int tag)
+ {
+ //double nextTime = 0;
+ Packet pkt = (Packet) ev.get_data();
+ PacketScheduler sched = getScheduler(pkt);
+ System.out.println("Packet id is " + pkt.getID());
+
+ // if a packet scheduler is not found, then try reschedule this packet
+ // in the future
+ if (sched == null)
+ {
+ System.out.println(super.get_name() + ".processNetPacket(): " +
+ "Warning - can't find a packet scheduler for " + pkt);
+ System.out.println("-> Will reschedule it again in the future.");
+
+ super.sim_schedule(super.get_id(), Router.DELAY, tag, pkt);
+ return;
+ }
+
+ // process ping() request
+ if (pkt instanceof InfoPacket)
+ {
+ ((InfoPacket) pkt).addHop(id);
+ ((InfoPacket) pkt).addEntryTime( GridSim.clock() );
+ ((InfoPacket) pkt).addBaudRate(sched.getBaudRate());
+ }
+
+ if (pkt instanceof FlowPacket && pkt.getTag() == GridSimTags.FLOW_SUBMIT ) {
+ ((FlowPacket)pkt).addBaudRate( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getBaudRate() );
+ ((FlowPacket)pkt).addLatency( ((Link)Sim_system.get_entity(getLinkName(pkt.getDestID()))).getDelay() );
+
+ }
+
+ // check downlink MTU, and split accordingly
+ //String linkName = getLinkName( pkt.getDestID() );
+ //Link downLink = (Link) Sim_system.get_entity(linkName);
+ //int MTU = downLink.getMTU();
+ //int numPackets = (int) Math.ceil(pkt.getSize() / (MTU * 1.0));
+
+ System.out.println(super.get_name() + ".processNetPacket() check sched Time now " + GridSim.clock());
+ // if no packets at the moment
+ if (sched.size() == 0)
+ {
+ System.out.println(super.get_name() + ".processNetPacket() #packets " +
+ " size " + pkt.getSize()*BITS + " baud sched " + sched.getBaudRate() +
+ " largest double " + Double.MAX_VALUE);
+
+ //if (numPackets == 1) {
+ // nextTime = (pkt.getSize() * BITS) / sched.getBaudRate();
+ //}
+ //else {
+ // nextTime = (MTU * BITS * 1.0) / sched.getBaudRate();
+ //}
+ System.out.println(super.get_name() + ".processNetPacket() set internal event to " +
+ "fire");
+ // Fire internal event without delay (delay is incurred entirely at source
+ // of Flow
+ sendInternalEvent(GridSimTags.SCHEDULE_NOW, sched);
+ }
+ System.out.println(super.get_name() + ".processNetPacket() done sched Time now " +
+ GridSim.clock());
+
+ // log / record ....
+ if (super.reportWriter_ != null)
+ {
+ super.write("");
+ super.write("receive incoming, " + pkt + ", delay, " + 0.0);
+ //super.write("break this packet into, " + numPackets);
+ }
+
+ // break a large packet into smaller ones that fit into MTU
+ // by making null or empty packets except for the last one
+ /*for (int i = 0; i < numPackets - 1; i++)
+ {
+ NetPacket np = new NetPacket(null, pkt.getID(), MTU, tag,
+ pkt.getSrcID(), pkt.getDestID(),
+ pkt.getNetServiceType(),i+1,numPackets);
+
+ np.setLast(id);
+ super.write("enqueing, " + np);
+ sched.enque(np); // put the packet into the scheduler
+ }*/
+
+ // put the actual packet into the last one and resize it accordingly
+ pkt.setLast(id);
+ pkt.setSize(pkt.getSize());
+ super.write("enqueing, " + pkt);
+ sched.enque(pkt); // put the packet into the scheduler
+ }
+
+
+ /**
+ * Gets the link's name for a given id
+ * @param destID a destination id
+ * @return the link's man
+ * @pre destID > 0
+ * @post $none
+ */
+ private synchronized String getLinkName(int destID)
+ {
+ String destName = GridSim.getEntityName(destID);
+ String linkName = null;
+
+ //directly connected
+ if (hostTable.containsValue(destName)) {
+ linkName = (String)linkTable.get(destName);
+ }
+ else
+ {
+ // need to forward to another router
+ Object[] data = (Object[]) forwardTable.get(destName);
+ String router = (String) data[0];
+ linkName = (String) linkTable.get(router);
+ }
+
+ return linkName;
+ }
+
+ /**
+ * Returns the Scheduler associated with a packet.
+ *
+ * @param np NetPacket for which the associated scheduler is to be returned
+ * @return the packet's scheduler or <tt>null</tt> if the packet is empty
+ * @pre np != null
+ * @post $none
+ */
+ public PacketScheduler getScheduler(Packet np)
+ {
+ if (np == null) {
+ return null;
+ }
+
+ String destName = GridSim.getEntityName( np.getDestID() );
+ return getScheduler(destName);
+ }
+
+ /**
+ * Returns the Scheduler that the router would use to reach a particular
+ * destination. This can be used to set weigths, priorities etc. as the
+ * case may be on the Scheduler
+ *
+ * @param dest id of the destination for which the Scheduler is required.
+ * @return the destination's packet scheduler
+ * @pre dest > 0
+ * @post $none
+ */
+ public PacketScheduler getScheduler(int dest)
+ {
+ if (dest < 0) {
+ return null;
+ }
+
+ String destName = GridSim.getEntityName(dest);
+ return getScheduler(destName);
+ }
+
+ /**
+ * Returns the Scheduler that the router would use to reach a particular
+ * destination. This can be used to set weigths, priorities etc. as the
+ * case may be on the Scheduler
+ *
+ * @param dest Name of the destination for which the Scheduler is required.
+ * @return destination's packet scheduler or <tt>null</tt> if destination
+ * name is invalid.
+ * @pre dest != null
+ * @post $none
+ */
+ public PacketScheduler getScheduler(String dest)
+ {
+ if (dest == null || dest.length() == 0) {
+ return null;
+ }
+
+ PacketScheduler sched = null;
+ try
+ {
+ if ( hostTable.containsValue(dest) )
+ {
+ String linkName = (String) linkTable.get(dest);
+ sched = (PacketScheduler) schedTable.get(linkName);
+ }
+ else
+ {
+ // need to forward to another router
+ Object[] data = (Object[]) forwardTable.get(dest);
+
+ // in case the forwarding table is incomplete
+ if (data == null) {
+ return null;
+ }
+
+ String router = (String) data[0];
+ String linkName = (String) linkTable.get(router);
+ sched = (PacketScheduler) schedTable.get(linkName);
+ }
+ }
+ catch (Exception e) {
+ sched = null;
+ }
+
+ return sched;
+ }
+
+ /**
+ * Processes internal event
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ private synchronized void processInternalEvent(Sim_event ev)
+ {
+ PacketScheduler sched = (PacketScheduler) ev.get_data();
+ dequeue(sched);
+ }
+
+ /**
+ * Dequeue a packet from the scheduler and sends it to the next
+ * destination via a link.
+ * @param sched the packet scheduler
+ * @pre sched != null
+ * @post $none
+ */
+ private synchronized void dequeue(PacketScheduler sched)
+ {
+ Packet np = sched.deque();
+
+ // process ping() packet
+ if (np instanceof InfoPacket) {
+ ((InfoPacket) np).addExitTime( GridSim.clock() );
+ }
+
+ super.write("dequeuing, " + np);
+
+ // must distinguish between normal and junk packet
+ int tag = GridSimTags.PKT_FORWARD;
+ if (np.getTag() == GridSimTags.JUNK_PKT) {
+ tag = GridSimTags.JUNK_PKT;
+ }
+
+ // sends the packet via the link
+ String linkName = getLinkName( np.getDestID() );
+ super.sim_schedule(GridSim.getEntityId(linkName),
+ GridSimTags.SCHEDULE_NOW, tag, np);
+
+ System.out.println(super.get_name() + ".deque() time now " + GridSim.clock());
+
+ // process the next packet in the scheduler
+ if ( !sched.isEmpty() )
+ {
+ double nextTime = (np.getSize() * BITS) / sched.getBaudRate();
+ sendInternalEvent(nextTime, sched);
+ }
+ }
+
+ /**-
+ * Sends an internal event to itself
+ * @param time the delay time period
+ * @param data the data to be sent
+ * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
+ * @pre time >= 0
+ * @post $none
+ */
+ private synchronized boolean sendInternalEvent(double time, Object data)
+ {
+ if (time < 0.0) {
+ return false;
+ }
+
+ super.sim_schedule(id, time, GridSimTags.INSIGNIFICANT, data);
+ return true;
+ }
+
+ /**
+ * Prints this router's routing table in a nice-formatted layout
+ * @pre $none
+ * @post $none
+ */
+ public synchronized void printRoutingTable()
+ {
+ synchronized (System.out)
+ {
+ System.out.println();
+ System.out.println("--- Routing Table for " +
+ super.get_name() + " ---");
+
+ for (Enumeration e = hostTable.keys(); e.hasMoreElements(); )
+ {
+ String link = (String) e.nextElement();
+ System.out.println(hostTable.get(link) + "\t\t" + link);
+ }
+
+ for (Enumeration e = forwardTable.keys(); e.hasMoreElements(); )
+ {
+ String host = (String)e.nextElement();
+ Object[] data = (Object[])forwardTable.get(host);
+ String nextHop = (String)data[0];
+ System.out.println(host + "\t\t" + nextHop);
+ }
+
+ System.out.println("-------------------------------------");
+ System.out.println();
+ }
+ }
+
+
+ //----------- ADVERTISING FUNCTIONS --------------//
+
+ /**
+ * All hosts connected to this router are advertised to adjacent routers
+ * @pre $none
+ * @post $none
+ */
+ protected synchronized void advertiseHosts()
+ {
+ Collection hosts = hostTable.values(); // who to advertise
+ Enumeration routers = routerTable.elements();
+
+ while ( routers.hasMoreElements() )
+ {
+ RIPAdPack ad = new RIPAdPack(super.get_name(), hosts);
+ String router = (String) routers.nextElement();
+ super.write("advertise to router, " + router);
+ sim_schedule(Sim_system.get_entity_id(router),
+ GridSimTags.SCHEDULE_NOW, GridSimTags.ROUTER_AD, ad);
+ }
+
+ //super.sim_pause(1); // wait for 5 secs to gather the results
+ }
+
+ /**
+ * When an ad is recieved, the forwarding table is updated. After that we
+ * need to propogate this ad along all links except the incoming one.
+ * {@link #forwardAd(RIPAdPack)} is used for that
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ private synchronized void receiveAd(Sim_event ev)
+ {
+ super.write("receive router ad from, "+GridSim.getEntityName(ev.get_src()));
+
+ // what to do when an ad is received
+ RIPAdPack ad = (RIPAdPack)ev.get_data();
+
+ // prevent count-to-infinity
+ if (ad.getHopCount() > 15) {
+ return;
+ }
+
+ String sender = ad.getSender();
+ Iterator it = ad.getHosts().iterator();
+
+ while ( it.hasNext() )
+ {
+ String host = (String) it.next();
+
+ if ( host.equals(super.get_name()) ) {
+ continue;
+ }
+
+ if (hostTable.containsValue(host)) { // direct connection
+ continue;
+ }
+
+ if (forwardTable.containsKey(host))
+ {
+ Object[] data = (Object[])forwardTable.get(host);
+ int hop = ((Integer)data[1]).intValue();
+
+ if ((hop) > ad.getHopCount())
+ {
+ Object[] toPut = { sender, new Integer(ad.getHopCount()) };
+ forwardTable.put(host, toPut);
+ }
+ }
+ else
+ {
+ Object[] toPut = { sender, new Integer(ad.getHopCount()) };
+ forwardTable.put(host, toPut);
+ }
+ }
+
+ forwardAd(ad);
+ }
+
+ /**
+ * Received ads should be forwarded along all links except the incoming
+ * one. Also need to change id to onself
+ *
+ * @param ad a RIPAdPack object
+ * @pre ad != null
+ * @post $none
+ */
+ private synchronized void forwardAd(RIPAdPack ad)
+ {
+ String sender = ad.getSender();
+ ad.incrementHopCount();
+ RIPAdPack newad = new RIPAdPack(super.get_name(),ad.getHosts());
+ newad.setHopCount(ad.getHopCount());
+
+ Enumeration routers = routerTable.elements();
+ while ( routers.hasMoreElements() )
+ {
+ String router = (String)routers.nextElement();
+ if (!router.equals(sender))
+ {
+ sim_schedule(Sim_system.get_entity_id(router),
+ GridSimTags.SCHEDULE_NOW, GridSimTags.ROUTER_AD, newad);
+ }
+ }
+ }
+
+} // 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-19 02:40:47
|
Revision: 112
http://gridsim.svn.sourceforge.net/gridsim/?rev=112&view=rev
Author: brobergj
Date: 2008-02-18 18:40:39 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*FlowBuffer replaces FlowInput/FlowOutput approach
*FlowBuffer acts as both a input and output port for simulation entities and as such it is a central point of control
Added Paths:
-----------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java (rev 0)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowBuffer.java 2008-02-19 02:40:39 UTC (rev 112)
@@ -0,0 +1,895 @@
+/*
+ * 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 & Anthony Sulistio (Adapted from original Output.java)
+ */
+
+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 FlowBuffer 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 outPacketList_; // store a list of packets
+ private HashMap<Integer, Packet> activeFlows_; // stores a list of active Flows
+ 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 FlowBuffer(String name, double baudRate) throws NullPointerException
+ {
+ super(name);
+ this.baudRate_ = baudRate;
+ link_ = null;
+ outPacketList_ = null;
+ activeFlows_ = 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();
+ outPacketList_ = new Vector();
+ 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 $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()
+ {
+
+ //System.out.println("Hello FlowOutput");
+
+ // 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());
+
+ // handle different types of incoming events
+ switch ( ev.get_tag() )
+ {
+ case GridSimTags.SEND_PACKET:
+ System.out.println(super.get_name() + ".body(): sendPacket() + at time = " + GridSim.clock());
+ sendPacket();
+ break;
+
+ // submit ping() request
+ case GridSimTags.INFOPKT_SUBMIT:
+ System.out.println(super.get_name() + ".body(): sendInfoPacket() + at time = " + GridSim.clock());
+ sendInfoPacket(ev);
+ break;
+
+ // replying ping() request from another entity
+ case GridSimTags.INFOPKT_RETURN:
+ System.out.println(super.get_name() + ".body(): returnInfoPacket() + at time = " + GridSim.clock());
+ returnInfoPacket(ev);
+ break;
+
+ // activate background traffic
+ case GridSimTags.JUNK_PKT:
+ generateBackgroundTraffic();
+ break;
+
+ case GridSimTags.PKT_FORWARD:
+ System.out.println(super.get_name() + ".body(): getDataFromLink() + at time = " + GridSim.clock());
+ getDataFromLink(ev);
+ break;
+
+ // Check if initial flow duration estimation was accurate
+ case GridSimTags.FLOW_HOLD:
+ System.out.println(super.get_name() + ".body(): checkForecast() + at time = " + GridSim.clock());
+ checkForecast(ev);
+ break;
+
+ default:
+ defaultSend(ev, gisID, statID, shutdownID);
+ break;
+ }
+ }
+
+ System.out.println(super.get_name() + ":%%%% Exiting body() at time " +
+ GridSim.clock() );
+ }
+
+ private void checkForecast(Sim_event ev) {
+ int pktID = (Integer) ev.get_data();
+ FlowPacket fp = null;
+
+ System.out.println(super.get_name() + ".checkForecast(): checking pkt id # " + pktID);
+
+ // If flow hasn't already finished
+ if ((fp = (FlowPacket) activeFlows_.get(pktID)) != null) {
+ Object data = fp.getData();
+ IO_data io = new IO_data( data, fp.getSize(),
+ outPort_.get_src());
+ super.sim_schedule(outPort_, GridSimTags.SCHEDULE_NOW, fp.getTag() , io.getData());
+ } else {
+ System.out.println(super.get_name() + ".checkForecast(): pkt id # " + pktID + " already removed");
+
+ }
+
+ }
+
+ /**
+ * 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 FlowPacket.
+ 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 FlowPacket.
+ 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() + " 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 = ( (FlowBuffer)
+ 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
+ outEnque(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
+ outEnque(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
+ outEnque(pkt, GridSimTags.SCHEDULE_NOW);
+ }
+
+ private synchronized void sendInfoPacket(int dest)
+ {
+ // IO_data data = (IO_data) ev.get_data();
+
+ // gets all the relevant info
+ long size = 1500;
+ int destId = dest;
+// / 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,0);
+
+ // set the required info
+ pkt.setLast( super.get_id() );
+ pkt.addHop( outPort_.get_dest() );
+ pkt.addEntryTime( GridSim.clock() );
+ pkt.setOriginalPingSize( 1500 );
+ pkt.setTag(GridSimTags.INFOPKT_SUBMIT);
+
+ pktID_++; // increments packet ID
+ outEnque(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() );
+ outEnque(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 outEnque(Packet pkt, double delay)
+ {
+
+ //if ((pkt instanceof InfoPacket) != true) {
+ // sendInfoPacket(pkt.getDestID());
+ //}
+
+ outPacketList_.add(pkt);
+ if (outPacketList_.size() == 1)
+ {
+ System.out.println(super.get_name() + ".outEnque() 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() + ".outEnque() 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 (outPacketList_ == null || outPacketList_.isEmpty() == true) {
+ return;
+ }
+
+ // submits the first packet in the list
+ Packet np = (Packet) outPacketList_.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;
+ tag = GridSimTags.INFOPKT_SUBMIT;
+ }
+
+ if (np instanceof FlowPacket && np.getTag() == GridSimTags.FLOW_SUBMIT ) {
+ ((FlowPacket)np).addBaudRate( link_.getBaudRate() );
+ ((FlowPacket)np).addLatency( link_.getDelay() );
+ }
+
+
+ // 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 + " time " + GridSim.clock());
+ /****/
+
+ // if the list is not empty, then schedule the next packet in the list
+ if (outPacketList_.isEmpty() != true)
+ {
+ //double delay = np.getSize() * SIZE / link_.getBaudRate();
+ double delay = 0.0;
+ super.sim_schedule(super.get_id(), delay, GridSimTags.SEND_PACKET);
+ }
+ }
+
+ 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;
+ }
+
+ // all except last packet in a data session are null packets
+ 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(),
+ outPort_.get_src());
+ System.out.println(super.get_name() + ".getDataFromLink() Time now " + GridSim.clock()
+ + " bottleneck was " + 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) {
+ 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()));
+
+ // 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 port
+ super.sim_schedule(outPort_, duration, tag,
+ io.getData() );
+ }
+
+
+ }
+ }
+ }
+
+ private void processPingRequest(InfoPacket pkt)
+ {
+ // add more information to ping() packet
+ pkt.addHop( outPort_.get_dest() );
+ pkt.addEntryTime( GridSim.clock() );
+
+ IO_data io = new IO_data( pkt, pkt.getSize(), outPort_.get_dest() );
+
+ // send this ping() packet to the entity
+ super.sim_schedule(outPort_, 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-02-19 02:38:20
|
Revision: 111
http://gridsim.svn.sourceforge.net/gridsim/?rev=111&view=rev
Author: brobergj
Date: 2008-02-18 18:38:19 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*Re-coded to support FlowBuffer instead of FlowInput/FlowOutput
*Added registerFlow() and deregisterFlow() functionality
*Update flow duration code needs to be fixed still
*Added additional toString() information
Added Paths:
-----------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java
Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java (rev 0)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-19 02:38:19 UTC (rev 111)
@@ -0,0 +1,478 @@
+/*
+ * ** Network and Service Differentiation Extensions to GridSim 4.0 **
+ *
+ * Author: James Broberg
+ *
+ * August 2007
+ *
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * FlowLink.java - Simulates a network link
+ *
+ */
+
+package gridsim.net.flow;
+
+import eduni.simjava.*;
+import gridsim.*;
+
+import java.util.*;
+import gridsim.net.Link;
+import gridsim.net.Packet;
+import gridsim.net.flow.FlowPacket;
+
+
+/**
+ * This class enables flow level networking over a shared link. It is based
+ * on SimpleLink.java by Gokul Poduval & Chen-Khong Tham
+ *
+ * @invariant $none
+ * @since GridSim Toolkit 4.0
+ * @author James Broberg, The University of Melbourne
+ */
+
+public class FlowLink extends Link
+{
+ private Vector q_;
+ private HashMap flows_;
+ private double lastUpdateTime_; // a timer to denote the last update time
+ private int inEnd1_;
+ private int outEnd1_;
+ private int inEnd2_;
+ private int outEnd2_;
+
+
+ /**
+ * Constructs a Link which simulates a physical link between two entities.
+ *
+ * @param name Name of this Link
+ * @param baudRate baud rate of this link (bits/s)
+ * @param propDelay Propogation delay of the Link in milli seconds
+ * @param MTU Maximum Transmission Unit of the Link in bytes.
+ * Packets which are larger than the MTU should be split
+ * up into MTU size units. <br>
+ * For e.g. a 1024 byte packet trying to cross a 576 byte
+ * MTU link should get split into 2 packets of 576 bytes
+ * and 448 bytes.
+ * @throws NullPointerException This happens when name is empty or null
+ * @throws ParameterException This happens for the following conditions:
+ * <ul>
+ * <li> name is null
+ * <li> baudRate <= 0
+ * <li> propDelay <= 0
+ * <li> MTU <= 0
+ * </ul>
+ *
+ * @pre name != null
+ * @pre baudRate > 0
+ * @pre propDelay > 0
+ * @pre MTU > 0
+ * @post $none
+ */
+ public FlowLink(String name, double baudRate, double propDelay, int MTU)
+ throws ParameterException, NullPointerException
+ {
+ super(name, baudRate, propDelay, MTU);
+ init();
+ }
+
+ /**
+ * Constructs a link with some default parameters. It simulates a link with
+ * a default value of baud rate, propagation delay and MTU.
+ *
+ * @param name Name of this Link
+ * @throws NullPointerException This happens when name is empty or null
+ * @throws ParameterException This happens when the given name is empty
+ * @see gridsim.net.Link#DEFAULT_BAUD_RATE
+ * @see gridsim.net.Link#DEFAULT_PROP_DELAY
+ * @see gridsim.net.Link#DEFAULT_MTU
+ * @pre name != null
+ * @post $none
+ */
+/* public FlowLink(String name) throws ParameterException,
+ NullPointerException
+ {
+ super(name, Link.DEFAULT_BAUD_RATE, Link.DEFAULT_PROP_DELAY,
+ Link.DEFAULT_MTU);
+
+ init();
+ }*/
+
+ /**
+ * Initialises all attributes
+ * @pre $none
+ * @post $none
+ */
+ private void init()
+ {
+ lastUpdateTime_ = 0.0;
+ q_ = new Vector();
+ flows_ = new HashMap();
+ inEnd1_ = -1;
+ outEnd1_ = -1;
+ inEnd2_ = -1;
+ outEnd2_ = -1;
+ }
+
+ /**
+ * Connects one entity to another via this link
+ * @param end1 an entity
+ * @param end2 an entity
+ * @pre end1 != null
+ * @pre end2 != null
+ * @post $none
+ */
+ public void attach(Sim_entity end1, Sim_entity end2)
+ {
+ if (end1 == null || end2 == null)
+ {
+ System.out.println(super.get_name() + ".attach(): Warning - " +
+ "one or both entities are null.");
+ return;
+ }
+
+ System.out.println(super.get_name() + ".attach(): " + end1.get_name() +
+ " " + end2.get_name());
+ inEnd1_ = GridSim.getEntityId( "Output_" + end1.get_name() );
+ outEnd1_ = GridSim.getEntityId( "Output_" + end1.get_name() );
+
+ System.out.println(super.get_name() + ".attach(): " + end1.get_id() + " " + end2.get_id());
+
+
+ // if end1 is a router/gateway with no Input and Output port
+ if (inEnd1_ == -1 || outEnd1_ == -1)
+ {
+ inEnd1_ = end1.get_id();
+ outEnd1_ = end1.get_id();
+ }
+
+ inEnd2_ = GridSim.getEntityId( "Output_" + end2.get_name() );
+ outEnd2_ = GridSim.getEntityId( "Output_" + end2.get_name() );
+
+ // if end2 is a router/gateway with no Input and Output port
+ if (inEnd2_ == -1 || outEnd2_ == -1)
+ {
+ inEnd2_ = end2.get_id();
+ outEnd2_ = end2.get_id();
+ }
+ }
+
+ /**
+ * Connects one entity to another via this link
+ * @param end1 an Entity name
+ * @param end2 an Entity name
+ * @pre end1 != null
+ * @pre end2 != null
+ * @post $none
+ */
+ public void attach(String end1, String end2)
+ {
+ if (end1 == null || end2 == null)
+ {
+ System.out.println(super.get_name() + ".attach(): Warning - " +
+ "can not connect since one or both entities are null.");
+ return;
+ }
+
+ if (end1.length() == 0 || end2.length() == 0)
+ {
+ System.out.println(super.get_name() + ".attach(): Warning - " +
+ "can not connect since one or both entities are null.");
+ return;
+ }
+
+ inEnd1_ = GridSim.getEntityId("Output_" + end1);
+ outEnd1_ = GridSim.getEntityId("Output_" + end1);
+
+ // if end1 is a router/gateway with no Input and Output port
+ if (inEnd1_ == -1 || outEnd1_ == -1)
+ {
+ inEnd1_ = GridSim.getEntityId(end1);
+ outEnd1_ = inEnd1_;
+ }
+
+ inEnd2_ = GridSim.getEntityId("Output_" + end2);
+ outEnd2_ = GridSim.getEntityId("Output_" + end2);
+
+ // if end1 is a router/gateway with no Input and Output port
+ if (inEnd2_ == -1 || outEnd2_ == -1)
+ {
+ inEnd2_ = GridSim.getEntityId(end1);
+ outEnd2_ = inEnd2_;
+ }
+ }
+
+ /**
+ * Handles external events that are coming to this link.
+ * @pre $none
+ * @post $none
+ */
+ public void body()
+ {
+ // register oneself to the system GIS
+ super.sim_schedule(GridSim.getGridInfoServiceEntityId(),
+ GridSimTags.SCHEDULE_NOW, GridSimTags.REGISTER_LINK,
+ new Integer(super.get_id()) );
+
+ Sim_event ev = new Sim_event();
+ while ( Sim_system.running() )
+ {
+ super.sim_get_next(ev);
+
+ // if the simulation finishes then exit the loop
+ if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) {
+ break;
+ }
+
+ // process the received event
+ System.out.println(super.get_name() + ".body(): processEvent() + at time = " + GridSim.clock());
+ processEvent(ev);
+ sim_completed(ev);
+ }
+
+ while(sim_waiting() > 0)
+ {
+ // wait for event and ignore
+ System.out.println(super.get_name() + ".body(): Ignore !!");
+ sim_get_next(ev);
+ }
+
+ System.out.println(super.get_name() + ":%%%% Exiting body() at time " +
+ GridSim.clock() );
+ }
+
+ /**
+ * Processes incoming events
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ private void processEvent(Sim_event ev)
+ {
+ switch ( ev.get_tag() )
+ {
+ case GridSimTags.PKT_FORWARD: // for normal packets
+ case GridSimTags.JUNK_PKT: // for background traffic
+ System.out.println(super.get_name() + ".processEvent(): enque() + at time = " + GridSim.clock());
+ enque(ev);
+ break;
+
+ case GridSimTags.INSIGNIFICANT:
+ System.out.println(super.get_name() + ".processEvent(): processInternalEvent() + at time = " + GridSim.clock());
+ processInternalEvent();
+ break;
+
+ default:
+ System.out.println(super.get_name() + ".body(): Warning - " +
+ "unable to handle request from GridSimTags " +
+ "with constant number " + ev.get_tag());
+ break;
+ }
+ }
+
+ /**
+ * Sends an internal event to itself for a certain time period
+ * @param time the delay time
+ * @pre time >= 0
+ * @post $none
+ */
+ private synchronized boolean sendInternalEvent(double time)
+ {
+ System.out.println(super.get_name() + " sendInternalEvent(): called at time = " + GridSim.clock());
+
+ if (time < 0.0) {
+ System.out.println(super.get_name() + " sendInternalEvent(): false at time = " + GridSim.clock());
+ return false;
+ }
+
+ System.out.println(super.get_name() + " sendInternalEvent(): scheduled for = " + time + " from now");
+ super.sim_schedule(super.get_id(), time, GridSimTags.INSIGNIFICANT);
+ return true;
+ }
+
+ /**
+ * Processes internal events
+ * @pre $none
+ * @post $none
+ */
+ private synchronized void processInternalEvent()
+ {
+
+ System.out.println(super.get_name() + "processInternalEvent(): " + GridSim.clock());
+
+ // this is a constraint that prevents an infinite loop
+ // Compare between 2 floating point numbers. This might be incorrect
+ // for some hardware platform.
+ if ( lastUpdateTime_ == GridSim.clock() ) {
+ return;
+ }
+
+ lastUpdateTime_ = GridSim.clock();
+
+ if (q_.size() == 0) {
+ return;
+ }
+ else if (q_.size() == 1) {
+ deque( (Packet) q_.remove(0) );
+ }
+ else
+ {
+ deque( (Packet)q_.remove(0) );
+ sendInternalEvent(super.delay_ / super.MILLI_SEC); // delay in ms
+
+ }
+
+ System.out.println("Super.delay_ is " + super.delay_);
+ System.out.println(super.get_name() + " processInternalEvent(): done at time = " + GridSim.clock());
+ }
+
+ /**
+ * Puts an event into a queue and sends an internal event to itself
+ * @param ev a Sim_event object
+ * @pre ev != null
+ * @post $none
+ */
+ private synchronized void enque(Sim_event ev)
+ {
+ System.out.println(super.get_name() + " enque() + at time = " + GridSim.clock());
+ q_.add( ev.get_data() );
+ if (q_.size() == 1) {
+ sendInternalEvent(super.delay_ / super.MILLI_SEC); // delay in ms
+ }
+
+ if (((Packet)ev.get_data()).getTag() == GridSimTags.FLOW_SUBMIT) {
+ registerFlow((Packet)ev.get_data());
+ }
+ }
+
+ /**
+ * Sends a packet to the next destination
+ * @param np a packet
+ * @pre np != null
+ * @post $none
+ */
+ private synchronized void deque(Packet np)
+ {
+ int dest = getNextHop(np);
+ if (dest == -1) {
+ return;
+ }
+
+ // other side is a Sim_entity
+ int tag = 0;
+ if (dest == outEnd2_ || dest == outEnd1_)
+ {
+ // for junk packets only
+ if (np.getTag() == GridSimTags.JUNK_PKT) {
+ tag = GridSimTags.JUNK_PKT;
+ }
+ // for other packets
+ else {
+ tag = GridSimTags.PKT_FORWARD;
+ }
+ }
+ // other side is a GridSim entity
+ else {
+ tag = np.getTag();
+ }
+
+ if (np.getTag() == GridSimTags.FLOW_RETURN) {
+ System.out.println("Dereg flow # " + np.getID() +" here");
+ deregisterFlow(np);
+ }
+
+ // sends the packet
+ super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np);
+ System.out.println(super.get_name() + " deque() + at time = " + GridSim.clock());
+
+ }
+
+ /**
+ * Determines which end to send the event to
+ * since sending entities are of the form Output_entityName.
+ * We need to check whether the source name ends with either end1 or end2
+ * the other end is the destination
+ * @param np a packet
+ * @pre np != null
+ * @post $none
+ */
+ private synchronized int getNextHop(Packet np)
+ {
+ int dest = -1;
+ int src = np.getLast();
+
+ // check if source is from outEnd1_
+ if (src == outEnd1_) {
+ dest = inEnd2_;
+ }
+ // or source is from outEnd2_
+ else if (src == outEnd2_) {
+ dest = inEnd1_;
+ }
+
+ return dest;
+ }
+
+ /**
+ * Registers active flow to link, and link to flow
+ * active flows
+ * @pre $none
+ * @post $none
+ */
+ private synchronized void registerFlow(Packet np) {
+ System.out.println(super.get_name() + ".registerFlow(): registering flow #" + np.getID()
+ + " total of " + flows_.size() + " flows");
+
+ // Add flow to link
+ flows_.put(np.getID(), np );
+
+ // Register link to flow
+ ((FlowPacket)np).addLink(this);
+
+ // Check if this affects any existing flows
+ Iterator<Integer> flowsIter = flows_.keySet().iterator();
+ while(flowsIter.hasNext()) {
+ // If change in bandwidth affects an existing flow i.e. is < current bottleneck
+ if (this.getBaudRate() < ((FlowPacket) flows_.get(flowsIter.next())).getBandwidth_() &&
+ ((FlowPacket) flows_.get(flowsIter.next())).getID() != np.getID()) {
+ // Need to notify flow
+ System.out.println(super.get_name() + ".registerFlow(): flow #" + np.getID()
+ + " bottleneck now " + this.getBaudRate() + " at time " + GridSim.clock());
+ // I can notify directly as I have know the destId's!!!!
+ }
+ }
+
+
+
+ }
+
+ private synchronized void deregisterFlow(Packet np) {
+ FlowPacket fp = null;
+ if ((fp = (FlowPacket) flows_.remove(np.getID())) != null) {
+
+ System.out.println(super.get_name() + ".deregisterFlow() success flow # " + np.getID()
+ + " " + fp.getBandwidth_());
+ }
+ }
+
+ /**
+ * Returns available baudRate depending on number of
+ * active flows
+ * @pre $none
+ * @post $none
+ */
+ public synchronized double getBaudRate() {
+ if (flows_.size() != 0) {
+ System.out.println(super.get_name() + ".getBaudRate() Getting latest baud! " + (super.baudRate_)/(flows_.size()));
+ return (super.baudRate_)/(flows_.size());
+ } else {
+ System.out.println(super.get_name() + ".getBaudRate() Getting latest baud! " + (super.baudRate_));
+ return super.baudRate_;
+ }
+
+ }
+
+
+
+} // 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-19 02:37:00
|
Revision: 110
http://gridsim.svn.sourceforge.net/gridsim/?rev=110&view=rev
Author: brobergj
Date: 2008-02-18 18:37:05 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*FlowPacket encapsulates a network Flow, and collects information as it passes from source to destination
Added Paths:
-----------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java
Added: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java (rev 0)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowPacket.java 2008-02-19 02:37:05 UTC (rev 110)
@@ -0,0 +1,398 @@
+/*
+ * ** Network and Service Differentiation Extensions to GridSim 3.0 **
+ *
+ * Author: James Broberg
+ *
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * FlowPacket.java - Implementation of a Flow Packet.
+ *
+ */
+
+package gridsim.net.flow;
+
+import java.util.Vector;
+
+import gridsim.*;
+import gridsim.net.Link;
+import gridsim.net.Packet;
+import eduni.simjava.*;
+
+
+/**
+ * Structure of a packet used to encapsulate flow passing through the network.
+ *
+ * @invariant $none
+ * @since GridSim Toolkit 4.0
+ * @author James Broberg
+ */
+public class FlowPacket implements Packet
+{
+ private int destID; // where the packet wants to go
+ private int srcID; // sender ID
+ private long size; // packet size (for calculating transmission time)
+ private long origSize; // original packet size
+ private Object obj; // the actual object, the type depends on context
+
+ private double bandwidth_; // Bottleneck baud rate
+
+ private Vector baudRates_; // list of entity's baud rate
+
+ private Vector links_;
+
+ // Sum of latency (delay) on path
+ private double latency;
+
+ // original tag with which the encapsulated object was submitted
+ private int tag;
+
+ // the last entity encountered by the object, used to determine direction
+ private int last;
+
+ private String desc_; // description of this packet
+ private int classType; // level of service for this packet
+ private int pktNum; // packet num in one group
+ private int totalPkts; // total num of packet that belongs to a group
+ private int pktID_; // a unique packet ID issued by an entity
+
+ /**
+ * Constructs a network packet for data that fits into a single network
+ * packet.
+ *
+ * @param data The data to be encapsulated.
+ * @param pktID The ID of this packet
+ * @param size The size of the data (in bytes)
+ * @param tag The original tag which was used with the data, its
+ * reapplied when the data is extracted from the NetPacket.
+ * @param srcID The id of the entity where the packet was created.
+ * @param destID The destination to which the packet has to be sent.
+ * @pre $none
+ * @post $none
+ */
+ public FlowPacket(Object data, int pktID, long size, int tag, int srcID,
+ int destID)
+ {
+ this.obj = data ;
+ this.size = size ;
+ this.origSize = size ;
+ this.tag = tag ;
+ this.destID = destID;
+ this.srcID = srcID ;
+ this.last = srcID ;
+ this.pktID_ = pktID;
+ this.classType = 0 ;
+ this.pktNum = 1;
+ this.totalPkts = 1;
+ this.desc_ = null;
+ this.latency = 0.0;
+ this.bandwidth_ = Double.MAX_VALUE;
+ this.baudRates_ = new Vector();
+
+ }
+
+ /**
+ * This is used to construct a packet that is one in a series. This happens
+ * when a large piece of data is required to be brokwn down into smaller
+ * chunks so that they can traverse of links that only support a certain
+ * MTU. It also allows setting of a classtype so that network schedulers
+ * maybe provide differntial service to it.
+ *
+ * @param data The data to be encapsulated.
+ * @param pktID The ID of this packet
+ * @param size The size of the data (in bytes)
+ * @param tag The original tag which was used with the data, its
+ * reapplied when the data is extracted from the NetPacket.
+ * @param srcID The id of the entity where the packet was created.
+ * @param destID The destination to which the packet has to be sent.
+ * @param netServiceType the network class type of this packet
+ * @param pktNum The packet number of this packet in its series. If there
+ * are 10 packets, they should be numbered from 1 to 10.
+ * @param totalPkts The total number of packets that the original data was
+ * split into. This is used by the receiver to confirm that
+ * all packets have been received.
+ * @pre $none
+ * @post $none
+ */
+ public FlowPacket(Object data, int pktID, long size, int tag, int srcID,
+ int destID, int netServiceType, int pktNum, int totalPkts)
+ {
+ this.obj = data;
+ this.size = size;
+ this.tag = tag;
+ this.destID = destID;
+ this.srcID = srcID;
+ this.last = srcID;
+ this.classType = netServiceType;
+ this.pktNum = pktNum;
+ this.pktID_ = pktID;
+ this.totalPkts = totalPkts;
+ this.desc_ = null;
+ this.latency = 0.0;
+ this.bandwidth_ = -1;
+ this.baudRates_ = new Vector();
+
+ }
+
+ /**
+ * Returns a description of this packet
+ * @return a description of this packet
+ * @pre $none
+ * @post $none
+ */
+ public String toString()
+ {
+ if (desc_ == null)
+ {
+ StringBuffer sb = new StringBuffer("Packet #");
+ sb.append(pktNum);
+ sb.append(", out of, ");
+ sb.append(totalPkts);
+ sb.append(", with id, ");
+ sb.append(pktID_);
+ sb.append(", from, ");
+ sb.append( GridSim.getEntityName(srcID) );
+ sb.append(", to, ");
+ sb.append( GridSim.getEntityName(destID) );
+ sb.append(", tag, ");
+
+ if (tag == GridSimTags.PKT_FORWARD) {
+ sb.append("GridSimTags.PKT_FORWARD");
+ }
+ else if (tag == GridSimTags.JUNK_PKT) {
+ sb.append("GridSimTags.JUNK_PKT");
+ } else if (tag == GridSimTags.FLOW_SUBMIT) {
+ sb.append("GridSimTags.FLOW_SUBMIT");
+ } else if (tag == GridSimTags.FLOW_RETURN) {
+ sb.append("GridSimTags.FLOW_RETURN");
+ } else {
+ sb.append(tag);
+ }
+
+ desc_ = sb.toString();
+ }
+
+ return desc_;
+ }
+
+ /**
+ * Returns the data encapsulated in this NetPacket
+ * @return data encapsulated in this packet
+ * @pre $none
+ * @post $none
+ */
+ public Object getData() {
+ return obj;
+ }
+
+ /**
+ * Returns the source ID of this packet. The source ID is where the
+ * NetPacket was originally created.
+ *
+ * @return the source id.
+ * @pre $none
+ * @post $none
+ */
+ public int getSrcID() {
+ return srcID;
+ }
+
+ /**
+ * Returns the ID of this packet
+ * @return packet ID
+ * @pre $none
+ * @post $none
+ */
+ public int getID() {
+ return pktID_;
+ }
+
+ /**
+ * Modifies the data encapsulated in this NetPacket.
+ * @param data the packet's data
+ * @pre $none
+ * @post $none
+ */
+ public void setData(Object data) {
+ this.obj = data;
+ }
+
+ /**
+ * Gets the size of this packet
+ * @return the packet size
+ * @pre $none
+ * @post $none
+ */
+ public long getSize() {
+ return size;
+ }
+
+ /**
+ * Gets the original size of this packet
+ * @return the packet size
+ * @pre $none
+ * @post $none
+ */
+ public long getOrigSize() {
+ return origSize;
+ }
+
+ /**
+ * Sets the packet size
+ * @param size the packet size
+ * @return <tt>true</tt> if it is successful, <tt>false</tt> otherwise
+ * @pre size >= 0
+ * @post $none
+ */
+ public boolean setSize(long size)
+ {
+ if (size < 0) {
+ return false;
+ }
+
+ this.size = size;
+ return true;
+ }
+
+ /**
+ * Returns the tag associated originally with data that was encapsulated in
+ * this packet.
+ *
+ * @return the tag of the data contained.
+ * @pre $none
+ * @post $none
+ */
+ public int getTag() {
+ return tag;
+ }
+
+ /**
+ * Returns the destination ID of this packet
+ *
+ * @return destination ID
+ * @pre $none
+ * @post $none
+ */
+ public int getDestID() {
+ return destID;
+ }
+
+ /**
+ * Sets the destination id of this packet
+ * @param id the destination id
+ * @pre id >= 0
+ * @post $none
+ */
+ public void setDestID(int id) {
+ this.destID = id;
+ }
+
+ /**
+ * Sets the last hop that this NetPacket traversed. This is used to
+ * determine the next hop at routers. Only routers and hosts/GridResources
+ * set this, links do not modify it.
+ * @param last the entity ID from the last hop
+ * @pre last >= 0
+ * @post $none
+ */
+ public void setLast(int last) {
+ this.last = last;
+ }
+
+ /**
+ * Returns the ID of the last hop that this packet traversed. This could be
+ * the ID of a router, host or GridResource.
+ *
+ * @return ID of the last hop
+ * @pre $none
+ * @post $none
+ */
+ public int getLast() {
+ return last;
+ }
+
+ /**
+ * Sets the network class type of this packet, so that it can receive
+ * differentiated services.
+ * @param netServiceType a network service type
+ * @pre netServiceType >= 0
+ * @post $none
+ */
+ public void setNetServiceType(int netServiceType) {
+ this.classType = netServiceType;
+ }
+
+ /**
+ * Returns the class type of this packet. Used by routers etc. to determine
+ * the level of service that this packet should obtain.
+ *
+ * @return the class of this packet
+ * @pre $none
+ * @post $none
+ */
+ public int getNetServiceType() {
+ return classType;
+ }
+
+ /**
+ * Returns the serial number of this packet.
+ *
+ * @return packet number
+ * @pre $none
+ * @post $none
+ */
+ public int getPacketNum() {
+ return pktNum;
+ }
+
+ /**
+ * Returns the total number of packets in this stream. A stream of
+ * packets is sent whenever the data is too big to be sent as one
+ * packet.
+ *
+ * @return total number of packets in this stream.
+ * @pre $none
+ * @post $none
+ */
+ public int getTotalPackets() {
+ return totalPkts;
+ }
+
+ public double getLatency() {
+ return latency;
+ }
+
+ public void addLatency(double latency) {
+ this.latency += latency;
+ }
+
+ public void addBaudRate(double baudRate)
+ {
+ if (baudRates_ == null) {
+ return;
+ }
+
+ baudRates_.add( new Double(baudRate) );
+ if (bandwidth_ < 0 || baudRate < this.bandwidth_) {
+ this.bandwidth_ = baudRate;
+ }
+ }
+
+ public double getBandwidth_() {
+ return bandwidth_;
+ }
+
+ public void setBandwidth_(double bandwidth_) {
+ this.bandwidth_ = bandwidth_;
+ }
+
+ public void addLink(Link link)
+ {
+ if (links_ == null) {
+ return;
+ }
+
+ links_.add( link );
+ }
+
+} // 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-19 02:30:39
|
Revision: 109
http://gridsim.svn.sourceforge.net/gridsim/?rev=109&view=rev
Author: brobergj
Date: 2008-02-18 18:30:40 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*Re-coded to support FlowBuffer instead of FlowInput/FlowOutput
*Added registerFlow() and deregisterFlow() functionality
*Update flow duration code needs to be fixed still
Removed Paths:
-------------
branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java
Deleted: branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-19 00:34:06 UTC (rev 108)
+++ branches/gridsim4.0-branch2/source/gridsim/net/flow/FlowLink.java 2008-02-19 02:30:40 UTC (rev 109)
@@ -1,379 +0,0 @@
-/*
- * ** Network and Service Differentiation Extensions to GridSim 4.0 **
- *
- * James Broberg
- *
- * August 2007
- *
- * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
- *
- * FlowLink.java - Simulates a network link
- *
- */
-
-package gridsim.net.flow;
-
-import eduni.simjava.*;
-import gridsim.*;
-import gridsim.net.Link;
-import gridsim.net.Packet;
-
-import java.util.*;
-
-
-/**
- * This class enables flow level networking over a shared link. It is based
- * on SimpleLink.java by Gokul Poduval & Chen-Khong Tham
- *
- * @invariant $none
- * @since GridSim Toolkit 4.0
- * @author James Broberg, The University of Melbourne
- */
-public class FlowLink extends Link
-{
- private Vector q_;
- private double lastUpdateTime_; // a timer to denote the last update time
- private int inEnd1_;
- private int outEnd1_;
- private int inEnd2_;
- private int outEnd2_;
-
-
- /**
- * Constructs a Link which simulates a physical link between two entities.
- *
- * @param name Name of this Link
- * @param baudRate baud rate of this link (bits/s)
- * @param propDelay Propogation delay of the Link in milli seconds
- * @param MTU Maximum Transmission Unit of the Link in bytes.
- * Packets which are larger than the MTU should be split
- * up into MTU size units. <br>
- * For e.g. a 1024 byte packet trying to cross a 576 byte
- * MTU link should get split into 2 packets of 576 bytes
- * and 448 bytes.
- * @throws NullPointerException This happens when name is empty or null
- * @throws ParameterException This happens for the following conditions:
- * <ul>
- * <li> name is null
- * <li> baudRate <= 0
- * <li> propDelay <= 0
- * <li> MTU <= 0
- * </ul>
- *
- * @pre name != null
- * @pre baudRate > 0
- * @pre propDelay > 0
- * @pre MTU > 0
- * @post $none
- */
- public FlowLink(String name, double baudRate, double propDelay, int MTU)
- throws ParameterException, NullPointerException
- {
- super(name, baudRate, propDelay, MTU);
- init();
- }
-
- /**
- * Constructs a link with some default parameters. It simulates a link with
- * a default value of baud rate, propagation delay and MTU.
- *
- * @param name Name of this Link
- * @throws NullPointerException This happens when name is empty or null
- * @throws ParameterException This happens when the given name is empty
- * @see gridsim.net.Link#DEFAULT_BAUD_RATE
- * @see gridsim.net.Link#DEFAULT_PROP_DELAY
- * @see gridsim.net.Link#DEFAULT_MTU
- * @pre name != null
- * @post $none
- */
- public FlowLink(String name) throws ParameterException,
- NullPointerException
- {
- super(name, Link.DEFAULT_BAUD_RATE, Link.DEFAULT_PROP_DELAY,
- Link.DEFAULT_MTU);
-
- init();
- }
-
- /**
- * Initialises all attributes
- * @pre $none
- * @post $none
- */
- private void init()
- {
- lastUpdateTime_ = 0.0;
- q_ = new Vector();
- inEnd1_ = -1;
- outEnd1_ = -1;
- inEnd2_ = -1;
- outEnd2_ = -1;
- }
-
- /**
- * Connects one entity to another via this link
- * @param end1 an entity
- * @param end2 an entity
- * @pre end1 != null
- * @pre end2 != null
- * @post $none
- */
- public void attach(Sim_entity end1, Sim_entity end2)
- {
- if (end1 == null || end2 == null)
- {
- System.out.println(super.get_name() + ".attach(): Warning - " +
- "one or both entities are null.");
- return;
- }
-
- inEnd1_ = GridSim.getEntityId( "Input_" + end1.get_name() );
- outEnd1_ = GridSim.getEntityId( "Output_" + end1.get_name() );
-
- // if end1 is a router/gateway with no Input and Output port
- if (inEnd1_ == -1 || outEnd1_ == -1)
- {
- inEnd1_ = end1.get_id();
- outEnd1_ = end1.get_id();
- }
-
- inEnd2_ = GridSim.getEntityId( "Input_" + end2.get_name() );
- outEnd2_ = GridSim.getEntityId( "Output_" + end2.get_name() );
-
- // if end1 is a router/gateway with no Input and Output port
- if (inEnd2_ == -1 || outEnd2_ == -1)
- {
- inEnd2_ = end2.get_id();
- outEnd2_ = end2.get_id();
- }
- }
-
- /**
- * Connects one entity to another via this link
- * @param end1 an Entity name
- * @param end2 an Entity name
- * @pre end1 != null
- * @pre end2 != null
- * @post $none
- */
- public void attach(String end1, String end2)
- {
- if (end1 == null || end2 == null)
- {
- System.out.println(super.get_name() + ".attach(): Warning - " +
- "can not connect since one or both entities are null.");
- return;
- }
-
- if (end1.length() == 0 || end2.length() == 0)
- {
- System.out.println(super.get_name() + ".attach(): Warning - " +
- "can not connect since one or both entities are null.");
- return;
- }
-
- inEnd1_ = GridSim.getEntityId("Input_" + end1);
- outEnd1_ = GridSim.getEntityId("Output_" + end1);
-
- // if end1 is a router/gateway with no Input and Output port
- if (inEnd1_ == -1 || outEnd1_ == -1)
- {
- inEnd1_ = GridSim.getEntityId(end1);
- outEnd1_ = inEnd1_;
- }
-
- inEnd2_ = GridSim.getEntityId("Input_" + end2);
- outEnd2_ = GridSim.getEntityId("Output_" + end2);
-
- // if end1 is a router/gateway with no Input and Output port
- if (inEnd2_ == -1 || outEnd2_ == -1)
- {
- inEnd2_ = GridSim.getEntityId(end1);
- outEnd2_ = inEnd2_;
- }
- }
-
- /**
- * Handles external events that are coming to this link.
- * @pre $none
- * @post $none
- */
- public void body()
- {
- // register oneself to the system GIS
- super.sim_schedule(GridSim.getGridInfoServiceEntityId(),
- GridSimTags.SCHEDULE_NOW, GridSimTags.REGISTER_LINK,
- new Integer(super.get_id()) );
-
- Sim_event ev = new Sim_event();
- while ( Sim_system.running() )
- {
- super.sim_get_next(ev);
-
- // if the simulation finishes then exit the loop
- if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) {
- break;
- }
-
- // process the received event
- processEvent(ev);
- sim_completed(ev);
- }
-
- while(sim_waiting() > 0)
- {
- // wait for event and ignore
- System.out.println(super.get_name() + ".body(): Ignore !!");
- sim_get_next(ev);
- }
- }
-
- /**
- * Processes incoming events
- * @param ev a Sim_event object
- * @pre ev != null
- * @post $none
- */
- private void processEvent(Sim_event ev)
- {
- switch ( ev.get_tag() )
- {
- case GridSimTags.PKT_FORWARD: // for normal packets
- case GridSimTags.JUNK_PKT: // for background traffic
- enque(ev);
- break;
-
- case GridSimTags.INSIGNIFICANT:
- processInternalEvent();
- break;
-
- default:
- System.out.println(super.get_name() + ".body(): Warning - " +
- "unable to handle request from GridSimTags " +
- "with constant number " + ev.get_tag());
- break;
- }
- }
-
- /**
- * Sends an internal event to itself for a certain time period
- * @param time the delay time
- * @pre time >= 0
- * @post $none
- */
- private synchronized boolean sendInternalEvent(double time)
- {
- if (time < 0.0) {
- return false;
- }
-
- super.sim_schedule(super.get_id(), time, GridSimTags.INSIGNIFICANT);
- return true;
- }
-
- /**
- * Processes internal events
- * @pre $none
- * @post $none
- */
- private synchronized void processInternalEvent()
- {
- // this is a constraint that prevents an infinite loop
- // Compare between 2 floating point numbers. This might be incorrect
- // for some hardware platform.
- if ( lastUpdateTime_ == GridSim.clock() ) {
- return;
- }
-
- lastUpdateTime_ = GridSim.clock();
-
- if (q_.size() == 0) {
- return;
- }
- else if (q_.size() == 1) {
- deque( (Packet) q_.remove(0) );
- }
- else
- {
- deque( (Packet)q_.remove(0) );
- sendInternalEvent(super.delay_ / super.MILLI_SEC); // delay in ms
- }
- }
-
- /**
- * Puts an event into a queue and sends an internal event to itself
- * @param ev a Sim_event object
- * @pre ev != null
- * @post $none
- */
- private synchronized void enque(Sim_event ev)
- {
- q_.add( ev.get_data() );
- if (q_.size() == 1) {
- sendInternalEvent(super.delay_ / super.MILLI_SEC); // delay in ms
- }
- }
-
- /**
- * Sends a packet to the next destination
- * @param np a packet
- * @pre np != null
- * @post $none
- */
- private synchronized void deque(Packet np)
- {
- int dest = getNextHop(np);
- if (dest == -1) {
- return;
- }
-
- // other side is a Sim_entity
- int tag = 0;
- if (dest == outEnd2_ || dest == outEnd1_)
- {
- // for junk packets only
- if (np.getTag() == GridSimTags.JUNK_PKT) {
- tag = GridSimTags.JUNK_PKT;
- }
- // for other packets
- else {
- tag = GridSimTags.PKT_FORWARD;
- }
- }
- // other side is a GridSim entity
- else {
- tag = np.getTag();
- }
-
- // sends the packet
- super.sim_schedule(dest, GridSimTags.SCHEDULE_NOW, tag, np);
- }
-
- /**
- * Determines which end to send the event to
- * since sending entities are of the form Output_entityName.
- * We need to check whether the source name ends with either end1 or end2
- * the other end is the destination
- * @param np a packet
- * @pre np != null
- * @post $none
- */
- private synchronized int getNextHop(Packet np)
- {
- int dest = -1;
- int src = np.getLast();
-
- // check if source is from outEnd1_
- if (src == outEnd1_) {
- dest = inEnd2_;
- }
- // or source is from outEnd2_
- else if (src == outEnd2_) {
- dest = inEnd1_;
- }
-
- return dest;
- }
-
-} // 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-19 00:34:06
|
Revision: 108
http://gridsim.svn.sourceforge.net/gridsim/?rev=108&view=rev
Author: brobergj
Date: 2008-02-18 16:34:06 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*Added tags required for GridSim flow implementation
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/GridSimTags.java
Modified: branches/gridsim4.0-branch2/source/gridsim/GridSimTags.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/GridSimTags.java 2008-02-19 00:31:31 UTC (rev 107)
+++ branches/gridsim4.0-branch2/source/gridsim/GridSimTags.java 2008-02-19 00:34:06 UTC (rev 108)
@@ -33,23 +33,35 @@
// TODO: new additions
public static final int NET_PACKET_LEVEL = NETBASE + 11;
- // TODO: NET_FLOW_LEVEL should default to NET_FLOW_LEVEL_INV_RTT_BOUND
+
public static final int NET_FLOW_LEVEL = NETBASE + 12;
- public static final int NET_BUFFER_PACKET_LEVEL = NETBASE + 13;
- // TODO: different flow sharing models
+ // Denotes flow en-route to destination
+ public static final int FLOW_SUBMIT = NETBASE + 13;
+
+ // Denotes flow acknowledgement en-route to source
+ public static final int FLOW_RETURN = NETBASE + 14;
+
+ // Internal message to check forecast of flow duration
+ public static final int FLOW_HOLD = NETBASE + 15;
+
+ // Message to update forecast of flow duration
+ public static final int FLOW_UPDATE = NETBASE + 16;
+
+ public static final int NET_BUFFER_PACKET_LEVEL = NETBASE + 17;
+
+ // TODO: different flow sharing models - not sure if I will need these
// INV-LAT flows are weighted proportionally to the bottleneck latency
- public static final int NET_FLOW_LEVEL_INV_LAT = NETBASE + 14;
+ // public static final int NET_FLOW_LEVEL_INV_LAT = NETBASE + 15;
// INV-LAT-BOUND flows are weighted proportionally to the bottleneck latency
// with bounded bandwidth availability
- public static final int NET_FLOW_LEVEL_INV_LAT_BOUND = NETBASE + 15;
// INV-RTT flows are weighted proportionally to the bottleneck RTT
- public static final int NET_FLOW_LEVEL_INV_RTT = NETBASE + 16;
+ // public static final int NET_FLOW_LEVEL_INV_RTT = NETBASE + 16;
// INV-RTT flows are weighted proportionally to the bottleneck RTT
// with bounded bandwidth availability
- public static final int NET_FLOW_LEVEL_INV_RTT_BOUND = NETBASE + 17;
+ // public static final int NET_FLOW_LEVEL_INV_RTT_BOUND = NETBASE + 17;
// MAX-MIN flows are equally weighted so all flows get equal share
- public static final int NET_FLOW_LEVEL_MAX_MIN = NETBASE + 18;
+ // public static final int NET_FLOW_LEVEL_MAX_MIN = NETBASE + 18;
//////////////////////////////////////////////////////////////////////
@@ -192,6 +204,7 @@
* {@link gridsim.net.Output} entities.
*/
public static final int EMPTY_PKT = NETBASE + 8;
+
/** Denotes that this packet will be sent to a packet scheduler by a router
* for enqueing.
@@ -207,7 +220,6 @@
*/
public static final int SCHEDULER_DEQUE = NETBASE + 10;
-
/////////////////////////////////////////////////////////////
// I intentionally put a gap to incorporate future tags
// so I don't have to change the numbers!
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <bro...@us...> - 2008-02-19 00:31:28
|
Revision: 107
http://gridsim.svn.sourceforge.net/gridsim/?rev=107&view=rev
Author: brobergj
Date: 2008-02-18 16:31:31 -0800 (Mon, 18 Feb 2008)
Log Message:
-----------
*Removed FlowInput and FlowOutput and replaced it with FlowBuffer input/output combined class
*Added support for FlowBuffer input/output combined class in initNetwork() and terminateIOEntities()
Modified Paths:
--------------
branches/gridsim4.0-branch2/source/gridsim/GridSimCore.java
Modified: branches/gridsim4.0-branch2/source/gridsim/GridSimCore.java
===================================================================
--- branches/gridsim4.0-branch2/source/gridsim/GridSimCore.java 2008-02-18 04:25:19 UTC (rev 106)
+++ branches/gridsim4.0-branch2/source/gridsim/GridSimCore.java 2008-02-19 00:31:31 UTC (rev 107)
@@ -11,8 +11,7 @@
import eduni.simjava.*;
import gridsim.net.*;
-import gridsim.net.flow.FlowInput;
-import gridsim.net.flow.FlowOutput;
+import gridsim.net.flow.FlowBuffer;
import gridsim.util.*;
import java.util.Collection;
@@ -192,13 +191,10 @@
/** Sending data via output port to external entities */
protected Sim_port output;
-
+
// Output port but only for a network extension.
private NetIO out_ = null;
- //private Output out_ = null;
- //private FlowOutput fout_ = null; // TODO: redundant
-
// TODO: new addition
protected static int NETWORK_TYPE = GridSimTags.NET_PACKET_LEVEL;
@@ -308,41 +304,45 @@
initNetwork(name, link.getBaudRate(), link);
}
- // TODO: new addition
private void initNetwork(String name, double baudRate, Link link)
{
// Every GridSim entity with network has its own input/output channels.
// Connect this entity "input" port to its input buffer "in_port"
NetIO in = null;
- //FlowInput fin = null; // TODO: redundant
+ // Packet Level networking has input & output
if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_PACKET_LEVEL)
{
in = new Input("Input_" + name, baudRate);
out_ = new Output("Output_" + name, baudRate);
+
+ System.out.println(super.get_name() + ".initNetwork()");
+ Sim_system.link_ports(name, "input", "Input_" + name, "input_buffer");
+ Sim_system.link_ports(name, "output", "Output_"+name, "output_buffer");
+ if (link != null)
+ {
+ in.addLink(link);
+ out_.addLink(link);
+ }
}
+ // Flow Level networking has a buffer that handles both input/output
else if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_FLOW_LEVEL)
{
- // TODO: ...
- //fin = new FlowInput("Input_" + name, baudRate);
- //fout_ = new FlowOutput("Output_" + name, baudRate);
- in = new FlowInput("Input_" + name, baudRate);
- out_ = new FlowOutput("Output_" + name, baudRate);
+
+ out_ = new FlowBuffer("Output_" + name, baudRate);
+
+ System.out.println(super.get_name() + ".initNetwork()");
+ Sim_system.link_ports(name, "output", "Output_"+name, "output_buffer");
+ if (link != null)
+ {
+ out_.addLink(link);
+ }
}
else if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_BUFFER_PACKET_LEVEL)
{
// TODO:
}
-
- System.out.println(super.get_name() + ".initNetwork()");
- Sim_system.link_ports(name, "input", "Input_" + name, "input_buffer");
- Sim_system.link_ports(name, "output", "Output_"+name, "output_buffer");
- if (link != null)
- {
- in.addLink(link);
- out_.addLink(link);
- }
}
@@ -678,11 +678,12 @@
* by the constructor: {@link GridSim#GridSim(String, double)}
* @pre $none
* @post $none
+ * WARNING: use this method if you use the NET FLOW type
*/
protected void terminateIOEntities()
{
// If it is Networked entity and Not yet terminated, then terminate.
- if ( isNetworked() && !terminateIOEntitiesFlag_ )
+ if ( isNetworked() && !terminateIOEntitiesFlag_ && NETWORK_TYPE == GridSimTags.NET_PACKET_LEVEL)
{
// Send END_OF_SIMULATION to Input entity
send(input, 0.0, GridSimTags.END_OF_SIMULATION);
@@ -691,6 +692,10 @@
send(output, 0.0, GridSimTags.END_OF_SIMULATION);
terminateIOEntitiesFlag_ = true;
+ // If we are using flow level networking, only terminate output as input is null!
+ } else if ( isNetworked() && !terminateIOEntitiesFlag_ && NETWORK_TYPE == GridSimTags.NET_FLOW_LEVEL) {
+ // Send END_OF_SIMULATION to Output entity
+ send(output, 0.0, GridSimTags.END_OF_SIMULATION);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <mar...@us...> - 2008-02-18 04:25:19
|
Revision: 106
http://gridsim.svn.sourceforge.net/gridsim/?rev=106&view=rev
Author: marcos_dias
Date: 2008-02-17 20:25:19 -0800 (Sun, 17 Feb 2008)
Log Message:
-----------
This update includes the final version of the multiple partition conservative policies. One of the policies supports advance reservations.
Modified Paths:
--------------
branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.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/ARTGridResource.java
branches/gridsim4.0-branch3/source/gridsim/turbo/Lublin99Workload.java
branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java
branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartitionPredicate.java
branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java
Added Paths:
-----------
branches/gridsim4.0-branch3/examples/examples/QueuePredicateExample.java
branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.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/EBMultiplePartitions.java
Removed Paths:
-------------
branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultipleQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultipleQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultipleQueues.java
Copied: branches/gridsim4.0-branch3/examples/examples/QueuePredicateExample.java (from rev 105, branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java)
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/QueuePredicateExample.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/QueuePredicateExample.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -0,0 +1,63 @@
+package examples;
+
+import gridsim.turbo.QueuePartitionPredicate;
+import gridsim.turbo.SSGridlet;
+import gridsim.turbo.SSReservation;
+import gridsim.turbo.ScheduleItem;
+
+/**
+ * Example of queue predicate. This predicate filters
+ * gridlets according to their runtime
+ *
+ * @author Marcos Dias de Assuncao
+ */
+public class QueuePredicateExample implements QueuePartitionPredicate {
+ int minRuntime_;
+ int maxRuntime_;
+ int resRating_;
+
+ /*
+ * Default constructor
+ */
+ public QueuePredicateExample(int minRuntime,
+ int maxRuntime, int rating) {
+ this.minRuntime_ = minRuntime;
+ this.maxRuntime_ = maxRuntime;
+ this.resRating_ = rating;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see gridsim.turbo.QueuePredicate#match(gridsim.turbo.ScheduleItem)
+ */
+ public boolean match(ScheduleItem item) {
+ double runtime = 0;
+ if(!item.isAdvanceReservation())
+ runtime = forecastExecutionTime((SSGridlet)item);
+ else
+ runtime = ((SSReservation)item).getDurationTime();
+
+ if(runtime < minRuntime_ || runtime >= maxRuntime_)
+ return false;
+
+ return true;
+ }
+
+ /*
+ * Forecast execution time of a Gridlet.
+ * <tt>execution time = length / available rating</tt>
+ * @param gridlet the gridlet to be considered
+ * @return Gridlet's execution time.
+ */
+ private double forecastExecutionTime(SSGridlet gridlet) {
+ double executionTime = (gridlet.getLength() / resRating_);
+
+ // This is as a safeguard since the finish time can be extremely
+ // small close to 0.0, such as 4.5474735088646414E-14. Hence causing
+ // some Gridlets never to be finished and consequently hang the program
+ if (executionTime < 1.0) {
+ executionTime = 1.0;
+ }
+ return executionTime;
+ }
+}
\ No newline at end of file
Modified: branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/WorkloadWithReservation.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -608,8 +608,7 @@
Sim_event ev = new Sim_event();
Object[] reservObj = null;
- while ( Sim_system.running()
- && counter < gridletID_ ) {
+ while ( Sim_system.running() && counter < gridletID_ ) {
super.sim_get_next(ev); // get the next available event
data = ev.get_data(); // get the event's data
@@ -629,10 +628,12 @@
// creates a new reservation
Reservation reservation = null;
- reservation = super.createReservation(startTime, duration, resGl.getNumPE(), resID_);
+ reservation = super.createReservation(startTime, duration,
+ resGl.getNumPE(), resID_);
success = true;
- if(reservation == null || reservation.getStatus() == Reservation.STATUS_FAILED) {
+ if(reservation == null ||
+ reservation.getStatus() == Reservation.STATUS_FAILED) {
success = false;
}
@@ -661,10 +662,13 @@
catch(Exception ex) {
}
- list_.add(resGl);
}
}
- counter++;
+
+ if(!success) {
+ list_.add(resGl);
+ counter++;
+ }
}
// get the Gridlet data
@@ -673,11 +677,6 @@
list_.add(gl);
counter++;
}
-
- // if all the Gridlets have been collected
- if (counter == gridletID_) {
- break;
- }
}
// shut down all the entities, including GridStatistics entity since
Added: branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/ar/TurboARCBMultipleQueuesExample01.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -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.ARCBMultiplePartitions;
+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 TurboARCBMultipleQueuesExample01
+{
+ /**
+ * 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.ARCB_MULTI_PARTITIONS,
+ time_zone, cost);
+
+ ARCBMultiplePartitions policy = null;
+ try {
+ policy = new ARCBMultiplePartitions(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
+
Deleted: branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -1,63 +0,0 @@
-package examples.workload.parallel;
-
-import gridsim.turbo.QueuePartitionPredicate;
-import gridsim.turbo.SSGridlet;
-import gridsim.turbo.SSReservation;
-import gridsim.turbo.ScheduleItem;
-
-/**
- * Example of queue predicate. This predicate filters
- * gridlets according to their runtime
- *
- * @author Marcos Dias de Assuncao
- */
-class QueuePredicateExample implements QueuePartitionPredicate {
- int minRuntime_;
- int maxRuntime_;
- int resRating_;
-
- /*
- * Default constructor
- */
- public QueuePredicateExample(int minRuntime,
- int maxRuntime, int rating) {
- this.minRuntime_ = minRuntime;
- this.maxRuntime_ = maxRuntime;
- this.resRating_ = rating;
- }
-
- /*
- * (non-Javadoc)
- * @see gridsim.turbo.QueuePredicate#match(gridsim.turbo.ScheduleItem)
- */
- public boolean match(ScheduleItem item) {
- double runtime = 0;
- if(!item.isAdvanceReservation())
- runtime = forecastExecutionTime((SSGridlet)item);
- else
- runtime = ((SSReservation)item).getDurationTime();
-
- if(runtime < minRuntime_ || runtime >= maxRuntime_)
- return false;
-
- return true;
- }
-
- /*
- * Forecast execution time of a Gridlet.
- * <tt>execution time = length / available rating</tt>
- * @param gridlet the gridlet to be considered
- * @return Gridlet's execution time.
- */
- private double forecastExecutionTime(SSGridlet gridlet) {
- double executionTime = (gridlet.getLength() / resRating_);
-
- // This is as a safeguard since the finish time can be extremely
- // small close to 0.0, such as 4.5474735088646414E-14. Hence causing
- // some Gridlets never to be finished and consequently hang the program
- if (executionTime < 1.0) {
- executionTime = 1.0;
- }
- return executionTime;
- }
-}
\ No newline at end of file
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -8,7 +8,7 @@
import gridsim.MachineList;
import gridsim.ResourceCalendar;
import gridsim.ResourceCharacteristics;
-import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.EBMultiplePartitions;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.util.Workload;
@@ -144,7 +144,7 @@
// this resource will use an aggressive backfilling policy (EASY)
TResourceCharacteristics resConfig =
new TResourceCharacteristics(arch, os, mList,
- TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES,
+ TResourceCharacteristics.CB_MULTI_PARTITIONS,
time_zone, cost);
//////////////////////////////////////////
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -1,13 +1,14 @@
package examples.workload.parallel;
+import examples.QueuePredicateExample;
import gridsim.GridResource;
import gridsim.GridSim;
import gridsim.Machine;
import gridsim.MachineList;
import gridsim.ResourceCalendar;
-import gridsim.turbo.CBMultipleQueues;
-import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.CBMultiplePartitions;
+import gridsim.turbo.EBMultiplePartitions;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.util.Workload;
@@ -142,12 +143,12 @@
// this resource will use an aggressive backfilling policy (EASY)
TResourceCharacteristics resConfig = new TResourceCharacteristics(
- arch, os, mList, TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES,
+ arch, os, mList, TResourceCharacteristics.CB_MULTI_PARTITIONS,
time_zone, cost);
- CBMultipleQueues policy = null;
+ CBMultiplePartitions policy = null;
try {
- policy = new CBMultipleQueues(name, "Policy", 3);
+ policy = new CBMultiplePartitions(name, "Policy", 3);
} catch (Exception e1) {
e1.printStackTrace();
}
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -8,7 +8,7 @@
import gridsim.MachineList;
import gridsim.ResourceCalendar;
import gridsim.ResourceCharacteristics;
-import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.EBMultiplePartitions;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.util.Workload;
@@ -143,7 +143,7 @@
// this resource will use an aggressive backfilling policy (EASY)
TResourceCharacteristics resConfig = new TResourceCharacteristics(
- arch, os, mList, TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES,
+ arch, os, mList, TResourceCharacteristics.EB_MULTI_PARTITIONS,
time_zone, cost);
//////////////////////////////////////////
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -1,12 +1,13 @@
package examples.workload.parallel;
+import examples.QueuePredicateExample;
import gridsim.GridResource;
import gridsim.GridSim;
import gridsim.Machine;
import gridsim.MachineList;
import gridsim.ResourceCalendar;
-import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.EBMultiplePartitions;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.util.Workload;
@@ -140,12 +141,12 @@
// this resource will use an aggressive backfilling policy (EASY)
TResourceCharacteristics resConfig = new TResourceCharacteristics(
- arch, os, mList, TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES,
+ arch, os, mList, TResourceCharacteristics.EB_MULTI_PARTITIONS,
time_zone, cost);
- EBMultipleQueues policy = null;
+ EBMultiplePartitions policy = null;
try {
- policy = new EBMultipleQueues(name, "Policy", 3);
+ policy = new EBMultiplePartitions(name, "Policy", 3);
} catch (Exception e1) {
e1.printStackTrace();
}
Modified: branches/gridsim4.0-branch3/source/gridsim/GridResource.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-17 05:40:32 UTC (rev 105)
+++ branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -10,11 +10,12 @@
package gridsim;
import gridsim.net.*;
+import gridsim.turbo.ARCBMultiplePartitions;
import gridsim.turbo.ARParallelSpaceShared;
-import gridsim.turbo.CBMultipleQueues;
+import gridsim.turbo.CBMultiplePartitions;
import gridsim.turbo.EBParallelSpaceShared;
import gridsim.turbo.CBParallelSpaceShared;
-import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.EBMultiplePartitions;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.index.*;
@@ -535,12 +536,10 @@
super.sim_get_next(ev);
// if the simulation finishes then exit the loop
- if (ev.get_tag() == GridSimTags.END_OF_SIMULATION)
- {
+ if (ev.get_tag() == GridSimTags.END_OF_SIMULATION) {
policy_.setEndSimulation();
break;
}
-
// process the received event
processEvent(ev);
}
@@ -648,16 +647,21 @@
break;
// creates the scheduler with only one queue
- case TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES:
- policy_ = new EBMultipleQueues(super.get_name(),
+ case TResourceCharacteristics.EB_MULTI_PARTITIONS:
+ policy_ = new EBMultiplePartitions(super.get_name(),
"EBMultipleQueues", 1);
break;
- case TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES:
- policy_ = new CBMultipleQueues(super.get_name(),
+ case TResourceCharacteristics.CB_MULTI_PARTITIONS:
+ policy_ = new CBMultiplePartitions(super.get_name(),
"CBMultipleQueues", 1);
break;
+ case TResourceCharacteristics.ARCB_MULTI_PARTITIONS:
+ policy_ = new ARCBMultiplePartitions(super.get_name(),
+ "ARCBMultipleQueues", 1);
+ break;
+
default:
throw new Exception(super.get_name()+" : Error - supports"+
" only TimeShared or SpaceShared policy.");
Copied: branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java (from rev 105, branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultipleQueues.java)
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java (rev 0)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultiplePartitions.java 2008-02-18 04:25:19 UTC (rev 106)
@@ -0,0 +1,1144 @@
+/*
+ * 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 conservative 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.CBMultiplePartitions
+ * @see gridsim.turbo.QueuePartitionPredicate
+ * @see gridsim.turbo.PERange
+ * @see gridsim.turbo.PERangeList
+ */
+
+public class ARCBMultiplePartitions extends
+ CBMultiplePartitions 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>CBMultipleQueues</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 ARCBMultiplePartitions(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>CBMultipleQueues</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 ARCBMultiplePartitions(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.setFinishTime(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.getFinishTime();
+ }
+ 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 = finishReservation(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 = startReservation(currentTime);
+
+ // Start the execution of Gridlets that are queued and whose
+ // potential start execution time is smaller than current time
+ itemsStarted += super.startQueuedGridlets(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 finishReservation(double refTime) {
+ int reservationFinished = 0;
+
+ Iterator<SSReservation> iterRes = reservTable_.values().iterator();
+ while(iterRes.hasNext()) {
+ SSReservation sRes = iterRes.next();
+ if(sRes.getFinishTime() <= 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 startReservation(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.getFinishTime()-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.getMessageTyp...
[truncated message content] |
|
From: <mar...@us...> - 2008-02-17 05:40:27
|
Revision: 105
http://gridsim.svn.sourceforge.net/gridsim/?rev=105&view=rev
Author: marcos_dias
Date: 2008-02-16 21:40:32 -0800 (Sat, 16 Feb 2008)
Log Message:
-----------
This update contains:
+ Changes in the multiple queue easy backfilling policy to make it reusable when implementing other multiple queue policies.
+ A preliminary implementation of a multiple queue policy that uses conservative backfilling.
+ A preliminary implementation of a multiple queue policy that uses conservative backfilling and supports advance reservation.
Modified Paths:
--------------
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java
branches/gridsim4.0-branch3/source/gridsim/GridResource.java
branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/EBParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/QueuePartitionPredicate.java
branches/gridsim4.0-branch3/source/gridsim/turbo/TResourceCharacteristics.java
Added Paths:
-----------
branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ARCBMultipleQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/CBMultipleQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/EBMultipleQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/MPAvailabilityProfile.java
branches/gridsim4.0-branch3/source/gridsim/turbo/MPProfileEntry.java
Removed Paths:
-------------
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java
branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java
Added: branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/QueuePredicateExample.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -0,0 +1,63 @@
+package examples.workload.parallel;
+
+import gridsim.turbo.QueuePartitionPredicate;
+import gridsim.turbo.SSGridlet;
+import gridsim.turbo.SSReservation;
+import gridsim.turbo.ScheduleItem;
+
+/**
+ * Example of queue predicate. This predicate filters
+ * gridlets according to their runtime
+ *
+ * @author Marcos Dias de Assuncao
+ */
+class QueuePredicateExample implements QueuePartitionPredicate {
+ int minRuntime_;
+ int maxRuntime_;
+ int resRating_;
+
+ /*
+ * Default constructor
+ */
+ public QueuePredicateExample(int minRuntime,
+ int maxRuntime, int rating) {
+ this.minRuntime_ = minRuntime;
+ this.maxRuntime_ = maxRuntime;
+ this.resRating_ = rating;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see gridsim.turbo.QueuePredicate#match(gridsim.turbo.ScheduleItem)
+ */
+ public boolean match(ScheduleItem item) {
+ double runtime = 0;
+ if(!item.isAdvanceReservation())
+ runtime = forecastExecutionTime((SSGridlet)item);
+ else
+ runtime = ((SSReservation)item).getDurationTime();
+
+ if(runtime < minRuntime_ || runtime >= maxRuntime_)
+ return false;
+
+ return true;
+ }
+
+ /*
+ * Forecast execution time of a Gridlet.
+ * <tt>execution time = length / available rating</tt>
+ * @param gridlet the gridlet to be considered
+ * @return Gridlet's execution time.
+ */
+ private double forecastExecutionTime(SSGridlet gridlet) {
+ double executionTime = (gridlet.getLength() / resRating_);
+
+ // This is as a safeguard since the finish time can be extremely
+ // small close to 0.0, such as 4.5474735088646414E-14. Hence causing
+ // some Gridlets never to be finished and consequently hang the program
+ if (executionTime < 1.0) {
+ executionTime = 1.0;
+ }
+ return executionTime;
+ }
+}
\ No newline at end of file
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExample01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -37,8 +37,6 @@
// ASCII text, gzip or zip.
String fileName = args[0];
- // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf
-
ArrayList<GridResource> resources = new ArrayList<GridResource>();
//////////////////////////////////////////
Added: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -0,0 +1,180 @@
+
+package examples.workload.parallel;
+
+import gridsim.AllocPolicy;
+import gridsim.GridResource;
+import gridsim.GridSim;
+import gridsim.Machine;
+import gridsim.MachineList;
+import gridsim.ResourceCalendar;
+import gridsim.ResourceCharacteristics;
+import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.TResourceCharacteristics;
+import gridsim.util.Workload;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.Random;
+
+
+/**
+ * Test Driver class for this example
+ */
+public class TurboExampleCBMultiQueues01
+{
+ /**
+ * 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);
+ Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
+
+ //////////////////////////////////////////
+ // 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
+
+ // this resource will use an aggressive backfilling policy (EASY)
+ TResourceCharacteristics resConfig =
+ new TResourceCharacteristics(arch, os, mList,
+ TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES,
+ time_zone, cost);
+
+ //////////////////////////////////////////
+ // 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();
+ GridResource gridRes = null;
+
+ try {
+ gridRes = new GridResource(name, baud_rate, seed,
+ resConfig, peakLoad, offPeakLoad, holidayLoad, weekends,
+ holidays);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("Creates one Grid resource with name = " + name);
+ return gridRes;
+ }
+} // end class
+
Added: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleCBMultiQueues02.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -0,0 +1,202 @@
+
+package examples.workload.parallel;
+
+import gridsim.GridResource;
+import gridsim.GridSim;
+import gridsim.Machine;
+import gridsim.MachineList;
+import gridsim.ResourceCalendar;
+import gridsim.turbo.CBMultipleQueues;
+import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.TResourceCharacteristics;
+import gridsim.util.Workload;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.Random;
+
+
+/**
+ * Test Driver class for this example
+ */
+public class TurboExampleCBMultiQueues02
+{
+ /**
+ * 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);
+ Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
+
+ //////////////////////////////////////////
+ // 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
+
+ // this resource will use an aggressive backfilling policy (EASY)
+ TResourceCharacteristics resConfig = new TResourceCharacteristics(
+ arch, os, mList, TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES,
+ time_zone, cost);
+
+ CBMultipleQueues policy = null;
+ try {
+ policy = new CBMultipleQueues(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();
+ GridResource gridRes = null;
+
+ ResourceCalendar resCalendar = new ResourceCalendar(time_zone,
+ peakLoad, offPeakLoad, holidayLoad, weekends,
+ holidays, seed);
+
+ try {
+ gridRes = new GridResource(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
+
+
+
+
+
Copied: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java (from rev 104, branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java)
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -0,0 +1,179 @@
+
+package examples.workload.parallel;
+
+import gridsim.AllocPolicy;
+import gridsim.GridResource;
+import gridsim.GridSim;
+import gridsim.Machine;
+import gridsim.MachineList;
+import gridsim.ResourceCalendar;
+import gridsim.ResourceCharacteristics;
+import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.TResourceCharacteristics;
+import gridsim.util.Workload;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.Random;
+
+
+/**
+ * Test Driver class for this example
+ */
+public class TurboExampleEBMultiQueues01
+{
+ /**
+ * 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);
+ Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
+
+ //////////////////////////////////////////
+ // 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
+
+ // this resource will use an aggressive backfilling policy (EASY)
+ TResourceCharacteristics resConfig = new TResourceCharacteristics(
+ arch, os, mList, TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES,
+ time_zone, cost);
+
+ //////////////////////////////////////////
+ // 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();
+ GridResource gridRes = null;
+
+ try {
+ gridRes = new GridResource(name, baud_rate, seed,
+ resConfig, peakLoad, offPeakLoad, holidayLoad, weekends,
+ holidays);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("Creates one Grid resource with name = " + name);
+ return gridRes;
+ }
+} // end class
+
Copied: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java (from rev 104, branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java)
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java (rev 0)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEBMultiQueues02.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -0,0 +1,195 @@
+
+package examples.workload.parallel;
+
+import gridsim.GridResource;
+import gridsim.GridSim;
+import gridsim.Machine;
+import gridsim.MachineList;
+import gridsim.ResourceCalendar;
+import gridsim.turbo.EBMultipleQueues;
+import gridsim.turbo.TResourceCharacteristics;
+import gridsim.util.Workload;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.LinkedList;
+import java.util.Random;
+
+
+/**
+ * Test Driver class for this example
+ */
+public class TurboExampleEBMultiQueues02
+{
+ /**
+ * 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);
+ Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
+
+ //////////////////////////////////////////
+ // 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
+
+ // this resource will use an aggressive backfilling policy (EASY)
+ TResourceCharacteristics resConfig = new TResourceCharacteristics(
+ arch, os, mList, TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES,
+ time_zone, cost);
+
+ EBMultipleQueues policy = null;
+ try {
+ policy = new EBMultipleQueues(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();
+ GridResource gridRes = null;
+
+ ResourceCalendar resCalendar = new ResourceCalendar(time_zone,
+ peakLoad, offPeakLoad, holidayLoad, weekends,
+ holidays, seed);
+
+ try {
+ gridRes = new GridResource(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/TurboExampleEasy01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleEasy01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -37,8 +37,6 @@
// ASCII text, gzip or zip.
String fileName = args[0];
- // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf
-
ArrayList<GridResource> resources = new ArrayList<GridResource>();
//////////////////////////////////////////
Deleted: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -1,181 +0,0 @@
-
-package examples.workload.parallel;
-
-import gridsim.AllocPolicy;
-import gridsim.GridResource;
-import gridsim.GridSim;
-import gridsim.Machine;
-import gridsim.MachineList;
-import gridsim.ResourceCalendar;
-import gridsim.ResourceCharacteristics;
-import gridsim.turbo.MultipleEasyBackfillingQueues;
-import gridsim.turbo.TResourceCharacteristics;
-import gridsim.util.Workload;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.LinkedList;
-import java.util.Random;
-
-
-/**
- * Test Driver class for this example
- */
-public class TurboExampleMultiEBQueues01
-{
- /**
- * 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];
- // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf
-
- 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);
- Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
-
- //////////////////////////////////////////
- // 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
-
- // this resource will use an aggressive backfilling policy (EASY)
- TResourceCharacteristics resConfig = new TResourceCharacteristics(
- arch, os, mList, TResourceCharacteristics.MULTIPLE_EASY_BACKFILLING_QUEUES,
- time_zone, cost);
-
- //////////////////////////////////////////
- // 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();
- GridResource gridRes = null;
-
- try {
- gridRes = new GridResource(name, baud_rate, seed,
- resConfig, peakLoad, offPeakLoad, holidayLoad, weekends,
- holidays);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
-
- System.out.println("Creates one Grid resource with name = " + name);
- return gridRes;
- }
-} // end class
-
Deleted: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -1,255 +0,0 @@
-
-package examples.workload.parallel;
-
-import gridsim.GridResource;
-import gridsim.GridSim;
-import gridsim.Machine;
-import gridsim.MachineList;
-import gridsim.ResourceCalendar;
-import gridsim.turbo.MultipleEasyBackfillingQueues;
-import gridsim.turbo.QueuePartitionPredicate;
-import gridsim.turbo.SSGridlet;
-import gridsim.turbo.TResourceCharacteristics;
-import gridsim.util.Workload;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.LinkedList;
-import java.util.Random;
-
-
-/**
- * Test Driver class for this example
- */
-public class TurboExampleMultiEBQueues02
-{
- /**
- * 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];
- // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf
-
- 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);
- Workload workload = new Workload("Load_1", fileName, resArray[resID], rating);
-
- //////////////////////////////////////////
- // 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
-
- // this resource will use an aggressive backfilling policy (EASY)
- TResourceCharacteristics resConfig = new TResourceCharacteristics(
- arch, os, mList, TResourceCharacteristics.MULTIPLE_EASY_BACKFILLING_QUEUES,
- time_zone, cost);
-
- MultipleEasyBackfillingQueues policy = null;
- try {
- policy = new MultipleEasyBackfillingQueues(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();
- GridResource gridRes = null;
-
- ResourceCalendar resCalendar = new ResourceCalendar(time_zone,
- peakLoad, offPeakLoad, holidayLoad, weekends,
- holidays, seed);
-
- try {
- gridRes = new GridResource(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
-
-/**
- * Example of queue predicate. This predicate filters
- * gridlets according to their runtime
- *
- * @author Marcos Dias de Assuncao
- */
-class QueuePredicateExample implements QueuePartitionPredicate {
- int minRuntime_;
- int maxRuntime_;
- int resRating_;
-
- /*
- * Default constructor
- */
- public QueuePredicateExample(int minRuntime,
- int maxRuntime, int rating) {
- this.minRuntime_ = minRuntime;
- this.maxRuntime_ = maxRuntime;
- this.resRating_ = rating;
- }
-
- /*
- * (non-Javadoc)
- * @see gridsim.turbo.QueuePredicate#match(gridsim.turbo.SSGridlet)
- */
- public boolean match(SSGridlet gridlet) {
- double runtime = forecastExecutionTime(gridlet);
- if(runtime < minRuntime_ || runtime >= maxRuntime_)
- return false;
-
- return true;
- }
-
- /*
- * Forecast execution time of a Gridlet.
- * <tt>execution time = length / available rating</tt>
- * @param gridlet the gridlet to be considered
- * @return Gridlet's execution time.
- */
- private double forecastExecutionTime(SSGridlet gridlet) {
- double executionTime = (gridlet.getLength() / resRating_);
-
- // This is as a safeguard since the finish time can be extremely
- // small close to 0.0, such as 4.5474735088646414E-14. Hence causing
- // some Gridlets never to be finished and consequently hang the program
- if (executionTime < 1.0) {
- executionTime = 1.0;
- }
- return executionTime;
- }
-}
-
-
-
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleWithCancellation01.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -37,8 +37,6 @@
// ASCII text, gzip or zip.
String fileName = args[0];
- // /Users/marcosd/Documents/workspace/intergrid/workloads/sdsc_blue_2000_400.swf
-
ArrayList<GridResource> resources = new ArrayList<GridResource>();
//////////////////////////////////////////
Modified: branches/gridsim4.0-branch3/source/gridsim/GridResource.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/source/gridsim/GridResource.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -11,9 +11,10 @@
import gridsim.net.*;
import gridsim.turbo.ARParallelSpaceShared;
+import gridsim.turbo.CBMultipleQueues;
import gridsim.turbo.EBParallelSpaceShared;
import gridsim.turbo.CBParallelSpaceShared;
-import gridsim.turbo.MultipleEasyBackfillingQueues;
+import gridsim.turbo.EBMultipleQueues;
import gridsim.turbo.TResourceCharacteristics;
import gridsim.index.*;
@@ -647,10 +648,15 @@
break;
// creates the scheduler with only one queue
- case TResourceCharacteristics.MULTIPLE_EASY_BACKFILLING_QUEUES:
- policy_ = new MultipleEasyBackfillingQueues(super.get_name(),
- "MultipleEasyBackfillingQueues", 1);
+ case TResourceCharacteristics.MULTI_EASY_BACKFILLING_QUEUES:
+ policy_ = new EBMultipleQueues(super.get_name(),
+ "EBMultipleQueues", 1);
break;
+
+ case TResourceCharacteristics.MULTI_CONSERVATIVE_BACKFILLING_QUEUES:
+ policy_ = new CBMultipleQueues(super.get_name(),
+ "CBMultipleQueues", 1);
+ break;
default:
throw new Exception(super.get_name()+" : Error - supports"+
Modified: branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-15 07:03:53 UTC (rev 104)
+++ branches/gridsim4.0-branch3/source/gridsim/gui/DefaultGridSimVisualizer.java 2008-02-17 05:40:32 UTC (rev 105)
@@ -18,8 +18,6 @@
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -206,27 +204,6 @@
status_ = new JLabel("Current simulation time is " + GridSim.clock() + " seconds.");
statusPanel.add(status_);
- /* to show simulation time when mouse cursor passing over buttons */
- ...
[truncated message content] |
|
From: <mar...@us...> - 2008-02-15 07:03:55
|
Revision: 104
http://gridsim.svn.sourceforge.net/gridsim/?rev=104&view=rev
Author: marcos_dias
Date: 2008-02-14 23:03:53 -0800 (Thu, 14 Feb 2008)
Log Message:
-----------
Implementation of priorities in the multiple queue policy.
Modified Paths:
--------------
branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java
branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java
branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java
branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java
branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java
branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java
Modified: branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java
===================================================================
--- branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/examples/examples/workload/parallel/TurboExampleMultiEBQueues02.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -89,10 +89,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
@@ -150,18 +150,20 @@
MultipleEasyBackfillingQueues policy = null;
try {
- policy = new MultipleEasyBackfillingQueues(name, "Policy", 2);
+ policy = new MultipleEasyBackfillingQueues(name, "Policy", 3);
} catch (Exception e1) {
e1.printStackTrace();
}
- // creates two partitions, one for small jobs and another for long jobs
- // assign the same number of PEs to both
- QueuePredicateExample pred1 = new QueuePredicateExample(0, 10000, peRating);
- QueuePredicateExample pred2 = new QueuePredicateExample(10000, Integer.MAX_VALUE, peRating);
+ // 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() / 2, pred1);
- policy.createPartition(1, resConfig.getNumPE() / 2, pred2);
+ 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.
@@ -197,6 +199,12 @@
}
} // end class
+/**
+ * Example of queue predicate. This predicate filters
+ * gridlets according to their runtime
+ *
+ * @author Marcos Dias de Assuncao
+ */
class QueuePredicateExample implements QueuePartitionPredicate {
int minRuntime_;
int maxRuntime_;
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/CBParallelSpaceShared.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -783,7 +783,7 @@
// if the above method returns null, it means that there are not enough
// PEs to serve the reservation or Gridlet
- if(availObj == null){
+ if(availObj == null) {
return false;
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/MultipleEasyBackfillingQueues.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -18,6 +18,8 @@
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
@@ -52,11 +54,8 @@
* <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. This could be
- * easily done, but due to time constraints, I could not
- * implement these features.
- * <li> This policy still neither supports priorities nor advance
- * reservation.
+ * <li> Gridlets cannot be paused nor migrated.
+ * <li> This policy does not support advance reservations.
* </ul>
*
* @author Marcos Dias de Assuncao
@@ -94,13 +93,16 @@
// the last time when the schedule updated was called
private double lastScheduleUpdate_;
+ // to order the gridlets according to their priorities and submission times
+ private OrderGridletsByPriority orderByPriority_;
+
// a tag to indicate that a gridlet has finished
private static final int UPDATE_SCHEDULE_TAG = 10;
// a constant that denotes an unknown value
private static final int UNKNOWN = -1;
- /**
+ /**
* Allocates a new <tt>MultiEasyBackfillingQueues</tt> object.
* If the policy is create with only one partition, it will then work as
* a normal aggressive (EASY) backfilling scheduler.
@@ -136,6 +138,7 @@
// initialises local data structure
runningGridlets_ = new LinkedList<SSGridlet>();
queuedGridlets_ = new LinkedList<SSGridlet>();
+ orderByPriority_ = new OrderGridletsByPriority();
numPartitions_ = numPartitions;
profile_ = new MultiPartitionProfile();
lastScheduleUpdate_ = 0.0D;
@@ -337,6 +340,9 @@
if(!success) {
scheduleGridlet(sgl);
queuedGridlets_.add(sgl);
+
+ // order gridlets according to their priorities
+ Collections.sort(queuedGridlets_, orderByPriority_);
}
//------------------ FOR DEBUGGING PURPOSES ONLY ----------------
@@ -365,7 +371,7 @@
* @pre userId > 0
* @post $none
*/
- public int gridletStatus(int gridletId,int userId){
+ public int gridletStatus(int gridletId, int userId) {
return UNKNOWN;
}
@@ -537,7 +543,18 @@
// if queue has a pivot already, then just add
// the job to the waiting queue
if(queue.pivot_ != null) {
- return false;
+ // 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())
+ return false;
+ else {
+ profile_.updateEntriesAtProfile(queue.pivot_);
+ queue.pivot_.setStartTime(-1);
+ queue.pivot_.setFinishTime(-1);
+ queue.pivot_ = null;
+ }
}
PERangeList ranges = null;
@@ -1696,6 +1713,103 @@
}
}
}
+
+ /**
+ * This method removes/updates the entries from the profile
+ * corresponding to a the given Gridlet or advance reservation.
+ * @param removedItem the Gridlet or advance reservation whose entries
+ * have to be removed or updated
+ */
+ protected void updateEntriesAtProfile(ScheduleItem removedItem) {
+
+ int partitionId = removedItem.getPartitionID();
+
+ // ranges of PEs used by the Gridlet
+ PERangeList allocatedRanges = removedItem.getPERangeList();
+
+ // the reference time used to update the entries in the profile
+ double startTime = removedItem.getStartTime();
+
+ // the entries between reference time and endTime must be updated
+ double finishTime = removedItem.getFinishTime();
+
+ // transfer the PEs back to the queue
+ transferPEs(partitionId, allocatedRanges, startTime, finishTime);
+
+ ProfileEntry entry = getPrecedingEntry(startTime);
+ if(entry.getTime() == startTime) {
+ entry.decreaseGridlet();
+ if(entry.getNumGridlets() == 0)
+ super.remove(entry);
+ }
+
+ entry = getPrecedingEntry(finishTime);
+ if(entry.getTime() == startTime) {
+ entry.decreaseGridlet();
+ if(entry.getNumGridlets() == 0)
+ super.remove(entry);
+ }
+
+// // if the Gridlet was running, then update the range of PEs currently
+// // available and set the reference time as current simulation time
+// if(wasRunning) {
+// // returns the ranges to the list of free ranges
+// resource_.setPEsAvailable(allocatedRanges);
+// }
+//
+// Iterator<ProfileEntry> iterProfile = super.iterator();
+// while(iterProfile.hasNext()) {
+// ProfileEntry entry = iterProfile.next();
+//
+// double entryTime = entry.getTime();
+// if(entryTime < startTime) {
+// continue;
+// }
+// else if(entryTime > finishTime) {
+// break;
+// }
+// else{
+// if(entryTime == finishTime) {
+// // if the entry is equals to the finish time of the
+// // gridlet, then it means that the gridlet uses this entry
+// // to mark its termination. Therefore, it decreases the
+// // number of gridlets that rely on this entry to mark
+// // the finish time. If the number of gridlets is 0, it
+// // means that the entry can be deleted because it is
+// // not needed anymore
+// entry.decreaseGridlet();
+// if(entry.getNumGridlets() == 0) {
+// iterProfile.remove();
+// }
+// continue;
+// }
+// // if the entry is the gridlet's anchor point, then
+// // decrease the number of gridlets that rely on this
+// // entry to either mark their start time or completion
+// // time. If the number of Gridlets is 0 then, the
+// // entry is removed from the profile
+// if(entryTime == startTime) {
+// entry.decreaseGridlet();
+// if(entry.getNumGridlets() == 0) {
+// iterProfile.remove();
+// continue;
+// }
+// }
+// // returns the ranges to the list of free ranges in
+// // the entry, and consolidates the ranges to avoid fragments
+// // As the list may be null, make sure that the list will not be
+// // null so the released ranges can be added back to it
+// PERangeList listEntry = entry.getPERanges(partitionId);
+// if(listEntry == null){
+// listEntry = new PERangeList();
+// }
+//
+// listEntry.addAll(allocatedRanges.clone());
+// listEntry.mergePERanges();
+// entry.setPERangeList(partitionId, listEntry);
+// }
+// }
+ }
/**
* Creates an string representation of the profile
@@ -1710,4 +1824,26 @@
return result;
}
}
+
+ /**
+ * Comparator to order jobs according to their priorities
+ * and start time
+ * @author Marcos Dias de Assuncao
+ */
+ private class OrderGridletsByPriority implements Comparator<SSGridlet> {
+
+ public int compare(SSGridlet gl0, SSGridlet gl1) {
+ int result;
+ Integer priority0 = gl0.getPriority();
+ Integer priority1 = gl1.getPriority();
+ result = priority0.compareTo(priority1);
+
+ if(result == 0) {
+ Double submission0 = gl0.getSubmissionTime();
+ Double submission1 = gl1.getSubmissionTime();
+ result = submission0.compareTo(submission1);
+ }
+ return result;
+ }
+ }
}
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSGridlet.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -52,7 +52,7 @@
// A list of ranges of PEs used by this Gridlet
private PERangeList peRangeList_ = null;
- // the partiton or queue in the resource to which this
+ // the partition or queue in the resource to which this
// gridlet was scheduled
private int partition_;
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/SSReservation.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -36,6 +36,13 @@
// expiry time once a reservation has been made
private double expiryTime_;
+ // the partition or queue in the resource to which this
+ // reservation was scheduled
+ private int partition_;
+
+ // the priority of this reservation assigned by the scheduler
+ private int priority_;
+
// used to format the values for display
private static DecimalFormat decFormater_;
@@ -157,6 +164,50 @@
}
/**
+ * Gets the id of the partition or queue to which this
+ * reservation was scheduled
+ * @return the partition id or <tt>-1</tt> if not found
+ */
+ public int getPartitionID() {
+ return partition_;
+ }
+
+ /**
+ * Sets the id of the partition or queue to which this
+ * reservation was scheduled
+ * @param partition the partition id
+ * @return <tt>true</tt> if set correctly or <tt>false</tt> otherwise.
+ */
+ public boolean setPartitionID(int partition) {
+ if(partition < 0)
+ return false;
+
+ partition_ = partition;
+ return true;
+ }
+
+ /**
+ * Gets the priority of this reservation assigned by the scheduler
+ * @return the priority or <tt>-1</tt> if not found
+ */
+ public int getPriority() {
+ return priority_;
+ }
+
+ /**
+ * Sets the priority of this reservation assigned by the scheduler
+ * @param priority the priority
+ * @return <tt>true</tt> if set correctly or <tt>false</tt> otherwise.
+ */
+ public boolean setPriority(int priority) {
+ if(priority < 0)
+ return false;
+
+ priority_ = priority;
+ return true;
+ }
+
+ /**
* Sets the time of submission of this reservation
* @param time the submission time
* @return <tt>true</tt> if the time has been set or
Modified: branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java
===================================================================
--- branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-15 04:13:00 UTC (rev 103)
+++ branches/gridsim4.0-branch3/source/gridsim/turbo/ScheduleItem.java 2008-02-15 07:03:53 UTC (rev 104)
@@ -51,7 +51,7 @@
* @return the number of items
*/
int getNumPE();
-
+
/**
* Returns the time of submission of this item
* @return the submission time
@@ -73,6 +73,19 @@
double getFinishTime();
/**
+ * Gets the priority of this item assigned by the scheduler
+ * @return the priority or <tt>-1</tt> if not found
+ */
+ int getPriority();
+
+ /**
+ * Gets the id of the partition or queue to which this
+ * item was scheduled
+ * @return the partition id or <tt>-1</tt> if not found
+ */
+ int getPartitionID();
+
+ /**
* Gets the list of ranges of PEs used by this item
* @return a list containing the ranges
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|