upgrade bundles to openROADM service 5.1.0
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / MappingConstraints.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9
10 package org.opendaylight.transportpce.servicehandler;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
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;
37
38 /**
39  * Class for mapping
40  * Hard/soft constraint from Service 1.2
41  * to servicePath 1.4.
42  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
43  *
44  */
45 public class MappingConstraints {
46     /** Logging. */
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;
54
55     /**
56      * MappingConstraints class constructor
57      * for hard/soft from service 1.2.
58      *
59      * @param hard HardConstraints
60      * @param soft SoftConstraints
61      */
62     public MappingConstraints(HardConstraints hard, SoftConstraints soft) {
63         setServiceHardConstraints(hard);
64         setServiceSoftConstraints(soft);
65     }
66
67     /**
68      * MappingConstraints class constructor
69      * for hard/soft from servicePath 1.4.
70      *
71      * @param hard HardConstraints
72      * @param soft SoftConstraints
73      */
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);
80     }
81
82     /**
83      *get all constraints informations
84      *from service constraints to map to
85      *servicePath constraints.
86      *
87      * @param input HardConstraints or SoftConstraints
88      * @return ConstraintsSp HardConstraintsSp or HardConstraintsSp
89      */
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())
121                                             .build())
122                                     .build());
123                         }
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());
129                             }
130                             finalGeneral.setExclude(
131                                     new ExcludeBuilder()
132                                     .setSupportingServiceName(tmpExclude.getSupportingServiceName())
133                                     .setClli(tmpExclude.getSite())
134                                     .setNodeId(nodeIdList)
135                                     //.setAffinity(value)
136                                     //.setSRLG(value)
137                                     .build());
138                         }
139                         Include tmpInclude = tmpGeneral.getInclude();
140                         if (tmpInclude  !=  null) {
141                             finalGeneral.setInclude(
142                                     new IncludeBuilder()
143                                     //.setOrderedHops()
144                                     .build());
145                         }
146                         Latency tmpLatency = tmpGeneral.getLatency();
147                         if (tmpLatency != null) {
148                             finalGeneral.setLatency(
149                                     new LatencyBuilder()
150                                     .setMaxLatency(tmpLatency.getMaxLatency())
151                                     .build());
152                         }
153                     }
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())
168                                     .build());
169                         }
170                     }
171                     tempHard.setCoRoutingOrGeneral(finalCoRouting.build())
172                         .setCustomerCode(constraints.getCustomerCode());
173                     tempSoft.setCoRoutingOrGeneral(finalCoRouting.build())
174                         .setCustomerCode(constraints.getCustomerCode());
175                 }
176             }
177         }
178         if (input instanceof HardConstraints) {
179             return tempHard.build();
180         } else if (input instanceof SoftConstraints) {
181             return tempSoft.build();
182         } else {
183             return null;
184         }
185     }
186
187     /**
188      * map hard/soft constraints from Service 1.2
189      * to ServicePath 1.4.
190      */
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;
200             }
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;
208             }
209         }
210     }
211
212
213     public HardConstraints getServiceHardConstraints() {
214         return serviceHardConstraints;
215     }
216
217
218     public void setServiceHardConstraints(HardConstraints serviceHardConstraints) {
219         this.serviceHardConstraints = serviceHardConstraints;
220     }
221
222
223     public SoftConstraints getServiceSoftConstraints() {
224         return serviceSoftConstraints;
225     }
226
227
228     public void setServiceSoftConstraints(SoftConstraints serviceSoftConstraints) {
229         this.serviceSoftConstraints = serviceSoftConstraints;
230     }
231
232
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;
236     }
237
238
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;
242     }
243
244
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;
248     }
249
250
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;
254     }
255
256 }