1
|
|
|
"""Module to overwrite all the needed methods to test the KytosGraph in graph.py""" |
2
|
|
|
from itertools import combinations |
3
|
|
|
|
4
|
|
|
# Core modules to import |
5
|
|
|
from kytos.core.link import Link |
6
|
|
|
|
7
|
|
|
from tests.integration.test_results import TestResults |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class EdgesSettings(TestResults): |
11
|
|
|
"""Class to setups all the settings related to topology.""" |
12
|
|
|
|
13
|
|
|
@staticmethod |
14
|
|
|
def generate_topology(): |
15
|
|
|
"""Generates a predetermined topology""" |
16
|
|
|
switches = {} |
17
|
|
|
interfaces = {} |
18
|
|
|
links = {} |
19
|
|
|
|
20
|
|
|
TestResults.create_switch("S1", switches) |
21
|
|
|
TestResults.add_interfaces(2, switches["S1"], interfaces) |
22
|
|
|
|
23
|
|
|
TestResults.create_switch("S2", switches) |
24
|
|
|
TestResults.add_interfaces(2, switches["S2"], interfaces) |
25
|
|
|
|
26
|
|
|
TestResults.create_switch("S3", switches) |
27
|
|
|
TestResults.add_interfaces(6, switches["S3"], interfaces) |
28
|
|
|
|
29
|
|
|
TestResults.create_switch("S4", switches) |
30
|
|
|
TestResults.add_interfaces(2, switches["S4"], interfaces) |
31
|
|
|
|
32
|
|
|
TestResults.create_switch("S5", switches) |
33
|
|
|
TestResults.add_interfaces(6, switches["S5"], interfaces) |
34
|
|
|
|
35
|
|
|
TestResults.create_switch("S6", switches) |
36
|
|
|
TestResults.add_interfaces(5, switches["S6"], interfaces) |
37
|
|
|
|
38
|
|
|
TestResults.create_switch("S7", switches) |
39
|
|
|
TestResults.add_interfaces(2, switches["S7"], interfaces) |
40
|
|
|
|
41
|
|
|
TestResults.create_switch("S8", switches) |
42
|
|
|
TestResults.add_interfaces(8, switches["S8"], interfaces) |
43
|
|
|
|
44
|
|
|
TestResults.create_switch("S9", switches) |
45
|
|
|
TestResults.add_interfaces(4, switches["S9"], interfaces) |
46
|
|
|
|
47
|
|
|
TestResults.create_switch("S10", switches) |
48
|
|
|
TestResults.add_interfaces(3, switches["S10"], interfaces) |
49
|
|
|
|
50
|
|
|
TestResults.create_switch("S11", switches) |
51
|
|
|
TestResults.add_interfaces(3, switches["S11"], interfaces) |
52
|
|
|
|
53
|
|
|
TestResults.create_switch("User1", switches) |
54
|
|
|
TestResults.add_interfaces(4, switches["User1"], interfaces) |
55
|
|
|
|
56
|
|
|
TestResults.create_switch("User2", switches) |
57
|
|
|
TestResults.add_interfaces(2, switches["User2"], interfaces) |
58
|
|
|
|
59
|
|
|
TestResults.create_switch("User3", switches) |
60
|
|
|
TestResults.add_interfaces(2, switches["User3"], interfaces) |
61
|
|
|
|
62
|
|
|
TestResults.create_switch("User4", switches) |
63
|
|
|
TestResults.add_interfaces(3, switches["User4"], interfaces) |
64
|
|
|
|
65
|
|
|
EdgesSettings._fill_links(links, interfaces) |
66
|
|
|
|
67
|
|
|
EdgesSettings._add_metadata_to_links(links) |
68
|
|
|
|
69
|
|
|
return switches, links |
70
|
|
|
|
71
|
|
|
@staticmethod |
72
|
|
|
def _add_metadata_to_links(links): |
73
|
|
|
links["S1:1<->S2:1"].extend_metadata( |
74
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 105}) |
75
|
|
|
|
76
|
|
|
links["S1:2<->User1:1"].extend_metadata( |
77
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
78
|
|
|
|
79
|
|
|
links["S2:2<->User4:1"].extend_metadata( |
80
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 10}) |
81
|
|
|
|
82
|
|
|
links["S3:1<->S5:1"].extend_metadata( |
83
|
|
|
{"reliability": 5, "bandwidth": 10, "delay": 112}) |
84
|
|
|
|
85
|
|
|
links["S3:2<->S7:1"].extend_metadata( |
86
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
87
|
|
|
|
88
|
|
|
links["S3:3<->S8:1"].extend_metadata( |
89
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
90
|
|
|
|
91
|
|
|
links["S3:4<->S11:1"].extend_metadata( |
92
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 6}) |
93
|
|
|
|
94
|
|
|
links["S3:5<->User3:1"].extend_metadata( |
95
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
96
|
|
|
|
97
|
|
|
links["S3:6<->User4:2"].extend_metadata( |
98
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 10}) |
99
|
|
|
|
100
|
|
|
links["S4:1<->S5:2"].extend_metadata( |
101
|
|
|
{"reliability": 1, "bandwidth": 100, "delay": 30, |
102
|
|
|
"ownership": "A"}) |
103
|
|
|
|
104
|
|
|
links["S4:2<->User1:2"].extend_metadata( |
105
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 110, |
106
|
|
|
"ownership": "A"}) |
107
|
|
|
|
108
|
|
|
links["S5:3<->S6:1"].extend_metadata( |
109
|
|
|
{"reliability": 1, "bandwidth": 100, "delay": 40}) |
110
|
|
|
|
111
|
|
|
links["S5:4<->S6:2"].extend_metadata( |
112
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 40, |
113
|
|
|
"ownership": "A"}) |
114
|
|
|
|
115
|
|
|
links["S5:5<->S8:2"].extend_metadata( |
116
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 112}) |
117
|
|
|
|
118
|
|
|
links["S5:6<->User1:3"].extend_metadata( |
119
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 60}) |
120
|
|
|
|
121
|
|
|
links["S6:3<->S9:1"].extend_metadata( |
122
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 60}) |
123
|
|
|
|
124
|
|
|
links["S6:4<->S9:2"].extend_metadata( |
125
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 62}) |
126
|
|
|
|
127
|
|
|
links["S6:5<->S10:1"].extend_metadata( |
128
|
|
|
{"bandwidth": 100, "delay": 108, "ownership": "A"}) |
129
|
|
|
|
130
|
|
|
links["S7:2<->S8:3"].extend_metadata( |
131
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
132
|
|
|
|
133
|
|
|
links["S8:4<->S9:3"].extend_metadata( |
134
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 32}) |
135
|
|
|
|
136
|
|
|
links["S8:5<->S9:4"].extend_metadata( |
137
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 110}) |
138
|
|
|
|
139
|
|
|
links["S8:6<->S10:2"].extend_metadata( |
140
|
|
|
{"reliability": 5, "bandwidth": 100, "ownership": "A"}) |
141
|
|
|
|
142
|
|
|
links["S8:7<->S11:2"].extend_metadata( |
143
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 7}) |
144
|
|
|
|
145
|
|
|
links["S8:8<->User3:2"].extend_metadata( |
146
|
|
|
{"reliability": 5, "bandwidth": 100, "delay": 1}) |
147
|
|
|
|
148
|
|
|
links["S10:3<->User2:1"].extend_metadata( |
149
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 10, |
150
|
|
|
"ownership": "A"}) |
151
|
|
|
|
152
|
|
|
links["S11:3<->User2:2"].extend_metadata( |
153
|
|
|
{"reliability": 3, "bandwidth": 100, "delay": 6}) |
154
|
|
|
|
155
|
|
|
links["User1:4<->User4:3"].extend_metadata( |
156
|
|
|
{"reliability": 5, "bandwidth": 10, "delay": 105}) |
157
|
|
|
|
158
|
|
|
@staticmethod |
159
|
|
|
def _fill_links(links, interfaces): |
160
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
161
|
|
|
|
162
|
|
|
links["S1:2<->User1:1"] = Link(interfaces["S1:2"], interfaces["User1:1"]) |
163
|
|
|
|
164
|
|
|
links["S2:2<->User4:1"] = Link(interfaces["S2:2"], interfaces["User4:1"]) |
165
|
|
|
|
166
|
|
|
links["S3:1<->S5:1"] = Link(interfaces["S3:1"], interfaces["S5:1"]) |
167
|
|
|
|
168
|
|
|
links["S3:2<->S7:1"] = Link(interfaces["S3:2"], interfaces["S7:1"]) |
169
|
|
|
|
170
|
|
|
links["S3:3<->S8:1"] = Link(interfaces["S3:3"], interfaces["S8:1"]) |
171
|
|
|
|
172
|
|
|
links["S3:4<->S11:1"] = Link(interfaces["S3:4"], interfaces["S11:1"]) |
173
|
|
|
|
174
|
|
|
links["S3:5<->User3:1"] = Link(interfaces["S3:5"], interfaces["User3:1"]) |
175
|
|
|
|
176
|
|
|
links["S3:6<->User4:2"] = Link(interfaces["S3:6"], interfaces["User4:2"]) |
177
|
|
|
|
178
|
|
|
links["S4:1<->S5:2"] = Link(interfaces["S4:1"], interfaces["S5:2"]) |
179
|
|
|
|
180
|
|
|
links["S4:2<->User1:2"] = Link(interfaces["S4:2"], interfaces["User1:2"]) |
181
|
|
|
|
182
|
|
|
links["S5:3<->S6:1"] = Link(interfaces["S5:3"], interfaces["S6:1"]) |
183
|
|
|
|
184
|
|
|
links["S5:4<->S6:2"] = Link(interfaces["S5:4"], interfaces["S6:2"]) |
185
|
|
|
|
186
|
|
|
links["S5:5<->S8:2"] = Link(interfaces["S5:5"], interfaces["S8:2"]) |
187
|
|
|
|
188
|
|
|
links["S5:6<->User1:3"] = Link(interfaces["S5:6"], interfaces["User1:3"]) |
189
|
|
|
|
190
|
|
|
links["S6:3<->S9:1"] = Link(interfaces["S6:3"], interfaces["S9:1"]) |
191
|
|
|
|
192
|
|
|
links["S6:4<->S9:2"] = Link(interfaces["S6:4"], interfaces["S9:2"]) |
193
|
|
|
|
194
|
|
|
links["S6:5<->S10:1"] = Link(interfaces["S6:5"], interfaces["S10:1"]) |
195
|
|
|
|
196
|
|
|
links["S7:2<->S8:3"] = Link(interfaces["S7:2"], interfaces["S8:3"]) |
197
|
|
|
|
198
|
|
|
links["S8:4<->S9:3"] = Link(interfaces["S8:4"], interfaces["S9:3"]) |
199
|
|
|
|
200
|
|
|
links["S8:5<->S9:4"] = Link(interfaces["S8:5"], interfaces["S9:4"]) |
201
|
|
|
|
202
|
|
|
links["S8:6<->S10:2"] = Link(interfaces["S8:6"], interfaces["S10:2"]) |
203
|
|
|
|
204
|
|
|
links["S8:7<->S11:2"] = Link(interfaces["S8:7"], interfaces["S11:2"]) |
205
|
|
|
|
206
|
|
|
links["S8:8<->User3:2"] = Link(interfaces["S8:8"], interfaces["User3:2"]) |
207
|
|
|
|
208
|
|
|
links["S10:3<->User2:1"] = Link(interfaces["S10:3"], interfaces["User2:1"]) |
209
|
|
|
|
210
|
|
|
links["S11:3<->User2:2"] = Link(interfaces["S11:3"], interfaces["User2:2"]) |
211
|
|
|
|
212
|
|
|
links["User1:4<->User4:3"] = Link(interfaces["User1:4"], interfaces["User4:3"]) |
213
|
|
|
|
214
|
|
|
def paths_between_all_users(self, item, base=None, flexible=None, metrics=None): |
215
|
|
|
"""Method to verify the existence of a path between |
216
|
|
|
a set of points given different constrains""" |
217
|
|
|
combos = combinations(["User1", "User2", "User3", "User4"], 2) |
218
|
|
|
self.initializer() |
219
|
|
|
|
220
|
|
|
valid = True |
221
|
|
|
for point_a, point_b in combos: |
222
|
|
|
results = [] |
223
|
|
|
if base is not None and flexible is None: |
224
|
|
|
results = self.get_path_constrained( |
225
|
|
|
point_a, point_b, base=base) |
226
|
|
|
|
227
|
|
|
elif base is None and flexible is not None: |
228
|
|
|
results = self.get_path_constrained( |
229
|
|
|
point_a, point_b, flexible=flexible) |
230
|
|
|
|
231
|
|
|
for result in results: |
232
|
|
|
if metrics is not None: |
233
|
|
|
if metrics in result["metrics"]: |
234
|
|
|
for path in result["paths"]: |
235
|
|
|
if item in path: |
236
|
|
|
valid = False |
237
|
|
|
else: |
238
|
|
|
for path in result["paths"]: |
239
|
|
|
if item in path: |
240
|
|
|
valid = False |
241
|
|
|
return valid |
242
|
|
|
|