Skip to content

Add rishab to Contributors list #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions src/Dijkstra.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Implementation of Link State Routing Protocol - Dijkstra's Algorithm */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
Expand All @@ -18,23 +16,18 @@ public class Dijkstra {
class ConTableEntry {
boolean flg;
int length;
int []ids;
int ids[];
int depth;
}

static ConTableEntry []conTable = null; //Connection Table initialization

/* Main Method */
public static void main(String[] args) {

//file obj1=new file();
Dijkstra psFrame = new Dijkstra();

}

public int nodeid(int in){
return (in+1);

}
/* ReadTextfileToBuildGraph Method */
public void ReadTextfileToBuildGraph() {
try
{
Expand All @@ -53,7 +46,7 @@ public void ReadTextfileToBuildGraph() {
DistGrph = new int [temp.length][temp.length];
br.close();
fr.close();
System.out.println("<=======:Graph Size Read:=======>"+temp.length);
System.out.println("Graph Size Read: "+temp.length);

fr = new FileReader(fiename); //Read the content of file into the FileReader object
val=new String();
Expand All @@ -70,7 +63,7 @@ public void ReadTextfileToBuildGraph() {
}
br.close();
fr.close();
System.out.println("<=======:Graph Table Initialized:=======>");
System.out.println("<=======Graph Table Initialized=======>");
Max_rooters = i;


Expand All @@ -92,9 +85,14 @@ public void ReadTextfileToBuildGraph() {
}
System.out.println("-------------------------------------------------------------------");
} catch(Exception e){
System.out.println("File Not Found, Please Enter a Valid File !"); //To Handle File Not Found Exception
System.out.println("File Not Found, Please Enter a Valid File !");
}
}
public int nodeid(int in){
return (in+1);
}
/* ReadTextfileToBuildGraph Method */

/* ComputeConnectionTable Method*/
public void ComputeConnectionTabel(){

Expand Down Expand Up @@ -203,7 +201,7 @@ public void ComputeConnectionTabel(){
}
else {
System.out.println("Router [" + nodeid(source) + "] "+ "Connection Table:");
System.out.println("============================");
System.out.println("*****************************");
System.out.println("Destination Interface"); //If there is no Interface to the router then assign -1
for (int i = 0; i<Max_rooters; i++){
System.out.print(" "+ nodeid(i) + " -1");
Expand Down Expand Up @@ -285,33 +283,29 @@ public void ChangeNetworkTopology(){
}
/* MENU */
public Dijkstra() {
/*Changed the menu code to switch chooses */
while (true){

while (true){
System.out.println("===========================================================\n");
System.out.println("\n*******************************************************\n");
System.out.println("Dijkstra's Algorithm - Link State Routing Simulator:");
System.out.println("===========================================================\n");
System.out.println("Enter The Option :\n==================\n1. Create a Network Topology\n \n2. Build a Connection Table \n \n3. Shortest Path to Destination Router \n \n4. Modify a topology \n \n5. Exit\n");
System.out.println("*********************************************************\n");
System.out.println("Enter The Option :\n1. Create a Network Topology\n2. Build a Connection Table \n3. Shortest Path to Destination Router \n4. Modify a topology \n5. Exit\n");
System.out.println("Command:");
Scanner in = new Scanner(System.in);
String regmessage = in.nextLine();
int ch = in.nextInt();

if (regmessage.equals("1")){
ReadTextfileToBuildGraph(); //ReadTextFiletoBuildGraph method call
switch(ch){
case 1: ReadTextfileToBuildGraph(); //ReadTextFiletoBuildGraph method call
for (int n = 0;n<Max_rooters;n++ ) { //EXTRA FEATURE IMPLEMENTATION -> TO DISPLAY CONNECTION TABLE FOR ALL NODES
source = n;
ComputeConnectionTabel(); //ComputeConnectionTable method call
System.out.println();
}
}
if (regmessage.equals("2")){
PrintConnectionTabel(); //PrintConnectionTable method call
}
if (regmessage.equals("3")){
PrintShortPathToDestination(); //PrintShortPathToDestination method call
}
if (regmessage.equals("4")){
ChangeNetworkTopology(); //ChangeNetworkTopology method call
if ((source >-1) && (source < Max_rooters)){
case 2 : PrintConnectionTabel();

case 3 : PrintShortPathToDestination();

case 4 : if ((source >-1) && (source < Max_rooters)){
ComputeConnectionTabel(); //ComputeConnectionTable method call
if (DistGrph[source][source] == 0) {
if ((destination >-1) && (destination < Max_rooters)){
Expand All @@ -331,11 +325,20 @@ public Dijkstra() {
} else System.out.println("Source Rooter is Down"); //Router Check conditions

}else System.out.println("Source node is not selected");

case 5 : System.out.println("Exit LinkStateRouting project. Good Bye!.");
System.exit(0);
}
if (regmessage.equals("5")){
System.out.println("Exit LinkStateRouting project. Good Bye!.");
System.exit(0); //Exit system call
}

}

}

}
}