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.utils;
10 import java.math.BigDecimal;
11 import java.util.Arrays;
12 import java.util.HashMap;
13 import java.util.List;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.DiversityConstraints.DiversityType;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifier;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRouting;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Distance;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DistanceBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Diversity;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DiversityBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Exclude;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.ExcludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCount;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCountBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Latency;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.LatencyBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetric;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetricBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierList;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierListKey;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.equipment.EquipmentBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.service.applicability.g.ServiceApplicabilityBuilder;
44 import org.opendaylight.yangtools.yang.common.Uint32;
45 import org.opendaylight.yangtools.yang.common.Uint8;
48 * Utility Class to Build Hard Constraints and Soft Constraints.
49 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
50 * @author Gilles Thouenon (gilles.thouenon@orange.com)
52 public final class ConstraintsUtils {
54 private ConstraintsUtils() {
58 * Build a rather configurable soft-constraint.
59 * @param customerCode set the list of customer-code provided
60 * @param operationalMode set list of operational-mode
61 * @param diversityServiceList set diversity constraints from serviceListId
63 * @param exclude set exclude constraints
64 * @param include set include constraints
65 * @param maxLatency set a maxLatency value, null otherwise
66 * @param hopCount set a max-wdm-hop-count value
67 * @param teMetric set a max-wdm-TE-metric
68 * @param maxDistance set a max-distance value, null otherwise
69 * @param coRoutingServiceId set co-routing constraints
70 * @return the hard-constraints
72 public static SoftConstraints buildSoftConstraint(List<String> customerCode, boolean operationalMode,
73 List<String> diversityServiceList, String exclude, String include,
74 Double maxLatency, boolean hopCount, boolean teMetric,
75 String maxDistance, String coRoutingServiceId) {
77 HardConstraints baseConstraint = buildHardConstraint(customerCode, operationalMode, diversityServiceList,
78 exclude, include, maxLatency, hopCount, teMetric, maxDistance, coRoutingServiceId);
79 return new SoftConstraintsBuilder()
80 .setCustomerCode(baseConstraint.getCustomerCode())
81 .setOperationalMode(baseConstraint.getOperationalMode())
82 .setDiversity(baseConstraint.getDiversity())
83 .setExclude(baseConstraint.getExclude())
84 .setInclude(baseConstraint.getInclude())
85 .setLatency(baseConstraint.getLatency())
86 .setHopCount(baseConstraint.getHopCount())
87 .setTEMetric(baseConstraint.getTEMetric())
88 .setDistance(baseConstraint.getDistance())
89 .setCoRouting(baseConstraint.getCoRouting())
94 * Build a rather configurable hard-constraint.
95 * @param customerCode set the list of customer-code provided
96 * @param operationalMode set list of operational-mode
97 * @param diversityServiceList set diversity constraints from serviceListId
99 * @param exclude set exclude constraints
100 * @param include set include constraints
101 * @param maxLatency set a maxLatency value, null otherwise
102 * @param hopCount set a max-wdm-hop-count value
103 * @param teMetric set a max-wdm-TE-metric
104 * @param maxDistance set a max-distance value, null otherwise
105 * @param coRoutingServiceId set co-routing constraints
106 * @return the hard-constraints
108 public static HardConstraints buildHardConstraint(List<String> customerCode, boolean operationalMode,
109 List<String> diversityServiceList, String exclude, String include,
110 Double maxLatency, boolean hopCount, boolean teMetric,
111 String maxDistance, String coRoutingServiceId) {
113 List<String> operationalModeList = null;
114 if (operationalMode) {
115 operationalModeList = Arrays.asList("operational-mode 1", "operational-mode 2");
117 Diversity diversity = null;
118 if (diversityServiceList != null && !diversityServiceList.isEmpty()) {
120 ServiceIdentifierListKey,
121 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
122 .constraints.ServiceIdentifierList> serviceIdList = new HashMap<>();
123 for (String serviceId : diversityServiceList) {
124 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
125 .constraints.ServiceIdentifierList sil = createServiceIdentifierListForDiversity(serviceId);
126 serviceIdList.put(sil.key(), sil);
128 diversity = new DiversityBuilder()
129 .setDiversityType(DiversityType.Serial)
130 .setServiceIdentifierList(serviceIdList)
134 Latency latency = null;
135 if (maxLatency != null) {
136 latency = new LatencyBuilder()
137 .setMaxLatency(new BigDecimal(maxLatency))
142 hc = new HopCountBuilder()
143 .setMaxWdmHopCount(Uint8.valueOf(3))
144 .setMaxOtnHopCount(Uint8.valueOf(5))
147 Map<String, Exclude> excludeMap = initialiseExcludeMap();
148 Exclude exclu = exclude == null || !excludeMap.containsKey(exclude)
150 : excludeMap.get(exclude);
152 Map<String, Include> includeMap = initialiseIncludeMap();
153 Include inclu = include == null || !includeMap.containsKey(include)
155 : includeMap.get(include);
159 tem = new TEMetricBuilder()
160 .setMaxWdmTEMetric(Uint32.valueOf(8))
161 .setMaxOtnTEMetric(Uint32.valueOf(11))
164 Distance distance = null;
165 if (maxDistance != null) {
166 distance = new DistanceBuilder()
167 .setMaxDistance(new BigDecimal(maxDistance))
170 Map<String, CoRouting> coRoutingMap = initialiseCoRoutingMap();
171 CoRouting coRouting = coRoutingServiceId == null || !coRoutingMap.containsKey(coRoutingServiceId)
173 : coRoutingMap.get(coRoutingServiceId);
174 return new HardConstraintsBuilder()
175 .setCustomerCode(customerCode)
176 .setOperationalMode(operationalModeList)
177 .setDiversity(diversity)
183 .setDistance(distance)
184 .setCoRouting(coRouting)
188 private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
189 .service.constraints.ServiceIdentifierList createServiceIdentifierListForDiversity(String serviceId) {
190 return new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
191 .service.constraints.ServiceIdentifierListBuilder()
192 .setServiceIndentifier(serviceId)
193 .setServiceApplicability(new ServiceApplicabilityBuilder()
202 private static Map<String, Exclude> initialiseExcludeMap() {
203 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
204 .setLinkId("link-id 1")
205 .setLinkNetworkId("openroadm-topology")
207 Exclude exclude1 = new ExcludeBuilder()
208 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
210 Exclude exclude2 = new ExcludeBuilder()
211 .setNodeId(List.of(new NodeIdType("node-id-2")))
213 Exclude exclude3 = new ExcludeBuilder()
214 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
216 Exclude exclude4 = new ExcludeBuilder()
217 .setFiberBundle(List.of("fiber-1", "fiber-2"))
219 Exclude exclude5 = new ExcludeBuilder()
220 .setFiberBundle(List.of("fiber-2", "fiber-3"))
222 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
223 .setLinkId("link-id 2")
224 .setLinkNetworkId("openroadm-topology")
226 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
227 .setLinkId("link-id 3")
228 .setLinkNetworkId("openroadm-topology")
230 Exclude exclude6 = new ExcludeBuilder()
231 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
233 return Map.of("link1", exclude1, "node", exclude2, "service", exclude3, "fiber1", exclude4, "fiber2", exclude5,
237 private static Map<String, Include> initialiseIncludeMap() {
238 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
239 .setLinkId("link-id 1")
240 .setLinkNetworkId("openroadm-topology")
242 Include exclude1 = new IncludeBuilder()
243 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
245 Include exclude2 = new IncludeBuilder()
246 .setNodeId(List.of(new NodeIdType("node-id-1"), new NodeIdType("node-id-3")))
248 Include exclude3 = new IncludeBuilder()
249 .setSupportingServiceName(List.of("supported-service-1", "supported-service-5"))
251 Include exclude4 = new IncludeBuilder()
252 .setFiberBundle(List.of("fiber-1", "fiber-2"))
254 Include exclude5 = new IncludeBuilder()
255 .setFiberBundle(List.of("fiber-2", "fiber-3"))
257 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
258 .setLinkId("link-id 2")
259 .setLinkNetworkId("openroadm-topology")
261 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
262 .setLinkId("link-id 3")
263 .setLinkNetworkId("openroadm-topology")
265 Include exclude6 = new IncludeBuilder()
266 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
268 return Map.of("link1", exclude1, "node", exclude2, "service", exclude3, "fiber1", exclude4, "fiber2", exclude5,
272 private static Map<String, CoRouting> initialiseCoRoutingMap() {
273 ServiceIdentifierList sil1 = new ServiceIdentifierListBuilder()
274 .setServiceIdentifier("service 1")
275 .setServiceApplicability(new ServiceApplicabilityBuilder()
276 .setEquipment(new EquipmentBuilder()
281 ServiceIdentifierList sil2 = new ServiceIdentifierListBuilder()
282 .setServiceIdentifier("service 2")
283 .setServiceApplicability(new ServiceApplicabilityBuilder()
287 ServiceIdentifierList sil3 = new ServiceIdentifierListBuilder()
288 .setServiceIdentifier("service 3")
289 .setServiceApplicability(new ServiceApplicabilityBuilder()
293 CoRouting coRouting1 = new CoRoutingBuilder()
294 .setServiceIdentifierList(Map.of(sil1.key(), sil1, sil2.key(), sil2))
296 CoRouting coRouting2 = new CoRoutingBuilder()
297 .setServiceIdentifierList(Map.of(sil3.key(), sil3))
299 return Map.of("coRouting1", coRouting1, "coRouting2", coRouting2);