GridSim 5.0 beta

gridsim.net
Class Router

Object
  extended by Thread
      extended by Sim_entity
          extended by Router
All Implemented Interfaces:
Cloneable, Runnable
Direct Known Subclasses:
FloodingRouter, FlowRouter, FnbRIPRouter, RateControlledRouter, RIPRouter

public abstract class Router
extends Sim_entity

This class implements a Router which forwards data from one entity to another.

This abstract class only contains abstract methods to connect other routers and hosts. In addition, common functionalities are available in this class for its children classes to use. However, this class does not provide methods on how to setup forwarding tables, so the design of that is left to the user if he/she wants to create a Router with some specific routing algorithm.

Few important notes to consider when extending from this class:

Since:
GridSim Toolkit 3.1
Author:
Gokul Poduval & Chen-Khong Tham, National University of Singapore
Invariant:
$none

Nested Class Summary
 
Nested classes/interfaces inherited from class Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected static int DELAY
          Denotes a time delay (in second) for sending events in the future.
static int MAX_HOP_COUNT
          An attribute that denotes the maximum number of hopcount used for advertising adjacent routers.
protected  SimReport reportWriter_
          An attribute that logs incoming and outgoing packets into a file.
 
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Router(String name)
          Creates a new RIPRouter object.
Router(String name, boolean trace)
          Creates a new Router object with logging facility if it is turned on.
 
Method Summary
protected abstract  void advertiseHosts()
          All hosts connected to this router are advertised to adjacent routers
abstract  void attachHost(GridSimCore entity, PacketScheduler sched)
          Attaches an entity to this router.
abstract  void attachRouter(Router router, Link link, PacketScheduler sched)
          Joins two routers together.
abstract  void attachRouter(Router router, Link link, PacketScheduler thisSched, PacketScheduler otherSched)
          Joins two routers with a Link.
 void body()
          Handles incoming requests.
abstract  PacketScheduler getScheduler(int dest)
          Returns the Scheduler that the router would use to reach a particular destination.
abstract  PacketScheduler getScheduler(Packet np)
          Returns the Scheduler associated with a packet.
abstract  PacketScheduler getScheduler(String dest)
          Returns the Scheduler that the router would use to reach a particular destination.
abstract  void printRoutingTable()
          This method prints out the forwarding table of the router in a human readable form.
protected abstract  void processEndSimulation()
          Informs the registered entities regarding to the end of a simulation.
protected abstract  void processEvent(Sim_event ev)
          Overrides this method when creating a new type of router.
protected  void registerOtherEntity()
          Overrides this method when making a new type of router.
protected  void sendInitialEvent()
          Overrides this method when sending initial event(s) to itself or others BEFORE receiving incoming events from other entities.
protected  void write(String str)
          Writes a debug information to a file.
 
Methods inherited from class Sim_entity
add_generator, add_param, add_port, clone, get_id, get_name, get_port, get_port, get_stat, run, send_on, set_invisible, set_stat, sim_cancel, sim_completed, sim_current, sim_get_next, sim_get_next, sim_hold_for, sim_hold, sim_pause_for, sim_pause_for, sim_pause_until, sim_pause_until, sim_pause, sim_process_for, sim_process_for, sim_process_until, sim_process_until, sim_process, sim_putback, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_schedule, sim_select, sim_trace, sim_wait_for, sim_wait_for, sim_wait_for, sim_wait, sim_waiting, sim_waiting
 
Methods inherited from class Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_HOP_COUNT

public static int MAX_HOP_COUNT
An attribute that denotes the maximum number of hopcount used for advertising adjacent routers. The default value is 15. This attribute is used to prevent from a count-to-infinity scenario. Note that if you have a large topology with many routers, you can set this attribute to a higher number.


reportWriter_

protected SimReport reportWriter_
An attribute that logs incoming and outgoing packets into a file. Use write(String) to log or record the information.


DELAY

protected static int DELAY
Denotes a time delay (in second) for sending events in the future.

Constructor Detail

Router

public Router(String name)
       throws NullPointerException
Creates a new RIPRouter object. By default, no recording or logging is done for packets' activities. If you want to log operations of this entity, please use Router(String, boolean).

Parameters:
name - Name of this router
Throws:
NullPointerException - This happens when name is empty or null
See Also:
Router(String, boolean)
Pre Condition:
name != null
Post Condition:
$none

Router

public Router(String name,
              boolean trace)
       throws NullPointerException
Creates a new Router object with logging facility if it is turned on.
NOTE: If logging facility is turned on, there are some overheads in terms of performance and memory consumption.

Parameters:
name - Name of this router
trace - true if you want to record this router's activity, false otherwise
Throws:
NullPointerException - This happens when name is empty or null
Pre Condition:
name != null
Post Condition:
$none
Method Detail

