# Routing Packets in a Network Overlay Using Dijkstra Shortest Path This project was an assignment for a Distributed Systems course where the goal was to use an overlay to communicate between messaging nodes (clients) and the Registry (server) to send messages using threads. It follows the principles of TCP/IP protocols and overlays used in P2P systems. Within node, there are two files that can be started; the Registry.java contains a main file that creates the main thread, which facilitates the user's interactions with the program, and any receiver and sender threads needed to communicate with messaging nodes. MessagingNode.java is used by the clients to connect to the server by specifying the hostname and port number. These can be run on multiple systems/ports. After nodes have connected, the registry is in charge of sending the list of nodes the messaging nodes need to connect to and when to start sending messages. It does so when the user enters a command to start doing something. Each node has a cache of the shortest path from itself to every other node in the system, which is computed using Dijkstra. When all nodes finish messaging each other randomly, the statistics are collected and can be compared to see if any packets were lost during the period. ## Project Structure ``` |--src/main/java |--csx55.overlay.dijkstra |--RoutingCache.java [Used to cache the shortest paths to each node in the overlay] |--ShortestPath.java [Used to calculate the shortest paths for the node to all other nodes using Dijkstra] |--csx55.overlay.node |--MessagingNode.java [Acts as the client and spwans threads to communicate with Registry and peers] |--Node.java [An interface that allows Registry and MessagingNode to be treated as a Node; provides the onEvent() method] |--Registry.java [Acts as the server and allows nodes to connect themselves; creates threads to communicate with nodes] |--csx55.overlay.transport |--TCPReceiverThread.java [Runs in a loop and reads from the socket's input stream; handles events by calling onEvent] |--TCPSenderThread.java [Writes marshalled data to the socket's output stream] |--TCPServerThread.java [Used by Registry and MessagingNode to accept new sockets and create sender & receiver threads] |--csx55.overlay.util |--OverlayCreator.java [Creates the regular graph needed by the nodes to communicate with each other] |--StatisticsCollector.java [Used by MessagingNodes to collect data about sent/received/relayed data when passing messages] |--csx55.overlay.wireformats |--Deregister.java [Used by the MessagingNode to deregister from the overlay; Sent to Registry as an event] |--DeregisterResponse.java [Used by the Registry to respond back to the MessagingNode regarding its deregistration request] |--Event.java [An interface that all wireformates implement; defines the getBytes method to marshall data into byte streams] |--EventFactory.java [A factory class that returns instances of events with the byte streams unmarshalled] |--LinkWeights.java [Used to assign weights to all edges in the graph and store the edges in a list] |--Message.java [Used when passing messages between MessagingNodes; includes the random payload that is summed to its stats] |--MessagingNodesList.java [Used by the Registry to send the list of peers the MessagingNodes must connect to] |--Protocol.java [An interface that simply specifies values for message types] |--Register.java [Used by the MessagingNodes to register to the Registry or peers with their hostname and port numbers] |--RegisterResponse.java [Used by the Registry to respond back to the MessagingNode regarding its registration request] |--TaskComplete.java [Used by the MessagingNode to tell the Registry that it has finished sending all of its messages] |--TaskInitiate.java [Used by the Registry to tell all nodes to start passing messages to random sink nodes for n rounds] |--TaskSummaryRequest.java [Used by the Registry to request MessagingNodes to send their traffic stats as a response] |--TaskSummaryResponse.java [Used by the MessagingNodes to send their traffic stats to the Registry to be displayed] |-- build.gradle [The file used to build this assignment] |-- README.txt [This file] ``` ## Foreground Commands Registry: - **list-messaging-nodes**: prints a list of messaging nodes connected to the registry in the format "hostname:port" - **list-weights**: prints out a list of all edge weights in the format "hostname:port hostname:port weight" - **setup-overlay**: creates the undirected graph with all registered nodes and sends each node a list of peers they need to connect to - **send-overlay-link-weights**: sends the list of all edge weights to all registered nodes so they can compute and cache the shortest paths - **start**: commands nodes to start exchanging messages with randomly chosen peers for num_rounds times and keep a summary of messages sent, relayed, received Messaging Nodes: - **print-shortest-path**: prints the shortest path from the node to every other node in the system in the format "host:port--weight--host:port--weight--host:port" - **exit-overlay**: exits the program and deregisters itself from the Registry ## Output Outputs are all printed in the console. After specifying the start command, the program will collect all statistics and display it. An example with 10 nodes with each having 4 edges in the overlay running for 10000 rounds. This means 10 nodes x 10000 rounds x 5 rounds each = 500,000 messages sent. Final Output ## Dependencies - Java 11 - Gradle 8.3 ## Compiling Clone the repository using: ```bash $ git clone https://github.com/ashsProjects/Routing_Packets_In_A_Network_Overlay.git ``` Compile the Program: ```bash $ gradle build ``` Change directories: ```bash $ cd build/classes/java/main ``` To run Registry: ```bash $ java csx55.overlay.node.Registry For example: java csx55.overlay.node.Registry 5000 ``` To run Messaging Node: ```bash $ java csx55.overlay.node.MessagingNode For example: java csx55.overlay.node.MessagingNode denver 5000 ``` To clean: ```bash $ gradle clean ```