2 * Copyright © 2018 2022 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.servicehandler;
10 import static org.hamcrest.CoreMatchers.is;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
13 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildHardConstraint;
19 import static org.opendaylight.transportpce.servicehandler.utils.ConstraintsUtils.buildSoftConstraint;
21 import java.util.Arrays;
22 import java.util.List;
23 import org.hamcrest.collection.IsMapContaining;
24 import org.junit.Test;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.DiversityConstraints.DiversityType;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierKey;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierListKey;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints;
34 * Class to test downgrading and updating Constraints .
35 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
36 * @author Gilles Thouenon (gilles.thouenon@orange.com)
38 public class DowngradeConstraintsTest {
41 public void testUpdateSoftConstraintsForCustomerCode() {
42 // test no addition when hard customer-code is null or empty
43 HardConstraints initialHardConstraints =
44 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
45 SoftConstraints initialSoftConstraints =
46 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
47 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
48 initialHardConstraints, initialSoftConstraints);
49 assertNull("updated soft constraints should contain no customer code",
50 generatedSoftConstraints.getCustomerCode());
51 List<String> softCustomerCode = Arrays.asList("soft-customer-code 3", "soft-customer-code 4");
52 initialSoftConstraints =
53 buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null);
54 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
55 initialHardConstraints, initialSoftConstraints);
56 assertEquals(initialSoftConstraints.getCustomerCode(), generatedSoftConstraints.getCustomerCode());
58 // test addition of hard customer-code when no soft customer-code
59 List<String> hardCustomerCode = Arrays.asList("hard-customer-code 1", "hard-customer-code 2");
60 initialHardConstraints =
61 buildHardConstraint(hardCustomerCode, false, null, null, null, null, false, false, null, null);
62 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
63 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
64 initialHardConstraints, initialSoftConstraints);
65 assertEquals("updated soft constraints should contain the customer code of hard constraint",
66 generatedSoftConstraints.getCustomerCode(),
67 initialHardConstraints.getCustomerCode());
68 // test addition of hard customer-code when existing soft customer-code
69 initialSoftConstraints =
70 buildSoftConstraint(softCustomerCode, false, null, null, null, null, false, false, null, null);
71 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
72 initialHardConstraints, initialSoftConstraints);
73 assertThat("updated soft constraints should contain 4 customer code",
74 generatedSoftConstraints.getCustomerCode(), hasSize(4));
75 assertThat(generatedSoftConstraints.getCustomerCode(),
76 containsInAnyOrder("hard-customer-code 1", "hard-customer-code 2", "soft-customer-code 3",
77 "soft-customer-code 4"));
81 public void testUpdateSoftConstraintsForDiversity() {
82 HardConstraints initialHardConstraints =
83 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
84 SoftConstraints initialSoftConstraints =
85 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
86 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
87 initialHardConstraints, initialSoftConstraints);
88 assertNull("updated soft constraints should contain no diversity constraint",
89 generatedSoftConstraints.getDiversity());
90 List<String> softDiversityServiceid = Arrays.asList("soft-service 3");
91 initialSoftConstraints =
92 buildSoftConstraint(null, false, softDiversityServiceid, null, null, null, false, false, null, null);
93 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
94 initialHardConstraints, initialSoftConstraints);
95 assertEquals(initialSoftConstraints.getDiversity(), generatedSoftConstraints.getDiversity());
97 // test addition of hard diversity when no soft diversity
98 List<String> hardDiversityServiceid = Arrays.asList("hard-service 1", "hard-service 2");
99 initialHardConstraints =
100 buildHardConstraint(null, false, hardDiversityServiceid, null, null, null, false, false, null, null);
101 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
102 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
103 initialHardConstraints, initialSoftConstraints);
104 assertEquals("updated soft constraints should contain the diversity of hard constraint",
105 generatedSoftConstraints.getDiversity(),
106 initialHardConstraints.getDiversity());
108 // test addition of hard diversity when existing soft diversity
109 initialSoftConstraints =
110 buildSoftConstraint(null, false, softDiversityServiceid, null, null, null, false, false, null, null);
111 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
112 initialHardConstraints, initialSoftConstraints);
113 assertThat("updated soft constraints should contain diversity with 3 services",
114 generatedSoftConstraints.getDiversity().getServiceIdentifierList().size(), is(3));
115 assertEquals("updated soft constraints should have diversity type of serial",
116 DiversityType.Serial,
117 generatedSoftConstraints.getDiversity().getDiversityType());
118 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
119 IsMapContaining.hasKey(new ServiceIdentifierListKey("hard-service 1")));
120 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
121 IsMapContaining.hasKey(new ServiceIdentifierListKey("hard-service 2")));
122 assertThat(generatedSoftConstraints.getDiversity().getServiceIdentifierList(),
123 IsMapContaining.hasKey(new ServiceIdentifierListKey("soft-service 3")));
127 public void testUpdateSoftConstraintsForExclude() {
128 HardConstraints initialHardConstraints =
129 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
130 SoftConstraints initialSoftConstraints =
131 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
132 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
133 initialHardConstraints, initialSoftConstraints);
134 assertNull("updated soft constraints should contain no exclude constraint",
135 generatedSoftConstraints.getExclude());
137 initialSoftConstraints = buildSoftConstraint(null, false, null, "link", null, null, false, false, null, null);
138 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
139 initialHardConstraints, initialSoftConstraints);
140 assertEquals("updated soft constraints should not be changed",
141 initialSoftConstraints.getExclude(), generatedSoftConstraints.getExclude());
143 // test addition of hard exclude with fiber list when no soft exclude
144 initialHardConstraints =
145 buildHardConstraint(null, false, null, "fiber1", null, null, false, false, null, null);
146 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
147 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
148 initialHardConstraints, initialSoftConstraints);
149 assertEquals("updated soft constraints should contain the exclude constraint of hard constraint",
150 generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude());
152 // test addition of hard exclude with fiber list when existing soft
153 // exclude with fiber list
154 initialSoftConstraints =
155 buildSoftConstraint(null, false, null, "fiber2", null, null, false, false, null, null);
156 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
157 initialHardConstraints, initialSoftConstraints);
158 assertThat("updated soft constraints should contain exclude with 3 fiber bundles",
159 generatedSoftConstraints.getExclude().getFiberBundle().size(), is(3));
160 assertThat(generatedSoftConstraints.getExclude().getFiberBundle(),
161 containsInAnyOrder("fiber-1", "fiber-2", "fiber-3"));
163 // test addition of hard exclude with link list when no soft exclude
164 initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, null, false, false, null, null);
165 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
166 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
167 initialHardConstraints, initialSoftConstraints);
168 assertEquals("updated soft constraints should contain the exclude constraint of hard constraint",
169 generatedSoftConstraints.getExclude(), initialHardConstraints.getExclude());
171 // test addition of hard exclude with link list when existing soft
172 // exclude with link list
173 initialSoftConstraints = buildSoftConstraint(null, false, null, "link2", null, null, false, false, null, null);
174 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
175 initialHardConstraints, initialSoftConstraints);
176 assertThat("updated soft constraints should contain exclude with 3 links",
177 generatedSoftConstraints.getExclude().getLinkIdentifier().size(), is(3));
178 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(),
179 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 1", "openroadm-topology")));
180 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(),
181 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 2", "openroadm-topology")));
182 assertThat(generatedSoftConstraints.getExclude().getLinkIdentifier(),
183 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 3", "openroadm-topology")));
187 public void testUpdateSoftConstraintsForInclude() {
188 HardConstraints initialHardConstraints =
189 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
190 SoftConstraints initialSoftConstraints =
191 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
192 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
193 initialHardConstraints, initialSoftConstraints);
194 assertNull("updated soft constraints should contain no include constraint",
195 generatedSoftConstraints.getInclude());
197 initialSoftConstraints = buildSoftConstraint(null, false, null, null, "link", null, false, false, null, null);
198 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
199 initialHardConstraints, initialSoftConstraints);
200 assertEquals("updated soft constraints should not be changed",
201 initialSoftConstraints.getInclude(), generatedSoftConstraints.getInclude());
203 // test addition of hard include with fiber list when no soft include
204 initialHardConstraints =
205 buildHardConstraint(null, false, null, null, "fiber1", null, false, false, null, null);
206 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
207 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
208 initialHardConstraints, initialSoftConstraints);
209 assertEquals("updated soft constraints should contain the include constraint of hard constraint",
210 generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude());
212 // test addition of hard include with fiber list when existing soft
213 // include with fiber list
214 initialSoftConstraints =
215 buildSoftConstraint(null, false, null, null, "fiber2", null, false, false, null, null);
216 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
217 initialHardConstraints, initialSoftConstraints);
218 assertThat("updated soft constraints should contain exclude with 3 fiber bundles",
219 generatedSoftConstraints.getInclude().getFiberBundle().size(), is(3));
220 assertThat(generatedSoftConstraints.getInclude().getFiberBundle(),
221 containsInAnyOrder("fiber-1", "fiber-2", "fiber-3"));
223 // test addition of hard include with link list when no soft include
224 initialHardConstraints = buildHardConstraint(null, false, null, null, "link1", null, false, false, null, null);
225 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
226 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
227 initialHardConstraints, initialSoftConstraints);
228 assertEquals("updated soft constraints should contain the include constraint of hard constraint",
229 generatedSoftConstraints.getInclude(), initialHardConstraints.getInclude());
231 // test addition of hard include with link list when existing soft
232 // include with link list
233 initialSoftConstraints = buildSoftConstraint(null, false, null, null, "link2", null, false, false, null, null);
234 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
235 initialHardConstraints, initialSoftConstraints);
236 assertThat("updated soft constraints should contain include with 3 links",
237 generatedSoftConstraints.getInclude().getLinkIdentifier().size(), is(3));
238 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(),
239 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 1", "openroadm-topology")));
240 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(),
241 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 2", "openroadm-topology")));
242 assertThat(generatedSoftConstraints.getInclude().getLinkIdentifier(),
243 IsMapContaining.hasKey(new LinkIdentifierKey("link-id 3", "openroadm-topology")));
247 public void testUpdateSoftConstraintsForLatency() {
248 HardConstraints initialHardConstraints =
249 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
250 SoftConstraints initialSoftConstraints =
251 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
252 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
253 initialHardConstraints, initialSoftConstraints);
254 assertNull("updated soft constraints should contain no latency constraint",
255 generatedSoftConstraints.getLatency());
257 initialSoftConstraints =
258 buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null);
259 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
260 initialHardConstraints, initialSoftConstraints);
261 assertEquals("updated soft constraints should not be changed",
262 initialSoftConstraints.getLatency(), generatedSoftConstraints.getLatency());
263 assertEquals("updated soft constraints value should be '12.2'",
264 (float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f);
266 // test addition of hard latency when no soft latency
267 initialHardConstraints =
268 buildHardConstraint(null, false, null, null, null, Double.valueOf(16.59), false, false, null, null);
269 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
270 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
271 initialHardConstraints, initialSoftConstraints);
272 assertEquals("updated soft constraints value should be '16.59'",
273 (float) 16.59, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f);
275 // test addition of hard latency when existing different soft latency
276 initialSoftConstraints =
277 buildSoftConstraint(null, false, null, null, null, Double.valueOf(12.2), false, false, null, null);
278 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
279 initialHardConstraints, initialSoftConstraints);
280 assertEquals("updated soft constraints value should be '12.2'",
281 (float) 12.2, generatedSoftConstraints.getLatency().getMaxLatency().floatValue(), 0.0f);
285 public void testUpdateSoftConstraintsForDistance() {
286 HardConstraints initialHardConstraints =
287 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
288 SoftConstraints initialSoftConstraints =
289 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
290 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
291 initialHardConstraints, initialSoftConstraints);
292 assertNull("updated soft constraints should contain no distance constraint",
293 generatedSoftConstraints.getDistance());
295 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null);
296 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
297 initialHardConstraints, initialSoftConstraints);
298 assertEquals("updated soft constraints should not be changed",
299 initialSoftConstraints.getDistance(), generatedSoftConstraints.getDistance());
300 assertEquals("updated soft constraints value should be '750.2'",
301 (float) 750.2, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f);
303 // test addition of hard distance when no soft distance
304 initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, false, false, "555.5", null);
305 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
306 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
307 initialHardConstraints, initialSoftConstraints);
308 assertEquals("updated soft constraints value should be '555.5'",
309 (float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f);
311 // test addition of hard distance when existing different soft distance
312 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, "750.2", null);
313 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
314 initialHardConstraints, initialSoftConstraints);
315 assertEquals("updated soft constraints value should be '555.5'",
316 (float) 555.5, generatedSoftConstraints.getDistance().getMaxDistance().floatValue(), 0.0f);
320 public void testUpdateSoftConstraintsForHopCount() {
321 HardConstraints initialHardConstraints =
322 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
323 SoftConstraints initialSoftConstraints =
324 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
325 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
326 initialHardConstraints, initialSoftConstraints);
327 assertNull("updated soft constraints should contain no hop-count constraint",
328 generatedSoftConstraints.getHopCount());
330 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, false, null, null);
331 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
332 initialHardConstraints, initialSoftConstraints);
333 assertEquals("updated soft constraints should not be changed",
334 initialSoftConstraints.getHopCount(), generatedSoftConstraints.getHopCount());
335 assertEquals("updated soft constraints max-wdm-hop-count should be '3'",
336 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue());
337 assertEquals("updated soft constraints max-otn-hop-count should be '5'",
338 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue());
340 // test addition of hard hop-count when no soft hop-count
341 initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, true, false, null, null);
342 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
343 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
344 initialHardConstraints, initialSoftConstraints);
345 assertEquals("updated soft constraints should contain hard constraint",
346 initialHardConstraints.getHopCount(), generatedSoftConstraints.getHopCount());
347 assertEquals("updated soft constraints max-wdm-hop-count should be '3'",
348 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue());
349 assertEquals("updated soft constraints max-otn-hop-count should be '5'",
350 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue());
352 // test addition of hard hop-count when existing soft hop-count
353 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, false, null, null);
354 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
355 initialHardConstraints, initialSoftConstraints);
356 assertEquals("updated soft constraints max-wdm-hop-count should be '3'",
357 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue());
358 assertEquals("updated soft constraints max-otn-hop-count should be '5'",
359 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue());
363 public void testUpdateSoftConstraintsForCoRouting() {
364 HardConstraints initialHardConstraints =
365 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
366 SoftConstraints initialSoftConstraints =
367 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
368 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
369 initialHardConstraints, initialSoftConstraints);
370 assertNull("updated soft constraints should contain no co-routing constraint",
371 generatedSoftConstraints.getCoRouting());
373 initialSoftConstraints =
374 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
375 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
376 initialHardConstraints, initialSoftConstraints);
377 assertEquals("updated soft constraints should not be changed",
378 initialSoftConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting());
379 assertEquals("updated soft constraints should contain 2 co-routed services",
380 2, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
381 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
382 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
383 .routing.ServiceIdentifierListKey("service 1"))
384 .getServiceApplicability().getEquipment().getRoadmSrg());
385 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
386 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
387 .routing.ServiceIdentifierListKey("service 1"))
388 .getServiceApplicability().getLink());
389 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
390 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
391 .routing.ServiceIdentifierListKey("service 2"))
392 .getServiceApplicability().getEquipment());
393 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
394 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
395 .routing.ServiceIdentifierListKey("service 2"))
396 .getServiceApplicability().getLink());
398 // test addition of hard co-routing when no soft co-routing
399 initialHardConstraints =
400 buildHardConstraint(null, false, null, null, null, null, true, false, null, "coRouting2");
401 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
402 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
403 initialHardConstraints, initialSoftConstraints);
404 assertEquals("updated soft constraints should contain hard constraint",
405 initialHardConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting());
406 assertEquals("updated soft constraints should contain 1 co-routed service",
407 1, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
408 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
409 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
410 .routing.ServiceIdentifierListKey("service 3"))
411 .getServiceApplicability().getSite());
412 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
413 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
414 .routing.ServiceIdentifierListKey("service 3"))
415 .getServiceApplicability().getLink());
417 // test addition of hard hop-count when existing soft hop-count
418 initialSoftConstraints =
419 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
420 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
421 initialHardConstraints, initialSoftConstraints);
422 assertEquals("updated soft constraints should contain 3 co-routed service",
423 3, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
424 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
425 IsMapContaining.hasKey(
426 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
427 .routing.ServiceIdentifierListKey("service 1")));
428 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
429 IsMapContaining.hasKey(
430 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
431 .routing.ServiceIdentifierListKey("service 2")));
432 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
433 IsMapContaining.hasKey(
434 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
435 .routing.ServiceIdentifierListKey("service 3")));
439 public void testDowngradeHardConstraints() {
440 HardConstraints initialHardConstraints = null;
441 HardConstraints genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
442 assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints);
443 initialHardConstraints = new HardConstraintsBuilder().build();
444 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
445 assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints);
446 initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, Double.valueOf(12.8), false,
448 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
449 assertEquals("Latency value should be 12.8",
450 (long) 12.8, genHardConstraints.getLatency().getMaxLatency().longValue());
451 assertNull("generated hard constraints should only contain max-latency value",
452 genHardConstraints.getCoRouting());
453 assertNull("generated hard constraints should only contain max-latency value",
454 genHardConstraints.getExclude());
455 assertNull("generated hard constraints should only contain max-latency value",
456 genHardConstraints.getInclude());
460 public void testConvertToSoftConstraints() {
461 HardConstraints initialHardConstraints = null;
462 SoftConstraints genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
463 assertNotNull("generated soft constraints should never be null", genSoftConstraints);
464 assertNull("generated soft constraints should be empty", genSoftConstraints.getExclude());
465 assertNull("generated soft constraints should be empty", genSoftConstraints.getCoRouting());
466 assertNull("generated soft constraints should be empty", genSoftConstraints.getLatency());
468 List<String> hardCustomerCode = Arrays.asList("customer-code 1", "customer-code 2");
469 initialHardConstraints =
470 buildHardConstraint(hardCustomerCode, false, null, "link1", "node", null, false, false, null, null);
471 genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
472 assertEquals("generated soft constraints should contain customer-code items", 2,
473 genSoftConstraints.getCustomerCode().size());
474 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 1"));
475 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 2"));
476 assertNotNull("generated soft constraints should contain exclude constraint", genSoftConstraints.getExclude());
477 assertEquals("generated soft constraints should contain exclude constraint with one link-id",
478 1, genSoftConstraints.getExclude().getLinkIdentifier().values().size());
479 assertEquals("link-id 1",
480 genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkId());
481 assertEquals("openroadm-topology",
482 genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkNetworkId());
483 assertNotNull("generated soft constraints should contain include constraint", genSoftConstraints.getInclude());
484 assertEquals("generated soft constraints should contain include constraint with two node-id",
485 2, genSoftConstraints.getInclude().getNodeId().size());
486 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-1")));
487 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-3")));
488 assertNull("generated soft constraints should not contain any latency constraint",
489 genSoftConstraints.getLatency());
490 assertNull("generated soft constraints should not contain any max-distance constraint",
491 genSoftConstraints.getDistance());
492 assertNull("generated soft constraints should not contain any co-routing constraint",
493 genSoftConstraints.getCoRouting());