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