-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestApp.c
More file actions
118 lines (109 loc) · 4.41 KB
/
testApp.c
File metadata and controls
118 lines (109 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "graph.h"
#include "distanceVector.h"
#include "linkState.h"
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include <time.h>
#include "css.h"
graph* buildFirstTopology();
// graph* printRoutingTables(graph*);
graph* buildSecondTopology();
graph* buildThirdTopology();
graph* buildFourthTopology();
// graph* buildRandomGeneratedTopology();
int main(){
while(1){
system("clear");
printf(ANSI_COLOR_YELLOW "CHOOSE A TOPOLOGY:\n\n1. FIRST TOPOLOGY\n2. SECOND TOPOLOGY - MESH \n3. THIRD TOPOLOGY - FULL MESH\n4. FOURTH TOPOLOGY - STAR\n5. EXIT."ANSI_COLOR_RESET);
int choice;
printf("\n\nENTER YOUR CHOICE : ");
scanf("%d",&choice);
graph* topo;
switch(choice)
{
case 1: printf(ANSI_COLOR_GREEN"\nFIRST TOPOLOGY BUILT SUCCESSFULLY."ANSI_COLOR_RESET);
topo=buildFirstTopology();
break;
case 2: printf(ANSI_COLOR_GREEN"\nSECOND TOPOLOGY BUILT SUCCESSFULLY AND ROUTING TABLES INITIALIZED!!!"ANSI_COLOR_RESET);
topo=buildSecondTopology();
break;
case 3: printf(ANSI_COLOR_GREEN"\nTHIRD TOPOLOGY BUILT SUCCESSFULLY AND ROUTING TABLES INITIALIZED!!!"ANSI_COLOR_RESET);
topo=buildThirdTopology();
break;
case 4: printf(ANSI_COLOR_GREEN"\nFOURTH TOPOLOGY BUILT SUCCESSFULLY.\n"ANSI_COLOR_RESET);
topo=buildFourthTopology();
break;
case 5: exit(1);
break;
default: printf(ANSI_COLOR_RED"\nPLEASE ENTER CORRECT CHOICE!!!!\n"ANSI_COLOR_RESET);
exit(1);
}
int v = topo->numVertex;
int e = topo->numEdges;
initializeRoutingTables(topo);
activateTopology(topo);
while(1){
// system("clear");
printf(ANSI_COLOR_CYAN"\n1. View Topology Details.\n2. Choose Routing Protocol to configure your topology.\n3. View Routing Tables.\n4. Go to Main Menu.\n\n"ANSI_COLOR_RESET);
int option;
scanf("%d",&option);
if(option==1){
printf("\n");
sleep(1);
printGraph(topo);
sleep(5);
}else if(option==2){
printf(ANSI_COLOR_CYAN"\na. Distance Vector Routing Protocol.\nb. Link State Routing Protocol.\n\n"ANSI_COLOR_RESET);
char proto;
scanf("%s",&proto);
clock_t t;
if(proto=='a'){
initializeRoutingTables(topo);
activateTopology(topo);
t = clock();
updatedBellmanFord(topo,v,e,0);
t = clock() - t;
}
else if(proto=='b'){
initializeRoutingTables(topo);
activateTopology(topo);
doReliableFlooding(topo);
t = clock();
linkState(topo);
t = clock() - t;
initializeRoutingTables(topo);
activateTopology(topo);
updatedBellmanFord(topo,v,e,0);
}
double time_taken = ((double)t)/CLOCKS_PER_SEC;
printf(ANSI_COLOR_GREEN"\nRouting Tables Updated.\n"ANSI_COLOR_RESET);
printf(ANSI_COLOR_RED"Time taken to Update: %f\n"ANSI_COLOR_RESET,time_taken);
sleep(2);
}else if(option==3){
int ch;
printf(ANSI_COLOR_CYAN"\n\n1. Show Routing Table of a Specific Router.\n2. Show all Routing Tables.\n"ANSI_COLOR_RESET);
scanf("%d",&ch);
if(ch==2){
printRoutingTables(topo);
}else{
for(int i=0;i<v;i++){
printf(ANSI_COLOR_YELLOW"\n%d. Show IP Route Router %d\n"ANSI_COLOR_RESET,i,i);
}
printf("Choose Command: ");
int x;
scanf("%d",&x);
if(x>=0 && x<v){
printRoutingTableForSpecificRouter(topo,x);
}else{
printf(ANSI_COLOR_RED"Check command Again !!"ANSI_COLOR_RESET);
}
sleep(2);
}
}else{
break;
}
}
}
return 0;
}