attachRouter

public abstract void attachRouter(Router router,
                                  Link link,
                                  PacketScheduler thisSched,
                                  PacketScheduler otherSched)
Joins two routers with a Link.

Parameters:
router - The router on the other side to which this one will be attached.
link - This is the link that will be used to connect the two routers.
thisSched - The scheduling policy used on this routers egress port when sending data through it.
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 Condition:
router != null, link != null, thisSched != null, otherSched != null
Post Condition:
$none

attachRouter

public abstract void attachRouter(Router router,
                                  Link link,
                                  PacketScheduler sched)
Joins two routers together. This is called by the routers themselves and should not be called by other entities.

Parameters:
router - The Router to which this router will be connected.
link - The Link that will be used to join these routers.
sched - The scheduling policy used on the egress port of the router when sending data through this route.
Pre Condition:
router != null, link != null, sched != null
Post Condition:
$none

attachHost

public abstract void attachHost(GridSimCore entity,
                                PacketScheduler sched)
Attaches an entity to this router. The link between the router and the entity being attached is taken from GridSimCore.getLink().

Parameters:
entity - The entity to be attached.
sched - The scheduling policy that will be used on the egress port when the router sends data to the entity being joined.
See Also:
GridSimCore.getLink()
Pre Condition:
entity != null, sched != null
Post Condition:
$none

getScheduler

public abstract PacketScheduler getScheduler(Packet np)
Returns the Scheduler associated with a packet. Each packet has a destination. The router returns the scheduler that it would use to scheduler this packet if it were traversing this router. Once a reference to the scheduler is obtained, different parameters (like priorities, weights etc.) could be modified.

Parameters:
np - NetPacket for which the associated scheduler is to be returned. This can be used to set weigths, priorities, etc. as the case may be on the Scheduler.
Returns:
the packet's scheduler
Pre Condition:
np != null
Post Condition:
$none

getScheduler

public abstract PacketScheduler getScheduler(int dest)
Returns the Scheduler that the router would use to reach a particular destination. Once a reference to the scheduler is obtained, different parameters (like priorities, weights etc.) could be modified.

Parameters:
dest - id of the destination for which the Scheduler is required.
Returns:
the packet's scheduler
Pre Condition:
dest > 0
Post Condition:
$none

getScheduler

public abstract PacketScheduler getScheduler(String dest)
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

Parameters:
dest - Name of the destination for which the Scheduler is required.
Returns:
the packet's scheduler
Pre Condition:
dest != null
Post Condition:
$none

printRoutingTable

public abstract void printRoutingTable()
This method prints out the forwarding table of the router in a human readable form.

Pre Condition:
$none
Post Condition:
$none

body

public void body()
Handles incoming requests. DO NOT overrides this method as it contains code/functionality to register this entity to GridInformationService entity, and finalizing logging information before exiting the simulation.

This method also calls these methods in the following order:

  1. must overridden advertiseHosts() method. It is needed for advertising all hosts or entities connected to this entity to adjacent routers.
  2. registerOtherEntity() method : for registering other event type/tag to GridInformationService. This is optional.
  3. must overridden processEvent(Sim_event) method. It is needed for processing incoming events.

Overrides:
body in class Sim_entity
Pre Condition:
$none
Post Condition:
$none

advertiseHosts

protected abstract void advertiseHosts()
All hosts connected to this router are advertised to adjacent routers

Pre Condition:
$none
Post Condition:
$none

processEvent

protected abstract void processEvent(Sim_event ev)
Overrides this method when creating a new type of router. This method is called by body() for incoming unknown tags.

The services or tags available for this resource are:

Parameters:
ev - a Sim_event object
Pre Condition:
ev != null
Post Condition:
$none

registerOtherEntity

protected void registerOtherEntity()
Overrides this method when making a new type of router. This method is called by the body() method to register to other type of the GridInformationService entity. In doing so, you need to create a new child class extending from the GridInformationService class.
NOTE: You do not need to override the body() method, if you use this method.

See Also:
GridInformationService
Pre Condition:
$none
Post Condition:
$none

sendInitialEvent

protected void sendInitialEvent()
Overrides this method when sending initial event(s) to itself or others BEFORE receiving incoming events from other entities.
NOTE: You do not need to override the body() method, if you use this method.

Pre Condition:
$none
Post Condition:
$none

write

protected void write(String str)
Writes a debug information to a file. The format of information is left to the coder.

Parameters:
str - a string message
Pre Condition:
str != null
Post Condition:
$none

processEndSimulation

protected abstract void processEndSimulation()
Informs the registered entities regarding to the end of a simulation.

Pre Condition:
$none
Post Condition:
$none

GridSim 5.0 beta

The University of Melbourne, Australia, 2009