How to use the simulator
This is a simulator for synchronous distributed systems. The simulator was written
in Java and it was
compiled with the Java compiler version 1.2.2 under Solaris.
First, download all the files and put them in the
same directory. To compile your java file type
Where file is the name of the java file containing your implementation of the distributed
algorithm that you want to run on the simulator. To run the simulator type
file is the name of the input
file specifying the network and algorithm to be executed.
The Input File
The input file is a text file and each line contains one of the following commands:
- AddNode x: x1 x2 ... xk. Adds a processor with id = x and neighbours
x1, x2, ... xk
- LoadAlgorithm Alg. Specifies the java class containing the distributed algorithm
to be executed. This means that the algorithm must be defined in a java file called
Alg.java. You must compile this java class before running the simulator.
- RootNode z. Marks node z as a special node. You might find this useful, for
example, when broadcasting information from a particular processor to the rest of the
- RoundTime t. Specifies the duration of each round in milliseconds. You have to choose
a sufficiently large number that allows the simulator to complete a round for each processor
before the next round starts.
- Debug flag. If flag = 1 the simulator will pause after completing each round.
If flag = 0 the simulator will execute the algorithm to completion.
The distributed algorithm to be executed by the simulator must be a java program. The name of
the java class containing the algorithm must be specified in the input file as described
above. Look at the examples to get an idea of how you must write your own distributed
algorithms. The simulator provides several commands that you can use to program your
- getID(). Gets the processors id.
- neighbours(). Returns a java Vector containing the id's of this processor's neighbours.
Each id is stored as a java String.
- new Message(String destination,String source,String data). Creates a new message. Each message
contains 3 fields:
the id of the destination processor, the id of the sending processor, and the message's
- new Message(Vector destinations,String source,String data). Creates a new message with multiple
destinations. When the message is sent a copy of the message will first be created
containing only one destination; then the message will be sent there.
- waitForNextRound(). Makes the current process wait until the beginning of the following
- send(Message mssg). Sends the specified message to the destination specified in the
- receive(). Waits for messages from the neighbours. If no messages arrive in the current
round, null is returned. If several messages are sent to the processor in a round, then
multiple invocations to the receive method will be needed to read them all.
- equal(String s, String t). Returns true if strings s and t are the same; returns
- larger(String s, String t). Returns true if s is larger than t; returns false
otherwise. If s and t contain only characters '0' to '9', then these strings are
first converted to integer numbers and then compared. Otherwise a lexicographic comparison
is made to determine which string is larger.
- printMessage(String message). Prints the argument on the screen.