Converging nodes to shortest paths by implementing Bellman Ford algorithm
The node class contains information about the nodes name, port number, neighbors, routing table, and a queue. Each node starts four threads.
Each node sends a packet to all its neighbors. The packet contains packet type and sending nodes name as header information. The distance vector, initially created from the nodes neighbors is added as the payload. Measures for Poison Reverse are taken here.
Each node is actively listening for any packet sent to its port number. On receiving a packet, it appends the packet to the queue. The queue stores packets it receives from its neighbors. These packets are then processed one by one by the processThread.
The process thread checks if there is any unprocessed packet in the queue. If so it extracts senders name and packet type from the header. If packet type is ‘change’, the payload is forwarded to change function which extracts the cost changed along with its new value and updates it. If the packet type is ‘DV’, the payload is forwarded to updateRoutingTable function. This is where the Bellman-Ford algorithm works. It also updates the timeout value for the sender here since the fact it sent its distance vector means that the sender is active.
This thread continuously checks if any neighbor node has exceeded its timeout value. If so, its cost is changed to infinity.
This script provides an interface to change costs for a selected pair of nodes. It reads the configuration files and creates its list from there. Once a pair of nodes is selected, it sends neighboring nodes name and the new cost as a payload to the both the nodes. It adds packet type of ‘change’ as header information.