EASIM is a MANET simulator which is an extension of the JiST/SWANS simulator. Our extension has two components: a framework of easy-to use wrappers of JiST/SWANS for developing routing protocols in a mobile environment, and a graphical user interface for testing purpose. We wrote this extension because most realistic ad hoc network simulators in the research community are
difficult to learn and use which distracts researchers from concentrating on the algorithm aspect. The graphical user interface, which synchronizes the simulation time and the computer time, provides a realtime simulation environment for the observation of the global statistics as well as per-node state, and it allows interaction with the simulator for easy testing and convenient network deployments.
Chapter 1 Installation and start-up
Chapter 2 Basic components
Chapter 3 The graphical user interface
Chapter 4 Developping simulation in MANETs
Chapter 5 Developping simulation in DTNs
Chapter 1 Installation and start-up
1) Install Java 1.4 (setting environment parameters.)
2) Download source code of JiST/SWANS from
http://jist.ece.cornell.edu/sw.html
and unzip it.
3) Upzip "easim.zip" to the "src" folder in JiST/SWANS.
4) Set environmental parameters
@set CP=..\libs\bcel.jar;..\libs\bsh.jar;..\libs\jargs.jar;..\libs\log4j.jar;..\libs\jython.jar;.
@set OPT=-g -source 1.4 -classpath %CP%
@set CLASSPATH=%CP%
path=C:\j2sdk1.4.2_17\bin;..\bin
5) Compile and run EASIM with the following commands:
------------
javac easim\net\*.java easim\win\*.java easim\draw\*.java easim\mobi\*.java easim\omar\*.java easim\examples\*.java
swans easim.examples.Main1
------------
If a window is shown without Java Exceptions, the installation is successful.
Chapter 2 Basic components
EASIM is very simple to use. One does not need to learn JiST/SWANS in advance in order to use the full feature of EASIM.
The basic classes in EASIM are:
easim.net.Field;
easim.net.Node;
easim.win.Frame;
Their interface are list as follows:
interface Node
{
/*
* initialized a Node with a unique integer identifier.
*/
Node(int id);
/*
* send a message to a neighbor.
* to broadcast, use Node.ADDRESS_ANY (-1) as the 2nd parameter.
*/
void send(Message msg, int dstId);
/*
* get the identifier of the current node.
*/
int getId();
/*
* get the position of the current node.
*/
float getX();
/*
* get the position of the current node.
*/
float getY();
/*
* To be implemented.
* This function is called when received a message.
*/
void receive(Message msg, int srcId, int dstId);
/*
* To be implemented (sometimes, this function can be left empty).
* This function is called when the status of the link layer changes.
* 'queueSize' is the number of messages in the queue.
* 'macBusy' is true if the MAC is sending a message.
*/
void pump(int queueSize, boolean macBusy);
}
/*
* A field is a square region when the nodes resides.
*/
interface Field
{
/*
* The maximum size of the field.
* The actual region of node placement
* are determined by the mobility model.
* @see easim.mobi.*;
*/
static int FIELD_SIZE = 999;
/*
* add a node to the field.
*/
static void add(Node node, float x, float y);
/*
* move a node to a new position [*].
*/
static void move(Node node, float x, float y);
/*
* delete a node.
*/
static void delete(Node node);
/*
* get the identifiers of the nodes within
* the transmission range of the current node [*].
*/
static int[] getNeighborIds(float x, float y);
}
Functions with [*] are not recommended be called directly in the user programs, they should be called only by other programs within the framework of EASIM.
interface Frame
{
/*
* start the graphical interface
*/
static void main(String[] args);
}
An example where 3 nodes send and receive unicast and broadcast messages are shown by the following files:
easim/exammples/Node1.java
easim/exammples/Main2.java
This example is run with the following command:
swans easim.examples.Main2
In this example, not all nodes receive messages as expected for interference.
Chapter 3 The graphical user interface
1) Starting the graphical interface
Using the following command to start the graphical interface:
swans easim.win.Frame
Since a customized Node class need to be defined by the user outside the framework of EASIM, The graphical interface will ask the use to select the class file where the user Node is defined. Node that the user defined Node should be a subclass of easim.net.Node.
Another way to start the graphical interface is shown in easim/example/Main1.java, where the graphical interface is started in line 16 by statement "Frame.main(args)". We can appoint a Node class (as shown in line 15) before starting the graphical interface so that the user need not select the Node class everytime he the graphical interface is started.
After starting the user interface, one and use mouse to add a node (move the mouse to any position in the white panel and click the left button), delete a node (move the mouse to a node and click the middle button), and move a node (drag and draw a node). When the mouse is moved over a node, the string return by the toString method of the node will be displayed. User can use this to display the internal information of each node.
2) Interacting with the simulator
Besides adding, moving, and removing nodes, EASIM allows user to interacting with the simulator. This includes calling function of a particular node, and call functions of calling functions of all nodes. This functions are implemented with two (or one) PopupMenus. Please see easim/examples/PopupMenu3.java as an example. Here, all actions are implemented inside a method of class easim.win.SynControler.Interactor which is executed when the simulator is interrupted.
3) Avoid loading classes each time.
If the graphical interface is started by calling "swans easim.win.Frame", the Node class and the 2 PopupMenu classes will be asked. One can tell the graphical interface before it starts to avoid being asked. This can be done by a way similar to line 17 through 20 of easim/examples/Main3.java. Frame.info can be assign an object whose toString method will be called at interval and the string returned will be printed in the top left corner of the panel. It can be used to show the internal state of the simulator.
Examples of definition of Interactors are shwon in line 24-55 in easim/examples/PopupMenu3.java, and example for invoking this Interactors (through calling SynControler.interact(Interactor)) are shown in line 71-85 in the same file.
Chapter 4 Developping simulation in MANETs
1) Timer & Clock
Two useful classes not yet mention are Timer and Clock. Timer is an interface with a method "timeout". The interface of Clock is in the following:
interface Clock
{
/*
* return the simulation time.
*/
static long getTime();
/*
* Schedule at an event (an execution of the timeout method of the
* given timer object). Here delay is the event time from the current
* simulation time.
* If cancelPrevTimer is true and a event of the same timer was previously
* sechduled, the previous event will be cancel. On the other hand, if
* cancelPrevTimer is false and a event of the same timer was previously
* sechduled, the event to be schedule by this method will not take effect.
* Return whether the current event is schedule successfully.
*/
static boolean start(Timer timer, long delay, boolean cancelPrevTimer);
/*
* Cancel the event scheduled for the given timer.
* Return whether a cancellation is successful (or whether an event is
* previously scheduled for the given timer).
*/
static boolean cancel(Timer timer);
}
An example of using Timer and Clock is shown in line 27-38 of easim/example/Node3.java, where Timer1 always schedule the next event in its timeout method such that its timeout method is invoked every 2 seconds.
Chapter 5 Developping simulation in DTNs
1) DtnNode
We provide an extension of Node for developping DTN routing algorithms, easim.net.DtnNode. DtnNode exposes a completely different interface than Node. DtnNode use a neighbor discovery mechanism which adopts periodical beacons. In the implementation, the beacon interval is a random time frame between 100ms and 200ms (configurable in easim.net.DtnNodeInterface). If no message is corresponded for T_{break} (1s), two nodes are regarded as disconnected. To reduce contention, we use a jitter delay n*d for any message, where n is the number of contacts and d is a random delay between 0 and 10ms.
DtnNode also implements reliable broadcast. By reliable broadcast, we mean that the sender application must be notified when some recipients fail to receive the broadcast message. Our reliable broadcast is based on the neighbor discovery mechanism which provides the information of the current contacts. It requires that the acknowledgements of a broadcast are replied from all contacts, piggybacked in their next messages (beacons or data messages). When a node A broadcasts a message m to its neighbors, say B
and C, sets of acknowledgements S_B and S_C (obtained from A¡¯s local acknowledgements depository D_B and D_C which store the unsent acknowledgements for B and C respectively) are piggybacked to m. When A receives acknowledgement of m from one of its neighbors, say B, it can remove S_B from D_B since all acknowledgements in S_B were received by B. If acknowledgement of m is not received from one of A¡¯s neighbors, say C, after a timeout Tack (500ms), a dropmessage event will be generated in A containing the ID of C, which will be reported to the sender application.
The interface of DtnNode is shown in the following:
interface DtnNode
{
/*
* Start the neighbor discovery protocol (start sending beacons).
*/
void start();
/*
* Inform the node that some message is ready to send.
* @see method 'nextMessageToSend'
*/
void startJitterTimer();
////////////////////
// The following method need to be implemented by subclasses.
//
/*
* This method is invoked for a possible next message to send.
* If the node has a message to send, return the message, otherwise
* returns null.
* This method is invoked when (1) a non-null message is returned
* in the last invocation of this method, or (2) method
* 'startJitterTimer' is called to explicitly required this method to
* be invoked.
*/
Message nextMessageToSend();
/*
* This method is invoked when the current node received a message.
*/
void receiveMessage(Message message, int srcId);
/*
* This method is invoked when the last message sent (the message
* returned to 'nextMessageToSend') is acknowledged by all of the current
* neighbors.
*/
void onAckMessage(Message message);
/*
* This method is invoked when the last message sent (the message
* returned to 'nextMessageToSend') is not acknowledged by all of the
* current neighbors. 'desIds' are the identifiers of those neighbors
* that did not acknowledge the last message.
*/
void onDropMessage(Message message, int[] dstIds);
/*
* This method is invoked when the current node has a new neighbor
* whose identifier is 'id'.
*/
void onContactDetected(int id);
/*
* This method is invoked when the current node loses a neighbor
* whose identifier is 'id'.
*/
void onContactBroken(int id);
}
An example of using class DtnNode is given by "easim/examples/Node3.java".
Note that this file together with "easim/examples/PopupMenu3.java" and "easim/examples/Main3.java" give an combined example of using the easim.mobi.Mobility, the PopupMenu and the DtnNode.
               (
geocities.com/gzcliu_proj)