This work tackles the creation of a router simulator that implements a distance-vector routing protocol with network load balance, routing measures, and some optimizations.
Message transmission is performed using UDP (User Datagran Protocol) and packets are encoded in JSON (JavaScript Object Notation) in order to allow future extensions of funcionality and also for usage simplicity. All types of message contain as default the following fields: source, destination, and type, where type indicates the message type, which can be:
- data: data message;
- update: route update message;
- trace: trace message.
Data messages have an additional field named payload whose type is string. The simulator displays this field every time a data message reaches a router.
Trace messages have an additional field named distances containing a dictionnary with the minimum known distance to some destination IP.
Route update messages have an additional field named hops that contain a list of IPs indicating all the routers the message have passed through. When the message arrives at the destination, it is encoded in JSON format and inserted into a data message. The new message then returns to the source.
As said above, the router simulator presented in this project implements a distance-vector routing protocol with network load balance. We show below all the implemented features.
Links between routers are stored in a dictionnary where addresses of adjacent routers are the keys and the stored value represents the cost.
Routes are stored in a dictionnary where the router's destination address is the key and the stored value is a list of tuples containing the addresses of the router that informed both route and cost.
Periodic updates are performed every π seconds, where π is update period parameter. Internally, this is implemented using a timer that sends an update message every π seconds.
Update messages that have been sent contain the routes learnt by the router. In order to reduce chances of counting infinity, sent routes ignore those to the router to which the message is destined as well as all routes learnt by it.
In cases where there exist multiple routes with the minimum cost, the decision is made in a random way. We chose this strategy because load balance implemented through round-robin would not make sense due to the dynamism inherent to the topology.
Routes evaluation is performed immediately before sending each message, and hence topology changes will not impact message transmissions.
If a router does not send update messages for a period of 4π seconds, every route that has been learnt so far will be removed. This is also implemented using a timer.
In the project root directory, use the following command in order to run the software:
python3 routersim.py --addr ADDR --update-period PERIOD [--startup-commands FILE]