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("S1", "S3", 0, bandwidth=50) |
64
|
|
|
for result in results: |
65
|
|
|
self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3'], result["paths"]) |
66
|
|
|
|
67
|
|
|
def test_constrained_path6(self): |
68
|
|
|
"""Tests constrained path""" |
69
|
|
|
self.setup() |
70
|
|
|
results = self.get_path_constrained("S1", "S2", 0, ownership="red") |
71
|
|
|
for result in results: |
72
|
|
|
self.assertNotIn(['S1', 'S1:2', 'S3:2', 'S3', |
73
|
|
|
'S3:1', 'S2:2', 'S2'], result["paths"]) |
74
|
|
|
|
75
|
|
|
def test_constrained_path7(self): |
76
|
|
|
"""Tests constrained path""" |
77
|
|
|
self.setup() |
78
|
|
|
results = self.get_path_constrained("S1", "S2", 0, ownership="blue") |
79
|
|
|
for result in results: |
80
|
|
|
self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"]) |
81
|
|
|
|
82
|
|
|
def test_constrained_path8(self): |
83
|
|
|
"""Tests constrained path, to self AGAIN""" |
84
|
|
|
self.setup() |
85
|
|
|
results = self.get_path_constrained("S5", "S5", 0, ownership="blue") |
86
|
|
|
for result in results: |
87
|
|
|
self.assertNotEqual([], result["paths"]) |
88
|
|
|
self.assertIn(['S5'], result["paths"]) |
89
|
|
|
|
90
|
|
|
def test_constrained_path9(self): |
91
|
|
|
"""Tests constrained path""" |
92
|
|
|
self.setup() |
93
|
|
|
results = self.get_path_constrained("S1", "S2", 1, ownership="blue") |
94
|
|
|
for result in results: |
95
|
|
|
self.assertNotIn(['S1', 'S1:1', 'S2:1', 'S2'], result["paths"]) |
96
|
|
|
|
97
|
|
|
@staticmethod |
98
|
|
|
def generate_topology(): |
99
|
|
|
"""Generates a predetermined topology""" |
100
|
|
|
switches = {} |
101
|
|
|
interfaces = {} |
102
|
|
|
links = {} |
103
|
|
|
|
104
|
|
|
TestSearchResults.create_switch("S1", switches) |
105
|
|
|
TestSearchResults.add_interfaces(2, switches["S1"], interfaces) |
106
|
|
|
|
107
|
|
|
TestSearchResults.create_switch("S2", switches) |
108
|
|
|
TestSearchResults.add_interfaces(3, switches["S2"], interfaces) |
109
|
|
|
|
110
|
|
|
TestSearchResults.create_switch("S3", switches) |
111
|
|
|
TestSearchResults.add_interfaces(2, switches["S3"], interfaces) |
112
|
|
|
|
113
|
|
|
TestSearchResults.create_switch("S4", switches) |
114
|
|
|
TestSearchResults.add_interfaces(2, switches["S4"], interfaces) |
115
|
|
|
|
116
|
|
|
TestSearchResults.create_switch("S5", switches) |
117
|
|
|
|
118
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
119
|
|
|
links["S1:1<->S2:1"].extend_metadata( |
120
|
|
|
{"bandwidth": 50, "ownership": "red"}) |
121
|
|
|
|
122
|
|
|
links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"]) |
123
|
|
|
links["S3:1<->S2:2"].extend_metadata( |
124
|
|
|
{"bandwidth": 51, "ownership": "blue"}) |
125
|
|
|
|
126
|
|
|
links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"]) |
127
|
|
|
links["S1:2<->S3:2"].extend_metadata( |
128
|
|
|
{"bandwidth": 49, "ownership": "blue"}) |
129
|
|
|
|
130
|
|
|
return (switches, links) |
131
|
|
|
|