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.util.HashMap;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.DiversityConstraints.DiversityType;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifier;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierBuilder;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRouting;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DistanceBuilder;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DiversityBuilder;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Exclude;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.ExcludeBuilder;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCountBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.LatencyBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetricBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierList;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service.constraints.ServiceIdentifierListKey;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.equipment.EquipmentBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.service.applicability.g.ServiceApplicabilityBuilder;
37 import org.opendaylight.yangtools.yang.common.Decimal64;
38 import org.opendaylight.yangtools.yang.common.Uint32;
39 import org.opendaylight.yangtools.yang.common.Uint8;
42 * Utility Class to Build Hard Constraints and Soft Constraints.
43 * @author Ahmed Helmy ( ahmad.helmy@orange.com )
44 * @author Gilles Thouenon (gilles.thouenon@orange.com)
46 public final class ConstraintsUtils {
48 private ConstraintsUtils() {
52 * Build a rather configurable soft-constraint.
53 * @param customerCode set the list of customer-code provided
54 * @param operationalMode set list of operational-mode
55 * @param diversityServiceList set diversity constraints from serviceListId
57 * @param exclude set exclude constraints
58 * @param include set include constraints
59 * @param maxLatency set a maxLatency value, null otherwise
60 * @param hopCount set a max-wdm-hop-count value
61 * @param teMetric set a max-wdm-TE-metric
62 * @param maxDistance set a max-distance value, null otherwise
63 * @param coRoutingServiceId set co-routing constraints
64 * @return the hard-constraints
66 public static SoftConstraints buildSoftConstraint(Set<String> customerCode, boolean operationalMode,
67 Set<String> diversityServiceList, String exclude, String include,
68 Double maxLatency, boolean hopCount, boolean teMetric,
69 String maxDistance, String coRoutingServiceId) {
71 HardConstraints baseConstraint = buildHardConstraint(customerCode, operationalMode, diversityServiceList,
72 exclude, include, maxLatency, hopCount, teMetric, maxDistance, coRoutingServiceId);
73 return new SoftConstraintsBuilder()
74 .setCustomerCode(baseConstraint.getCustomerCode())
75 .setOperationalMode(baseConstraint.getOperationalMode())
76 .setDiversity(baseConstraint.getDiversity())
77 .setExclude(baseConstraint.getExclude())
78 .setInclude(baseConstraint.getInclude())
79 .setLatency(baseConstraint.getLatency())
80 .setHopCount(baseConstraint.getHopCount())
81 .setTEMetric(baseConstraint.getTEMetric())
82 .setDistance(baseConstraint.getDistance())
83 .setCoRouting(baseConstraint.getCoRouting())
88 * Build a rather configurable hard-constraint.
89 * @param customerCode set the list of customer-code provided
90 * @param operationalMode set list of operational-mode
91 * @param diversityServiceList set diversity constraints from serviceListId
93 * @param exclude set exclude constraints
94 * @param include set include constraints
95 * @param maxLatency set a maxLatency value, null otherwise
96 * @param hopCount set a max-wdm-hop-count value
97 * @param teMetric set a max-wdm-TE-metric
98 * @param maxDistance set a max-distance value, null otherwise
99 * @param coRoutingServiceId set co-routing constraints
100 * @return the hard-constraints
102 public static HardConstraints buildHardConstraint(Set<String> customerCode, boolean operationalMode,
103 Set<String> diversityServiceList, String exclude, String include,
104 Double maxLatency, boolean hopCount, boolean teMetric,
105 String maxDistance, String coRoutingServiceId) {
107 Map<ServiceIdentifierListKey,
108 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
109 .constraints.ServiceIdentifierList>
110 serviceIdList = new HashMap<>();
111 if (diversityServiceList != null) {
112 for (String serviceId : diversityServiceList) {
113 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service
114 .constraints.ServiceIdentifierList sil = createServiceIdentifierListForDiversity(serviceId);
115 serviceIdList.put(sil.key(), sil);
119 Map<String, Exclude> excludeMap = initialiseExcludeMap();
120 Map<String, Include> includeMap = initialiseIncludeMap();
121 Map<String, CoRouting> coRoutingMap = initialiseCoRoutingMap();
123 return new HardConstraintsBuilder()
124 .setCustomerCode(customerCode)
127 ? Set.of("operational-mode 1", "operational-mode 2")
130 serviceIdList.isEmpty()
132 : new DiversityBuilder()
133 .setDiversityType(DiversityType.Serial)
134 .setServiceIdentifierList(serviceIdList)
137 exclude == null || !excludeMap.containsKey(exclude)
139 : excludeMap.get(exclude))
141 include == null || !includeMap.containsKey(include)
143 : includeMap.get(include))
147 : new LatencyBuilder().setMaxLatency(Decimal64.valueOf(String.valueOf(maxLatency))).build())
150 ? new HopCountBuilder()
151 .setMaxWdmHopCount(Uint8.valueOf(3))
152 .setMaxOtnHopCount(Uint8.valueOf(5))
157 ? new TEMetricBuilder()
158 .setMaxWdmTEMetric(Uint32.valueOf(8))
159 .setMaxOtnTEMetric(Uint32.valueOf(11))
165 : new DistanceBuilder().setMaxDistance(Decimal64.valueOf(String.valueOf(maxDistance))).build())
167 coRoutingServiceId == null || !coRoutingMap.containsKey(coRoutingServiceId)
169 : coRoutingMap.get(coRoutingServiceId))
173 private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
174 .service.constraints.ServiceIdentifierList createServiceIdentifierListForDiversity(String serviceId) {
175 return new org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing
176 .service.constraints.ServiceIdentifierListBuilder()
177 .setServiceIndentifier(serviceId)
178 .setServiceApplicability(new ServiceApplicabilityBuilder()
187 private static Map<String, Exclude> initialiseExcludeMap() {
188 HashMap<String, Exclude> excludeHashMap = new HashMap<>();
189 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
190 .setLinkId("link-id 1")
191 .setLinkNetworkId("openroadm-topology")
196 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
201 .setNodeId(Set.of(new NodeIdType("node-id-2")))
206 .setSupportingServiceName(Set.of("supported-service-1", "supported-service-5"))
211 .setFiberBundle(Set.of("fiber-1", "fiber-2"))
216 .setFiberBundle(Set.of("fiber-2", "fiber-3"))
218 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
219 .setLinkId("link-id 2")
220 .setLinkNetworkId("openroadm-topology")
222 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
223 .setLinkId("link-id 3")
224 .setLinkNetworkId("openroadm-topology")
229 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
231 return excludeHashMap;
234 private static Map<String, Include> initialiseIncludeMap() {
235 HashMap<String, Include> includeHashMap = new HashMap<>();
236 LinkIdentifier linkId1 = new LinkIdentifierBuilder()
237 .setLinkId("link-id 1")
238 .setLinkNetworkId("openroadm-topology")
243 .setLinkIdentifier(Map.of(linkId1.key(), linkId1))
248 .setNodeId(Set.of(new NodeIdType("node-id-1"), new NodeIdType("node-id-3")))
253 .setSupportingServiceName(Set.of("supported-service-1", "supported-service-5"))
258 .setFiberBundle(Set.of("fiber-1", "fiber-2"))
263 .setFiberBundle(Set.of("fiber-2", "fiber-3"))
265 LinkIdentifier linkId2 = new LinkIdentifierBuilder()
266 .setLinkId("link-id 2")
267 .setLinkNetworkId("openroadm-topology")
269 LinkIdentifier linkId3 = new LinkIdentifierBuilder()
270 .setLinkId("link-id 3")
271 .setLinkNetworkId("openroadm-topology")
276 .setLinkIdentifier(Map.of(linkId2.key(), linkId2, linkId3.key(), linkId3))
278 return includeHashMap;
281 private static Map<String, CoRouting> initialiseCoRoutingMap() {
282 ServiceIdentifierList sil1 = new ServiceIdentifierListBuilder()
283 .setServiceIdentifier("service 1")
284 .setServiceApplicability(new ServiceApplicabilityBuilder()
285 .setEquipment(new EquipmentBuilder()
290 ServiceIdentifierList sil2 = new ServiceIdentifierListBuilder()
291 .setServiceIdentifier("service 2")
292 .setServiceApplicability(new ServiceApplicabilityBuilder()
296 ServiceIdentifierList sil3 = new ServiceIdentifierListBuilder()
297 .setServiceIdentifier("service 3")
298 .setServiceApplicability(new ServiceApplicabilityBuilder()
304 new CoRoutingBuilder().setServiceIdentifierList(Map.of(sil1.key(), sil1, sil2.key(), sil2)).build(),
306 new CoRoutingBuilder().setServiceIdentifierList(Map.of(sil3.key(), sil3)).build());