Class Simulator

java.lang.Object
  extended by Manager
      extended by Simulator

public class Simulator
extends Manager

 Manages a simulation. All nodes are instantiated in process.
 


Field Summary
static int MAX_NODES_TO_SIMULATE
           
 
Fields inherited from class Manager
parser, reader, sortedEvents
 
Constructor Summary
Simulator(int numNodes, java.lang.String topoFile)
          Creates a new simulation
 
Method Summary
 void addTimerAt(int nodeAddr, long t, Callback callback)
          Adds a timer to be fired at time t
 long now()
          Retrieve current time in milliseconds
 void parseRestOfTopoFile()
          Parses rest of topology file.
 boolean sendNodeMsg(int nodeAddr, java.lang.String msg)
          Sends the msg to the the specified node
 boolean sendPkt(int from, int to, byte[] pkt)
          Send the pkt to the specified node
 void setTimescale(double timescale)
          Sets the amount to scale real time by.
 void start()
          Starts the simulation
 
Methods inherited from class Manager
addEvent, addTimer, packetDropped, packetLost, readFishFile, setFishnetFile, setParser, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_NODES_TO_SIMULATE

public static final int MAX_NODES_TO_SIMULATE
See Also:
Constant Field Values
Constructor Detail

Simulator

public Simulator(int numNodes,
                 java.lang.String topoFile)
          throws java.lang.IllegalArgumentException,
                 java.io.FileNotFoundException
Creates a new simulation

Parameters:
numNodes - The number of nodes to simulate
topoFile - The name of the topology file to use
Throws:
java.lang.IllegalArgumentException - If the number of nodes to simulate is < 0 or > MAX_NODES_TO_SIMULATE
java.io.FileNotFoundException - If the given topology file cannot be found
Method Detail

start

public void start()
Starts the simulation

Specified by:
start in class Manager

sendPkt

public boolean sendPkt(int from,
                       int to,
                       byte[] pkt)
                throws java.lang.IllegalArgumentException
Send the pkt to the specified node

Overrides:
sendPkt in class Manager
Parameters:
from - The node that is sending the packet
to - Int spefying the destination node
pkt - The packet to be sent, serialized to a byte array
Returns:
True if the packet was sent, false otherwise
Throws:
java.lang.IllegalArgumentException - If the arguments are invalid

now

public long now()
Retrieve current time in milliseconds

Specified by:
now in class Manager
Returns:
Current time in milliseconds

addTimerAt

public void addTimerAt(int nodeAddr,
                       long t,
                       Callback callback)
Adds a timer to be fired at time t

Overrides:
addTimerAt in class Manager
Parameters:
nodeAddr - Addr of node that is registering this timer
t - The time when the timer should fire. Its in milliseconds
callback - The callback to be invoked when the timer fires

sendNodeMsg

public boolean sendNodeMsg(int nodeAddr,
                           java.lang.String msg)
Sends the msg to the the specified node

Specified by:
sendNodeMsg in class Manager
Parameters:
nodeAddr - Address of the node to whom the message should be sent
msg - The msg to send to the node
Returns:
True if msg sent, false if address is not valid

setTimescale

public void setTimescale(double timescale)
Sets the amount to scale real time by.

Overrides:
setTimescale in class Manager
Parameters:
timescale - The amount to scale real time by

parseRestOfTopoFile

public void parseRestOfTopoFile()
Parses rest of topology file. Has public accesibility since used as a callback