From: <sul...@us...> - 2008-08-03 06:00:34
|
Revision: 195 http://gridsim.svn.sourceforge.net/gridsim/?rev=195&view=rev Author: sulistio Date: 2008-08-03 06:00:43 +0000 (Sun, 03 Aug 2008) Log Message: ----------- modify this class to incorporate the latest network flow functionality into GridSim. Modified Paths: -------------- trunk/source/gridsim/GridSim.java trunk/source/gridsim/GridSimCore.java trunk/source/gridsim/GridSimTags.java trunk/source/gridsim/net/Input.java trunk/source/gridsim/net/Link.java trunk/source/gridsim/net/Output.java trunk/source/gridsim/net/Packet.java Modified: trunk/source/gridsim/GridSim.java =================================================================== --- trunk/source/gridsim/GridSim.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/GridSim.java 2008-08-03 06:00:43 UTC (rev 195) @@ -9,13 +9,13 @@ package gridsim; +//import gridsim.net.fnb.FnbWhiteList; import gridsim.net.Link; import gridsim.filter.*; import java.io.*; import java.util.*; import eduni.simjava.*; - /** * This class is mainly responsible in initialization, running and stopping of * the overall simulation. @@ -71,7 +71,7 @@ private final int ARRAY_SIZE = 3; private final int SIZE = 12; // Integer object size incl. overhead private final int RESULT = 1; // array[0] = gridlet id, [1] = result - private final static String GRIDSIM_VERSION_STRING = "GridSim Version 4.1"; + private final static String GRIDSIM_VERSION_STRING = "4.2"; /////////////////////////// STATIC variables //////////////////// @@ -98,13 +98,21 @@ */ public static int PAUSE = 10; // pause before registering to regional GIS + /** + * A white list that records entity IDs. + * The main purpose is that network packets are not going to be dropped, + * if they are going to/coming from the entity stored in the list. + * @see gridsim.net.fnb.FnbWhiteList + */ + //public static FnbWhiteList fnbWhiteList_ = null; // TODO + private static int gisID_ = -1; // id of GIS entity private static int shutdownID_ = -1; // id of GridSimShutdown entity private static int statsID_ = -1; // id of GridStatistics entity private static Calendar calendar_ = null; // a Calendar object private static GridInformationService gis_ = null; // a GIS object private final static int NOT_FOUND = -1; // a constant - private static boolean traceFlag_; + private static boolean traceFlag_ = false; // trace events or other activities //////////////////////////////////////////////////////////////////////// @@ -544,7 +552,7 @@ Sim_system.initialise(); Sim_system.set_trc_level(1); Sim_system.set_auto_trace(traceFlag); - + traceFlag_ = traceFlag; // Set the current Wall clock time as the starting time of simulation @@ -601,7 +609,7 @@ */ public static void startGridSimulation() throws NullPointerException { - System.out.println("Starting GridSim " + GRIDSIM_VERSION_STRING); + System.out.println("Starting GridSim version " + GRIDSIM_VERSION_STRING); try { Sim_system.run(); } @@ -2135,10 +2143,10 @@ return GridSim.isResourceExist(id); } - + /** * Checks whether simulation's statistics of other log should be created - * @return <tt>true</tt> if the information should be logged + * @return <tt>true</tt> if the information should be logged * or <tt>false</tt> otherwise. */ public static boolean isTraceEnabled() { @@ -2501,5 +2509,56 @@ ); } + /** + * Initializes the {@link gridsim.GridSimCore#NETWORK_TYPE} to be used in + * the simulation. By default, the {@link gridsim.GridSimCore#NETWORK_TYPE} + * is set to {@link gridsim.GridSimTags.NET_PACKET_LEVEL}. + * + * @param networkType network type + * @return <tt>true</tt> if the network type has been initialized successfully + * or <tt>false</tt> otherwise. + * + * @see gridsim.GridSimCore#NETWORK_TYPE + * @see gridsim.GridSimTags.NET_PACKET_LEVEL + * @see gridsim.GridSimTags.NET_FLOW_LEVEL + * @see gridsim.GridSimTags.NET_BUFFER_PACKET_LEVEL + */ + public static boolean initNetworkType(int networkType) + { + boolean result = true; + switch(networkType) + { + case GridSimTags.NET_PACKET_LEVEL: + GridSimCore.NETWORK_TYPE = GridSimTags.NET_PACKET_LEVEL; + break; + + case GridSimTags.NET_FLOW_LEVEL: + GridSimCore.NETWORK_TYPE = GridSimTags.NET_FLOW_LEVEL; + break; + + case GridSimTags.NET_BUFFER_PACKET_LEVEL: + GridSimCore.NETWORK_TYPE = GridSimTags.NET_BUFFER_PACKET_LEVEL; + //fnbWhiteList_ = new FnbWhiteList(); // TODO + break; + + default: + result = false; + break; + } + + return result; + } + + /** Returns the network type used in this simulation. + * @return the network type + * @see gridsim.GridSimCore#NETWORK_TYPE + * @see gridsim.GridSimTags.NET_PACKET_LEVEL + * @see gridsim.GridSimTags.NET_FLOW_LEVEL + * @see gridsim.GridSimTags.NET_BUFFER_PACKET_LEVEL + */ + public static int getNetworkType() { + return GridSimCore.NETWORK_TYPE; + } + } // end class Modified: trunk/source/gridsim/GridSimCore.java =================================================================== --- trunk/source/gridsim/GridSimCore.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/GridSimCore.java 2008-08-03 06:00:43 UTC (rev 195) @@ -13,8 +13,9 @@ import gridsim.net.*; import gridsim.util.*; import java.util.Collection; +import gridsim.net.flow.*; +//import gridsim.net.fnb.*; - /** * Since GridSim version 3.0, this is the overall class of GridSim package, * that must be extended by other GridSim @@ -188,7 +189,19 @@ protected Sim_port output; // Output port but only for a network extension. - private Output out_ = null; + private NetIO out_ = null; + + /** Specifies which type of network to be used. + * By default, the simulation uses the gridsim.net package or differentiated + * network service. To change this default property, please use the + * {@link gridsim.GridSim#initNetworkType(int)} method <b>before</b> the + * simulation starts. + * @see gridsim.GridSim#initNetworkType(int) + * @see gridsim.GridSimTags.NET_PACKET_LEVEL + * @see gridsim.GridSimTags.NET_FLOW_LEVEL + * @see gridsim.GridSimTags.NET_BUFFER_PACKET_LEVEL + */ + protected static int NETWORK_TYPE = GridSimTags.NET_PACKET_LEVEL; /** @@ -253,13 +266,7 @@ super.add_port(input); super.add_port(output); - // Every GridSim entity with network has its own input/output channels. - // Connect this entity "input" port to its input buffer "in_port" - new Input("Input_" + name, baudRate); - Sim_system.link_ports(name, "input", "Input_" + name, "input_buffer"); - - new Output("Output_" + name, baudRate); - Sim_system.link_ports(name, "output", "Output_"+name, "output_buffer"); + initNetwork(name, baudRate, null); } /** @@ -274,7 +281,7 @@ * @param name the name to be associated with this entity (as * required by Sim_entity class from simjava package) * @param link the link that this GridSim entity will use to - communicate with other GridSim or Network entities. + * communicate with other GridSim or Network entities. * @throws Exception This happens when creating this entity before * initializing GridSim package or this entity name is * <tt>null</tt> or empty @@ -299,15 +306,49 @@ super.add_port(input); super.add_port(output); + initNetwork(name, link.getBaudRate(), link); + } + + /** + * Creates Input and Output entities according to the network type + * @param name the name to be associated with this entity (as + * required by Sim_entity class from simjava package) + * @param baudRate network communication or bandwidth speed + * @param link the link that this GridSim entity will use to + * communicate with other GridSim or Network entities. + */ + 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" - Input in = new Input("Input_" + name, link_.getBaudRate()); - in.addLink(link_); + NetIO in = null; + + // Packet Level networking + if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_PACKET_LEVEL) + { + in = new Input("Input_" + name, baudRate); + out_ = new Output("Output_" + name, baudRate); + } + // Flow Level networking + else if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_FLOW_LEVEL) + { + in = new FlowInput("Input_" + name, baudRate); + out_ = new FlowOutput("Output_" + name, baudRate); + } + // Use Finite network buffer + else if (GridSimCore.NETWORK_TYPE == GridSimTags.NET_BUFFER_PACKET_LEVEL) + { // TODO: + //in = new FnbInput("Input_" + name, baudRate); + //out_ = new FnbOutput("Output_" + name, baudRate); + } + Sim_system.link_ports(name, "input", "Input_" + name, "input_buffer"); - - out_ = new Output("Output_" + name, link_.getBaudRate()); - out_.addLink(link_); - Sim_system.link_ports(name, "output", "Output_"+name, "output_buffer"); + Sim_system.link_ports(name, "output", "Output_" + name, "output_buffer"); + if (link != null) + { + in.addLink(link); + out_.addLink(link); + } } /** Modified: trunk/source/gridsim/GridSimTags.java =================================================================== --- trunk/source/gridsim/GridSimTags.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/GridSimTags.java 2008-08-03 06:00:43 UTC (rev 195) @@ -188,7 +188,25 @@ */ public static final int SCHEDULER_DEQUE = NETBASE + 10; + public static final int NET_PACKET_LEVEL = NETBASE + 11; + public static final int NET_FLOW_LEVEL = NETBASE + 12; + + public static final int NET_BUFFER_PACKET_LEVEL = NETBASE + 13; + + // Denotes flow en-route to destination (used manually by entities) + public static final int FLOW_SUBMIT = 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; + + // Denotes flow ack en-route to destination (used manually by entities) + public static final int FLOW_ACK = NETBASE + 17; + + ///////////////////////////////////////////////////////////// // I intentionally put a gap to incorporate future tags // so I don't have to change the numbers! Modified: trunk/source/gridsim/net/Input.java =================================================================== --- trunk/source/gridsim/net/Input.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/net/Input.java 2008-08-03 06:00:43 UTC (rev 195) @@ -11,6 +11,8 @@ import gridsim.*; import gridsim.net.*; +import gridsim.util.TrafficGenerator; +import java.util.Collection; import eduni.simjava.*; /** @@ -29,7 +31,7 @@ * @since GridSim Toolkit 1.0 * @invariant $none */ -public class Input extends Sim_entity +public class Input extends Sim_entity implements NetIO { private Sim_port inPort_; private Link link_; @@ -64,8 +66,10 @@ * @pre link != null * @post $none */ - public void addLink(Link link) { + public void addLink(Link link) + { this.link_ = link; + baudRate_ = link_.getBaudRate(); } /** @@ -113,6 +117,37 @@ } /** + * This is an empty method and only applicable to + * {@link gridsim.net.Output} class. + * @param gen a background traffic generator + * @param userName a collection of user entity name (in String object). + * @return <tt>false</tt> since this method is not used by this class. + * @pre gen != null + * @pre userName != null + * @post $none + * @see gridsim.net.Output + */ + public boolean setBackgroundTraffic(TrafficGenerator gen, + Collection userName) + { + return false; + } + + /** + * This is an empty method and only applicable to + * {@link gridsim.net.Output} class. + * @param gen a background traffic generator + * @return <tt>false</tt> since this method is not used by this class. + * @pre gen != null + * @post $none + * @see gridsim.net.Output + */ + public boolean setBackgroundTraffic(TrafficGenerator gen) + { + return false; + } + + /** * A method that gets one process event at one time until the end * of a simulation, then delivers an event to the entity (its parent) * @pre $none Modified: trunk/source/gridsim/net/Link.java =================================================================== --- trunk/source/gridsim/net/Link.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/net/Link.java 2008-08-03 06:00:43 UTC (rev 195) @@ -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."); Modified: trunk/source/gridsim/net/Output.java =================================================================== --- trunk/source/gridsim/net/Output.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/net/Output.java 2008-08-03 06:00:43 UTC (rev 195) @@ -31,7 +31,7 @@ * @since GridSim Toolkit 1.0 * @invariant $none */ -public class Output extends Sim_entity +public class Output extends Sim_entity implements NetIO { private Sim_port outPort_; // output port private Link link_; // a link to this output entity @@ -180,6 +180,7 @@ public void addLink(Link link) { this.link_ = link; + baudRate_ = link_.getBaudRate(); packetList_ = new Vector(); } Modified: trunk/source/gridsim/net/Packet.java =================================================================== --- trunk/source/gridsim/net/Packet.java 2008-08-03 05:58:42 UTC (rev 194) +++ trunk/source/gridsim/net/Packet.java 2008-08-03 06:00:43 UTC (rev 195) @@ -17,7 +17,7 @@ /** - * This the structure for packets. + * This class contains the structure for a network packet. * * @since GridSim Toolkit 3.1 * @author Gokul Poduval & Chen-Khong Tham, National University of Singapore @@ -64,7 +64,7 @@ * @post $none */ int getID(); - + /** * Returns the ID of the source of this packet. * @return source id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |