@@ 54-74 (lines=21) @@ | ||
51 | paths = self.graph.path_cost_builder(paths, weight=spf_attribute) |
|
52 | assert paths[0]["cost"] == 105 + 1 + 1 |
|
53 | ||
54 | def test_cspf_reliability_between_u1_u2(self): |
|
55 | """Test CSPF reliability constraint between user1 and user2.""" |
|
56 | self.initializer() |
|
57 | source = "User1" |
|
58 | destination = "User2" |
|
59 | paths = self.graph.constrained_k_shortest_paths( |
|
60 | source, destination, mandatory_metrics={"reliability": 10} |
|
61 | ) |
|
62 | assert not paths |
|
63 | ||
64 | paths = self.graph.constrained_k_shortest_paths( |
|
65 | source, destination, mandatory_metrics={"reliability": 3} |
|
66 | ) |
|
67 | assert paths |
|
68 | ||
69 | for path in paths: |
|
70 | assert path["hops"][0] == source |
|
71 | assert path["hops"][-1] == destination |
|
72 | assert path["metrics"] == {"reliability": 3} |
|
73 | paths = self.graph.path_cost_builder(paths) |
|
74 | assert paths[0]["cost"] == 12 |
|
75 | ||
76 | def test_cspf_bandwidth_between_u1_u4(self): |
|
77 | """Test CSPF bandwidth constraint between user1 and user4.""" |
|
@@ 126-145 (lines=20) @@ | ||
123 | paths = self.graph.path_cost_builder(paths) |
|
124 | assert paths[0]["cost"] >= 3 |
|
125 | ||
126 | def test_cspf_ownership_between_s4_s6(self): |
|
127 | """Test CSPF ownership constraint between switch4 and switch6.""" |
|
128 | self.initializer() |
|
129 | source = "S6:2" |
|
130 | destination = "S4:2" |
|
131 | ||
132 | paths = self.graph.constrained_k_shortest_paths( |
|
133 | source, destination, mandatory_metrics={"ownership": "B"} |
|
134 | ) |
|
135 | assert not paths |
|
136 | ||
137 | paths = self.graph.constrained_k_shortest_paths( |
|
138 | source, destination, mandatory_metrics={"ownership": "A"} |
|
139 | ) |
|
140 | assert paths |
|
141 | for path in paths: |
|
142 | assert path["hops"][0] == source |
|
143 | assert path["hops"][-1] == destination |
|
144 | paths = self.graph.path_cost_builder(paths) |
|
145 | assert paths[0]["cost"] >= 3 |
|
146 | ||
147 | def test_cspf_flexible_between_s4_s6(self): |
|
148 | """Test CSPF flexible constraint between switch4 and switch6.""" |
|
@@ 105-124 (lines=20) @@ | ||
102 | paths = self.graph.path_cost_builder(paths, weight=spf_attribute) |
|
103 | assert paths[0]["cost"] == 122 |
|
104 | ||
105 | def test_cspf_delay_between_u2_u3(self): |
|
106 | """Test CSPF delay constraint between user2 and user3.""" |
|
107 | self.initializer() |
|
108 | source = "User2" |
|
109 | destination = "User3" |
|
110 | ||
111 | paths = self.graph.constrained_k_shortest_paths( |
|
112 | source, destination, mandatory_metrics={"delay": 1} |
|
113 | ) |
|
114 | assert not paths |
|
115 | ||
116 | paths = self.graph.constrained_k_shortest_paths( |
|
117 | source, destination, mandatory_metrics={"delay": 50} |
|
118 | ) |
|
119 | assert paths |
|
120 | for path in paths: |
|
121 | assert path["hops"][0] == source |
|
122 | assert path["hops"][-1] == destination |
|
123 | paths = self.graph.path_cost_builder(paths) |
|
124 | assert paths[0]["cost"] >= 3 |
|
125 | ||
126 | def test_cspf_ownership_between_s4_s6(self): |
|
127 | """Test CSPF ownership constraint between switch4 and switch6.""" |