|
1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
|
2
|
|
|
# Core modules to import |
|
3
|
|
|
from kytos.core.link import Link |
|
4
|
|
|
|
|
5
|
|
|
# module under test |
|
6
|
|
|
from tests.unit.test_search_results import TestSearchResults |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TestSearchResults1(TestSearchResults): |
|
10
|
|
|
"""Tests for the graph class.""" |
|
11
|
|
|
|
|
12
|
|
|
def test_path1(self): |
|
13
|
|
|
"""Tests a simple, definetly possible path""" |
|
14
|
|
|
self.setup() |
|
15
|
|
|
results = self.get_path("S1", "S2") |
|
16
|
|
|
self.assertNotEqual(results, []) |
|
17
|
|
|
|
|
18
|
|
|
def test_constrained_path1(self): |
|
19
|
|
|
"""Tests a simple, definetly possible path""" |
|
20
|
|
|
self.setup() |
|
21
|
|
|
results = self.get_path_constrained("S1", "S2") |
|
22
|
|
|
self.assertNotEqual(results, []) |
|
23
|
|
|
|
|
24
|
|
|
def test_path2(self): |
|
25
|
|
|
"""Tests a simple, impossible path""" |
|
26
|
|
|
self.setup() |
|
27
|
|
|
results = self.get_path("S1", "S4") |
|
28
|
|
|
self.assertEqual(results, []) |
|
29
|
|
|
|
|
30
|
|
|
def test_constrained_path2(self): |
|
31
|
|
|
"""Tests a simple, impossible path""" |
|
32
|
|
|
self.setup() |
|
33
|
|
|
results = self.get_path_constrained("S1", "S4") |
|
34
|
|
|
self.assertEqual(results, []) |
|
35
|
|
|
|
|
36
|
|
|
def test_path3(self): |
|
37
|
|
|
"""Tests a path to self""" |
|
38
|
|
|
self.setup() |
|
39
|
|
|
results = self.get_path("S4", "S4") |
|
40
|
|
|
self.assertNotEqual(results, []) |
|
41
|
|
|
|
|
42
|
|
|
def test_constrained_path3(self): |
|
43
|
|
|
"""Tests a path to self""" |
|
44
|
|
|
self.setup() |
|
45
|
|
|
results = self.get_path_constrained("S4", "S4") |
|
46
|
|
|
self.assertNotEqual(results, []) |
|
47
|
|
|
|
|
48
|
|
|
def test_path4(self): |
|
49
|
|
|
"""Tests a path to self again""" |
|
50
|
|
|
self.setup() |
|
51
|
|
|
results = self.get_path("S1", "S1") |
|
52
|
|
|
self.assertNotEqual(results, []) |
|
53
|
|
|
|
|
54
|
|
|
def test_constrained_path4(self): |
|
55
|
|
|
"""Tests a path to self again""" |
|
56
|
|
|
self.setup() |
|
57
|
|
|
results = self.get_path_constrained("S1", "S1") |
|
58
|
|
|
self.assertNotEqual(results, []) |
|
59
|
|
|
|
|
60
|
|
|
def test_constrained_path5(self): |
|
61
|
|
|
"""Tests constrained path""" |
|
62
|
|
|
self.setup() |
|
63
|
|
|
results = self.get_path_constrained( |
|
64
|
|
|
"S1", "S3", base={"bandwidth": 50}) |
|
65
|
|
|
for result in results: |
|
66
|
|
|
self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3'], result["paths"]) |
|
67
|
|
|
|
|
68
|
|
|
def test_constrained_path6(self): |
|
69
|
|
|
"""Tests constrained path""" |
|
70
|
|
|
self.setup() |
|
71
|
|
|
results = self.get_path_constrained( |
|
72
|
|
|
"S1", "S2", base={"ownership": "red"}) |
|
73
|
|
|
for result in results: |
|
74
|
|
|
self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3', |
|
75
|
|
|
'S3:1', 'S2:2', 'S2'], result["paths"]) |
|
76
|
|
|
|
|
77
|
|
|
def test_constrained_path7(self): |
|
78
|
|
|
"""Tests constrained path""" |
|
79
|
|
|
self.setup() |
|
80
|
|
|
results = self.get_path_constrained( |
|
81
|
|
|
"S1", "S2", base={"ownership": "blue"}) |
|
82
|
|
|
for result in results: |
|
83
|
|
|
self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"]) |
|
84
|
|
|
|
|
85
|
|
|
def test_constrained_path8(self): |
|
86
|
|
|
"""Tests constrained path, to self AGAIN""" |
|
87
|
|
|
self.setup() |
|
88
|
|
|
results = self.get_path_constrained( |
|
89
|
|
|
"S5", "S5", base={"ownership": "blue"}) |
|
90
|
|
|
for result in results: |
|
91
|
|
|
self.assertNotEqual([], result["paths"]) |
|
92
|
|
|
self.assertIn(['S5'], result["paths"]) |
|
93
|
|
|
|
|
94
|
|
|
def test_constrained_path9(self): |
|
95
|
|
|
"""Tests constrained path""" |
|
96
|
|
|
self.setup() |
|
97
|
|
|
results = self.get_path_constrained( |
|
98
|
|
|
"S1", "S2", 1, base={"ownership": "blue"}) |
|
99
|
|
|
for result in results: |
|
100
|
|
|
self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"]) |
|
101
|
|
|
|
|
102
|
|
|
@staticmethod |
|
103
|
|
|
def generate_topology(): |
|
104
|
|
|
"""Generates a predetermined topology""" |
|
105
|
|
|
switches = {} |
|
106
|
|
|
interfaces = {} |
|
107
|
|
|
links = {} |
|
108
|
|
|
|
|
109
|
|
|
TestSearchResults.create_switch("S1", switches) |
|
110
|
|
|
TestSearchResults.add_interfaces(2, switches["S1"], interfaces) |
|
111
|
|
|
|
|
112
|
|
|
TestSearchResults.create_switch("S2", switches) |
|
113
|
|
|
TestSearchResults.add_interfaces(3, switches["S2"], interfaces) |
|
114
|
|
|
|
|
115
|
|
|
TestSearchResults.create_switch("S3", switches) |
|
116
|
|
|
TestSearchResults.add_interfaces(2, switches["S3"], interfaces) |
|
117
|
|
|
|
|
118
|
|
|
TestSearchResults.create_switch("S4", switches) |
|
119
|
|
|
TestSearchResults.add_interfaces(2, switches["S4"], interfaces) |
|
120
|
|
|
|
|
121
|
|
|
TestSearchResults.create_switch("S5", switches) |
|
122
|
|
|
|
|
123
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
|
124
|
|
|
links["S1:1<->S2:1"].extend_metadata( |
|
125
|
|
|
{"bandwidth": 50, "ownership": "red"}) |
|
126
|
|
|
|
|
127
|
|
|
links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"]) |
|
128
|
|
|
links["S3:1<->S2:2"].extend_metadata( |
|
129
|
|
|
{"bandwidth": 51, "ownership": "blue"}) |
|
130
|
|
|
|
|
131
|
|
|
links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"]) |
|
132
|
|
|
links["S1:2<->S3:2"].extend_metadata( |
|
133
|
|
|
{"bandwidth": 49, "ownership": "blue"}) |
|
134
|
|
|
|
|
135
|
|
|
return (switches, links) |
|
136
|
|
|
|