SimpleNet consists of a main engine that provides the basic network
functionality, including some basic node functionalities, the network
topology configuration, link-layer communication, and forwarding. The
user must provide the implementation of a routing protocol. This is
done by implementing a class that extends the simplenet.Router
class.
MyRouter
as follows:
import simplenet.*;
class MyRoutingMessage extends RoutingMessage {
public int address;
public MyRoutingMessage(int addr) {
address = addr;
}
}
public class MyRouter extends simplenet.Router {
public void process_routing_message(RoutingMessage m, int ifx) {
System.out.println("I got a routing message from interface " + ifx);
System.out.println("Hello neighbor " + ((MyRoutingMessage)m).address);
}
public void initialize() {
System.out.println("I am router " + my_address());
System.out.println("I have " + interfaces() + " neighbors.");
for(int i = 0; i < interfaces(); ++i) {
send_message(new MyRoutingMessage(my_address()), i);
}
}
}
Assuming the simplenet.jar
file is in the current
directory, and obviously that this code is in a file called
MyRouter.java
this code can be compiled with the
following command:
javac -classpath simplenet.jar MyRouter.java
We are now almost ready to run the simulation. Before doing that, we
should define a network topology to use in our simulation. We ca do
that by creating a file, called test1
, containing the
following lines:
1 2 3.0
2 3 4.0
3 4 1.0
4 1 9.0
The format of the input file will be discussed later. We can now run
the simulation with the following command:
java -classpath simplenet.jar:. simplenet.Network MyRouter test1
simplenet.Router
class, and are documented there.
The network model consists of a graph. Routers are connected through
symmetric, duplex links. The cost of a link is a double
value, and represents the latency of the link. Routers have one
address. Addresses are int
values. Each node has a
number of interfaces, connecting it to its neighbors. Interfaces are
numbered starting from 0
, up to interfaces() -
1
.
source-address destination-address link-cost
Where source-address and destination-address are integer identifiers, and link-cost is a number (integer or floating point) representing the latency of the link. These elements are separated by one or more spaces.
After the topology specification, the workload may contain one or more message lines in the following format:
M
send-time source-address
destination-address message-text
Where send-time is a floating point representing the time when the message is sent, source-address is the source of the message, destination-address is the destination, and message-text is a string representing the message data.
For example,
1 2 3.0
2 3 4.0
3 4 1.0
4 1 9.0
M 100 1 3 ciao
M 150 4 2 hello!
Package | Description |
---|---|
simplenet |