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