-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
185 lines (139 loc) · 6.32 KB
/
main.cpp
File metadata and controls
185 lines (139 loc) · 6.32 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
#include <bits/stdc++.h>
#include "network_components.hpp"
int Node::assign_node_id = -1;
int Link::assign_link_id = -1;
using namespace std;
int main()
{
cout << "Ring Topology" << endl;
Node *A = new Node("12:34:56:78");
Node *B = new Node("12:34:65:78");
Node *C = new Node("12:34:56:87");
Node *D = new Node("12:34:65:87");
Node *E = new Node("12:43:56:78");
Node *F = new Node("21:34:65:78");
Node *G = new Node("12:43:65:78");
vector<Node *> n1 = {A, C, F};
vector<Node *> n2 = {A, D, G, B, E};
Link *L1 = new Link(n1, true);
Link *L2 = new Link(n2, false);
L1->make_mapping();
L2->make_mapping();
A->links = {L1, L2};
B->links = {L2};
C->links = {L1};
F->links = {L1};
D->links = {L2};
E->links = {L2};
G->links = {L2};
A->routing_table[B->mac_addr] = L2;
A->routing_table[G->mac_addr] = L2;
A->routing_table[E->mac_addr] = L2;
A->routing_table[D->mac_addr] = L2;
A->routing_table[C->mac_addr] = L1;
A->routing_table[F->mac_addr] = L1;
B->routing_table[G->mac_addr] = L2;
B->routing_table[E->mac_addr] = L2;
B->routing_table[D->mac_addr] = L2;
B->routing_table[A->mac_addr] = L2;
B->routing_table[C->mac_addr] = L2;
B->routing_table[F->mac_addr] = L2;
C->routing_table[B->mac_addr] = L1;
C->routing_table[G->mac_addr] = L1;
C->routing_table[E->mac_addr] = L1;
C->routing_table[D->mac_addr] = L1;
C->routing_table[A->mac_addr] = L1;
C->routing_table[F->mac_addr] = L1;
D->routing_table[B->mac_addr] = L2;
D->routing_table[G->mac_addr] = L2;
D->routing_table[E->mac_addr] = L2;
D->routing_table[A->mac_addr] = L2;
D->routing_table[C->mac_addr] = L2;
D->routing_table[F->mac_addr] = L2;
E->routing_table[B->mac_addr] = L2;
E->routing_table[G->mac_addr] = L2;
E->routing_table[A->mac_addr] = L2;
E->routing_table[D->mac_addr] = L2;
E->routing_table[C->mac_addr] = L2;
E->routing_table[F->mac_addr] = L2;
F->routing_table[B->mac_addr] = L1;
F->routing_table[G->mac_addr] = L1;
F->routing_table[E->mac_addr] = L1;
F->routing_table[D->mac_addr] = L1;
F->routing_table[C->mac_addr] = L1;
F->routing_table[A->mac_addr] = L1;
G->routing_table[B->mac_addr] = L2;
G->routing_table[A->mac_addr] = L2;
G->routing_table[E->mac_addr] = L2;
G->routing_table[D->mac_addr] = L2;
G->routing_table[C->mac_addr] = L2;
G->routing_table[F->mac_addr] = L2;
//E->send(D->mac_addr,"Ayushman, thanks bhai for debugging!");
cout << endl
<< "SIM 1: Sending message from Node B to Node D in same ring." << endl;
B->send(D->mac_addr, "INTRA RING");
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 2: Sending message from Node B to Node C in a different ring." << endl;
B->send(C->mac_addr, "TRANS RING");
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 3 (Node Failure): Sending message as in the above two simulations (from Node B to Node D and C) after Node A has failed." << endl;
A->failure = true;
B->send(D->mac_addr, "INTRA RING");
B->send(C->mac_addr, "TRANS RING"); // this will fail
A->failure = false;
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 4 (Link Failure): Sending message as in the above two simulations (from Node B to Node D and C) after Link L2 has failed." << endl;
L2->link_failure[4] = true;
B->send(D->mac_addr, "INTRA RING");
B->send(C->mac_addr, "TRANS RING");
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 5 (Link Failure): Sending message from Node A to C after Link L2 has failed." << endl;
A->send(C->mac_addr, "Sending A to C");
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 6 (Link Failure): Sending message from Node C to D after Link L2 has failed. (Routing through a damaged link)" << endl;
C->send(D->mac_addr, "Routing through a damaged link");
L2->link_failure[4] = false;
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< "SIM 7 (Node Failure): Sending message from Node B to Node C after Node D has failed." << endl;
D->failure = true;
B->send(C->mac_addr, "Hii C");
D->failure = false;
cout<<endl<<"................................................................................................................"<<endl;
usleep(1000000);
cout << endl
<< endl
<< "Now simulating for broadcast messages." << endl;
cout << endl
<< "SIM 8: Broadcast message from B to all nodes." << endl;
B->send("00:00:00:00", "Hii All");
cout<<endl<<"................................................................................................................"<<endl;
usleep(2000000);
cout << endl
<< "SIM 9: Broadcast message from B after Node A fails." << endl;
A->failure = true;
B->send("00:00:00:00", "Hii everyone");
A->failure = false;
cout<<endl<<"................................................................................................................"<<endl;
usleep(2000000);
cout << endl
<< "SIM 10: Broadcast message from B after Node E fails." << endl;
E->failure = true;
B->send("00:00:00:00", "Hii everyone");
E->failure = false;
usleep(2000000);
cout<<endl;
cout<<"------------------------------------------------- END OF SIMULATIONS ------------------------------------------------"<<endl;
return 0;
}