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