2 * Copyright © 2017 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
10 package org.opendaylight.transportpce.servicehandler;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.Constraints;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.CoRoutingOrGeneral;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRouting;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Diversity;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Exclude;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Latency;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.ConstraintsSp;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp.co.routing.or.general.general.DiversityBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp.co.routing.or.general.general.IncludeBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp.co.routing.or.general.general.LatencyBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing.constraints.sp.HardConstraintsBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing.constraints.sp.SoftConstraintsBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
39 * Hard/soft constraint from Service 1.2
41 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
44 public class MappingConstraints {
46 private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
47 private HardConstraints serviceHardConstraints;
48 private SoftConstraints serviceSoftConstraints;
49 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
50 .constraints.sp.HardConstraints servicePathHardConstraints;
51 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
52 .constraints.sp.SoftConstraints servicePathSoftConstraints;
55 * MappingConstraints class constructor
56 * for hard/soft from service 1.2.
58 * @param hard HardConstraints
59 * @param soft SoftConstraints
61 public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
62 setServiceHardConstraints(hard);
63 setServiceSoftConstraints(soft);
67 * MappingConstraints class constructor
68 * for hard/soft from servicePath 1.4.
70 * @param hard HardConstraints
71 * @param soft SoftConstraints
73 public MappingConstraints(
74 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
75 .constraints.sp.HardConstraints hard,
76 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
77 .constraints.sp.SoftConstraints soft) {
78 setServicePathHardConstraints(hard);
79 setServicePathSoftConstraints(soft);
83 *get all constraints informations
84 *from service constraints to map to
85 *servicePath constraints.
87 * @param input HardConstraints or SoftConstraints
88 * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
90 private <T> ConstraintsSp getConstraints(T input) {
91 HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
92 SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
93 if ((input != null) && (input instanceof Constraints)) {
94 updateConstraintBuilders(input, tempHard, tempSoft);
96 if (input instanceof HardConstraints) {
97 return tempHard.build();
98 } else if (input instanceof SoftConstraints) {
99 return tempSoft.build();
106 * Update hardConstraintsBuilder and softConstraintsBuilder regarding input.
109 * @param hardConstraintsBuilder HardConstraintsBuilder
110 * @param softConstraintsBuilder SoftConstraintsBuilder
112 private <T> void updateConstraintBuilders(T input,
113 HardConstraintsBuilder hardConstraintsBuilder,
114 SoftConstraintsBuilder softConstraintsBuilder) {
115 Constraints constraints = (Constraints)input;
116 CoRoutingOrGeneral coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
117 if (coRoutingOrGeneral != null) {
118 if (coRoutingOrGeneral instanceof General) {
119 updateConstraintBuilders4General(hardConstraintsBuilder, softConstraintsBuilder, constraints);
120 } else if (coRoutingOrGeneral instanceof CoRouting) {
121 updateConstraintBuilders4Corouting(hardConstraintsBuilder, softConstraintsBuilder, constraints);
127 * Update hardConstraintsBuilder and softConstraintsBuilder for corouting constraints.
128 * @param hardConstraintsBuilder HardConstraintsBuilder
129 * @param softConstraintsBuilder SoftConstraintsBuilder
130 * @param constraints Constraints
132 private void updateConstraintBuilders4Corouting(HardConstraintsBuilder hardConstraintsBuilder,
133 SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
134 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp
135 .co.routing.or.general.CoRoutingBuilder finalCoRouting =
136 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118
137 .constraints.sp.co.routing.or.general.CoRoutingBuilder();
138 CoRouting tmpCoRouting = (CoRouting)constraints.getCoRoutingOrGeneral();
139 if (tmpCoRouting != null) {
140 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or
141 .general.co.routing.CoRouting tmpCoRoutingCoRouting = tmpCoRouting.getCoRouting();
142 if (tmpCoRoutingCoRouting != null) {
143 finalCoRouting.setCoRouting(new CoRoutingBuilder()
144 .setExistingService(tmpCoRoutingCoRouting.getExistingService())
148 hardConstraintsBuilder
149 .setCoRoutingOrGeneral(finalCoRouting.build())
150 .setCustomerCode(constraints.getCustomerCode());
151 softConstraintsBuilder
152 .setCoRoutingOrGeneral(finalCoRouting.build())
153 .setCustomerCode(constraints.getCustomerCode());
157 * Update hardConstraintsBuilder and softConstraintsBuilder for general constraints.
158 * @param hardConstraintsBuilder HardConstraintsBuilder
159 * @param softConstraintsBuilder SoftConstraintsBuilder
160 * @param constraints Constraints
162 private void updateConstraintBuilders4General(HardConstraintsBuilder hardConstraintsBuilder,
163 SoftConstraintsBuilder softConstraintsBuilder, Constraints constraints) {
164 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.constraints.sp
165 .co.routing.or.general.GeneralBuilder finalGeneral =
166 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118
167 .constraints.sp.co.routing.or.general.GeneralBuilder();
168 General tmpGeneral = (General) constraints.getCoRoutingOrGeneral();
169 if (tmpGeneral != null) {
170 Diversity tmpDiversity = tmpGeneral.getDiversity();
171 if (tmpDiversity != null) {
172 finalGeneral.setDiversity(
173 new DiversityBuilder()
174 .setExistingService(tmpDiversity.getExistingService())
175 .setExistingServiceApplicability(
176 new ExistingServiceApplicabilityBuilder()
177 .setClli(tmpDiversity.getExistingServiceApplicability().getSite())
178 .setNode(tmpDiversity.getExistingServiceApplicability().getNode())
179 .setSrlg(tmpDiversity.getExistingServiceApplicability().getSrlg())
183 Exclude tmpExclude = tmpGeneral.getExclude();
184 if (tmpExclude != null) {
185 List<String> nodeIdList = new ArrayList<>();
186 for (NodeIdType nodeId : tmpExclude.getNodeId()) {
187 nodeIdList.add(nodeId.getValue());
189 finalGeneral.setExclude(
191 .setSupportingServiceName(tmpExclude.getSupportingServiceName())
192 .setClli(tmpExclude.getSite())
193 .setNodeId(nodeIdList)
196 Include tmpInclude = tmpGeneral.getInclude();
197 if (tmpInclude != null) {
198 finalGeneral.setInclude(
202 Latency tmpLatency = tmpGeneral.getLatency();
203 if (tmpLatency != null) {
204 finalGeneral.setLatency(
206 .setMaxLatency(tmpLatency.getMaxLatency())
210 hardConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
211 .setCustomerCode(constraints.getCustomerCode());
212 softConstraintsBuilder.setCoRoutingOrGeneral(finalGeneral.build())
213 .setCustomerCode(constraints.getCustomerCode());
217 * map hard/soft constraints from Service 1.2
218 * to ServicePath 1.4.
220 public void serviceToServicePathConstarints() {
221 LOG.info("Mapping Service Constraints to ServicePath Constraints");
222 if (serviceHardConstraints != null) {
223 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
224 .constraints.sp.HardConstraints tempHard =
225 (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
226 .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
227 if (tempHard != null) {
228 servicePathHardConstraints = tempHard;
230 } else if (serviceSoftConstraints != null) {
231 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
232 .constraints.sp.SoftConstraints tempSoft =
233 (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev220118.routing
234 .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
235 if (tempSoft != null) {
236 servicePathSoftConstraints = tempSoft;
242 public HardConstraints getServiceHardConstraints() {
243 return serviceHardConstraints;
247 public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
248 this.serviceHardConstraints = serviceHardConstraints;
252 public SoftConstraints getServiceSoftConstraints() {
253 return serviceSoftConstraints;
257 public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
258 this.serviceSoftConstraints = serviceSoftConstraints;
262 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
263 .routing.constraints.rev220118.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
264 return servicePathHardConstraints;
268 public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
269 .routing.constraints.rev220118.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
270 this.servicePathHardConstraints = servicePathHardConstraints;
274 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
275 .routing.constraints.rev220118.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
276 return servicePathSoftConstraints;
280 public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
281 .routing.constraints.rev220118.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
282 this.servicePathSoftConstraints = servicePathSoftConstraints;