1
|
|
|
"""Module to test the KytosGraph in graph.py.""" |
2
|
|
|
from kytos.core.link import Link |
3
|
|
|
|
4
|
|
|
# module under test |
5
|
|
|
from tests.integration.test_results import TestResults |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TestResultsSimple(TestResults): |
9
|
|
|
"""Tests for the graph class. |
10
|
|
|
|
11
|
|
|
Tests if the paths returned have only legal edges. |
12
|
|
|
""" |
13
|
|
|
|
14
|
|
|
def test_path1(self): |
15
|
|
|
"""Tests a simple, possible path""" |
16
|
|
|
self.initializer() |
17
|
|
|
results = self.get_path_constrained("S1", "S2") |
18
|
|
|
|
19
|
|
|
self.assertNotEqual(results, []) |
20
|
|
|
|
21
|
|
|
def test_path2(self): |
22
|
|
|
"""Tests a simple, impossible path""" |
23
|
|
|
self.initializer() |
24
|
|
|
results = self.get_path_constrained("S1", "S4") |
25
|
|
|
|
26
|
|
|
self.assertEqual(results, []) |
27
|
|
|
|
28
|
|
|
def test_path3(self): |
29
|
|
|
"""Tests a path to self again""" |
30
|
|
|
self.initializer() |
31
|
|
|
results = self.get_path_constrained("S1", "S1") |
32
|
|
|
|
33
|
|
|
self.assertNotEqual(results, []) |
34
|
|
|
|
35
|
|
|
def test_path4(self): |
36
|
|
|
"""Tests constrained path to self again""" |
37
|
|
|
self.initializer() |
38
|
|
|
results = self.get_path_constrained("S5", "S5", base={"ownership": "blue"}) |
39
|
|
|
|
40
|
|
|
for result in results: |
41
|
|
|
self.assertNotEqual([], result["paths"]) |
42
|
|
|
self.assertIn(['S5'], result["paths"]) |
43
|
|
|
|
44
|
|
|
def test_path5(self): |
45
|
|
|
"""Tests constrained path to self again""" |
46
|
|
|
self.initializer() |
47
|
|
|
results = self.get_path_constrained("S5", "S5", flexible={"priority": 5}) |
48
|
|
|
|
49
|
|
|
for result in results: |
50
|
|
|
self.assertNotEqual([], result["paths"]) |
51
|
|
|
self.assertIn(['S5'], result["paths"]) |
52
|
|
|
|
53
|
|
|
@staticmethod |
54
|
|
|
def generate_topology(): |
55
|
|
|
"""Generates a predetermined topology""" |
56
|
|
|
switches = {} |
57
|
|
|
interfaces = {} |
58
|
|
|
links = {} |
59
|
|
|
|
60
|
|
|
TestResults.create_switch("S1", switches) |
61
|
|
|
TestResults.add_interfaces(2, switches["S1"], interfaces) |
62
|
|
|
|
63
|
|
|
TestResults.create_switch("S2", switches) |
64
|
|
|
TestResults.add_interfaces(3, switches["S2"], interfaces) |
65
|
|
|
|
66
|
|
|
TestResults.create_switch("S3", switches) |
67
|
|
|
TestResults.add_interfaces(2, switches["S3"], interfaces) |
68
|
|
|
|
69
|
|
|
TestResults.create_switch("S4", switches) |
70
|
|
|
TestResults.add_interfaces(2, switches["S4"], interfaces) |
71
|
|
|
|
72
|
|
|
TestResults.create_switch("S5", switches) |
73
|
|
|
|
74
|
|
|
links["S1:1<->S2:1"] = Link(interfaces["S1:1"], interfaces["S2:1"]) |
75
|
|
|
links["S1:1<->S2:1"].extend_metadata({"bandwidth": 50, "ownership": "red"}) |
76
|
|
|
|
77
|
|
|
links["S3:1<->S2:2"] = Link(interfaces["S3:1"], interfaces["S2:2"]) |
78
|
|
|
links["S3:1<->S2:2"].extend_metadata({"bandwidth": 51, "ownership": "blue"}) |
79
|
|
|
|
80
|
|
|
links["S1:2<->S3:2"] = Link(interfaces["S1:2"], interfaces["S3:2"]) |
81
|
|
|
links["S1:2<->S3:2"].extend_metadata({"bandwidth": 49, "ownership": "blue"}) |
82
|
|
|
|
83
|
|
|
return switches, links |
84
|
|
|
|