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;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev181130.NodeIdType;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.Constraints;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.CoRoutingOrGeneral;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.CoRouting;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Diversity;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Exclude;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Latency;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ConstraintsSp;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.co.routing.CoRoutingBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.DiversityBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.ExcludeBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.IncludeBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.constraints.sp.co.routing.or.general.general.LatencyBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.diversity.existing.service.contraints.sp.ExistingServiceApplicabilityBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.SoftConstraintsBuilder;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
40 * Hard/soft constraint from Service 1.2
42 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
45 public class MappingConstraints {
47 private static final Logger LOG = LoggerFactory.getLogger(MappingConstraints.class);
48 private HardConstraints serviceHardConstraints;
49 private SoftConstraints serviceSoftConstraints;
50 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
51 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints;
52 private org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
53 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints;
56 * MappingConstraints class constructor
57 * for hard/soft from service 1.2.
59 * @param hard HardConstraints
60 * @param soft SoftConstraints
62 public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
63 setServiceHardConstraints(hard);
64 setServiceSoftConstraints(soft);
68 * MappingConstraints class constructor
69 * for hard/soft from servicePath 1.4.
71 * @param hard HardConstraints
72 * @param soft SoftConstraints
74 public MappingConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
75 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints hard,
76 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
77 .routing.constraints.rev171017.routing.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 CoRoutingOrGeneral coRoutingOrGeneral = null;
92 HardConstraintsBuilder tempHard = new HardConstraintsBuilder();
93 SoftConstraintsBuilder tempSoft = new SoftConstraintsBuilder();
94 if ((input != null) && (input instanceof Constraints)) {
95 Constraints constraints = (Constraints)input;
96 coRoutingOrGeneral = constraints.getCoRoutingOrGeneral();
97 General tmpGeneral = null;
98 CoRouting tmpCoRouting = null;
99 if (coRoutingOrGeneral != null) {
100 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
101 .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder finalGeneral =
102 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
103 .rev171017.constraints.sp.co.routing.or.general.GeneralBuilder();
104 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
105 .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder finalCoRouting =
106 new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
107 .rev171017.constraints.sp.co.routing.or.general.CoRoutingBuilder();
108 if (coRoutingOrGeneral instanceof General) {
109 tmpGeneral = (General) coRoutingOrGeneral;
110 if (tmpGeneral != null) {
111 Diversity tmpDiversity = tmpGeneral.getDiversity();
112 if (tmpDiversity != null) {
113 finalGeneral.setDiversity(
114 new DiversityBuilder()
115 .setExistingService(tmpDiversity.getExistingService())
116 .setExistingServiceApplicability(
117 new ExistingServiceApplicabilityBuilder()
118 .setClli(tmpDiversity.getExistingServiceApplicability().isSite())
119 .setNode(tmpDiversity.getExistingServiceApplicability().isNode())
120 .setSrlg(tmpDiversity.getExistingServiceApplicability().isSrlg())
124 Exclude tmpExclude = tmpGeneral.getExclude();
125 if (tmpExclude != null) {
126 List<String> nodeIdList = new ArrayList<>();
127 for (NodeIdType nodeId : tmpExclude.getNodeId()) {
128 nodeIdList.add(nodeId.getValue());
130 finalGeneral.setExclude(
132 .setSupportingServiceName(tmpExclude.getSupportingServiceName())
133 .setClli(tmpExclude.getSite())
134 .setNodeId(nodeIdList)
135 //.setAffinity(value)
139 Include tmpInclude = tmpGeneral.getInclude();
140 if (tmpInclude != null) {
141 finalGeneral.setInclude(
146 Latency tmpLatency = tmpGeneral.getLatency();
147 if (tmpLatency != null) {
148 finalGeneral.setLatency(
150 .setMaxLatency(tmpLatency.getMaxLatency())
154 tempHard.setCoRoutingOrGeneral(finalGeneral.build())
155 .setCustomerCode(constraints.getCustomerCode());
156 tempSoft.setCoRoutingOrGeneral(finalGeneral.build())
157 .setCustomerCode(constraints.getCustomerCode());
158 } else if (coRoutingOrGeneral instanceof CoRouting) {
159 tmpCoRouting = (CoRouting)coRoutingOrGeneral;
160 if (tmpCoRouting != null) {
161 org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329
162 .constraints.co.routing.or.general.co.routing.CoRouting tmpCoRoutingCoRouting =
163 tmpCoRouting.getCoRouting();
164 if (tmpCoRoutingCoRouting != null) {
165 finalCoRouting.setCoRouting(
166 new CoRoutingBuilder()
167 .setExistingService(tmpCoRoutingCoRouting.getExistingService())
171 tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
172 .setCustomerCode(constraints.getCustomerCode());
173 tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
174 .setCustomerCode(constraints.getCustomerCode());
178 if (input instanceof HardConstraints) {
179 return tempHard.build();
180 } else if (input instanceof SoftConstraints) {
181 return tempSoft.build();
188 * map hard/soft constraints from Service 1.2
189 * to ServicePath 1.4.
191 public void serviceToServicePathConstarints() {
192 LOG.info("Mapping Service Constraints to ServicePath Constraints");
193 if (serviceHardConstraints != null) {
194 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
195 .rev171017.routing.constraints.sp.HardConstraints tempHard = (org.opendaylight.yang.gen
196 .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
197 .constraints.sp.HardConstraints) getConstraints(serviceHardConstraints);
198 if (tempHard != null) {
199 servicePathHardConstraints = tempHard;
201 } else if (serviceSoftConstraints != null) {
202 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints
203 .rev171017.routing.constraints.sp.SoftConstraints tempSoft = (org.opendaylight.yang.gen
204 .v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing
205 .constraints.sp.SoftConstraints) getConstraints(serviceSoftConstraints);
206 if (tempSoft != null) {
207 servicePathSoftConstraints = tempSoft;
213 public HardConstraints getServiceHardConstraints() {
214 return serviceHardConstraints;
218 public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
219 this.serviceHardConstraints = serviceHardConstraints;
223 public SoftConstraints getServiceSoftConstraints() {
224 return serviceSoftConstraints;
228 public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
229 this.serviceSoftConstraints = serviceSoftConstraints;
233 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
234 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints getServicePathHardConstraints() {
235 return servicePathHardConstraints;
239 public void setServicePathHardConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
240 .routing.constraints.rev171017.routing.constraints.sp.HardConstraints servicePathHardConstraints) {
241 this.servicePathHardConstraints = servicePathHardConstraints;
245 public org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
246 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints getServicePathSoftConstraints() {
247 return servicePathSoftConstraints;
251 public void setServicePathSoftConstraints(org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
252 .routing.constraints.rev171017.routing.constraints.sp.SoftConstraints servicePathSoftConstraints) {
253 this.servicePathSoftConstraints = servicePathSoftConstraints;