|
1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
|
2
|
|
|
from kytos.core.link import Link |
|
3
|
|
|
|
|
4
|
|
|
# module under test |
|
5
|
|
|
# pylint: disable=import-error |
|
6
|
|
|
from tests.integration.test_paths import TestPaths |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class TestPathsSimple(TestPaths): |
|
10
|
|
|
"""Tests for the graph class. |
|
11
|
|
|
|
|
12
|
|
|
Tests if the paths returned have only legal edges. |
|
13
|
|
|
""" |
|
14
|
|
|
|
|
15
|
|
|
def test_path_s1_s2(self): |
|
16
|
|
|
"""Tests a simple, possible path""" |
|
17
|
|
|
self.initializer() |
|
18
|
|
|
|
|
19
|
|
|
source = "S1" |
|
20
|
|
|
destination = "S2" |
|
21
|
|
|
results = self.graph.constrained_k_shortest_paths("S1", "S2") |
|
22
|
|
|
|
|
23
|
|
|
assert results |
|
24
|
|
|
for result in results: |
|
25
|
|
|
path = result["hops"] |
|
26
|
|
|
assert source == path[0] |
|
27
|
|
|
assert destination == path[-1] |
|
28
|
|
|
|
|
29
|
|
|
def test_path_s1_s4(self): |
|
30
|
|
|
"""Tests a simple, impossible path""" |
|
31
|
|
|
self.initializer() |
|
32
|
|
|
|
|
33
|
|
|
assert not self.graph.constrained_k_shortest_paths("S1", "S4") |
|
34
|
|
|
|
|
35
|
|
|
def test_path_to_self(self): |
|
36
|
|
|
"""Tests a path to self again""" |
|
37
|
|
|
self.initializer() |
|
38
|
|
|
results = self.graph.constrained_k_shortest_paths("S1", "S1") |
|
39
|
|
|
|
|
40
|
|
|
assert results |
|
41
|
|
|
for result in results: |
|
42
|
|
|
path = result["hops"] |
|
43
|
|
|
assert path[0] == "S1" |
|
44
|
|
|
assert path[-1] == "S1" |
|
45
|
|
|
|
|
46
|
|
|
def test_path_s1_s3_constrained_red(self): |
|
47
|
|
|
"""Tests path from s1 to s3 constrained ownership red""" |
|
48
|
|
|
self.initializer() |
|
49
|
|
|
|
|
50
|
|
|
source = "S1" |
|
51
|
|
|
destination = "S3" |
|
52
|
|
|
results = self.graph.constrained_k_shortest_paths( |
|
53
|
|
|
source, destination, mandatory_metrics={"ownership": "red"} |
|
54
|
|
|
) |
|
55
|
|
|
assert not results |
|
56
|
|
|
|
|
57
|
|
|
def test_path_s1_s3_constrained_blue(self): |
|
58
|
|
|
"""Tests path from s1 to s3 constrained ownership blue""" |
|
59
|
|
|
self.initializer() |
|
60
|
|
|
|
|
61
|
|
|
source = "S1" |
|
62
|
|
|
destination = "S3" |
|
63
|
|
|
results = self.graph.constrained_k_shortest_paths( |
|
64
|
|
|
source, destination, mandatory_metrics={"ownership": "blue"} |
|
65
|
|
|
) |
|
66
|
|
|
assert results |
|
67
|
|
|
|
|
68
|
|
|
for result in results: |
|
69
|
|
|
path = result["hops"] |
|
70
|
|
|
assert source == path[0] |
|
71
|
|
|
assert destination == path[-1] |
|
72
|
|
|
|
|
73
|
|
|
def test_path_s1_s3_constrained_bandwidth(self): |
|
74
|
|
|
"""Tests path from s1 to s3 constrained bandwdith, the best path |
|
75
|
|
|
is supposed to be via s2""" |
|
76
|
|
|
|
|
77
|
|
|
self.initializer() |
|
78
|
|
|
|
|
79
|
|
|
source = "S1" |
|
80
|
|
|
destination = "S3" |
|
81
|
|
|
results = self.graph.constrained_k_shortest_paths( |
|
82
|
|
|
source, destination, mandatory_metrics={"bandwidth": 50} |
|
83
|
|
|
) |
|
84
|
|
|
|
|
85
|
|
|
assert results |
|
86
|
|
|
|
|
87
|
|
|
for result in results: |
|
88
|
|
|
path = result["hops"] |
|
89
|
|
|
assert source == path[0] |
|
90
|
|
|
assert "S2" in path |
|
91
|
|
|
assert destination == path[-1] |
|
92
|
|
|
|
|
93
|
|
|
@staticmethod |
|
94
|
|
|
def generate_topology(): |
|
95
|
|
|
"""Generates a predetermined topology. Topology 1""" |
|
96
|
|
|
switches = {} |
|
97
|
|
|
interfaces = {} |
|
98
|
|
|
links = {} |
|
99
|
|
|
|
|
100
|
|
|
TestPaths.create_switch("S1", switches) |
|
101
|
|
|
TestPaths.add_interfaces(2, switches["S1"], interfaces) |
|
102
|
|
|
|
|
103
|
|
|
TestPaths.create_switch("S2", switches) |
|
104
|
|
|
TestPaths.add_interfaces(3, switches["S2"], interfaces) |
|
105
|
|
|
|
|
106
|
|
|
TestPaths.create_switch("S3", switches) |
|
107
|
|
|
TestPaths.add_interfaces(2, switches["S3"], interfaces) |
|
108
|
|
|
|
|
109
|
|
|
TestPaths.create_switch("S4", switches) |
|
110
|
|
|
TestPaths.add_interfaces(2, switches["S4"], interfaces) |
|
111
|
|
|
|
|
112
|
|
|
TestPaths.create_switch("S5", switches) |
|
113
|
|
|
|
|
114
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
|
115
|
|
|
links["S1:1<->S2:1"].extend_metadata( |
|
116
|
|
|
{"bandwidth": 50, "ownership": "red"} |
|
117
|
|
|
) |
|
118
|
|
|
|
|
119
|
|
|
links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"]) |
|
120
|
|
|
links["S3:1<->S2:2"].extend_metadata( |
|
121
|
|
|
{"bandwidth": 51, "ownership": "blue"} |
|
122
|
|
|
) |
|
123
|
|
|
|
|
124
|
|
|
links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"]) |
|
125
|
|
|
links["S1:2<->S3:2"].extend_metadata( |
|
126
|
|
|
{"bandwidth": 49, "ownership": "blue"} |
|
127
|
|
|
) |
|
128
|
|
|
|
|
129
|
|
|
for link in links.values(): |
|
130
|
|
|
link.enable() |
|
131
|
|
|
link.activate() |
|
132
|
|
|
|
|
133
|
|
|
return switches, links |
|
134
|
|
|
|