Class CommandsParser

java.lang.Object
  extended byCommandsParser
Direct Known Subclasses:
EmulationCommandsParser, SimulationCommandsParser, TrawlerCommandsParser

public abstract class CommandsParser
extends java.lang.Object

 CommandsParser -- parses topology and keyboard commands
 
 COMMANDS ARE CASE SENSITIVE. 
 
 Pay attention to the spaces.
 Commands are parsed by using the spaces as delimiters thus it is very important
 to put spaces where required. Also putting consecutive spaces will cause the command to be incorrect.

 THUS THE PARSER IS VERY SENSITIVE TO THE LOCATION OF SPACES AND NUMBER OF SPACES 

 The topology file and the keyboard input file have the same format;
 all the same commands can be entered from either one.  Both
 are line-oriented (one command per line). 
 Nodes (e.g., a, b) are referred to by their FishnetAddress (0..254).

	[// | #]   -- any line starting with // or # is ignored
	edge a b [lossRate ] [delay ] [bw ]
		-- this creates an edge between a and b, with the
		specified loss rate, delay (in milliseconds), and bw (in KB/s),
		or changes the specifics for an existing link
		defaults: 0 lossRate, 1 msec delay, and 10Kb/s bw
	time [+ ]x  -- any subsequent command is delayed until simulation/real
			has reached x (or now + x, if + is used), in milliseconds from start
                    NOTE: IF + IS USED THERE MUST BE A SPACE BETWEEN + AND x
	fail a [b] -- this removes node a (if b is not specified) or an edge (if it is)
	restart a [b]  -- this restarts a node or edge.  previous information about
		the node/edge is preserved
	echo text -- print the text 
	exit  -- cleanly stop the simulation/emulation run and print statistics
	a   -- deliver text  to node a (for simulation mode only)
	 -- deliver text  to this node (for emulation mode only)
		Note that msg cannot start with any keyword defined above

 To avoid a race condition with respect to starting up the user protocol code,
 the simulator will only process keyboard commands at time >  0.
 


Constructor Summary
protected CommandsParser()
           
 
Method Summary
protected  void createNewEdge(int nodeA, int nodeB, EdgeOptions options)
           
protected abstract  void exit(java.lang.String[] cmd)
          Call manager.stop() if the command is exit.
protected  boolean failEdge(int nodeA, int nodeB)
           
protected  void failNode(int node)
           
protected  long parseCommonCmds(java.lang.String[] cmd, long now)
          Parses exit, echo, time and node commands Returns how long parsing should be deferred for if time command encountered.
 long parseFile(java.lang.String filename, long now)
          Open and process a topology file.
 long parseLine(java.lang.String line, long now)
          Process one line of topology file or keyboard input.
protected abstract  void parseNodeCmd(java.lang.String[] cmd)
           
 long parseRemainder(long now)
          Parse the rest of a command file.
protected  void printStrArray(java.lang.String[] strArray, int startIndex, int endIndex, java.io.PrintStream stream)
           
protected  void printStrArray(java.lang.String[] strArray, java.io.PrintStream stream)
           
protected  boolean restartEdge(int nodeA, int nodeB)
           
protected  void restartNode(int node)
           
protected  boolean skipLine(java.lang.String line)
          Returns true if line should be skipped, either because its empty or is a comment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandsParser

protected CommandsParser()
Method Detail

parseFile

public long parseFile(java.lang.String filename,
                      long now)
               throws java.io.FileNotFoundException
Open and process a topology file.

Parameters:
filename - The name of the command file.
now - The current time.
Returns:
How long to defer further processing. Returns -1 if do not have to defer
Throws:
java.io.FileNotFoundException - If the named filed does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading

parseRemainder

public long parseRemainder(long now)
Parse the rest of a command file. Parsing will be deferred if we run into a time command.

Parameters:
now - The current time in microseconds
Returns:
How long to defer further processing. Returns -1 if do not have to defer

parseLine

public long parseLine(java.lang.String line,
                      long now)
Process one line of topology file or keyboard input.

Parameters:
line - A command line.
now - The current time in microseconds
Returns:
How long to defer further processing. Returns -1 if do not have to defer

exit

protected abstract void exit(java.lang.String[] cmd)
Call manager.stop() if the command is exit. Actually will accept exit followed by anything Thus "exit" and "exit blahblah" will both cause fishnet to exit. However "exitblahblah" will not.


parseNodeCmd

protected abstract void parseNodeCmd(java.lang.String[] cmd)

skipLine

protected boolean skipLine(java.lang.String line)
Returns true if line should be skipped, either because its empty or is a comment


parseCommonCmds

protected long parseCommonCmds(java.lang.String[] cmd,
                               long now)
Parses exit, echo, time and node commands Returns how long parsing should be deferred for if time command encountered. Returns -1 if parsing should not be deferred


createNewEdge

protected void createNewEdge(int nodeA,
                             int nodeB,
                             EdgeOptions options)

failEdge

protected boolean failEdge(int nodeA,
                           int nodeB)

failNode

protected void failNode(int node)

restartEdge

protected boolean restartEdge(int nodeA,
                              int nodeB)

restartNode

protected void restartNode(int node)

printStrArray

protected void printStrArray(java.lang.String[] strArray,
                             int startIndex,
                             int endIndex,
                             java.io.PrintStream stream)

printStrArray

protected void printStrArray(java.lang.String[] strArray,
                             java.io.PrintStream stream)