|
From: <sul...@us...> - 2008-09-29 10:30:49
|
Revision: 249
http://gridsim.svn.sourceforge.net/gridsim/?rev=249&view=rev
Author: sulistio
Date: 2008-09-29 10:30:45 +0000 (Mon, 29 Sep 2008)
Log Message:
-----------
minor updates due to changes in the ../Router.java and the removal of FnbRouter.java
Modified Paths:
--------------
trunk/source/gridsim/net/fnb/FnbNetworkReader.java
trunk/source/gridsim/net/fnb/FnbRIPRouter.java
Modified: trunk/source/gridsim/net/fnb/FnbNetworkReader.java
===================================================================
--- trunk/source/gridsim/net/fnb/FnbNetworkReader.java 2008-09-29 10:29:42 UTC (rev 248)
+++ trunk/source/gridsim/net/fnb/FnbNetworkReader.java 2008-09-29 10:30:45 UTC (rev 249)
@@ -8,9 +8,13 @@
* Organization: Universidad de Castilla La Mancha (UCLM), Spain.
* Copyright (c) 2008, The University of Melbourne, Australia and
* Universidad de Castilla La Mancha (UCLM), Spain
+ *
+ * Based on NetworkReader class.
+ * Things added or modifyed:
+ * - createNetworkSCFQ(...)
+ * - Use finiteBufferSCFQScheduler instead of SCFQScheduler
*/
-// NOTE: this class is similar to NetworkReader.java -- perhaps modify the original one?
package gridsim.net.fnb;
import gridsim.net.fnb.*;
@@ -19,9 +23,13 @@
import java.io.*;
import gridsim.*;
+
/**
* This is an utility class, which parses a file and constructs the
- * network topology automatically. <br>
+ * network topology automatically, using the SCFQ packet scheduler
+ * for network buffers ({@link gridsim.net.fnb.FnbSCFQScheduler}).
+ * Note that this class is based on the {@link gridsim.util.NetworkReader} class.
+ * <p>
* The file that defines the network has the following form: <br> <br>
* <tt>
* # specify the number of routers<br>
@@ -43,13 +51,9 @@
* inside a router.
* If it is not given, then by default the value is false.
*
- * Things added or modifyed:
- * - createNetworkSCFQ(...)
- * - Use finiteBufferSCFQScheduler instead of SCFQScheduler
- *
+ * @see gridsim.net.fnb.FnbSCFQScheduler
* @since GridSim Toolkit 4.2
- * @author Agustin Caminero, Universidad de Castilla La Mancha (Spain).
- * Based on NetworkReader class, by Uros Cibej and Anthony Sulistio.
+ * @author Agustin Caminero, Universidad de Castilla-La Mancha (UCLM) (Spain).
*/
public class FnbNetworkReader
{
@@ -66,8 +70,8 @@
* @param max_p maximum drop probability for RED
* @param queue_weight queue weight for RED
* @param stats whether we want to store stats or not
- * @return the list of finiteBufferRouters of the network or <tt>null</tt> if an error
- * occurs
+ * @return the list of finiteBufferRouters of the network or
+ * <tt>null</tt> if an error occurs
* @see gridsim.net.fnb.FnbSCFQScheduler
*/
public static LinkedList createSCFQ(String filename, double[] weight,
@@ -103,24 +107,25 @@
/**
- * Gets a finiteBufferRouter object from the list
+ * Gets a {@link gridsim.net.Router} object from the list
* @param name a router name
* @param routerList a list containing the finiteBufferRouter objects
- * @return a finiteBufferRouter object or <tt>null</tt> if not found
+ * @return a {@link gridsim.net.fnb.FnbRouter} object or
+ * <tt>null</tt> if not found
*/
- public static FnbRouter getRouter(String name, LinkedList routerList)
+ public static Router getRouter(String name, LinkedList routerList)
{
if (name == null || routerList == null || name.length() == 0) {
return null;
}
- FnbRouter router = null;
+ Router router = null;
try
{
Iterator it = routerList.iterator();
while ( it.hasNext() )
{
- router = (FnbRouter) it.next();
+ router = (Router) it.next();
if (router.get_name().equals(name) == true) {
break;
}
@@ -139,12 +144,13 @@
/**
* Creates a number of routers from a given buffered reader
* @param buf a Buffered Reader object
- * @param rate a flag denotes the type of FnbRouter will be using
+ * @param rate a flag denotes the type of Router will be using
* @param stats true if we want to store statistics
- * @return a list of FnbRouter objects or <tt>null</tt> if an error occurs
+ * @return a list of {@link gridsim.net.fnb.FnbRIPRouter} objects or
+ * <tt>null</tt> if an error occurs
*/
- private static LinkedList createRouter(BufferedReader buf,
- boolean rate, boolean stats) throws Exception
+ private static LinkedList createRouter(BufferedReader buf, boolean rate,
+ boolean stats) throws Exception
{
String line = null;
StringTokenizer str = null;
@@ -172,7 +178,7 @@
}
LinkedList routerList = new LinkedList();
- FnbRouter router = null; // a FnbRouter object
+ Router router = null; // a Router object
String name = null; // router name
String flag = null; // a flag to denote logging router or not
boolean log = false;
@@ -211,7 +217,7 @@
int my_id = (Integer.decode(my_id_str)).intValue();
- // create a specific FnbRouter object
+ // create a specific Router object
if (rate == true)
{
System.out.println(" ****** FnbNetworkReader.createRouter(): " +
@@ -240,28 +246,27 @@
* @param max_p maximum drop probability for RED
* @param queue_weight queue weight for RED
* @param stats true if we want to store statistics
- * @return a list of FnbRouter objects or <tt>null</tt> if an error occurs
+ * @return a list of {@link gridsim.net.fnb.FnbRIPRouter} objects or
+ * <tt>null</tt> if an error occurs
*/
- private static LinkedList createNetworkSCFQ(BufferedReader buf,
- double[] weight,
- int max_buf_size, int drop_alg,
- int min_th, int max_th,
- double max_p, double queue_weight, boolean stats) throws
- Exception
+ private static LinkedList createNetworkSCFQ(BufferedReader buf, double[] weight,
+ int max_buf_size, int drop_alg, int min_th,
+ int max_th, double max_p, double queue_weight,
+ boolean stats) throws Exception
{
if (buf == null)
{
return null;
}
- // create the FnbRouter objects first
+ // create the Router objects first
LinkedList routerList = createRouter(buf, false, stats);
int GB = 1000000000; // 1 GB in bits
String line;
String name1, name2;
StringTokenizer str = null;
- FnbRouter r1, r2;
+ Router r1, r2;
Link tempLink = null;
// creating the linking between two routers
@@ -344,17 +349,13 @@
queue_weight, stats);
}
-
-
-
r1Sched.setWeights(weight);
r2Sched.setWeights(weight);
r1.attachRouter(r2, tempLink, r1Sched, r2Sched);
}
+
return routerList;
}
-
-
} // end class
Modified: trunk/source/gridsim/net/fnb/FnbRIPRouter.java
===================================================================
--- trunk/source/gridsim/net/fnb/FnbRIPRouter.java 2008-09-29 10:29:42 UTC (rev 248)
+++ trunk/source/gridsim/net/fnb/FnbRIPRouter.java 2008-09-29 10:30:45 UTC (rev 249)
@@ -53,7 +53,7 @@
* processCountDroppedPkts()
* processEndOfSimulation(...)
*/
-public class FnbRIPRouter extends FnbRouter
+public class FnbRIPRouter extends Router
{
private Hashtable linkTable;
private Hashtable schedTable; // table of schedulers
@@ -61,7 +61,6 @@
private Hashtable routerTable;
private Hashtable forwardTable;
private int id;
- private final int BITS = 8; // 1 byte in bits
private int my_id_; // for a router named "router0", its my_id will be 0
@@ -194,9 +193,8 @@
* @pre otherSched != null
* @post $none
*/
- public void attachRouter(FnbRouter router, Link link,
- PacketScheduler thisSched,
- PacketScheduler otherSched)
+ public void attachRouter(Router router, Link link,
+ PacketScheduler thisSched, PacketScheduler otherSched)
{
String msg = super.get_name() + ".attachRouter(): Error - ";
if (router == null)
@@ -214,12 +212,12 @@
if (thisSched == null || otherSched == null)
{
System.out.println(msg +
- "the one or more packet schedulers are null.");
+ "the one or more packet schedulers are null.");
return;
}
- thisSched.setBaudRate(link.getBaudRate());
- otherSched.setBaudRate(link.getBaudRate());
+ thisSched.setBaudRate( link.getBaudRate() );
+ otherSched.setBaudRate( link.getBaudRate() );
link.attach(this, router);
this.attachRouter(router, link, thisSched);
@@ -230,7 +228,7 @@
* Joins two routers together. This is called by the routers themselves
* and should not be called by other entities.
*
- * @param router The FnbRouter to which this router will be connected.
+ * @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.
@@ -239,8 +237,7 @@
* @pre sched != null
* @post $none
*/
- protected void attachRouter(FnbRouter router, Link link,
- PacketScheduler sched)
+ public void attachRouter(Router router, Link link, PacketScheduler sched)
{
String msg = super.get_name() + ".attachRouter(): Error - ";
if (router == null)
@@ -263,26 +260,25 @@
linkTable.put(router.get_name(), link.get_name());
- if (!schedTable.containsKey(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());
+ 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( router.get_name() );
sb.append(", with link, ");
- sb.append(link.get_name());
+ sb.append( link.get_name() );
sb.append(", with packet scheduler, ");
- sb.append(sched.getSchedName());
+ sb.append( sched.getSchedName() );
- super.write(sb.toString());
+ super.write( sb.toString() );
}
}
@@ -316,27 +312,26 @@
}
Link link = entity.getLink();
- sched.setBaudRate(link.getBaudRate());
+ sched.setBaudRate( link.getBaudRate() );
link.attach(this, entity);
- linkTable.put(entity.get_name(), link.get_name());
+ linkTable.put( entity.get_name(), link.get_name() );
- if (!schedTable.containsKey(link.get_name()))
- {
+ if (!schedTable.containsKey( link.get_name() )) {
schedTable.put(link.get_name(), sched);
}
- hostTable.put(link.get_name(), entity.get_name());
+ 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( entity.get_name() );
sb.append(", with packet scheduler, ");
- sb.append(sched.getSchedName());
+ sb.append( sched.getSchedName() );
- super.write(sb.toString());
+ super.write( sb.toString() );
}
}
@@ -348,7 +343,7 @@
*/
protected synchronized void processEvent(Sim_event ev)
{
- switch (ev.get_tag())
+ switch ( ev.get_tag() )
{
case GridSimTags.PKT_FORWARD:
case GridSimTags.JUNK_PKT:
@@ -364,7 +359,8 @@
break;
case GridSimTags.END_OF_SIMULATION:
- processEndOfSimulation(ev);
+ //processEndOfSimulation(ev);
+ processEndSimulation(ev);
break;
case GridSimTags.FNB_UPDATE_ARED_PARAMETERS:
@@ -373,8 +369,8 @@
default:
System.out.println(super.get_name() + ".body(): Unable to " +
- "handle request from GridSimTags " +
- "with constant number " + ev.get_tag());
+ "handle request from GridSimTags " +
+ "with constant number " + ev.get_tag() );
break;
}
}
@@ -396,28 +392,13 @@
if ((schedTable.get(link)) instanceof ARED)
{
((ARED) sched).updateAREDParameters();
-
- if (storeStats)
- {
- ((ARED) sched).updateStats();
- }
}
- else if ((schedTable.get(link)) instanceof RED)
+
+ if (storeStats == true)
{
- if (storeStats)
- {
- ((RED) sched).updateStats();
- }
- }
- else
- {
- if (storeStats)
- {
- ((FIFO) sched).updateStats();
- }
+ sched.updateStats();
+ }
- }
-
} //for (Enumeration e = schedTable.keys(); e.hasMoreElements(); )
super.sim_schedule(super.get_id(),
@@ -426,14 +407,40 @@
GridSimTags.FNB_UPDATE_ARED_PARAMETERS);
}
+
+ //////////////////////////////////////////////////////////////////
/**At the end of simulations, write the counters into files.
* @param ev an event*/
- private void processEndOfSimulation(Sim_event ev)
+ protected void processEndSimulation(Sim_event ev)
{
processCountDroppedPkts(ev);
}
+
+ // todo
+ protected void processEndSimulation()
+ {
+ // empty
+ }
+
+ // todo
+ public ArrayList getRoutingTable()
+ {
+ return null;
+ }
+
+ protected void sendInitialEvent()
+ {
+ // This random is to avoid the initial stages of sims, where nothing happens
+ // (as users have not started to send gridlets).
+ Random random = new Random();
+ super.sim_schedule(super.get_id(),
+ GridSimTags.SCHEDULE_NOW + (200 * random.nextDouble()),
+ GridSimTags.FNB_UPDATE_ARED_PARAMETERS);
+ }
+
+ //////////////////////////////////////////////////////////////////
/**
@@ -504,19 +511,30 @@
double nextTime = 0;
Packet pkt = (Packet) ev.get_data();
-
PacketScheduler sched = getScheduler(pkt);
+
+ // 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).addEntryTime( GridSim.clock() );
((InfoPacket) pkt).addBaudRate(sched.getBaudRate());
}
// check downlink MTU, and split accordingly
- String linkName = getLinkName(pkt.getDestID());
+ 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));
@@ -524,13 +542,11 @@
// if no packets at the moment
if (sched.size() == 0)
{
- if (numPackets == 1)
- {
- nextTime = (pkt.getSize() * BITS) / sched.getBaudRate();
+ if (numPackets == 1) {
+ nextTime = (pkt.getSize() * NetIO.BITS) / sched.getBaudRate();
}
- else
- {
- nextTime = (MTU * BITS * 1.0) / sched.getBaudRate();
+ else {
+ nextTime = (MTU * NetIO.BITS * 1.0) / sched.getBaudRate();
}
sendInternalEvent(nextTime, sched);
@@ -570,15 +586,19 @@
np.setPath(conn);
np.setLast(id);
- super.write("enqueing, " + np);
- sched.enque(np); // put the packet into the scheduler
+ if (super.reportWriter_ != null) {
+ 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() - MTU * (numPackets - 1));
- super.write("enqueing, " + pkt);
- sched.enque(pkt); // put the packet into the scheduler
+ if (super.reportWriter_ != null) {
+ super.write("enqueing, " + pkt);
+ }
+ sched.enque(pkt); // put the packet into the scheduler
}
/**
@@ -594,9 +614,8 @@
String linkName = null;
//directly connected
- if (hostTable.containsValue(destName))
- {
- linkName = (String) linkTable.get(destName);
+ if (hostTable.containsValue(destName)) {
+ linkName = (String)linkTable.get(destName);
}
else
{
@@ -619,12 +638,11 @@
*/
public PacketScheduler getScheduler(Packet np)
{
- if (np == null)
- {
+ if (np == null) {
return null;
}
- String destName = GridSim.getEntityName(np.getDestID());
+ String destName = GridSim.getEntityName( np.getDestID() );
return getScheduler(destName);
}
@@ -640,8 +658,7 @@
*/
public PacketScheduler getScheduler(int dest)
{
- if (dest < 0)
- {
+ if (dest < 0) {
return null;
}
@@ -662,26 +679,37 @@
*/
public PacketScheduler getScheduler(String dest)
{
- if (dest == null || dest.length() == 0)
- {
+ if (dest == null || dest.length() == 0) {
return null;
}
PacketScheduler sched = null;
- if (hostTable.containsValue(dest))
+ try
{
- String linkName = (String) linkTable.get(dest);
- sched = (PacketScheduler) schedTable.get(linkName);
+ 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);
+ }
}
- else
- {
- // need to forward to another router
- Object[] data = (Object[]) forwardTable.get(dest);
- String router = (String) data[0];
- String linkName = (String) linkTable.get(router);
- sched = (PacketScheduler) schedTable.get(linkName);
+ catch (Exception e) {
+ sched = null;
}
-
+
return sched;
}
@@ -711,32 +739,32 @@
if (np != null)
{
// process ping() packet
- if (np instanceof InfoPacket)
- {
- ((InfoPacket) np).addExitTime(GridSim.clock());
+ if (np instanceof InfoPacket) {
+ ((InfoPacket) np).addExitTime( GridSim.clock() );
}
- super.write("dequeuing, " + np);
+ if (super.reportWriter_ != null) {
+ super.write("dequeuing, " + np);
+ }
// must distinguish between normal and junk packet
int tag = GridSimTags.PKT_FORWARD;
- if (np.getTag() == GridSimTags.JUNK_PKT)
- {
+ if (np.getTag() == GridSimTags.JUNK_PKT) {
tag = GridSimTags.JUNK_PKT;
}
// sends the packet via the link
- String linkName = getLinkName(np.getDestID());
+ String linkName = getLinkName( np.getDestID() );
super.sim_schedule(GridSim.getEntityId(linkName),
GridSimTags.SCHEDULE_NOW, tag, np);
// process the next packet in the scheduler
- if (!sched.isEmpty())
+ if ( !sched.isEmpty() )
{
- double nextTime = (np.getSize() * BITS) / sched.getBaudRate();
+ double nextTime = (np.getSize() * NetIO.BITS) / sched.getBaudRate();
sendInternalEvent(nextTime, sched);
}
- } // if (np !=null)
+ }
}
/**
@@ -749,8 +777,7 @@
*/
private synchronized boolean sendInternalEvent(double time, Object data)
{
- if (time < 0.0)
- {
+ if (time < 0.0) {
return false;
}
@@ -779,9 +806,9 @@
for (Enumeration e = forwardTable.keys(); e.hasMoreElements(); )
{
- String host = (String) e.nextElement();
- Object[] data = (Object[]) forwardTable.get(host);
- String nextHop = (String) data[0];
+ String host = (String)e.nextElement();
+ Object[] data = (Object[])forwardTable.get(host);
+ String nextHop = (String)data[0];
System.out.println(host + "\t\t" + nextHop);
}
@@ -814,16 +841,18 @@
Collection hosts = hostTable.values(); // who to advertise
Enumeration routers = routerTable.elements();
- while (routers.hasMoreElements())
+ while ( routers.hasMoreElements() )
{
RIPAdPack ad = new RIPAdPack(super.get_name(), hosts);
String router = (String) routers.nextElement();
- super.write("advertise to router, " + router);
+ if (super.reportWriter_ != null) {
+ super.write("advertise to router, " + router);
+ }
sim_schedule(Sim_system.get_entity_id(router),
GridSimTags.SCHEDULE_NOW, GridSimTags.ROUTER_AD, ad);
}
- super.sim_pause(5); // wait for 5 secs to gather the results
+ super.sim_pause(5); // wait for 5 secs to gather the results
}
/**
@@ -836,32 +865,31 @@
*/
private synchronized void receiveAd(Sim_event ev)
{
- super.write("receive router ad from, " +
- GridSim.getEntityName(ev.get_src()));
+ if (super.reportWriter_ != null) {
+ 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();
+ RIPAdPack ad = (RIPAdPack)ev.get_data();
// prevent count-to-infinity
- if (ad.getHopCount() > 15)
- {
+ if (ad.getHopCount() > Router.MAX_HOP_COUNT) {
return;
}
String sender = ad.getSender();
Iterator it = ad.getHosts().iterator();
- while (it.hasNext())
+ while ( it.hasNext() )
{
String host = (String) it.next();
- if (host.equals(super.get_name()))
- {
+ if ( host.equals(super.get_name()) ) {
continue;
}
- if (hostTable.containsValue(host))
- { // direct connection
+ if (hostTable.containsValue(host)) { // direct connection
continue;
}
@@ -872,15 +900,13 @@
if ((hop) > ad.getHopCount())
{
- Object[] toPut =
- {sender, new Integer(ad.getHopCount())};
+ Object[] toPut = {sender, new Integer(ad.getHopCount()) };
forwardTable.put(host, toPut);
}
}
else
{
- Object[] toPut =
- {sender, new Integer(ad.getHopCount())};
+ Object[] toPut = {sender, new Integer(ad.getHopCount()) };
forwardTable.put(host, toPut);
}
}
@@ -900,18 +926,17 @@
{
String sender = ad.getSender();
ad.incrementHopCount();
- RIPAdPack newad = new RIPAdPack(super.get_name(), ad.getHosts());
+ RIPAdPack newad = new RIPAdPack(super.get_name(),ad.getHosts());
newad.setHopCount(ad.getHopCount());
Enumeration routers = routerTable.elements();
- while (routers.hasMoreElements())
+ while ( routers.hasMoreElements() )
{
- String router = (String) routers.nextElement();
+ String router = (String)routers.nextElement();
if (!router.equals(sender))
{
sim_schedule(Sim_system.get_entity_id(router),
- GridSimTags.SCHEDULE_NOW, GridSimTags.ROUTER_AD,
- newad);
+ GridSimTags.SCHEDULE_NOW, GridSimTags.ROUTER_AD, newad);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|