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 testUpdateSoftConstraintsForHopCountAndTEmetric() {
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, true, 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());
339 assertEquals("updated soft constraints max-wdm-TE-metric should be '8'",
340 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue());
341 assertEquals("updated soft constraints max-otn-TE-metric should be '11'",
342 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue());
344 // test addition of hard hop-count when no soft hop-count
345 initialHardConstraints = buildHardConstraint(null, false, null, null, null, null, true, true, null, null);
346 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
347 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
348 initialHardConstraints, initialSoftConstraints);
349 assertEquals("updated soft constraints should contain hard constraint",
350 initialHardConstraints.getHopCount(), generatedSoftConstraints.getHopCount());
351 assertEquals("updated soft constraints max-wdm-hop-count should be '3'",
352 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue());
353 assertEquals("updated soft constraints max-otn-hop-count should be '5'",
354 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue());
355 assertEquals("updated soft constraints max-wdm-TE-metric should be '8'",
356 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue());
357 assertEquals("updated soft constraints max-otn-TE-metric should be '11'",
358 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue());
360 // test addition of hard hop-count when existing soft hop-count
361 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, true, true, null, null);
362 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
363 initialHardConstraints, initialSoftConstraints);
364 assertEquals("updated soft constraints max-wdm-hop-count should be '3'",
365 3, generatedSoftConstraints.getHopCount().getMaxWdmHopCount().intValue());
366 assertEquals("updated soft constraints max-otn-hop-count should be '5'",
367 5, generatedSoftConstraints.getHopCount().getMaxOtnHopCount().intValue());
368 assertEquals("updated soft constraints max-wdm-TE-metric should be '8'",
369 8, generatedSoftConstraints.getTEMetric().getMaxWdmTEMetric().intValue());
370 assertEquals("updated soft constraints max-otn-TE-metric should be '11'",
371 11, generatedSoftConstraints.getTEMetric().getMaxOtnTEMetric().intValue());
375 public void testUpdateSoftConstraintsForCoRouting() {
376 HardConstraints initialHardConstraints =
377 buildHardConstraint(null, false, null, null, null, null, false, false, null, null);
378 SoftConstraints initialSoftConstraints =
379 buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
380 SoftConstraints generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
381 initialHardConstraints, initialSoftConstraints);
382 assertNull("updated soft constraints should contain no co-routing constraint",
383 generatedSoftConstraints.getCoRouting());
385 initialSoftConstraints =
386 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
387 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
388 initialHardConstraints, initialSoftConstraints);
389 assertEquals("updated soft constraints should not be changed",
390 initialSoftConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting());
391 assertEquals("updated soft constraints should contain 2 co-routed services",
392 2, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
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 1"))
396 .getServiceApplicability().getEquipment().getRoadmSrg());
397 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
398 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
399 .routing.ServiceIdentifierListKey("service 1"))
400 .getServiceApplicability().getLink());
401 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
402 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
403 .routing.ServiceIdentifierListKey("service 2"))
404 .getServiceApplicability().getEquipment());
405 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
406 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
407 .routing.ServiceIdentifierListKey("service 2"))
408 .getServiceApplicability().getLink());
410 // test addition of hard co-routing when no soft co-routing
411 initialHardConstraints =
412 buildHardConstraint(null, false, null, null, null, null, true, false, null, "coRouting2");
413 initialSoftConstraints = buildSoftConstraint(null, false, null, null, null, null, false, false, null, null);
414 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
415 initialHardConstraints, initialSoftConstraints);
416 assertEquals("updated soft constraints should contain hard constraint",
417 initialHardConstraints.getCoRouting(), generatedSoftConstraints.getCoRouting());
418 assertEquals("updated soft constraints should contain 1 co-routed service",
419 1, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
420 assertTrue(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
421 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
422 .routing.ServiceIdentifierListKey("service 3"))
423 .getServiceApplicability().getSite());
424 assertNull(generatedSoftConstraints.getCoRouting().getServiceIdentifierList()
425 .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
426 .routing.ServiceIdentifierListKey("service 3"))
427 .getServiceApplicability().getLink());
429 // test addition of hard hop-count when existing soft hop-count
430 initialSoftConstraints =
431 buildSoftConstraint(null, false, null, null, null, null, true, false, null, "coRouting1");
432 generatedSoftConstraints = DowngradeConstraints.updateSoftConstraints(
433 initialHardConstraints, initialSoftConstraints);
434 assertEquals("updated soft constraints should contain 3 co-routed service",
435 3, generatedSoftConstraints.getCoRouting().getServiceIdentifierList().size());
436 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
437 IsMapContaining.hasKey(
438 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
439 .routing.ServiceIdentifierListKey("service 1")));
440 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
441 IsMapContaining.hasKey(
442 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
443 .routing.ServiceIdentifierListKey("service 2")));
444 assertThat(generatedSoftConstraints.getCoRouting().getServiceIdentifierList(),
445 IsMapContaining.hasKey(
446 new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co
447 .routing.ServiceIdentifierListKey("service 3")));
451 public void testDowngradeHardConstraints() {
452 HardConstraints initialHardConstraints = null;
453 HardConstraints genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
454 assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints);
455 initialHardConstraints = new HardConstraintsBuilder().build();
456 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
457 assertNotNull("generated hard-constraints should be empty, not null", genHardConstraints);
458 initialHardConstraints = buildHardConstraint(null, false, null, "link1", null, Double.valueOf(12.8), false,
460 genHardConstraints = DowngradeConstraints.downgradeHardConstraints(initialHardConstraints);
461 assertEquals("Latency value should be 12.8",
462 (long) 12.8, genHardConstraints.getLatency().getMaxLatency().longValue());
463 assertNull("generated hard constraints should only contain max-latency value",
464 genHardConstraints.getCoRouting());
465 assertNull("generated hard constraints should only contain max-latency value",
466 genHardConstraints.getExclude());
467 assertNull("generated hard constraints should only contain max-latency value",
468 genHardConstraints.getInclude());
472 public void testConvertToSoftConstraints() {
473 HardConstraints initialHardConstraints = null;
474 SoftConstraints genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
475 assertNotNull("generated soft constraints should never be null", genSoftConstraints);
476 assertNull("generated soft constraints should be empty", genSoftConstraints.getExclude());
477 assertNull("generated soft constraints should be empty", genSoftConstraints.getCoRouting());
478 assertNull("generated soft constraints should be empty", genSoftConstraints.getLatency());
480 List<String> hardCustomerCode = Arrays.asList("customer-code 1", "customer-code 2");
481 initialHardConstraints =
482 buildHardConstraint(hardCustomerCode, false, null, "link1", "node", null, false, false, null, null);
483 genSoftConstraints = DowngradeConstraints.convertToSoftConstraints(initialHardConstraints);
484 assertEquals("generated soft constraints should contain customer-code items", 2,
485 genSoftConstraints.getCustomerCode().size());
486 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 1"));
487 assertTrue(genSoftConstraints.getCustomerCode().contains("customer-code 2"));
488 assertNotNull("generated soft constraints should contain exclude constraint", genSoftConstraints.getExclude());
489 assertEquals("generated soft constraints should contain exclude constraint with one link-id",
490 1, genSoftConstraints.getExclude().getLinkIdentifier().values().size());
491 assertEquals("link-id 1",
492 genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkId());
493 assertEquals("openroadm-topology",
494 genSoftConstraints.getExclude().getLinkIdentifier().values().stream().findAny().get().getLinkNetworkId());
495 assertNotNull("generated soft constraints should contain include constraint", genSoftConstraints.getInclude());
496 assertEquals("generated soft constraints should contain include constraint with two node-id",
497 2, genSoftConstraints.getInclude().getNodeId().size());
498 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-1")));
499 assertTrue(genSoftConstraints.getInclude().getNodeId().contains(new NodeIdType("node-id-3")));
500 assertNull("generated soft constraints should not contain any latency constraint",
501 genSoftConstraints.getLatency());
502 assertNull("generated soft constraints should not contain any max-distance constraint",
503 genSoftConstraints.getDistance());
504 assertNull("generated soft constraints should not contain any co-routing constraint",
505 genSoftConstraints.getCoRouting());