-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_Network.cpp
More file actions
206 lines (187 loc) · 5.45 KB
/
Copy pathmain_Network.cpp
File metadata and controls
206 lines (187 loc) · 5.45 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include<iostream>
#include<cstring>
#include<cmath>
#include<stdlib.h>
#include<time.h>
using namespace std;
#include "Distributed_Network.h"
int main()
{
int bit = 0;
Distributed_Network<string> net;
cout << "Enter Bit Size for Distributed_Network : ";
cin >> bit;
net.set_bit_size(bit);
int total_machine = 0;
cout << "Enter Total Machines For Distributed_Network : ";
cin >> total_machine;
net.set_total_machine(total_machine);
cout << endl;
int n = 0;
cout << "1) Use machine IP to make Distributed_Network." << endl
<< "2) Use machine no to make Distributed_Network." << endl
<< "3) Automatically make Distributed_Network" << endl;
cout << "Input your choice : ";
cin >> n;
cout << endl;
if (n == 1)
{
string machine = "";
for (int i = 0; i < total_machine; i++)
{
cout << "Enter machine IP Address : ";
cin >> machine;
net.make_network_using_IP(machine);
}
}
else if (n == 2) {
int machine = 0;
for (int i = 0; i < total_machine; i++)
{
cout << "Enter machine no : ";
cin >> machine;
net.make_network_using_machine_no(machine);
}
}
else if (n == 3) {
srand(1);
int total_space = pow(2, bit);
for (int i = 0; i < total_machine; i++)
{
int machine = rand() % total_space;
net.make_network_using_machine_no(machine);
}
cout << "Distributed_Network Created" << endl;
}
cout << endl;
net.display_all_machines();
net.manage_table();
cout << endl;
int pair = 0;
cout << "How much {Key-Value} you want to store in Distributed_Network Ring : ";
cin >> pair;
cout << endl;
// Use For testing the file limit
/*
for(int i=0; i<pair; i++)
{
net.insert_data_to_cloud(to_string(i), to_string(i+1));
}
*/
for (int i = 0; i < pair; i++)
{
string key = "";
cout << "Enter Key : ";
cin >> key;
string data = "";
cout << "Enter Data : ";
cin.ignore();
getline(cin, data);
int mac = 0;
cout << "Enter machine no : ";
cin >> mac;
net.insert_data_to_cloud(key, data, mac);
cout << endl;
}
cout << "DO YOU Want....." << endl;
int choice = 0;
cout << "1) To add new Machines" << endl
<< "2) To Delete " << endl
<< "0) Skip" << endl;
cout << "Enter Your Choice : ";
cin >> choice;
cout << endl;
n = 0;
if (choice == 1)
{
cout << "1) Use machine IP to make Distributed_Network." << endl
<< "2) Use machine no to make Distributed_Network." << endl
<< "3) Automatically make Distributed_Network" << endl;
cout << "Input your choice : ";
cin >> n;
}
else if (choice == 2)
{
int no = 0;
cout << "Enter machine number you want to Delete : ";
cin >> no;
net.delete_machine_from_cloud(no);
}
cout << endl;
if (n == 1)
{
string machine = "";
cout << "Enter machine IP Address : ";
cin >> machine;
net.make_network_using_IP(machine);
}
else if (n == 2) {
int machine = 0;
cout << "Enter machine no : ";
cin >> machine;
net.make_network_using_machine_no(machine);
}
else if (n == 3) {
srand(1);
int total_space = pow(2, bit);
int machine = rand() % total_space;
net.make_network_using_machine_no(machine);
cout << "Distributed_Network Created" << endl;
}
net.display_all_machines();
net.manage_table();
cout << endl;
int display_Table = 0;
cout << "Enter Machine-no to print Finger Table : ";
cin >> display_Table;
net.display_Table_of_machines(display_Table);
cout << endl;
int z = 0;
cout << "How many AVL Tree's you want to print : ";
cin >> z;
for (int i = 0; i < z; i++)
{
int AVL_no = 0;
cout << "Enter Machine-no to print AVL Tree : ";
cin >> AVL_no;
net.display_AVL_of_machines(AVL_no);
cout << endl;
}
int x = 0;
cout << "HOw many Key_Value pair you want to delete : ";
cin >> x;
for (int i = 0; i < x; i++)
{
string delete_key = "";
cout << "Enter Key YOu want to delete from Cloud : ";
cin >> delete_key;
int g = 0;
cout << "Enter Machine no to send delete request : ";
cin >> g;
net.delete_data(delete_key, g);
cout << endl;
}
x = 0;
cout << "How many AVL Tree's you want to print : ";
cin >> x;
for (int i = 0; i < x; i++)
{
int tree = 0;
cout << "Enter Machine-no to print AVL Tree : ";
cin >> tree;
net.display_AVL_of_machines(tree);
cout << endl;
}
int limit = 0;
cout << "How much Key you want to reterive from Distributed Network : ";
cin >> limit;
for (int i = 0; i < limit; i++)
{
cout << endl;
string test = "";
cout << "Enter key to Reterive Data from Distributed Network : ";
cin >> test;
cout << test << " : " << net.reterive_data_from_cloud(test) << endl;
}
return 0;
}