1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
|
3
|
|
|
# module under test |
4
|
|
|
from tests.unit.test_search_results import TestSearchResults |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class TestSearchResults3(TestSearchResults): |
8
|
|
|
"""Tests for the graph class.""" |
9
|
|
|
|
10
|
|
|
def test_path9(self): |
11
|
|
|
"""Tests to see if an illegal path is not in the set of paths that |
12
|
|
|
use only edges owned by A.""" |
13
|
|
|
# Arrange |
14
|
|
|
self.test_setup() |
15
|
|
|
illegal_path = ['User1', 'User1:1', 'S2:1', |
16
|
|
|
'S2', 'S2:2', 'User2:1', 'User2'] |
17
|
|
|
# Act |
18
|
|
|
result = self.get_path_constrained( |
19
|
|
|
"User1", "User2", dict(ownership='A')) |
20
|
|
|
# Assert |
21
|
|
|
self.assertNotIn(illegal_path, result[0]["paths"]) |
22
|
|
|
|
23
|
|
|
def test_path10(self): |
24
|
|
|
"""Tests to see if the edges used in the paths of the result set |
25
|
|
|
do not have poor reliability""" |
26
|
|
|
# Arrange |
27
|
|
|
self.test_setup() |
28
|
|
|
reliabilities = [] |
29
|
|
|
requirements = {"reliability": 3} |
30
|
|
|
poor_reliability = 1 |
31
|
|
|
|
32
|
|
|
# Act |
33
|
|
|
result = self.get_path_constrained("User1", "User2", requirements) |
34
|
|
|
|
35
|
|
|
if result: |
36
|
|
|
for path in result[0]["paths"]: |
37
|
|
|
for i in range(1, len(path)): |
38
|
|
|
endpoint_a = path[i - 1] |
39
|
|
|
endpoint_b = path[i] |
40
|
|
|
meta_data = self.graph.get_metadata_from_link( |
41
|
|
|
endpoint_a, endpoint_b) |
42
|
|
|
if meta_data and "reliability" in meta_data.keys(): |
43
|
|
|
reliabilities.append(meta_data["reliability"]) |
44
|
|
|
|
45
|
|
|
# Assert |
46
|
|
|
self.assertNotIn(poor_reliability, reliabilities) |
47
|
|
|
|
48
|
|
View Code Duplication |
def test_path11(self): |
|
|
|
|
49
|
|
|
"""Tests to see if the edges used in the paths from User 1 to User 2 |
50
|
|
|
have less than 30 delay.""" |
51
|
|
|
# Arrange |
52
|
|
|
self.test_setup() |
53
|
|
|
delays = [] |
54
|
|
|
requirements = {"delay": 29} |
55
|
|
|
|
56
|
|
|
# Act |
57
|
|
|
result = self.get_path_constrained( |
58
|
|
|
"User1", "User2", requirements) |
59
|
|
|
|
60
|
|
|
if result: |
61
|
|
|
for path in result[0]["paths"]: |
62
|
|
|
for i in range(1, len(path)): |
63
|
|
|
endpoint_a = path[i - 1] |
64
|
|
|
endpoint_b = path[i] |
65
|
|
|
meta_data = self.graph.get_metadata_from_link( |
66
|
|
|
endpoint_a, endpoint_b) |
67
|
|
|
if meta_data and "delay" in meta_data.keys(): |
68
|
|
|
delays.append(meta_data["delay"]) |
69
|
|
|
|
70
|
|
|
# Assert |
71
|
|
|
for delay in delays: |
72
|
|
|
self.assertEqual(delay > requirements["delay"], False) |
73
|
|
|
|
74
|
|
View Code Duplication |
def test_path12(self): |
|
|
|
|
75
|
|
|
"""Tests to see if the edges used in the paths from User 1 to User 2 |
76
|
|
|
have at least 20 bandwidth.""" |
77
|
|
|
# Arrange |
78
|
|
|
self.test_setup() |
79
|
|
|
bandwidths = [] |
80
|
|
|
requirements = {"bandwidth": 20} |
81
|
|
|
|
82
|
|
|
# Act |
83
|
|
|
result = self.get_path_constrained( |
84
|
|
|
"User1", "User2", requirements) |
85
|
|
|
|
86
|
|
|
if result: |
87
|
|
|
for path in result[0]["paths"]: |
88
|
|
|
for i in range(1, len(path)): |
89
|
|
|
endpoint_a = path[i - 1] |
90
|
|
|
endpoint_b = path[i] |
91
|
|
|
meta_data = self.graph.get_metadata_from_link( |
92
|
|
|
endpoint_a, endpoint_b) |
93
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
94
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
95
|
|
|
|
96
|
|
|
# Assert |
97
|
|
|
for bandwidth in bandwidths: |
98
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
99
|
|
|
|
100
|
|
|
def test_path13(self): |
101
|
|
|
"""Tests to see if the edges used in the paths from User 1 to User 2 |
102
|
|
|
have at least 20 bandwidth and under 30 delay.""" |
103
|
|
|
# Arrange |
104
|
|
|
self.test_setup() |
105
|
|
|
bandwidths = [] |
106
|
|
|
delays = [] |
107
|
|
|
requirements = {"bandwidth": 20, "delay": 29} |
108
|
|
|
|
109
|
|
|
# Act |
110
|
|
|
result = self.get_path_constrained( |
111
|
|
|
"User1", "User2", requirements) |
112
|
|
|
|
113
|
|
|
if result: |
114
|
|
|
for path in result[0]["paths"]: |
115
|
|
|
for i in range(1, len(path)): |
116
|
|
|
endpoint_a = path[i - 1] |
117
|
|
|
endpoint_b = path[i] |
118
|
|
|
meta_data = self.graph.get_metadata_from_link( |
119
|
|
|
endpoint_a, endpoint_b) |
120
|
|
|
if meta_data and "bandwidth" in meta_data.keys(): |
121
|
|
|
bandwidths.append(meta_data["bandwidth"]) |
122
|
|
|
elif meta_data and "delay" in meta_data.keys(): |
123
|
|
|
delays.append(meta_data["delay"]) |
124
|
|
|
|
125
|
|
|
# Assert |
126
|
|
|
for bandwidth in bandwidths: |
127
|
|
|
self.assertEqual(bandwidth < requirements["bandwidth"], False) |
128
|
|
|
|
129
|
|
|
for delay in delays: |
130
|
|
|
self.assertEqual(delay > requirements["delay"], False) |
131
|
|
|
|
132
|
|
|
@staticmethod |
133
|
|
|
def generate_topology(): |
134
|
|
|
"""Generates a predetermined topology""" |
135
|
|
|
switches = {} |
136
|
|
|
interfaces = {} |
137
|
|
|
links = {} |
138
|
|
|
|
139
|
|
|
TestSearchResults.create_switch("User1", switches) |
140
|
|
|
TestSearchResults.add_interfaces(3, switches["User1"], interfaces) |
141
|
|
|
|
142
|
|
|
TestSearchResults.create_switch("S2", switches) |
143
|
|
|
TestSearchResults.add_interfaces(2, switches["S2"], interfaces) |
144
|
|
|
|
145
|
|
|
TestSearchResults.create_switch("User2", switches) |
146
|
|
|
TestSearchResults.add_interfaces(3, switches["User2"], interfaces) |
147
|
|
|
|
148
|
|
|
TestSearchResults.create_switch("S4", switches) |
149
|
|
|
TestSearchResults.add_interfaces(4, switches["S4"], interfaces) |
150
|
|
|
|
151
|
|
|
TestSearchResults.create_switch("S5", switches) |
152
|
|
|
TestSearchResults.add_interfaces(2, switches["S5"], interfaces) |
153
|
|
|
|
154
|
|
|
TestSearchResults.create_link("User1:1", "S2:1", interfaces, links) |
155
|
|
|
TestSearchResults.create_link("User1:2", "S5:1", interfaces, links) |
156
|
|
|
TestSearchResults.create_link("User1:3", "S4:1", interfaces, links) |
157
|
|
|
TestSearchResults.create_link("S2:2", "User2:1", interfaces, links) |
158
|
|
|
TestSearchResults.create_link("User2:2", "S4:2", interfaces, links) |
159
|
|
|
TestSearchResults.create_link("S5:2", "S4:3", interfaces, links) |
160
|
|
|
TestSearchResults.create_link("User2:3", "S4:4", interfaces, links) |
161
|
|
|
|
162
|
|
|
TestSearchResults.add_metadata_to_link( |
163
|
|
|
"User1:1", "S2:1", { |
164
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
165
|
|
|
"bandwidth": 20}, links) |
166
|
|
|
TestSearchResults.add_metadata_to_link( |
167
|
|
|
"User1:2", "S5:1", { |
168
|
|
|
"reliability": 1, "ownership": "A", "delay": 5, |
169
|
|
|
"bandwidth": 50}, links) |
170
|
|
|
TestSearchResults.add_metadata_to_link( |
171
|
|
|
"User1:3", "S4:1", { |
172
|
|
|
"reliability": 3, "ownership": "A", "delay": 60, |
173
|
|
|
"bandwidth": 10}, links) |
174
|
|
|
TestSearchResults.add_metadata_to_link( |
175
|
|
|
"S2:2", "User2:1", { |
176
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
177
|
|
|
"bandwidth": 20}, links) |
178
|
|
|
TestSearchResults.add_metadata_to_link( |
179
|
|
|
"User2:2", "S4:2", { |
180
|
|
|
"reliability": 3, "ownership": "B", "delay": 30, |
181
|
|
|
"bandwidth": 10}, links) |
182
|
|
|
TestSearchResults.add_metadata_to_link( |
183
|
|
|
"S5:2", "S4:3", { |
184
|
|
|
"reliability": 1, "ownership": "A", "delay": 10, |
185
|
|
|
"bandwidth": 50}, links) |
186
|
|
|
TestSearchResults.add_metadata_to_link( |
187
|
|
|
"User2:3", "S4:4", { |
188
|
|
|
"reliability": 3, "ownership": "A", "delay": 29, |
189
|
|
|
"bandwidth": 20}, links) |
190
|
|
|
|
191
|
|
|
return (switches, links) |
192
|
|
|
|