-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
190 lines (183 loc) · 5.35 KB
/
main.c
File metadata and controls
190 lines (183 loc) · 5.35 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include"header.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
int main()
{
printf("\t\tDSA MINI PROJECT : STATIC IP ROUTING USING DIJKSTRA ALGORITHM\n\n");
if(login()==0)
printf("...................Access Denied!!!.................\n");
else
{
printf("...................Access Granted.................\n\n");
clear_screen();
printf("\t\tDSA MINI PROJECT : STATIC IP ROUTING USING DIJKSTRA ALGORITHM\n\n");
printf("Enter no. of routers : \n");
int no;
scanf("%d",&no);
graph* g=create_graph(no);
printf("..............Graph is successfully created!!!.............\n\n");
printf("Nodes available in network are from 0 to %d\n\n",no-1);
while(1)
{
printf("1. Add Edge\n");
printf("2. Delete Edge\n");
printf("3. Add Devices\n");
printf("4. Delete Devices\n");
printf("5. Print Routing Table\n");
printf("6. Short Paths to routers\n");
printf("7. Find Next Hop\n");
printf("8. Find Next Hop(LPM)\n");
printf("9. Print Network\n");
printf("10. Exit\n\n");
int choice;
printf("Enter Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
int src,des,cost;
printf("Enter Source Vertex : \n");
scanf("%d",&src);
while(src<0 || src>=g->total_vertices)
{
printf("Enter Valid Source Vertex : \n");
scanf("%d",&src);
}
printf("Enter Destination Vertex : \n");
scanf("%d",&des);
while(des<0 || des>=g->total_vertices || des==src)
{
printf("Enter Valid Destination Vertex : \n");
scanf("%d",&des);
}
printf("Enter Weight : \n");
scanf("%d",&cost);
while(cost<0 || cost>=INT_MAX)
{
printf("Enter Valid Weight : \n");
scanf("%d",&des);
}
addedge(g,src,des,cost);
break;
}
case 2:
{
int src,des;
printf("Enter Source Vertex : \n");
scanf("%d",&src);
while(src<0 || src>=g->total_vertices)
{
printf("Enter Valid Source Vertex : \n");
scanf("%d",&src);
}
printf("Enter Destination Vertex : \n");
scanf("%d",&des);
while(des<0 || des>=g->total_vertices)
{
printf("Enter Valid Destination Vertex : \n");
scanf("%d",&des);
}
clear_screen();
delete_edge(g,src,des);
break;
}
case 3:
{
int vertex;
printf("Enter router vertex :\n");
scanf("%d",&vertex);
while(vertex<0 || vertex>=g->total_vertices)
{
printf("Enter Valid Source Vertex : \n");
scanf("%d",&vertex);
}
if(add_device(g,vertex)==-1)
printf("Devices cannot be added to disconnected router\n");
break;
}
case 4:
{
char*str=(char*)malloc(sizeof(char)*32);
printf("Enter Device IP to be removed from Network\n");
scanf("%s",str);
delete_device(g,str);
break;
}
case 5:
{
int vertex;
printf("Enter Router Vertex :\n");
scanf("%d",&vertex);
while(vertex<0 || vertex>=g->total_vertices)
{
printf("Enter Valid Source Vertex : \n");
scanf("%d",&vertex);
clear_screen();
}
routing_table(g,vertex);
break;
}
case 6:
{
int src;
printf("Enter Source Vertex :\n");
scanf("%d",&src);
while(src<0 || src>=g->total_vertices)
{
printf("Enter Valid Source Vertex : \n");
scanf("%d",&src);
}
dijkstra(g,src,src);
break;
}
case 7:
{
char*str=(char*)malloc(sizeof(char)*20);
printf("Enter Destination IP :\n");
scanf("%s",str);
char*temp=(char*)malloc(sizeof(char)*20);
strcpy(temp,str);
if(valid_ip(temp)==0)
{
printf("\nInvalid IP Address\n\n");
}
else
next_short_path(g,str);
break;
}
case 8:
{
char*str=(char*)malloc(sizeof(char)*20);
printf("Enter Destination IP :\n");
scanf("%s",str);
char*temp=(char*)malloc(sizeof(char)*20);
strcpy(temp,str);
if(valid_ip(temp)==0)
{
printf("Invalid IP Address\n");
}
else
next_lpm_hop(g,str);
break;
}
case 9:
{
print_network(g);
break;
}
case 10:
{
destroy(g);
exit(1);
break;
}
default:
break;
}
}
}
return 0;
}