|
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.
|